diff --git a/dom/media/fmp4/MP4Reader.cpp b/dom/media/fmp4/MP4Reader.cpp index c5f4eb7a5094..25faeac8970d 100644 --- a/dom/media/fmp4/MP4Reader.cpp +++ b/dom/media/fmp4/MP4Reader.cpp @@ -470,19 +470,16 @@ MP4Reader::RequestVideoData(bool aSkipToNextKeyframe, MOZ_ASSERT(GetTaskQueue()->IsCurrentThreadIn()); VLOG("RequestVideoData skip=%d time=%lld", aSkipToNextKeyframe, aTimeThreshold); - // Record number of frames decoded and parsed. Automatically update the - // stats counters using the AutoNotifyDecoded stack-based class. - uint32_t parsed = 0, decoded = 0; - AbstractMediaDecoder::AutoNotifyDecoded autoNotify(mDecoder, parsed, decoded); - MOZ_ASSERT(HasVideo() && mPlatform && mVideo.mDecoder); bool eos = false; if (aSkipToNextKeyframe) { + uint32_t parsed = 0; eos = !SkipVideoDemuxToNextKeyFrame(aTimeThreshold, parsed); if (!eos && NS_FAILED(mVideo.mDecoder->Flush())) { NS_WARNING("Failed to skip/flush video when skipping-to-next-keyframe."); } + mDecoder->NotifyDecodedFrames(parsed, 0); } MonitorAutoLock lock(mVideo.mMonitor); @@ -493,12 +490,6 @@ MP4Reader::RequestVideoData(bool aSkipToNextKeyframe, ScheduleUpdate(kVideo); } - // Report the number of "decoded" frames as the difference in the - // mNumSamplesOutput field since the last time we were called. - uint64_t delta = mVideo.mNumSamplesOutput - mLastReportedNumDecodedFrames; - decoded = static_cast(delta); - mLastReportedNumDecodedFrames = mVideo.mNumSamplesOutput; - return p; } @@ -551,6 +542,11 @@ MP4Reader::Update(TrackType aTrack) { MOZ_ASSERT(GetTaskQueue()->IsCurrentThreadIn()); + // Record number of frames decoded and parsed. Automatically update the + // stats counters using the AutoNotifyDecoded stack-based class. + uint32_t parsed = 0, decoded = 0; + AbstractMediaDecoder::AutoNotifyDecoded autoNotify(mDecoder, parsed, decoded); + bool needInput = false; bool needOutput = false; auto& decoder = GetDecoderData(aTrack); @@ -562,6 +558,11 @@ MP4Reader::Update(TrackType aTrack) decoder.mInputExhausted = false; decoder.mNumSamplesInput++; } + if (aTrack == kVideo) { + uint64_t delta = decoder.mNumSamplesOutput - mLastReportedNumDecodedFrames; + decoded = static_cast(delta); + mLastReportedNumDecodedFrames = decoder.mNumSamplesOutput; + } if (decoder.HasPromise()) { needOutput = true; if (!decoder.mOutput.IsEmpty()) { @@ -585,6 +586,9 @@ MP4Reader::Update(TrackType aTrack) MP4Sample* sample = PopSample(aTrack); if (sample) { decoder.mDecoder->Input(sample); + if (aTrack == kVideo) { + parsed++; + } } else { { MonitorAutoLock lock(decoder.mMonitor);