diff options
author | Fulup Ar Foll <fulup@iot.bzh> | 2018-06-04 00:33:34 +0200 |
---|---|---|
committer | Fulup Ar Foll <fulup@iot.bzh> | 2018-06-04 00:33:34 +0200 |
commit | bbaf42c6b02ca5d1bdceb7e215807abdbf8cd61d (patch) | |
tree | 48368647ddfa11483d72a9a577cfa0a11f575d93 /plugins/alsa/alsa-api-source.c | |
parent | 2af80583a462fa0f71d0250bca03db5a4cf22fe8 (diff) |
Move to Dynamic Mixer API (work in progress)
Diffstat (limited to 'plugins/alsa/alsa-api-source.c')
-rw-r--r-- | plugins/alsa/alsa-api-source.c | 84 |
1 files changed, 84 insertions, 0 deletions
diff --git a/plugins/alsa/alsa-api-source.c b/plugins/alsa/alsa-api-source.c new file mode 100644 index 0000000..6315a14 --- /dev/null +++ b/plugins/alsa/alsa-api-source.c @@ -0,0 +1,84 @@ +/* + * Copyright (C) 2018 "IoT.bzh" + * Author Fulup Ar Foll <fulup@iot.bzh> + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ + +#define _GNU_SOURCE // needed for vasprintf + +#include "alsa-softmixer.h" +#include <string.h> + +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; + } + } + return NULL; +} + +PUBLIC int ApiSourceAttach(SoftMixerT *mixer, AFB_ReqT request, const char *uid, json_object * argsJ) { + + int index; + for (index = 0; index < mixer->max.sources; index++) { + if (!mixer->sources[index]) break; + } + + if (index == mixer->max.sources) { + AFB_ReqFailF(request, "too-small", "mixer=%s max source=%d argsJ= %s", mixer->uid, mixer->max.sources, json_object_get_string(argsJ)); + goto OnErrorExit; + } + + 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]) { + AFB_ReqFailF(request, "invalid-syntax", "mixer=%s invalid source= %s", mixer->uid, json_object_get_string(argsJ)); + goto OnErrorExit; + } + break; + + case json_type_array: + count = json_object_array_length(argsJ); + if (count > (mixer->max.sources - count)) { + AFB_ReqFailF(request, "too-small", "mixer=%s max source=%d argsJ= %s", mixer->uid, mixer->max.sources, json_object_get_string(argsJ)); + goto OnErrorExit; + + } + + 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]) { + AFB_ReqFailF(request, "invalid-syntax", "mixer=%s invalid source= %s", mixer->uid, json_object_get_string(sourceJ)); + goto OnErrorExit; + } + } + break; + default: + AFB_ReqFailF(request, "invalid-syntax", "mixer=%s sources invalid argsJ= %s", mixer->uid, json_object_get_string(argsJ)); + goto OnErrorExit; + } + + return 0; + +OnErrorExit: + return -1; +}
\ No newline at end of file |