summaryrefslogtreecommitdiffstats
path: root/mixer.c
diff options
context:
space:
mode:
authorwm4 <wm4@mplayer2.org>2012-01-07 14:10:05 +0100
committerwm4 <wm4@mplayer2.org>2012-01-18 04:21:45 +0100
commitaae97b7e254f312e5c7bfbe940cb8515a25bf11d (patch)
tree0444ae3fe25edef952757d2d6b2b79a560209cd9 /mixer.c
parent15a318b2a56766e7bc2dee5d4cc8f514ba21fe39 (diff)
downloadmpv-aae97b7e254f312e5c7bfbe940cb8515a25bf11d.tar.bz2
mpv-aae97b7e254f312e5c7bfbe940cb8515a25bf11d.tar.xz
audio: properly restore audio volume on exit when mute is used
When you mute audio, mplayer is supposed to restore the volume controls on exit. This affects when --softvol isn't used and the audio output driver volume controls directly affect the system wide volume controls. This wasn't done in some cases.
Diffstat (limited to 'mixer.c')
-rw-r--r--mixer.c36
1 files changed, 34 insertions, 2 deletions
diff --git a/mixer.c b/mixer.c
index 5cd1b722d9..d0e6423e6f 100644
--- a/mixer.c
+++ b/mixer.c
@@ -45,11 +45,36 @@ void mixer_reinit(mixer_t *mixer)
mixer_setvolume(mixer, mixer->restore_vol_l, mixer->restore_vol_r);
mixer->muted = muted;
}
+ if (mixer->muted) {
+ // undo mixer_uninit()
+ mixer_setvolume(mixer, 0, 0);
+ mixer->muted = true;
+ }
if (mixer->restore_balance) {
mixer_setbalance(mixer, mixer->balance);
}
}
+// Called before the audio output is uninitialized.
+// Note that this doesn't necessarily terminate the mixer_t instance, and it's
+// possible that mixer_reinit() will be called later.
+void mixer_uninit(mixer_t *mixer)
+{
+ if (!mixer->ao)
+ return;
+ // The player is supposed to turn off the mute state when the player
+ // terminates. No other attempts at restoring the volume are done.
+ // 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) {
+ // avoid playing the rest of the audio buffer at restored volume
+ ao_reset(mixer->ao);
+ mixer_setmuted(mixer, false);
+ mixer->muted = true;
+ }
+}
+
void mixer_getvolume(mixer_t *mixer, float *l, float *r)
{
ao_control_vol_t vol;
@@ -124,7 +149,7 @@ void mixer_setvolume(mixer_t *mixer, float l, float r)
mixer->restore_vol_r = r;
}
}
- mixer->muted = 0;
+ mixer->muted = false;
}
void mixer_incvolume(mixer_t *mixer)
@@ -162,12 +187,19 @@ void mixer_getbothvolume(mixer_t *mixer, float *b)
void mixer_mute(mixer_t *mixer)
{
+ mixer_setmuted(mixer, !mixer->muted);
+}
+
+void mixer_setmuted(mixer_t *mixer, bool mute)
+{
+ if (mute == mixer->muted)
+ return;
if (mixer->muted) {
mixer_setvolume(mixer, mixer->last_l, mixer->last_r);
} else {
mixer_getvolume(mixer, &mixer->last_l, &mixer->last_r);
mixer_setvolume(mixer, 0, 0);
- mixer->muted = 1;
+ mixer->muted = true;
}
}