summaryrefslogtreecommitdiffstats
path: root/plugins/alsa/alsa-api-mixer.c
diff options
context:
space:
mode:
authorFulup Ar Foll <fulup@iot.bzh>2018-05-17 23:52:28 +0200
committerFulup Ar Foll <fulup@iot.bzh>2018-05-17 23:52:28 +0200
commite4d8efb814307bfeec227f72c77a4cf0bdf135bf (patch)
tree0f2d60dd85b926c44765f721583996178c5e124a /plugins/alsa/alsa-api-mixer.c
parent253df14bd84f535a54f4d12c95399899e1343c20 (diff)
Implemented sub API for stream with volume/pause/toggle/...
Diffstat (limited to 'plugins/alsa/alsa-api-mixer.c')
-rw-r--r--plugins/alsa/alsa-api-mixer.c60
1 files changed, 56 insertions, 4 deletions
diff --git a/plugins/alsa/alsa-api-mixer.c b/plugins/alsa/alsa-api-mixer.c
index f1619c2..31854b0 100644
--- a/plugins/alsa/alsa-api-mixer.c
+++ b/plugins/alsa/alsa-api-mixer.c
@@ -27,9 +27,11 @@ extern Lua2cWrapperT Lua2cWrap;
// API
static void MixerApiVerbCB(AFB_ReqT request) {
- json_object *responseJ, *backendJ = NULL, *frontendJ = NULL, *zonesJ = NULL, *streamsJ = NULL;
+ json_object *valueJ, *backendJ = NULL, *frontendJ = NULL, *zonesJ = NULL, *streamsJ = NULL, *listJ = NULL;
// retrieve action handle from request and execute the request
json_object *argsJ = afb_request_json(request);
+ json_object *responseJ = json_object_new_object();
+
SoftMixerHandleT *mixerHandle = (SoftMixerHandleT*) afb_request_get_vcbdata(request);
int error;
int close = 0;
@@ -40,24 +42,74 @@ static void MixerApiVerbCB(AFB_ReqT request) {
source->request = request;
source->context = mixerHandle;
- error = wrap_json_unpack(argsJ, "{s?b s?o,s?o,s?o,s?o !}"
+ error = wrap_json_unpack(argsJ, "{s?b,s?o,s?o,s?o,s?o,s?o !}"
, "close", &close
+ , "list", &listJ
, "backend", &backendJ
, "frontend", &frontendJ
, "zones", &zonesJ
, "streams", &streamsJ
);
if (error) {
- AFB_ReqFailF(request, "MixerApiVerbCB", "missing 'uid|backend|frontend|zones|streams' mixer=%s", json_object_get_string(argsJ));
+ AFB_ReqFailF(request, "invalid syntax", "request missing 'uid|list|backend|frontend|zones|streams' mixer=%s", json_object_get_string(argsJ));
goto OnErrorExit;
}
// Free attached resources and free mixer
if (close) {
- AFB_ReqFailF(request, "MixerApiVerbCB", "(Fulup) Close action still to be done mixer=%s", json_object_get_string(argsJ));
+ AFB_ReqFailF(request, "not implemented", "(Fulup) Close action still to be done mixer=%s", json_object_get_string(argsJ));
goto OnErrorExit;
}
+ if (listJ) {
+ int streams = 0, quiet = 0, backend = 0, frontend = 0, zones = 0;
+
+ error = wrap_json_unpack(listJ, "{s?b,s?b,s?b,s?b,s?b !}"
+ , "quiet", &quiet
+ , "streams", &streams
+ , "backend", &backend
+ , "frontend", &frontend
+ , "zones", &zones
+ );
+ if (error) {
+ AFB_ReqFailF(request, "invalid syntax", "list missing 'uid|backend|frontend|zones|streams' list=%s", json_object_get_string(listJ));
+ goto OnErrorExit;
+ }
+
+ if (streams) {
+ streamsJ = json_object_new_array();
+
+ AlsaSndStreamT *streams = mixerHandle->streams;
+ for (int idx = 0; streams[idx].uid; idx++) {
+ if (quiet) {
+ json_object_array_add(streamsJ, json_object_new_string(streams[idx].uid));
+ } else {
+ json_object *numidJ;
+ wrap_json_pack(&numidJ, "{si,si}"
+ , "volume", streams[idx].volume
+ , "mute", streams[idx].mute
+ );
+ wrap_json_pack(&valueJ, "{ss,so}"
+ , "uid", streams[idx].uid
+ , "numid", numidJ
+ );
+ json_object_array_add(streamsJ, valueJ);
+ AFB_ApiWarning (request->dynapi, "stream=%s", json_object_get_string(streamsJ));
+ }
+
+ }
+ json_object_object_add(responseJ, "streams", streamsJ);
+ }
+
+ if (backend || frontend || zones) {
+ AFB_ReqFailF(request, "not implemented", "(Fulup) list action Still To Be Done");
+ goto OnErrorExit;
+ }
+
+ AFB_ReqSucess(request, responseJ, NULL);
+ return;
+ }
+
if (backendJ) {
error = SndBackend(source, backendJ);
if (error) goto OnErrorExit;