summaryrefslogtreecommitdiffstats
path: root/mixer.c
diff options
context:
space:
mode:
authorUoti Urpala <uau@mplayer2.org>2012-04-09 22:11:49 +0300
committerUoti Urpala <uau@mplayer2.org>2012-04-11 03:52:34 +0300
commit9624f10aa85039c73d4bdb70e8062daeabaa90c6 (patch)
tree7303f5d0011c5f7a320f0e24d74c42d8e5e2eb3f /mixer.c
parente29cb8f323031b32369bc2104ea1fd4422dd2945 (diff)
downloadmpv-9624f10aa85039c73d4bdb70e8062daeabaa90c6.tar.bz2
mpv-9624f10aa85039c73d4bdb70e8062daeabaa90c6.tar.xz
audio: fix unmute-at-end logic
The player tried to disable mute before exiting, so that if mute is emulated by setting volume to 0 and the volume setting is a system-global one, we don't leave it at 0. However, the logic doing this at process exit was flawed, as volume settings are handled by audio output instances and the audio output that set the mute state may have been closed earlier. Trying to write reliably working logic that restores volume at exit only would be tricky, so change the code to always unmute an audio driver before closing it and restore mute status if one is opened again later.
Diffstat (limited to 'mixer.c')
-rw-r--r--mixer.c28
1 files changed, 25 insertions, 3 deletions
diff --git a/mixer.c b/mixer.c
index e694253b11..793a6ac58e 100644
--- a/mixer.c
+++ b/mixer.c
@@ -235,10 +235,32 @@ void mixer_reinit(struct mixer *mixer, struct ao *ao)
const char *restore_reason = mixer->softvol ? "softvol" :
mixer->ao->driver->info->short_name;
if (mixer->restore_volume && !strcmp(mixer->restore_volume,
- restore_reason)) {
+ restore_reason))
mixer_setvolume(mixer, left, right);
- mixer_setmute(mixer, muted);
- }
+ mixer_setmute(mixer, muted);
if (mixer->balance != 0)
mixer_setbalance(mixer, mixer->balance);
}
+
+/* Called before uninitializing the audio output. The main purpose is to
+ * turn off mute, in case it's a global/persistent setting which might
+ * otherwise be left enabled even after this player instance exits.
+ */
+void mixer_uninit(struct mixer *mixer)
+{
+ checkvolume(mixer);
+ if (mixer->muted) {
+ /* Current audio output API combines playing the remaining buffered
+ * audio and uninitializing the AO into one operation, even though
+ * ideally unmute would happen between those two steps. We can't do
+ * volume changes after uninitialization, but we don't want the
+ * remaining audio to play at full volume either. Thus this
+ * workaround to drop remaining audio first. */
+ ao_reset(mixer->ao);
+ mixer_setmute(mixer, false);
+ /* We remember mute status and re-enable it if we play more audio
+ * in the same process. */
+ mixer->muted = true;
+ }
+ mixer->ao = NULL;
+}