summaryrefslogtreecommitdiffstats
path: root/mixer.c
diff options
context:
space:
mode:
authorwm4 <wm4@mplayer2.org>2012-01-07 18:06:30 +0100
committerwm4 <wm4@mplayer2.org>2012-01-18 04:21:45 +0100
commitb338b16be7fe902723fc9c5c20f88959264e67d7 (patch)
tree0fc7f4f90430e1a73a977f1932ea541244115725 /mixer.c
parent6afaf948cd80e348c4ff93f44baae362d4423793 (diff)
downloadmpv-b338b16be7fe902723fc9c5c20f88959264e67d7.tar.bz2
mpv-b338b16be7fe902723fc9c5c20f88959264e67d7.tar.xz
audio: reset mplayer's mute state when the system mixer volume changes
Before this commit, the mute state was only reset when either mute was explicitly cleared, or the volume was changed via mplayer controls. If the volume controls are connected to the system mixer, and the system mixer volume is changed otherwise (e.g. with alsamixer), the mute setting was inconsistent. Avoid this by checking the volume. If the returned volume is not 0, the mute flag is considered invalid. This relies on system mixers always returning a volume of 0 when mplayer has set the volume 0. Possible caveat: if the audio output's volume control don't return a volume of exactly 0 after 0 was written, enabling mute basically won't work. It will set the volume to silence, forget the previous volume, and report that mute is disabled.
Diffstat (limited to 'mixer.c')
-rw-r--r--mixer.c25
1 files changed, 20 insertions, 5 deletions
diff --git a/mixer.c b/mixer.c
index 4b99a6e967..61dc1dcb13 100644
--- a/mixer.c
+++ b/mixer.c
@@ -67,7 +67,7 @@ void mixer_uninit(mixer_t *mixer)
// One complication is that the mute state should survive audio
// reinitialization (e.g. when switching to a new file), so we have to be
// sure mixer_reinit() will restore the mute state.
- if (mixer->muted) {
+ if (mixer_getmuted(mixer)) {
// avoid playing the rest of the audio buffer at restored volume
ao_reset(mixer->ao);
mixer_setmuted(mixer, false);
@@ -164,11 +164,17 @@ void mixer_getvolume(mixer_t *mixer, float *l, float *r)
*l = 0;
*r = 0;
if (mixer->ao) {
+ float real_l, real_r;
+ internal_getvolume(mixer, &real_l, &real_r);
+ // consider the case when the system mixer volumes change independently
+ if (real_l != 0 || real_r != 0)
+ mixer->muted = false;
if (mixer->muted) {
*l = mixer->last_l;
*r = mixer->last_r;
} else {
- internal_getvolume(mixer, l, r);
+ *l = real_l;
+ *r = real_r;
}
}
}
@@ -199,14 +205,23 @@ void mixer_getbothvolume(mixer_t *mixer, float *b)
void mixer_mute(mixer_t *mixer)
{
- mixer_setmuted(mixer, !mixer->muted);
+ mixer_setmuted(mixer, !mixer_getmuted(mixer));
+}
+
+bool mixer_getmuted(mixer_t *mixer)
+{
+ // this call will also check whether mute is still active, and "fix" it
+ float l, r;
+ mixer_getvolume(mixer, &l, &r);
+ return mixer->muted;
}
void mixer_setmuted(mixer_t *mixer, bool mute)
{
- if (mute == mixer->muted)
+ bool muted = mixer_getmuted(mixer);
+ if (mute == muted)
return;
- if (mixer->muted) {
+ if (muted) {
mixer_setvolume(mixer, mixer->last_l, mixer->last_r);
} else {
mixer_getvolume(mixer, &mixer->last_l, &mixer->last_r);