qtdemux: push buffers after segment stop until reaching a keyframe
authorThiago Santos <thiago.sousa.santos@collabora.com>
Tue, 27 Aug 2013 20:33:40 +0000 (17:33 -0300)
committerThiago Santos <thiago.sousa.santos@collabora.com>
Wed, 28 Aug 2013 15:58:56 +0000 (12:58 -0300)
This should make decoders able to precisely push buffers until the stop
time in case they need the next keyframe to do it.

Also, according to gst_segment_clip, it should only push a buffer that
the starting ts is strictly smaller than the segment stop, so we change
the min < comparison for <=

gst/isomp4/qtdemux.c

index 4c7a90b..36b6fbe 100644 (file)
@@ -206,6 +206,10 @@ struct _QtDemuxStream
 
   gboolean new_caps;
   gboolean new_stream;          /* signals that a stream_start is required */
+  gboolean on_keyframe;         /* if this stream last pushed buffer was a
+                                 * keyframe. This is important to identify
+                                 * where to stop pushing buffers after a
+                                 * segment stop time */
 
   /* if the stream has a redirect URI in its headers, we store it here */
   gchar *redirect_uri;
@@ -4067,8 +4071,13 @@ gst_qtdemux_decorate_and_push_buffer (GstQTDemux * qtdemux,
     GST_BUFFER_FLAG_UNSET (buf, GST_BUFFER_FLAG_DISCONT);
   }
 
-  if (!keyframe)
+  if (!keyframe) {
     GST_BUFFER_FLAG_SET (buf, GST_BUFFER_FLAG_DELTA_UNIT);
+    stream->on_keyframe = FALSE;
+  } else {
+    stream->on_keyframe = TRUE;
+  }
+
 
   GST_LOG_OBJECT (qtdemux,
       "Pushing buffer with dts %" GST_TIME_FORMAT ", pts %" GST_TIME_FORMAT
@@ -4130,7 +4139,8 @@ gst_qtdemux_loop_state_movie (GstQTDemux * qtdemux)
 
   /* check for segment end */
   if (G_UNLIKELY (qtdemux->segment.stop != -1
-          && qtdemux->segment.stop < min_time)) {
+          && qtdemux->segment.stop <= min_time
+          && qtdemux->streams[index]->on_keyframe)) {
     GST_DEBUG_OBJECT (qtdemux, "we reached the end of our segment.");
     goto eos;
   }