appsrc: If do-timestamp=TRUE, capture the time when the buffer was pushed to the...
authorSebastian Dröge <sebastian@centricular.com>
Wed, 16 Mar 2016 22:19:18 +0000 (00:19 +0200)
committerSebastian Dröge <sebastian@centricular.com>
Fri, 1 Jul 2016 12:32:26 +0000 (14:32 +0200)
... instead of the time when it was pushed further downstream.

https://bugzilla.gnome.org/show_bug.cgi?id=763630

gst-libs/gst/app/gstappsrc.c

index 026a770..dcbed51 100644 (file)
@@ -1707,6 +1707,40 @@ gst_app_src_push_buffer_full (GstAppSrc * appsrc, GstBuffer * buffer,
 
   priv = appsrc->priv;
 
+  if (GST_BUFFER_DTS (buffer) == GST_CLOCK_TIME_NONE &&
+      GST_BUFFER_PTS (buffer) == GST_CLOCK_TIME_NONE &&
+      gst_base_src_get_do_timestamp (GST_BASE_SRC_CAST (appsrc))) {
+    GstClock *clock;
+
+    clock = gst_element_get_clock (GST_ELEMENT_CAST (appsrc));
+    if (clock) {
+      GstClockTime now;
+      GstClockTime base_time =
+          gst_element_get_base_time (GST_ELEMENT_CAST (appsrc));
+
+      now = gst_clock_get_time (clock);
+      if (now > base_time)
+        now -= base_time;
+      else
+        now = 0;
+      gst_object_unref (clock);
+
+      if (!steal_ref)
+        buffer = gst_buffer_copy (buffer);
+      else
+        buffer = gst_buffer_make_writable (buffer);
+
+      GST_BUFFER_PTS (buffer) = now;
+      GST_BUFFER_DTS (buffer) = now;
+      steal_ref = TRUE;
+    } else {
+      GST_WARNING_OBJECT (appsrc,
+          "do-timestamp=TRUE but buffers are provided before "
+          "reaching the PLAYING state and having a clock. Timestamps will "
+          "not be accurate!");
+    }
+  }
+
   g_mutex_lock (&priv->mutex);
 
   while (TRUE) {