qtdemux: Always snap to the start of the keyframe

When performing a key-unit seek, always snap to the start ts
of the keyframe buffer we landed on so that the keyframe is
entirely within the resulting outgoing segment. That seems
the most sensible result, since the user requested snapping
to the keyframe position.
This commit is contained in:
Jan Schmidt 2016-12-31 01:54:01 +11:00
parent f415730fdf
commit 107902ec51

View file

@ -1294,7 +1294,7 @@ gst_qtdemux_adjust_seek (GstQTDemux * qtdemux, gint64 desired_time,
* and move back to the previous keyframe. */ * and move back to the previous keyframe. */
for (n = 0; n < qtdemux->n_streams; n++) { for (n = 0; n < qtdemux->n_streams; n++) {
QtDemuxStream *str; QtDemuxStream *str;
guint32 index, kindex; guint32 index;
guint32 seg_idx; guint32 seg_idx;
GstClockTime media_start; GstClockTime media_start;
GstClockTime media_time; GstClockTime media_time;
@ -1348,37 +1348,33 @@ gst_qtdemux_adjust_seek (GstQTDemux * qtdemux, gint64 desired_time,
if (!empty_segment) { if (!empty_segment) {
/* find previous keyframe */ /* find previous keyframe */
kindex = gst_qtdemux_find_keyframe (qtdemux, str, index, next); index = gst_qtdemux_find_keyframe (qtdemux, str, index, next);
/* we will settle for one before if none found after */ /* we will settle for one before if none found after */
if (next && kindex == -1) if (next && index == -1)
kindex = gst_qtdemux_find_keyframe (qtdemux, str, index, FALSE); index = gst_qtdemux_find_keyframe (qtdemux, str, index, FALSE);
/* if the keyframe is at a different position, we need to update the /* Snap to the start ts of the keyframe we found */
* requested seek time */
if (index != kindex) {
index = kindex;
/* get timestamp of keyframe */ /* get timestamp of keyframe */
media_time = QTSAMPLE_PTS_NO_CSLG (str, &str->samples[kindex]); media_time = QTSAMPLE_PTS_NO_CSLG (str, &str->samples[index]);
GST_DEBUG_OBJECT (qtdemux, GST_DEBUG_OBJECT (qtdemux,
"keyframe at %u with time %" GST_TIME_FORMAT " at offset %" "keyframe at %u with time %" GST_TIME_FORMAT " at offset %"
G_GUINT64_FORMAT, kindex, GST_TIME_ARGS (media_time), G_GUINT64_FORMAT, index, GST_TIME_ARGS (media_time),
str->samples[kindex].offset); str->samples[index].offset);
/* keyframes in the segment get a chance to change the /* keyframes in the segment get a chance to change the
* desired_offset. keyframes out of the segment are * desired_offset. keyframes out of the segment are
* ignored. */ * ignored. */
if (media_time >= seg->media_start) { if (media_time >= seg->media_start) {
GstClockTime seg_time; GstClockTime seg_time;
/* this keyframe is inside the segment, convert back to /* this keyframe is inside the segment, convert back to
* segment time */ * segment time */
seg_time = (media_time - seg->media_start) + seg->time; seg_time = (media_time - seg->media_start) + seg->time;
if ((!next && (seg_time < min_offset)) || if ((!next && (seg_time < min_offset)) ||
(next && (seg_time > min_offset))) (next && (seg_time > min_offset)))
min_offset = seg_time; min_offset = seg_time;
}
} }
} }