summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--audio/a2dp.c7
-rw-r--r--audio/a2dp.h3
-rw-r--r--audio/device.c10
-rw-r--r--audio/device.h2
-rw-r--r--audio/headset.c32
-rw-r--r--audio/headset.h2
-rw-r--r--audio/ipc.h1
-rw-r--r--audio/pcm_bluetooth.c32
-rw-r--r--audio/sink.c12
-rw-r--r--audio/sink.h2
-rw-r--r--audio/unix.c18
-rw-r--r--audio/unix.h2
12 files changed, 61 insertions, 62 deletions
diff --git a/audio/a2dp.c b/audio/a2dp.c
index 3afc133d..abd348c3 100644
--- a/audio/a2dp.c
+++ b/audio/a2dp.c
@@ -552,7 +552,8 @@ gboolean a2dp_select_capabilities(struct avdtp_remote_sep *rsep, GSList **caps)
return TRUE;
}
-gboolean a2dp_get_config(struct avdtp_stream *stream, struct ipc_data_cfg **cfg)
+gboolean a2dp_get_config(struct avdtp_stream *stream,
+ struct ipc_data_cfg **cfg, int *fd)
{
struct avdtp_service_capability *cap;
struct avdtp_media_codec_capability *codec_cap = NULL;
@@ -563,10 +564,10 @@ gboolean a2dp_get_config(struct avdtp_stream *stream, struct ipc_data_cfg **cfg)
rsp = g_malloc0(sizeof(struct ipc_data_cfg) +
sizeof(struct ipc_codec_sbc));
- rsp->fd = -1;
+ *fd = -1;
sbc = (void *) rsp->data;
- if (!avdtp_stream_get_transport(stream, &rsp->fd, &rsp->pkt_len,
+ if (!avdtp_stream_get_transport(stream, fd, &rsp->pkt_len,
&caps)) {
g_free(rsp);
return FALSE;
diff --git a/audio/a2dp.h b/audio/a2dp.h
index 7e53f7a9..708f9f94 100644
--- a/audio/a2dp.h
+++ b/audio/a2dp.h
@@ -68,4 +68,5 @@ void a2dp_exit(void);
gboolean a2dp_select_capabilities(struct avdtp_remote_sep *rsep, GSList **caps);
-gboolean a2dp_get_config(struct avdtp_stream *stream, struct ipc_data_cfg **cfg);
+gboolean a2dp_get_config(struct avdtp_stream *stream,
+ struct ipc_data_cfg **cfg, int *fd);
diff --git a/audio/device.c b/audio/device.c
index 1d39cb16..18e494c1 100644
--- a/audio/device.c
+++ b/audio/device.c
@@ -252,16 +252,16 @@ void device_finish_sdp_transaction(struct device *dev)
}
int device_get_config(struct device *dev, int sock, struct ipc_packet *req,
- int pkt_len, struct ipc_data_cfg **rsp)
+ int pkt_len, struct ipc_data_cfg **rsp, int *fd)
{
if (dev->sink && sink_is_active(dev))
- return sink_get_config(dev, sock, req, pkt_len, rsp);
+ return sink_get_config(dev, sock, req, pkt_len, rsp, fd);
else if (dev->headset && headset_is_active(dev))
- return headset_get_config(dev, sock, req, pkt_len, rsp);
+ return headset_get_config(dev, sock, req, pkt_len, rsp, fd);
else if (dev->sink)
- return sink_get_config(dev, sock, req, pkt_len, rsp);
+ return sink_get_config(dev, sock, req, pkt_len, rsp, fd);
else if (dev->headset)
- return headset_get_config(dev, sock, req, pkt_len, rsp);
+ return headset_get_config(dev, sock, req, pkt_len, rsp, fd);
return -EINVAL;
}
diff --git a/audio/device.h b/audio/device.h
index 62c13e9e..d7608741 100644
--- a/audio/device.h
+++ b/audio/device.h
@@ -77,7 +77,7 @@ int device_store(struct device *device, gboolean is_default);
void device_finish_sdp_transaction(struct device *device);
int device_get_config(struct device *dev, int sock, struct ipc_packet *req,
- int pkt_len, struct ipc_data_cfg **rsp);
+ int pkt_len, struct ipc_data_cfg **rsp, int *fd);
void device_set_state(struct device *dev, uint8_t state);
diff --git a/audio/headset.c b/audio/headset.c
index 2bc8583b..9c91c925 100644
--- a/audio/headset.c
+++ b/audio/headset.c
@@ -343,16 +343,16 @@ static void pending_connect_ok(struct pending_connect *c, struct device *dev)
}
else if (c->pkt) {
struct ipc_data_cfg *rsp;
- int ret;
+ int ret, fd;
- ret = headset_get_config(dev, c->sock, c->pkt,
- c->pkt_len, &rsp);
+ ret = headset_get_config(dev, c->sock, c->pkt, c->pkt_len,
+ &rsp, &fd);
if (ret == 0) {
- unix_send_cfg(c->sock, rsp);
+ unix_send_cfg(c->sock, rsp, fd);
g_free(rsp);
}
else
- unix_send_cfg(c->sock, NULL);
+ unix_send_cfg(c->sock, NULL, -1);
}
pending_connect_free(c);
@@ -363,7 +363,7 @@ static void pending_connect_failed(struct pending_connect *c, struct device *dev
if (c->msg)
err_connect_failed(dev->conn, c->msg, strerror(c->err));
if (c->pkt)
- unix_send_cfg(c->sock, NULL);
+ unix_send_cfg(c->sock, NULL, -1);
pending_connect_free(c);
}
@@ -1391,12 +1391,11 @@ void headset_free(void *device)
}
int headset_get_config(void *device, int sock, struct ipc_packet *pkt,
- int pkt_len, struct ipc_data_cfg **cfg)
+ int pkt_len, struct ipc_data_cfg **cfg, int *fd)
{
struct headset *hs = ((struct device *) device)->headset;
int err = EINVAL;
struct pending_connect *c;
- struct ipc_data_cfg *rsp;
if (hs->rfcomm && hs->sco)
goto proceed;
@@ -1420,15 +1419,14 @@ int headset_get_config(void *device, int sock, struct ipc_packet *pkt,
proceed:
*cfg = g_new0(struct ipc_data_cfg, 1);
- rsp = *cfg;
- rsp->fd = g_io_channel_unix_get_fd(hs->sco);
- rsp->fd_opt = CFG_FD_OPT_READWRITE;
- rsp->codec = CFG_CODEC_NONE;
- rsp->channels = 1;
- rsp->channel_mode = CFG_CHANNEL_MODE_MONO;
- rsp->pkt_len = 48;
- rsp->sample_size = 2;
- rsp->rate = 8000;
+ (*cfg)->fd_opt = CFG_FD_OPT_READWRITE;
+ (*cfg)->codec = CFG_CODEC_NONE;
+ (*cfg)->channels = 1;
+ (*cfg)->channel_mode = CFG_CHANNEL_MODE_MONO;
+ (*cfg)->pkt_len = 48;
+ (*cfg)->sample_size = 2;
+ (*cfg)->rate = 8000;
+ *fd = g_io_channel_unix_get_fd(hs->sco);
return 0;
diff --git a/audio/headset.h b/audio/headset.h
index 530bdea8..db1fef65 100644
--- a/audio/headset.h
+++ b/audio/headset.h
@@ -65,7 +65,7 @@ void headset_free(void *device);
void headset_update(void *device, sdp_record_t *record, uint16_t svc);
int headset_get_config(void *device, int sock, struct ipc_packet *pkt,
- int pkt_len, struct ipc_data_cfg **rsp);
+ int pkt_len, struct ipc_data_cfg **rsp, int *fd);
headset_type_t headset_get_type(void *device);
void headset_set_type(void *device, headset_type_t type);
diff --git a/audio/ipc.h b/audio/ipc.h
index bd31abbc..473efc05 100644
--- a/audio/ipc.h
+++ b/audio/ipc.h
@@ -78,7 +78,6 @@ struct ipc_packet {
#define CFG_CODEC_SBC 1
struct ipc_data_cfg {
- int fd; /* Stream file descriptor */
uint8_t fd_opt; /* Stream file descriptor options: read, write or readwrite*/
uint8_t channels; /* Number of audio channel */
uint8_t channel_mode; /* Audio channel mode*/
diff --git a/audio/pcm_bluetooth.c b/audio/pcm_bluetooth.c
index 3f428ecd..b5f74c94 100644
--- a/audio/pcm_bluetooth.c
+++ b/audio/pcm_bluetooth.c
@@ -101,6 +101,7 @@ struct bluetooth_data {
snd_pcm_ioplug_t io;
snd_pcm_sframes_t hw_ptr;
struct ipc_data_cfg cfg; /* Bluetooth device config */
+ int stream_fd; /* Audio stream filedescriptor */
int sock; /* Daemon unix socket */
uint8_t buffer[BUFFER_SIZE]; /* Encoded transfer buffer */
int count; /* Transfer buffer counter */
@@ -147,8 +148,8 @@ static void bluetooth_exit(struct bluetooth_data *data)
if (data->sock >= 0)
close(data->sock);
- if (data->cfg.fd >= 0)
- close(data->cfg.fd);
+ if (data->stream_fd >= 0)
+ close(data->stream_fd);
free(data);
}
@@ -186,7 +187,6 @@ static int bluetooth_prepare(snd_pcm_ioplug_t *io)
static int bluetooth_hw_params(snd_pcm_ioplug_t *io, snd_pcm_hw_params_t *params)
{
struct bluetooth_data *data = io->private_data;
- struct ipc_data_cfg cfg = data->cfg;
uint32_t period_count = io->buffer_size / io->period_size;
int opt_name, err;
@@ -195,14 +195,14 @@ static int bluetooth_hw_params(snd_pcm_ioplug_t *io, snd_pcm_hw_params_t *params
opt_name = (io->stream == SND_PCM_STREAM_PLAYBACK) ?
SCO_TXBUFS : SCO_RXBUFS;
- if (setsockopt(cfg.fd, SOL_SCO, opt_name, &period_count,
+ if (setsockopt(data->stream_fd, SOL_SCO, opt_name, &period_count,
sizeof(period_count)) == 0)
return 0;
opt_name = (io->stream == SND_PCM_STREAM_PLAYBACK) ?
SO_SNDBUF : SO_RCVBUF;
- if (setsockopt(cfg.fd, SOL_SCO, opt_name, &period_count,
+ if (setsockopt(data->stream_fd, SOL_SCO, opt_name, &period_count,
sizeof(period_count)) == 0)
return 0;
@@ -233,7 +233,7 @@ static snd_pcm_sframes_t bluetooth_hsp_read(snd_pcm_ioplug_t *io,
frame_size = areas->step / 8;
- nrecv = recv(cfg.fd, data->buffer, cfg.pkt_len,
+ nrecv = recv(data->stream_fd, data->buffer, cfg.pkt_len,
MSG_WAITALL | (io->nonblock ? MSG_DONTWAIT : 0));
if (nrecv < 0) {
@@ -308,7 +308,7 @@ static snd_pcm_sframes_t bluetooth_hsp_write(snd_pcm_ioplug_t *io,
goto done;
}
- rsend = send(cfg.fd, data->buffer, cfg.pkt_len,
+ rsend = send(data->stream_fd, data->buffer, cfg.pkt_len,
io->nonblock ? MSG_DONTWAIT : 0);
if (rsend > 0) {
/* Reset count pointer */
@@ -338,13 +338,13 @@ static snd_pcm_sframes_t bluetooth_a2dp_read(snd_pcm_ioplug_t *io,
return ret;
}
-static int avdtp_write(struct bluetooth_a2dp *a2dp, struct ipc_data_cfg *cfg,
- unsigned int nonblock)
+static int avdtp_write(struct bluetooth_data *data, unsigned int nonblock)
{
int count = 0;
int written;
struct rtp_header *header;
struct rtp_payload *payload;
+ struct bluetooth_a2dp *a2dp = &data->a2dp;
#ifdef ENABLE_DEBUG
static struct timeval send_date = { 0, 0 };
static struct timeval prev_date = { 0, 0 };
@@ -368,7 +368,7 @@ static int avdtp_write(struct bluetooth_a2dp *a2dp, struct ipc_data_cfg *cfg,
#ifdef ENABLE_DEBUG
gettimeofday(&send_date, NULL);
#endif
- written = send(cfg->fd, a2dp->buffer, a2dp->count,
+ written = send(data->stream_fd, a2dp->buffer, a2dp->count,
nonblock ? MSG_DONTWAIT : 0);
#ifdef ENABLE_DEBUG
@@ -508,7 +508,7 @@ static snd_pcm_sframes_t bluetooth_a2dp_write(snd_pcm_ioplug_t *io,
DBG("encoded = %d a2dp.sbc.len= %d", encoded, a2dp->sbc.len);
if (a2dp->count + a2dp->sbc.len >= data->cfg.pkt_len)
- avdtp_write(a2dp, &data->cfg, io->nonblock);
+ avdtp_write(data, io->nonblock);
memcpy(a2dp->buffer + a2dp->count, a2dp->sbc.data, a2dp->sbc.len);
a2dp->count += a2dp->sbc.len;
@@ -655,8 +655,8 @@ static int bluetooth_recvmsg_fd(struct bluetooth_data *data)
cmsg = CMSG_NXTHDR(&msgh,cmsg)) {
if (cmsg->cmsg_level == SOL_SOCKET
&& cmsg->cmsg_type == SCM_RIGHTS)
- data->cfg.fd = (*(int *) CMSG_DATA(cmsg));
- DBG("fd = %d", data->cfg.fd);
+ data->stream_fd = (*(int *) CMSG_DATA(cmsg));
+ DBG("stream_fd = %d", data->stream_fd);
return 0;
}
}
@@ -780,7 +780,7 @@ done:
a2dp->sbc.bitpool);
}
- if (data->cfg.fd == -1) {
+ if (data->stream_fd == -1) {
SNDERR("Error while configuring device: could not acquire "
"audio socket");
return -EINVAL;
@@ -792,7 +792,7 @@ done:
/* It is possible there is some outstanding
data in the pipe - we have to empty it */
- while (recv(data->cfg.fd, data->buffer, data->cfg.pkt_len,
+ while (recv(data->stream_fd, data->buffer, data->cfg.pkt_len,
MSG_DONTWAIT) > 0);
memset(data->buffer, 0, data->cfg.pkt_len);
@@ -855,7 +855,7 @@ SND_PCM_PLUGIN_DEFINE_FUNC(bluetooth)
data->io.version = SND_PCM_IOPLUG_VERSION;
data->io.name = "Bluetooth Audio Device";
data->io.mmap_rw = 0; /* No direct mmap communication */
- data->io.poll_fd = data->cfg.fd;
+ data->io.poll_fd = data->stream_fd;
data->io.poll_events = stream == SND_PCM_STREAM_PLAYBACK ?
POLLOUT : POLLIN;
data->io.private_data = data;
diff --git a/audio/sink.c b/audio/sink.c
index f7e32647..a660556d 100644
--- a/audio/sink.c
+++ b/audio/sink.c
@@ -132,16 +132,16 @@ void stream_state_changed(struct avdtp_stream *stream, avdtp_state_t old_state,
}
if (c->pkt) {
struct ipc_data_cfg *rsp;
- int ret;
+ int ret, fd;
ret = sink_get_config(dev, c->sock, c->pkt,
- c->pkt_len, &rsp);
+ c->pkt_len, &rsp, &fd);
if (ret == 0) {
- unix_send_cfg(c->sock, rsp);
+ unix_send_cfg(c->sock, rsp, fd);
g_free(rsp);
}
else
- unix_send_cfg(c->sock, NULL);
+ unix_send_cfg(c->sock, NULL, -1);
}
pending_connect_free(c);
@@ -350,7 +350,7 @@ void sink_free(void *device)
}
int sink_get_config(void *device, int sock, struct ipc_packet *req,
- int pkt_len, struct ipc_data_cfg **rsp)
+ int pkt_len, struct ipc_data_cfg **rsp, int *fd)
{
struct device *dev = device;
struct sink *sink = dev->sink;
@@ -382,7 +382,7 @@ int sink_get_config(void *device, int sock, struct ipc_packet *req,
return 1;
proceed:
- if (!a2dp_get_config(sink->stream, rsp))
+ if (!a2dp_get_config(sink->stream, rsp, fd))
goto error;
return 0;
diff --git a/audio/sink.h b/audio/sink.h
index 9d65e278..b14a29a7 100644
--- a/audio/sink.h
+++ b/audio/sink.h
@@ -32,7 +32,7 @@ struct sink *sink_init(void *device);
void sink_new_stream(void *device, void *lsep);
void sink_free(void *device);
int sink_get_config(void *device, int sock, struct ipc_packet *req,
- int pkt_len, struct ipc_data_cfg **rsp);
+ int pkt_len, struct ipc_data_cfg **rsp, int *fd);
gboolean sink_is_active(void *device);
void sink_set_state(void *device, avdtp_state_t state);
avdtp_state_t sink_get_state(void *device);
diff --git a/audio/unix.c b/audio/unix.c
index 0880f4ff..355a7403 100644
--- a/audio/unix.c
+++ b/audio/unix.c
@@ -97,7 +97,7 @@ static void cfg_event(struct unix_client *client, struct ipc_packet *pkt,
{
struct ipc_data_cfg *rsp;
struct device *dev;
- int ret;
+ int ret, fd;
dev = manager_get_connected_device();
if (dev)
@@ -108,7 +108,7 @@ static void cfg_event(struct unix_client *client, struct ipc_packet *pkt,
goto failed;
proceed:
- ret = device_get_config(dev, client->sock, pkt, len, &rsp);
+ ret = device_get_config(dev, client->sock, pkt, len, &rsp, &fd);
if (ret < 0)
goto failed;
@@ -118,13 +118,13 @@ proceed:
if (ret == 1)
return;
- unix_send_cfg(client->sock, rsp);
+ unix_send_cfg(client->sock, rsp, fd);
g_free(rsp);
return;
failed:
- unix_send_cfg(client->sock, NULL);
+ unix_send_cfg(client->sock, NULL, -1);
}
static void ctl_event(struct unix_client *client, struct ipc_packet *pkt,
@@ -286,7 +286,7 @@ void unix_exit(void)
unix_sock = -1;
}
-int unix_send_cfg(int sock, struct ipc_data_cfg *cfg)
+int unix_send_cfg(int sock, struct ipc_data_cfg *cfg, int fd)
{
char buf[IPC_MTU];
struct ipc_packet *pkt = (void *) buf;
@@ -305,8 +305,8 @@ int unix_send_cfg(int sock, struct ipc_data_cfg *cfg)
}
debug("fd=%d, fd_opt=%u, channels=%u, pkt_len=%u,"
- "sample_size=%u, rate=%u", cfg->fd, cfg->fd_opt,
- cfg->channels, cfg->pkt_len, cfg->sample_size, cfg->rate);
+ "sample_size=%u, rate=%u", fd, cfg->fd_opt, cfg->channels,
+ cfg->pkt_len, cfg->sample_size, cfg->rate);
if (cfg->codec == CFG_CODEC_SBC)
codec_len = sizeof(struct ipc_codec_sbc);
@@ -324,8 +324,8 @@ int unix_send_cfg(int sock, struct ipc_data_cfg *cfg)
debug("%d bytes sent", len);
- if (cfg->fd != -1) {
- len = unix_sendmsg_fd(sock, cfg->fd, pkt);
+ if (fd != -1) {
+ len = unix_sendmsg_fd(sock, fd, pkt);
if (len < 0)
error("Error %s(%d)", strerror(errno), errno);
debug("%d bytes sent", len);
diff --git a/audio/unix.h b/audio/unix.h
index c771b965..83e2518a 100644
--- a/audio/unix.h
+++ b/audio/unix.h
@@ -26,4 +26,4 @@
int unix_init(void);
void unix_exit(void);
-int unix_send_cfg(int sock, struct ipc_data_cfg *cfg);
+int unix_send_cfg(int sock, struct ipc_data_cfg *cfg, int fd);