From ba943a82c0bbfd17c9ee9f5068d44c9d9274fd13 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sebastian=20Dr=C3=B6ge?= Date: Tue, 18 Mar 2014 18:11:15 +0100 Subject: [PATCH] basesink: Update start time when we lose our state Otherwise we report not the correct position while the state is lost. --- libs/gst/base/gstbasesink.c | 40 +++++++++++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) diff --git a/libs/gst/base/gstbasesink.c b/libs/gst/base/gstbasesink.c index 702d801c6e..ef100859e6 100644 --- a/libs/gst/base/gstbasesink.c +++ b/libs/gst/base/gstbasesink.c @@ -2856,6 +2856,44 @@ gst_base_sink_do_render_stats (GstBaseSink * basesink, gboolean start) } } +static void +gst_base_sink_update_start_time (GstBaseSink * basesink) +{ + GstClock *clock; + + GST_OBJECT_LOCK (basesink); + if ((clock = GST_ELEMENT_CLOCK (basesink))) { + GstClockTime now; + + gst_object_ref (clock); + GST_OBJECT_UNLOCK (basesink); + + /* calculate the time when we stopped */ + now = gst_clock_get_time (clock); + gst_object_unref (clock); + + GST_OBJECT_LOCK (basesink); + /* store the current running time */ + if (GST_ELEMENT_START_TIME (basesink) != GST_CLOCK_TIME_NONE) { + if (now != GST_CLOCK_TIME_NONE) + GST_ELEMENT_START_TIME (basesink) = + now - GST_ELEMENT_CAST (basesink)->base_time; + else + GST_WARNING_OBJECT (basesink, + "Clock %s returned invalid time, can't calculate " + "running_time when going to the PAUSED state", + GST_OBJECT_NAME (clock)); + } + GST_DEBUG_OBJECT (basesink, + "start_time=%" GST_TIME_FORMAT ", now=%" GST_TIME_FORMAT + ", base_time %" GST_TIME_FORMAT, + GST_TIME_ARGS (GST_ELEMENT_START_TIME (basesink)), + GST_TIME_ARGS (now), + GST_TIME_ARGS (GST_ELEMENT_CAST (basesink)->base_time)); + } + GST_OBJECT_UNLOCK (basesink); +} + static void gst_base_sink_flush_start (GstBaseSink * basesink, GstPad * pad) { @@ -2872,6 +2910,7 @@ gst_base_sink_flush_start (GstBaseSink * basesink, GstPad * pad) * prerolled buffer */ basesink->playing_async = TRUE; if (basesink->priv->async_enabled) { + gst_base_sink_update_start_time (basesink); gst_element_lost_state (GST_ELEMENT_CAST (basesink)); } else { /* start time reset in above case as well; @@ -3819,6 +3858,7 @@ gst_base_sink_perform_step (GstBaseSink * sink, GstPad * pad, GstEvent * event) sink->playing_async = TRUE; priv->pending_step.need_preroll = TRUE; sink->need_preroll = FALSE; + gst_base_sink_update_start_time (sink); gst_element_lost_state (GST_ELEMENT_CAST (sink)); } else { sink->priv->have_latency = TRUE;