From c53b55c4f7dd02dd9029d5db226673d740c51a79 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bart=C5=82omiej=20Grzesik?= <bgrzesik@google.com> Date: Tue, 7 Mar 2023 10:15:53 +0000 Subject: [PATCH] V4L2DecodeInterface: Switch to C2BufferQueueBlockPool Due to move to Codec 2.0 VNDK 1.2 and implementation of asynchronous graphic buffer fetching, there is no need to use C2VdaBqBlockPool. Limitation of number of fetched buffers is done by C2SurfaceSyncMemory and VideoFramePool. For this reason switching to C2BufferQueueBlockPool. This moves unblocks a dozen of tests failures on Android T. Bug: 268301611 Bug: 268305422 Bug: 270329448 Bug: 238710012 Bug: 238390060 Bug: 270331759 Bug: 238709912 Test: CtsMediaCodecTestCases Test: CtsMediaDecoderTestCases Test: CtsMediaV2TestCases Test: GtsExoPlayerTestCases com.google.android.exoplayer.gts.CommonEncryptionDrmTest#cencSchemeTypeV* Change-Id: Ia36a290146860f68c611da4746cd0375225adc99 --- components/V4L2DecodeInterface.cpp | 2 +- components/VideoFramePool.cpp | 28 +++++++++---------- plugin_store/V4L2PluginStore.cpp | 7 ++--- .../plugin_store/V4L2AllocatorId.h | 3 +- 4 files changed, 18 insertions(+), 22 deletions(-) diff --git a/components/V4L2DecodeInterface.cpp b/components/V4L2DecodeInterface.cpp index a218f13..e8c7996 100644 --- a/components/V4L2DecodeInterface.cpp +++ b/components/V4L2DecodeInterface.cpp @@ -331,7 +331,7 @@ V4L2DecodeInterface::V4L2DecodeInterface(const std::string& name, const C2Allocator::id_t outputAllocators[] = {V4L2AllocatorId::V4L2_BUFFERPOOL}; const C2Allocator::id_t surfaceAllocator = - secureMode ? V4L2AllocatorId::SECURE_GRAPHIC : V4L2AllocatorId::V4L2_BUFFERQUEUE; + secureMode ? V4L2AllocatorId::SECURE_GRAPHIC : C2PlatformAllocatorStore::BUFFERQUEUE; const C2BlockPool::local_id_t outputBlockPools[] = {C2BlockPool::BASIC_GRAPHIC}; addParameter( diff --git a/components/VideoFramePool.cpp b/components/VideoFramePool.cpp index c8ea842..97eea13 100644 --- a/components/VideoFramePool.cpp +++ b/components/VideoFramePool.cpp @@ -17,8 +17,8 @@ #include <log/log.h> #include <v4l2_codec2/common/VideoTypes.h> -#include <v4l2_codec2/plugin_store/C2VdaBqBlockPool.h> #include <v4l2_codec2/plugin_store/C2VdaPooledBlockPool.h> +#include <v4l2_codec2/plugin_store/DmabufHelpers.h> #include <v4l2_codec2/plugin_store/V4L2AllocatorId.h> using android::hardware::graphics::common::V1_0::BufferUsage; @@ -30,11 +30,20 @@ std::optional<uint32_t> VideoFramePool::getBufferIdFromGraphicBlock(C2BlockPool& const C2Block2D& block) { ALOGV("%s() blockPool.getAllocatorId() = %u", __func__, blockPool.getAllocatorId()); - if (blockPool.getAllocatorId() == android::V4L2AllocatorId::V4L2_BUFFERPOOL) { + switch (blockPool.getAllocatorId()) { + case V4L2AllocatorId::SECURE_GRAPHIC: + FALLTHROUGH; + case C2PlatformAllocatorStore::BUFFERQUEUE: { + auto dmabufId = android::getDmabufId(block.handle()->data[0]); + if (!dmabufId) { + return std::nullopt; + } + return dmabufId.value(); + } + case V4L2AllocatorId::V4L2_BUFFERPOOL: + FALLTHROUGH; + case V4L2AllocatorId::SECURE_LINEAR: return C2VdaPooledBlockPool::getBufferIdFromGraphicBlock(block); - } else if (blockPool.getAllocatorId() == C2PlatformAllocatorStore::BUFFERQUEUE) { - C2VdaBqBlockPool* bqPool = static_cast<C2VdaBqBlockPool*>(&blockPool); - return bqPool->getBufferIdFromGraphicBlock(block); } ALOGE("%s(): unknown allocator ID: %u", __func__, blockPool.getAllocatorId()); @@ -50,9 +59,6 @@ c2_status_t VideoFramePool::requestNewBufferSet(C2BlockPool& blockPool, int32_t if (blockPool.getAllocatorId() == android::V4L2AllocatorId::V4L2_BUFFERPOOL) { C2VdaPooledBlockPool* bpPool = static_cast<C2VdaPooledBlockPool*>(&blockPool); return bpPool->requestNewBufferSet(bufferCount); - } else if (blockPool.getAllocatorId() == C2PlatformAllocatorStore::BUFFERQUEUE) { - C2VdaBqBlockPool* bqPool = static_cast<C2VdaBqBlockPool*>(&blockPool); - return bqPool->requestNewBufferSet(bufferCount, size.width, size.height, format, usage); } ALOGE("%s(): unknown allocator ID: %u", __func__, blockPool.getAllocatorId()); @@ -61,12 +67,6 @@ c2_status_t VideoFramePool::requestNewBufferSet(C2BlockPool& blockPool, int32_t // static bool VideoFramePool::setNotifyBlockAvailableCb(C2BlockPool& blockPool, ::base::OnceClosure cb) { - ALOGV("%s() blockPool.getAllocatorId() = %u", __func__, blockPool.getAllocatorId()); - - if (blockPool.getAllocatorId() == C2PlatformAllocatorStore::BUFFERQUEUE) { - C2VdaBqBlockPool* bqPool = static_cast<C2VdaBqBlockPool*>(&blockPool); - return bqPool->setNotifyBlockAvailableCb(std::move(cb)); - } return false; } diff --git a/plugin_store/V4L2PluginStore.cpp b/plugin_store/V4L2PluginStore.cpp index 2d53c5f..b116759 100644 --- a/plugin_store/V4L2PluginStore.cpp +++ b/plugin_store/V4L2PluginStore.cpp @@ -12,10 +12,10 @@ #include <mutex> #include <C2AllocatorGralloc.h> +#include <C2BqBufferPriv.h> #include <C2BufferPriv.h> #include <log/log.h> -#include <v4l2_codec2/plugin_store/C2VdaBqBlockPool.h> #include <v4l2_codec2/plugin_store/C2VdaPooledBlockPool.h> #include <v4l2_codec2/plugin_store/V4L2AllocatorId.h> #include <v4l2_codec2/plugin_store/VendorAllocatorLoader.h> @@ -70,14 +70,11 @@ C2BlockPool* createBlockPool(C2Allocator::id_t allocatorId, C2BlockPool::local_i case V4L2AllocatorId::V4L2_BUFFERPOOL: return new C2VdaPooledBlockPool(allocator, poolId); - case V4L2AllocatorId::V4L2_BUFFERQUEUE: - return new C2VdaBqBlockPool(allocator, poolId); - case V4L2AllocatorId::SECURE_LINEAR: return new C2PooledBlockPool(allocator, poolId); case V4L2AllocatorId::SECURE_GRAPHIC: - return new C2VdaBqBlockPool(allocator, poolId); + return new C2BufferQueueBlockPool(allocator, poolId); default: ALOGE("%s(): Unknown allocator id=%u", __func__, allocatorId); diff --git a/plugin_store/include/v4l2_codec2/plugin_store/V4L2AllocatorId.h b/plugin_store/include/v4l2_codec2/plugin_store/V4L2AllocatorId.h index 0808963..45a470c 100644 --- a/plugin_store/include/v4l2_codec2/plugin_store/V4L2AllocatorId.h +++ b/plugin_store/include/v4l2_codec2/plugin_store/V4L2AllocatorId.h @@ -12,8 +12,7 @@ namespace V4L2AllocatorId { // The allocator ids used for V4L2DecodeComponent. enum : C2AllocatorStore::id_t { - V4L2_BUFFERQUEUE = C2PlatformAllocatorStore::PLATFORM_END, - V4L2_BUFFERPOOL, + V4L2_BUFFERPOOL = C2PlatformAllocatorStore::PLATFORM_END, SECURE_LINEAR, SECURE_GRAPHIC, }; -- GitLab