From d25fbb081387ddb9679a31faf43946ad837c5d66 Mon Sep 17 00:00:00 2001 From: wm4 Date: Fri, 31 May 2019 22:28:28 +0200 Subject: demux: fix backward playback at EOF with full demuxer cache Fixes "mpv file.mkv --cache --demuxer-cache-wait --play-dir=backward", and other situations where the demuxer cache contains the entire file, and playback is to start from the end. It also can be triggered when starting playback normally with --cache, and once everything is in the cache, enabling backward playback and seeking past EOF. In all cases, the cache seek will set reader_head=NULL (because you seeked to/past EOF). Then the code (the one modified by this commit) sees that ds->queue->is_bof==true, and thinks we've reached BOF (beginning of file) while searching for a useful packet, i.e. we found nothing and playback really can only end. Obviously this is nonsense, we've found only nothing if we actually searched from the beginning, not some "random" reader_head (== first) value that does not include the entire cache. That means the condition should trigger only if the start of the search (first variable) points to the beginning of the cache (ds->queue->head). Not taking this if means we'll seek to an earlier position and retry. Also, a seek before the beginning of the cache will always end up with reader_head==ds->queue->head, i.e. we'll terminate properly. That comment was quite right. --- demux/demux.c | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) (limited to 'demux/demux.c') diff --git a/demux/demux.c b/demux/demux.c index f65d606b92..0582ccc661 100644 --- a/demux/demux.c +++ b/demux/demux.c @@ -1393,9 +1393,7 @@ static void find_backward_restart_pos(struct demux_stream *ds) } if (!target) { - // Note: assume this holds true. You could think of various reasons why - // this might break. - if (ds->queue->is_bof) { + if (ds->queue->is_bof && first == ds->queue->head) { MP_VERBOSE(in, "BOF for stream %d\n", ds->index); ds->back_restarting = false; ds->back_range_started = false; -- cgit v1.2.3