Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 78763d3e authored by Android Build Coastguard Worker's avatar Android Build Coastguard Worker
Browse files

Snap for 7761443 from 6e6c9b08 to sc-v2-release

Change-Id: I55fef7b0f3d7cc85e15937fbd4d2e4d4b44f4cf1
parents 03f44055 6e6c9b08
Loading
Loading
Loading
Loading
+3 −5
Original line number Diff line number Diff line
@@ -287,6 +287,7 @@ c2_status_t C2SoftAacDec::onStop() {
    mOutputDelayRingBufferWritePos = 0;
    mOutputDelayRingBufferReadPos = 0;
    mOutputDelayRingBufferFilled = 0;
    mOutputDelayRingBuffer.reset();
    mBuffersInfo.clear();

    status_t status = UNKNOWN_ERROR;
@@ -308,10 +309,7 @@ void C2SoftAacDec::onRelease() {
        aacDecoder_Close(mAACDecoder);
        mAACDecoder = nullptr;
    }
    if (mOutputDelayRingBuffer) {
        delete[] mOutputDelayRingBuffer;
        mOutputDelayRingBuffer = nullptr;
    }
    mOutputDelayRingBuffer.reset();
}

status_t C2SoftAacDec::initDecoder() {
@@ -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;
+1 −1
Original line number Diff line number Diff line
@@ -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;
+7 −4
Original line number Diff line number Diff line
@@ -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;
@@ -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();
+31 −27
Original line number Diff line number Diff line
@@ -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,
@@ -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(
@@ -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(
@@ -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(
@@ -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(
@@ -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;
@@ -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);
@@ -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;
@@ -574,7 +589,6 @@ private:

static std::unique_ptr<_C2BlockPoolCache> sBlockPoolCache =
    std::make_unique<_C2BlockPoolCache>();
static std::mutex sBlockPoolCacheMutex;

} // anynymous namespace

@@ -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) {
@@ -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;
    }
@@ -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);
}

@@ -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);
}

+9 −5
Original line number Diff line number Diff line
@@ -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.
@@ -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