void BenchmarkPlayback::InputExhausted() { MOZ_ASSERT(OnThread()); if (mFinished || mSampleIndex >= mSamples.Length()) { return; } RefPtr<Benchmark> ref(mMainThreadState); mDecoder->Decode(mSamples[mSampleIndex]) ->Then(Thread(), __func__, [ref, this](const MediaDataDecoder::DecodedData& aResults) { Output(aResults); InputExhausted(); }, [ref, this](const MediaResult& aError) { MainThreadShutdown(); }); mSampleIndex++; if (mSampleIndex == mSamples.Length()) { if (ref->mParameters.mStopAtFrame) { mSampleIndex = 0; } else { mDecoder->Drain()->Then( Thread(), __func__, [ref, this](const MediaDataDecoder::DecodedData& aResults) { mDrained = true; Output(aResults); }, [ref, this](const MediaResult& aError) { MainThreadShutdown(); }); } } }
void BenchmarkPlayback::DemuxNextSample() { MOZ_ASSERT(OnThread()); RefPtr<Benchmark> ref(mMainThreadState); RefPtr<MediaTrackDemuxer::SamplesPromise> promise = mTrackDemuxer->GetSamples(); promise->Then( Thread(), __func__, [this, ref](RefPtr<MediaTrackDemuxer::SamplesHolder> aHolder) { mSamples.AppendElements(Move(aHolder->mSamples)); if (ref->mParameters.mStopAtFrame && mSamples.Length() == (size_t)ref->mParameters.mStopAtFrame.ref()) { InitDecoder(Move(*mTrackDemuxer->GetInfo())); } else { Dispatch(NS_NewRunnableFunction([this, ref]() { DemuxNextSample(); })); } }, [this, ref](DemuxerFailureReason aReason) { switch (aReason) { case DemuxerFailureReason::END_OF_STREAM: InitDecoder(Move(*mTrackDemuxer->GetInfo())); break; default: MainThreadShutdown(); } }); }
void BenchmarkPlayback::Error(MediaDataDecoderError aError) { RefPtr<Benchmark> ref(mMainThreadState); Dispatch(NS_NewRunnableFunction([this, ref]() { MainThreadShutdown(); })); }
void BenchmarkPlayback::DemuxSamples() { MOZ_ASSERT(OnThread()); RefPtr<Benchmark> ref(mMainThreadState); mDemuxer->Init()->Then( Thread(), __func__, [this, ref](nsresult aResult) { MOZ_ASSERT(OnThread()); mTrackDemuxer = mDemuxer->GetTrackDemuxer(TrackInfo::kVideoTrack, 0); if (!mTrackDemuxer) { MainThreadShutdown(); } DemuxNextSample(); }, [this, ref](DemuxerFailureReason aReason) { MainThreadShutdown(); }); }
void BenchmarkPlayback::InitDecoder(TrackInfo&& aInfo) { MOZ_ASSERT(OnThread()); RefPtr<PDMFactory> platform = new PDMFactory(); mDecoder = platform->CreateDecoder(aInfo, mDecoderTaskQueue, this); if (!mDecoder) { MainThreadShutdown(); return; } RefPtr<Benchmark> ref(mMainThreadState); mDecoder->Init()->Then( ref->Thread(), __func__, [this, ref](TrackInfo::TrackType aTrackType) { Dispatch(NS_NewRunnableFunction([this, ref]() { InputExhausted(); })); }, [this, ref](MediaDataDecoder::DecoderFailureReason aReason) { MainThreadShutdown(); }); }
void BenchmarkPlayback::InitDecoder(TrackInfo&& aInfo) { MOZ_ASSERT(OnThread()); RefPtr<PDMFactory> platform = new PDMFactory(); mDecoder = platform->CreateDecoder({ aInfo, mDecoderTaskQueue, reinterpret_cast<MediaDataDecoderCallback*>(this) }); if (!mDecoder) { MainThreadShutdown(); return; } RefPtr<Benchmark> ref(mMainThreadState); mDecoder->Init()->Then( Thread(), __func__, [this, ref](TrackInfo::TrackType aTrackType) { InputExhausted(); }, [this, ref](MediaDataDecoder::DecoderFailureReason aReason) { MainThreadShutdown(); }); }
void BenchmarkPlayback::InitDecoder(TrackInfo&& aInfo) { MOZ_ASSERT(OnThread()); RefPtr<PDMFactory> platform = new PDMFactory(); mDecoder = platform->CreateDecoder({ aInfo, mDecoderTaskQueue }); if (!mDecoder) { MainThreadShutdown(); return; } RefPtr<Benchmark> ref(mMainThreadState); mDecoder->Init()->Then( Thread(), __func__, [this, ref](TrackInfo::TrackType aTrackType) { InputExhausted(); }, [this, ref](const MediaResult& aError) { MainThreadShutdown(); }); }
void BenchmarkPlayback::DrainComplete() { RefPtr<Benchmark> ref(mMainThreadState); Dispatch(NS_NewRunnableFunction([this, ref]() { int32_t frames = mFrameCount - ref->mParameters.mStartupFrame; TimeDuration elapsedTime = TimeStamp::Now() - mDecodeStartTime; uint32_t decodeFps = frames / elapsedTime.ToSeconds(); MainThreadShutdown(); ref->Dispatch(NS_NewRunnableFunction([ref, decodeFps]() { ref->ReturnResult(decodeFps); })); })); }
void BenchmarkPlayback::Output(MediaData* aData) { RefPtr<Benchmark> ref(mMainThreadState); Dispatch(NS_NewRunnableFunction([this, ref]() { mFrameCount++; if (mFrameCount == ref->mParameters.mStartupFrame) { mDecodeStartTime = TimeStamp::Now(); } int32_t frames = mFrameCount - ref->mParameters.mStartupFrame; TimeDuration elapsedTime = TimeStamp::Now() - mDecodeStartTime; if (!mFinished && (frames == ref->mParameters.mFramesToMeasure || elapsedTime >= ref->mParameters.mTimeout)) { uint32_t decodeFps = frames / elapsedTime.ToSeconds(); MainThreadShutdown(); ref->Dispatch(NS_NewRunnableFunction([ref, decodeFps]() { ref->ReturnResult(decodeFps); })); } })); }
void BenchmarkPlayback::Output(const MediaDataDecoder::DecodedData& aResults) { MOZ_ASSERT(OnThread()); RefPtr<Benchmark> ref(mMainThreadState); mFrameCount += aResults.Length(); if (!mDecodeStartTime && mFrameCount >= ref->mParameters.mStartupFrame) { mDecodeStartTime = Some(TimeStamp::Now()); } TimeStamp now = TimeStamp::Now(); int32_t frames = mFrameCount - ref->mParameters.mStartupFrame; TimeDuration elapsedTime = now - mDecodeStartTime.refOr(now); if (!mFinished && (((frames == ref->mParameters.mFramesToMeasure) && frames > 0) || elapsedTime >= ref->mParameters.mTimeout || mDrained)) { uint32_t decodeFps = frames / elapsedTime.ToSeconds(); MainThreadShutdown(); ref->Dispatch(NS_NewRunnableFunction([ref, decodeFps]() { ref->ReturnResult(decodeFps); })); } }