From 949902f1e25c7a85666e435f4f5d71b4c3a3812a Mon Sep 17 00:00:00 2001 From: Mark Nauwelaerts Date: Mon, 19 Jun 2017 21:13:42 +0200 Subject: [PATCH] qtmux: correctly calculate overall first_ts to ensure stream sync ... by minding and compensating for the dts_adjustment that may have been introduced in the PTS timeline. --- gst/isomp4/gstqtmux.c | 14 ++++++++++++-- gst/isomp4/gstqtmux.h | 4 +++- 2 files changed, 15 insertions(+), 3 deletions(-) diff --git a/gst/isomp4/gstqtmux.c b/gst/isomp4/gstqtmux.c index ba5539bcdd..7169572254 100644 --- a/gst/isomp4/gstqtmux.c +++ b/gst/isomp4/gstqtmux.c @@ -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; } } diff --git a/gst/isomp4/gstqtmux.h b/gst/isomp4/gstqtmux.h index 598a39c7d5..c9ef21ddf4 100644 --- a/gst/isomp4/gstqtmux.h +++ b/gst/isomp4/gstqtmux.h @@ -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;