summaryrefslogtreecommitdiffstats
path: root/src/modules/alsa/alsa-mixer.c
diff options
context:
space:
mode:
authorTanu Kaskinen <tanu.kaskinen@digia.com>2011-03-17 12:23:41 +0200
committerColin Guthrie <cguthrie@mandriva.org>2011-03-20 12:42:27 +0000
commite1c289cc6b9f9399f9626304dcd3a2c1aca668a7 (patch)
tree543579e3acc3261c258109debf9cfa5c3e8e3d21 /src/modules/alsa/alsa-mixer.c
parent55936640a198877b3906a425d218b4a02f39f673 (diff)
alsa-mixer: Implement constant volume.
This change makes it possible to configure an arbitrary constant volume for a volume element in the path configuration, which is applied when the path is selected. Note: this is only useful when the exact hardware and driver are known beforehand.
Diffstat (limited to 'src/modules/alsa/alsa-mixer.c')
-rw-r--r--src/modules/alsa/alsa-mixer.c46
1 files changed, 44 insertions, 2 deletions
diff --git a/src/modules/alsa/alsa-mixer.c b/src/modules/alsa/alsa-mixer.c
index a0fa865f..1d00a3d4 100644
--- a/src/modules/alsa/alsa-mixer.c
+++ b/src/modules/alsa/alsa-mixer.c
@@ -1145,6 +1145,31 @@ static int element_zero_volume(pa_alsa_element *e, snd_mixer_t *m) {
return r;
}
+static int element_apply_constant_volume(pa_alsa_element *e, snd_mixer_t *m) {
+ snd_mixer_elem_t *me;
+ snd_mixer_selem_id_t *sid;
+ int r;
+
+ pa_assert(m);
+ pa_assert(e);
+
+ SELEM_INIT(sid, e->alsa_name);
+ if (!(me = snd_mixer_find_selem(m, sid))) {
+ pa_log_warn("Element %s seems to have disappeared.", e->alsa_name);
+ return -1;
+ }
+
+ if (e->direction == PA_ALSA_DIRECTION_OUTPUT)
+ r = snd_mixer_selem_set_playback_volume_all(me, e->constant_volume);
+ else
+ r = snd_mixer_selem_set_capture_volume_all(me, e->constant_volume);
+
+ if (r < 0)
+ pa_log_warn("Failed to set volume to %li of %s: %s", e->constant_volume, e->alsa_name, pa_alsa_strerror(errno));
+
+ return r;
+}
+
int pa_alsa_path_select(pa_alsa_path *p, snd_mixer_t *m) {
pa_alsa_element *e;
int r = 0;
@@ -1185,6 +1210,10 @@ int pa_alsa_path_select(pa_alsa_path *p, snd_mixer_t *m) {
r = element_zero_volume(e, m);
break;
+ case PA_ALSA_VOLUME_CONSTANT:
+ r = element_apply_constant_volume(e, m);
+ break;
+
case PA_ALSA_VOLUME_MERGE:
case PA_ALSA_VOLUME_IGNORE:
r = 0;
@@ -1368,6 +1397,12 @@ static int element_probe(pa_alsa_element *e, snd_mixer_t *m) {
pa_log_warn("Your kernel driver is broken: it reports a volume range from %li to %li which makes no sense.", e->min_volume, e->max_volume);
e->volume_use = PA_ALSA_VOLUME_IGNORE;
+ } else if (e->volume_use == PA_ALSA_VOLUME_CONSTANT &&
+ (e->min_volume > e->constant_volume || e->max_volume < e->constant_volume)) {
+ pa_log_warn("Constant volume %li configured for element %s, but the available range is from %li to %li.",
+ e->constant_volume, e->alsa_name, e->min_volume, e->max_volume);
+ e->volume_use = PA_ALSA_VOLUME_IGNORE;
+
} else {
pa_bool_t is_mono;
pa_channel_position_t p;
@@ -1685,8 +1720,15 @@ static int element_parse_volume(
else if (pa_streq(rvalue, "zero"))
e->volume_use = PA_ALSA_VOLUME_ZERO;
else {
- pa_log("[%s:%u] Volume invalid of '%s'", filename, line, section);
- return -1;
+ uint32_t constant;
+
+ if (pa_atou(rvalue, &constant) >= 0) {
+ e->volume_use = PA_ALSA_VOLUME_CONSTANT;
+ e->constant_volume = constant;
+ } else {
+ pa_log("[%s:%u] Volume invalid of '%s'", filename, line, section);
+ return -1;
+ }
}
return 0;