aboutsummaryrefslogtreecommitdiffstats
path: root/plugins
diff options
context:
space:
mode:
Diffstat (limited to 'plugins')
-rw-r--r--plugins/lib/bluealsa/hal-bluealsa-transports.c4
-rw-r--r--plugins/lib/bluealsa/hal-bluealsa.c313
2 files changed, 159 insertions, 158 deletions
diff --git a/plugins/lib/bluealsa/hal-bluealsa-transports.c b/plugins/lib/bluealsa/hal-bluealsa-transports.c
index b528212..341fb6b 100644
--- a/plugins/lib/bluealsa/hal-bluealsa-transports.c
+++ b/plugins/lib/bluealsa/hal-bluealsa-transports.c
@@ -107,8 +107,8 @@ int halBlueAlsaTransportUpdate(
char transportS[HAL_BLUEALSA_TRANSPORT_LEN_MAX];
AFB_API_INFO(watch->plugin->api,
- "Unregister transport %s",
- halBlueAlsaTransportAsString(transportS, HAL_BLUEALSA_TRANSPORT_LEN_MAX, &transport->transport));
+ "Unregister transport %s",
+ halBlueAlsaTransportAsString(transportS, HAL_BLUEALSA_TRANSPORT_LEN_MAX, &transport->transport));
cds_list_del(&transport->list);
if (destructor) {
diff --git a/plugins/lib/bluealsa/hal-bluealsa.c b/plugins/lib/bluealsa/hal-bluealsa.c
index 58c4b54..efce322 100644
--- a/plugins/lib/bluealsa/hal-bluealsa.c
+++ b/plugins/lib/bluealsa/hal-bluealsa.c
@@ -70,7 +70,8 @@ CTLP_INIT(plugin, callbacks)
CtlConfigT *ctrlConfig;
struct HalData *currentHalData;
- if (!(ctrlConfig = (CtlConfigT *) afb_api_get_userdata(plugin->api))) {
+ ctrlConfig = (CtlConfigT *) afb_api_get_userdata(plugin->api);
+ if (!ctrlConfig) {
AFB_API_ERROR(plugin->api, "Can't get current internal hal controller config");
goto fail;
}
@@ -83,7 +84,7 @@ CTLP_INIT(plugin, callbacks)
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);
+ "Controller initialization of %s plugin cannot be done because hal is not ready to be used", HAL_BLUEALSA_PLUGIN_NAME);
goto done;
}
@@ -127,17 +128,17 @@ CTLP_CAPI(init, source, argsJ, queryJ)
int error;
/*
- * "params": {
- "sco": {
- "mic": "2CH-GENERIC-USB",
- "zone": "full-stereo",
- "delayms": 300
- },
- "a2dp": {
- "zone": "full-stereo",
- "delayms": 1000
- }
- }
+ "params": {
+ "sco": {
+ "mic": "2CH-GENERIC-USB",
+ "zone": "full-stereo",
+ "delayms": 300
+ },
+ "a2dp": {
+ "zone": "full-stereo",
+ "delayms": 1000
+ }
+ }
*/
json_object * scoParamsJ = NULL;
@@ -184,7 +185,7 @@ CTLP_CAPI(init, source, argsJ, queryJ)
return 0;
fail:
- return -1;
+ return -1;
}
@@ -228,104 +229,100 @@ done:
*
* A2DP Case:
*
- * {
- "uid":"a2dp_F6:32:15:2A:80:70",
- "captures":
- {
- "uid":"a2dp_listen_capture",
- "pcmplug_params" : "bluealsa:HCI=hci0,DEV=F6:32:15:2A:80:70,PROFILE=a2dp",
- "source" : {
- "channels": [
- {
- "uid": "a2dp-right",
- "port": 0
- },
- {
- "uid": "a2dp-left",
- "port": 1
- }
- ]
- }
- },
- "streams":
- {
- "uid" : "a2dp_listen_stream",
- "source":"a2dp_listen_capture",
- "zone": "full-stereo"
- }
- }
+{
+ "uid":"a2dp_F6:32:15:2A:80:70",
+ "captures": {
+ "uid":"a2dp_listen_capture",
+ "pcmplug_params" : "bluealsa:HCI=hci0,DEV=F6:32:15:2A:80:70,PROFILE=a2dp",
+ "source" : {
+ "channels": [
+ {
+ "uid": "a2dp-right",
+ "port": 0
+ },
+ {
+ "uid": "a2dp-left",
+ "port": 1
+ }
+ ]
+ }
+ },
+ "streams": {
+ "uid" : "a2dp_listen_stream",
+ "source":"a2dp_listen_capture",
+ "zone": "full-stereo"
+ }
+}
*
*-----------------------------------------------------------------------------------
*
* SCO Case:
*
- * {
- "uid":"sco_F6:32:15:2A:80:70",",
- "captures":
- {
- "uid":"sco_listen_capture",
- "pcmplug_params" : "bluealsa:HCI=hci0,DEV=F6:32:15:2A:80:70,PROFILE=sco",
- "source" : {
- "channels": [
- {
- "uid": "sco-right",
- "port": 0
- },
- {
- "uid": "sco-left",
- "port": 1
- }
- ]
- }
- },
- "playbacks" :
- {
- "uid"="sco_talk_playback",
- "pcmplug_params" : "bluealsa:HCI=hci0,DEV=F6:32:15:2A:80:70,PROFILE=sco",
- "params": {
- "rate": 44100,
- "format": "S16_LE",
- },
- "sink": {
- "channels": [
- {
- "uid": "sco-mono"
- }
- ]
- }
- },
- "zones" : [
- {
- "uid": "sco_talk_zone",
- "sink": [
- {
- "target": "sco-mono",
- "channel": 0,
- "volume": 0.5
- },
- {
- "target": "sco-mono",
- "channel": 1,
- "volume": 0.5
- }
- ]
- }
- ] ,
- "streams": [
- {
- "uid" : "sco_listen_stream",
- "source":"sco_listen_capture",
- "zone": "full-stereo",
- "delayms": 300
- },
- {
- "uid" : "sco_talk_stream",
- "source": "2CH-GENERIC-USB",
- "zone": "sco_talk_zone",
- "delayms": 300
- }
- ]
- }
+{
+ "uid":"sco_F6:32:15:2A:80:70",",
+ "captures": {
+ "uid":"sco_listen_capture",
+ "pcmplug_params" : "bluealsa:HCI=hci0,DEV=F6:32:15:2A:80:70,PROFILE=sco",
+ "source" : {
+ "channels": [
+ {
+ "uid": "sco-right",
+ "port": 0
+ },
+ {
+ "uid": "sco-left",
+ "port": 1
+ }
+ ]
+ }
+ },
+ "playbacks" : {
+ "uid"="sco_talk_playback",
+ "pcmplug_params" : "bluealsa:HCI=hci0,DEV=F6:32:15:2A:80:70,PROFILE=sco",
+ "params": {
+ "rate": 44100,
+ "format": "S16_LE",
+ },
+ "sink": {
+ "channels": [
+ {
+ "uid": "sco-mono"
+ }
+ ]
+ }
+ },
+ "zones" : [
+ {
+ "uid": "sco_talk_zone",
+ "sink": [
+ {
+ "target": "sco-mono",
+ "channel": 0,
+ "volume": 0.5
+ },
+ {
+ "target": "sco-mono",
+ "channel": 1,
+ "volume": 0.5
+ }
+ ]
+ }
+ ],
+ "streams": [
+ {
+ "uid" : "sco_listen_stream",
+ "source":"sco_listen_capture",
+ "zone": "full-stereo",
+ "delayms": 300
+ },
+ {
+ "uid" : "sco_talk_stream",
+ "source": "2CH-GENERIC-USB",
+ "zone": "sco_talk_zone",
+ "delayms": 300
+ }
+ ]
+}
*
* */
@@ -566,7 +563,7 @@ static int halBlueAlsaAttachTransportStreams(bluealsa_transport_t * transport) {
json_object_object_add(streamJ, "uid", json_object_new_string(streamS));
json_object_object_add(streamJ, "source", json_object_new_string(captureS));
json_object_object_add(streamJ, "zone", json_object_new_string(playbackZoneS));
- if (delayms != 0) {
+ if (delayms) {
json_object_object_add(streamJ, "delayms", json_object_new_int(delayms));
}
@@ -582,7 +579,7 @@ static int halBlueAlsaAttachTransportStreams(bluealsa_transport_t * transport) {
json_object_object_add(streamJ, "uid", json_object_new_string(streamS));
json_object_object_add(streamJ, "source", json_object_new_string(pluginData->sco.mic));
json_object_object_add(streamJ, "zone", json_object_new_string(SCO_TALK_ZONE));
- if (delayms != 0)
+ if (delayms)
json_object_object_add(streamJ, "delayms", json_object_new_int(delayms));
json_object_array_add(streamsJ, streamJ);
}
@@ -614,7 +611,7 @@ static int halBluezAlsaRemoveTransportStream(bluealsa_transport_t * transport) {
json_object* requestJ = NULL;
AFB_API_INFO(plugin->api, "Call transaction detach verb %s", transport->transactionUidS);
- if (transport->transactionUidS == NULL)
+ if (!transport->transactionUidS)
goto fail;
requestJ = json_object_new_object();
@@ -642,7 +639,8 @@ static int halBlueAlsaFetchTransports(bluealsa_watch * watch) {
AFB_API_DEBUG(plugin->api, "Fetching available transports of interface %s", watch->interface);
- if ((nbTransports = bluealsa_get_transports(watch->fd, &transports)) == -1) {
+ nbTransports = bluealsa_get_transports(watch->fd, &transports);
+ if (nbTransports == -1) {
AFB_API_ERROR(plugin->api, "Couldn't get transports: %s", strerror(errno));
goto done;
}
@@ -676,7 +674,7 @@ static int halBlueAlsaFetchTransports(bluealsa_watch * watch) {
AFB_API_INFO(plugin->api, "Registering transport type %s, dev %s", typeS, addr);
transport = halBlueAlsaTransportsAdd(watch, transport_list, ba_transport);
- if (transport == NULL) {
+ if (!transport) {
AFB_API_ERROR(plugin->api, "Failed to register this transport");
goto done;
}
@@ -738,47 +736,49 @@ static int halBlueAlsaUnregister(CtlPluginT * plugin, const char * dbus_name) {
static int halBlueAlsaRegister(CtlPluginT* plugin, const char * dbus_name) {
int ret;
- sd_event * sdLoop;
- sd_event_source * evtsrc;
+ sd_event * sdLoop;
+ sd_event_source * evtsrc;
- const char * interface = dbus_name + strlen(BLUEZALSA_DBUS_NAME_PREFIX) +1 ;
+ const char * interface = dbus_name + strlen(BLUEZALSA_DBUS_NAME_PREFIX) +1 ;
- sdLoop = afb_api_get_event_loop(plugin->api);
+ sdLoop = afb_api_get_event_loop(plugin->api);
- enum ba_event transport_mask = BA_EVENT_TRANSPORT_ADDED |
- BA_EVENT_TRANSPORT_CHANGED |
- BA_EVENT_TRANSPORT_REMOVED;
+ enum ba_event transport_mask = BA_EVENT_TRANSPORT_ADDED |
+ BA_EVENT_TRANSPORT_CHANGED |
+ BA_EVENT_TRANSPORT_REMOVED;
- bluealsa_watch * watch = (bluealsa_watch *)malloc(sizeof(bluealsa_watch));
- if (watch == NULL)
- goto fail;
+ bluealsa_watch * watch = (bluealsa_watch *)malloc(sizeof(bluealsa_watch));
+ if (!watch)
+ goto fail;
- watch->interface = strdup(interface);
- if (!watch->interface) {
- AFB_API_ERROR(plugin->api, "%s: Insufficient memory", __func__);
+ watch->interface = strdup(interface);
+ if (!watch->interface) {
+ AFB_API_ERROR(plugin->api, "%s: Insufficient memory", __func__);
goto fail;
}
- watch->plugin = plugin;
+ watch->plugin = plugin;
- if ((watch->fd = bluealsa_open(interface)) == -1) {
- AFB_API_ERROR(plugin->api, "BlueALSA connection failed: %s", strerror(errno));
- goto fail;
- }
+ watch->fd = bluealsa_open(interface);
+ if (watch->fd == -1) {
+ AFB_API_ERROR(plugin->api, "BlueALSA connection failed: %s", strerror(errno));
+ goto fail;
+ }
halBlueAlsaFetchTransports(watch);
- if (bluealsa_event_subscribe(watch->fd, transport_mask) == -1) {
- AFB_API_ERROR(plugin->api, "BlueALSA subscription failed: %s", strerror(errno));
- goto fail;
- }
+ if (bluealsa_event_subscribe(watch->fd, transport_mask) == -1) {
+ AFB_API_ERROR(plugin->api, "BlueALSA subscription failed: %s", strerror(errno));
+ goto fail;
+ }
- // Register transport change event to the main loop of the binder
- if ((ret = sd_event_add_io(sdLoop, &evtsrc, watch->fd, EPOLLIN, halBlueAlsaTransportEventCB, watch)) < 0) {
- AFB_API_ERROR(plugin->api,
- "%s: Failed to register event fd to io loop",
- __func__);
- goto fail;
- }
+ // Register transport change event to the main loop of the binder
+ ret = sd_event_add_io(sdLoop, &evtsrc, watch->fd, EPOLLIN, halBlueAlsaTransportEventCB, watch);
+ if (ret < 0) {
+ AFB_API_ERROR(plugin->api,
+ "%s: Failed to register event fd to io loop",
+ __func__);
+ goto fail;
+ }
return 0;
@@ -812,7 +812,7 @@ static int name_changed_cb(sd_bus_message *m, void *userdata, sd_bus_error * ret
}
if (strcmp(signature,"sss") != 0) {
- AFB_API_ERROR(plugin->api, "%s: wrong message signature '%s'", __func__, signature);
+ AFB_API_ERROR(plugin->api, "%s: wrong message signature '%s'", __func__, signature);
goto done;
}
@@ -821,7 +821,7 @@ static int name_changed_cb(sd_bus_message *m, void *userdata, sd_bus_error * ret
const char *owner_new;
if (sd_bus_message_read(m, "sss", &name, &owner_old, &owner_new) < 0) {
- AFB_API_ERROR(plugin->api, "%s: failed to read message parameters", __func__);
+ AFB_API_ERROR(plugin->api, "%s: failed to read message parameters", __func__);
goto done;
}
@@ -829,12 +829,12 @@ static int name_changed_cb(sd_bus_message *m, void *userdata, sd_bus_error * ret
goto done;
if (owner_old != NULL && owner_old[0] != '\0') {
- AFB_API_INFO(plugin->api, "bluez-alsa: %s disappeared", name);
+ AFB_API_INFO(plugin->api, "bluez-alsa: %s disappeared", name);
halBlueAlsaUnregister(plugin, name);
}
if (owner_new != NULL && owner_new[0] != '\0') {
- AFB_API_INFO(plugin->api, "bluez-alsa %s appeared", name);
+ AFB_API_INFO(plugin->api, "bluez-alsa %s appeared", name);
halBlueAlsaRegister(plugin, name);
}
@@ -865,8 +865,9 @@ static int sd_bus_list_message_handler (sd_bus_message *m, void *userdata, sd_bu
const char * string = NULL;
- if ( (ret = sd_bus_message_enter_container(m, SD_BUS_TYPE_ARRAY, "s")) < 0) {
- AFB_API_ERROR(plugin->api, "failed to enter container, err=%s\n", strerror(-ret));
+ ret = sd_bus_message_enter_container(m, SD_BUS_TYPE_ARRAY, "s");
+ if (ret < 0) {
+ AFB_API_ERROR(plugin->api, "failed to enter container, err=%s", strerror(-ret));
goto failed;
}
@@ -877,7 +878,7 @@ static int sd_bus_list_message_handler (sd_bus_message *m, void *userdata, sd_bu
goto done;
}
- if (ret == 0)
+ if (!ret)
break;
if (strstr(string, BLUEZALSA_DBUS_NAME_PREFIX) != 0) {
@@ -906,14 +907,14 @@ static int halBlueAlsaRegisterAll(CtlPluginT* plugin) {
AFB_API_INFO(plugin->api, "Ask DBus for the list of services");
ret = sd_bus_call_method_async(bus,
- &slot,
- ORG_FREEDESKTOP_DBUS_NAME,
- ORG_FREEDESKTOP_DBUS_PATH,
- ORG_FREEDESKTOP_DBUS_INTERFACE,
- "ListNames",
- sd_bus_list_message_handler,
- plugin,
- NULL);
+ &slot,
+ ORG_FREEDESKTOP_DBUS_NAME,
+ ORG_FREEDESKTOP_DBUS_PATH,
+ ORG_FREEDESKTOP_DBUS_INTERFACE,
+ "ListNames",
+ sd_bus_list_message_handler,
+ plugin,
+ NULL);
if (ret < 0) {
AFB_API_ERROR(plugin->api, "Unable to request service list from DBus: %s", strerror(-ret));
goto failed;