videoencoder: use oldest frame PTS to estimate missing outgoing DTS
authorMark Nauwelaerts <mark.nauwelaerts@collabora.co.uk>
Wed, 26 Sep 2012 14:31:27 +0000 (16:31 +0200)
committerMark Nauwelaerts <mark.nauwelaerts@collabora.co.uk>
Wed, 26 Sep 2012 14:32:37 +0000 (16:32 +0200)
gst-libs/gst/video/gstvideoencoder.c

index 79999f3..63e2d02 100644 (file)
@@ -1757,6 +1757,17 @@ gst_video_encoder_finish_frame (GstVideoEncoder * encoder,
     GST_BUFFER_FLAG_SET (frame->output_buffer, GST_BUFFER_FLAG_DELTA_UNIT);
   }
 
+  /* DTS is expected monotone ascending, so a good guess is the lowest PTS
+   * of all pending frames, i.e. the oldest frame's PTS (all being OK) */
+  if (!GST_CLOCK_TIME_IS_VALID (frame->dts) && encoder->priv->frames) {
+    GstVideoCodecFrame *oframe = encoder->priv->frames->data;
+
+    frame->dts = oframe->pts;
+    GST_DEBUG_OBJECT (encoder,
+        "no valid DTS, using oldest frame's PTS %" GST_TIME_FORMAT,
+        GST_TIME_ARGS (frame->pts));
+  }
+
   frame->distance_from_sync = priv->distance_from_sync;
   priv->distance_from_sync++;