Skip to content

Commit

Permalink
Bug 1900191 - use default duration if exists. r=media-playback-review…
Browse files Browse the repository at this point in the history
…ers,karlt a=pascalc

Differential Revision: https://phabricator.services.mozilla.com/D214648
  • Loading branch information
alastor0325 committed Jun 24, 2024
1 parent 873dcb5 commit 9513ca2
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 6 deletions.
20 changes: 17 additions & 3 deletions dom/media/webm/NesteggPacketHolder.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,12 @@ class NesteggPacketHolder {
mOffset(-1),
mTimestamp(-1),
mDuration(-1),
mDefaultDuration(-1),
mTrack(0),
mIsKeyframe(false) {}

bool Init(nestegg_packet* aPacket, int64_t aOffset, unsigned aTrack,
bool aIsKeyframe) {
bool Init(nestegg_packet* aPacket, nestegg* aContext, int64_t aOffset,
unsigned aTrack, bool aIsKeyframe) {
uint64_t timestamp_ns;
if (nestegg_packet_tstamp(aPacket, &timestamp_ns) == -1) {
return false;
Expand All @@ -47,6 +48,10 @@ class NesteggPacketHolder {
if (!nestegg_packet_duration(aPacket, &duration_ns)) {
mDuration = duration_ns / 1000;
}
if (!nestegg_track_default_duration(aContext, mTrack, &duration_ns)) {
mDefaultDuration = duration_ns / 1000;
}

return true;
}

Expand All @@ -66,6 +71,10 @@ class NesteggPacketHolder {
MOZ_ASSERT(IsInitialized());
return mDuration;
}
int64_t DefaultDuration() const {
MOZ_ASSERT(IsInitialized());
return mDefaultDuration;
}
unsigned Track() {
MOZ_ASSERT(IsInitialized());
return mTrack;
Expand All @@ -78,7 +87,7 @@ class NesteggPacketHolder {
private:
~NesteggPacketHolder() { nestegg_free_packet(mPacket); }

bool IsInitialized() { return mOffset >= 0; }
bool IsInitialized() const { return mOffset >= 0; }

nestegg_packet* mPacket;

Expand All @@ -90,8 +99,13 @@ class NesteggPacketHolder {
int64_t mTimestamp;

// Packet duration in microseconds; -1 if unknown or retrieval failed.
// https://www.webmproject.org/docs/container/#BlockDuration
int64_t mDuration;

// Default durtaion in microseconds; -1 if unknown or retrieval failed.
// https://www.webmproject.org/docs/container/#Duration
int64_t mDefaultDuration;

// Track ID.
unsigned mTrack;

Expand Down
10 changes: 7 additions & 3 deletions dom/media/webm/WebMDemuxer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -599,9 +599,11 @@ nsresult WebMDemuxer::GetNextPacket(TrackInfo::TrackType aType,
}
int64_t tstamp = holder->Timestamp();
int64_t duration = holder->Duration();
int64_t defaultDuration = holder->DefaultDuration();
if (aType == TrackInfo::TrackType::kVideoTrack) {
WEBM_DEBUG("GetNextPacket(video): tstamp=%" PRId64 ", duration=%" PRId64,
tstamp, duration);
WEBM_DEBUG("GetNextPacket(video): tstamp=%" PRId64 ", duration=%" PRId64
", defaultDuration=%" PRId64,
tstamp, duration, defaultDuration);
}

// The end time of this frame is the start time of the next frame. Fetch
Expand All @@ -625,6 +627,8 @@ nsresult WebMDemuxer::GetNextPacket(TrackInfo::TrackType aType,
next_tstamp = tstamp + duration;
} else if (lastFrameTime.isSome()) {
next_tstamp = tstamp + (tstamp - lastFrameTime.ref());
} else if (defaultDuration >= 0) {
next_tstamp = tstamp + defaultDuration;
} else if (mVideoFrameEndTimeBeforeReset) {
WEBM_DEBUG("Setting next timestamp to be %" PRId64 " us",
mVideoFrameEndTimeBeforeReset->ToMicroseconds());
Expand Down Expand Up @@ -949,7 +953,7 @@ nsresult WebMDemuxer::DemuxPacket(TrackInfo::TrackType aType,

int64_t offset = Resource(aType).Tell();
RefPtr<NesteggPacketHolder> holder = new NesteggPacketHolder();
if (!holder->Init(packet, offset, track, false)) {
if (!holder->Init(packet, Context(aType), offset, track, false)) {
WEBM_DEBUG("NesteggPacketHolder::Init: error");
return NS_ERROR_DOM_MEDIA_DEMUXER_ERR;
}
Expand Down

0 comments on commit 9513ca2

Please sign in to comment.