From 729dc40f6afd4f6a691b9cad970c1121709a3367 Mon Sep 17 00:00:00 2001 From: Gilbok Lee Date: Wed, 3 Nov 2021 15:30:32 +0900 Subject: [PATCH] qtdemux: Determine duration with reference to track header duration - The maximum value of the duration of each tkhd is decided with the total duration. Change-Id: I8a88cd63ed58ce6677b70943d71ee5df8bfa2013 --- gst/isomp4/qtdemux.c | 40 +++++++++++++++++++++++++++++++++ packaging/gst-plugins-good.spec | 1 + 2 files changed, 41 insertions(+) diff --git a/gst/isomp4/qtdemux.c b/gst/isomp4/qtdemux.c index 1ebb081bc..ca78b20d1 100644 --- a/gst/isomp4/qtdemux.c +++ b/gst/isomp4/qtdemux.c @@ -330,6 +330,10 @@ struct _QtDemuxStream /* track id */ guint track_id; +#ifdef TIZEN_FEATURE_QTDEMUX_DURATION + guint64 tkhd_duration; +#endif + /* duration/scale */ guint64 duration; /* in timescale units */ guint32 timescale; @@ -11038,6 +11042,22 @@ qtdemux_parse_trak (GstQTDemux * qtdemux, GNode * trak) stream = _create_stream (qtdemux, track_id); stream->stream_tags = gst_tag_list_make_writable (stream->stream_tags); +#ifdef TIZEN_FEATURE_QTDEMUX_DURATION + if (!gst_byte_reader_skip (&tkhd, 4)) + goto corrupt_file; + + if (tkhd_version == 1) { + if (!gst_byte_reader_get_uint64_be (&tkhd, &stream->tkhd_duration)) + goto corrupt_file; + } else { + guint32 dur = 0; + if (!gst_byte_reader_get_uint32_be (&tkhd, &dur)) + goto corrupt_file; + stream->tkhd_duration = dur; + } + GST_INFO_OBJECT (qtdemux, "tkhd duration: %" G_GUINT64_FORMAT, + stream->tkhd_duration); +#endif /* need defaults for fragments */ qtdemux_parse_trex (qtdemux, stream, &dummy, &dummy, &dummy); @@ -11203,7 +11223,11 @@ qtdemux_parse_trak (GstQTDemux * qtdemux, GNode * trak) guint32 matrix[9]; /* version 1 uses some 64-bit ints */ +#ifdef TIZEN_FEATURE_QTDEMUX_DURATION + if (!gst_byte_reader_skip (&tkhd, 16)) +#else if (!gst_byte_reader_skip (&tkhd, 20 + value_size)) +#endif goto corrupt_file; if (!qtdemux_parse_transformation_matrix (qtdemux, &tkhd, matrix, "tkhd")) @@ -13254,6 +13278,9 @@ static GstFlowReturn qtdemux_prepare_streams (GstQTDemux * qtdemux) { GstFlowReturn ret = GST_FLOW_OK; +#ifdef TIZEN_FEATURE_QTDEMUX_DURATION + guint64 tkhd_max_duration = 0; +#endif gint i; GST_DEBUG_OBJECT (qtdemux, "prepare streams"); @@ -13275,6 +13302,10 @@ qtdemux_prepare_streams (GstQTDemux * qtdemux) } else { /* discard any stray moof */ qtdemux->moof_offset = 0; +#ifdef TIZEN_FEATURE_QTDEMUX_DURATION + if (tkhd_max_duration < stream->tkhd_duration) + tkhd_max_duration = stream->tkhd_duration; +#endif } /* prepare braking */ @@ -13306,6 +13337,15 @@ qtdemux_prepare_streams (GstQTDemux * qtdemux) } } +#ifdef TIZEN_FEATURE_QTDEMUX_DURATION + if (!qtdemux->fragmented && (qtdemux->duration > tkhd_max_duration)) { + GST_INFO_OBJECT (qtdemux, + "Update duration: %" G_GUINT64_FORMAT " -> %" G_GUINT64_FORMAT, + qtdemux->duration, tkhd_max_duration); + qtdemux->duration = tkhd_max_duration; + } +#endif + return ret; } diff --git a/packaging/gst-plugins-good.spec b/packaging/gst-plugins-good.spec index 510716ccd..fc53ff288 100644 --- a/packaging/gst-plugins-good.spec +++ b/packaging/gst-plugins-good.spec @@ -80,6 +80,7 @@ export CFLAGS+=" \ -DTIZEN_FEATURE_MP3PARSE_MODIFICATION\ -DTIZEN_FEATURE_AACPARSE_MODIFICATION\ -DTIZEN_FEATURE_QTDEMUX_MODIFICATION\ + -DTIZEN_FEATURE_QTDEMUX_DURATION\ -DTIZEN_FEATURE_FLVDEMUX_MODIFICATION\ -DTIZEN_FEATURE_GST_UPSTREAM_AVOID_BUILD_BREAK\ -DTIZEN_FEATURE_RTSP_MODIFICATION\ -- 2.34.1