From db98c8b058f8a97bfcbf140a5423852bf772c45a Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Bart=C5=82omiej=20Grzesik?= <bgrzesik@google.com>
Date: Tue, 7 Mar 2023 10:30:51 +0000
Subject: [PATCH] V4L2DecodeInterface: Switch to C2PooledBlockPool

With implementation of limitation of number of fetched buffers inside
VideoFramePool, there is no need to use C2VdaPooledBlockPool, hence
switching to C2PooledBlockPool.

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: Iaac647c0ddbeba1e820bb2daf63e94894eb2b424
---
 components/VideoFramePool.cpp    | 28 ++++++++++++++++++----------
 plugin_store/V4L2PluginStore.cpp |  3 +--
 2 files changed, 19 insertions(+), 12 deletions(-)

diff --git a/components/VideoFramePool.cpp b/components/VideoFramePool.cpp
index 97eea13..bb892a8 100644
--- a/components/VideoFramePool.cpp
+++ b/components/VideoFramePool.cpp
@@ -10,6 +10,9 @@
 #include <stdint.h>
 #include <memory>
 
+#include <C2BlockInternal.h>
+#include <bufferpool/BufferPoolTypes.h>
+
 #include <android/hardware/graphics/common/1.0/types.h>
 #include <base/bind.h>
 #include <base/memory/ptr_util.h>
@@ -17,11 +20,11 @@
 #include <log/log.h>
 
 #include <v4l2_codec2/common/VideoTypes.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;
+using android::hardware::media::bufferpool::BufferPoolData;
 
 namespace android {
 
@@ -42,8 +45,20 @@ std::optional<uint32_t> VideoFramePool::getBufferIdFromGraphicBlock(C2BlockPool&
     }
     case V4L2AllocatorId::V4L2_BUFFERPOOL:
         FALLTHROUGH;
-    case V4L2AllocatorId::SECURE_LINEAR:
-        return C2VdaPooledBlockPool::getBufferIdFromGraphicBlock(block);
+    case V4L2AllocatorId::SECURE_LINEAR: {
+        std::shared_ptr<_C2BlockPoolData> blockPoolData =
+                _C2BlockFactory::GetGraphicBlockPoolData(block);
+        if (blockPoolData->getType() != _C2BlockPoolData::TYPE_BUFFERPOOL) {
+            ALOGE("Obtained C2GraphicBlock is not bufferpool-backed.");
+            return std::nullopt;
+        }
+        std::shared_ptr<BufferPoolData> bpData;
+        if (!_C2BlockFactory::GetBufferPoolData(blockPoolData, &bpData) || !bpData) {
+            ALOGE("BufferPoolData unavailable in block.");
+            return std::nullopt;
+        }
+        return bpData->mId;
+    }
     }
 
     ALOGE("%s(): unknown allocator ID: %u", __func__, blockPool.getAllocatorId());
@@ -54,13 +69,6 @@ std::optional<uint32_t> VideoFramePool::getBufferIdFromGraphicBlock(C2BlockPool&
 c2_status_t VideoFramePool::requestNewBufferSet(C2BlockPool& blockPool, int32_t bufferCount,
                                                 const ui::Size& size, uint32_t format,
                                                 C2MemoryUsage usage) {
-    ALOGV("%s() blockPool.getAllocatorId() = %u", __func__, blockPool.getAllocatorId());
-
-    if (blockPool.getAllocatorId() == android::V4L2AllocatorId::V4L2_BUFFERPOOL) {
-        C2VdaPooledBlockPool* bpPool = static_cast<C2VdaPooledBlockPool*>(&blockPool);
-        return bpPool->requestNewBufferSet(bufferCount);
-    }
-
     ALOGE("%s(): unknown allocator ID: %u", __func__, blockPool.getAllocatorId());
     return C2_BAD_VALUE;
 }
diff --git a/plugin_store/V4L2PluginStore.cpp b/plugin_store/V4L2PluginStore.cpp
index b116759..a8cdab6 100644
--- a/plugin_store/V4L2PluginStore.cpp
+++ b/plugin_store/V4L2PluginStore.cpp
@@ -16,7 +16,6 @@
 #include <C2BufferPriv.h>
 #include <log/log.h>
 
-#include <v4l2_codec2/plugin_store/C2VdaPooledBlockPool.h>
 #include <v4l2_codec2/plugin_store/V4L2AllocatorId.h>
 #include <v4l2_codec2/plugin_store/VendorAllocatorLoader.h>
 
@@ -68,7 +67,7 @@ C2BlockPool* createBlockPool(C2Allocator::id_t allocatorId, C2BlockPool::local_i
 
     switch (allocatorId) {
     case V4L2AllocatorId::V4L2_BUFFERPOOL:
-        return new C2VdaPooledBlockPool(allocator, poolId);
+        return new C2PooledBlockPool(allocator, poolId);
 
     case V4L2AllocatorId::SECURE_LINEAR:
         return new C2PooledBlockPool(allocator, poolId);
-- 
GitLab