diff --git a/audio/mixer.c b/audio/mixer.c index d97391cf7e..b67e548a3c 100644 --- a/audio/mixer.c +++ b/audio/mixer.c @@ -130,6 +130,7 @@ void mixer_setvolume(mixer_t *mixer, float l, float r) if (!mixer->ao || mixer->muted_using_volume) return; setvolume_internal(mixer, mixer->vol_l, mixer->vol_r); + mixer->user_set_volume = true; } void mixer_getbothvolume(mixer_t *mixer, float *b) @@ -152,6 +153,7 @@ void mixer_setmute(struct mixer *mixer, bool mute) } mixer->muted = mute; mixer->muted_by_us = mute; + mixer->user_set_mute = true; } } @@ -264,6 +266,8 @@ void mixer_reinit(struct mixer *mixer, struct ao *ao) mixer_setmute(mixer, true); if (mixer->balance != 0) mixer_setbalance(mixer, mixer->balance); + mixer->user_set_mute = false; + mixer->user_set_volume = false; } /* Called before uninitializing the audio output. The main purpose is to diff --git a/audio/mixer.h b/audio/mixer.h index 3de92e1e03..3160c20cfe 100644 --- a/audio/mixer.h +++ b/audio/mixer.h @@ -41,6 +41,8 @@ typedef struct mixer { * and needs to be restored after the driver is reinitialized. */ const char *restore_volume; float balance; + bool user_set_mute; + bool user_set_volume; } mixer_t; void mixer_reinit(struct mixer *mixer, struct ao *ao); diff --git a/core/mplayer.c b/core/mplayer.c index ee1df36654..0a108cb514 100644 --- a/core/mplayer.c +++ b/core/mplayer.c @@ -450,6 +450,8 @@ static void uninit_subs(struct demuxer *demuxer) void uninit_player(struct MPContext *mpctx, unsigned int mask) { + struct MPOpts *opts = &mpctx->opts; + mask &= mpctx->initialized_flags; mp_msg(MSGT_CPLAYER, MSGL_DBG2, "\n*** uninit(0x%X)\n", mask); @@ -542,8 +544,15 @@ void uninit_player(struct MPContext *mpctx, unsigned int mask) if (mask & INITIALIZED_AO) { mpctx->initialized_flags &= ~INITIALIZED_AO; - if (mpctx->mixer.ao) + if (mpctx->mixer.ao) { + // Normally the mixer remembers volume, but do it even if the + // volume is set explicitly with --volume=... + if (opts->mixer_init_volume >= 0 && mpctx->mixer.user_set_volume) + mixer_getbothvolume(&mpctx->mixer, &opts->mixer_init_volume); + if (opts->mixer_init_mute >= 0 && mpctx->mixer.user_set_mute) + opts->mixer_init_mute = mixer_getmute(&mpctx->mixer); mixer_uninit(&mpctx->mixer); + } if (mpctx->ao) ao_uninit(mpctx->ao, mpctx->stop_play != AT_END_OF_FILE); mpctx->ao = NULL; @@ -4148,9 +4157,6 @@ terminate_playback: // don't jump here after ao/vo/getch initialization! mp_msg(MSGT_CPLAYER, MSGL_INFO, "\n"); - // xxx handle this as INITIALIZED_CONFIG? - m_config_leave_file_local(mpctx->mconfig); - // time to uninit all, except global stuff: int uninitialize_parts = INITIALIZED_ALL; if (opts->fixed_vo) @@ -4160,6 +4166,9 @@ terminate_playback: // don't jump here after ao/vo/getch initialization! uninitialize_parts -= INITIALIZED_AO; uninit_player(mpctx, uninitialize_parts); + // xxx handle this as INITIALIZED_CONFIG? + m_config_leave_file_local(mpctx->mconfig); + mpctx->filename = NULL; mpctx->file_format = DEMUXER_TYPE_UNKNOWN; talloc_free(mpctx->resolve_result);