From 92fc37ef9120ce0886aadc3fb86c6c9673c9e07e Mon Sep 17 00:00:00 2001 From: Jean-Yves Avenard Date: Thu, 1 Sep 2016 19:29:19 +1000 Subject: [PATCH] Bug 1297265: P3. Rework Apple VT use of InputExhausted. r=me The only time we need to use InputExhausted is for the initial video decoding or when a frame is dropped. MozReview-Commit-ID: IrHqZXJwQe1 --HG-- extra : rebase_source : eb7ff378adafe05458b79a6c3b6c7593c84d40a2 --- dom/media/platforms/apple/AppleVTDecoder.cpp | 32 +++----------------- dom/media/platforms/apple/AppleVTDecoder.h | 8 ----- 2 files changed, 5 insertions(+), 35 deletions(-) diff --git a/dom/media/platforms/apple/AppleVTDecoder.cpp b/dom/media/platforms/apple/AppleVTDecoder.cpp index b7364d9fb68a..05f4b7884a70 100644 --- a/dom/media/platforms/apple/AppleVTDecoder.cpp +++ b/dom/media/platforms/apple/AppleVTDecoder.cpp @@ -34,11 +34,9 @@ AppleVTDecoder::AppleVTDecoder(const VideoInfo& aConfig, , mPictureHeight(aConfig.mImage.height) , mDisplayWidth(aConfig.mDisplay.width) , mDisplayHeight(aConfig.mDisplay.height) - , mQueuedSamples(0) , mTaskQueue(aTaskQueue) , mMaxRefFrames(mp4_demuxer::H264::ComputeMaxRefFrames(aConfig.mExtraData)) , mImageContainer(aImageContainer) - , mInputIncoming(0) , mIsShutDown(false) #ifdef MOZ_WIDGET_UIKIT , mUseSoftwareImages(true) @@ -88,8 +86,6 @@ AppleVTDecoder::Input(MediaRawData* aSample) aSample->mKeyframe ? " keyframe" : "", aSample->Size()); - mInputIncoming++; - mTaskQueue->Dispatch(NewRunnableMethod>( this, &AppleVTDecoder::ProcessDecode, aSample)); return NS_OK; @@ -104,8 +100,6 @@ AppleVTDecoder::Flush() NewRunnableMethod(this, &AppleVTDecoder::ProcessFlush); SyncRunnable::DispatchToThread(mTaskQueue, runnable); mIsFlushing = false; - // All ProcessDecode() tasks should be done. - MOZ_ASSERT(mInputIncoming == 0); mSeekTargetThreshold.reset(); @@ -142,18 +136,11 @@ AppleVTDecoder::ProcessDecode(MediaRawData* aSample) { AssertOnTaskQueueThread(); - mInputIncoming--; - if (mIsFlushing) { return NS_OK; } auto rv = DoDecode(aSample); - // Ask for more data. - if (NS_SUCCEEDED(rv) && !mInputIncoming && mQueuedSamples <= mMaxRefFrames) { - LOG("%s task queue empty; requesting more data", GetDescriptionName()); - mCallback->InputExhausted(); - } return rv; } @@ -213,7 +200,6 @@ AppleVTDecoder::DrainReorderedFrames() while (!mReorderQueue.IsEmpty()) { mCallback->Output(mReorderQueue.Pop().get()); } - mQueuedSamples = 0; } void @@ -223,7 +209,6 @@ AppleVTDecoder::ClearReorderedFrames() while (!mReorderQueue.IsEmpty()) { mReorderQueue.Pop(); } - mQueuedSamples = 0; } void @@ -288,16 +273,10 @@ AppleVTDecoder::OutputFrame(CVPixelBufferRef aImage, aFrameRef.is_sync_point ? " keyframe" : "" ); - if (mQueuedSamples > mMaxRefFrames) { - // We had stopped requesting more input because we had received too much at - // the time. We can ask for more once again. - mCallback->InputExhausted(); - } - MOZ_ASSERT(mQueuedSamples); - mQueuedSamples--; - if (!aImage) { - // Image was dropped by decoder. + // Image was dropped by decoder or none return yet. + // We need more input to continue. + mCallback->InputExhausted(); return NS_OK; } @@ -410,9 +389,10 @@ AppleVTDecoder::OutputFrame(CVPixelBufferRef aImage, // in composition order. MonitorAutoLock mon(mMonitor); mReorderQueue.Push(data); - while (mReorderQueue.Length() > mMaxRefFrames) { + if (mReorderQueue.Length() > mMaxRefFrames) { mCallback->Output(mReorderQueue.Pop().get()); } + mCallback->InputExhausted(); LOG("%llu decoded frames queued", static_cast(mReorderQueue.Length())); @@ -480,8 +460,6 @@ AppleVTDecoder::DoDecode(MediaRawData* aSample) return NS_ERROR_FAILURE; } - mQueuedSamples++; - VTDecodeFrameFlags decodeFlags = kVTDecodeFrame_EnableAsynchronousDecompression; rv = VTDecompressionSessionDecodeFrame(mSession, diff --git a/dom/media/platforms/apple/AppleVTDecoder.h b/dom/media/platforms/apple/AppleVTDecoder.h index ce65d3ade804..5e0b45029864 100644 --- a/dom/media/platforms/apple/AppleVTDecoder.h +++ b/dom/media/platforms/apple/AppleVTDecoder.h @@ -90,11 +90,6 @@ private: const uint32_t mDisplayWidth; const uint32_t mDisplayHeight; - // Number of times a sample was queued via Input(). Will be decreased upon - // the decoder's callback being invoked. - // This is used to calculate how many frames has been buffered by the decoder. - Atomic mQueuedSamples; - // Method to set up the decompression session. nsresult InitializeSession(); nsresult WaitForAsynchronousFrames(); @@ -106,9 +101,6 @@ private: const RefPtr mTaskQueue; const uint32_t mMaxRefFrames; const RefPtr mImageContainer; - // Increased when Input is called, and decreased when ProcessFrame runs. - // Reaching 0 indicates that there's no pending Input. - Atomic mInputIncoming; Atomic mIsShutDown; const bool mUseSoftwareImages;