summaryrefslogtreecommitdiffstats
path: root/plugins/alsa
diff options
context:
space:
mode:
Diffstat (limited to 'plugins/alsa')
-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);