From 8eeb61572da601502d4c3121e6809280bba9ac9a Mon Sep 17 00:00:00 2001 From: "lee.fordyce" Date: Mon, 13 May 2024 17:26:54 -0600 Subject: [PATCH] fix: flag to indicate origin of header duration --- packager/media/base/stream_info.h | 9 +++++++++ packager/media/formats/mp4/mp4_media_parser.cc | 4 ++++ packager/media/formats/mp4/mp4_muxer.cc | 3 ++- 3 files changed, 15 insertions(+), 1 deletion(-) diff --git a/packager/media/base/stream_info.h b/packager/media/base/stream_info.h index 0180958be1..b2d68d21ce 100644 --- a/packager/media/base/stream_info.h +++ b/packager/media/base/stream_info.h @@ -110,6 +110,7 @@ class StreamInfo { uint32_t get_default_sample_duration() const { return default_sample_duration_; } + bool is_mehd_header_duration() const { return mehd_header_carryover_; }; void set_duration(int64_t duration) { duration_ = duration; } void set_codec(Codec codec) { codec_ = codec; } @@ -132,6 +133,10 @@ class StreamInfo { default_sample_duration_ = duration; } + void set_mehd_header_carryover(bool mehd_header_carryover) { + mehd_header_carryover_ = mehd_header_carryover; + } + private: // Whether the stream is Audio or Video. StreamType stream_type_; @@ -161,6 +166,10 @@ class StreamInfo { // repackaging an init segment alone. uint32_t default_sample_duration_ = 0; + // Flag to indicate whether the duration originated in the movie extends + // header and should carry over to the output segment. + bool mehd_header_carryover_ = false; + // Not using DISALLOW_COPY_AND_ASSIGN here intentionally to allow the compiler // generated copy constructor and assignment operator. Since the extra data is // typically small, the performance impact is minimal. diff --git a/packager/media/formats/mp4/mp4_media_parser.cc b/packager/media/formats/mp4/mp4_media_parser.cc index 98de99bfa6..1a05fb0e35 100644 --- a/packager/media/formats/mp4/mp4_media_parser.cc +++ b/packager/media/formats/mp4/mp4_media_parser.cc @@ -410,6 +410,7 @@ bool MP4MediaParser::ParseMoov(BoxReader* reader) { // Calculate duration (based on timescale). int64_t duration = 0; + bool mehd_header_carryover = false; if (track->media.header.duration > 0 && track->media.header.duration != std::numeric_limits::max()) { duration = track->media.header.duration; @@ -419,6 +420,7 @@ bool MP4MediaParser::ParseMoov(BoxReader* reader) { DCHECK(moov_->header.timescale != 0); duration = Rescale(moov_->extends.header.fragment_duration, moov_->header.timescale, timescale); + mehd_header_carryover = true; } else if (moov_->header.duration > 0 && moov_->header.duration != std::numeric_limits::max()) { DCHECK(moov_->header.timescale != 0); @@ -593,6 +595,7 @@ bool MP4MediaParser::ParseMoov(BoxReader* reader) { num_channels, sampling_frequency, seek_preroll_ns, codec_delay_ns, max_bitrate, avg_bitrate, track->media.header.language.code, is_encrypted)); + streams.back()->set_mehd_header_carryover(mehd_header_carryover); const EditList& edit_list = track->edit.list; if (edit_list.edits.size() == 1u) { @@ -786,6 +789,7 @@ bool MP4MediaParser::ParseMoov(BoxReader* reader) { break; } } + video_stream_info->set_mehd_header_carryover(mehd_header_carryover); streams.push_back(video_stream_info); } diff --git a/packager/media/formats/mp4/mp4_muxer.cc b/packager/media/formats/mp4/mp4_muxer.cc index 64f0465780..8f84bd5ff3 100644 --- a/packager/media/formats/mp4/mp4_muxer.cc +++ b/packager/media/formats/mp4/mp4_muxer.cc @@ -248,7 +248,8 @@ Status MP4Muxer::DelayInitializeMuxer() { ftyp->compatible_brands.push_back(FOURCC_cmfc); // Carry over movie extends header duration from init segment. - if (streams()[0].get()->duration() > 0) { + if (streams()[0].get()->duration() > 0 && + streams()[0].get()->is_mehd_header_duration()) { moov->extends.header.fragment_duration = streams()[0].get()->duration(); } }