diff options
author | Jan Schmidt <jan@centricular.com> | 2015-01-31 02:30:40 +1100 |
---|---|---|
committer | Jan Schmidt <jan@centricular.com> | 2015-01-31 06:15:44 +1100 |
commit | 4a77c8a84fe921d754124c87e7a8f16e4f49523c (patch) | |
tree | 8ece20bb16435721da42227973f940a1d60675f2 /gst/matroska/matroska-read-common.c | |
parent | 075eb10e65a84b524f8f8b72d3bdfefb0bf27588 (diff) |
matroska: Fix seeking past the end of the file in reverse mode.
Snap to the end of the file when seeking past the end in reverse mode,
and also fix GST_SEEK_TYPE_END and GST_SEEK_TYPE_NONE handling
for the stop position by always seeking on a segment in stream time
Diffstat (limited to 'gst/matroska/matroska-read-common.c')
-rw-r--r-- | gst/matroska/matroska-read-common.c | 18 |
1 files changed, 10 insertions, 8 deletions
diff --git a/gst/matroska/matroska-read-common.c b/gst/matroska/matroska-read-common.c index 51494a123..f2f1ee1ed 100644 --- a/gst/matroska/matroska-read-common.c +++ b/gst/matroska/matroska-read-common.c @@ -375,30 +375,32 @@ gst_matroska_index_seek_find (GstMatroskaIndex * i1, GstClockTime * time, GstMatroskaIndex * gst_matroska_read_common_do_index_seek (GstMatroskaReadCommon * common, GstMatroskaTrackContext * track, gint64 seek_pos, GArray ** _index, - gint * _entry_index, gboolean next) + gint * _entry_index, GstSearchMode snap_dir) { GstMatroskaIndex *entry = NULL; GArray *index; - if (!common->index || !common->index->len) - return NULL; - /* find entry just before or at the requested position */ if (track && track->index_table) index = track->index_table; else index = common->index; + if (!index || !index->len) + return NULL; + entry = gst_util_array_binary_search (index->data, index->len, sizeof (GstMatroskaIndex), - (GCompareDataFunc) gst_matroska_index_seek_find, - next ? GST_SEARCH_MODE_AFTER : GST_SEARCH_MODE_BEFORE, &seek_pos, NULL); + (GCompareDataFunc) gst_matroska_index_seek_find, snap_dir, &seek_pos, + NULL); if (entry == NULL) { - if (next) { - return NULL; + if (snap_dir == GST_SEARCH_MODE_AFTER) { + /* Can only happen with a reverse seek past the end */ + entry = &g_array_index (index, GstMatroskaIndex, index->len - 1); } else { + /* Can only happen with a forward seek before the start */ entry = &g_array_index (index, GstMatroskaIndex, 0); } } |