From 29e23e9142ed2bf6fa1357aeb92763cb8c7e201e Mon Sep 17 00:00:00 2001 From: Wim Taymans Date: Fri, 24 Sep 2010 12:22:33 +0200 Subject: [PATCH] basesink: improve adjust_time() Add some more comments. Make sure we don't end up with negative timestamps. --- libs/gst/base/gstbasesink.c | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/libs/gst/base/gstbasesink.c b/libs/gst/base/gstbasesink.c index 612feccccc..a14542a105 100644 --- a/libs/gst/base/gstbasesink.c +++ b/libs/gst/base/gstbasesink.c @@ -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; }