From c13bfd271c416d1c1fd8991f7058c289a40a4ea3 Mon Sep 17 00:00:00 2001 From: wm4 Date: Sun, 16 Jun 2019 16:08:54 +0200 Subject: demux_mkv: fix subtitle preroll in some cases Subtitle packets with a timestamp before the seek target may overlap with the seek target anyway. This is why this subtitle preroll crap exists: it needs to return packets before the seek target to ensure that the subtitle is displayed at the seek target. This didn't always work. Maybe it's a regression, but it must have been an old one. The breakage is triggered by heuristic that is to prevent excessive queuing of packets in garbage files (this heuristic apparently became immediately necessary when this preroll mechanism was implemented). If a video keyframe packet was found, but no audio packet yet, then subtitle_preroll was set to 0, and since a_skip_to_keyframe was still 0, the subtitle packet was discarded. The dumb thing is that subtitle and video seeking is finished at this point, so the preroll crap should not be applied at all. Fix this by moving the preoll overflow code into the block that handles preroll. --- demux/demux_mkv.c | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/demux/demux_mkv.c b/demux/demux_mkv.c index a98d2864e6..c33fab3a2d 100644 --- a/demux/demux_mkv.c +++ b/demux/demux_mkv.c @@ -2652,14 +2652,13 @@ static int handle_block(demuxer_t *demuxer, struct block_info *block_info) if (!block_info->duration) end_time = INT64_MAX; use_this_block = end_time > mkv_d->skip_to_timecode; - } - if (use_this_block) { - if (mkv_d->subtitle_preroll) { - mkv_d->subtitle_preroll--; - } else { - // This could overflow the demuxer queue. - if (mkv_d->a_skip_to_keyframe || mkv_d->v_skip_to_keyframe) + if (use_this_block) { + if (mkv_d->subtitle_preroll) { + mkv_d->subtitle_preroll--; + } else { + // This could overflow the demuxer queue. use_this_block = 0; + } } } if (use_this_block) { -- cgit v1.2.3