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

Commit df5dd141 authored by Wonsik Kim's avatar Wonsik Kim
Browse files

CCodec: limit number of max output buffers client can keep

Bug: 123632127
Test: bug repro steps
Test: atest CtsMediaTestCases -- --module-arg CtsMediaTestCases:size:small
Change-Id: I0040755aa904749e96c1c905e913beab570bd5b8
parent 627cb60a
Loading
Loading
Loading
Loading
+24 −8
Original line number Diff line number Diff line
@@ -94,6 +94,11 @@ public:
     */
    virtual void getArray(Vector<sp<MediaCodecBuffer>> *) const {}

    /**
     * Return number of buffers the client owns.
     */
    virtual size_t numClientBuffers() const = 0;

protected:
    std::string mComponentName; ///< name of component for debugging
    std::string mChannelName; ///< name of channel for debugging
@@ -152,11 +157,6 @@ public:
     */
    virtual std::unique_ptr<InputBuffers> toArrayMode(size_t size) = 0;

    /**
     * Return number of buffers the client owns.
     */
    virtual size_t numClientBuffers() const = 0;

protected:
    // Pool to obtain blocks for input buffers.
    std::shared_ptr<C2BlockPool> mPool;
@@ -1226,6 +1226,10 @@ public:
        mImpl.realloc(alloc);
    }

    size_t numClientBuffers() const final {
        return mImpl.numClientBuffers();
    }

private:
    BuffersArrayImpl mImpl;
};
@@ -1287,6 +1291,10 @@ public:
        return std::move(array);
    }

    size_t numClientBuffers() const final {
        return mImpl.numClientBuffers();
    }

    /**
     * Return an appropriate Codec2Buffer object for the type of buffers.
     *
@@ -1816,9 +1824,17 @@ void CCodecBufferChannel::feedInputBufferIfAvailable() {
}

void CCodecBufferChannel::feedInputBufferIfAvailableInternal() {
    while (!mInputMetEos &&
           !mReorderStash.lock()->hasPending() &&
           !mPipelineWatcher.lock()->pipelineFull()) {
    if (mInputMetEos ||
           mReorderStash.lock()->hasPending() ||
           mPipelineWatcher.lock()->pipelineFull()) {
        return;
    } else {
        Mutexed<std::unique_ptr<OutputBuffers>>::Locked buffers(mOutputBuffers);
        if ((*buffers)->numClientBuffers() >= mNumOutputSlots) {
            return;
        }
    }
    for (size_t i = 0; i < mNumInputSlots; ++i) {
        sp<MediaCodecBuffer> inBuffer;
        size_t index;
        {