diff options
author | Chih-yu Huang <akahuang@google.com> | 2020-09-03 02:35:07 +0000 |
---|---|---|
committer | Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com> | 2020-09-03 02:35:07 +0000 |
commit | d13dccf0008e331dd60e27064cbf0342605366e0 (patch) | |
tree | 8e78e0bc610cda0020f54653e4666660300605f1 | |
parent | ee6b49c5d431b3932bfb91bcb947bec0ddc13fbc (diff) | |
parent | 4a28554a31d2179de1d929f15de500d3db2a7a2a (diff) | |
download | v4l2_codec2-d13dccf0008e331dd60e27064cbf0342605366e0.tar.gz |
Merge "VideoFramePool: Only accept one request at the same time" into rvc-dev am: 842849a0ac am: 4a28554a31
Original change: https://googleplex-android-review.googlesource.com/c/platform/external/v4l2_codec2/+/12497569
Change-Id: Idcf18ea6f99a38b6a080c8be62de22ad4f158560
-rw-r--r-- | components/V4L2Decoder.cpp | 10 | ||||
-rw-r--r-- | components/VideoFramePool.cpp | 32 | ||||
-rw-r--r-- | components/include/v4l2_codec2/components/VideoFramePool.h | 15 |
3 files changed, 24 insertions, 33 deletions
diff --git a/components/V4L2Decoder.cpp b/components/V4L2Decoder.cpp index 0a58e20..26f1365 100644 --- a/components/V4L2Decoder.cpp +++ b/components/V4L2Decoder.cpp @@ -502,17 +502,15 @@ void V4L2Decoder::tryFetchVideoFrame() { if (mState == State::Idle) return; - if (mVideoFramePool->hasPendingRequests()) { - ALOGV("Previous callback is running, ignore."); - return; - } - if (mOutputQueue->FreeBuffersCount() == 0) { ALOGD("No free V4L2 output buffers, ignore."); return; } - mVideoFramePool->getVideoFrame(::base::BindOnce(&V4L2Decoder::onVideoFrameReady, mWeakThis)); + if (!mVideoFramePool->getVideoFrame( + ::base::BindOnce(&V4L2Decoder::onVideoFrameReady, mWeakThis))) { + ALOGV("%s(): Previous callback is running, ignore.", __func__); + } } void V4L2Decoder::onVideoFrameReady( diff --git a/components/VideoFramePool.cpp b/components/VideoFramePool.cpp index 0fdd260..22b622d 100644 --- a/components/VideoFramePool.cpp +++ b/components/VideoFramePool.cpp @@ -122,23 +122,21 @@ void VideoFramePool::destroyTask() { mFetchWeakThisFactory.InvalidateWeakPtrs(); } -void VideoFramePool::getVideoFrame(GetVideoFrameCB cb) { +bool VideoFramePool::getVideoFrame(GetVideoFrameCB cb) { ALOGV("%s()", __func__); ALOG_ASSERT(mClientTaskRunner->RunsTasksInCurrentSequence()); - ++mNumPendingRequests; - mFetchTaskRunner->PostTask(FROM_HERE, ::base::BindOnce(&VideoFramePool::getVideoFrameTask, - mFetchWeakThis, std::move(cb))); -} - -bool VideoFramePool::hasPendingRequests() const { - ALOGV("%s()", __func__); - ALOG_ASSERT(mClientTaskRunner->RunsTasksInCurrentSequence()); + if (mOutputCb) { + return false; + } - return mNumPendingRequests > 0; + mOutputCb = std::move(cb); + mFetchTaskRunner->PostTask( + FROM_HERE, ::base::BindOnce(&VideoFramePool::getVideoFrameTask, mFetchWeakThis)); + return true; } -void VideoFramePool::getVideoFrameTask(GetVideoFrameCB cb) { +void VideoFramePool::getVideoFrameTask() { ALOGV("%s()", __func__); ALOG_ASSERT(mFetchTaskRunner->RunsTasksInCurrentSequence()); // Initial delay: 64us @@ -184,25 +182,21 @@ void VideoFramePool::getVideoFrameTask(GetVideoFrameCB cb) { mClientTaskRunner->PostTask( FROM_HERE, ::base::BindOnce(&VideoFramePool::onVideoFrameReady, mClientWeakThis, - std::move(cb), std::move(frameWithBlockId))); + std::move(frameWithBlockId))); } -void VideoFramePool::onVideoFrameReady(GetVideoFrameCB cb, - std::optional<FrameWithBlockId> frameWithBlockId) { +void VideoFramePool::onVideoFrameReady(std::optional<FrameWithBlockId> frameWithBlockId) { ALOGV("%s()", __func__); ALOG_ASSERT(mClientTaskRunner->RunsTasksInCurrentSequence()); - --mNumPendingRequests; - if (!frameWithBlockId) { ALOGE("Failed to get GraphicBlock, abandoning all pending requests."); mClientWeakThisFactory.InvalidateWeakPtrs(); mClientWeakThis = mClientWeakThisFactory.GetWeakPtr(); - - mNumPendingRequests = 0; } - std::move(cb).Run(std::move(frameWithBlockId)); + ALOG_ASSERT(mOutputCb); + std::move(mOutputCb).Run(std::move(frameWithBlockId)); } } // namespace android diff --git a/components/include/v4l2_codec2/components/VideoFramePool.h b/components/include/v4l2_codec2/components/VideoFramePool.h index ca26004..c05c4ff 100644 --- a/components/include/v4l2_codec2/components/VideoFramePool.h +++ b/components/include/v4l2_codec2/components/VideoFramePool.h @@ -37,11 +37,10 @@ public: ~VideoFramePool(); // Get a VideoFrame instance, which will be passed via |cb|. - // If any error occurs, then pass nullptr. - void getVideoFrame(GetVideoFrameCB cb); - - // Return true if any callback of getting VideoFrame instance is pending. - bool hasPendingRequests() const; + // If any error occurs, then nullptr will be passed via |cb|. + // Return false if the previous callback has not been called, and |cb| will + // be dropped directly. + bool getVideoFrame(GetVideoFrameCB cb); private: // |blockPool| is the C2BlockPool that we fetch graphic blocks from. @@ -55,8 +54,8 @@ private: bool initialize(); void destroyTask(); - void getVideoFrameTask(GetVideoFrameCB cb); - void onVideoFrameReady(GetVideoFrameCB cb, std::optional<FrameWithBlockId> frameWithBlockId); + void getVideoFrameTask(); + void onVideoFrameReady(std::optional<FrameWithBlockId> frameWithBlockId); // Extracts buffer ID from graphic block. // |block| is the graphic block allocated by |blockPool|. @@ -72,7 +71,7 @@ private: const HalPixelFormat mPixelFormat; const C2MemoryUsage mMemoryUsage; - size_t mNumPendingRequests = 0; + GetVideoFrameCB mOutputCb; scoped_refptr<::base::SequencedTaskRunner> mClientTaskRunner; ::base::Thread mFetchThread{"VideoFramePoolFetchThread"}; |