From dbd22f43be49059c0ec801389103d5d16229bf26 Mon Sep 17 00:00:00 2001 From: wm4 Date: Mon, 23 Oct 2017 19:05:39 +0200 Subject: demux: drop redundant SEEK_BACKWARD flag Seems like most code dealing with this was for setting it in redundant cases. Now SEEK_BACKWARD is redundant, and SEEK_FORWARD is the odd one out. Also fix that SEEK_FORWARD was not correctly unset in try_seek_cache(). In demux_mkv_seek(), make the arbitrary decision that a video stream is not required for the subtitle prefetch logic to be active. We might want subtitles with long duration even with audio only playback, or if the file is used as external subtitle. --- demux/demux_mkv.c | 22 +++++++++------------- 1 file changed, 9 insertions(+), 13 deletions(-) (limited to 'demux/demux_mkv.c') diff --git a/demux/demux_mkv.c b/demux/demux_mkv.c index c95de36f00..753d783063 100644 --- a/demux/demux_mkv.c +++ b/demux/demux_mkv.c @@ -2893,8 +2893,6 @@ static int create_index_until(struct demuxer *demuxer, int64_t timecode) return 0; } -#define FLAG_BACKWARD 1 -#define FLAG_SUBPREROLL 2 static struct mkv_index *seek_with_cues(struct demuxer *demuxer, int seek_id, int64_t target_timecode, int flags) { @@ -2905,8 +2903,8 @@ static struct mkv_index *seek_with_cues(struct demuxer *demuxer, int seek_id, for (size_t i = 0; i < mkv_d->num_indexes; i++) { if (seek_id < 0 || mkv_d->indexes[i].tnum == seek_id) { int64_t diff = - target_timecode - mkv_d->indexes[i].timecode * mkv_d->tc_scale; - if (flags & FLAG_BACKWARD) + mkv_d->indexes[i].timecode * mkv_d->tc_scale - target_timecode; + if (flags & SEEK_FORWARD) diff = -diff; if (min_diff != INT64_MIN) { if (diff <= 0) { @@ -2922,7 +2920,7 @@ static struct mkv_index *seek_with_cues(struct demuxer *demuxer, int seek_id, if (index) { /* We've found an entry. */ uint64_t seek_pos = index->filepos; - if (flags & FLAG_SUBPREROLL) { + if (flags & SEEK_HR) { // Find the cluster with the highest filepos, that has a timestamp // still lower than min_tc. double secs = mkv_d->opts->subtitle_preroll_secs; @@ -2987,14 +2985,12 @@ static void demux_mkv_seek(demuxer_t *demuxer, double seek_pts, int flags) } } - int cueflags = (flags & SEEK_BACKWARD) ? FLAG_BACKWARD : 0; - mkv_d->subtitle_preroll = NUM_SUB_PREROLL_PACKETS; int preroll_opt = mkv_d->opts->subtitle_preroll; - if (((flags & SEEK_HR) || preroll_opt == 1 || - (preroll_opt == 2 && mkv_d->index_has_durations)) - && st_active[STREAM_SUB] && st_active[STREAM_VIDEO]) - cueflags |= FLAG_SUBPREROLL; + if (preroll_opt == 1 || (preroll_opt == 2 && mkv_d->index_has_durations)) + flags |= SEEK_HR; + if (!st_active[STREAM_SUB]) + flags &= ~SEEK_HR; // Adjust the target a little bit to catch cases where the target position // specifies a keyframe with high, but not perfect, precision. @@ -3008,9 +3004,9 @@ static void demux_mkv_seek(demuxer_t *demuxer, double seek_pts, int flags) if (create_index_until(demuxer, target_timecode) >= 0) { int seek_id = st_active[STREAM_VIDEO] ? v_tnum : a_tnum; - index = seek_with_cues(demuxer, seek_id, target_timecode, cueflags); + index = seek_with_cues(demuxer, seek_id, target_timecode, flags); if (!index) - index = seek_with_cues(demuxer, -1, target_timecode, cueflags); + index = seek_with_cues(demuxer, -1, target_timecode, flags); } if (!index) -- cgit v1.2.3