demux_mkv: fix seeking with files that miss the first index entry

Now it will always be able to seek back to the start, even if the index
is sparse or misses the first entry.

This can be achieved by reusing the logic for incremental index
generation (for files with no index), and start time probing (for making
sure the first block is always indexed).
This commit is contained in:
wm4 2016-04-12 15:41:44 +02:00
parent 837b865c7f
commit f4142ab9ad
1 changed files with 6 additions and 3 deletions

View File

@ -773,8 +773,9 @@ static int demux_mkv_read_cues(demuxer_t *demuxer)
if (cues.n_cue_point <= 3) // probably too sparse and will just break seeking if (cues.n_cue_point <= 3) // probably too sparse and will just break seeking
goto done; goto done;
// Discard incremental index. // Discard incremental index. (Keep the first entry, which must be the
mkv_d->num_indexes = 0; // start of the file - helps with files that miss the first index entry.)
mkv_d->num_indexes = MPMIN(1, mkv_d->num_indexes);
mkv_d->index_has_durations = false; mkv_d->index_has_durations = false;
for (int i = 0; i < cues.n_cue_point; i++) { for (int i = 0; i < cues.n_cue_point; i++) {
@ -2963,8 +2964,10 @@ static void probe_first_timestamp(struct demuxer *demuxer)
return; return;
struct block_info block; struct block_info block;
if (read_next_block(demuxer, &block) > 0) if (read_next_block(demuxer, &block) > 0) {
index_block(demuxer, &block);
mkv_d->tmp_block = block; mkv_d->tmp_block = block;
}
demuxer->start_time = mkv_d->cluster_tc / 1e9; demuxer->start_time = mkv_d->cluster_tc / 1e9;