basesink: improve adjust_time()
authorWim Taymans <wim.taymans@collabora.co.uk>
Fri, 24 Sep 2010 10:22:33 +0000 (12:22 +0200)
committerWim Taymans <wim.taymans@collabora.co.uk>
Fri, 24 Sep 2010 10:22:33 +0000 (12:22 +0200)
Add some more comments.
Make sure we don't end up with negative timestamps.

libs/gst/base/gstbasesink.c

index 612fecc..a14542a 100644 (file)
@@ -2005,7 +2005,8 @@ out_of_segment:
 }
 
 /* with STREAM_LOCK, PREROLL_LOCK, LOCK
- * adjust a timestamp with the latency and timestamp offset */
+ * adjust a timestamp with the latency and timestamp offset. This function does
+ * not adjust for the render delay. */
 static GstClockTime
 gst_base_sink_adjust_time (GstBaseSink * basesink, GstClockTime time)
 {
@@ -2015,7 +2016,7 @@ gst_base_sink_adjust_time (GstBaseSink * basesink, GstClockTime time)
   if (G_UNLIKELY (!GST_CLOCK_TIME_IS_VALID (time)))
     return time;
 
-  time += basesink->priv->latency - basesink->priv->render_delay;
+  time += basesink->priv->latency;
 
   /* apply offset, be carefull for underflows */
   ts_offset = basesink->priv->ts_offset;
@@ -2028,6 +2029,12 @@ gst_base_sink_adjust_time (GstBaseSink * basesink, GstClockTime time)
   } else
     time += ts_offset;
 
+  /* subtract the render delay again, which was included in the latency */
+  if (time > basesink->priv->render_delay)
+    time -= basesink->priv->render_delay;
+  else
+    time = 0;
+
   return time;
 }