From e5a97ef27f8be577debb0cbd8acbcc8f743cc4d1 Mon Sep 17 00:00:00 2001 From: wm4 Date: Sun, 6 Oct 2019 20:28:55 +0200 Subject: [PATCH] audio: do not try gapless if video is still ongoing In this case, gapless will most likely not work. It will result in (very slight) desync, or (more commonly with small buffer sizes), in an underflow. I think it would be legitimate to disable gapless at end of playback completely if video is enabled at all. But this would need an exception for cover art mode, so I guess the current solution is OK as well. --- DOCS/man/options.rst | 2 ++ player/audio.c | 6 +++++- 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/DOCS/man/options.rst b/DOCS/man/options.rst index 52f179051d..99c02d7fe6 100644 --- a/DOCS/man/options.rst +++ b/DOCS/man/options.rst @@ -1798,6 +1798,8 @@ Audio an implementation detail, and can change from version to version. Currently, the device is kept even if the sample format changes, but the sample formats are convertible. + If video is still going on when there is still audio, trying to use + gapless is also explicitly given up. .. note:: diff --git a/player/audio.c b/player/audio.c index 308b27aec1..161e3d7c69 100644 --- a/player/audio.c +++ b/player/audio.c @@ -980,7 +980,11 @@ void fill_audio_out_buffers(struct MPContext *mpctx) // With gapless audio, delay this to ao_uninit. There must be only // 1 final chunk, and that is handled when calling ao_uninit(). - if (audio_eof && !opts->gapless_audio) + // If video is still on-going, trying to do gapless is pointless, as video + // will have to continue for a while with audio stopped (but still try to + // do it if gapless is forced, mostly for testing). + if (audio_eof && (!opts->gapless_audio || + (opts->gapless_audio <= 0 && mpctx->video_status != STATUS_EOF))) playflags |= AOPLAY_FINAL_CHUNK; uint8_t **planes;