diff options
author | Edward Hervey <bilboed@bilboed.com> | 2014-10-28 10:35:19 +0100 |
---|---|---|
committer | Edward Hervey <bilboed@bilboed.com> | 2014-10-28 11:38:32 +0100 |
commit | 6ff96a8ff347cba9da561d47b835b35270becdd3 (patch) | |
tree | 0566b18953d71a62bbf9855dd51b48cbef0d3a0c | |
parent | 0911e76bd21f272d435f36e66ad5822628c1689c (diff) |
qtdemux: Update global duration on moov+moof filesqtdemux
Otherwise we end up stopping reading after the first fragment
-rw-r--r-- | gst/isomp4/qtdemux.c | 49 |
1 files changed, 49 insertions, 0 deletions
diff --git a/gst/isomp4/qtdemux.c b/gst/isomp4/qtdemux.c index 12ab815c3..848f4dc92 100644 --- a/gst/isomp4/qtdemux.c +++ b/gst/isomp4/qtdemux.c @@ -2613,6 +2613,26 @@ qtdemux_parse_trun (GstQTDemux * qtdemux, GstByteReader * trun, sample++; } + /* Update the stream duration if needed */ + if (timestamp && timestamp > stream->duration) { + GstClockTime gstdur = + gst_util_uint64_scale (timestamp, GST_SECOND, stream->timescale); + GST_DEBUG_OBJECT (qtdemux, "Stream duration is now %" GST_TIME_FORMAT, + GST_TIME_ARGS (gstdur)); + stream->duration = timestamp; + + /* If we only have one segment, then update the end */ + if (stream->n_segments == 1 + && GST_CLOCK_TIME_IS_VALID (stream->segments[0].stop_time)) { + QtDemuxSegment *seg = &stream->segments[0]; + GstClockTimeDiff durdiff = gstdur - seg->stop_time; + seg->stop_time += durdiff; + if (GST_CLOCK_TIME_IS_VALID (seg->duration)) + seg->duration += durdiff; + if (GST_CLOCK_TIME_IS_VALID (seg->media_stop)) + seg->media_stop += durdiff; + } + } stream->n_samples += samples_count; return TRUE; @@ -2762,6 +2782,32 @@ failed: } } +static void +check_duration_update (GstQTDemux * qtdemux) +{ + if (GST_CLOCK_TIME_IS_VALID (qtdemux->segment.duration)) { + guint i; + GstClockTime curdur = qtdemux->segment.duration; + GstClockTime stdur; + QtDemuxStream *stream; + + /* Go over each stream and see if we currently have the proper + * up-to-date duration */ + for (i = 0; i < qtdemux->n_streams; i++) { + stream = qtdemux->streams[i]; + stdur = + gst_util_uint64_scale (stream->duration, GST_SECOND, + stream->timescale); + if (stdur > curdur) + curdur = stdur; + } + GST_DEBUG_OBJECT (qtdemux, "Updating global duration to %" GST_TIME_FORMAT, + GST_TIME_ARGS (curdur)); + qtdemux->segment.duration = curdur; + qtdemux->segment.stop = curdur; + } +} + static gboolean qtdemux_parse_moof (GstQTDemux * qtdemux, const guint8 * buffer, guint length, guint64 moof_offset, QtDemuxStream * stream) @@ -2838,6 +2884,9 @@ qtdemux_parse_moof (GstQTDemux * qtdemux, const guint8 * buffer, guint length, traf_node = qtdemux_tree_get_sibling_by_type (traf_node, FOURCC_traf); } g_node_destroy (moof_node); + + check_duration_update (qtdemux); + return TRUE; missing_tfhd: |