event: Make sure that timestamp + diff in QoS events is never smaller than 0
authorSebastian Dröge <sebastian@centricular.com>
Mon, 31 Aug 2015 12:35:11 +0000 (15:35 +0300)
committerSebastian Dröge <sebastian@centricular.com>
Fri, 25 Sep 2015 21:55:18 +0000 (23:55 +0200)
When a running-time-offset is stored in the event, it could become smaller
than 0 although the event is otherwise correct. This can happen when pad
offsets are used.

To prevent this, we set the timestamp to -diff, so that in the end the sum of
both is exactly 0.

https://bugzilla.gnome.org/show_bug.cgi?id=754356

gst/gstevent.c

index 421682c..baeb0f4 100644 (file)
@@ -1057,6 +1057,9 @@ gst_event_parse_qos (GstEvent * event, GstQOSType * type,
             GST_QUARK (DIFF)));
   if (timestamp) {
     gint64 offset = gst_event_get_running_time_offset (event);
+    GstClockTimeDiff diff_ =
+        g_value_get_int64 (gst_structure_id_get_value (structure,
+            GST_QUARK (DIFF)));
 
     *timestamp =
         g_value_get_uint64 (gst_structure_id_get_value (structure,
@@ -1066,6 +1069,11 @@ gst_event_parse_qos (GstEvent * event, GstQOSType * type,
       *timestamp += offset;
     else
       *timestamp = 0;
+
+    /* Make sure that timestamp + diff is always >= 0. Because
+     * of the running time offset this might not be true */
+    if (diff_ < 0 && *timestamp < -diff_)
+      *timestamp = (GstClockTime) - diff_;
   }
 }