From 2359ee29e87715a34d71208dc634a3259a660f85 Mon Sep 17 00:00:00 2001 From: Nicolas Dufresne Date: Tue, 23 Jun 2015 17:54:31 -0400 Subject: [PATCH] qtmux: Correctly calculate the elst media start The media start has nothing to do with the shift we have applied but with the value of the first PTS. This is defined as: Dt(0) = 0 Ct(0) = Dt(0) + CTTS(0) So the media start is always the first CTTS. https://bugzilla.gnome.org/show_bug.cgi?id=751361 --- gst/isomp4/gstqtmux.c | 15 ++++++++++----- gst/isomp4/gstqtmux.h | 2 ++ 2 files changed, 12 insertions(+), 5 deletions(-) diff --git a/gst/isomp4/gstqtmux.c b/gst/isomp4/gstqtmux.c index 2ee662f12e..c43d612ce2 100644 --- a/gst/isomp4/gstqtmux.c +++ b/gst/isomp4/gstqtmux.c @@ -495,6 +495,7 @@ gst_qt_mux_pad_reset (GstQTPad * qtpad) qtpad->last_dts = 0; qtpad->dts_adjustment = GST_CLOCK_TIME_NONE; qtpad->first_ts = GST_CLOCK_TIME_NONE; + qtpad->first_dts = GST_CLOCK_TIME_NONE; qtpad->prepare_buf_func = NULL; qtpad->create_empty_buffer = NULL; qtpad->avg_bitrate = 0; @@ -2476,10 +2477,14 @@ gst_qt_mux_update_edit_lists (GstQTMux * qtmux) } if (has_gap || has_shift) { - guint32 shift = gst_util_uint64_scale_round (qtpad->dts_adjustment, + GstClockTime ctts; + guint32 media_start; + + ctts = qtpad->first_ts - qtpad->first_dts; + media_start = gst_util_uint64_scale_round (ctts, atom_trak_get_timescale (qtpad->trak), GST_SECOND); - atom_trak_set_elst_entry (qtpad->trak, 1, duration, shift, + atom_trak_set_elst_entry (qtpad->trak, 1, duration, media_start, (guint32) (1 * 65536.0)); } @@ -3046,9 +3051,9 @@ gst_qt_mux_add_buffer (GstQTMux * qtmux, GstQTPad * pad, GstBuffer * buf) } if (GST_BUFFER_DTS_IS_VALID (last_buf)) { - pad->last_dts = GST_BUFFER_DTS (last_buf); + pad->first_dts = pad->last_dts = GST_BUFFER_DTS (last_buf); } else if (GST_BUFFER_PTS_IS_VALID (last_buf)) { - pad->last_dts = GST_BUFFER_PTS (last_buf); + pad->first_dts = pad->last_dts = GST_BUFFER_PTS (last_buf); } if (GST_CLOCK_TIME_IS_VALID (pad->first_ts)) { @@ -3056,7 +3061,7 @@ gst_qt_mux_add_buffer (GstQTMux * qtmux, GstQTPad * pad, GstBuffer * buf) } else { GST_WARNING_OBJECT (qtmux, "First buffer for pad %s has no timestamp, " "using 0 as first timestamp", GST_PAD_NAME (pad->collect.pad)); - pad->first_ts = 0; + pad->first_ts = pad->first_dts = 0; } GST_DEBUG_OBJECT (qtmux, "Stored first timestamp for pad %s %" GST_TIME_FORMAT, GST_PAD_NAME (pad->collect.pad), diff --git a/gst/isomp4/gstqtmux.h b/gst/isomp4/gstqtmux.h index bf9317947a..81a23faa4f 100644 --- a/gst/isomp4/gstqtmux.h +++ b/gst/isomp4/gstqtmux.h @@ -115,6 +115,8 @@ struct _GstQTPad /* store the first timestamp for comparing with other streams and * know if there are late streams */ GstClockTime first_ts; + GstClockTime first_dts; + guint buf_head; guint buf_tail;