From 78e22f902404cc08512e949e08be3a0e49b0a1d9 Mon Sep 17 00:00:00 2001 From: alwu Date: Mon, 24 Jun 2024 13:33:01 +0000 Subject: [PATCH] Bug 1900191 - use default duration if exists. r=media-playback-reviewers,karlt Differential Revision: https://phabricator.services.mozilla.com/D214648 --- dom/media/webm/NesteggPacketHolder.h | 20 +++++++++++++++++--- dom/media/webm/WebMDemuxer.cpp | 10 +++++++--- 2 files changed, 24 insertions(+), 6 deletions(-) diff --git a/dom/media/webm/NesteggPacketHolder.h b/dom/media/webm/NesteggPacketHolder.h index 7c74f752d35f8..e1e7822106d5a 100644 --- a/dom/media/webm/NesteggPacketHolder.h +++ b/dom/media/webm/NesteggPacketHolder.h @@ -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, ×tamp_ns) == -1) { return false; @@ -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; } @@ -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; @@ -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; @@ -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; diff --git a/dom/media/webm/WebMDemuxer.cpp b/dom/media/webm/WebMDemuxer.cpp index 8b8b10b4673cf..5cb529bec15f2 100644 --- a/dom/media/webm/WebMDemuxer.cpp +++ b/dom/media/webm/WebMDemuxer.cpp @@ -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 @@ -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()); @@ -949,7 +953,7 @@ nsresult WebMDemuxer::DemuxPacket(TrackInfo::TrackType aType, int64_t offset = Resource(aType).Tell(); RefPtr 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; }