diff --git a/packager/media/base/stream_info.h b/packager/media/base/stream_info.h index b2d68d21ce..947d40818c 100644 --- a/packager/media/base/stream_info.h +++ b/packager/media/base/stream_info.h @@ -110,7 +110,9 @@ class StreamInfo { uint32_t get_default_sample_duration() const { return default_sample_duration_; } - bool is_mehd_header_duration() const { return mehd_header_carryover_; }; + int64_t get_default_fragment_duration() const { + return default_fragment_duration_; + }; void set_duration(int64_t duration) { duration_ = duration; } void set_codec(Codec codec) { codec_ = codec; } @@ -133,8 +135,8 @@ class StreamInfo { default_sample_duration_ = duration; } - void set_mehd_header_carryover(bool mehd_header_carryover) { - mehd_header_carryover_ = mehd_header_carryover; + void set_default_fragment_duration(int64_t default_fragment_duration) { + default_fragment_duration_ = default_fragment_duration; } private: @@ -166,9 +168,9 @@ 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; + // Data to indicate whether the fragment duration originated in the movie + // extends header and should carry over to the output segment. + int64_t default_fragment_duration_ = 0; // Not using DISALLOW_COPY_AND_ASSIGN here intentionally to allow the compiler // generated copy constructor and assignment operator. Since the extra data is diff --git a/packager/media/formats/mp4/mp4_media_parser.cc b/packager/media/formats/mp4/mp4_media_parser.cc index 1a05fb0e35..af8a0eea73 100644 --- a/packager/media/formats/mp4/mp4_media_parser.cc +++ b/packager/media/formats/mp4/mp4_media_parser.cc @@ -410,17 +410,16 @@ 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()) { + int64_t default_fragment_duration = 0; + if (track->media.header.duration > 0) { duration = track->media.header.duration; - } else if (moov_->extends.header.fragment_duration > 0 && - moov_->extends.header.fragment_duration != - std::numeric_limits::max()) { + } else if (moov_->extends.header.fragment_duration > 0) { DCHECK(moov_->header.timescale != 0); duration = Rescale(moov_->extends.header.fragment_duration, moov_->header.timescale, timescale); - mehd_header_carryover = true; + if (duration > 0) { + default_fragment_duration = duration; + } } else if (moov_->header.duration > 0 && moov_->header.duration != std::numeric_limits::max()) { DCHECK(moov_->header.timescale != 0); @@ -595,7 +594,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); + streams.back()->set_default_fragment_duration(default_fragment_duration); const EditList& edit_list = track->edit.list; if (edit_list.edits.size() == 1u) { @@ -789,7 +788,8 @@ bool MP4MediaParser::ParseMoov(BoxReader* reader) { break; } } - video_stream_info->set_mehd_header_carryover(mehd_header_carryover); + video_stream_info->set_default_fragment_duration( + default_fragment_duration); 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 8f84bd5ff3..9411a459d6 100644 --- a/packager/media/formats/mp4/mp4_muxer.cc +++ b/packager/media/formats/mp4/mp4_muxer.cc @@ -248,10 +248,9 @@ 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 && - streams()[0].get()->is_mehd_header_duration()) { - moov->extends.header.fragment_duration = streams()[0].get()->duration(); - } + if (streams()[0].get()->get_default_fragment_duration() > 0) + moov->extends.header.fragment_duration = + streams()[0].get()->get_default_fragment_duration(); } moov->header.creation_time = IsoTimeNow();