From 38b2c97fd6b59b923ad309c19c457cbc0210da17 Mon Sep 17 00:00:00 2001 From: wm4 Date: Thu, 19 Sep 2013 14:32:09 +0200 Subject: mixer: refactor, fix some aspects of --volume handling Refactor how mixer.c does volume/mute restoration and initialization. Move to handling of --volume and --mute to mixer.c. Simplify the implementation of these and hopefully fix bugs/strange behavior related to using them as file-local options (this uses a somewhat dirty trick: the option values are reverted to "auto" after initialization). Put most code related to initialization and volume restoring in probe_softvol() and restore_volume(). Having this code all in one place is less confusing. Instead of trying to detect whether to use softvol at runtime, detect it at initialization time using AOCONTROL_GET_VOLUME (same with mute, AOCONTROL_GET_MUTE). This implies we expect SET_VOLUME/SET_MUTE to work if the GET variants work. Hopefully this is always the case. This is also preparation for being able to change volume/mute settings if audio is disabled, and for allowing restoring value with playback resume. --- mpvcore/mplayer.c | 42 +++++++----------------------------------- 1 file changed, 7 insertions(+), 35 deletions(-) (limited to 'mpvcore/mplayer.c') diff --git a/mpvcore/mplayer.c b/mpvcore/mplayer.c index a2c96bb270..fafb88d022 100644 --- a/mpvcore/mplayer.c +++ b/mpvcore/mplayer.c @@ -443,18 +443,16 @@ 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); if (mask & INITIALIZED_ACODEC) { mpctx->initialized_flags &= ~INITIALIZED_ACODEC; + mixer_uninit_audio(&mpctx->mixer); if (mpctx->sh_audio) uninit_audio(mpctx->sh_audio); cleanup_demux_stream(mpctx, STREAM_AUDIO); - mpctx->mixer.af = NULL; } if (mask & INITIALIZED_SUB) { @@ -526,24 +524,8 @@ void uninit_player(struct MPContext *mpctx, unsigned int mask) getch2_disable(); } - if (mask & INITIALIZED_VOL) { - mpctx->initialized_flags &= ~INITIALIZED_VOL; - if (mpctx->mixer.ao) { - // Normally the mixer remembers volume, but do it even if the - // volume is set explicitly with --volume=... (so that the same - // volume is restored on reinit) - 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); - } - } - if (mask & INITIALIZED_AO) { mpctx->initialized_flags &= ~INITIALIZED_AO; - if (mpctx->mixer.ao) - mixer_uninit_audio(&mpctx->mixer); - mpctx->mixer.ao = NULL; if (mpctx->ao) ao_uninit(mpctx->ao, mpctx->stop_play != AT_END_OF_FILE); mpctx->ao = NULL; @@ -1618,7 +1600,6 @@ static int build_afilter_chain(struct MPContext *mpctx) static int recreate_audio_filters(struct MPContext *mpctx) { - struct MPOpts *opts = mpctx->opts; assert(mpctx->sh_audio); // init audio filters: @@ -1629,15 +1610,6 @@ static int recreate_audio_filters(struct MPContext *mpctx) } mixer_reinit_audio(&mpctx->mixer, mpctx->ao, mpctx->sh_audio->afilter); - if (!(mpctx->initialized_flags & INITIALIZED_VOL)) { - if (opts->mixer_init_volume >= 0) { - mixer_setvolume(&mpctx->mixer, opts->mixer_init_volume, - opts->mixer_init_volume); - } - if (opts->mixer_init_mute >= 0) - mixer_setmute(&mpctx->mixer, opts->mixer_init_mute); - mpctx->initialized_flags |= INITIALIZED_VOL; - } return 0; } @@ -1662,7 +1634,7 @@ void reinit_audio_chain(struct MPContext *mpctx) struct MPOpts *opts = mpctx->opts; init_demux_stream(mpctx, STREAM_AUDIO); if (!mpctx->sh_audio) { - uninit_player(mpctx, INITIALIZED_VOL | INITIALIZED_AO); + uninit_player(mpctx, INITIALIZED_AO); goto no_audio; } @@ -1733,7 +1705,7 @@ void reinit_audio_chain(struct MPContext *mpctx) return; init_error: - uninit_player(mpctx, INITIALIZED_ACODEC | INITIALIZED_AO | INITIALIZED_VOL); + uninit_player(mpctx, INITIALIZED_ACODEC | INITIALIZED_AO); cleanup_demux_stream(mpctx, STREAM_AUDIO); no_audio: mpctx->current_track[STREAM_AUDIO] = NULL; @@ -2040,7 +2012,7 @@ void mp_switch_track(struct MPContext *mpctx, enum stream_type type, uninit_player(mpctx, INITIALIZED_VCODEC | (mpctx->opts->fixed_vo && track ? 0 : INITIALIZED_VO)); } else if (type == STREAM_AUDIO) { - uninit_player(mpctx, INITIALIZED_AO | INITIALIZED_ACODEC | INITIALIZED_VOL); + uninit_player(mpctx, INITIALIZED_AO | INITIALIZED_ACODEC); } else if (type == STREAM_SUB) { uninit_player(mpctx, INITIALIZED_SUB); } @@ -2280,7 +2252,7 @@ static int fill_audio_out_buffers(struct MPContext *mpctx, double endpts) * while displaying video, then doing the output format switch. */ if (!mpctx->opts->gapless_audio) - uninit_player(mpctx, INITIALIZED_AO | INITIALIZED_VOL); + uninit_player(mpctx, INITIALIZED_AO); reinit_audio_chain(mpctx); return -1; } else if (res == ASYNC_PLAY_DONE) @@ -2909,7 +2881,7 @@ static bool timeline_set_part(struct MPContext *mpctx, int i, bool force) enum stop_play_reason orig_stop_play = mpctx->stop_play; if (!mpctx->sh_video && mpctx->stop_play == KEEP_PLAYING) mpctx->stop_play = AT_END_OF_FILE; // let audio uninit drain data - uninit_player(mpctx, INITIALIZED_VCODEC | (mpctx->opts->fixed_vo ? 0 : INITIALIZED_VO) | (mpctx->opts->gapless_audio ? 0 : INITIALIZED_AO) | INITIALIZED_VOL | INITIALIZED_ACODEC | INITIALIZED_SUB); + uninit_player(mpctx, INITIALIZED_VCODEC | (mpctx->opts->fixed_vo ? 0 : INITIALIZED_VO) | (mpctx->opts->gapless_audio ? 0 : INITIALIZED_AO) | INITIALIZED_ACODEC | INITIALIZED_SUB); mpctx->stop_play = orig_stop_play; mpctx->demuxer = n->source; @@ -4855,7 +4827,7 @@ static int mpv_main(int argc, char *argv[]) init_libav(); GetCpuCaps(&gCpuCaps); screenshot_init(mpctx); - mpctx->mixer.opts = opts; + mixer_init(&mpctx->mixer, opts); // Preparse the command line m_config_preparse_command_line(mpctx->mconfig, argc, argv); -- cgit v1.2.3