diff options
author | Thierry Bultel <thierry.bultel@iot.bzh> | 2019-05-13 14:26:49 +0200 |
---|---|---|
committer | Thierry Bultel <thierry.bultel@iot.bzh> | 2019-05-14 15:11:31 +0200 |
commit | d47f47e7a8dd685c44506e3b37e11b017744261f (patch) | |
tree | 631ce3c7175c52026cf1d9f6ede6db847c2b7380 | |
parent | 2d4da5da14a328fa04ebddad33750c033523c383 (diff) | |
parent | 33fb9656b6d72f32ddf0d04db5c3edab57faa308 (diff) |
Merge branch 'sandbox/tbultel/spec-2387' into guppyguppy_7.0.4guppy_7.0.3guppy_7.0.2guppy/7.0.4guppy/7.0.3guppy/7.0.27.0.47.0.37.0.2guppy
Bug AGL: SPEC-2387
This cherry-picks the following commits from master:
* 33fb965 .gitignore: added wildcard for build directory
* 43efc33 bluealsa plugin: do not do anything when the HAL is not ready
* db4eeea bluealsa plugin: get the sampling rate from the transport
Change-Id: I35c46c3adbd39fcabc6b616ad3c7456d088f0028
Signed-off-by: Thierry Bultel <thierry.bultel@iot.bzh>
-rw-r--r-- | .gitignore | 2 | ||||
-rw-r--r-- | plugins/lib/bluealsa/hal-bluealsa-transports.c | 6 | ||||
-rw-r--r-- | plugins/lib/bluealsa/hal-bluealsa.c | 63 |
3 files changed, 54 insertions, 17 deletions
@@ -8,7 +8,7 @@ *.vcxproj *.user obj -build +build* bin docs_doxygen node_modules/ 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..415b160 100644 --- a/plugins/lib/bluealsa/hal-bluealsa.c +++ b/plugins/lib/bluealsa/hal-bluealsa.c @@ -29,9 +29,12 @@ #include <urcu/list.h> #include "hal-bluealsa.h" +#include "4a-hal-utilities-data.h" #define HAL_BLUEALSA_PLUGIN_NAME "hal-bluealsa" +#define A2DP_LISTEN_FORMAT "S16_LE" + #define SCO_TALK_RATE 44100 #define SCO_TALK_FORMAT "S16_LE" @@ -65,17 +68,29 @@ CTLP_INIT(plugin, callbacks) { json_object *actionsToAdd = NULL; CtlConfigT *ctrlConfig; - - wrap_json_pack(&actionsToAdd, "{s:s s:s s:s}", - "uid", "init-bluealsa-plugin", - "info", "Init Bluez-Alsa hal plugin", - "action", "plugin://hal-bluealsa#init"); + struct SpecificHalData *currentHalData; if (!(ctrlConfig = (CtlConfigT *) afb_api_get_userdata(plugin->api))) { AFB_API_ERROR(plugin->api, "Can't get current hal controller config"); goto fail; } + if (!(currentHalData = (struct SpecificHalData *) ctrlConfig->external)) { + AFB_API_ERROR(plugin->api, "Can't get current hal controller data"); + goto fail; + } + + if (currentHalData->status != HAL_STATUS_AVAILABLE) { + AFB_API_WARNING(plugin->api, + "Controller initialization of %s plugin cannot be done because hal is not ready to be used", HAL_BLUEALSA_PLUGIN_NAME); + goto done; + } + + wrap_json_pack(&actionsToAdd, "{s:s s:s s:s}", + "uid", "init-bluealsa-plugin", + "info", "Init Bluez-Alsa hal plugin", + "action", "plugin://hal-bluealsa#init"); + int idx = 0; while (ctrlConfig->sections[idx].key && strcasecmp(ctrlConfig->sections[idx].key, "onload")) idx++; @@ -91,10 +106,11 @@ CTLP_INIT(plugin, callbacks) } AFB_API_NOTICE(plugin->api, "Plugin initialization of %s plugin correctly done", HAL_BLUEALSA_PLUGIN_NAME); - +done: return 0; fail: - json_object_put(actionsToAdd); + if (actionsToAdd) + json_object_put(actionsToAdd); return -1; } @@ -373,12 +389,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 +418,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 +474,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 +530,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 +571,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 +660,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 +805,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 +902,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, |