summaryrefslogtreecommitdiffstats
path: root/plugins
diff options
context:
space:
mode:
authorJonathan Aillet <jonathan.aillet@iot.bzh>2018-09-19 12:23:59 +0200
committerJonathan Aillet <jonathan.aillet@iot.bzh>2018-10-08 15:57:27 +0200
commit04bb36a2bf5eac8d605c9e63b5cc9c1cf79be905 (patch)
treecd1bb95ecc7afadcbfa892312cf2701e7f958be0 /plugins
parente1b9634b554d91012edef2a564a9dcfb25cae503 (diff)
hal-bt: Enrich 'halmixer' section in plugin init
Enrich 'halmixer' section with bluetooth specific 'source' and 'stream' during hal-bt plugin initialization. Some parameters must be passed to plugin using 'params' key in controller json plugin section. This allows to get rid of must of the additional configuration when using bluetooth in a hal. Change-Id: I5820e75307a3394eca80cf783e7bc4c31c2d7659 Signed-off-by: Jonathan Aillet <jonathan.aillet@iot.bzh>
Diffstat (limited to 'plugins')
-rw-r--r--plugins/lib/bluetooth/hal-bt-mixer-link.h33
-rw-r--r--plugins/lib/bluetooth/hal-bt.c79
2 files changed, 105 insertions, 7 deletions
diff --git a/plugins/lib/bluetooth/hal-bt-mixer-link.h b/plugins/lib/bluetooth/hal-bt-mixer-link.h
index a1a3ef6..6fc90f6 100644
--- a/plugins/lib/bluetooth/hal-bt-mixer-link.h
+++ b/plugins/lib/bluetooth/hal-bt-mixer-link.h
@@ -26,6 +26,39 @@
#define MIXER_SET_STREAMED_BT_DEVICE_VERB "bluezalsa_dev"
+#define MIXER_BT_CAPTURE_JSON_SECTION "\
+{\
+ \"uid\": \"bluetooth\",\
+ \"pcmplug_params\": \"bluealsa_proxy\",\
+ \"source\": {\
+ \"channels\": [\
+ {\
+ \"uid\": \"bluetooth-right\",\
+ \"port\": 0\
+ },\
+ {\
+ \"uid\": \"bluetooth-left\",\
+ \"port\": 1\
+ }\
+ ]\
+ }\
+}\
+"
+#define MIXER_BT_STREAM_JSON_SECTION "\
+{\
+ \"uid\": \"bluetooth_stream\",\
+ \"verb\": \"bluetooth_stream\",\
+ \"source\" : \"bluetooth\",\
+ \"volume\": 80,\
+ \"mute\": false,\
+ \"params\": {\
+ \"rate\" : 48000,\
+ \"format\": \"S16_LE\",\
+ \"channels\": 2\
+ }\
+}\
+"
+
// HAL controllers handle mixer bt calls functions
int HalBtMixerLinkSetBtStreamingSettings(AFB_ApiT apiHandle, char *mixerApiName, unsigned int btStreamStatus, char *hci, char *btAddress);
diff --git a/plugins/lib/bluetooth/hal-bt.c b/plugins/lib/bluetooth/hal-bt.c
index bacf9d2..a145df3 100644
--- a/plugins/lib/bluetooth/hal-bt.c
+++ b/plugins/lib/bluetooth/hal-bt.c
@@ -51,13 +51,15 @@ CTLP_ONLOAD(plugin, callbacks)
CTLP_INIT(plugin, callbacks)
{
+ int btChannelsNumber;
+
unsigned int idx;
- char *returnedInfo;
+ char *btStreamZone, *returnedInfo;
CtlConfigT *ctrlConfig;
- json_object *actionsToAdd, *returnedJ;
+ json_object *actionsToAdd, *returnedJ, *halMixerJ, *halOrigCaptureJ, *halNewCaptureJ, *halOrigStreamJ, *halNewStreamJ, *btCaptureJ, *btCaptureParamsJ, *btStreamJ;
AFB_ApiInfo(plugin->api, "Plugin initialization of HAL-BT plugin");
@@ -76,6 +78,12 @@ CTLP_INIT(plugin, callbacks)
return -2;
}
+ if((! localHalBtPluginData.currentHalData->ctlHalSpecificData) ||
+ (! (halMixerJ = localHalBtPluginData.currentHalData->ctlHalSpecificData->halMixerJ))) {
+ AFB_ApiError(plugin->api, "Can't get current hal mixer json section");
+ return -3;
+ }
+
if(AFB_ServiceSync(plugin->api, BT_MANAGER_API, BT_MANAGER_GET_POWER_INFO, NULL, &returnedJ)) {
if((! wrap_json_unpack(returnedJ, "{s:{s:s}}", "request", "info", &returnedInfo)) &&
(! strncmp(returnedInfo, "Unable to get power status", strlen(returnedInfo)))) {
@@ -91,10 +99,16 @@ CTLP_INIT(plugin, callbacks)
BT_MANAGER_GET_POWER_INFO,
BT_MANAGER_API,
json_object_get_string(returnedJ));
- return -3;
+ return -4;
}
}
+ if((! json_object_is_type(plugin->paramsJ, json_type_object)) ||
+ (wrap_json_unpack(plugin->paramsJ, "{s:i, s:s}", "channels", &btChannelsNumber, "zone", &btStreamZone))) {
+ AFB_ApiError(plugin->api, "Can't get HAL-BT plugin parameters from json ('%s')", json_object_get_string(plugin->paramsJ));
+ return -5;
+ }
+
wrap_json_pack(&actionsToAdd, "{s:s s:s}",
"uid", "Bluetooth-Manager/device_updated",
"action", "plugin://hal-bt#events");
@@ -106,13 +120,13 @@ CTLP_INIT(plugin, callbacks)
if(! ctrlConfig->sections[idx].key) {
AFB_ApiError(plugin->api, "Wasn't able to add '%s' as a new event, 'events' section not found", json_object_get_string(actionsToAdd));
json_object_put(actionsToAdd);
- return -4;
+ return -6;
}
if(AddActionsToSectionFromPlugin(plugin->api, *ctrlConfig->ctlPlugins, &ctrlConfig->sections[idx], actionsToAdd, 0)) {
AFB_ApiError(plugin->api, "Wasn't able to add '%s' as a new event to %s", json_object_get_string(actionsToAdd), ctrlConfig->sections[idx].key);
json_object_put(actionsToAdd);
- return -5;
+ return -7;
}
wrap_json_pack(&actionsToAdd, "{s:s s:s s:s}",
@@ -127,13 +141,64 @@ CTLP_INIT(plugin, callbacks)
if(! ctrlConfig->sections[idx].key) {
AFB_ApiError(plugin->api, "Wasn't able to add '%s' as a new onload, 'onload' section not found", json_object_get_string(actionsToAdd));
json_object_put(actionsToAdd);
- return -6;
+ return -8;
}
if(AddActionsToSectionFromPlugin(plugin->api, *ctrlConfig->ctlPlugins, &ctrlConfig->sections[idx], actionsToAdd, 0)) {
AFB_ApiError(plugin->api, "Wasn't able to add '%s' as a new onload to %s", json_object_get_string(actionsToAdd), ctrlConfig->sections[idx].uid);
json_object_put(actionsToAdd);
- return -7;
+ return -9;
+ }
+
+ btCaptureJ = json_tokener_parse(MIXER_BT_CAPTURE_JSON_SECTION);
+ wrap_json_pack(&btCaptureParamsJ, "{s:i}", "channels", btChannelsNumber);
+ json_object_object_add(btCaptureJ, "params", btCaptureParamsJ);
+
+ if(! json_object_object_get_ex(halMixerJ, "captures", &halOrigCaptureJ)) {
+ halNewCaptureJ = json_object_new_array();
+ json_object_array_add(halNewCaptureJ, btCaptureJ);
+ json_object_object_add(halMixerJ, "captures", halNewCaptureJ);
+ }
+ else if(json_object_is_type(halOrigCaptureJ, json_type_array)) {
+ halNewCaptureJ = halOrigCaptureJ;
+ json_object_array_add(halNewCaptureJ, btCaptureJ);
+ }
+ else if(json_object_is_type(halOrigCaptureJ, json_type_object)) {
+ json_object_get(halOrigCaptureJ);
+ json_object_object_del(halMixerJ, "captures");
+ halNewCaptureJ = json_object_new_array();
+ json_object_array_add(halNewCaptureJ, halOrigCaptureJ);
+ json_object_array_add(halNewCaptureJ, btCaptureJ);
+ json_object_object_add(halMixerJ, "captures", halNewCaptureJ);
+ }
+ else {
+ AFB_ApiError(plugin->api, "Unrecognized 'halmixer' captures format");
+ return -10;
+ }
+
+ btStreamJ = json_tokener_parse(MIXER_BT_STREAM_JSON_SECTION);
+ json_object_object_add(btStreamJ, "zone", json_object_new_string(btStreamZone));
+
+ if(! json_object_object_get_ex(halMixerJ, "streams", &halOrigStreamJ)) {
+ halNewStreamJ = json_object_new_array();
+ json_object_array_add(halNewStreamJ, btStreamJ);
+ json_object_object_add(halMixerJ, "streams", halNewStreamJ);
+ }
+ else if(json_object_is_type(halOrigStreamJ, json_type_array)) {
+ halNewStreamJ = halOrigStreamJ;
+ json_object_array_add(halNewStreamJ, btStreamJ);
+ }
+ else if(json_object_is_type(halOrigStreamJ, json_type_object)) {
+ json_object_get(halOrigStreamJ);
+ json_object_object_del(halMixerJ, "streams");
+ halNewStreamJ = json_object_new_array();
+ json_object_array_add(halNewStreamJ, halOrigStreamJ);
+ json_object_array_add(halNewStreamJ, btStreamJ);
+ json_object_object_add(halMixerJ, "streams", halNewStreamJ);
+ }
+ else {
+ AFB_ApiError(plugin->api, "Unrecognized 'halmixer' streams format");
+ return -11;
}
localHalBtPluginData.halBtPluginEnabled = 1;