aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJonathan Aillet <jonathan.aillet@iot.bzh>2019-01-16 11:21:45 +0100
committerJonathan Aillet <jonathan.aillet@iot.bzh>2019-01-16 17:17:28 +0100
commit739ff0e0de5ed0a921395dd24b882d795123be30 (patch)
treedf84e02c1f9926d638c8741c5a1ef3c89ce6a059
parent1103db258f1864b96565c3789bd91bd4ffadc7a7 (diff)
Correct sent back stream volume
Send back the real applied value when a stream volume changed. Change-Id: If11e11271080c1f1710775b120f26e1cf34f0a67 Signed-off-by: Jonathan Aillet <jonathan.aillet@iot.bzh>
-rw-r--r--plugins/alsa/alsa-api-streams.c35
1 files changed, 20 insertions, 15 deletions
diff --git a/plugins/alsa/alsa-api-streams.c b/plugins/alsa/alsa-api-streams.c
index 80609bc..6b743e2 100644
--- a/plugins/alsa/alsa-api-streams.c
+++ b/plugins/alsa/alsa-api-streams.c
@@ -43,7 +43,7 @@ typedef struct {
STATIC void StreamApiVerbCB(AFB_ReqT request) {
apiHandleT *handle = (apiHandleT*) afb_req_get_vcbdata(request);
int error, verbose = 0, doClose = 0, doToggle = 0, doMute = -1, doInfo = 0;
- long mute, volume, curvol;
+ long mute, volume, prevvol;
json_object *volumeJ = NULL, *rampJ = NULL, *argsJ = afb_req_json(request);
json_object *responseJ = NULL;
SoftMixerT *mixer = handle->mixer;
@@ -99,31 +99,30 @@ STATIC void StreamApiVerbCB(AFB_ReqT request) {
}
if (volumeJ) {
- long newvol;
+ long voltoset, newvol;
const char*volString;
- error = AlsaCtlNumidGetLong(mixer, handle->sndcard, handle->stream->volume, &curvol);
+ error = AlsaCtlNumidGetLong(mixer, handle->sndcard, handle->stream->volume, &prevvol);
if (error) {
AFB_ReqFailF(request, "invalid-numid", "Fail to get volume numid=%d value=%ld", handle->stream->volume, volume);
goto OnErrorExit;
}
-
switch (json_object_get_type(volumeJ)) {
case json_type_string:
volString = json_object_get_string(volumeJ);
switch (volString[0]) {
case '+':
- sscanf(&volString[1], "%ld", &newvol);
- newvol = curvol + newvol;
+ sscanf(&volString[1], "%ld", &voltoset);
+ voltoset = prevvol + voltoset;
break;
case '-':
- sscanf(&volString[1], "%ld", &newvol);
- newvol = curvol - newvol;
+ sscanf(&volString[1], "%ld", &voltoset);
+ voltoset = prevvol - voltoset;
break;
default:
- error = sscanf(&volString[0], "%ld", &newvol);
+ error = sscanf(&volString[0], "%ld", &voltoset);
if (error != 1) {
AFB_ReqFailF(request, "not-integer", "relative volume should start by '+|-' value=%s", json_object_get_string(volumeJ));
goto OnErrorExit;
@@ -131,7 +130,7 @@ STATIC void StreamApiVerbCB(AFB_ReqT request) {
}
break;
case json_type_int:
- newvol = json_object_get_int(volumeJ);
+ voltoset = json_object_get_int(volumeJ);
break;
default:
AFB_ReqFailF(request, "not-integer", "volume should be string or integer value=%s", json_object_get_string(volumeJ));
@@ -139,22 +138,28 @@ STATIC void StreamApiVerbCB(AFB_ReqT request) {
}
- error = AlsaCtlNumidSetLong(mixer, handle->sndcard, handle->stream->volume, newvol);
+ error = AlsaCtlNumidSetLong(mixer, handle->sndcard, handle->stream->volume, voltoset);
+ if (error) {
+ AFB_ReqFailF(request, "StreamApiVerbCB", "Fail to set stream volume numid=%d value=%ld", handle->stream->volume, voltoset);
+ goto OnErrorExit;
+ }
+
+ error = AlsaCtlNumidGetLong(mixer, handle->sndcard, handle->stream->volume, &newvol);
if (error) {
- AFB_ReqFailF(request, "StreamApiVerbCB", "Fail to set stream volume numid=%d value=%ld", handle->stream->volume, newvol);
+ AFB_ReqFailF(request, "invalid-numid", "Fail to get volume numid=%d value=%ld", handle->stream->volume, volume);
goto OnErrorExit;
}
if (verbose) {
json_object_object_add(responseJ, "volnew", json_object_new_int((int) newvol));
- json_object_object_add(responseJ, "volold", json_object_new_int((int) curvol));
+ json_object_object_add(responseJ, "volold", json_object_new_int((int) prevvol));
}
}
if (rampJ) {
if (verbose) {
- error = AlsaCtlNumidGetLong(mixer, handle->sndcard, handle->stream->volume, &curvol);
- json_object_object_add(responseJ, "volold", json_object_new_int((int) curvol));
+ error = AlsaCtlNumidGetLong(mixer, handle->sndcard, handle->stream->volume, &prevvol);
+ json_object_object_add(responseJ, "volold", json_object_new_int((int) prevvol));
}
error += AlsaVolRampApply(mixer, handle->sndcard, handle->stream, rampJ);