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.
This commit is contained in:
Mark Nauwelaerts 2017-06-19 21:13:42 +02:00
parent 04fd953713
commit 949902f1e2
2 changed files with 15 additions and 3 deletions

View 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;
}
}

View 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;