From e0f57e523112e1bc73a04e8615d7a21355f0ce0e Mon Sep 17 00:00:00 2001 From: Thierry Bultel Date: Tue, 4 Dec 2018 23:11:20 +0100 Subject: Add support for bluetooth telephony This adds support for bluetooth telephony. A big rework in the softmixer internals has been mandatory, in order to support dynamic streams creation and deletions. Bluetooth telephony relies on the recent evolutions of bluez-alsa, the most important one being the support of HFP over Ofono. The softmixer opens PCM ioplugs provided by bluez-alsa. Bluetooth SCO needs 2 streams, one for listening and the other for talking. These streams are created upon requests sent by the hal-manager. The hal manager subscribes for bluez-alsa events and request the list of availalble transports. For each "attach" transaction verb, the softmixer maintains a list of the all created objects (sources, sinks, zones, ramps, streams, and more) Additionnally, it creates a new verb when the attach succeeds, that verb is typically something like "sco_XX:XX:XX:XX:XX:XX", and the only supported action at the present time is {"action":"remove"}, that performs all the cleanup of the registered objects. Change-Id: I1b119e6c079e60daf771e63c083a1ef33a39f379 Signed-off-by: Thierry Bultel --- plugins/alsa/alsa-api-source.c | 74 ++++++++++++++++++++++++++++-------------- 1 file changed, 50 insertions(+), 24 deletions(-) (limited to 'plugins/alsa/alsa-api-source.c') diff --git a/plugins/alsa/alsa-api-source.c b/plugins/alsa/alsa-api-source.c index 4f356b2..d227eab 100644 --- a/plugins/alsa/alsa-api-source.c +++ b/plugins/alsa/alsa-api-source.c @@ -23,62 +23,88 @@ PUBLIC AlsaSndCtlT *ApiSourceFindSubdev(SoftMixerT *mixer, const char *target) { - // search for subdev into every registered source - for (int idx = 0; mixer->sources[idx]; idx++) { - if (mixer->sources[idx]->uid && !strcasecmp(mixer->sources[idx]->uid, target)) { - return mixer->sources[idx]->sndcard; - } - } + // search for subdev into every registered source in the mixer + + AlsaSndPcmT * source; + cds_list_for_each_entry(source, &mixer->sources.list, list) { + if (source->uid && !strcmp(source->uid, target)) + return source->sndcard; + } + return NULL; } -PUBLIC int ApiSourceAttach(SoftMixerT *mixer, AFB_ReqT request, const char *uid, json_object * argsJ) { +static void sourceDestroy(SoftMixerT* mixer, void * arg) { + AlsaSndPcmT * source = (AlsaSndPcmT*) arg; + AFB_ApiDebug(mixer->api, "%s... %s", __func__, source->uid); - int index; - for (index = 0; index < mixer->max.sources; index++) { - if (!mixer->sources[index]) break; - } + cds_list_del(&source->list); + mixer->nbSources--; + ApiPcmDelete(mixer, source); + + AFB_ApiDebug(mixer->api, "%s... DONE", __func__); +} + +static AlsaSndPcmT * sourceCreate(SoftMixerT* mixer, const char * uid, json_object * argsJ) { + AlsaSndPcmT * newSource = NULL; + newSource = ApiPcmAttachOne(mixer, uid, SND_PCM_STREAM_CAPTURE, argsJ); + if (!newSource) { + goto fail; + } + + mixer->nbSources++; + cds_list_add(&newSource->list, &mixer->sources.list); + AlsaMixerTransactionObjectAdd(mixer->transaction, newSource, sourceDestroy); - if (index == mixer->max.sources) { +fail: + return newSource; +} + +PUBLIC int ApiSourceAttach(SoftMixerT *mixer, AFB_ReqT request, const char * uid, json_object * argsJ) { + + if (mixer->nbSources >= mixer->max.sources) { AFB_ReqFailF(request, "too-small", "mixer=%s max source=%d", mixer->uid, mixer->max.sources); - goto OnErrorExit; + goto fail; } + AlsaSndPcmT * newSource = NULL; + switch (json_object_get_type(argsJ)) { long count; case json_type_object: - mixer->sources[index] = ApiPcmAttachOne(mixer, uid, SND_PCM_STREAM_CAPTURE, argsJ); - if (!mixer->sources[index]) { + newSource = sourceCreate(mixer, uid, argsJ); + if (!newSource) { AFB_ReqFailF(request, "bad-pcm", "mixer=%s invalid source= %s", mixer->uid, json_object_get_string(argsJ)); - goto OnErrorExit; + goto fail; } + break; case json_type_array: count = json_object_array_length(argsJ); - if (count > (mixer->max.sources - index)) { + if (count > (mixer->max.sources - mixer->nbSources)) { AFB_ReqFailF(request, "too-small", "mixer=%s max source=%d", mixer->uid, mixer->max.sources); - goto OnErrorExit; - + goto fail; } for (int idx = 0; idx < count; idx++) { json_object *sourceJ = json_object_array_get_idx(argsJ, idx); - mixer->sources[index + idx] = ApiPcmAttachOne(mixer, uid, SND_PCM_STREAM_CAPTURE, sourceJ); - if (!mixer->sources[index + idx]) { + newSource = sourceCreate(mixer, uid, sourceJ); + if (!newSource) { AFB_ReqFailF(request, "bad-pcm", "mixer=%s invalid source= %s", mixer->uid, json_object_get_string(sourceJ)); - goto OnErrorExit; + goto fail; } } + break; default: AFB_ReqFailF(request, "invalid-syntax", "mixer=%s sources invalid argsJ= %s", mixer->uid, json_object_get_string(argsJ)); - goto OnErrorExit; + goto fail; } return 0; -OnErrorExit: +fail: return -1; } -- cgit 1.2.3-korg