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

Commit 315e40a3 authored by Wonsik Kim's avatar Wonsik Kim
Browse files

CCodec: reorganize max dequeue count update

Bug: 166411210
Test: atest CtsMediaTestCases -- --module-arg CtsMediaTestCases:size:small
Change-Id: I417be209330e699b48b097115e8302310c1c9da2
parent c1532745
Loading
Loading
Loading
Loading
+19 −34
Original line number Diff line number Diff line
@@ -1064,9 +1064,6 @@ status_t CCodecBufferChannel::start(
            Mutexed<OutputSurface>::Locked output(mOutputSurface);
            output->maxDequeueBuffers = numOutputSlots +
                    reorderDepth.value + kRenderingDepth;
            if (!secure) {
                output->maxDequeueBuffers += numInputSlots;
            }
            outputSurface = output->surface ?
                    output->surface->getIGraphicBufferProducer() : nullptr;
            if (outputSurface) {
@@ -1527,6 +1524,7 @@ bool CCodecBufferChannel::handleWork(
    }

    std::optional<uint32_t> newInputDelay, newPipelineDelay;
    bool needMaxDequeueBufferCountUpdate = false;
    while (!worklet->output.configUpdate.empty()) {
        std::unique_ptr<C2Param> param;
        worklet->output.configUpdate.back().swap(param);
@@ -1535,24 +1533,10 @@ bool CCodecBufferChannel::handleWork(
            case C2PortReorderBufferDepthTuning::CORE_INDEX: {
                C2PortReorderBufferDepthTuning::output reorderDepth;
                if (reorderDepth.updateFrom(*param)) {
                    bool secure = mComponent->getName().find(".secure") !=
                                  std::string::npos;
                    mOutput.lock()->buffers->setReorderDepth(
                            reorderDepth.value);
                    ALOGV("[%s] onWorkDone: updated reorder depth to %u",
                          mName, reorderDepth.value);
                    size_t numOutputSlots = mOutput.lock()->numSlots;
                    size_t numInputSlots = mInput.lock()->numSlots;
                    Mutexed<OutputSurface>::Locked output(mOutputSurface);
                    output->maxDequeueBuffers = numOutputSlots +
                            reorderDepth.value + kRenderingDepth;
                    if (!secure) {
                        output->maxDequeueBuffers += numInputSlots;
                    }
                    if (output->surface) {
                        output->surface->setMaxDequeuedBufferCount(
                                output->maxDequeueBuffers);
                    }
                    mOutput.lock()->buffers->setReorderDepth(reorderDepth.value);
                    needMaxDequeueBufferCountUpdate = true;
                } else {
                    ALOGD("[%s] onWorkDone: failed to read reorder depth",
                          mName);
@@ -1596,14 +1580,11 @@ bool CCodecBufferChannel::handleWork(
                    if (outputDelay.updateFrom(*param)) {
                        ALOGV("[%s] onWorkDone: updating output delay %u",
                              mName, outputDelay.value);
                        bool secure = mComponent->getName().find(".secure") !=
                                      std::string::npos;
                        (void)mPipelineWatcher.lock()->outputDelay(
                                outputDelay.value);
                        (void)mPipelineWatcher.lock()->outputDelay(outputDelay.value);
                        needMaxDequeueBufferCountUpdate = true;

                        bool outputBuffersChanged = false;
                        size_t numOutputSlots = 0;
                        size_t numInputSlots = mInput.lock()->numSlots;
                        {
                            Mutexed<Output>::Locked output(mOutput);
                            if (!output->buffers) {
@@ -1629,16 +1610,6 @@ bool CCodecBufferChannel::handleWork(
                        if (outputBuffersChanged) {
                            mCCodecCallback->onOutputBuffersChanged();
                        }

                        uint32_t depth = mOutput.lock()->buffers->getReorderDepth();
                        Mutexed<OutputSurface>::Locked output(mOutputSurface);
                        output->maxDequeueBuffers = numOutputSlots + depth + kRenderingDepth;
                        if (!secure) {
                            output->maxDequeueBuffers += numInputSlots;
                        }
                        if (output->surface) {
                            output->surface->setMaxDequeuedBufferCount(output->maxDequeueBuffers);
                        }
                    }
                }
                break;
@@ -1667,6 +1638,20 @@ bool CCodecBufferChannel::handleWork(
            input->numSlots = newNumSlots;
        }
    }
    if (needMaxDequeueBufferCountUpdate) {
        size_t numOutputSlots = 0;
        uint32_t reorderDepth = 0;
        {
            Mutexed<Output>::Locked output(mOutput);
            numOutputSlots = output->numSlots;
            reorderDepth = output->buffers->getReorderDepth();
        }
        Mutexed<OutputSurface>::Locked output(mOutputSurface);
        output->maxDequeueBuffers = numOutputSlots + reorderDepth + kRenderingDepth;
        if (output->surface) {
            output->surface->setMaxDequeuedBufferCount(output->maxDequeueBuffers);
        }
    }

    int32_t flags = 0;
    if (worklet->output.flags & C2FrameData::FLAG_END_OF_STREAM) {