From 7807f46cd1b8f58ee8f2e5f6d7240d7ca7502311 Mon Sep 17 00:00:00 2001 From: Uoti Urpala Date: Mon, 9 Apr 2012 17:39:01 +0300 Subject: audio: keep volume level internally (not only in AO) Current volume was always queried from the the audio output driver (or filter in case of --softvol). The only case where it was stored on mixer level was that when turning off mute, volume was set to the value it had before mute was activated. Change the mixer code to always store the current target volume internally. It still checks for significant changes from external sources and resets the internal value in that case. The main functionality changes are: Volume will now be kept separately from mute status. Increasing or decreasing volume will now change it relative to the original value before mute, even if mute is implemented by setting AO level volume to 0. Volume changes no longer automatically disable mute. The exception is relative changes up (like the volume increase key in default keybindings); that's the only case which still disables mute. Keeping the value internally avoids problems with granularity of possible volume values supported by AO. Increase/decrease keys could work unsymmetrically, or when specifying a smaller than default --volstep, even fail completely. In one case occurring in practice, if the AO only supports changing volume in steps of about 2 and rounds down the requested volume, then volume down key would decrease by 4 but volume up would increase by 2 (previous volume plus or minus the default change of 3, rounded down to a multiple of 2). Now, the internal value will keep full precision. --- mplayer.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'mplayer.c') diff --git a/mplayer.c b/mplayer.c index d410008dff..7696b92ce8 100644 --- a/mplayer.c +++ b/mplayer.c @@ -692,7 +692,7 @@ void uninit_player(struct MPContext *mpctx, unsigned int mask) void exit_player_with_rc(struct MPContext *mpctx, enum exit_reason how, int rc) { if (mpctx->user_muted) - mixer_mute(&mpctx->mixer); + mixer_setmute(&mpctx->mixer, false); uninit_player(mpctx, INITIALIZED_ALL); #if defined(__MINGW32__) || defined(__CYGWIN__) timeEndPeriod(1); -- cgit v1.2.3 From 87dad2a4704b2fb0f983d5cb665a065437288d35 Mon Sep 17 00:00:00 2001 From: Uoti Urpala Date: Mon, 9 Apr 2012 21:02:27 +0300 Subject: audio: restore volume setting after AO reinit if needed MPlayer volume control was originally implemented with the assumption that it controls a system-wide volume setting which keeps its value even if a process closes and reopens the audio device. However, this is not actually true for --softvol mode or some audio output APIs that only consider volume as a per-client setting for software mixing. This could have annoying results, as the volume would be reset to a default value if the AO was closed and reopened, for example whem moving to a new file or crossing ordered chapter boundaries. Add code to set the previous volume again after audio reinitialization if the current audio chain is known to behave this way (softvol active or the AO driver is known to not keep persistent volume externally). This also avoids an inconsistency with the mute flag. The frontend assumed the mute status is persistent across file changes, but it could be similarly lost. The audio drivers that are assumed to not keep persistent volume are: coreaudio, dsound, esd, nas, openal, sdl. None of these changes have been tested. I'm guessing that ESD and NAS do per-connection non-persistent volume settings. Partially based on code by wm4. --- mplayer.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'mplayer.c') diff --git a/mplayer.c b/mplayer.c index 7696b92ce8..9140b16bca 100644 --- a/mplayer.c +++ b/mplayer.c @@ -1821,10 +1821,10 @@ void reinit_audio_chain(struct MPContext *mpctx) "Couldn't find matching filter/ao format!\n"); goto init_error; } - mpctx->mixer.ao = ao; mpctx->mixer.volstep = volstep; mpctx->mixer.softvol = opts->softvol; mpctx->mixer.softvol_max = opts->softvol_max; + mixer_reinit(&mpctx->mixer, ao); mpctx->syncing_audio = true; return; -- cgit v1.2.3 From 9624f10aa85039c73d4bdb70e8062daeabaa90c6 Mon Sep 17 00:00:00 2001 From: Uoti Urpala Date: Mon, 9 Apr 2012 22:11:49 +0300 Subject: 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. --- mplayer.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'mplayer.c') diff --git a/mplayer.c b/mplayer.c index 9140b16bca..f3a9cbdc10 100644 --- a/mplayer.c +++ b/mplayer.c @@ -681,8 +681,10 @@ void uninit_player(struct MPContext *mpctx, unsigned int mask) if (mask & INITIALIZED_AO) { mpctx->initialized_flags &= ~INITIALIZED_AO; current_module = "uninit_ao"; - if (mpctx->ao) + if (mpctx->ao) { + mixer_uninit(&mpctx->mixer); ao_uninit(mpctx->ao, mpctx->stop_play != AT_END_OF_FILE); + } mpctx->ao = NULL; } @@ -691,8 +693,6 @@ void uninit_player(struct MPContext *mpctx, unsigned int mask) void exit_player_with_rc(struct MPContext *mpctx, enum exit_reason how, int rc) { - if (mpctx->user_muted) - mixer_setmute(&mpctx->mixer, false); uninit_player(mpctx, INITIALIZED_ALL); #if defined(__MINGW32__) || defined(__CYGWIN__) timeEndPeriod(1); -- cgit v1.2.3