Loading media/codec2/components/aac/C2SoftAacDec.cpp +3 −5 Original line number Diff line number Diff line Loading @@ -287,6 +287,7 @@ c2_status_t C2SoftAacDec::onStop() { mOutputDelayRingBufferWritePos = 0; mOutputDelayRingBufferReadPos = 0; mOutputDelayRingBufferFilled = 0; mOutputDelayRingBuffer.reset(); mBuffersInfo.clear(); status_t status = UNKNOWN_ERROR; Loading @@ -308,10 +309,7 @@ void C2SoftAacDec::onRelease() { aacDecoder_Close(mAACDecoder); mAACDecoder = nullptr; } if (mOutputDelayRingBuffer) { delete[] mOutputDelayRingBuffer; mOutputDelayRingBuffer = nullptr; } mOutputDelayRingBuffer.reset(); } status_t C2SoftAacDec::initDecoder() { Loading @@ -327,7 +325,7 @@ status_t C2SoftAacDec::initDecoder() { mOutputDelayCompensated = 0; mOutputDelayRingBufferSize = 2048 * MAX_CHANNEL_COUNT * kNumDelayBlocksMax; mOutputDelayRingBuffer = new short[mOutputDelayRingBufferSize]; mOutputDelayRingBuffer.reset(new short[mOutputDelayRingBufferSize]); mOutputDelayRingBufferWritePos = 0; mOutputDelayRingBufferReadPos = 0; mOutputDelayRingBufferFilled = 0; Loading media/codec2/components/aac/C2SoftAacDec.h +1 −1 Original line number Diff line number Diff line Loading @@ -93,7 +93,7 @@ private: bool mEndOfOutput; int32_t mOutputDelayCompensated; int32_t mOutputDelayRingBufferSize; short *mOutputDelayRingBuffer; std::unique_ptr<short[]> mOutputDelayRingBuffer; int32_t mOutputDelayRingBufferWritePos; int32_t mOutputDelayRingBufferReadPos; int32_t mOutputDelayRingBufferFilled; Loading media/codec2/vndk/C2PlatformStorePluginLoader.cpp +7 −4 Original line number Diff line number Diff line Loading @@ -59,13 +59,14 @@ C2PlatformStorePluginLoader::~C2PlatformStorePluginLoader() { c2_status_t C2PlatformStorePluginLoader::createBlockPool( ::C2Allocator::id_t allocatorId, ::C2BlockPool::local_id_t blockPoolId, std::shared_ptr<C2BlockPool>* pool) { std::shared_ptr<C2BlockPool>* pool, std::function<void(C2BlockPool *)> deleter) { if (mCreateBlockPool == nullptr) { ALOGD("Handle or CreateBlockPool symbol is null"); return C2_NOT_FOUND; } std::shared_ptr<::C2BlockPool> ptr(mCreateBlockPool(allocatorId, blockPoolId)); std::shared_ptr<::C2BlockPool> ptr(mCreateBlockPool(allocatorId, blockPoolId), deleter); if (ptr) { *pool = ptr; return C2_OK; Loading @@ -75,14 +76,16 @@ c2_status_t C2PlatformStorePluginLoader::createBlockPool( } c2_status_t C2PlatformStorePluginLoader::createAllocator( ::C2Allocator::id_t allocatorId, std::shared_ptr<C2Allocator>* const allocator) { ::C2Allocator::id_t allocatorId, std::shared_ptr<C2Allocator>* const allocator, std::function<void(C2Allocator *)> deleter) { if (mCreateAllocator == nullptr) { ALOGD("Handle or CreateAllocator symbol is null"); return C2_NOT_FOUND; } c2_status_t res = C2_CORRUPTED; allocator->reset(mCreateAllocator(allocatorId, &res)); allocator->reset(mCreateAllocator(allocatorId, &res), deleter); if (res != C2_OK) { ALOGD("Failed to CreateAllocator by id: %u, res: %d", allocatorId, res); allocator->reset(); Loading media/codec2/vndk/C2Store.cpp +31 −27 Original line number Diff line number Diff line Loading @@ -443,6 +443,7 @@ class _C2BlockPoolCache { public: _C2BlockPoolCache() : mBlockPoolSeqId(C2BlockPool::PLATFORM_START + 1) {} private: c2_status_t _createBlockPool( C2PlatformAllocatorStore::id_t allocatorId, std::vector<std::shared_ptr<const C2Component>> components, Loading @@ -456,14 +457,19 @@ public: if (allocatorId == C2AllocatorStore::DEFAULT_LINEAR) { allocatorId = GetPreferredLinearAllocatorId(GetCodec2PoolMask()); } auto deleter = [this, poolId](C2BlockPool *pool) { std::unique_lock lock(mMutex); mBlockPools.erase(poolId); mComponents.erase(poolId); delete pool; }; switch(allocatorId) { case C2PlatformAllocatorStore::ION: /* also ::DMABUFHEAP */ res = allocatorStore->fetchAllocator( C2PlatformAllocatorStore::ION, &allocator); if (res == C2_OK) { std::shared_ptr<C2BlockPool> ptr = std::make_shared<C2PooledBlockPool>( allocator, poolId); std::shared_ptr<C2BlockPool> ptr( new C2PooledBlockPool(allocator, poolId), deleter); *pool = ptr; mBlockPools[poolId] = ptr; mComponents[poolId].insert( Loading @@ -475,9 +481,8 @@ public: res = allocatorStore->fetchAllocator( C2PlatformAllocatorStore::BLOB, &allocator); if (res == C2_OK) { std::shared_ptr<C2BlockPool> ptr = std::make_shared<C2PooledBlockPool>( allocator, poolId); std::shared_ptr<C2BlockPool> ptr( new C2PooledBlockPool(allocator, poolId), deleter); *pool = ptr; mBlockPools[poolId] = ptr; mComponents[poolId].insert( Loading @@ -490,8 +495,8 @@ public: res = allocatorStore->fetchAllocator( C2AllocatorStore::DEFAULT_GRAPHIC, &allocator); if (res == C2_OK) { std::shared_ptr<C2BlockPool> ptr = std::make_shared<C2PooledBlockPool>(allocator, poolId); std::shared_ptr<C2BlockPool> ptr( new C2PooledBlockPool(allocator, poolId), deleter); *pool = ptr; mBlockPools[poolId] = ptr; mComponents[poolId].insert( Loading @@ -503,9 +508,8 @@ public: res = allocatorStore->fetchAllocator( C2PlatformAllocatorStore::BUFFERQUEUE, &allocator); if (res == C2_OK) { std::shared_ptr<C2BlockPool> ptr = std::make_shared<C2BufferQueueBlockPool>( allocator, poolId); std::shared_ptr<C2BlockPool> ptr( new C2BufferQueueBlockPool(allocator, poolId), deleter); *pool = ptr; mBlockPools[poolId] = ptr; mComponents[poolId].insert( Loading @@ -517,7 +521,7 @@ public: // Try to create block pool from platform store plugins. std::shared_ptr<C2BlockPool> ptr; res = C2PlatformStorePluginLoader::GetInstance()->createBlockPool( allocatorId, poolId, &ptr); allocatorId, poolId, &ptr, deleter); if (res == C2_OK) { *pool = ptr; mBlockPools[poolId] = ptr; Loading @@ -530,17 +534,20 @@ public: return res; } public: c2_status_t createBlockPool( C2PlatformAllocatorStore::id_t allocatorId, std::vector<std::shared_ptr<const C2Component>> components, std::shared_ptr<C2BlockPool> *pool) { std::unique_lock lock(mMutex); return _createBlockPool(allocatorId, components, mBlockPoolSeqId++, pool); } bool getBlockPool( c2_status_t getBlockPool( C2BlockPool::local_id_t blockPoolId, std::shared_ptr<const C2Component> component, std::shared_ptr<C2BlockPool> *pool) { std::unique_lock lock(mMutex); // TODO: use one iterator for multiple blockpool type scalability. std::shared_ptr<C2BlockPool> ptr; auto it = mBlockPools.find(blockPoolId); Loading @@ -558,14 +565,22 @@ public: }); if (found != mComponents[blockPoolId].end()) { *pool = ptr; return true; return C2_OK; } } } return false; // TODO: remove this. this is temporary if (blockPoolId == C2BlockPool::PLATFORM_START) { return _createBlockPool( C2PlatformAllocatorStore::BUFFERQUEUE, {component}, blockPoolId, pool); } return C2_NOT_FOUND; } private: // Deleter needs to hold this mutex, and there is a small chance that deleter // is invoked while the mutex is held. std::recursive_mutex mMutex; C2BlockPool::local_id_t mBlockPoolSeqId; std::map<C2BlockPool::local_id_t, std::weak_ptr<C2BlockPool>> mBlockPools; Loading @@ -574,7 +589,6 @@ private: static std::unique_ptr<_C2BlockPoolCache> sBlockPoolCache = std::make_unique<_C2BlockPoolCache>(); static std::mutex sBlockPoolCacheMutex; } // anynymous namespace Loading @@ -582,15 +596,12 @@ c2_status_t GetCodec2BlockPool( C2BlockPool::local_id_t id, std::shared_ptr<const C2Component> component, std::shared_ptr<C2BlockPool> *pool) { pool->reset(); std::lock_guard<std::mutex> lock(sBlockPoolCacheMutex); std::shared_ptr<C2AllocatorStore> allocatorStore = GetCodec2PlatformAllocatorStore(); std::shared_ptr<C2Allocator> allocator; c2_status_t res = C2_NOT_FOUND; if (id >= C2BlockPool::PLATFORM_START) { if (sBlockPoolCache->getBlockPool(id, component, pool)) { return C2_OK; } return sBlockPoolCache->getBlockPool(id, component, pool); } switch (id) { Loading @@ -606,11 +617,6 @@ c2_status_t GetCodec2BlockPool( *pool = std::make_shared<C2BasicGraphicBlockPool>(allocator); } break; // TODO: remove this. this is temporary case C2BlockPool::PLATFORM_START: res = sBlockPoolCache->_createBlockPool( C2PlatformAllocatorStore::BUFFERQUEUE, {component}, id, pool); break; default: break; } Loading @@ -623,7 +629,6 @@ c2_status_t CreateCodec2BlockPool( std::shared_ptr<C2BlockPool> *pool) { pool->reset(); std::lock_guard<std::mutex> lock(sBlockPoolCacheMutex); return sBlockPoolCache->createBlockPool(allocatorId, components, pool); } Loading @@ -633,7 +638,6 @@ c2_status_t CreateCodec2BlockPool( std::shared_ptr<C2BlockPool> *pool) { pool->reset(); std::lock_guard<std::mutex> lock(sBlockPoolCacheMutex); return sBlockPoolCache->createBlockPool(allocatorId, {component}, pool); } Loading media/codec2/vndk/include/C2PlatformStorePluginLoader.h +9 −5 Original line number Diff line number Diff line Loading @@ -61,9 +61,11 @@ public: * \retval C2_NOT_FOUND the extension symbol was not found. * \retval C2_BAD_INDEX the input allocatorId is not defined in platform store extension. */ c2_status_t createBlockPool(::C2Allocator::id_t allocatorId, c2_status_t createBlockPool( ::C2Allocator::id_t allocatorId, ::C2BlockPool::local_id_t blockPoolId, std::shared_ptr<C2BlockPool>* pool); std::shared_ptr<C2BlockPool>* pool, std::function<void(C2BlockPool *)> deleter = std::default_delete<C2BlockPool>()); /** * Creates allocator from platform store extension. Loading @@ -81,8 +83,10 @@ public: * \retval C2_BAD_INDEX the input allocatorId is not defined in platform store extension. * \retval C2_NO_MEMORY not enough memory to create the allocator */ c2_status_t createAllocator(::C2Allocator::id_t allocatorId, std::shared_ptr<C2Allocator>* const allocator); c2_status_t createAllocator( ::C2Allocator::id_t allocatorId, std::shared_ptr<C2Allocator>* const allocator, std::function<void(C2Allocator *)> deleter = std::default_delete<C2Allocator>()); private: explicit C2PlatformStorePluginLoader(const char *libPath); Loading Loading
media/codec2/components/aac/C2SoftAacDec.cpp +3 −5 Original line number Diff line number Diff line Loading @@ -287,6 +287,7 @@ c2_status_t C2SoftAacDec::onStop() { mOutputDelayRingBufferWritePos = 0; mOutputDelayRingBufferReadPos = 0; mOutputDelayRingBufferFilled = 0; mOutputDelayRingBuffer.reset(); mBuffersInfo.clear(); status_t status = UNKNOWN_ERROR; Loading @@ -308,10 +309,7 @@ void C2SoftAacDec::onRelease() { aacDecoder_Close(mAACDecoder); mAACDecoder = nullptr; } if (mOutputDelayRingBuffer) { delete[] mOutputDelayRingBuffer; mOutputDelayRingBuffer = nullptr; } mOutputDelayRingBuffer.reset(); } status_t C2SoftAacDec::initDecoder() { Loading @@ -327,7 +325,7 @@ status_t C2SoftAacDec::initDecoder() { mOutputDelayCompensated = 0; mOutputDelayRingBufferSize = 2048 * MAX_CHANNEL_COUNT * kNumDelayBlocksMax; mOutputDelayRingBuffer = new short[mOutputDelayRingBufferSize]; mOutputDelayRingBuffer.reset(new short[mOutputDelayRingBufferSize]); mOutputDelayRingBufferWritePos = 0; mOutputDelayRingBufferReadPos = 0; mOutputDelayRingBufferFilled = 0; Loading
media/codec2/components/aac/C2SoftAacDec.h +1 −1 Original line number Diff line number Diff line Loading @@ -93,7 +93,7 @@ private: bool mEndOfOutput; int32_t mOutputDelayCompensated; int32_t mOutputDelayRingBufferSize; short *mOutputDelayRingBuffer; std::unique_ptr<short[]> mOutputDelayRingBuffer; int32_t mOutputDelayRingBufferWritePos; int32_t mOutputDelayRingBufferReadPos; int32_t mOutputDelayRingBufferFilled; Loading
media/codec2/vndk/C2PlatformStorePluginLoader.cpp +7 −4 Original line number Diff line number Diff line Loading @@ -59,13 +59,14 @@ C2PlatformStorePluginLoader::~C2PlatformStorePluginLoader() { c2_status_t C2PlatformStorePluginLoader::createBlockPool( ::C2Allocator::id_t allocatorId, ::C2BlockPool::local_id_t blockPoolId, std::shared_ptr<C2BlockPool>* pool) { std::shared_ptr<C2BlockPool>* pool, std::function<void(C2BlockPool *)> deleter) { if (mCreateBlockPool == nullptr) { ALOGD("Handle or CreateBlockPool symbol is null"); return C2_NOT_FOUND; } std::shared_ptr<::C2BlockPool> ptr(mCreateBlockPool(allocatorId, blockPoolId)); std::shared_ptr<::C2BlockPool> ptr(mCreateBlockPool(allocatorId, blockPoolId), deleter); if (ptr) { *pool = ptr; return C2_OK; Loading @@ -75,14 +76,16 @@ c2_status_t C2PlatformStorePluginLoader::createBlockPool( } c2_status_t C2PlatformStorePluginLoader::createAllocator( ::C2Allocator::id_t allocatorId, std::shared_ptr<C2Allocator>* const allocator) { ::C2Allocator::id_t allocatorId, std::shared_ptr<C2Allocator>* const allocator, std::function<void(C2Allocator *)> deleter) { if (mCreateAllocator == nullptr) { ALOGD("Handle or CreateAllocator symbol is null"); return C2_NOT_FOUND; } c2_status_t res = C2_CORRUPTED; allocator->reset(mCreateAllocator(allocatorId, &res)); allocator->reset(mCreateAllocator(allocatorId, &res), deleter); if (res != C2_OK) { ALOGD("Failed to CreateAllocator by id: %u, res: %d", allocatorId, res); allocator->reset(); Loading
media/codec2/vndk/C2Store.cpp +31 −27 Original line number Diff line number Diff line Loading @@ -443,6 +443,7 @@ class _C2BlockPoolCache { public: _C2BlockPoolCache() : mBlockPoolSeqId(C2BlockPool::PLATFORM_START + 1) {} private: c2_status_t _createBlockPool( C2PlatformAllocatorStore::id_t allocatorId, std::vector<std::shared_ptr<const C2Component>> components, Loading @@ -456,14 +457,19 @@ public: if (allocatorId == C2AllocatorStore::DEFAULT_LINEAR) { allocatorId = GetPreferredLinearAllocatorId(GetCodec2PoolMask()); } auto deleter = [this, poolId](C2BlockPool *pool) { std::unique_lock lock(mMutex); mBlockPools.erase(poolId); mComponents.erase(poolId); delete pool; }; switch(allocatorId) { case C2PlatformAllocatorStore::ION: /* also ::DMABUFHEAP */ res = allocatorStore->fetchAllocator( C2PlatformAllocatorStore::ION, &allocator); if (res == C2_OK) { std::shared_ptr<C2BlockPool> ptr = std::make_shared<C2PooledBlockPool>( allocator, poolId); std::shared_ptr<C2BlockPool> ptr( new C2PooledBlockPool(allocator, poolId), deleter); *pool = ptr; mBlockPools[poolId] = ptr; mComponents[poolId].insert( Loading @@ -475,9 +481,8 @@ public: res = allocatorStore->fetchAllocator( C2PlatformAllocatorStore::BLOB, &allocator); if (res == C2_OK) { std::shared_ptr<C2BlockPool> ptr = std::make_shared<C2PooledBlockPool>( allocator, poolId); std::shared_ptr<C2BlockPool> ptr( new C2PooledBlockPool(allocator, poolId), deleter); *pool = ptr; mBlockPools[poolId] = ptr; mComponents[poolId].insert( Loading @@ -490,8 +495,8 @@ public: res = allocatorStore->fetchAllocator( C2AllocatorStore::DEFAULT_GRAPHIC, &allocator); if (res == C2_OK) { std::shared_ptr<C2BlockPool> ptr = std::make_shared<C2PooledBlockPool>(allocator, poolId); std::shared_ptr<C2BlockPool> ptr( new C2PooledBlockPool(allocator, poolId), deleter); *pool = ptr; mBlockPools[poolId] = ptr; mComponents[poolId].insert( Loading @@ -503,9 +508,8 @@ public: res = allocatorStore->fetchAllocator( C2PlatformAllocatorStore::BUFFERQUEUE, &allocator); if (res == C2_OK) { std::shared_ptr<C2BlockPool> ptr = std::make_shared<C2BufferQueueBlockPool>( allocator, poolId); std::shared_ptr<C2BlockPool> ptr( new C2BufferQueueBlockPool(allocator, poolId), deleter); *pool = ptr; mBlockPools[poolId] = ptr; mComponents[poolId].insert( Loading @@ -517,7 +521,7 @@ public: // Try to create block pool from platform store plugins. std::shared_ptr<C2BlockPool> ptr; res = C2PlatformStorePluginLoader::GetInstance()->createBlockPool( allocatorId, poolId, &ptr); allocatorId, poolId, &ptr, deleter); if (res == C2_OK) { *pool = ptr; mBlockPools[poolId] = ptr; Loading @@ -530,17 +534,20 @@ public: return res; } public: c2_status_t createBlockPool( C2PlatformAllocatorStore::id_t allocatorId, std::vector<std::shared_ptr<const C2Component>> components, std::shared_ptr<C2BlockPool> *pool) { std::unique_lock lock(mMutex); return _createBlockPool(allocatorId, components, mBlockPoolSeqId++, pool); } bool getBlockPool( c2_status_t getBlockPool( C2BlockPool::local_id_t blockPoolId, std::shared_ptr<const C2Component> component, std::shared_ptr<C2BlockPool> *pool) { std::unique_lock lock(mMutex); // TODO: use one iterator for multiple blockpool type scalability. std::shared_ptr<C2BlockPool> ptr; auto it = mBlockPools.find(blockPoolId); Loading @@ -558,14 +565,22 @@ public: }); if (found != mComponents[blockPoolId].end()) { *pool = ptr; return true; return C2_OK; } } } return false; // TODO: remove this. this is temporary if (blockPoolId == C2BlockPool::PLATFORM_START) { return _createBlockPool( C2PlatformAllocatorStore::BUFFERQUEUE, {component}, blockPoolId, pool); } return C2_NOT_FOUND; } private: // Deleter needs to hold this mutex, and there is a small chance that deleter // is invoked while the mutex is held. std::recursive_mutex mMutex; C2BlockPool::local_id_t mBlockPoolSeqId; std::map<C2BlockPool::local_id_t, std::weak_ptr<C2BlockPool>> mBlockPools; Loading @@ -574,7 +589,6 @@ private: static std::unique_ptr<_C2BlockPoolCache> sBlockPoolCache = std::make_unique<_C2BlockPoolCache>(); static std::mutex sBlockPoolCacheMutex; } // anynymous namespace Loading @@ -582,15 +596,12 @@ c2_status_t GetCodec2BlockPool( C2BlockPool::local_id_t id, std::shared_ptr<const C2Component> component, std::shared_ptr<C2BlockPool> *pool) { pool->reset(); std::lock_guard<std::mutex> lock(sBlockPoolCacheMutex); std::shared_ptr<C2AllocatorStore> allocatorStore = GetCodec2PlatformAllocatorStore(); std::shared_ptr<C2Allocator> allocator; c2_status_t res = C2_NOT_FOUND; if (id >= C2BlockPool::PLATFORM_START) { if (sBlockPoolCache->getBlockPool(id, component, pool)) { return C2_OK; } return sBlockPoolCache->getBlockPool(id, component, pool); } switch (id) { Loading @@ -606,11 +617,6 @@ c2_status_t GetCodec2BlockPool( *pool = std::make_shared<C2BasicGraphicBlockPool>(allocator); } break; // TODO: remove this. this is temporary case C2BlockPool::PLATFORM_START: res = sBlockPoolCache->_createBlockPool( C2PlatformAllocatorStore::BUFFERQUEUE, {component}, id, pool); break; default: break; } Loading @@ -623,7 +629,6 @@ c2_status_t CreateCodec2BlockPool( std::shared_ptr<C2BlockPool> *pool) { pool->reset(); std::lock_guard<std::mutex> lock(sBlockPoolCacheMutex); return sBlockPoolCache->createBlockPool(allocatorId, components, pool); } Loading @@ -633,7 +638,6 @@ c2_status_t CreateCodec2BlockPool( std::shared_ptr<C2BlockPool> *pool) { pool->reset(); std::lock_guard<std::mutex> lock(sBlockPoolCacheMutex); return sBlockPoolCache->createBlockPool(allocatorId, {component}, pool); } Loading
media/codec2/vndk/include/C2PlatformStorePluginLoader.h +9 −5 Original line number Diff line number Diff line Loading @@ -61,9 +61,11 @@ public: * \retval C2_NOT_FOUND the extension symbol was not found. * \retval C2_BAD_INDEX the input allocatorId is not defined in platform store extension. */ c2_status_t createBlockPool(::C2Allocator::id_t allocatorId, c2_status_t createBlockPool( ::C2Allocator::id_t allocatorId, ::C2BlockPool::local_id_t blockPoolId, std::shared_ptr<C2BlockPool>* pool); std::shared_ptr<C2BlockPool>* pool, std::function<void(C2BlockPool *)> deleter = std::default_delete<C2BlockPool>()); /** * Creates allocator from platform store extension. Loading @@ -81,8 +83,10 @@ public: * \retval C2_BAD_INDEX the input allocatorId is not defined in platform store extension. * \retval C2_NO_MEMORY not enough memory to create the allocator */ c2_status_t createAllocator(::C2Allocator::id_t allocatorId, std::shared_ptr<C2Allocator>* const allocator); c2_status_t createAllocator( ::C2Allocator::id_t allocatorId, std::shared_ptr<C2Allocator>* const allocator, std::function<void(C2Allocator *)> deleter = std::default_delete<C2Allocator>()); private: explicit C2PlatformStorePluginLoader(const char *libPath); Loading