From ede4c41a59dac5439cb82fb43cd0ca6b483b949b Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Bart=C5=82omiej=20Grzesik?= <bgrzesik@google.com>
Date: Thu, 9 Mar 2023 13:50:08 +0000
Subject: [PATCH] V4L2DecodeInterface: Switch to GRALLOC allocator

This CL switches to output allocator to C2PlatformAllocatorStore::GRALLOC
that enforces use of C2PooledBufferPool without need of allocating a
separate allocator ID. For this reason V4L2AllocatorId::V4L2_BUFFERPOOL
is no longer used and is removed in this change.

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: Ife2fbb6ac4ff2dc25e006792f8dad2d8ec6f4ac4
(cherry picked from commit 210185e4071e84c508fab3305477e96137507b06)
---
 components/V4L2DecodeInterface.cpp                            | 2 +-
 components/VideoFramePool.cpp                                 | 4 ++--
 plugin_store/V4L2PluginStore.cpp                              | 3 ---
 .../include/v4l2_codec2/plugin_store/V4L2AllocatorId.h        | 3 +--
 4 files changed, 4 insertions(+), 8 deletions(-)

diff --git a/components/V4L2DecodeInterface.cpp b/components/V4L2DecodeInterface.cpp
index fb384c6..32483be 100644
--- a/components/V4L2DecodeInterface.cpp
+++ b/components/V4L2DecodeInterface.cpp
@@ -267,7 +267,7 @@ V4L2DecodeInterface::V4L2DecodeInterface(const std::string& name,
     const C2Allocator::id_t inputAllocators[] = {secureMode ? V4L2AllocatorId::SECURE_LINEAR
                                                             : C2AllocatorStore::DEFAULT_LINEAR};
 
-    const C2Allocator::id_t outputAllocators[] = {V4L2AllocatorId::V4L2_BUFFERPOOL};
+    const C2Allocator::id_t outputAllocators[] = {C2PlatformAllocatorStore::GRALLOC};
     const C2Allocator::id_t surfaceAllocator =
             secureMode ? V4L2AllocatorId::SECURE_GRAPHIC : C2PlatformAllocatorStore::BUFFERQUEUE;
     const C2BlockPool::local_id_t outputBlockPools[] = {C2BlockPool::BASIC_GRAPHIC};
diff --git a/components/VideoFramePool.cpp b/components/VideoFramePool.cpp
index 070cc40..4bf45f3 100644
--- a/components/VideoFramePool.cpp
+++ b/components/VideoFramePool.cpp
@@ -43,7 +43,7 @@ std::optional<uint32_t> VideoFramePool::getBufferIdFromGraphicBlock(C2BlockPool&
         }
         return dmabufId.value();
     }
-    case V4L2AllocatorId::V4L2_BUFFERPOOL:
+    case C2PlatformAllocatorStore::GRALLOC:
         FALLTHROUGH;
     case V4L2AllocatorId::SECURE_LINEAR: {
         std::shared_ptr<_C2BlockPoolData> blockPoolData =
@@ -75,7 +75,7 @@ std::unique_ptr<VideoFramePool> VideoFramePool::Create(
     uint64_t usage = static_cast<uint64_t>(BufferUsage::VIDEO_DECODER);
     if (isSecure) {
         usage |= C2MemoryUsage::READ_PROTECTED;
-    } else if (blockPool->getAllocatorId() == android::V4L2AllocatorId::V4L2_BUFFERPOOL) {
+    } else if (blockPool->getAllocatorId() == C2PlatformAllocatorStore::GRALLOC) {
         // CPU access to buffers is only required in byte buffer mode.
         usage |= C2MemoryUsage::CPU_READ;
     }
diff --git a/plugin_store/V4L2PluginStore.cpp b/plugin_store/V4L2PluginStore.cpp
index a8cdab6..9f9f262 100644
--- a/plugin_store/V4L2PluginStore.cpp
+++ b/plugin_store/V4L2PluginStore.cpp
@@ -66,9 +66,6 @@ C2BlockPool* createBlockPool(C2Allocator::id_t allocatorId, C2BlockPool::local_i
     }
 
     switch (allocatorId) {
-    case V4L2AllocatorId::V4L2_BUFFERPOOL:
-        return new C2PooledBlockPool(allocator, poolId);
-
     case V4L2AllocatorId::SECURE_LINEAR:
         return new C2PooledBlockPool(allocator, poolId);
 
diff --git a/plugin_store/include/v4l2_codec2/plugin_store/V4L2AllocatorId.h b/plugin_store/include/v4l2_codec2/plugin_store/V4L2AllocatorId.h
index 45a470c..2353076 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_BUFFERPOOL = C2PlatformAllocatorStore::PLATFORM_END,
-    SECURE_LINEAR,
+    SECURE_LINEAR = C2PlatformAllocatorStore::PLATFORM_END,
     SECURE_GRAPHIC,
 };
 
-- 
GitLab