qtmux: correctly calculate overall first_ts to ensure stream sync
authorMark Nauwelaerts <mnauw@users.sourceforge.net>
Mon, 19 Jun 2017 19:13:42 +0000 (21:13 +0200)
committerMark Nauwelaerts <mnauw@users.sourceforge.net>
Sat, 24 Jun 2017 15:36:54 +0000 (17:36 +0200)
... by minding and compensating for the dts_adjustment that may have
been introduced in the PTS timeline.

gst/isomp4/gstqtmux.c
gst/isomp4/gstqtmux.h

index ba5539b..7169572 100644 (file)
@@ -3037,14 +3037,24 @@ gst_qt_mux_update_global_statistics (GstQTMux * qtmux)
 
     /* having flushed above, can check for buffers now */
     if (GST_CLOCK_TIME_IS_VALID (qtpad->first_ts)) {
+      GstClockTime first_pts_in = qtpad->first_ts;
+      /* it should be, since we got first_ts by adding adjustment
+       * to a positive incoming PTS */
+      if (qtpad->dts_adjustment <= first_pts_in)
+        first_pts_in -= qtpad->dts_adjustment;
       /* determine max stream duration */
       if (!GST_CLOCK_TIME_IS_VALID (qtmux->last_dts)
           || qtpad->last_dts > qtmux->last_dts) {
         qtmux->last_dts = qtpad->last_dts;
       }
       if (!GST_CLOCK_TIME_IS_VALID (qtmux->first_ts)
-          || qtpad->first_ts < qtmux->first_ts) {
-        qtmux->first_ts = qtpad->first_ts;
+          || first_pts_in < qtmux->first_ts) {
+        /* we need the original incoming PTS here, as this first_ts
+         * is used in update_edit_lists to construct the edit list that arrange
+         * for sync'ed streams.  The first_ts is most likely obtained from
+         * some (audio) stream with 0 dts_adjustment and initial 0 PTS,
+         * so it makes no difference, though it matters in other cases */
+        qtmux->first_ts = first_pts_in;
       }
     }
 
index 598a39c..c9ef21d 100644 (file)
@@ -118,6 +118,7 @@ struct _GstQTPad
 
   /* store the first timestamp for comparing with other streams and
    * know if there are late streams */
+  /* subjected to dts adjustment */
   GstClockTime first_ts;
   GstClockTime first_dts;
 
@@ -205,7 +206,8 @@ struct _GstQTMux
   /* keep track of the largest chunk to fine-tune brands */
   GstClockTime longest_chunk;
 
-  /* Earliest timestamp across all pads/traks */
+  /* Earliest timestamp across all pads/traks
+   * (unadjusted incoming PTS) */
   GstClockTime first_ts;
   /* Last DTS across all pads (= duration) */
   GstClockTime last_dts;