summaryrefslogtreecommitdiffstats
path: root/core
diff options
context:
space:
mode:
authorwm4 <wm4@nowhere>2013-05-28 01:49:07 +0200
committerwm4 <wm4@nowhere>2013-05-29 14:56:35 +0200
commit362e0aa7d5c495bd017167ba519b177e9c1e82f7 (patch)
tree8ce343b5ae9d908a0bb1f65ba65bd3522c9b00f4 /core
parenta9892f901fdf1e737c569a7a975f87232318fdce (diff)
downloadmpv-362e0aa7d5c495bd017167ba519b177e9c1e82f7.tar.bz2
mpv-362e0aa7d5c495bd017167ba519b177e9c1e82f7.tar.xz
mplayer: fix volume setting with --gapless-audio
Playing something with "mpv f1.mkv f2.mkv --gapless-audio --volume=20" caused the volume to be reset when playing a new file. Normally, the volume should not be reset (unless explicitly requested with per-file options), and without either --gapless-audio or --volume it works as expected. The underlying problem is that volume was saved only when the AO was uninitialized, and also the volume was always set when starting a file. Fix this by saving the volume when playback ends, and when the audio is reinitialized. To make sure the volume is never restored twice or saved in the wrong situation, introduce INITIALIZED_VOL. Also note that this volume saving and restoring only happens if the --volume option is used. mixer.c does its own bookkeeping of volume. The main reason for this is that the volume option could be reset by per-file options (see manpage), and mixer.c doesn't know anything about this stuff. This is probably dumb, and maybe some things could be simplified. But for now this will work.
Diffstat (limited to 'core')
-rw-r--r--core/mp_core.h2
-rw-r--r--core/mplayer.c40
2 files changed, 26 insertions, 16 deletions
diff --git a/core/mp_core.h b/core/mp_core.h
index 3b693d1658..9e61c8ffa3 100644
--- a/core/mp_core.h
+++ b/core/mp_core.h
@@ -31,7 +31,7 @@
#define INITIALIZED_VO 1
#define INITIALIZED_AO 2
-
+#define INITIALIZED_VOL 4
#define INITIALIZED_GETCH2 8
#define INITIALIZED_SPUDEC 32
#define INITIALIZED_STREAM 64
diff --git a/core/mplayer.c b/core/mplayer.c
index ad8441f476..684991127b 100644
--- a/core/mplayer.c
+++ b/core/mplayer.c
@@ -557,21 +557,27 @@ void uninit_player(struct MPContext *mpctx, unsigned int mask)
vo_spudec = NULL;
}
- if (mask & INITIALIZED_AO) {
- mpctx->initialized_flags &= ~INITIALIZED_AO;
+ 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=...
+ // 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);
- mixer_uninit(&mpctx->mixer);
}
+ }
+
+ if (mask & INITIALIZED_AO) {
+ mpctx->initialized_flags &= ~INITIALIZED_AO;
+ if (mpctx->mixer.ao)
+ mixer_uninit(&mpctx->mixer);
+ mpctx->mixer.ao = NULL;
if (mpctx->ao)
ao_uninit(mpctx->ao, mpctx->stop_play != AT_END_OF_FILE);
mpctx->ao = NULL;
- mpctx->mixer.ao = NULL;
}
}
@@ -1693,7 +1699,7 @@ void reinit_audio_chain(struct MPContext *mpctx)
struct ao *ao;
init_demux_stream(mpctx, STREAM_AUDIO);
if (!mpctx->sh_audio) {
- uninit_player(mpctx, INITIALIZED_AO);
+ uninit_player(mpctx, INITIALIZED_VOL | INITIALIZED_AO);
goto no_audio;
}
if (!(mpctx->initialized_flags & INITIALIZED_ACODEC)) {
@@ -1759,11 +1765,20 @@ void reinit_audio_chain(struct MPContext *mpctx)
mpctx->mixer.softvol = opts->softvol;
mpctx->mixer.softvol_max = opts->softvol_max;
mixer_reinit(&mpctx->mixer, ao);
+ 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;
+ }
mpctx->syncing_audio = true;
return;
init_error:
- uninit_player(mpctx, INITIALIZED_ACODEC | INITIALIZED_AO);
+ uninit_player(mpctx, INITIALIZED_ACODEC | INITIALIZED_AO | INITIALIZED_VOL);
cleanup_demux_stream(mpctx, STREAM_AUDIO);
no_audio:
mpctx->current_track[STREAM_AUDIO] = NULL;
@@ -2165,7 +2180,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);
+ uninit_player(mpctx, INITIALIZED_AO | INITIALIZED_ACODEC | INITIALIZED_VOL);
} else if (type == STREAM_SUB) {
uninit_player(mpctx, INITIALIZED_SUB);
}
@@ -2405,7 +2420,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);
+ uninit_player(mpctx, INITIALIZED_AO | INITIALIZED_VOL);
reinit_audio_chain(mpctx);
return -1;
} else if (res == ASYNC_PLAY_DONE)
@@ -2942,7 +2957,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_ACODEC | INITIALIZED_SUB);
+ 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);
mpctx->stop_play = orig_stop_play;
mpctx->demuxer = n->source;
@@ -4404,11 +4419,6 @@ goto_enable_cache: ;
mpctx->audio_delay += mpctx->sh_video->stream_delay;
}
if (mpctx->sh_audio) {
- 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);
if (!opts->ignore_start)
mpctx->audio_delay -= mpctx->sh_audio->stream_delay;
}