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 13, 2024
1 parent 43bea6c commit 8eeb615
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 1 deletion.
9 changes: 9 additions & 0 deletions packager/media/base/stream_info.h
Original file line number Diff line number Diff line change
Expand Up @@ -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; }
Expand All @@ -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_;
Expand Down Expand Up @@ -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.
Expand Down
4 changes: 4 additions & 0 deletions packager/media/formats/mp4/mp4_media_parser.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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<uint64_t>::max()) {
duration = track->media.header.duration;
Expand All @@ -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<uint64_t>::max()) {
DCHECK(moov_->header.timescale != 0);
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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);
}
Expand Down
3 changes: 2 additions & 1 deletion packager/media/formats/mp4/mp4_muxer.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
}
Expand Down

0 comments on commit 8eeb615

Please sign in to comment.