summaryrefslogtreecommitdiffstats
path: root/demux/demux_mkv.c
diff options
context:
space:
mode:
authorwm4 <wm4@nowhere>2014-11-11 19:36:03 +0100
committerwm4 <wm4@nowhere>2014-11-11 19:36:03 +0100
commitc827ae5f3603378b291d0575920e0cf87f5d0bfe (patch)
treef2e709bb55037c77c183553f8a78ed5fb3ecad68 /demux/demux_mkv.c
parent481ab94c4e16da53def1b4329b8e2883f40fae8e (diff)
downloadmpv-c827ae5f3603378b291d0575920e0cf87f5d0bfe.tar.bz2
mpv-c827ae5f3603378b291d0575920e0cf87f5d0bfe.tar.xz
demux_mkv: adjust subtitle preroll again
Revert commit 24e52f66; even though the old beheavior doesn't make sense (as the commit message assured), it turns out that this works better: typically, it means preroll will start from the previous video key frame (the video CUE index will contain clusters with video key frames only), which often coincides with subtitle changes. Thus the old behavior is actually better. Change the code that uses CueDuration elements. Instead of merely checking whether preroll should be done, find the first cluster that needs to be read to get all subtitle packets. (The intention is to compensate for the enlarged preroll cluster-range due to reverting commit 24e52f66.)
Diffstat (limited to 'demux/demux_mkv.c')
-rw-r--r--demux/demux_mkv.c31
1 files changed, 17 insertions, 14 deletions
diff --git a/demux/demux_mkv.c b/demux/demux_mkv.c
index 8b49169423..79e62a112c 100644
--- a/demux/demux_mkv.c
+++ b/demux/demux_mkv.c
@@ -2716,25 +2716,28 @@ static struct mkv_index *seek_with_cues(struct demuxer *demuxer, int seek_id,
if (flags & SEEK_SUBPREROLL) {
uint64_t prev_target = 0;
for (size_t i = 0; i < mkv_d->num_indexes; i++) {
- uint64_t index_pos = mkv_d->indexes[i].filepos;
- if (index_pos > prev_target && index_pos < seek_pos)
- prev_target = index_pos;
+ if (seek_id < 0 || mkv_d->indexes[i].tnum == seek_id) {
+ uint64_t index_pos = mkv_d->indexes[i].filepos;
+ if (index_pos > prev_target && index_pos < seek_pos)
+ prev_target = index_pos;
+ }
}
if (mkv_d->index_has_durations) {
- // If there are no earlier subtitles overlapping with the
- // target cluster, then disable preroll-seeking.
- bool overlap = false;
+ // Find the earliest cluster that is not before prev_target,
+ // but contains subtitle packets overlapping with the cluster
+ // at seek_pos.
+ uint64_t target = seek_pos;
for (size_t i = 0; i < mkv_d->num_indexes; i++) {
struct mkv_index *cur = &mkv_d->indexes[i];
- overlap = cur->timecode <= index->timecode &&
- cur->timecode + cur->duration > index->timecode &&
- cur->filepos >= prev_target &&
- cur->filepos != seek_pos;
- if (overlap)
- break;
+ if (cur->timecode <= index->timecode &&
+ cur->timecode + cur->duration > index->timecode &&
+ cur->filepos >= prev_target &&
+ cur->filepos < target)
+ {
+ target = cur->filepos;
+ }
}
- if (!overlap)
- prev_target = 0;
+ prev_target = target;
}
if (prev_target)
seek_pos = prev_target;