codec2: allow multiple components to get block pool from ID
Bug: 160259947
Test: manual test with a sample plugin
Change-Id: I9fe167dd8d0daf7b0ee320dbb8783f423996dbe0
diff --git a/media/codec2/vndk/C2Store.cpp b/media/codec2/vndk/C2Store.cpp
index 74ef9ea..13c90f2 100644
--- a/media/codec2/vndk/C2Store.cpp
+++ b/media/codec2/vndk/C2Store.cpp
@@ -445,7 +445,7 @@
c2_status_t _createBlockPool(
C2PlatformAllocatorStore::id_t allocatorId,
- std::shared_ptr<const C2Component> component,
+ std::vector<std::shared_ptr<const C2Component>> components,
C2BlockPool::local_id_t poolId,
std::shared_ptr<C2BlockPool> *pool) {
std::shared_ptr<C2AllocatorStore> allocatorStore =
@@ -466,7 +466,9 @@
allocator, poolId);
*pool = ptr;
mBlockPools[poolId] = ptr;
- mComponents[poolId] = component;
+ mComponents[poolId].insert(
+ mComponents[poolId].end(),
+ components.begin(), components.end());
}
break;
case C2PlatformAllocatorStore::BLOB:
@@ -478,7 +480,9 @@
allocator, poolId);
*pool = ptr;
mBlockPools[poolId] = ptr;
- mComponents[poolId] = component;
+ mComponents[poolId].insert(
+ mComponents[poolId].end(),
+ components.begin(), components.end());
}
break;
case C2PlatformAllocatorStore::GRALLOC:
@@ -490,7 +494,9 @@
std::make_shared<C2PooledBlockPool>(allocator, poolId);
*pool = ptr;
mBlockPools[poolId] = ptr;
- mComponents[poolId] = component;
+ mComponents[poolId].insert(
+ mComponents[poolId].end(),
+ components.begin(), components.end());
}
break;
case C2PlatformAllocatorStore::BUFFERQUEUE:
@@ -502,7 +508,9 @@
allocator, poolId);
*pool = ptr;
mBlockPools[poolId] = ptr;
- mComponents[poolId] = component;
+ mComponents[poolId].insert(
+ mComponents[poolId].end(),
+ components.begin(), components.end());
}
break;
default:
@@ -513,7 +521,9 @@
if (res == C2_OK) {
*pool = ptr;
mBlockPools[poolId] = ptr;
- mComponents[poolId] = component;
+ mComponents[poolId].insert(
+ mComponents[poolId].end(),
+ components.begin(), components.end());
}
break;
}
@@ -522,9 +532,9 @@
c2_status_t createBlockPool(
C2PlatformAllocatorStore::id_t allocatorId,
- std::shared_ptr<const C2Component> component,
+ std::vector<std::shared_ptr<const C2Component>> components,
std::shared_ptr<C2BlockPool> *pool) {
- return _createBlockPool(allocatorId, component, mBlockPoolSeqId++, pool);
+ return _createBlockPool(allocatorId, components, mBlockPoolSeqId++, pool);
}
bool getBlockPool(
@@ -540,8 +550,13 @@
mBlockPools.erase(it);
mComponents.erase(blockPoolId);
} else {
- auto found = mComponents.find(blockPoolId);
- if (component == found->second.lock()) {
+ auto found = std::find_if(
+ mComponents[blockPoolId].begin(),
+ mComponents[blockPoolId].end(),
+ [component](const std::weak_ptr<const C2Component> &ptr) {
+ return component == ptr.lock();
+ });
+ if (found != mComponents[blockPoolId].end()) {
*pool = ptr;
return true;
}
@@ -554,7 +569,7 @@
C2BlockPool::local_id_t mBlockPoolSeqId;
std::map<C2BlockPool::local_id_t, std::weak_ptr<C2BlockPool>> mBlockPools;
- std::map<C2BlockPool::local_id_t, std::weak_ptr<const C2Component>> mComponents;
+ std::map<C2BlockPool::local_id_t, std::vector<std::weak_ptr<const C2Component>>> mComponents;
};
static std::unique_ptr<_C2BlockPoolCache> sBlockPoolCache =
@@ -594,7 +609,7 @@
// TODO: remove this. this is temporary
case C2BlockPool::PLATFORM_START:
res = sBlockPoolCache->_createBlockPool(
- C2PlatformAllocatorStore::BUFFERQUEUE, component, id, pool);
+ C2PlatformAllocatorStore::BUFFERQUEUE, {component}, id, pool);
break;
default:
break;
@@ -604,12 +619,22 @@
c2_status_t CreateCodec2BlockPool(
C2PlatformAllocatorStore::id_t allocatorId,
+ const std::vector<std::shared_ptr<const C2Component>> &components,
+ std::shared_ptr<C2BlockPool> *pool) {
+ pool->reset();
+
+ std::lock_guard<std::mutex> lock(sBlockPoolCacheMutex);
+ return sBlockPoolCache->createBlockPool(allocatorId, components, pool);
+}
+
+c2_status_t CreateCodec2BlockPool(
+ C2PlatformAllocatorStore::id_t allocatorId,
std::shared_ptr<const C2Component> component,
std::shared_ptr<C2BlockPool> *pool) {
pool->reset();
std::lock_guard<std::mutex> lock(sBlockPoolCacheMutex);
- return sBlockPoolCache->createBlockPool(allocatorId, component, pool);
+ return sBlockPoolCache->createBlockPool(allocatorId, {component}, pool);
}
class C2PlatformComponentStore : public C2ComponentStore {
diff --git a/media/codec2/vndk/include/C2PlatformSupport.h b/media/codec2/vndk/include/C2PlatformSupport.h
index 6d351c2..dc82e82 100644
--- a/media/codec2/vndk/include/C2PlatformSupport.h
+++ b/media/codec2/vndk/include/C2PlatformSupport.h
@@ -138,6 +138,23 @@
std::shared_ptr<C2BlockPool> *pool);
/**
+ * Creates a block pool.
+ * \param allocatorId the allocator ID which is used to allocate blocks
+ * \param components the components using the block pool
+ * \param pool pointer to where the created block pool shall be store on success.
+ * nullptr will be stored here on failure
+ *
+ * \retval C2_OK the operation was successful
+ * \retval C2_BAD_VALUE the component is null
+ * \retval C2_NOT_FOUND if the allocator does not exist
+ * \retval C2_NO_MEMORY not enough memory to create a block pool
+ */
+c2_status_t CreateCodec2BlockPool(
+ C2PlatformAllocatorStore::id_t allocatorId,
+ const std::vector<std::shared_ptr<const C2Component>> &components,
+ std::shared_ptr<C2BlockPool> *pool);
+
+/**
* Returns the platform component store.
* \retval nullptr if the platform component store could not be obtained
*/