[Converter] set timestamp when buffer has invalid ts
authorJaeyun <jy1210.jung@samsung.com>
Fri, 26 Oct 2018 09:36:39 +0000 (18:36 +0900)
committerMyungJoo Ham <myungjoo.ham@gmail.com>
Mon, 29 Oct 2018 08:18:41 +0000 (08:18 +0000)
When set-timestamp is true and incoming buffer has invalid timestamp, set the timestamp using given framerate.
If caps does not include the framerate info, then it will set current time.

Signed-off-by: Jaeyun Jung <jy1210.jung@samsung.com>
gst/tensor_converter/tensor_converter.c
gst/tensor_converter/tensor_converter.h

index 402885a..b3024db 100644 (file)
@@ -708,21 +708,53 @@ gst_tensor_converter_chain (GstPad * pad, GstObject * parent, GstBuffer * buf)
     gst_pad_push_event (self->srcpad, gst_event_new_segment (&seg));
   }
 
-  /**
-   * @todo fill here
-   */
   if (self->set_timestamp) {
     /* set duration */
-    if (!GST_BUFFER_DURATION_IS_VALID (inbuf)) {
+    duration = GST_BUFFER_DURATION (inbuf);
+
+    if (!GST_CLOCK_TIME_IS_VALID (duration)) {
+      if (have_framerate) {
+        duration =
+            gst_util_uint64_scale_int (frames_in * config->rate_d, GST_SECOND,
+            config->rate_n);
+
+        GST_BUFFER_DURATION (inbuf) = duration;
+      }
     }
 
     /* set timestamp if buffer has invalid timestamp */
     pts = GST_BUFFER_TIMESTAMP (inbuf);
 
     if (!GST_CLOCK_TIME_IS_VALID (pts)) {
+      pts = self->segment.start;
+
+      if (have_framerate) {
+        if (GST_CLOCK_TIME_IS_VALID (self->old_timestamp)) {
+          pts = self->old_timestamp + duration;
+        }
+      } else {
+        GstClock *clock;
+
+        clock = gst_element_get_clock (GST_ELEMENT (self));
+
+        if (clock) {
+          GstClockTime now, base;
+
+          base = gst_element_get_base_time (GST_ELEMENT (self));
+          now = gst_clock_get_time (clock);
+
+          pts = (base < now) ? (now - base) : 0;
+          gst_object_unref (clock);
+        }
+      }
+
+      GST_BUFFER_TIMESTAMP (inbuf) = pts;
     }
   }
 
+  /* update old timestamp */
+  self->old_timestamp = GST_BUFFER_TIMESTAMP (inbuf);
+
   if (frames_in == frames_out) {
     silent_debug_timestamp (inbuf);
 
@@ -833,6 +865,8 @@ gst_tensor_converter_reset (GstTensorConverter * self)
   self->have_segment = FALSE;
   self->need_segment = FALSE;
   gst_segment_init (&self->segment, GST_FORMAT_TIME);
+
+  self->old_timestamp = GST_CLOCK_TIME_NONE;
 }
 
 /**
index c1d06fc..28a65e3 100644 (file)
@@ -86,6 +86,7 @@ struct _GstTensorConverter
   gboolean have_segment; /**< True if received segment */
   gboolean need_segment; /**< True to handle seg event */
   GstSegment segment; /**< Segment, supposed time format */
+  GstClockTime old_timestamp; /**< timestamp at prev buffer */
 };
 
 /**