qtdemux: Determine duration with reference to track header duration 79/265979/1 accepted/tizen/unified/20211109.042824 submit/tizen/20211108.033958
authorGilbok Lee <gilbok.lee@samsung.com>
Wed, 3 Nov 2021 06:30:32 +0000 (15:30 +0900)
committerGilbok Lee <gilbok.lee@samsung.com>
Wed, 3 Nov 2021 06:30:39 +0000 (15:30 +0900)
- The maximum value of the duration of each tkhd is decided with the total duration.

Change-Id: I8a88cd63ed58ce6677b70943d71ee5df8bfa2013

gst/isomp4/qtdemux.c
packaging/gst-plugins-good.spec

index 1ebb081bcb95a7ace25d6cadccb47c592adca529..ca78b20d152cd72fa3fedb80fa8879e9bf01ca50 100644 (file)
@@ -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;
 }
 
index 510716ccd6e1367216789075e301b518be525f1f..fc53ff28869e8c473938c7a5bf82287375a89ba8 100644 (file)
@@ -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\