summaryrefslogtreecommitdiffstats
path: root/plugins/alsa/alsa-api-source.c
diff options
context:
space:
mode:
Diffstat (limited to 'plugins/alsa/alsa-api-source.c')
-rw-r--r--plugins/alsa/alsa-api-source.c74
1 files changed, 50 insertions, 24 deletions
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;
}