aboutsummaryrefslogtreecommitdiffstats
path: root/plugins/alsa/alsa-api-ramp.c
diff options
context:
space:
mode:
Diffstat (limited to 'plugins/alsa/alsa-api-ramp.c')
-rw-r--r--plugins/alsa/alsa-api-ramp.c86
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;
}