summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSebastian Dröge <sebastian@centricular.com>2018-03-05 12:48:15 +0200
committerSebastian Dröge <sebastian@centricular.com>2018-03-20 12:08:28 +0200
commit850e678813f11b439994d434f2800bfbbb140864 (patch)
tree2fc9247bb4d7a5d2ce21fdb6f400704b2b53c834
parented2ccb1a60f6756b5c59df40460dc2dd0b7f7f37 (diff)
qtdemux: Fix seeking on streams with frame reordering
The samples table is sorted by DTS, not PTS. As such we can only get the correct result when using a binary search on it, if we search for the DTS. Also if we only ever search for the frame, where the following frame is the first one with a PTS after the search position, we will generally stop searching too early if frames are reordered. In forwards playback this is not really a problem (after the decoder reordered the frames, clipping is happening), in reverse playback it means that we can output one or more frames too few as we stop too early and the decoder would never receive it. https://bugzilla.gnome.org/show_bug.cgi?id=782118
-rw-r--r--gst/isomp4/qtdemux.c37
1 files changed, 24 insertions, 13 deletions
diff --git a/gst/isomp4/qtdemux.c b/gst/isomp4/qtdemux.c
index a6f870f03..cadb544ff 100644
--- a/gst/isomp4/qtdemux.c
+++ b/gst/isomp4/qtdemux.c
@@ -1055,9 +1055,9 @@ typedef struct
static gint
find_func (QtDemuxSample * s1, gint64 * media_time, gpointer user_data)
{
- if ((gint64) s1->timestamp + s1->pts_offset > *media_time)
+ if ((gint64) s1->timestamp > *media_time)
return 1;
- if ((gint64) s1->timestamp + s1->pts_offset == *media_time)
+ if ((gint64) s1->timestamp == *media_time)
return 0;
return -1;
@@ -1066,7 +1066,7 @@ find_func (QtDemuxSample * s1, gint64 * media_time, gpointer user_data)
/* find the index of the sample that includes the data for @media_time using a
* binary search. Only to be called in optimized cases of linear search below.
*
- * Returns the index of the sample.
+ * Returns the index of the sample with the corresponding *DTS*.
*/
static guint32
gst_qtdemux_find_index (GstQTDemux * qtdemux, QtDemuxStream * str,
@@ -1156,20 +1156,31 @@ gst_qtdemux_find_index_linear (GstQTDemux * qtdemux, QtDemuxStream * str,
/* use faster search if requested time in already parsed range */
sample = str->samples + str->stbl_index;
- if (str->stbl_index >= 0 &&
- mov_time <= (sample->timestamp + sample->pts_offset))
- return gst_qtdemux_find_index (qtdemux, str, media_time);
+ if (str->stbl_index >= 0 && mov_time <= sample->timestamp) {
+ index = gst_qtdemux_find_index (qtdemux, str, media_time);
+ sample = str->samples + index;
+ } else {
+ while (index < str->n_samples - 1) {
+ if (!qtdemux_parse_samples (qtdemux, str, index + 1))
+ goto parse_failed;
- while (index < str->n_samples - 1) {
- if (!qtdemux_parse_samples (qtdemux, str, index + 1))
- goto parse_failed;
+ sample = str->samples + index + 1;
+ if (mov_time < sample->timestamp) {
+ sample = str->samples + index;
+ break;
+ }
- sample = str->samples + index + 1;
- if (mov_time < (sample->timestamp + sample->pts_offset))
- break;
+ index++;
+ }
+ }
- index++;
+ /* sample->timestamp is now <= media_time, need to find the corresponding
+ * PTS now by looking backwards */
+ while (index > 0 && sample->timestamp + sample->pts_offset > mov_time) {
+ index--;
+ sample = str->samples + index;
}
+
return index;
/* ERRORS */