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

Commit d7d89aa1 authored by Wonsik Kim's avatar Wonsik Kim Committed by Cherrypicker Worker
Browse files

CCodecBufferChannel: stash flushed input buffers from PipelineWatcher

Currently converter code reconstructs a buffer object when it comes
through HAL interface. Using this buffer in flushed work could
confuse lifecycle management of the buffers, so retrieve the input
buffers from the PipelineWatcher which stores the original input
buffer references.

Bug: 196014695
Test: cts/media/device-small
(cherry picked from commit 92df7e4f)
Merged-In:I06128438d0de52e139e939afe7e59b166f404c1a

Change-Id: I575d77a6d501d0736ddca1a924c5a6b0d6427a47
parents 2e035132 127cfb1e
Loading
Loading
Loading
Loading
+45 −37
Original line number Diff line number Diff line
@@ -1455,6 +1455,16 @@ status_t CCodecBufferChannel::requestInitialInputBuffers() {
    std::list<std::unique_ptr<C2Work>> flushedConfigs;
    mFlushedConfigs.lock()->swap(flushedConfigs);
    if (!flushedConfigs.empty()) {
        {
            Mutexed<PipelineWatcher>::Locked watcher(mPipelineWatcher);
            PipelineWatcher::Clock::time_point now = PipelineWatcher::Clock::now();
            for (const std::unique_ptr<C2Work> &work : flushedConfigs) {
                watcher->onWorkQueued(
                        work->input.ordinal.frameIndex.peeku(),
                        std::vector(work->input.buffers),
                        now);
            }
        }
        err = mComponent->queue(&flushedConfigs);
        if (err != C2_OK) {
            ALOGW("[%s] Error while queueing a flushed config", mName);
@@ -1521,31 +1531,33 @@ void CCodecBufferChannel::release() {
    setDescrambler(nullptr);
}


void CCodecBufferChannel::flush(const std::list<std::unique_ptr<C2Work>> &flushedWork) {
    ALOGV("[%s] flush", mName);
    std::vector<uint64_t> indices;
    std::list<std::unique_ptr<C2Work>> configs;
    mInput.lock()->lastFlushIndex = mFrameIndex.load(std::memory_order_relaxed);
    {
        Mutexed<PipelineWatcher>::Locked watcher(mPipelineWatcher);
        for (const std::unique_ptr<C2Work> &work : flushedWork) {
        indices.push_back(work->input.ordinal.frameIndex.peeku());
            uint64_t frameIndex = work->input.ordinal.frameIndex.peeku();
            if (!(work->input.flags & C2FrameData::FLAG_CODEC_CONFIG)) {
                watcher->onWorkDone(frameIndex);
                continue;
            }
            if (work->input.buffers.empty()
                    || work->input.buffers.front() == nullptr
                    || work->input.buffers.front()->data().linearBlocks().empty()) {
                ALOGD("[%s] no linear codec config data found", mName);
                watcher->onWorkDone(frameIndex);
                continue;
            }
            std::unique_ptr<C2Work> copy(new C2Work);
        copy->input.flags = C2FrameData::flags_t(work->input.flags | C2FrameData::FLAG_DROP_FRAME);
            copy->input.flags = C2FrameData::flags_t(
                    work->input.flags | C2FrameData::FLAG_DROP_FRAME);
            copy->input.ordinal = work->input.ordinal;
            copy->input.ordinal.frameIndex = mFrameIndex++;
        copy->input.buffers.insert(
                copy->input.buffers.begin(),
                work->input.buffers.begin(),
                work->input.buffers.end());
            for (size_t i = 0; i < work->input.buffers.size(); ++i) {
                copy->input.buffers.push_back(watcher->onInputBufferReleased(frameIndex, i));
            }
            for (const std::unique_ptr<C2Param> &param : work->input.configUpdate) {
                copy->input.configUpdate.push_back(C2Param::Copy(*param));
            }
@@ -1555,8 +1567,10 @@ void CCodecBufferChannel::flush(const std::list<std::unique_ptr<C2Work>> &flushe
                    work->input.infoBuffers.end());
            copy->worklets.emplace_back(new C2Worklet);
            configs.push_back(std::move(copy));
            watcher->onWorkDone(frameIndex);
            ALOGV("[%s] stashed flushed codec config data", mName);
        }
    }
    mFlushedConfigs.lock()->swap(configs);
    {
        Mutexed<Input>::Locked input(mInput);
@@ -1570,12 +1584,6 @@ void CCodecBufferChannel::flush(const std::list<std::unique_ptr<C2Work>> &flushe
            output->buffers->flushStash();
        }
    }
    {
        Mutexed<PipelineWatcher>::Locked watcher(mPipelineWatcher);
        for (uint64_t index : indices) {
            watcher->onWorkDone(index);
        }
    }
}

void CCodecBufferChannel::onWorkDone(