plugin_store: Switch to use C2VdaPooledBlockPool

The V4L2 stateful API requires the caller pass the same buffers to the
output queue slot. Originally we use C2PooledBlockPool for byte buffer
mode, but C2PooledBlockPool cannot get buffer identifier.

This CL switches to use C2VdaPooledBlockPool, which guarantees to
return a fixed set of buffers and could query the buffer index.

Bug: 161770200
Test: pass e2e test
Change-Id: Ief2bdd9ceb6655cd47627ccf6c239a1e6d73482e
diff --git a/components/V4L2DecodeComponent.cpp b/components/V4L2DecodeComponent.cpp
index 8a86466..0f59d79 100644
--- a/components/V4L2DecodeComponent.cpp
+++ b/components/V4L2DecodeComponent.cpp
@@ -275,12 +275,7 @@
         return;
     }
 
-    // TODO(b/160307705): Consider to remove the dependency of C2VdaBqBlockPool.
-    if (blockPool->getAllocatorId() == C2PlatformAllocatorStore::BUFFERQUEUE) {
-        reinterpret_cast<C2VdaBqBlockPool*>(blockPool.get())->requestNewBufferSet(numBuffers);
-    }
-
-    *pool = VideoFramePool::Create(std::move(blockPool), size, pixelFormat, mIsSecure,
+    *pool = VideoFramePool::Create(std::move(blockPool), numBuffers, size, pixelFormat, mIsSecure,
                                    mDecoderTaskRunner);
 }
 
diff --git a/components/V4L2DecodeInterface.cpp b/components/V4L2DecodeInterface.cpp
index f975e95..71d36e0 100644
--- a/components/V4L2DecodeInterface.cpp
+++ b/components/V4L2DecodeInterface.cpp
@@ -265,7 +265,7 @@
     const C2Allocator::id_t inputAllocators[] = {secureMode ? V4L2AllocatorId::SECURE_LINEAR
                                                             : C2PlatformAllocatorStore::BLOB};
 
-    const C2Allocator::id_t outputAllocators[] = {C2AllocatorStore::DEFAULT_GRAPHIC};
+    const C2Allocator::id_t outputAllocators[] = {V4L2AllocatorId::V4L2_BUFFERPOOL};
     const C2Allocator::id_t surfaceAllocator =
             secureMode ? V4L2AllocatorId::SECURE_GRAPHIC : V4L2AllocatorId::V4L2_BUFFERQUEUE;
     const C2BlockPool::local_id_t outputBlockPools[] = {C2BlockPool::BASIC_GRAPHIC};
diff --git a/components/VideoFramePool.cpp b/components/VideoFramePool.cpp
index 33e01e9..8703acf 100644
--- a/components/VideoFramePool.cpp
+++ b/components/VideoFramePool.cpp
@@ -17,6 +17,9 @@
 #include <log/log.h>
 
 #include <v4l2_codec2/components/VideoTypes.h>
+#include <v4l2_codec2/plugin_store/C2VdaBqBlockPool.h>
+#include <v4l2_codec2/plugin_store/C2VdaPooledBlockPool.h>
+#include <v4l2_codec2/plugin_store/V4L2AllocatorId.h>
 
 using android::hardware::graphics::common::V1_0::BufferUsage;
 
@@ -29,8 +32,17 @@
 
 // static
 std::unique_ptr<VideoFramePool> VideoFramePool::Create(
-        std::shared_ptr<C2BlockPool> blockPool, const media::Size& size, HalPixelFormat pixelFormat,
-        bool isSecure, scoped_refptr<::base::SequencedTaskRunner> taskRunner) {
+        std::shared_ptr<C2BlockPool> blockPool, const size_t numBuffers, const media::Size& size,
+        HalPixelFormat pixelFormat, bool isSecure,
+        scoped_refptr<::base::SequencedTaskRunner> taskRunner) {
+    ALOG_ASSERT(blockPool != nullptr);
+
+    if (blockPool->getAllocatorId() == V4L2AllocatorId::V4L2_BUFFERPOOL) {
+        static_cast<C2VdaPooledBlockPool*>(blockPool.get())->requestNewBufferSet(numBuffers);
+    } else {
+        static_cast<C2VdaBqBlockPool*>(blockPool.get())->requestNewBufferSet(numBuffers);
+    }
+
     std::unique_ptr<VideoFramePool> pool = ::base::WrapUnique(new VideoFramePool(
             std::move(blockPool), size, pixelFormat, isSecure, std::move(taskRunner)));
     if (!pool->initialize()) return nullptr;
@@ -115,6 +127,7 @@
                                                         mMemoryUsage, &block);
 
         if (err == C2_OK) {
+            ALOG_ASSERT(block != nullptr);
             frame = VideoFrame::Create(std::move(block));
             break;
         } else if (err != C2_TIMED_OUT && err != C2_BLOCKING) {
diff --git a/components/include/v4l2_codec2/components/VideoFramePool.h b/components/include/v4l2_codec2/components/VideoFramePool.h
index 079e640..7097ad9 100644
--- a/components/include/v4l2_codec2/components/VideoFramePool.h
+++ b/components/include/v4l2_codec2/components/VideoFramePool.h
@@ -28,8 +28,8 @@
     using GetVideoFrameCB = base::OnceCallback<void(std::unique_ptr<VideoFrame>)>;
 
     static std::unique_ptr<VideoFramePool> Create(
-            std::shared_ptr<C2BlockPool> blockPool, const media::Size& size,
-            HalPixelFormat pixelFormat, bool isSecure,
+            std::shared_ptr<C2BlockPool> blockPool, const size_t numBuffers,
+            const media::Size& size, HalPixelFormat pixelFormat, bool isSecure,
             scoped_refptr<::base::SequencedTaskRunner> taskRunner);
     ~VideoFramePool();
 
diff --git a/plugin_store/V4L2PluginStore.cpp b/plugin_store/V4L2PluginStore.cpp
index 86dd018..4475e2f 100644
--- a/plugin_store/V4L2PluginStore.cpp
+++ b/plugin_store/V4L2PluginStore.cpp
@@ -16,6 +16,7 @@
 #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>
 
@@ -67,7 +68,7 @@
 
     switch (allocatorId) {
     case V4L2AllocatorId::V4L2_BUFFERPOOL:
-        return new C2PooledBlockPool(allocator, poolId);
+        return new C2VdaPooledBlockPool(allocator, poolId);
 
     case V4L2AllocatorId::V4L2_BUFFERQUEUE:
         return new C2VdaBqBlockPool(allocator, poolId);