From db4eeea4a25740595e4760c2e55f37c625344046 Mon Sep 17 00:00:00 2001 From: Thierry Bultel Date: Wed, 13 Feb 2019 09:30:58 +0100 Subject: bluealsa plugin: get the sampling rate from the transport The sampling rate, for both SCO and A2DP, had been harcoded for convenience. But this is not a constant, because it depends on the connected handset. This commit retrieves the sampling rate for each new transport and uses that information as a parameter for the stream creation in the softmixer. Change-Id: I4d30eccba9cc63d7f4e618c571719996a136b4f5 Signed-off-by: Thierry Bultel --- plugins/lib/bluealsa/hal-bluealsa-transports.c | 6 +++-- plugins/lib/bluealsa/hal-bluealsa.c | 35 ++++++++++++++++++++------ 2 files changed, 32 insertions(+), 9 deletions(-) diff --git a/plugins/lib/bluealsa/hal-bluealsa-transports.c b/plugins/lib/bluealsa/hal-bluealsa-transports.c index 590ab5d..b528212 100644 --- a/plugins/lib/bluealsa/hal-bluealsa-transports.c +++ b/plugins/lib/bluealsa/hal-bluealsa-transports.c @@ -147,9 +147,11 @@ char * halBlueAlsaTransportAsString(char * buff, size_t len, const struct ba_msg char addr[18]; ba2str(&transport->addr, addr); - snprintf(buff, len, "%s,%s,%s", addr, + snprintf(buff, len, "%s,%s,%s sampling %d codec %d", addr, transport->type & BA_PCM_TYPE_A2DP?"a2dp":"sco", - transport->type & BA_PCM_STREAM_PLAYBACK?"playback":"capture"); + transport->type & BA_PCM_STREAM_PLAYBACK?"playback":"capture", + transport->sampling, + transport->codec); return buff; } diff --git a/plugins/lib/bluealsa/hal-bluealsa.c b/plugins/lib/bluealsa/hal-bluealsa.c index 10a61ae..05a1540 100644 --- a/plugins/lib/bluealsa/hal-bluealsa.c +++ b/plugins/lib/bluealsa/hal-bluealsa.c @@ -32,6 +32,8 @@ #define HAL_BLUEALSA_PLUGIN_NAME "hal-bluealsa" +#define A2DP_LISTEN_FORMAT "S16_LE" + #define SCO_TALK_RATE 44100 #define SCO_TALK_FORMAT "S16_LE" @@ -373,12 +375,14 @@ fail: static json_object* halBlueAlsaListenCapture( const char * listenCaptureS, json_object * pcmplugParamsJ, + json_object * captureParamsJ, json_object * sourceJ) { json_object * captureJ = json_object_new_object(); json_object_object_add(captureJ, "uid", json_object_new_string(listenCaptureS)); json_object_object_add(captureJ, "pcmplug_params", pcmplugParamsJ); + json_object_object_add(captureJ, "params", captureParamsJ); json_object_object_add(captureJ, "source", sourceJ); return captureJ; @@ -400,11 +404,20 @@ static json_object * halBlueAlsaTalkPlayback( return playbackJ; } -static json_object * halBlueAlsaScoTalkParamsJ() { +static json_object * halBlueAlsaScoTalkParamsJ(uint32_t sampling) { json_object * paramsJ = json_object_new_object(); - json_object_object_add(paramsJ, "rate", json_object_new_int(SCO_TALK_RATE)); + json_object_object_add(paramsJ, "rate", json_object_new_int(sampling)); json_object_object_add(paramsJ, "format", json_object_new_string(SCO_TALK_FORMAT)); + json_object_object_add(paramsJ, "channels", json_object_new_int(1)); + return paramsJ; +} + +static json_object * halBlueAlsaListenParamsJ(uint32_t sampling) { + json_object * paramsJ = json_object_new_object(); + + json_object_object_add(paramsJ, "rate", json_object_new_int(sampling)); + json_object_object_add(paramsJ, "format", json_object_new_string(A2DP_LISTEN_FORMAT)); return paramsJ; } @@ -447,6 +460,7 @@ static int halBlueAlsaAttachTransportStreams(bluealsa_transport_t * transport) { json_object* playbackJ = NULL; json_object* pcmplugParamsJ, *pcmplugParamsJ2 = NULL; + json_object* captureParamsJ; json_object* streamsJ = NULL; json_object* streamJ = NULL; @@ -502,13 +516,15 @@ static int halBlueAlsaAttachTransportStreams(bluealsa_transport_t * transport) { else json_object_object_add(sourceJ, "channels", halBlueAlsaSCOTransportChannels(transportTypeS)); - json_object_object_add(requestJ, "captures", halBlueAlsaListenCapture(captureS, pcmplugParamsJ, sourceJ)); + captureParamsJ = halBlueAlsaListenParamsJ(ba_transport->sampling); + + json_object_object_add(requestJ, "captures", halBlueAlsaListenCapture(captureS, pcmplugParamsJ, captureParamsJ, sourceJ)); if (ba_transport->type & BA_PCM_TYPE_SCO) { playbackJ = json_object_new_object(); // that is a shame that deep copy in not available in the current json-c version pcmplugParamsJ2 = halBlueAlsaPcmPlugParams(watch->interface, addr, transportTypeS); - json_object * paramsJ = halBlueAlsaScoTalkParamsJ(); + json_object * paramsJ = halBlueAlsaScoTalkParamsJ(ba_transport->sampling); json_object_object_add(playbackJ, "channels", halBlueAlsaSCOTransportChannels(transportTypeS)); json_object_object_add(requestJ, "playbacks", halBlueAlsaTalkPlayback(playbackS, pcmplugParamsJ2, paramsJ, playbackJ)); @@ -541,7 +557,7 @@ static int halBlueAlsaAttachTransportStreams(bluealsa_transport_t * transport) { json_object_array_add(streamsJ, streamJ); - /* In case of SCO, to have full-duplex, we instantiate a stream for talk */ + /* In case of SCO, to have full-duplex, we instantiate a stream for 'talk' */ if (ba_transport->type & BA_PCM_TYPE_SCO ) { streamJ = json_object_new_object(); @@ -630,7 +646,7 @@ static int halBlueAlsaFetchTransports(bluealsa_watch * watch) { else typeS = "unknown"; - AFB_API_DEBUG(plugin->api, "Transport %d: type %s (%x), dev %s", ix, typeS, ba_transport->type, addr); + AFB_API_DEBUG(plugin->api, "Transport %d: type %s (%x), dev %s, codec %d", ix, typeS, ba_transport->type, addr, ba_transport->codec); if (BA_PCM_TYPE(ba_transport->type) == BA_PCM_TYPE_SCO && ba_transport->codec == 0) { @@ -775,6 +791,11 @@ static int name_changed_cb(sd_bus_message *m, void *userdata, sd_bus_error * ret const char * signature = sd_bus_message_get_signature(m, 1); + /* simply ignore silently that spurious message */ + if (strcmp(signature,"s") == 0) { + goto done; + } + if (strcmp(signature,"sss") != 0) { AFB_API_ERROR(plugin->api, "%s: wrong message signature '%s'", __func__, signature); goto done; @@ -867,7 +888,7 @@ static int halBlueAlsaRegisterAll(CtlPluginT* plugin) { goto failed; } - AFB_API_ERROR(plugin->api, "Ask DBus for the list of services"); + AFB_API_INFO(plugin->api, "Ask DBus for the list of services"); ret = sd_bus_call_method_async(bus, &slot, -- cgit 1.2.3-korg