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

Commit 3dedf68b authored by Wonsik Kim's avatar Wonsik Kim
Browse files

CCodecBufferChannel: fix output delay/reorder config

Record the changes first, and apply the changes after all settings
are read, similar to input delay handling.

Bug: 185869285
Test: cts/media/device-small
Merged-In: I449ae82c83001f5c76402df76eaa7672315aa32d
Change-Id: I449ae82c83001f5c76402df76eaa7672315aa32d
parent 5410138c
Loading
Loading
Loading
Loading
+41 −37
Original line number Diff line number Diff line
@@ -1629,7 +1629,8 @@ bool CCodecBufferChannel::handleWork(
        }
    }

    std::optional<uint32_t> newInputDelay, newPipelineDelay;
    std::optional<uint32_t> newInputDelay, newPipelineDelay, newOutputDelay, newReorderDepth;
    std::optional<C2Config::ordinal_key_t> newReorderKey;
    bool needMaxDequeueBufferCountUpdate = false;
    while (!worklet->output.configUpdate.empty()) {
        std::unique_ptr<C2Param> param;
@@ -1641,7 +1642,7 @@ bool CCodecBufferChannel::handleWork(
                if (reorderDepth.updateFrom(*param)) {
                    ALOGV("[%s] onWorkDone: updated reorder depth to %u",
                          mName, reorderDepth.value);
                    mOutput.lock()->buffers->setReorderDepth(reorderDepth.value);
                    newReorderDepth = reorderDepth.value;
                    needMaxDequeueBufferCountUpdate = true;
                } else {
                    ALOGD("[%s] onWorkDone: failed to read reorder depth",
@@ -1652,7 +1653,7 @@ bool CCodecBufferChannel::handleWork(
            case C2PortReorderKeySetting::CORE_INDEX: {
                C2PortReorderKeySetting::output reorderKey;
                if (reorderKey.updateFrom(*param)) {
                    mOutput.lock()->buffers->setReorderKey(reorderKey.value);
                    newReorderKey = reorderKey.value;
                    ALOGV("[%s] onWorkDone: updated reorder key to %u",
                          mName, reorderKey.value);
                } else {
@@ -1687,35 +1688,9 @@ bool CCodecBufferChannel::handleWork(
                        ALOGV("[%s] onWorkDone: updating output delay %u",
                              mName, outputDelay.value);
                        (void)mPipelineWatcher.lock()->outputDelay(outputDelay.value);
                        newOutputDelay = outputDelay.value;
                        needMaxDequeueBufferCountUpdate = true;

                        bool outputBuffersChanged = false;
                        size_t numOutputSlots = 0;
                        {
                            Mutexed<Output>::Locked output(mOutput);
                            if (!output->buffers) {
                                return false;
                            }
                            output->outputDelay = outputDelay.value;
                            numOutputSlots = outputDelay.value +
                                             kSmoothnessFactor;
                            if (output->numSlots < numOutputSlots) {
                                output->numSlots = numOutputSlots;
                                if (output->buffers->isArrayMode()) {
                                    OutputBuffersArray *array =
                                        (OutputBuffersArray *)output->buffers.get();
                                    ALOGV("[%s] onWorkDone: growing output buffer array to %zu",
                                          mName, numOutputSlots);
                                    array->grow(numOutputSlots);
                                    outputBuffersChanged = true;
                                }
                            }
                            numOutputSlots = output->numSlots;
                        }

                        if (outputBuffersChanged) {
                            mCCodecCallback->onOutputBuffersChanged();
                        }
                    }
                }
                break;
@@ -1755,14 +1730,43 @@ bool CCodecBufferChannel::handleWork(
            input->numSlots = newNumSlots;
        }
    }
    if (needMaxDequeueBufferCountUpdate) {
    size_t numOutputSlots = 0;
    uint32_t reorderDepth = 0;
        {
    bool outputBuffersChanged = false;
    if (newReorderKey || newReorderDepth || needMaxDequeueBufferCountUpdate) {
        Mutexed<Output>::Locked output(mOutput);
        if (!output->buffers) {
            return false;
        }
        numOutputSlots = output->numSlots;
            reorderDepth = output->buffers ? output->buffers->getReorderDepth() : 0;
        if (newReorderKey) {
            output->buffers->setReorderKey(newReorderKey.value());
        }
        if (newReorderDepth) {
            output->buffers->setReorderDepth(newReorderDepth.value());
        }
        reorderDepth = output->buffers->getReorderDepth();
        if (newOutputDelay) {
            output->outputDelay = newOutputDelay.value();
            numOutputSlots = newOutputDelay.value() + kSmoothnessFactor;
            if (output->numSlots < numOutputSlots) {
                output->numSlots = numOutputSlots;
                if (output->buffers->isArrayMode()) {
                    OutputBuffersArray *array =
                        (OutputBuffersArray *)output->buffers.get();
                    ALOGV("[%s] onWorkDone: growing output buffer array to %zu",
                          mName, numOutputSlots);
                    array->grow(numOutputSlots);
                    outputBuffersChanged = true;
                }
            }
        }
        numOutputSlots = output->numSlots;
    }
    if (outputBuffersChanged) {
        mCCodecCallback->onOutputBuffersChanged();
    }
    if (needMaxDequeueBufferCountUpdate) {
        Mutexed<OutputSurface>::Locked output(mOutputSurface);
        output->maxDequeueBuffers = numOutputSlots + reorderDepth + kRenderingDepth;
        if (output->surface) {