Loading media/codec2/vndk/C2Store.cpp +38 −13 Original line number Diff line number Diff line Loading @@ -445,7 +445,7 @@ public: 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 = Loading @@ -466,7 +466,9 @@ public: allocator, poolId); *pool = ptr; mBlockPools[poolId] = ptr; mComponents[poolId] = component; mComponents[poolId].insert( mComponents[poolId].end(), components.begin(), components.end()); } break; case C2PlatformAllocatorStore::BLOB: Loading @@ -478,7 +480,9 @@ public: allocator, poolId); *pool = ptr; mBlockPools[poolId] = ptr; mComponents[poolId] = component; mComponents[poolId].insert( mComponents[poolId].end(), components.begin(), components.end()); } break; case C2PlatformAllocatorStore::GRALLOC: Loading @@ -490,7 +494,9 @@ public: 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: Loading @@ -502,7 +508,9 @@ public: allocator, poolId); *pool = ptr; mBlockPools[poolId] = ptr; mComponents[poolId] = component; mComponents[poolId].insert( mComponents[poolId].end(), components.begin(), components.end()); } break; default: Loading @@ -513,7 +521,9 @@ public: if (res == C2_OK) { *pool = ptr; mBlockPools[poolId] = ptr; mComponents[poolId] = component; mComponents[poolId].insert( mComponents[poolId].end(), components.begin(), components.end()); } break; } Loading @@ -522,9 +532,9 @@ public: 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( Loading @@ -540,8 +550,13 @@ public: 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; } Loading @@ -554,7 +569,7 @@ private: 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 = Loading Loading @@ -594,7 +609,7 @@ c2_status_t GetCodec2BlockPool( // 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; Loading @@ -602,6 +617,16 @@ c2_status_t GetCodec2BlockPool( return res; } 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, Loading @@ -609,7 +634,7 @@ c2_status_t CreateCodec2BlockPool( 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 { Loading media/codec2/vndk/include/C2PlatformSupport.h +17 −0 Original line number Diff line number Diff line Loading @@ -137,6 +137,23 @@ c2_status_t CreateCodec2BlockPool( std::shared_ptr<const C2Component> component, 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 Loading Loading
media/codec2/vndk/C2Store.cpp +38 −13 Original line number Diff line number Diff line Loading @@ -445,7 +445,7 @@ public: 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 = Loading @@ -466,7 +466,9 @@ public: allocator, poolId); *pool = ptr; mBlockPools[poolId] = ptr; mComponents[poolId] = component; mComponents[poolId].insert( mComponents[poolId].end(), components.begin(), components.end()); } break; case C2PlatformAllocatorStore::BLOB: Loading @@ -478,7 +480,9 @@ public: allocator, poolId); *pool = ptr; mBlockPools[poolId] = ptr; mComponents[poolId] = component; mComponents[poolId].insert( mComponents[poolId].end(), components.begin(), components.end()); } break; case C2PlatformAllocatorStore::GRALLOC: Loading @@ -490,7 +494,9 @@ public: 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: Loading @@ -502,7 +508,9 @@ public: allocator, poolId); *pool = ptr; mBlockPools[poolId] = ptr; mComponents[poolId] = component; mComponents[poolId].insert( mComponents[poolId].end(), components.begin(), components.end()); } break; default: Loading @@ -513,7 +521,9 @@ public: if (res == C2_OK) { *pool = ptr; mBlockPools[poolId] = ptr; mComponents[poolId] = component; mComponents[poolId].insert( mComponents[poolId].end(), components.begin(), components.end()); } break; } Loading @@ -522,9 +532,9 @@ public: 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( Loading @@ -540,8 +550,13 @@ public: 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; } Loading @@ -554,7 +569,7 @@ private: 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 = Loading Loading @@ -594,7 +609,7 @@ c2_status_t GetCodec2BlockPool( // 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; Loading @@ -602,6 +617,16 @@ c2_status_t GetCodec2BlockPool( return res; } 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, Loading @@ -609,7 +634,7 @@ c2_status_t CreateCodec2BlockPool( 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 { Loading
media/codec2/vndk/include/C2PlatformSupport.h +17 −0 Original line number Diff line number Diff line Loading @@ -137,6 +137,23 @@ c2_status_t CreateCodec2BlockPool( std::shared_ptr<const C2Component> component, 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 Loading