From 296531ad0050fbc38fb1cf7823f6e22f97d502b1 Mon Sep 17 00:00:00 2001 From: wm4 Date: Thu, 19 Sep 2013 14:31:43 +0200 Subject: mixer: minor refactoring Let struct mixer access access MPOpts to simplify some things. Rename some variables and functions. There should be no functional changes. --- mpvcore/mplayer.c | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) (limited to 'mpvcore/mplayer.c') diff --git a/mpvcore/mplayer.c b/mpvcore/mplayer.c index d9715e447f..a2c96bb270 100644 --- a/mpvcore/mplayer.c +++ b/mpvcore/mplayer.c @@ -454,7 +454,7 @@ void uninit_player(struct MPContext *mpctx, unsigned int mask) if (mpctx->sh_audio) uninit_audio(mpctx->sh_audio); cleanup_demux_stream(mpctx, STREAM_AUDIO); - mpctx->mixer.afilter = NULL; + mpctx->mixer.af = NULL; } if (mask & INITIALIZED_SUB) { @@ -542,7 +542,7 @@ void uninit_player(struct MPContext *mpctx, unsigned int mask) if (mask & INITIALIZED_AO) { mpctx->initialized_flags &= ~INITIALIZED_AO; if (mpctx->mixer.ao) - mixer_uninit(&mpctx->mixer); + mixer_uninit_audio(&mpctx->mixer); mpctx->mixer.ao = NULL; if (mpctx->ao) ao_uninit(mpctx->ao, mpctx->stop_play != AT_END_OF_FILE); @@ -1628,11 +1628,7 @@ static int recreate_audio_filters(struct MPContext *mpctx) return -1; } - mpctx->mixer.afilter = mpctx->sh_audio->afilter; - mpctx->mixer.volstep = opts->volstep; - mpctx->mixer.softvol = opts->softvol; - mpctx->mixer.softvol_max = opts->softvol_max; - mixer_reinit(&mpctx->mixer, mpctx->ao); + 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, @@ -4859,6 +4855,7 @@ static int mpv_main(int argc, char *argv[]) init_libav(); GetCpuCaps(&gCpuCaps); screenshot_init(mpctx); + mpctx->mixer.opts = opts; // Preparse the command line m_config_preparse_command_line(mpctx->mconfig, argc, argv); -- cgit v1.2.3 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 From b8e42ae13c511855fcba0b6b795d55b37e461665 Mon Sep 17 00:00:00 2001 From: wm4 Date: Thu, 19 Sep 2013 14:32:47 +0200 Subject: mixer: restore volume with playback resume Note that this is intentionally never done if the AO or softvolume is different, or if the current volume control method is thought to control system wide volume (such as ALSA) or otherwise user controllable (such as PulseAudio). The intention is to keep things robust and to avoid messing with the user's audio settings as far as possible, while still providing the ability to resume volume if it makes sense. --- mpvcore/mplayer.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) (limited to 'mpvcore/mplayer.c') diff --git a/mpvcore/mplayer.c b/mpvcore/mplayer.c index fafb88d022..00229364e6 100644 --- a/mpvcore/mplayer.c +++ b/mpvcore/mplayer.c @@ -809,8 +809,7 @@ static const char *backup_properties[] = { "speed", "edition", "pause", - //"volume", - //"mute", + "volume-restore-data", "audio-delay", //"balance", "fullscreen", -- cgit v1.2.3 From 01622717257673d424debfa762536f998d97a4dd Mon Sep 17 00:00:00 2001 From: wm4 Date: Thu, 19 Sep 2013 14:33:26 +0200 Subject: mixer: make struct opaque Also remove stray include statements from ao_alsa and ao_oss. --- mpvcore/mplayer.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'mpvcore/mplayer.c') diff --git a/mpvcore/mplayer.c b/mpvcore/mplayer.c index 00229364e6..dc4322d4e3 100644 --- a/mpvcore/mplayer.c +++ b/mpvcore/mplayer.c @@ -449,7 +449,7 @@ void uninit_player(struct MPContext *mpctx, unsigned int mask) if (mask & INITIALIZED_ACODEC) { mpctx->initialized_flags &= ~INITIALIZED_ACODEC; - mixer_uninit_audio(&mpctx->mixer); + mixer_uninit_audio(mpctx->mixer); if (mpctx->sh_audio) uninit_audio(mpctx->sh_audio); cleanup_demux_stream(mpctx, STREAM_AUDIO); @@ -1608,7 +1608,7 @@ static int recreate_audio_filters(struct MPContext *mpctx) return -1; } - mixer_reinit_audio(&mpctx->mixer, mpctx->ao, mpctx->sh_audio->afilter); + mixer_reinit_audio(mpctx->mixer, mpctx->ao, mpctx->sh_audio->afilter); return 0; } @@ -4826,7 +4826,7 @@ static int mpv_main(int argc, char *argv[]) init_libav(); GetCpuCaps(&gCpuCaps); screenshot_init(mpctx); - mixer_init(&mpctx->mixer, opts); + mpctx->mixer = mixer_init(mpctx, opts); // Preparse the command line m_config_preparse_command_line(mpctx->mconfig, argc, argv); -- cgit v1.2.3