basesink: improve position reporting without clock
authorWim Taymans <wim.taymans@collabora.co.uk>
Thu, 30 May 2013 04:51:24 +0000 (06:51 +0200)
committerWim Taymans <wim.taymans@collabora.co.uk>
Thu, 30 May 2013 04:51:24 +0000 (06:51 +0200)
When no base time or when sync is disabled, use the same logic as
in paused to report position. The logic in PLAYING assumes we use the
clock.

libs/gst/base/gstbasesink.c

index eb3ca1b..d517fed 100644 (file)
@@ -4372,14 +4372,36 @@ gst_base_sink_get_position (GstBaseSink * basesink, GstFormat format,
   rate = segment->rate * segment->applied_rate;
   latency = basesink->priv->latency;
 
+  if (in_paused) {
+    /* in paused, use start_time */
+    base_time = GST_ELEMENT_START_TIME (basesink);
+    GST_DEBUG_OBJECT (basesink, "in paused, using start time %" GST_TIME_FORMAT,
+        GST_TIME_ARGS (base_time));
+  } else if (with_clock) {
+    /* else use clock when needed */
+    base_time = GST_ELEMENT_CAST (basesink)->base_time;
+    GST_DEBUG_OBJECT (basesink, "using clock and base time %" GST_TIME_FORMAT,
+        GST_TIME_ARGS (base_time));
+  } else {
+    /* else, no sync or clock -> no base time */
+    GST_DEBUG_OBJECT (basesink, "no sync or no clock");
+    base_time = -1;
+  }
+
+  /* no base_time, we can't calculate running_time, use last seem timestamp to report
+   * time */
+  if (base_time == -1)
+    last_seen = TRUE;
+
   if (oformat == GST_FORMAT_TIME) {
     gint64 start, stop;
 
     start = basesink->priv->current_sstart;
     stop = basesink->priv->current_sstop;
 
-    if (in_paused) {
-      /* in paused we use the last position as a lower bound */
+    if (in_paused || last_seen) {
+      /* in paused or when we don't use the clock, we use the last position
+       * as a lower bound */
       if (stop == -1 || segment->rate > 0.0)
         last = start;
       else
@@ -4398,33 +4420,12 @@ gst_base_sink_get_position (GstBaseSink * basesink, GstFormat format,
           GST_TIME_ARGS (last));
     }
   } else {
-    /* convert last stop to stream time */
+    /* convert position to stream time */
     last = gst_segment_to_stream_time (segment, oformat, segment->position);
 
     GST_DEBUG_OBJECT (basesink, "in using last %" G_GINT64_FORMAT, last);
   }
 
-  if (in_paused) {
-    /* in paused, use start_time */
-    base_time = GST_ELEMENT_START_TIME (basesink);
-    GST_DEBUG_OBJECT (basesink, "in paused, using start time %" GST_TIME_FORMAT,
-        GST_TIME_ARGS (base_time));
-  } else if (with_clock) {
-    /* else use clock when needed */
-    base_time = GST_ELEMENT_CAST (basesink)->base_time;
-    GST_DEBUG_OBJECT (basesink, "using clock and base time %" GST_TIME_FORMAT,
-        GST_TIME_ARGS (base_time));
-  } else {
-    /* else, no sync or clock -> no base time */
-    GST_DEBUG_OBJECT (basesink, "no sync or no clock");
-    base_time = -1;
-  }
-
-  /* no base_time, we can't calculate running_time, use last seem timestamp to report
-   * time */
-  if (base_time == -1)
-    last_seen = TRUE;
-
   /* need to release the object lock before we can get the time,
    * a clock might take the LOCK of the provider, which could be
    * a basesink subclass. */