diff options
author | Thierry Bultel <thierry.bultel@iot.bzh> | 2018-12-04 23:11:20 +0100 |
---|---|---|
committer | Thierry Bultel <thierry.bultel@iot.bzh> | 2018-12-19 23:09:21 +0100 |
commit | e0f57e523112e1bc73a04e8615d7a21355f0ce0e (patch) | |
tree | 19198c38d7433862cee733fde3efca8170228279 /plugins/alsa/alsa-api-ramp.c | |
parent | 7df040a3742af8d800852dd39f8e921cd82a4cf2 (diff) |
Add support for bluetooth telephonyguppy_6.99.3guppy/6.99.36.99.3
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 <thierry.bultel@iot.bzh>
Diffstat (limited to 'plugins/alsa/alsa-api-ramp.c')
-rw-r--r-- | plugins/alsa/alsa-api-ramp.c | 86 |
1 files changed, 55 insertions, 31 deletions
diff --git a/plugins/alsa/alsa-api-ramp.c b/plugins/alsa/alsa-api-ramp.c index 21ec165..060c917 100644 --- a/plugins/alsa/alsa-api-ramp.c +++ b/plugins/alsa/alsa-api-ramp.c @@ -28,20 +28,22 @@ PUBLIC AlsaVolRampT *ApiRampGetByUid(SoftMixerT *mixer, const char *uid) { AlsaVolRampT *ramp = NULL; - - // Loop on every Register zone pcm and extract (cardid) from (uid) - for (int idx = 0; mixer->ramps[idx]->uid != NULL; idx++) { - if (!strcasecmp(mixer->ramps[idx]->uid, uid)) { - ramp = mixer->ramps[idx]; - return ramp; - } + cds_list_for_each_entry(ramp, &mixer->ramps.list, list) { + if (!strcasecmp(ramp->uid, uid)) + return ramp; } return NULL; } STATIC AlsaVolRampT *AttachOneRamp(SoftMixerT *mixer, const char *uid, json_object *rampJ) { - const char*rampUid; + const char * rampUid; AlsaVolRampT *ramp = calloc(1, sizeof (AlsaVolRampT)); + if (ramp == NULL) { + SOFTMIXER_NOMEM(mixer->api); + goto fail; + } + + CDS_INIT_LIST_HEAD(&ramp->list); int error = wrap_json_unpack(rampJ, "{ss,si,si,si !}" , "uid", &rampUid @@ -50,65 +52,87 @@ STATIC AlsaVolRampT *AttachOneRamp(SoftMixerT *mixer, const char *uid, json_obje , "down", &ramp->stepDown ); if (error) { - AFB_ApiError(mixer->api, "AttachOneRamp mixer=%s hal=%s error=%s json=%s", mixer->uid, uid, wrap_json_get_error_string(error), json_object_get_string(rampJ)); - goto OnErrorExit; + AFB_ApiError(mixer->api, + "%s mixer=%s hal=%s error=%s json=%s", + __func__, mixer->uid, uid, wrap_json_get_error_string(error), json_object_get_string(rampJ)); + goto fail_ramp; } ramp->delay = ramp->delay * 1000; // move from ms to us ramp->uid = strdup(rampUid); + if (ramp->uid == NULL) { + SOFTMIXER_NOMEM(mixer->api); + goto fail_ramp; + } + return ramp; -OnErrorExit: +fail_ramp: free(ramp); +fail: return NULL; } -PUBLIC int ApiRampAttach(SoftMixerT *mixer, AFB_ReqT request, const char *uid, json_object *argsJ) { - int index; - for (index = 0; index < mixer->max.ramps; index++) { - if (!mixer->ramps[index]) break; - } +static void rampDestroy(SoftMixerT * mixer, void * arg) { + AlsaVolRampT * ramp = (AlsaVolRampT*) arg; + AFB_ApiDebug(mixer->api, "%s... %s not implemented", __func__, ramp->uid); +} - if (index == mixer->max.ramps) { - AFB_ReqFailF(request, "too-small", "mixer=%s hal=%s max ramp=%d", mixer->uid, uid, mixer->max.ramps); - goto OnErrorExit; +static AlsaVolRampT * rampCreate(SoftMixerT * mixer, const char * uid, json_object *argsJ) { + AlsaVolRampT * newRamp = AttachOneRamp(mixer, uid, argsJ); + if (!newRamp) { + goto fail; + } + mixer->nbRamps++; + cds_list_add_tail(&newRamp->list, &mixer->ramps.list); + AlsaMixerTransactionObjectAdd(mixer->transaction, newRamp, rampDestroy); +fail: + return newRamp; +} + +PUBLIC int ApiRampAttach(SoftMixerT *mixer, AFB_ReqT request, const char * uid, json_object *argsJ) { + + if (mixer->nbRamps >= mixer->max.ramps) { + AFB_ReqFailF(request, "too-small", "mixer=%s hal=%s max ramp=%d", mixer->uid, uid, mixer->max.ramps); + goto fail; } + AlsaVolRampT * newRamp = NULL; + switch (json_object_get_type(argsJ)) { long count; case json_type_object: - mixer->ramps[index] = AttachOneRamp(mixer, uid, argsJ); - if (!mixer->ramps[index]) { + newRamp = rampCreate(mixer, uid, argsJ); + if (!newRamp) { AFB_ReqFailF(request, "bad-ramp", "mixer=%s hal=%s invalid ramp= %s", mixer->uid, 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.ramps - index)) { + if (count > (mixer->max.ramps - mixer->nbRamps)) { AFB_ReqFailF(request, "too-small", "mixer=%s hal=%s max ramp=%d", mixer->uid, uid, mixer->max.ramps); - goto OnErrorExit; - + goto fail; } for (int idx = 0; idx < count; idx++) { json_object *streamAudioJ = json_object_array_get_idx(argsJ, idx); - mixer->ramps[index + idx] = AttachOneRamp(mixer, uid, streamAudioJ); - if (!mixer->ramps[index + idx]) { - AFB_ReqFailF(request, "bad-ramp", "mixer=%s hal=%s invalid ramp= %s", mixer->uid, uid, json_object_get_string(streamAudioJ)); - goto OnErrorExit; + newRamp = rampCreate(mixer, uid, streamAudioJ); + if (!newRamp) { + AFB_ReqFailF(request, "bad-ramp", "mixer=%s hal=%s invalid ramp= %s", mixer->uid, uid, json_object_get_string(argsJ)); + goto fail; } } break; default: AFB_ReqFailF(request, "invalid-syntax", "mixer=%s hal=%s ramps invalid argsJ= %s", mixer->uid, uid, json_object_get_string(argsJ)); - goto OnErrorExit; + goto fail; } return 0; -OnErrorExit: +fail: return -1; } |