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

Commit 60569140 authored by TreeHugger Robot's avatar TreeHugger Robot Committed by Android (Google) Code Review
Browse files

Merge "codec2: switch perferred linear allocator type by pool mask"

parents e3c93d02 aa18ea5e
Loading
Loading
Loading
Loading
+4 −6
Original line number Diff line number Diff line
@@ -826,10 +826,8 @@ status_t CCodecBufferChannel::start(
    bool secure = mComponent->getName().find(".secure") != std::string::npos;

    std::shared_ptr<C2AllocatorStore> allocatorStore = GetCodec2PlatformAllocatorStore();
    int poolMask = property_get_int32(
            "debug.stagefright.c2-poolmask",
            1 << C2PlatformAllocatorStore::ION |
            1 << C2PlatformAllocatorStore::BUFFERQUEUE);
    int poolMask = GetCodec2PoolMask();
    C2PlatformAllocatorStore::id_t preferredLinearId = GetPreferredLinearAllocatorId(poolMask);

    if (inputFormat != nullptr) {
        bool graphic = (iStreamFormat.value == C2BufferData::GRAPHIC);
@@ -839,7 +837,7 @@ status_t CCodecBufferChannel::start(

            // set default allocator ID.
            pools->inputAllocatorId = (graphic) ? C2PlatformAllocatorStore::GRALLOC
                                                : C2PlatformAllocatorStore::ION;
                                                : preferredLinearId;

            // query C2PortAllocatorsTuning::input from component. If an allocator ID is obtained
            // from component, create the input block pool with given ID. Otherwise, use default IDs.
@@ -978,7 +976,7 @@ status_t CCodecBufferChannel::start(

            // set default allocator ID.
            pools->outputAllocatorId = (graphic) ? C2PlatformAllocatorStore::GRALLOC
                                                 : C2PlatformAllocatorStore::ION;
                                                 : preferredLinearId;

            // query C2PortAllocatorsTuning::output from component, or use default allocator if
            // unsuccessful.
+46 −5
Original line number Diff line number Diff line
@@ -22,14 +22,17 @@
#include <map>
#include <mutex>

#include <C2AllocatorIon.h>
#include <C2AllocatorBlob.h>
#include <C2AllocatorGralloc.h>
#include <C2AllocatorIon.h>
#include <C2BufferPriv.h>
#include <C2BlockInternal.h>
#include <C2PlatformSupport.h>
#include <bufferpool/ClientManager.h>

namespace {

using android::C2AllocatorBlob;
using android::C2AllocatorGralloc;
using android::C2AllocatorIon;
using android::hardware::media::bufferpool::BufferPoolData;
@@ -393,10 +396,29 @@ std::shared_ptr<_C2BlockPoolData> _C2BlockFactory::GetLinearBlockPoolData(
std::shared_ptr<C2LinearBlock> _C2BlockFactory::CreateLinearBlock(
        const C2Handle *handle) {
    // TODO: get proper allocator? and mutex?
    static std::unique_ptr<C2AllocatorIon> sAllocator = std::make_unique<C2AllocatorIon>(0);
    static std::unique_ptr<C2Allocator> sAllocator = []{
        std::unique_ptr<C2Allocator> allocator;
        if (android::GetPreferredLinearAllocatorId(android::GetCodec2PoolMask()) ==
                android::C2PlatformAllocatorStore::BLOB) {
            allocator = std::make_unique<C2AllocatorBlob>(android::C2PlatformAllocatorStore::BLOB);
        } else {
            allocator = std::make_unique<C2AllocatorIon>(android::C2PlatformAllocatorStore::ION);
        }
        return allocator;
    }();

    if (sAllocator == nullptr)
        return nullptr;

    bool isValidHandle = false;
    if (sAllocator->getId() == android::C2PlatformAllocatorStore::BLOB) {
        isValidHandle = C2AllocatorBlob::isValid(handle);
    } else {
        isValidHandle = C2AllocatorIon::isValid(handle);
    }

    std::shared_ptr<C2LinearAllocation> alloc;
    if (C2AllocatorIon::isValid(handle)) {
    if (isValidHandle) {
        c2_status_t err = sAllocator->priorLinearAllocation(handle, &alloc);
        if (err == C2_OK) {
            std::shared_ptr<C2LinearBlock> block = _C2BlockFactory::CreateLinearBlock(alloc);
@@ -409,10 +431,29 @@ std::shared_ptr<C2LinearBlock> _C2BlockFactory::CreateLinearBlock(
std::shared_ptr<C2LinearBlock> _C2BlockFactory::CreateLinearBlock(
        const C2Handle *cHandle, const std::shared_ptr<BufferPoolData> &data) {
    // TODO: get proper allocator? and mutex?
    static std::unique_ptr<C2AllocatorIon> sAllocator = std::make_unique<C2AllocatorIon>(0);
    static std::unique_ptr<C2Allocator> sAllocator = []{
        std::unique_ptr<C2Allocator> allocator;
        if (android::GetPreferredLinearAllocatorId(android::GetCodec2PoolMask()) ==
                android::C2PlatformAllocatorStore::BLOB) {
            allocator = std::make_unique<C2AllocatorBlob>(android::C2PlatformAllocatorStore::BLOB);
        } else {
            allocator = std::make_unique<C2AllocatorIon>(android::C2PlatformAllocatorStore::ION);
        }
        return allocator;
    }();

    if (sAllocator == nullptr)
        return nullptr;

    bool isValidHandle = false;
    if (sAllocator->getId() == android::C2PlatformAllocatorStore::BLOB) {
        isValidHandle = C2AllocatorBlob::isValid(cHandle);
    } else {
        isValidHandle = C2AllocatorIon::isValid(cHandle);
    }

    std::shared_ptr<C2LinearAllocation> alloc;
    if (C2AllocatorIon::isValid(cHandle)) {
    if (isValidHandle) {
        c2_status_t err = sAllocator->priorLinearAllocation(cHandle, &alloc);
        const std::shared_ptr<C2PooledBlockPoolData> poolData =
                std::make_shared<C2PooledBlockPoolData>(data);
+52 −3
Original line number Diff line number Diff line
@@ -18,6 +18,7 @@
#define LOG_NDEBUG 0
#include <utils/Log.h>

#include <C2AllocatorBlob.h>
#include <C2AllocatorGralloc.h>
#include <C2AllocatorIon.h>
#include <C2BufferPriv.h>
@@ -26,6 +27,7 @@
#include <C2Config.h>
#include <C2PlatformStorePluginLoader.h>
#include <C2PlatformSupport.h>
#include <cutils/properties.h>
#include <util/C2InterfaceHelper.h>

#include <dlfcn.h>
@@ -75,6 +77,9 @@ public:
    ~C2PlatformAllocatorStoreImpl() override = default;

private:
    /// returns a shared-singleton blob allocator (gralloc-backed)
    std::shared_ptr<C2Allocator> fetchBlobAllocator();

    /// returns a shared-singleton ion allocator
    std::shared_ptr<C2Allocator> fetchIonAllocator();

@@ -97,10 +102,12 @@ C2PlatformAllocatorStoreImpl::C2PlatformAllocatorStoreImpl() {
c2_status_t C2PlatformAllocatorStoreImpl::fetchAllocator(
        id_t id, std::shared_ptr<C2Allocator> *const allocator) {
    allocator->reset();
    if (id == C2AllocatorStore::DEFAULT_LINEAR) {
        id = GetPreferredLinearAllocatorId(GetCodec2PoolMask());
    }
    switch (id) {
    // TODO: should we implement a generic registry for all, and use that?
    case C2PlatformAllocatorStore::ION:
    case C2AllocatorStore::DEFAULT_LINEAR:
        *allocator = fetchIonAllocator();
        break;

@@ -113,6 +120,10 @@ c2_status_t C2PlatformAllocatorStoreImpl::fetchAllocator(
        *allocator = fetchBufferQueueAllocator();
        break;

    case C2PlatformAllocatorStore::BLOB:
        *allocator = fetchBlobAllocator();
        break;

    default:
        // Try to create allocator from platform store plugins.
        c2_status_t res =
@@ -222,6 +233,18 @@ std::shared_ptr<C2Allocator> C2PlatformAllocatorStoreImpl::fetchIonAllocator() {
    return allocator;
}

std::shared_ptr<C2Allocator> C2PlatformAllocatorStoreImpl::fetchBlobAllocator() {
    static std::mutex mutex;
    static std::weak_ptr<C2Allocator> blobAllocator;
    std::lock_guard<std::mutex> lock(mutex);
    std::shared_ptr<C2Allocator> allocator = blobAllocator.lock();
    if (allocator == nullptr) {
        allocator = std::make_shared<C2AllocatorBlob>(C2PlatformAllocatorStore::BLOB);
        blobAllocator = allocator;
    }
    return allocator;
}

std::shared_ptr<C2Allocator> C2PlatformAllocatorStoreImpl::fetchGrallocAllocator() {
    static std::mutex mutex;
    static std::weak_ptr<C2Allocator> grallocAllocator;
@@ -292,6 +315,18 @@ std::shared_ptr<C2ComponentStore> GetPreferredCodec2ComponentStore() {
    return gPreferredComponentStore ? gPreferredComponentStore : GetCodec2PlatformComponentStore();
}

int GetCodec2PoolMask() {
    return property_get_int32(
            "debug.stagefright.c2-poolmask",
            1 << C2PlatformAllocatorStore::ION |
            1 << C2PlatformAllocatorStore::BUFFERQUEUE);
}

C2PlatformAllocatorStore::id_t GetPreferredLinearAllocatorId(int poolMask) {
    return ((poolMask >> C2PlatformAllocatorStore::BLOB) & 1) ? C2PlatformAllocatorStore::BLOB
                                                              : C2PlatformAllocatorStore::ION;
}

namespace {

class _C2BlockPoolCache {
@@ -308,11 +343,25 @@ public:
        std::shared_ptr<C2Allocator> allocator;
        c2_status_t res = C2_NOT_FOUND;

        if (allocatorId == C2AllocatorStore::DEFAULT_LINEAR) {
            allocatorId = GetPreferredLinearAllocatorId(GetCodec2PoolMask());
        }
        switch(allocatorId) {
            case C2PlatformAllocatorStore::ION:
            case C2AllocatorStore::DEFAULT_LINEAR:
                res = allocatorStore->fetchAllocator(
                        C2AllocatorStore::DEFAULT_LINEAR, &allocator);
                        C2PlatformAllocatorStore::ION, &allocator);
                if (res == C2_OK) {
                    std::shared_ptr<C2BlockPool> ptr =
                            std::make_shared<C2PooledBlockPool>(
                                    allocator, poolId);
                    *pool = ptr;
                    mBlockPools[poolId] = ptr;
                    mComponents[poolId] = component;
                }
                break;
            case C2PlatformAllocatorStore::BLOB:
                res = allocatorStore->fetchAllocator(
                        C2PlatformAllocatorStore::BLOB, &allocator);
                if (res == C2_OK) {
                    std::shared_ptr<C2BlockPool> ptr =
                            std::make_shared<C2PooledBlockPool>(
+23 −0
Original line number Diff line number Diff line
@@ -65,6 +65,15 @@ public:
         */
        BUFFERQUEUE,

        /**
         * ID of the gralloc backed platform allocator for linear blob buffer.
         *
         * C2Handle layout is not public. Use C2AllocatorGralloc::UnwrapNativeCodec2GrallocHandle
         * to get the underlying gralloc handle from a C2Handle, and WrapNativeCodec2GrallocHandle
         * to create a C2Handle from a gralloc handle - for C2Allocator::priorAllocation.
         */
        BLOB,

        /**
         * ID of indicating the end of platform allocator definition.
         *
@@ -131,6 +140,20 @@ std::shared_ptr<C2ComponentStore> GetCodec2PlatformComponentStore();
 */
void SetPreferredCodec2ComponentStore(std::shared_ptr<C2ComponentStore> store);

/**
 * Returns the pool mask.
 * \retval the default pool mask should be adopted if it could not be obtained from property
 *         "debug.stagefright.c2-poolmask"
 */
int GetCodec2PoolMask();

/**
 * Returns the preferred linear buffer allocator id from param poolMask.
 * C2PlatformAllocatorStore::ION should be chosen as fallback allocator if BLOB is not enabled from
 * param poolMask.
 */
C2PlatformAllocatorStore::id_t GetPreferredLinearAllocatorId(int poolMask);

} // namespace android

#endif // STAGEFRIGHT_CODEC2_PLATFORM_SUPPORT_H_