IPC integration part for HFP Audio gateway -- take4 -- rebased
PATCH 4/4 IPC integration part for HFP Audio gateway -- take4 -- rebased
--- audio/gateway.c | 77 ++++++++++++++++++++++++++++++++++++ audio/gateway.h | 7 +++ audio/ipc.h | 11 ++++- audio/ipctest.c | 2 + audio/pcm_bluetooth.c | 30 ++++++++++++++- audio/unix.c | 103 +++++++++++++++++++++++++++++++++++++++++++++--- 6 files changed, 220 insertions(+), 10 deletions(-)
audio/gateway.c +77 -0
@@ -1126,3 +1126,80 @@ int gateway_close(struct audio_device *device) "Connected", DBUS_TYPE_BOOLEAN, &value);return 0 ; } + +/* These are functions to be called from unix.c for audio system +* ifaces (alsa, gstreamer, etc.) */ +gboolean gateway_request_stream (struct audio_device *dev, +gateway_stream_cb_t cb,void *user_data) +{ +struct gateway *gw = dev->gateway; +GError *err =NULL ; +GIOChannel *io; + +if (!gw->sco) { +if (!gw->rfcomm) +return FALSE; + gw->sco_start_cb = cb; + gw->sco_start_cb_data = user_data; + io =bt_io_connect (BT_IO_SCO , sco_connect_cb, dev,NULL , &err, +BT_IO_OPT_SOURCE_BDADDR , &dev->src, +BT_IO_OPT_DEST_BDADDR , &dev->dst, +BT_IO_OPT_INVALID ); +if (!io) { +error ("%s" , err->message); +g_error_free (err); +return FALSE; + } + }else { +if (cb) +cb (dev, user_data); + } +return TRUE; +} + +int gateway_config_stream (struct audio_device *dev,gateway_stream_cb_t sco_cb, +void *user_data) +{ +struct gateway *gw = dev->gateway; + +if (!gw->rfcomm) { + gw->sco_start_cb = sco_cb; + gw->sco_start_cb_data = user_data; +return get_records (dev); + } + +if (sco_cb) +sco_cb (dev, user_data); + +return 0 ; +} + +gboolean gateway_cancel_stream (struct audio_device *dev,unsigned int id) +{ +gateway_close (dev); +return TRUE; +} + +int gateway_get_sco_fd (struct audio_device *dev) +{ +GIOChannel *sco_chan = dev->gateway->sco; + +if (!sco_chan) +return -1 ; + +return g_io_channel_unix_get_fd (sco_chan); +} + +void gateway_suspend_stream (struct audio_device *dev) +{ +struct gateway *gw = dev->gateway; + +if (gw->sco) { +g_io_channel_close (gw->sco); +g_io_channel_unref (gw->sco); + gw->sco =NULL ; + gw->sco_start_cb =NULL ; + gw->sco_start_cb_data =NULL ; + } +} +
audio/gateway.h +7 -0
@@ -32,3 +32,10 @@ struct gateway *gateway_init(struct audio_device *device);gboolean gateway_is_connected (struct audio_device *dev);int gateway_connect_rfcomm (struct audio_device *dev,GIOChannel *chan);void gateway_start_service (struct audio_device *device); +gboolean gateway_request_stream (struct audio_device *dev, +gateway_stream_cb_t cb,void *user_data); +int gateway_config_stream (struct audio_device *dev,gateway_stream_cb_t cb, +void *user_data); +gboolean gateway_cancel_stream (struct audio_device *dev,unsigned int id); +int gateway_get_sco_fd (struct audio_device *dev); +void gateway_suspend_stream (struct audio_device *dev);
audio/ipc.h +9 -2
@@ -110,7 +110,13 @@ typedef struct {#define BT_CAPABILITIES_ACCESS_MODE_WRITE 2#define BT_CAPABILITIES_ACCESS_MODE_READWRITE 3 +#define BT_CAPABILITIES_ROLE_SLAVE 0 +#define BT_CAPABILITIES_ROLE_MASTER 1 +#define BT_FLAG_AUTOCONNECT 1 +/* choose between gateway/source (set bit) and +* headset/sink (clear bit aka default) */ +#define BT_FLAG_MASTER 0x2struct bt_get_capabilities_req {bt_audio_msg_header_t h;
@@ -182,8 +188,8 @@ struct bt_get_capabilities_req { typedef struct { uint8_t seid; - uint8_t transport; - uint8_t type; + uint8_t transport; /* sco | a2dp */ + uint8_t type; /* sbc | mpeg12 | mpeg24 | atrac */ uint8_t length; uint8_t configured; uint8_t lock;
@@ -243,6 +249,7 @@ struct bt_open_rsp {struct bt_set_configuration_req {bt_audio_msg_header_t h; +uint8_t flags;/* Requested flags */ codec_capabilities_t codec;/* Requested codec */ } __attribute__ ((packed));
audio/ipctest.c +2 -0
@@ -38,6 +38,8 @@#include <fcntl.h> #include <signal.h> +#include <signal.h> +#include <glib.h> #include "ipc.h"
audio/pcm_bluetooth.c +29 -1
@@ -109,8 +109,10 @@ struct bluetooth_a2dp {struct bluetooth_alsa_config {char device[18 ];/* Address of the remote Device */ int has_device; -uint8_t transport;/* Requested transport */ +uint8_t transport;/* SCO or A2DP */ int has_transport; +uint8_t role;/* Master (gateway|a2dp source) or Slave (headset|a2dp sink) */ +int has_role;uint16_t rate;int has_rate;uint8_t channel_mode;/* A2DP only */
@@ -429,6 +431,7 @@ static int bluetooth_hsp_hw_params(snd_pcm_ioplug_t *io, snd_pcm_hw_params_t *params) {struct bluetooth_data *data = io->private_data; +struct bluetooth_alsa_config *alsa_conf = &data->alsa_config;char buf[BT_SUGGESTED_BUFFER_SIZE ];struct bt_open_req *open_req = (void *) buf;struct bt_open_rsp *open_rsp = (void *) buf;
@@ -468,6 +471,10 @@ static int bluetooth_hsp_hw_params(snd_pcm_ioplug_t *io, req->codec.seid =BT_A2DP_SEID_RANGE +1 ; req->codec.length =sizeof (pcm_capabilities_t); +if (alsa_conf->has_role && + alsa_conf->role ==BT_CAPABILITIES_ROLE_MASTER ) + req->flags |=BT_FLAG_MASTER ; + req->h.length += req->codec.length -sizeof (req->codec); err =audioservice_send (data->server.fd, &req->h);if (err <0 )
@@ -1436,6 +1443,21 @@ static int bluetooth_parse_config(snd_config_t *conf, }continue ; } +if (strcmp (id,"role" ) ==0 ){ +if (snd_config_get_string (n, &value) <0 ) { +SNDERR ("Invalid type for %s" , id); +return -EINVAL ; + } + +if (strcmp (value,"master" ) ==0 ) { + bt_config->role =BT_CAPABILITIES_ROLE_MASTER ; + bt_config->has_role =1 ; + }else { + bt_config->role =BT_CAPABILITIES_ROLE_SLAVE ; + bt_config->has_role =1 ; + } +continue ; + }if (strcmp (id,"rate" ) ==0 ) {if (snd_config_get_string (n, &value) <0 ) {
@@ -1691,6 +1713,12 @@ static int bluetooth_init(struct bluetooth_data *data, snd_pcm_stream_t stream,if (alsa_conf->autoconnect) req->flags |=BT_FLAG_AUTOCONNECT ;strncpy (req->destination, alsa_conf->device,18 ); + +if (alsa_conf->has_role && + alsa_conf->role ==BT_CAPABILITIES_ROLE_MASTER ) { + req->flags |=BT_FLAG_MASTER ; + } +if (alsa_conf->has_transport) req->transport = alsa_conf->transport;else
audio/unix.c +96 -7
175 lines not on this page · raw message
Signature · 1 line
1.5.4.5