flvmux: Force timestamps to always be increasing
authorOlivier Crête <olivier.crete@collabora.com>
Sat, 27 Oct 2018 18:27:12 +0000 (19:27 +0100)
committerOlivier Crête <olivier.crete@collabora.com>
Mon, 5 Nov 2018 23:17:01 +0000 (18:17 -0500)
https://bugzilla.gnome.org/show_bug.cgi?id=796382

gst/flv/gstflvmux.c
gst/flv/gstflvmux.h

index c094016..a37acd4 100644 (file)
@@ -322,6 +322,7 @@ gst_flv_mux_reset (GstElement * element)
   mux->duration = GST_CLOCK_TIME_NONE;
   mux->new_tags = FALSE;
   mux->first_timestamp = GST_CLOCK_STIME_NONE;
+  mux->last_dts = 0;
 
   mux->state = GST_FLV_MUX_STATE_HEADER;
   mux->sent_header = FALSE;
@@ -1145,6 +1146,19 @@ gst_flv_mux_buffer_to_tag_internal (GstFlvMux * mux, GstBuffer * buffer,
     dts = pad->dts / GST_MSECOND;
   }
 
+  /* We prevent backwards timestamps because they confuse librtmp,
+   * it expects timestamps to go forward not only inside one stream, but
+   * also between the audio & video streams.
+   */
+  if (dts < mux->last_dts) {
+    GST_WARNING_OBJECT (pad, "Got backwards dts! (%" GST_TIME_FORMAT
+        " < %" GST_TIME_FORMAT ")", GST_TIME_ARGS (dts),
+        GST_TIME_ARGS (mux->last_dts));
+    dts = mux->last_dts;
+  }
+  mux->last_dts = dts;
+
+
   /* Be safe in case TS are buggy */
   if (pts > dts)
     cts = pts - dts;
@@ -1190,6 +1204,7 @@ gst_flv_mux_buffer_to_tag_internal (GstFlvMux * mux, GstBuffer * buffer,
   data[2] = ((size - 11 - 4) >> 8) & 0xff;
   data[3] = ((size - 11 - 4) >> 0) & 0xff;
 
+
   GST_WRITE_UINT24_BE (data + 4, dts);
   data[7] = (((guint) dts) >> 24) & 0xff;
 
index e116d4c..d2ad8da 100644 (file)
@@ -98,6 +98,7 @@ typedef struct _GstFlvMux {
   guint64 byte_count;
   guint64 duration;
   gint64 first_timestamp;
+  GstClockTime last_dts;
 
   gboolean sent_header;
 } GstFlvMux;