summaryrefslogtreecommitdiffstats
path: root/plugins
diff options
context:
space:
mode:
Diffstat (limited to 'plugins')
-rw-r--r--plugins/alsa/alsa-api-streams.c35
-rw-r--r--plugins/alsa/alsa-core-ctl.c14
2 files changed, 34 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);
diff --git a/plugins/alsa/alsa-core-ctl.c b/plugins/alsa/alsa-core-ctl.c
index 020c13c..e747090 100644
--- a/plugins/alsa/alsa-core-ctl.c
+++ b/plugins/alsa/alsa-core-ctl.c
@@ -232,6 +232,7 @@ PUBLIC int CtlElemIdSetLong(SoftMixerT *mixer, AlsaSndCtlT *sndcard, snd_ctl_ele
snd_ctl_elem_info_t *elemInfo;
const char* name;
int error, numid;
+ long min, max;
snd_ctl_elem_info_alloca(&elemInfo);
snd_ctl_elem_info_set_id(elemInfo, elemId);
@@ -247,6 +248,19 @@ PUBLIC int CtlElemIdSetLong(SoftMixerT *mixer, AlsaSndCtlT *sndcard, snd_ctl_ele
error = snd_ctl_elem_read(sndcard->ctl, elemData);
if (error) goto OnErrorExit;
+ switch(snd_ctl_elem_info_get_type(elemInfo)) {
+ case SND_CTL_ELEM_TYPE_INTEGER:
+ min = snd_ctl_elem_info_get_min(elemInfo);
+ max = snd_ctl_elem_info_get_max(elemInfo);
+
+ value = (value < min) ? min : value;
+ value = (value > max) ? max : value;
+ break;
+
+ default:
+ break;
+ }
+
for (int index = 0; index < count; index++) {
snd_ctl_elem_value_set_integer(elemData, index, value);
}