Skip to content

Commit

Permalink
fix: flag to indicate origin of header duration
Browse files Browse the repository at this point in the history
  • Loading branch information
lee.fordyce committed May 14, 2024
1 parent 8eeb615 commit 205a107
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 19 deletions.
14 changes: 8 additions & 6 deletions packager/media/base/stream_info.h
Original file line number Diff line number Diff line change
Expand Up @@ -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; }
Expand All @@ -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:
Expand Down Expand Up @@ -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
Expand Down
18 changes: 9 additions & 9 deletions packager/media/formats/mp4/mp4_media_parser.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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<uint64_t>::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<uint64_t>::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<uint64_t>::max()) {
DCHECK(moov_->header.timescale != 0);
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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);
}
Expand Down
7 changes: 3 additions & 4 deletions packager/media/formats/mp4/mp4_muxer.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down

0 comments on commit 205a107

Please sign in to comment.