diff options
author | wm4 <wm4@nowhere> | 2014-10-29 22:34:40 +0100 |
---|---|---|
committer | wm4 <wm4@nowhere> | 2014-10-29 22:34:40 +0100 |
commit | a1083fb46148dee550b41ffb3d27cc1dbe21b2a9 (patch) | |
tree | 283a7c02d1a827917323ea0567454caca10c8237 /demux | |
parent | f2f9d23e7960df5516eea4fb00218cdb9a2b3977 (diff) | |
download | mpv-a1083fb46148dee550b41ffb3d27cc1dbe21b2a9.tar.bz2 mpv-a1083fb46148dee550b41ffb3d27cc1dbe21b2a9.tar.xz |
demux_mkv: implement percentage seeking with no index
It was implemented only for the case the index exists (pretty useless).
Diffstat (limited to 'demux')
-rw-r--r-- | demux/demux_mkv.c | 46 |
1 files changed, 24 insertions, 22 deletions
diff --git a/demux/demux_mkv.c b/demux/demux_mkv.c index 63738702df..c35ef7ad21 100644 --- a/demux/demux_mkv.c +++ b/demux/demux_mkv.c @@ -2764,40 +2764,42 @@ static void demux_mkv_seek(demuxer_t *demuxer, double rel_seek_secs, int flags) MP_VERBOSE(demuxer, "seek unsupported flags\n"); else { stream_t *s = demuxer->stream; - uint64_t target_filepos; - mkv_index_t *index = NULL; read_deferred_cues(demuxer); - if (!mkv_d->index_complete) { /* not implemented without index */ - MP_VERBOSE(demuxer, "seek unsupported flags\n"); - stream_seek(s, old_pos); - return; - } - int64_t size = 0; stream_control(s, STREAM_CTRL_GET_SIZE, &size); - target_filepos = (uint64_t) (size * rel_seek_secs); - for (size_t i = 0; i < mkv_d->num_indexes; i++) - if (mkv_d->indexes[i].tnum == v_tnum) - if ((index == NULL) - || ((mkv_d->indexes[i].filepos >= target_filepos) - && ((index->filepos < target_filepos) - || (mkv_d->indexes[i].filepos < index->filepos)))) - index = &mkv_d->indexes[i]; - - if (!index) { - stream_seek(s, old_pos); - return; + int64_t target_filepos = size * MPCLAMP(rel_seek_secs, 0, 1); + + mkv_index_t *index = NULL; + if (mkv_d->index_complete) { + for (size_t i = 0; i < mkv_d->num_indexes; i++) { + if (mkv_d->indexes[i].tnum == v_tnum) { + if ((index == NULL) + || ((mkv_d->indexes[i].filepos >= target_filepos) + && ((index->filepos < target_filepos) + || (mkv_d->indexes[i].filepos < index->filepos)))) + index = &mkv_d->indexes[i]; + } + } } mkv_d->cluster_end = 0; - stream_seek(s, index->filepos); mkv_d->v_skip_to_keyframe = st_active[STREAM_VIDEO]; mkv_d->a_skip_to_keyframe = st_active[STREAM_AUDIO]; - mkv_d->skip_to_timecode = index->timecode * mkv_d->tc_scale; + + if (index) { + stream_seek(s, index->filepos); + mkv_d->skip_to_timecode = index->timecode * mkv_d->tc_scale; + } else { + stream_seek(s, target_filepos); + if (ebml_resync_cluster(mp_null_log, s) < 0) { + // Assume EOF + mkv_d->cluster_end = size; + } + } demux_mkv_fill_buffer(demuxer); } |