[Converter/Aggregator] update timestamp
authorJaeyun <jy1210.jung@samsung.com>
Tue, 16 Oct 2018 11:26:05 +0000 (20:26 +0900)
committerMyungJoo Ham <myungjoo.ham@gmail.com>
Wed, 17 Oct 2018 06:33:00 +0000 (15:33 +0900)
1. set timestamp at first frame
2. add duration in output buffer

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

index 71830cd..1fc4210 100644 (file)
@@ -798,6 +798,7 @@ gst_tensor_aggregator_chain (GstPad * pad, GstObject * parent, GstBuffer * buf)
   GstAdapter *adapter;
   gsize avail, buf_size, frame_size, out_size;
   guint frames_in, frames_out, frames_flush;
+  GstClockTime duration;
 
   self = GST_TENSOR_AGGREGATOR (parent);
   g_assert (self->tensor_configured);
@@ -819,6 +820,12 @@ gst_tensor_aggregator_chain (GstPad * pad, GstObject * parent, GstBuffer * buf)
   adapter = self->adapter;
   g_assert (adapter != NULL);
 
+  duration = GST_BUFFER_DURATION (buf);
+  if (GST_CLOCK_TIME_IS_VALID (duration)) {
+    /** supposed same duration for incoming buffer */
+    duration = gst_util_uint64_scale_int (duration, frames_out, frames_in);
+  }
+
   gst_adapter_push (adapter, buf);
 
   out_size = frame_size * frames_out;
@@ -829,16 +836,13 @@ gst_tensor_aggregator_chain (GstPad * pad, GstObject * parent, GstBuffer * buf)
     GstBuffer *outbuf;
     GstClockTime pts, dts;
     guint64 pts_dist, dts_dist;
-    gsize flush, offset;
-
-    /** offset for last frame */
-    offset = frame_size * (frames_out - 1) + 1; /** +1 byte */
+    gsize flush;
 
-    pts = gst_adapter_prev_pts_at_offset (adapter, offset, &pts_dist);
-    dts = gst_adapter_prev_dts_at_offset (adapter, offset, &dts_dist);
+    pts = gst_adapter_prev_pts (adapter, &pts_dist);
+    dts = gst_adapter_prev_dts (adapter, &dts_dist);
 
     /**
-     * Update timestamp of last frame.
+     * Update timestamp.
      * If frames-in is larger then frames-out, the same timestamp (pts and dts) would be returned.
      */
     if (frames_in > 1) {
@@ -849,13 +853,13 @@ gst_tensor_aggregator_chain (GstPad * pad, GstObject * parent, GstBuffer * buf)
 
       if (fn > 0 && fd > 0) {
         if (GST_CLOCK_TIME_IS_VALID (pts)) {
-          pts =
+          pts +=
               gst_util_uint64_scale_int (pts_dist * fd, GST_SECOND,
               fn * frame_size);
         }
 
         if (GST_CLOCK_TIME_IS_VALID (dts)) {
-          dts =
+          dts +=
               gst_util_uint64_scale_int (dts_dist * fd, GST_SECOND,
               fn * frame_size);
         }
@@ -868,6 +872,7 @@ gst_tensor_aggregator_chain (GstPad * pad, GstObject * parent, GstBuffer * buf)
     /** set timestamp */
     GST_BUFFER_PTS (outbuf) = pts;
     GST_BUFFER_DTS (outbuf) = dts;
+    GST_BUFFER_DURATION (outbuf) = duration;
 
     ret = gst_tensor_aggregator_push (self, outbuf, frame_size);
 
index 6e9bdf6..b70988a 100644 (file)
@@ -506,6 +506,7 @@ gst_tensor_converter_chain (GstPad * pad, GstObject * parent, GstBuffer * buf)
   gsize avail, buf_size, frame_size, out_size;
   guint frames_in, frames_out;
   GstFlowReturn ret = GST_FLOW_OK;
+  GstClockTime duration;
 
   buf_size = gst_buffer_get_size (buf);
   g_return_val_if_fail (buf_size > 0, GST_FLOW_ERROR);
@@ -573,7 +574,7 @@ gst_tensor_converter_chain (GstPad * pad, GstObject * parent, GstBuffer * buf)
         gst_buffer_unmap (inbuf, &dest_info);
 
         /** copy timestamps */
-        gst_buffer_copy_into (inbuf, buf, GST_BUFFER_COPY_TIMESTAMPS, 0, -1);
+        gst_buffer_copy_into (inbuf, buf, GST_BUFFER_COPY_METADATA, 0, -1);
       }
       break;
     }
@@ -602,7 +603,7 @@ gst_tensor_converter_chain (GstPad * pad, GstObject * parent, GstBuffer * buf)
         gst_buffer_unmap (inbuf, &dest_info);
 
         /** copy timestamps */
-        gst_buffer_copy_into (inbuf, buf, GST_BUFFER_COPY_TIMESTAMPS, 0, -1);
+        gst_buffer_copy_into (inbuf, buf, GST_BUFFER_COPY_METADATA, 0, -1);
       }
       break;
 
@@ -628,6 +629,12 @@ gst_tensor_converter_chain (GstPad * pad, GstObject * parent, GstBuffer * buf)
   adapter = self->adapter;
   g_assert (adapter != NULL);
 
+  duration = GST_BUFFER_DURATION (inbuf);
+  if (GST_CLOCK_TIME_IS_VALID (duration)) {
+    /** supposed same duration for incoming buffer */
+    duration = gst_util_uint64_scale_int (duration, frames_out, frames_in);
+  }
+
   gst_adapter_push (adapter, inbuf);
 
   out_size = frames_out * frame_size;
@@ -636,16 +643,12 @@ gst_tensor_converter_chain (GstPad * pad, GstObject * parent, GstBuffer * buf)
     GstBuffer *outbuf;
     GstClockTime pts, dts;
     guint64 pts_dist, dts_dist;
-    gsize offset;
-
-    /** offset for last frame */
-    offset = frame_size * (frames_out - 1) + 1; /** +1 byte */
 
-    pts = gst_adapter_prev_pts_at_offset (adapter, offset, &pts_dist);
-    dts = gst_adapter_prev_dts_at_offset (adapter, offset, &dts_dist);
+    pts = gst_adapter_prev_pts (adapter, &pts_dist);
+    dts = gst_adapter_prev_dts (adapter, &dts_dist);
 
     /**
-     * Update timestamp of last frame.
+     * Update timestamp.
      * If frames-in is larger then frames-out, the same timestamp (pts and dts) would be returned.
      */
     if (frames_in > 1) {
@@ -656,13 +659,13 @@ gst_tensor_converter_chain (GstPad * pad, GstObject * parent, GstBuffer * buf)
 
       if (fn > 0 && fd > 0) {
         if (GST_CLOCK_TIME_IS_VALID (pts)) {
-          pts =
+          pts +=
               gst_util_uint64_scale_int (pts_dist * fd, GST_SECOND,
               fn * frame_size);
         }
 
         if (GST_CLOCK_TIME_IS_VALID (dts)) {
-          dts =
+          dts +=
               gst_util_uint64_scale_int (dts_dist * fd, GST_SECOND,
               fn * frame_size);
         }
@@ -675,6 +678,7 @@ gst_tensor_converter_chain (GstPad * pad, GstObject * parent, GstBuffer * buf)
     /** set timestamp */
     GST_BUFFER_PTS (outbuf) = pts;
     GST_BUFFER_DTS (outbuf) = dts;
+    GST_BUFFER_DURATION (outbuf) = duration;
 
     ret = gst_pad_push (self->srcpad, outbuf);
   }