summaryrefslogtreecommitdiffstats
path: root/mpvcore
diff options
context:
space:
mode:
authorwm4 <wm4@nowhere>2013-09-19 14:32:09 +0200
committerwm4 <wm4@nowhere>2013-09-19 14:32:09 +0200
commit38b2c97fd6b59b923ad309c19c457cbc0210da17 (patch)
tree9a0512b19ab0c0ce7ca3470512c0b648ee2afc57 /mpvcore
parent4ba52a9e821486d9d9b076a5187583af144b8cec (diff)
downloadmpv-38b2c97fd6b59b923ad309c19c457cbc0210da17.tar.bz2
mpv-38b2c97fd6b59b923ad309c19c457cbc0210da17.tar.xz
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.
Diffstat (limited to 'mpvcore')
-rw-r--r--mpvcore/mp_core.h1
-rw-r--r--mpvcore/mplayer.c42
2 files changed, 7 insertions, 36 deletions
diff --git a/mpvcore/mp_core.h b/mpvcore/mp_core.h
index 9f3e095110..8f57a65edf 100644
--- a/mpvcore/mp_core.h
+++ b/mpvcore/mp_core.h
@@ -29,7 +29,6 @@
#define INITIALIZED_VO 1
#define INITIALIZED_AO 2
-#define INITIALIZED_VOL 4
#define INITIALIZED_GETCH2 8
#define INITIALIZED_PLAYBACK 16
#define INITIALIZED_STREAM 64
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);