From e7bd84e89e0af0cd2c2390bf7a173f90a473fc62 Mon Sep 17 00:00:00 2001 From: Marcel Holtmann Date: Wed, 4 Apr 2007 09:39:23 +0000 Subject: Add skeleton for generic ALSA plugins --- audio/ctl_bluetooth.c | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) create mode 100644 audio/ctl_bluetooth.c (limited to 'audio/ctl_bluetooth.c') diff --git a/audio/ctl_bluetooth.c b/audio/ctl_bluetooth.c new file mode 100644 index 00000000..7e9755b8 --- /dev/null +++ b/audio/ctl_bluetooth.c @@ -0,0 +1,26 @@ +/* + * + * BlueZ - Bluetooth protocol stack for Linux + * + * Copyright (C) 2004-2007 Marcel Holtmann + * + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + * + */ + +#ifdef HAVE_CONFIG_H +#include +#endif -- cgit From 5ad9e0ec87dd078dc2a4e70967f1e9ace1ebf43f Mon Sep 17 00:00:00 2001 From: Marcel Holtmann Date: Wed, 4 Apr 2007 09:51:11 +0000 Subject: Add basic plugin code --- audio/ctl_bluetooth.c | 12 ++++++++++++ 1 file changed, 12 insertions(+) (limited to 'audio/ctl_bluetooth.c') diff --git a/audio/ctl_bluetooth.c b/audio/ctl_bluetooth.c index 7e9755b8..511a1b24 100644 --- a/audio/ctl_bluetooth.c +++ b/audio/ctl_bluetooth.c @@ -24,3 +24,15 @@ #ifdef HAVE_CONFIG_H #include #endif + +#include +#include + +SND_CTL_PLUGIN_DEFINE_FUNC(bluetooth) +{ + printf("Bluetooth control plugin\n"); + + return -EIO; +} + +SND_CTL_PLUGIN_SYMBOL(bluetooth); -- cgit From 67d220c148f13abca61977b3036ea9f356db9205 Mon Sep 17 00:00:00 2001 From: Marcel Holtmann Date: Mon, 9 Apr 2007 01:14:21 +0000 Subject: Simple process communication --- audio/ctl_bluetooth.c | 244 +++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 242 insertions(+), 2 deletions(-) (limited to 'audio/ctl_bluetooth.c') diff --git a/audio/ctl_bluetooth.c b/audio/ctl_bluetooth.c index 511a1b24..4e55058e 100644 --- a/audio/ctl_bluetooth.c +++ b/audio/ctl_bluetooth.c @@ -25,14 +25,254 @@ #include #endif +#include +#include + #include #include +#ifndef UNIX_PATH_MAX +#define UNIX_PATH_MAX 108 +#endif + +#define DBG(fmt, arg...) printf("DEBUG: %s: " fmt "\n" , __FUNCTION__ , ## arg) + +#define SOCKET_NAME "/org/bluez/audio" + +#define BLUETOOTH_MINVOL 0 +#define BLUETOOTH_MAXVOL 15 + +struct bluetooth_data { + snd_ctl_ext_t ext; + int sock; +}; + +enum { + BLUETOOTH_PLAYBACK, + BLUETOOTH_CAPTURE, +}; + +static const char *vol_devices[2] = { + [BLUETOOTH_PLAYBACK] = "Playback volume", + [BLUETOOTH_CAPTURE] = "Capture volume", +}; + +static void bluetooth_close(snd_ctl_ext_t *ext) +{ + struct bluetooth_data *data = ext->private_data; + + DBG("ext %p", ext); + + close(data->sock); + + free(data); +} + +static int bluetooth_elem_count(snd_ctl_ext_t *ext) +{ + DBG("ext %p", ext); + + return 2; +} + +static int bluetooth_elem_list(snd_ctl_ext_t *ext, + unsigned int offset, snd_ctl_elem_id_t *id) +{ + DBG("ext %p offset %d id %p", ext, offset, id); + + snd_ctl_elem_id_set_interface(id, SND_CTL_ELEM_IFACE_MIXER); + + if (offset > 1) + return -EINVAL; + + snd_ctl_elem_id_set_name(id, vol_devices[offset]); + + return 0; +} + +static snd_ctl_ext_key_t bluetooth_find_elem(snd_ctl_ext_t *ext, + const snd_ctl_elem_id_t *id) +{ + const char *name = snd_ctl_elem_id_get_name(id); + int i; + + DBG("ext %p id %p name '%s'", ext, id, name); + + for (i = 0; i < 2; i++) + if (strcmp(name, vol_devices[i]) == 0) + return i; + + return SND_CTL_EXT_KEY_NOT_FOUND; +} + +static int bluetooth_get_attribute(snd_ctl_ext_t *ext, snd_ctl_ext_key_t key, + int *type, unsigned int *acc, unsigned int *count) +{ + DBG("ext %p key %td", ext, key); + + *type = SND_CTL_ELEM_TYPE_INTEGER; + *acc = SND_CTL_EXT_ACCESS_READWRITE; + *count = 1; + + return 0; +} + +static int bluetooth_get_integer_info(snd_ctl_ext_t *ext, snd_ctl_ext_key_t key, + long *imin, long *imax, long *istep) +{ + DBG("ext %p key %td", ext, key); + + *istep = 1; + *imin = BLUETOOTH_MINVOL; + *imax = BLUETOOTH_MAXVOL; + + return 0; +} + +static int bluetooth_read_integer(snd_ctl_ext_t *ext, snd_ctl_ext_key_t key, + long *value) +{ + struct bluetooth_data *data = ext->private_data; + unsigned char buf[] = { 0x00, 0x00 }; + int len; + + DBG("ext %p key %td", ext, key); + + len = write(data->sock, buf, sizeof(buf)); + + *value = 0; + + return 0; +} + +static int bluetooth_write_integer(snd_ctl_ext_t *ext, snd_ctl_ext_key_t key, + long *value) +{ + struct bluetooth_data *data = ext->private_data; + unsigned char buf[] = { 0xff, 0xff }; + int len; + + DBG("ext %p key %td", ext, key); + + len = write(data->sock, buf, sizeof(buf)); + + return 0; +} + +static int bluetooth_read_event(snd_ctl_ext_t *ext, snd_ctl_elem_id_t *id, + unsigned int *event_mask) +{ + struct bluetooth_data *data = ext->private_data; + unsigned char buf[128]; + int len; + + //DBG("ext %p id %p", ext, id); + + len = recv(data->sock, buf, sizeof(buf), MSG_DONTWAIT); + + return 0; +} + +static snd_ctl_ext_callback_t bluetooth_callback = { + .close = bluetooth_close, + .elem_count = bluetooth_elem_count, + .elem_list = bluetooth_elem_list, + .find_elem = bluetooth_find_elem, + .get_attribute = bluetooth_get_attribute, + .get_integer_info = bluetooth_get_integer_info, + .read_integer = bluetooth_read_integer, + .write_integer = bluetooth_write_integer, + .read_event = bluetooth_read_event, +}; + SND_CTL_PLUGIN_DEFINE_FUNC(bluetooth) { - printf("Bluetooth control plugin\n"); + snd_config_iterator_t iter, next; + struct bluetooth_data *data; + struct sockaddr_un addr; + unsigned int id; + int sk, err; + + DBG(""); + + snd_config_for_each(iter, next, conf) { + snd_config_t *n = snd_config_iterator_entry(iter); + const char *id; + + if (snd_config_get_id(n, &id) < 0) + continue; + + if (strcmp(id, "comment") == 0 || strcmp(id, "type") == 0) + continue; + + SNDERR("Unknown field %s", id); + + return -EINVAL; + } + + id = abs(getpid() * rand()); + + sk = socket(PF_LOCAL, SOCK_DGRAM, 0); + if (sk < 0) { + SNDERR("Can't open socket"); + return -errno; + } + + memset(&addr, 0, sizeof(addr)); + addr.sun_family = AF_UNIX; + snprintf(addr.sun_path + 1, UNIX_PATH_MAX - 2, "%s/%d", SOCKET_NAME, id); + + if (bind(sk, (struct sockaddr *) &addr, sizeof(addr)) < 0) { + SNDERR("Can't bind socket"); + close(sk); + return -errno; + } + + memset(&addr, 0, sizeof(addr)); + addr.sun_family = AF_UNIX; + snprintf(addr.sun_path + 1, UNIX_PATH_MAX - 2, "%s", SOCKET_NAME); + + if (connect(sk, (struct sockaddr *) &addr, sizeof(addr)) < 0) { + SNDERR("Can't connect socket"); + close(sk); + return -errno; + } + + data = malloc(sizeof(*data)); + if (!data) { + close(sk); + return -ENOMEM; + } + + memset(data, 0, sizeof(*data)); + + data->sock = sk; + + data->ext.version = SND_CTL_EXT_VERSION; + data->ext.card_idx = -1; + + strncpy(data->ext.id, "bluetooth", sizeof(data->ext.id) - 1); + strncpy(data->ext.driver, "Bluetooth-Audio", sizeof(data->ext.driver) - 1); + strncpy(data->ext.name, "Bluetooth Audio", sizeof(data->ext.name) - 1); + strncpy(data->ext.longname, "Bluetooth Audio", sizeof(data->ext.longname) - 1); + strncpy(data->ext.mixername, "Bluetooth Audio", sizeof(data->ext.mixername) - 1); + + data->ext.callback = &bluetooth_callback; + data->ext.poll_fd = sk; + data->ext.private_data = data; + + err = snd_ctl_ext_create(&data->ext, name, mode); + if (err < 0) + goto error; + + *handlep = data->ext.handle; + + return 0; + +error: + free(data); - return -EIO; + return err; } SND_CTL_PLUGIN_SYMBOL(bluetooth); -- cgit From b8a407aa8470ad8d92d9142edb41c17548b0cb2c Mon Sep 17 00:00:00 2001 From: Marcel Holtmann Date: Tue, 10 Apr 2007 21:37:24 +0000 Subject: Add first step of ALSA plugin integration --- audio/ctl_bluetooth.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'audio/ctl_bluetooth.c') diff --git a/audio/ctl_bluetooth.c b/audio/ctl_bluetooth.c index 4e55058e..037cfb09 100644 --- a/audio/ctl_bluetooth.c +++ b/audio/ctl_bluetooth.c @@ -193,7 +193,7 @@ SND_CTL_PLUGIN_DEFINE_FUNC(bluetooth) unsigned int id; int sk, err; - DBG(""); + DBG("Bluetooth Control plugin"); snd_config_for_each(iter, next, conf) { snd_config_t *n = snd_config_iterator_entry(iter); @@ -270,6 +270,8 @@ SND_CTL_PLUGIN_DEFINE_FUNC(bluetooth) return 0; error: + close(sk); + free(data); return err; -- cgit From 37cf1720b4b90bf2ad23b07d89c641959dcd9cab Mon Sep 17 00:00:00 2001 From: Marcel Holtmann Date: Fri, 27 Apr 2007 05:27:50 +0000 Subject: Fix some debug outputs --- audio/ctl_bluetooth.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'audio/ctl_bluetooth.c') diff --git a/audio/ctl_bluetooth.c b/audio/ctl_bluetooth.c index 037cfb09..bcc37659 100644 --- a/audio/ctl_bluetooth.c +++ b/audio/ctl_bluetooth.c @@ -108,7 +108,7 @@ static snd_ctl_ext_key_t bluetooth_find_elem(snd_ctl_ext_t *ext, static int bluetooth_get_attribute(snd_ctl_ext_t *ext, snd_ctl_ext_key_t key, int *type, unsigned int *acc, unsigned int *count) { - DBG("ext %p key %td", ext, key); + DBG("ext %p key %ld", ext, key); *type = SND_CTL_ELEM_TYPE_INTEGER; *acc = SND_CTL_EXT_ACCESS_READWRITE; @@ -120,7 +120,7 @@ static int bluetooth_get_attribute(snd_ctl_ext_t *ext, snd_ctl_ext_key_t key, static int bluetooth_get_integer_info(snd_ctl_ext_t *ext, snd_ctl_ext_key_t key, long *imin, long *imax, long *istep) { - DBG("ext %p key %td", ext, key); + DBG("ext %p key %ld", ext, key); *istep = 1; *imin = BLUETOOTH_MINVOL; @@ -136,7 +136,7 @@ static int bluetooth_read_integer(snd_ctl_ext_t *ext, snd_ctl_ext_key_t key, unsigned char buf[] = { 0x00, 0x00 }; int len; - DBG("ext %p key %td", ext, key); + DBG("ext %p key %ld", ext, key); len = write(data->sock, buf, sizeof(buf)); @@ -152,7 +152,7 @@ static int bluetooth_write_integer(snd_ctl_ext_t *ext, snd_ctl_ext_key_t key, unsigned char buf[] = { 0xff, 0xff }; int len; - DBG("ext %p key %td", ext, key); + DBG("ext %p key %ld", ext, key); len = write(data->sock, buf, sizeof(buf)); -- cgit From e343f2b21a2209d5713e20ad38bbcc862897380b Mon Sep 17 00:00:00 2001 From: Johan Hedberg Date: Sat, 26 May 2007 21:12:20 +0000 Subject: Move more common stuff to ipc.h --- audio/ctl_bluetooth.c | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) (limited to 'audio/ctl_bluetooth.c') diff --git a/audio/ctl_bluetooth.c b/audio/ctl_bluetooth.c index bcc37659..4d73c788 100644 --- a/audio/ctl_bluetooth.c +++ b/audio/ctl_bluetooth.c @@ -31,14 +31,10 @@ #include #include -#ifndef UNIX_PATH_MAX -#define UNIX_PATH_MAX 108 -#endif +#include "ipc.h" #define DBG(fmt, arg...) printf("DEBUG: %s: " fmt "\n" , __FUNCTION__ , ## arg) -#define SOCKET_NAME "/org/bluez/audio" - #define BLUETOOTH_MINVOL 0 #define BLUETOOTH_MAXVOL 15 @@ -220,7 +216,8 @@ SND_CTL_PLUGIN_DEFINE_FUNC(bluetooth) memset(&addr, 0, sizeof(addr)); addr.sun_family = AF_UNIX; - snprintf(addr.sun_path + 1, UNIX_PATH_MAX - 2, "%s/%d", SOCKET_NAME, id); + snprintf(addr.sun_path + 1, UNIX_PATH_MAX - 2, "%s/%d", + IPC_SOCKET_NAME, id); if (bind(sk, (struct sockaddr *) &addr, sizeof(addr)) < 0) { SNDERR("Can't bind socket"); @@ -230,7 +227,7 @@ SND_CTL_PLUGIN_DEFINE_FUNC(bluetooth) memset(&addr, 0, sizeof(addr)); addr.sun_family = AF_UNIX; - snprintf(addr.sun_path + 1, UNIX_PATH_MAX - 2, "%s", SOCKET_NAME); + snprintf(addr.sun_path + 1, UNIX_PATH_MAX - 2, "%s", IPC_SOCKET_NAME); if (connect(sk, (struct sockaddr *) &addr, sizeof(addr)) < 0) { SNDERR("Can't connect socket"); -- cgit From 5ed2a3ba745856206c66d8ecb98afb8a1f9ec7b5 Mon Sep 17 00:00:00 2001 From: Luiz Augusto von Dentz Date: Thu, 14 Jun 2007 20:36:26 +0000 Subject: Initial support for audio control plugin and some code cleanups. --- audio/ctl_bluetooth.c | 222 +++++++++++++++++++++++++++++++++++--------------- 1 file changed, 158 insertions(+), 64 deletions(-) (limited to 'audio/ctl_bluetooth.c') diff --git a/audio/ctl_bluetooth.c b/audio/ctl_bluetooth.c index 4d73c788..411d7e00 100644 --- a/audio/ctl_bluetooth.c +++ b/audio/ctl_bluetooth.c @@ -33,7 +33,11 @@ #include "ipc.h" +#ifdef ENABLE_DEBUG #define DBG(fmt, arg...) printf("DEBUG: %s: " fmt "\n" , __FUNCTION__ , ## arg) +#else +#define DBG(fmt, arg...) +#endif #define BLUETOOTH_MINVOL 0 #define BLUETOOTH_MAXVOL 15 @@ -53,15 +57,24 @@ static const char *vol_devices[2] = { [BLUETOOTH_CAPTURE] = "Capture volume", }; +static void bluetooth_exit(struct bluetooth_data *data) +{ + if (data == NULL) + return; + + if (data->sock >= 0) + close(data->sock); + + free(data); +} + static void bluetooth_close(snd_ctl_ext_t *ext) { struct bluetooth_data *data = ext->private_data; DBG("ext %p", ext); - close(data->sock); - - free(data); + bluetooth_exit(data); } static int bluetooth_elem_count(snd_ctl_ext_t *ext) @@ -125,48 +138,140 @@ static int bluetooth_get_integer_info(snd_ctl_ext_t *ext, snd_ctl_ext_key_t key, return 0; } +static int bluetooth_send_ctl(struct bluetooth_data *data, + struct ipc_packet *pkt, int len) +{ + int ret; + + ret = send(data->sock, pkt, len, MSG_NOSIGNAL); + if (ret <= 0) { + SYSERR("Unable to request new volume value to server"); + return -errno; + } + + ret = recv(data->sock, pkt, len, 0); + if (ret <= 0) { + SYSERR("Unable to receive new volume value from server"); + return -errno; + } + + if(pkt->type != PKT_TYPE_CTL_RSP) { + SNDERR("Unexpected packet type %d received", pkt->type); + return -EINVAL; + } + + if(pkt->length != sizeof(struct ipc_data_ctl)) { + SNDERR("Unexpected packet length %d received", pkt->length); + return -EINVAL; + } + + return 0; +} + static int bluetooth_read_integer(snd_ctl_ext_t *ext, snd_ctl_ext_key_t key, long *value) { struct bluetooth_data *data = ext->private_data; - unsigned char buf[] = { 0x00, 0x00 }; - int len; + struct ipc_packet *pkt; + struct ipc_data_ctl *ctl; + int len, ret; DBG("ext %p key %ld", ext, key); - len = write(data->sock, buf, sizeof(buf)); - + len = sizeof(struct ipc_packet) + sizeof(struct ipc_data_ctl); + pkt = malloc(len); + memset(pkt, 0, len); *value = 0; - return 0; + pkt->type = PKT_TYPE_CTL_REQ; + pkt->length = sizeof(struct ipc_data_ctl); + ctl = (struct ipc_data_ctl *) pkt->data; + ctl->mode = key; + + if ((ret = bluetooth_send_ctl(data, pkt, len)) < 0) + goto done; + + *value = ctl->key; +done: + free(pkt); + return ret; } static int bluetooth_write_integer(snd_ctl_ext_t *ext, snd_ctl_ext_key_t key, long *value) { struct bluetooth_data *data = ext->private_data; - unsigned char buf[] = { 0xff, 0xff }; - int len; + struct ipc_packet *pkt; + struct ipc_data_ctl *ctl; + long current; + int len, ret; DBG("ext %p key %ld", ext, key); - len = write(data->sock, buf, sizeof(buf)); + if ((ret = bluetooth_read_integer(ext, key, ¤t)) < 0) + return ret; - return 0; + if (*value == current) + return 0; + + len = sizeof(struct ipc_packet) + sizeof(struct ipc_data_ctl); + pkt = malloc(len); + memset(pkt, 0, len); + + pkt->length = sizeof(struct ipc_data_ctl); + ctl = (struct ipc_data_ctl *) pkt->data; + ctl->mode = key; + + while (*value != current) { + pkt->type = PKT_TYPE_CTL_REQ; + ctl->key = (*value > current) ? CTL_KEY_VOL_UP : CTL_KEY_VOL_DOWN; + + if ((ret = bluetooth_send_ctl(data, pkt, len)) < 0) + break; + + current = ctl->key; + } + + free(pkt); + return ret; } static int bluetooth_read_event(snd_ctl_ext_t *ext, snd_ctl_elem_id_t *id, unsigned int *event_mask) { struct bluetooth_data *data = ext->private_data; - unsigned char buf[128]; - int len; + struct ipc_packet *pkt; + struct ipc_data_ctl *ctl; + int len, ret; - //DBG("ext %p id %p", ext, id); + DBG("ext %p id %p", ext, id); - len = recv(data->sock, buf, sizeof(buf), MSG_DONTWAIT); + len = sizeof(struct ipc_packet) + sizeof(struct ipc_data_ctl); + pkt = malloc(len); + memset(pkt, 0, len); - return 0; + ret = recv(data->sock, pkt, len, MSG_DONTWAIT); + if (ret <= 0) + return -errno; + + if(pkt->type != PKT_TYPE_CTL_NTFY) { + SNDERR("Unexpected packet type %d received!", pkt->type); + return -EAGAIN; + } + + if(pkt->length != sizeof(struct ipc_data_ctl)) { + SNDERR("Unexpected packet length %d received", pkt->length); + return -EAGAIN; + } + + ctl = (struct ipc_data_ctl *) pkt->data; + snd_ctl_elem_id_set_interface(id, SND_CTL_ELEM_IFACE_MIXER); + snd_ctl_elem_id_set_name(id, ctl->mode == BLUETOOTH_PLAYBACK ? + vol_devices[BLUETOOTH_PLAYBACK] : + vol_devices[BLUETOOTH_CAPTURE]); + *event_mask = SND_CTL_EVENT_MASK_VALUE; + + return 1; } static snd_ctl_ext_callback_t bluetooth_callback = { @@ -181,69 +286,60 @@ static snd_ctl_ext_callback_t bluetooth_callback = { .read_event = bluetooth_read_event, }; -SND_CTL_PLUGIN_DEFINE_FUNC(bluetooth) +static int bluetooth_init(struct bluetooth_data *data) { - snd_config_iterator_t iter, next; - struct bluetooth_data *data; - struct sockaddr_un addr; - unsigned int id; - int sk, err; - - DBG("Bluetooth Control plugin"); - - snd_config_for_each(iter, next, conf) { - snd_config_t *n = snd_config_iterator_entry(iter); - const char *id; - - if (snd_config_get_id(n, &id) < 0) - continue; + int sk, err, id; + struct sockaddr_un addr = { + AF_UNIX, IPC_SOCKET_NAME + }; - if (strcmp(id, "comment") == 0 || strcmp(id, "type") == 0) - continue; + if (!data) + return -EINVAL; - SNDERR("Unknown field %s", id); + memset(data, 0, sizeof(struct bluetooth_data)); - return -EINVAL; - } + data->sock = -1; id = abs(getpid() * rand()); - sk = socket(PF_LOCAL, SOCK_DGRAM, 0); - if (sk < 0) { + if ((sk = socket(PF_LOCAL, SOCK_STREAM, 0)) < 0) { + err = -errno; SNDERR("Can't open socket"); return -errno; } - memset(&addr, 0, sizeof(addr)); - addr.sun_family = AF_UNIX; - snprintf(addr.sun_path + 1, UNIX_PATH_MAX - 2, "%s/%d", - IPC_SOCKET_NAME, id); - - if (bind(sk, (struct sockaddr *) &addr, sizeof(addr)) < 0) { - SNDERR("Can't bind socket"); - close(sk); - return -errno; - } - - memset(&addr, 0, sizeof(addr)); - addr.sun_family = AF_UNIX; - snprintf(addr.sun_path + 1, UNIX_PATH_MAX - 2, "%s", IPC_SOCKET_NAME); - + DBG("Connecting to address: %s", addr.sun_path + 1); if (connect(sk, (struct sockaddr *) &addr, sizeof(addr)) < 0) { + err = -errno; SNDERR("Can't connect socket"); close(sk); - return -errno; + return err; } - data = malloc(sizeof(*data)); + data->sock = sk; + + return 0; +} + +SND_CTL_PLUGIN_DEFINE_FUNC(bluetooth) +{ + struct bluetooth_data *data; + int err; + + DBG("Bluetooth Control plugin"); + + data = malloc(sizeof(struct bluetooth_data)); + memset(data, 0, sizeof(struct bluetooth_data)); if (!data) { - close(sk); - return -ENOMEM; + err = -ENOMEM; + goto error; } - memset(data, 0, sizeof(*data)); + err = bluetooth_init(data); + if (err < 0) + goto error; - data->sock = sk; + memset(data, 0, sizeof(*data)); data->ext.version = SND_CTL_EXT_VERSION; data->ext.card_idx = -1; @@ -255,7 +351,7 @@ SND_CTL_PLUGIN_DEFINE_FUNC(bluetooth) strncpy(data->ext.mixername, "Bluetooth Audio", sizeof(data->ext.mixername) - 1); data->ext.callback = &bluetooth_callback; - data->ext.poll_fd = sk; + data->ext.poll_fd = data->sock; data->ext.private_data = data; err = snd_ctl_ext_create(&data->ext, name, mode); @@ -267,9 +363,7 @@ SND_CTL_PLUGIN_DEFINE_FUNC(bluetooth) return 0; error: - close(sk); - - free(data); + bluetooth_exit(data); return err; } -- cgit From c2833e263d6cfc4cf82f4bfdcc59640a4071aeae Mon Sep 17 00:00:00 2001 From: Johan Hedberg Date: Mon, 13 Aug 2007 08:14:22 +0000 Subject: Remove ifndef protections and includes from .h files --- audio/ctl_bluetooth.c | 2 ++ 1 file changed, 2 insertions(+) (limited to 'audio/ctl_bluetooth.c') diff --git a/audio/ctl_bluetooth.c b/audio/ctl_bluetooth.c index 411d7e00..9e1c320c 100644 --- a/audio/ctl_bluetooth.c +++ b/audio/ctl_bluetooth.c @@ -31,6 +31,8 @@ #include #include +#include + #include "ipc.h" #ifdef ENABLE_DEBUG -- cgit From d4e24bf6a3d8af6479abce92fbbf1869a59669aa Mon Sep 17 00:00:00 2001 From: Luiz Augusto von Dentz Date: Wed, 21 Nov 2007 20:24:11 +0000 Subject: Integrate new ipc API implementation. --- audio/ctl_bluetooth.c | 134 ++++++++++++++++++++++---------------------------- 1 file changed, 60 insertions(+), 74 deletions(-) (limited to 'audio/ctl_bluetooth.c') diff --git a/audio/ctl_bluetooth.c b/audio/ctl_bluetooth.c index 9e1c320c..5c198b1a 100644 --- a/audio/ctl_bluetooth.c +++ b/audio/ctl_bluetooth.c @@ -65,7 +65,7 @@ static void bluetooth_exit(struct bluetooth_data *data) return; if (data->sock >= 0) - close(data->sock); + bt_audio_service_close(data->sock); free(data); } @@ -141,32 +141,49 @@ static int bluetooth_get_integer_info(snd_ctl_ext_t *ext, snd_ctl_ext_key_t key, } static int bluetooth_send_ctl(struct bluetooth_data *data, - struct ipc_packet *pkt, int len) + uint8_t mode, uint8_t key, struct bt_control_rsp *ctl_rsp) { int ret; + struct bt_control_req *ctl_req = (void *) ctl_rsp; + const char *type; - ret = send(data->sock, pkt, len, MSG_NOSIGNAL); + memset(ctl_req, 0, BT_AUDIO_IPC_PACKET_SIZE); + ctl_req->h.msg_type = BT_CONTROL_REQ; + ctl_req->mode = mode; + ctl_req->key = key; + + ret = send(data->sock, ctl_req, BT_AUDIO_IPC_PACKET_SIZE, MSG_NOSIGNAL); if (ret <= 0) { SYSERR("Unable to request new volume value to server"); return -errno; } - ret = recv(data->sock, pkt, len, 0); + ret = recv(data->sock, ctl_rsp, BT_AUDIO_IPC_PACKET_SIZE, 0); if (ret <= 0) { - SYSERR("Unable to receive new volume value from server"); + SNDERR("Unable to receive new volume value from server"); return -errno; } - if(pkt->type != PKT_TYPE_CTL_RSP) { - SNDERR("Unexpected packet type %d received", pkt->type); + type = bt_audio_strmsg(ctl_rsp->h.msg_type); + if (!type) { + SNDERR("Bogus message type %d " + "received from audio service", + ctl_rsp->h.msg_type); return -EINVAL; } - if(pkt->length != sizeof(struct ipc_data_ctl)) { - SNDERR("Unexpected packet length %d received", pkt->length); + if (ctl_rsp->h.msg_type != BT_CONTROL_RSP) { + SNDERR("Unexpected message %s received", type); return -EINVAL; } + if (ctl_rsp->posix_errno != 0) { + SNDERR("BT_CONTROL failed : %s (%d)", + strerror(ctl_rsp->posix_errno), + ctl_rsp->posix_errno); + return -ctl_rsp->posix_errno; + } + return 0; } @@ -174,28 +191,21 @@ static int bluetooth_read_integer(snd_ctl_ext_t *ext, snd_ctl_ext_key_t key, long *value) { struct bluetooth_data *data = ext->private_data; - struct ipc_packet *pkt; - struct ipc_data_ctl *ctl; - int len, ret; + int ret; + char buf[BT_AUDIO_IPC_PACKET_SIZE]; + struct bt_control_rsp *rsp = (void *) buf; DBG("ext %p key %ld", ext, key); - len = sizeof(struct ipc_packet) + sizeof(struct ipc_data_ctl); - pkt = malloc(len); - memset(pkt, 0, len); + memset(buf, 0, sizeof(buf)); *value = 0; - pkt->type = PKT_TYPE_CTL_REQ; - pkt->length = sizeof(struct ipc_data_ctl); - ctl = (struct ipc_data_ctl *) pkt->data; - ctl->mode = key; - - if ((ret = bluetooth_send_ctl(data, pkt, len)) < 0) + ret = bluetooth_send_ctl(data, key, 0, rsp); + if (ret < 0) goto done; - *value = ctl->key; + *value = rsp->key; done: - free(pkt); return ret; } @@ -203,38 +213,31 @@ static int bluetooth_write_integer(snd_ctl_ext_t *ext, snd_ctl_ext_key_t key, long *value) { struct bluetooth_data *data = ext->private_data; - struct ipc_packet *pkt; - struct ipc_data_ctl *ctl; + char buf[BT_AUDIO_IPC_PACKET_SIZE]; + struct bt_control_rsp *rsp = (void *) buf; long current; - int len, ret; + int ret, keyvalue; DBG("ext %p key %ld", ext, key); - if ((ret = bluetooth_read_integer(ext, key, ¤t)) < 0) + ret = bluetooth_read_integer(ext, key, ¤t); + if (ret < 0) return ret; if (*value == current) return 0; - len = sizeof(struct ipc_packet) + sizeof(struct ipc_data_ctl); - pkt = malloc(len); - memset(pkt, 0, len); - - pkt->length = sizeof(struct ipc_data_ctl); - ctl = (struct ipc_data_ctl *) pkt->data; - ctl->mode = key; - while (*value != current) { - pkt->type = PKT_TYPE_CTL_REQ; - ctl->key = (*value > current) ? CTL_KEY_VOL_UP : CTL_KEY_VOL_DOWN; + keyvalue = (*value > current) ? BT_CONTROL_KEY_VOL_UP : + BT_CONTROL_KEY_VOL_DOWN; - if ((ret = bluetooth_send_ctl(data, pkt, len)) < 0) + ret = bluetooth_send_ctl(data, key, keyvalue, rsp); + if (ret < 0) break; - current = ctl->key; + current = keyvalue; } - free(pkt); return ret; } @@ -242,33 +245,31 @@ static int bluetooth_read_event(snd_ctl_ext_t *ext, snd_ctl_elem_id_t *id, unsigned int *event_mask) { struct bluetooth_data *data = ext->private_data; - struct ipc_packet *pkt; - struct ipc_data_ctl *ctl; - int len, ret; + char buf[BT_AUDIO_IPC_PACKET_SIZE]; + struct bt_control_ind *ind = (void *) buf; + int ret; + const char *type; DBG("ext %p id %p", ext, id); - len = sizeof(struct ipc_packet) + sizeof(struct ipc_data_ctl); - pkt = malloc(len); - memset(pkt, 0, len); - - ret = recv(data->sock, pkt, len, MSG_DONTWAIT); - if (ret <= 0) - return -errno; + memset(buf, 0, sizeof(buf)); - if(pkt->type != PKT_TYPE_CTL_NTFY) { - SNDERR("Unexpected packet type %d received!", pkt->type); + ret = recv(data->sock, ind, BT_AUDIO_IPC_PACKET_SIZE, MSG_DONTWAIT); + type = bt_audio_strmsg(ind->h.msg_type); + if (!type) { + SNDERR("Bogus message type %d " + "received from audio service", + ind->h.msg_type); return -EAGAIN; } - if(pkt->length != sizeof(struct ipc_data_ctl)) { - SNDERR("Unexpected packet length %d received", pkt->length); + if (ind->h.msg_type != BT_CONTROL_IND) { + SNDERR("Unexpected message %s received", type); return -EAGAIN; } - ctl = (struct ipc_data_ctl *) pkt->data; snd_ctl_elem_id_set_interface(id, SND_CTL_ELEM_IFACE_MIXER); - snd_ctl_elem_id_set_name(id, ctl->mode == BLUETOOTH_PLAYBACK ? + snd_ctl_elem_id_set_name(id, ind->mode == BLUETOOTH_PLAYBACK ? vol_devices[BLUETOOTH_PLAYBACK] : vol_devices[BLUETOOTH_CAPTURE]); *event_mask = SND_CTL_EVENT_MASK_VALUE; @@ -290,10 +291,7 @@ static snd_ctl_ext_callback_t bluetooth_callback = { static int bluetooth_init(struct bluetooth_data *data) { - int sk, err, id; - struct sockaddr_un addr = { - AF_UNIX, IPC_SOCKET_NAME - }; + int sk; if (!data) return -EINVAL; @@ -302,21 +300,9 @@ static int bluetooth_init(struct bluetooth_data *data) data->sock = -1; - id = abs(getpid() * rand()); - - if ((sk = socket(PF_LOCAL, SOCK_STREAM, 0)) < 0) { - err = -errno; - SNDERR("Can't open socket"); + sk = bt_audio_service_open(); + if (sk < 0) return -errno; - } - - DBG("Connecting to address: %s", addr.sun_path + 1); - if (connect(sk, (struct sockaddr *) &addr, sizeof(addr)) < 0) { - err = -errno; - SNDERR("Can't connect socket"); - close(sk); - return err; - } data->sock = sk; -- cgit From d51c190ddd0c2774509d0284979b24b9b0f3524a Mon Sep 17 00:00:00 2001 From: Luiz Augusto von Dentz Date: Tue, 4 Dec 2007 19:42:00 +0000 Subject: Fix error messages. (thanks to fchevalier for the patch) --- audio/ctl_bluetooth.c | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) (limited to 'audio/ctl_bluetooth.c') diff --git a/audio/ctl_bluetooth.c b/audio/ctl_bluetooth.c index 5c198b1a..04185b36 100644 --- a/audio/ctl_bluetooth.c +++ b/audio/ctl_bluetooth.c @@ -164,24 +164,24 @@ static int bluetooth_send_ctl(struct bluetooth_data *data, return -errno; } - type = bt_audio_strmsg(ctl_rsp->h.msg_type); + type = bt_audio_strmsg(ctl_rsp->rsp_h.msg_h.msg_type); if (!type) { SNDERR("Bogus message type %d " "received from audio service", - ctl_rsp->h.msg_type); + ctl_rsp->rsp_h.msg_h.msg_type); return -EINVAL; } - if (ctl_rsp->h.msg_type != BT_CONTROL_RSP) { + if (ctl_rsp->rsp_h.msg_h.msg_type != BT_CONTROL_RSP) { SNDERR("Unexpected message %s received", type); return -EINVAL; } - if (ctl_rsp->posix_errno != 0) { + if (ctl_rsp->rsp_h.posix_errno != 0) { SNDERR("BT_CONTROL failed : %s (%d)", - strerror(ctl_rsp->posix_errno), - ctl_rsp->posix_errno); - return -ctl_rsp->posix_errno; + strerror(ctl_rsp->rsp_h.posix_errno), + ctl_rsp->rsp_h.posix_errno); + return -ctl_rsp->rsp_h.posix_errno; } return 0; -- cgit From 259598d66abd75124bc1c5f008a504d98e78b847 Mon Sep 17 00:00:00 2001 From: Brad Midgley Date: Mon, 7 Jan 2008 23:52:02 +0000 Subject: don't overwrite the output of bluetooth_init also the memset is done inside bluetooth_init --- audio/ctl_bluetooth.c | 3 --- 1 file changed, 3 deletions(-) (limited to 'audio/ctl_bluetooth.c') diff --git a/audio/ctl_bluetooth.c b/audio/ctl_bluetooth.c index 04185b36..f7239f67 100644 --- a/audio/ctl_bluetooth.c +++ b/audio/ctl_bluetooth.c @@ -317,7 +317,6 @@ SND_CTL_PLUGIN_DEFINE_FUNC(bluetooth) DBG("Bluetooth Control plugin"); data = malloc(sizeof(struct bluetooth_data)); - memset(data, 0, sizeof(struct bluetooth_data)); if (!data) { err = -ENOMEM; goto error; @@ -327,8 +326,6 @@ SND_CTL_PLUGIN_DEFINE_FUNC(bluetooth) if (err < 0) goto error; - memset(data, 0, sizeof(*data)); - data->ext.version = SND_CTL_EXT_VERSION; data->ext.card_idx = -1; -- cgit From e823c15e43a6f924779e466d434c51157002d9ee Mon Sep 17 00:00:00 2001 From: Marcel Holtmann Date: Sat, 2 Feb 2008 03:37:05 +0000 Subject: Update copyright information --- audio/ctl_bluetooth.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'audio/ctl_bluetooth.c') diff --git a/audio/ctl_bluetooth.c b/audio/ctl_bluetooth.c index f7239f67..a87c3c19 100644 --- a/audio/ctl_bluetooth.c +++ b/audio/ctl_bluetooth.c @@ -2,7 +2,7 @@ * * BlueZ - Bluetooth protocol stack for Linux * - * Copyright (C) 2004-2007 Marcel Holtmann + * Copyright (C) 2004-2008 Marcel Holtmann * * * This library is free software; you can redistribute it and/or -- cgit