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::InitDecoder(TrackInfo&& aInfo) { MOZ_ASSERT(OnThread()); RefPtr<PDMFactory> platform = new PDMFactory(); mDecoder = platform->CreateDecoder({aInfo, mDecoderTaskQueue}); if (!mDecoder) { Error(MediaResult(NS_ERROR_FAILURE, "Failed to create decoder")); return; } RefPtr<Benchmark> ref(mGlobalState); mDecoder->Init()->Then( Thread(), __func__, [this, ref](TrackInfo::TrackType aTrackType) { InputExhausted(); }, [this, ref](const MediaResult& aError) { Error(aError); }); }
void BenchmarkPlayback::InputExhausted() { MOZ_ASSERT(OnThread()); MOZ_ASSERT(!mFinished); if (mSampleIndex >= mSamples.Length()) { Error(MediaResult(NS_ERROR_FAILURE, "Nothing left to decode")); return; } RefPtr<MediaRawData> sample = mSamples[mSampleIndex]; RefPtr<Benchmark> ref(mGlobalState); RefPtr<MediaDataDecoder::DecodePromise> p = mDecoder->Decode(sample); mSampleIndex++; if (mSampleIndex == mSamples.Length() && !ref->mParameters.mStopAtFrame) { // Complete current frame decode then drain if still necessary. p->Then(Thread(), __func__, [ref, this](MediaDataDecoder::DecodedData&& aResults) { Output(std::move(aResults)); if (!mFinished) { mDecoder->Drain()->Then( Thread(), __func__, [ref, this](MediaDataDecoder::DecodedData&& aResults) { mDrained = true; Output(std::move(aResults)); MOZ_ASSERT(mFinished, "We must be done now"); }, [ref, this](const MediaResult& aError) { Error(aError); }); } }, [ref, this](const MediaResult& aError) { Error(aError); }); } else { if (mSampleIndex == mSamples.Length() && ref->mParameters.mStopAtFrame) { mSampleIndex = 0; } // Continue decoding p->Then(Thread(), __func__, [ref, this](MediaDataDecoder::DecodedData&& aResults) { Output(std::move(aResults)); if (!mFinished) { InputExhausted(); } }, [ref, this](const MediaResult& aError) { Error(aError); }); } }
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(); }); }