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

Commit 6b2c8bee authored by Wonsik Kim's avatar Wonsik Kim
Browse files

CCodec: ignore input buffer done callbacks before flush

These callbacks will clear buffer references that stashed
codec config is holding onto.

Bug: 196014695
Bug: 199818561
Test: cts/media/device-small
Change-Id: I9c04aaff26ad5e4f8b66e341e2098e863c1ce314
parent 16f2a93c
Loading
Loading
Loading
Loading
+14 −4
Original line number Original line Diff line number Diff line
@@ -19,6 +19,7 @@
#include <utils/Log.h>
#include <utils/Log.h>


#include <algorithm>
#include <algorithm>
#include <atomic>
#include <list>
#include <list>
#include <numeric>
#include <numeric>


@@ -155,6 +156,7 @@ CCodecBufferChannel::CCodecBufferChannel(
        input->pipelineDelay = 0u;
        input->pipelineDelay = 0u;
        input->numSlots = kSmoothnessFactor;
        input->numSlots = kSmoothnessFactor;
        input->numExtraSlots = 0u;
        input->numExtraSlots = 0u;
        input->lastFlushIndex = 0u;
    }
    }
    {
    {
        Mutexed<Output>::Locked output(mOutput);
        Mutexed<Output>::Locked output(mOutput);
@@ -1122,6 +1124,7 @@ status_t CCodecBufferChannel::start(
        input->numSlots = numInputSlots;
        input->numSlots = numInputSlots;
        input->extraBuffers.flush();
        input->extraBuffers.flush();
        input->numExtraSlots = 0u;
        input->numExtraSlots = 0u;
        input->lastFlushIndex = mFrameIndex.load(std::memory_order_relaxed);
        if (audioEncoder && encoderFrameSize && sampleRate && channelCount) {
        if (audioEncoder && encoderFrameSize && sampleRate && channelCount) {
            input->frameReassembler.init(
            input->frameReassembler.init(
                    pool,
                    pool,
@@ -1535,6 +1538,7 @@ void CCodecBufferChannel::flush(const std::list<std::unique_ptr<C2Work>> &flushe
    ALOGV("[%s] flush", mName);
    ALOGV("[%s] flush", mName);
    std::vector<uint64_t> indices;
    std::vector<uint64_t> indices;
    std::list<std::unique_ptr<C2Work>> configs;
    std::list<std::unique_ptr<C2Work>> configs;
    mInput.lock()->lastFlushIndex = mFrameIndex.load(std::memory_order_relaxed);
    for (const std::unique_ptr<C2Work> &work : flushedWork) {
    for (const std::unique_ptr<C2Work> &work : flushedWork) {
        indices.push_back(work->input.ordinal.frameIndex.peeku());
        indices.push_back(work->input.ordinal.frameIndex.peeku());
        if (!(work->input.flags & C2FrameData::FLAG_CODEC_CONFIG)) {
        if (!(work->input.flags & C2FrameData::FLAG_CODEC_CONFIG)) {
@@ -1601,14 +1605,20 @@ void CCodecBufferChannel::onInputBufferDone(
    }
    }
    std::shared_ptr<C2Buffer> buffer =
    std::shared_ptr<C2Buffer> buffer =
            mPipelineWatcher.lock()->onInputBufferReleased(frameIndex, arrayIndex);
            mPipelineWatcher.lock()->onInputBufferReleased(frameIndex, arrayIndex);
    bool newInputSlotAvailable;
    bool newInputSlotAvailable = false;
    {
    {
        Mutexed<Input>::Locked input(mInput);
        Mutexed<Input>::Locked input(mInput);
        if (input->lastFlushIndex >= frameIndex) {
            ALOGD("[%s] Ignoring stale input buffer done callback: "
                  "last flush index = %lld, frameIndex = %lld",
                  mName, input->lastFlushIndex.peekll(), (long long)frameIndex);
        } else {
            newInputSlotAvailable = input->buffers->expireComponentBuffer(buffer);
            newInputSlotAvailable = input->buffers->expireComponentBuffer(buffer);
            if (!newInputSlotAvailable) {
            if (!newInputSlotAvailable) {
                (void)input->extraBuffers.expireComponentBuffer(buffer);
                (void)input->extraBuffers.expireComponentBuffer(buffer);
            }
            }
        }
        }
    }
    if (newInputSlotAvailable) {
    if (newInputSlotAvailable) {
        feedInputBufferIfAvailable();
        feedInputBufferIfAvailable();
    }
    }
+1 −0
Original line number Original line Diff line number Diff line
@@ -273,6 +273,7 @@ private:
        size_t numExtraSlots;
        size_t numExtraSlots;
        uint32_t inputDelay;
        uint32_t inputDelay;
        uint32_t pipelineDelay;
        uint32_t pipelineDelay;
        c2_cntr64_t lastFlushIndex;


        FrameReassembler frameReassembler;
        FrameReassembler frameReassembler;
    };
    };