basesink: Fix treating base_time as unsigned in position calculation
authorJan Schmidt <thaytan@noraisin.net>
Wed, 11 Nov 2009 17:12:19 +0000 (17:12 +0000)
committerJan Schmidt <thaytan@noraisin.net>
Wed, 11 Nov 2009 17:12:19 +0000 (17:12 +0000)
Element base_time is a signed quantity, which leads to basesink returning
a position of 0 when dealing with a negative base time - which are quite
legal when clocks (such as the audio clock) are close to 0.

This doesn't manifest in normal pipelines, of course - but can happen
(at least) when manually setting the base time on a pipeline.

libs/gst/base/gstbasesink.c

index c7f06a4..7bc76a3 100644 (file)
@@ -4294,7 +4294,8 @@ gst_base_sink_get_position (GstBaseSink * basesink, GstFormat format,
   GstClock *clock;
   gboolean res = FALSE;
   GstFormat oformat, tformat;
-  GstClockTime now, base, latency;
+  GstClockTime now, latency;
+  GstClockTimeDiff base;
   gint64 time, accum, duration;
   gdouble rate;
   gint64 last;
@@ -4375,9 +4376,10 @@ gst_base_sink_get_position (GstBaseSink * basesink, GstFormat format,
    * rate and applied rate. */
   base += accum;
   base += latency;
-  base = MIN (now, base);
+  if (GST_CLOCK_DIFF (base, now) < 0)
+    base = -now;
 
-  /* for negative rates we need to count back from from the segment
+  /* for negative rates we need to count back from the segment
    * duration. */
   if (rate < 0.0)
     time += duration;