From 066558cba1b24416dfdf8bb9dfead1ca0fce5058 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sebastian=20Dr=C3=B6ge?= Date: Fri, 16 Dec 2022 17:27:33 +0200 Subject: [PATCH] qtdemux: Always use `tfdt` if available in BYTE segments MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This reverts the decision from https://bugzilla.gnome.org/show_bug.cgi?id=754230 where it was decided that we rather play safe and only use the `tfdt` if it is "significantly different" to the sum of sample durations. As the specification says If the time expressed in the track fragment decode time (‘tfdt’) box exceeds the sum of the durations of the samples in the preceding movie and movie fragments, then the duration of the last sample preceding this track fragment is extended such that the sum now equals the time given in this box. we have to use the `tfdt` in general to allow for it to signal gaps in the stream. A muxer producing fragments might not yet know the full duration of the last sample of a previous fragment if the next fragment starts with a gap, and knowing the actual start of the next fragment would potentially require to violate latency requirements. Additionally, the existence of `tfdt` allows to avoid accumulating rounding errors from summing up the durations. Part-of: --- .../gst-plugins-good/gst/isomp4/qtdemux.c | 39 +++++++------------ 1 file changed, 14 insertions(+), 25 deletions(-) diff --git a/subprojects/gst-plugins-good/gst/isomp4/qtdemux.c b/subprojects/gst-plugins-good/gst/isomp4/qtdemux.c index 845f1a0c98..7b1209bf53 100644 --- a/subprojects/gst-plugins-good/gst/isomp4/qtdemux.c +++ b/subprojects/gst-plugins-good/gst/isomp4/qtdemux.c @@ -3477,33 +3477,22 @@ qtdemux_parse_trun (GstQTDemux * qtdemux, GstByteReader * trun, GST_INFO_OBJECT (stream->pad, "first sample ts %" GST_TIME_FORMAT, GST_TIME_ARGS (gst_ts)); } else { - /* subsequent fragments extend stream */ - timestamp = - stream->samples[stream->n_samples - 1].timestamp + - stream->samples[stream->n_samples - 1].duration; - - /* If this is a GST_FORMAT_BYTES stream and there's a significant - * difference (1 sec.) between decode_ts and timestamp, prefer the - * former */ - if (has_tfdt && !qtdemux->upstream_format_is_time - && ABSDIFF (decode_ts, timestamp) > - MAX (stream->duration_last_moof / 2, - GSTTIME_TO_QTSTREAMTIME (stream, GST_SECOND))) { - GST_INFO_OBJECT (qtdemux, - "decode_ts (%" GST_TIME_FORMAT ") and timestamp (%" GST_TIME_FORMAT - ") are significantly different (more than %" GST_TIME_FORMAT - "), using decode_ts", - GST_TIME_ARGS (QTSTREAMTIME_TO_GSTTIME (stream, decode_ts)), - GST_TIME_ARGS (QTSTREAMTIME_TO_GSTTIME (stream, timestamp)), - GST_TIME_ARGS (QTSTREAMTIME_TO_GSTTIME (stream, - MAX (stream->duration_last_moof / 2, - GSTTIME_TO_QTSTREAMTIME (stream, GST_SECOND))))); + /* If this is a GST_FORMAT_BYTES stream and we have a tfdt then use it + * instead of the sum of sample durations */ + if (has_tfdt && !qtdemux->upstream_format_is_time) { timestamp = decode_ts; + gst_ts = QTSTREAMTIME_TO_GSTTIME (stream, timestamp); + GST_INFO_OBJECT (qtdemux, "first sample ts %" GST_TIME_FORMAT + " (using tfdt)", GST_TIME_ARGS (gst_ts)); + } else { + /* subsequent fragments extend stream */ + timestamp = + stream->samples[stream->n_samples - 1].timestamp + + stream->samples[stream->n_samples - 1].duration; + gst_ts = QTSTREAMTIME_TO_GSTTIME (stream, timestamp); + GST_INFO_OBJECT (qtdemux, "first sample ts %" GST_TIME_FORMAT + " (extends previous samples)", GST_TIME_ARGS (gst_ts)); } - - gst_ts = QTSTREAMTIME_TO_GSTTIME (stream, timestamp); - GST_INFO_OBJECT (qtdemux, "first sample ts %" GST_TIME_FORMAT - " (extends previous samples)", GST_TIME_ARGS (gst_ts)); } }