avimux: use running time for synchronization
authorMark Nauwelaerts <mark.nauwelaerts@collabora.co.uk>
Tue, 22 Mar 2011 18:35:58 +0000 (19:35 +0100)
committerMark Nauwelaerts <mark.nauwelaerts@collabora.co.uk>
Tue, 22 Mar 2011 19:55:27 +0000 (20:55 +0100)
See bug #432612.

gst/avi/gstavimux.c

index d0d2f0e..37f9291 100644 (file)
@@ -1916,6 +1916,11 @@ gst_avi_mux_do_buffer (GstAviMux * avimux, GstAviPad * avipad)
   guint flags;
 
   data = gst_collect_pads_pop (avimux->collect, avipad->collect);
+  /* arrange downstream running time */
+  data = gst_buffer_make_metadata_writable (data);
+  GST_BUFFER_TIMESTAMP (data) =
+      gst_segment_to_running_time (&avipad->collect->segment,
+      GST_FORMAT_TIME, GST_BUFFER_TIMESTAMP (data));
 
   /* Prepend a special buffer to the first one for some formats */
   if (avipad->is_video) {
@@ -2042,6 +2047,19 @@ gst_avi_mux_do_one_buffer (GstAviMux * avimux)
     time = GST_BUFFER_TIMESTAMP (buffer);
     gst_buffer_unref (buffer);
 
+    /* invalid should pass */
+    if (G_LIKELY (GST_CLOCK_TIME_IS_VALID (time))) {
+      time = gst_segment_to_running_time (&avipad->collect->segment,
+          GST_FORMAT_TIME, time);
+      if (G_UNLIKELY (!GST_CLOCK_TIME_IS_VALID (time))) {
+        GST_DEBUG_OBJECT (avimux, "clipping buffer on pad %s outside segment",
+            GST_PAD_NAME (avipad->collect->pad));
+        buffer = gst_collect_pads_pop (avimux->collect, avipad->collect);
+        gst_buffer_unref (buffer);
+        return GST_FLOW_OK;
+      }
+    }
+
     delay = avipad->is_video ? GST_SECOND / 2 : 0;
 
     /* invalid timestamp buffers pass first,