summaryrefslogtreecommitdiffstats
path: root/plugins/lib
diff options
context:
space:
mode:
Diffstat (limited to 'plugins/lib')
-rw-r--r--plugins/lib/bluetooth/CMakeLists.txt1
-rw-r--r--plugins/lib/bluetooth/hal-bt-cb.c42
-rw-r--r--plugins/lib/bluetooth/hal-bt-mixer-link.c67
-rw-r--r--plugins/lib/bluetooth/hal-bt-mixer-link.h32
-rw-r--r--plugins/lib/bluetooth/hal-bt.c44
5 files changed, 168 insertions, 18 deletions
diff --git a/plugins/lib/bluetooth/CMakeLists.txt b/plugins/lib/bluetooth/CMakeLists.txt
index 5969755..ae9f5ab 100644
--- a/plugins/lib/bluetooth/CMakeLists.txt
+++ b/plugins/lib/bluetooth/CMakeLists.txt
@@ -23,6 +23,7 @@ PROJECT_TARGET_ADD(hal-bt)
hal-bt.c
hal-bt-cb.c
hal-bt-data.c
+ hal-bt-mixer-link.c
)
# Alsa Plugin properties
diff --git a/plugins/lib/bluetooth/hal-bt-cb.c b/plugins/lib/bluetooth/hal-bt-cb.c
index f57f7ac..731f4d8 100644
--- a/plugins/lib/bluetooth/hal-bt-cb.c
+++ b/plugins/lib/bluetooth/hal-bt-cb.c
@@ -26,6 +26,7 @@
#include <ctl-plugin.h>
#include "hal-bt-data.h"
+#include "hal-bt-mixer-link.h"
/*******************************************************************************
* HAL Bluetooth plugin verbs functions *
@@ -51,6 +52,8 @@ void HalBtSetStreamingStatus(AFB_ReqT request)
json_object *requestJson;
+ AFB_ApiT apiHandle;
+
if(! (localHalBtPluginData = (struct HalBtPluginData *) afb_request_get_vcbdata(request))) {
AFB_ReqFail(request, "bt_plugin_data", "Can't get bluetooth plugin data");
return;
@@ -61,6 +64,11 @@ void HalBtSetStreamingStatus(AFB_ReqT request)
return;
}
+ if(! (apiHandle = (AFB_ApiT ) afb_request_get_dynapi(request))) {
+ AFB_ReqFail(request, "api_handle", "Can't get current hal controller api handle");
+ return;
+ }
+
if(wrap_json_unpack(requestJson, "{s:b}", "status", &requestedBtStreamingStatus)) {
AFB_ReqFail(request, "requested_status", "Can't get requested bluetooth streaming status");
return;
@@ -68,7 +76,18 @@ void HalBtSetStreamingStatus(AFB_ReqT request)
localHalBtPluginData->btStreamEnabled = requestedBtStreamingStatus;
- // TODO JAI : Enable capture stream to playback using 'uid' used at 'set-capture' call
+ if(HalBtMixerLinkSetBtStreamingSettings(apiHandle,
+ localHalBtPluginData->currentHalData->ctlHalSpecificData->mixerApiName,
+ localHalBtPluginData->btStreamEnabled,
+ localHalBtPluginData->selectedBtDevice ? localHalBtPluginData->selectedBtDevice->hci : NULL,
+ localHalBtPluginData->selectedBtDevice ? localHalBtPluginData->selectedBtDevice->address : NULL)) {
+ AFB_ApiError(apiHandle,
+ "Couldn't set bluetooth streaming settings during call to verb '%s' of api '%s'",
+ MIXER_SET_STREAMED_BT_DEVICE_VERB,
+ localHalBtPluginData->currentHalData->ctlHalSpecificData->mixerApiName);
+ AFB_ReqFail(request, "requested_device_to_select", "Error happened during set of streamed bt device");
+ return;
+ }
AFB_ReqSuccess(request, NULL, "Bluetooth streaming status successfully set");
}
@@ -146,6 +165,8 @@ void HalBtSetSelectedBluetoothDevice(AFB_ReqT request)
json_object *requestJson;
+ AFB_ApiT apiHandle;
+
if(! (localHalBtPluginData = (struct HalBtPluginData *) afb_request_get_vcbdata(request))) {
AFB_ReqFail(request, "bt_plugin_data", "Can't get bluetooth plugin data");
return;
@@ -156,6 +177,11 @@ void HalBtSetSelectedBluetoothDevice(AFB_ReqT request)
return;
}
+ if(! (apiHandle = (AFB_ApiT ) afb_request_get_dynapi(request))) {
+ AFB_ReqFail(request, "api_handle", "Can't get current hal controller api handle");
+ return;
+ }
+
if(wrap_json_unpack(requestJson, "{s:s}", "Address", &requestedBtDeviceToSelect)) {
AFB_ReqFail(request, "requested_device_to_select", "Can't get requested bluetooth device to select");
return;
@@ -173,8 +199,18 @@ void HalBtSetSelectedBluetoothDevice(AFB_ReqT request)
localHalBtPluginData->selectedBtDevice = selectedBtDeviceData;
- // TODO JAI : Tell the softmixer that we want it as an input using 'bluealsa:HCI=hci0,DEV=F6:32:15:2A:80:70,PROFILE=a2dp'
- // string as capture associated with an 'uid' using smixer verb 'set-capture'
+ if(HalBtMixerLinkSetBtStreamingSettings(apiHandle,
+ localHalBtPluginData->currentHalData->ctlHalSpecificData->mixerApiName,
+ localHalBtPluginData->btStreamEnabled,
+ localHalBtPluginData->selectedBtDevice->hci,
+ localHalBtPluginData->selectedBtDevice->address)) {
+ AFB_ApiError(apiHandle,
+ "Couldn't set bluetooth streaming settings during call to verb '%s' of api '%s'",
+ MIXER_SET_STREAMED_BT_DEVICE_VERB,
+ localHalBtPluginData->currentHalData->ctlHalSpecificData->mixerApiName);
+ AFB_ReqFail(request, "requested_device_to_select", "Error happened during set of streamed bt device");
+ return;
+ }
AFB_ReqSuccess(request, NULL, "Selected bluetooth device successfully set");
} \ No newline at end of file
diff --git a/plugins/lib/bluetooth/hal-bt-mixer-link.c b/plugins/lib/bluetooth/hal-bt-mixer-link.c
new file mode 100644
index 0000000..2c46fb4
--- /dev/null
+++ b/plugins/lib/bluetooth/hal-bt-mixer-link.c
@@ -0,0 +1,67 @@
+/*
+ * Copyright (C) 2018 "IoT.bzh"
+ * Author Jonathan Aillet <jonathan.aillet@iot.bzh>
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#define _GNU_SOURCE
+
+#include <stdio.h>
+#include <string.h>
+#include <stdbool.h>
+
+#include <wrap-json.h>
+
+#include <ctl-plugin.h>
+
+#include "hal-bt-mixer-link.h"
+
+/*******************************************************************************
+ * HAL controllers handle mixer bt calls functions *
+ ******************************************************************************/
+
+int HalBtMixerLinkSetBtStreamingSettings(AFB_ApiT apiHandle, char *mixerApiName, unsigned int btStreamStatus, char *hci, char *btAddress)
+{
+ char *returnedError = NULL;
+
+ json_object *toSendJ, *returnedJ;
+
+ if(! apiHandle || ! mixerApiName)
+ return -1;
+
+ if(! btStreamStatus)
+ toSendJ = NULL;
+ else if(btStreamStatus == 1 && hci && btAddress)
+ wrap_json_pack(&toSendJ, "{s:s s:s s:s}", "interface", hci, "device", btAddress, "profile", "a2dp");
+ else
+ return -3;
+
+ if(AFB_ServiceSync(apiHandle, mixerApiName, MIXER_SET_STREAMED_BT_DEVICE_VERB, toSendJ, &returnedJ)) {
+ AFB_ApiError(apiHandle,
+ "Error during call to verb %s of %s api",
+ MIXER_SET_STREAMED_BT_DEVICE_VERB,
+ mixerApiName);
+ return -3;
+ }
+ else if(wrap_json_unpack(returnedJ, "{s:{s:s}}", "request", "info", &returnedError)) {
+ AFB_ApiError(apiHandle,
+ "Error '%s' happened during set bluetooth streaming settings during call to verb '%s' of api '%s'",
+ returnedError ? returnedError : "no_error_string",
+ MIXER_SET_STREAMED_BT_DEVICE_VERB,
+ mixerApiName);
+ return -4;
+ }
+
+ return 0;
+} \ No newline at end of file
diff --git a/plugins/lib/bluetooth/hal-bt-mixer-link.h b/plugins/lib/bluetooth/hal-bt-mixer-link.h
new file mode 100644
index 0000000..ae43e72
--- /dev/null
+++ b/plugins/lib/bluetooth/hal-bt-mixer-link.h
@@ -0,0 +1,32 @@
+/*
+ * Copyright (C) 2018 "IoT.bzh"
+ * Author Jonathan Aillet <jonathan.aillet@iot.bzh>
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#ifndef _HAL_BT_MIXER_LINK_INCLUDE_
+#define _HAL_BT_MIXER_LINK_INCLUDE_
+
+#include <stdio.h>
+#include <string.h>
+#include <stdbool.h>
+
+#include <ctl-plugin.h>
+
+#define MIXER_SET_STREAMED_BT_DEVICE_VERB "bluezalsa_dev"
+
+// HAL controllers handle mixer bt calls functions
+int HalBtMixerLinkSetBtStreamingSettings(AFB_ApiT apiHandle, char *mixerApiName, unsigned int btStreamStatus, char *hci, char *btAddress);
+
+#endif /* _HAL_BT_MIXER_LINK_INCLUDE_ */ \ No newline at end of file
diff --git a/plugins/lib/bluetooth/hal-bt.c b/plugins/lib/bluetooth/hal-bt.c
index bc89fe1..329cc48 100644
--- a/plugins/lib/bluetooth/hal-bt.c
+++ b/plugins/lib/bluetooth/hal-bt.c
@@ -28,6 +28,7 @@
#include "hal-bt.h"
#include "hal-bt-cb.h"
#include "hal-bt-data.h"
+#include "hal-bt-mixer-link.h"
// Local (static) Hal manager data structure
static struct HalBtPluginData localHalBtPluginData;
@@ -171,11 +172,18 @@ CTLP_CAPI(init, source, argsJ, queryJ)
if(localHalBtPluginData.selectedBtDevice) {
localHalBtPluginData.btStreamEnabled = 1;
- /* TODO JAI : send selected device to softmixer (and enable stream here for now)
- * Tell the softmixer that we want it as an input using 'bluealsa:HCI=hci0,DEV=F6:32:15:2A:80:70,PROFILE=a2dp'
- string as capture associated with an 'uid' using smixer verb 'set-capture'
- * Enable capture stream to playback using 'uid' used at 'set-capture' call
- */
+
+ if(HalBtMixerLinkSetBtStreamingSettings(source->api,
+ localHalBtPluginData.currentHalData->ctlHalSpecificData->mixerApiName,
+ localHalBtPluginData.btStreamEnabled,
+ localHalBtPluginData.selectedBtDevice->hci,
+ localHalBtPluginData.selectedBtDevice->address)) {
+ AFB_ApiError(source->api,
+ "Couldn't set bluetooth streaming settings during call to verb '%s' of api '%s'",
+ MIXER_SET_STREAMED_BT_DEVICE_VERB,
+ localHalBtPluginData.currentHalData->ctlHalSpecificData->mixerApiName);
+ return -8;
+ }
}
return 0;
@@ -191,18 +199,24 @@ CTLP_CAPI(events, source, argsJ, queryJ)
return -1;
}
- if(localHalBtPluginData.selectedBtDevice && localHalBtPluginData.selectedBtDevice != previouslySelectedBtDevice) {
+ if(localHalBtPluginData.selectedBtDevice && localHalBtPluginData.selectedBtDevice != previouslySelectedBtDevice)
localHalBtPluginData.btStreamEnabled = 1;
- /* TODO JAI : send selected device to softmixer (and enable stream here for now)
- * Tell the softmixer that we want it as an input using 'bluealsa:HCI=hci0,DEV=F6:32:15:2A:80:70,PROFILE=a2dp'
- string as capture associated with an 'uid' using smixer verb 'set-capture'
- * Enable capture stream to playback using 'uid' used at 'set-capture' call
- */
- }
- else if (! localHalBtPluginData.selectedBtDevice) {
+ else if (! localHalBtPluginData.selectedBtDevice)
localHalBtPluginData.btStreamEnabled = 0;
- // TODO JAI: Disable capture stream to playback using 'uid' used at 'set-capture' call
+ else
+ return 0;
+
+ if(HalBtMixerLinkSetBtStreamingSettings(source->api,
+ localHalBtPluginData.currentHalData->ctlHalSpecificData->mixerApiName,
+ localHalBtPluginData.btStreamEnabled,
+ localHalBtPluginData.selectedBtDevice ? localHalBtPluginData.selectedBtDevice->hci : NULL,
+ localHalBtPluginData.selectedBtDevice ? localHalBtPluginData.selectedBtDevice->address : NULL)) {
+ AFB_ApiError(source->api,
+ "Couldn't set bluetooth streaming settings during call to verb '%s' of api '%s'",
+ MIXER_SET_STREAMED_BT_DEVICE_VERB,
+ localHalBtPluginData.currentHalData->ctlHalSpecificData->mixerApiName);
+ return -2;
}
- return 0;
+ return 1;
} \ No newline at end of file