summaryrefslogtreecommitdiff
path: root/android/hal-audio.c
diff options
context:
space:
mode:
authorAndrzej Kaczmarek <andrzej.kaczmarek@tieto.com>2014-05-26 15:16:34 +0200
committerLuiz Augusto von Dentz <luiz.von.dentz@intel.com>2014-06-01 10:17:16 +0300
commit27f17d4083f725c150f310186ca7d73d29064ccc (patch)
treea81f7d06de45d5b05b4a869522c8383ce1ec5064 /android/hal-audio.c
parent5dab4aaafaeff8d3a71e8e03eecbe62392075d19 (diff)
downloadbluez-27f17d4083f725c150f310186ca7d73d29064ccc.tar.gz
android/hal-audio: Allow to autoselect endpoint in open_stream IPC
audio_open_output_stream always tries to open 1st registered endpoint based on assumption that there is only one endpoint registered anyway (due to support for only one codec). With more endpoints available in future we need to be able to retrieve endpoint id which is connected and use it for streaming. This patch adds special case for id=0 in open_stream IPC to return 1st opened endpoint on BlueZ side which is enough for now since only one headset can be connected at any time (i.e. we should not have more than 1 endpoint opened).
Diffstat (limited to 'android/hal-audio.c')
-rw-r--r--android/hal-audio.c36
1 files changed, 28 insertions, 8 deletions
diff --git a/android/hal-audio.c b/android/hal-audio.c
index 9807a5d5a..8b8249883 100644
--- a/android/hal-audio.c
+++ b/android/hal-audio.c
@@ -337,7 +337,7 @@ static int ipc_close_cmd(uint8_t endpoint_id)
return result;
}
-static int ipc_open_stream_cmd(uint8_t endpoint_id, uint16_t *mtu, int *fd,
+static int ipc_open_stream_cmd(uint8_t *endpoint_id, uint16_t *mtu, int *fd,
struct audio_preset **caps)
{
char buf[BLUEZ_AUDIO_MTU];
@@ -352,13 +352,14 @@ static int ipc_open_stream_cmd(uint8_t endpoint_id, uint16_t *mtu, int *fd,
if (!caps)
return AUDIO_STATUS_FAILED;
- cmd.id = endpoint_id;
+ cmd.id = *endpoint_id;
result = audio_ipc_cmd(AUDIO_SERVICE_ID, AUDIO_OP_OPEN_STREAM,
sizeof(cmd), &cmd, &rsp_len, rsp, fd);
if (result == AUDIO_STATUS_SUCCESS) {
size_t buf_len = sizeof(struct audio_preset) +
rsp->preset[0].len;
+ *endpoint_id = rsp->id;
*mtu = rsp->mtu;
*caps = malloc(buf_len);
memcpy(*caps, &rsp->preset, buf_len);
@@ -452,20 +453,39 @@ static void unregister_endpoints(void)
}
}
-static bool open_endpoint(struct audio_endpoint *ep,
+static bool open_endpoint(struct audio_endpoint **epp,
struct audio_input_config *cfg)
{
struct audio_preset *preset;
+ struct audio_endpoint *ep = *epp;
const struct audio_codec *codec;
uint16_t mtu;
uint16_t payload_len;
int fd;
+ size_t i;
+ uint8_t ep_id = 0;
+
+ if (ep)
+ ep_id = ep->id;
- if (ipc_open_stream_cmd(ep->id, &mtu, &fd, &preset) !=
+ if (ipc_open_stream_cmd(&ep_id, &mtu, &fd, &preset) !=
AUDIO_STATUS_SUCCESS)
return false;
- DBG("mtu=%u", mtu);
+ DBG("ep_id=%d mtu=%u", ep_id, mtu);
+
+ for (i = 0; i < MAX_AUDIO_ENDPOINTS; i++)
+ if (audio_endpoints[i].id == ep_id) {
+ ep = &audio_endpoints[i];
+ break;
+ }
+
+ if (!ep) {
+ error("Cound not find opened endpoint");
+ return false;
+ }
+
+ *epp = ep;
payload_len = mtu;
if (ep->codec->use_rtp)
@@ -1096,10 +1116,10 @@ static int audio_open_output_stream(struct audio_hw_device *dev,
out->stream.write = out_write;
out->stream.get_render_position = out_get_render_position;
- /* TODO: for now we always use endpoint 0 */
- out->ep = &audio_endpoints[0];
+ /* We want to autoselect opened endpoint */
+ out->ep = NULL;
- if (!open_endpoint(out->ep, &out->cfg))
+ if (!open_endpoint(&out->ep, &out->cfg))
goto fail;
DBG("rate=%d channels=%d format=%d", out->cfg.rate,