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

Commit e321f352 authored by Sungtak Lee's avatar Sungtak Lee
Browse files

Enable pooled C2BlockPool

C2PooledBlockPool supports allocate & recycle blocks.
Currently C2PooledBlockPool supports C2LinearAllocation only.

Test: setprop debug.stagefright.ccodec yes
Test: stagefright -S -N c2.google.avc.decoder /sdcard/a.mp4
Test: stagefright -ao -N c2.google.aac.decoder /sdcard/a.mp4
Test: audioloop -N c2.google.aac.encoder -M audio/mp4a-latm
Test: screenrecord --codec-name c2.google.avc.encoder /sdcard/record.mp4

Bug: 72651719
Change-Id: I3948afecf492ef62860c9e8f18fc9243ddca78bd
parent b95a5989
Loading
Loading
Loading
Loading
+7 −8
Original line number Diff line number Diff line
@@ -760,19 +760,18 @@ void CCodecBufferChannel::setComponent(const std::shared_ptr<C2Component> &compo

        ALOGV("graphic = %s", graphic ? "true" : "false");
        std::shared_ptr<C2BlockPool> pool;
        err = GetCodec2BlockPool(
                graphic ? C2BlockPool::BASIC_GRAPHIC : C2BlockPool::BASIC_LINEAR,
                component,
                &pool);
        if (graphic) {
            err = GetCodec2BlockPool(C2BlockPool::BASIC_GRAPHIC, component, &pool);
        } else {
            err = CreateCodec2BlockPool(C2PlatformAllocatorStore::ION,
                                        component, &pool);
        }

        if (err == C2_OK) {
            (*buffers)->setPool(pool);
        } else {
            // TODO: error
        }
        // TODO: remove once we switch to proper buffer pool.
        if (!graphic) {
            *buffers = (*buffers)->toArrayMode();
        }
    }

    {
+9 −6
Original line number Diff line number Diff line
@@ -302,12 +302,15 @@ void SimpleC2Component::processQueue() {
            if (err != C2_OK) {
                return err;
            }
            if (outputFormat.value == C2FormatVideo) {
                err = GetCodec2BlockPool(
                    (outputFormat.value == C2FormatVideo)
                    ? C2BlockPool::BASIC_GRAPHIC
                    : C2BlockPool::BASIC_LINEAR,
                    shared_from_this(),
                    &mOutputBlockPool);
                        C2BlockPool::BASIC_GRAPHIC,
                        shared_from_this(), &mOutputBlockPool);
            } else {
                err = CreateCodec2BlockPool(
                        C2PlatformAllocatorStore::ION,
                        shared_from_this(), &mOutputBlockPool);
            }
            if (err != C2_OK) {
                return err;
            }
+4 −2
Original line number Diff line number Diff line
@@ -232,7 +232,8 @@ class C2BufferUtilsTest : public ::testing::Test {
class C2BufferTest : public ::testing::Test {
public:
    C2BufferTest()
        : mLinearAllocator(std::make_shared<C2AllocatorIon>('i')),
        : mBlockPoolId(C2BlockPool::PLATFORM_START),
          mLinearAllocator(std::make_shared<C2AllocatorIon>('i')),
          mSize(0u),
          mAddr(nullptr),
          mGraphicAllocator(std::make_shared<C2AllocatorGralloc>('g')) {
@@ -281,7 +282,7 @@ public:
    }

    std::shared_ptr<C2BlockPool> makeLinearBlockPool() {
        return std::make_shared<C2BasicLinearBlockPool>(mLinearAllocator);
        return std::make_shared<C2PooledBlockPool>(mLinearAllocator, mBlockPoolId++);
    }

    void allocateGraphic(uint32_t width, uint32_t height) {
@@ -328,6 +329,7 @@ public:
    }

private:
    C2BlockPool::local_id_t mBlockPoolId;
    std::shared_ptr<C2Allocator> mLinearAllocator;
    std::shared_ptr<C2LinearAllocation> mLinearAllocation;
    size_t mSize;
+3 −0
Original line number Diff line number Diff line
@@ -39,14 +39,17 @@ cc_library_shared {
    shared_libs: [
        "android.hardware.graphics.allocator@2.0",
        "android.hardware.graphics.mapper@2.0",
        "android.hardware.media.bufferpool@1.0",
        "libbinder",
        "libcutils",
        "libdl",
        "libhardware",
        "libhidlbase",
        "libion",
        "libfmq",
        "liblog",
        "libstagefright_foundation",
        "libstagefright_bufferpool@1.0",
        "libui",
        "libutils",
    ],
+9 −4
Original line number Diff line number Diff line
@@ -148,6 +148,7 @@ private:
     * so that we can capture the error.
     *
     * \param ionFd     ion client (ownership transferred to created object)
     * \param owned     whehter native_handle_t is owned by an allocation or not.
     * \param capacity  size of allocation
     * \param bufferFd  buffer handle (ownership transferred to created object). Must be
     *                  invalid if err is not 0.
@@ -155,8 +156,9 @@ private:
     *                  invalid if err is not 0.
     * \param err       errno during buffer allocation or import
     */
    Impl(int ionFd, size_t capacity, int bufferFd, ion_user_handle_t buffer, C2Allocator::id_t id, int err)
    Impl(int ionFd, bool owned, size_t capacity, int bufferFd, ion_user_handle_t buffer, C2Allocator::id_t id, int err)
        : mIonFd(ionFd),
          mHandleOwned(owned),
          mHandle(bufferFd, capacity),
          mBuffer(buffer),
          mId(id),
@@ -188,7 +190,7 @@ public:
    static Impl *Import(int ionFd, size_t capacity, int bufferFd, C2Allocator::id_t id) {
        ion_user_handle_t buffer = -1;
        int ret = ion_import(ionFd, bufferFd, &buffer);
        return new Impl(ionFd, capacity, bufferFd, buffer, id, ret);
        return new Impl(ionFd, false, capacity, bufferFd, buffer, id, ret);
    }

    /**
@@ -215,7 +217,7 @@ public:
                buffer = -1;
            }
        }
        return new Impl(ionFd, size, bufferFd, buffer, id, ret);
        return new Impl(ionFd, true, size, bufferFd, buffer, id, ret);
    }

    c2_status_t map(size_t offset, size_t size, C2MemoryUsage usage, C2Fence *fence, void **addr) {
@@ -302,8 +304,10 @@ public:
        if (mIonFd >= 0) {
            close(mIonFd);
        }
        if (mHandleOwned) {
            native_handle_close(&mHandle);
        }
    }

    c2_status_t status() const {
        return mInit;
@@ -323,6 +327,7 @@ public:

private:
    int mIonFd;
    bool mHandleOwned;
    C2HandleIon mHandle;
    ion_user_handle_t mBuffer;
    C2Allocator::id_t mId;
Loading