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

Commit 325322dd authored by Wonsik Kim's avatar Wonsik Kim
Browse files

CCodec: make config consistent before/after flush

If the CSD is processed before flush, make sure client and component
are in sync.

Bug: 141097367
Bug: 142542964
Bug: 149537770
Test: atest CtsMediaTestCases -- --module-arg CtsMediaTestCases:size:small
Change-Id: Ia51591770a4fdac1c1334a94fa8d6b2776da1a81
Merged-In: Ia51591770a4fdac1c1334a94fa8d6b2776da1a81
parent 29d260f6
Loading
Loading
Loading
Loading
+15 −3
Original line number Original line Diff line number Diff line
@@ -1295,6 +1295,8 @@ void CCodec::start() {
        mCallback->onError(err2, ACTION_CODE_FATAL);
        mCallback->onError(err2, ACTION_CODE_FATAL);
        return;
        return;
    }
    }
    // We're not starting after flush.
    (void)mSentConfigAfterResume.test_and_set();
    err2 = mChannel->start(inputFormat, outputFormat);
    err2 = mChannel->start(inputFormat, outputFormat);
    if (err2 != OK) {
    if (err2 != OK) {
        mCallback->onError(err2, ACTION_CODE_FATAL);
        mCallback->onError(err2, ACTION_CODE_FATAL);
@@ -1523,18 +1525,26 @@ void CCodec::flush() {
}
}


void CCodec::signalResume() {
void CCodec::signalResume() {
    auto setResuming = [this] {
    std::shared_ptr<Codec2Client::Component> comp;
    auto setResuming = [this, &comp] {
        Mutexed<State>::Locked state(mState);
        Mutexed<State>::Locked state(mState);
        if (state->get() != FLUSHED) {
        if (state->get() != FLUSHED) {
            return UNKNOWN_ERROR;
            return UNKNOWN_ERROR;
        }
        }
        state->set(RESUMING);
        state->set(RESUMING);
        comp = state->comp;
        return OK;
        return OK;
    };
    };
    if (tryAndReportOnError(setResuming) != OK) {
    if (tryAndReportOnError(setResuming) != OK) {
        return;
        return;
    }
    }


    mSentConfigAfterResume.clear();
    {
        Mutexed<Config>::Locked config(mConfig);
        config->queryConfiguration(comp);
    }

    (void)mChannel->start(nullptr, nullptr);
    (void)mChannel->start(nullptr, nullptr);


    {
    {
@@ -1730,7 +1740,7 @@ void CCodec::onMessageReceived(const sp<AMessage> &msg) {


            // handle configuration changes in work done
            // handle configuration changes in work done
            Mutexed<Config>::Locked config(mConfig);
            Mutexed<Config>::Locked config(mConfig);
            bool changed = false;
            bool changed = !mSentConfigAfterResume.test_and_set();
            Config::Watcher<C2StreamInitDataInfo::output> initData =
            Config::Watcher<C2StreamInitDataInfo::output> initData =
                config->watch<C2StreamInitDataInfo::output>();
                config->watch<C2StreamInitDataInfo::output>();
            if (!work->worklets.empty()
            if (!work->worklets.empty()
@@ -1762,7 +1772,9 @@ void CCodec::onMessageReceived(const sp<AMessage> &msg) {
                    ++stream;
                    ++stream;
                }
                }


                changed = config->updateConfiguration(updates, config->mOutputDomain);
                if (config->updateConfiguration(updates, config->mOutputDomain)) {
                    changed = true;
                }


                // copy standard infos to graphic buffers if not already present (otherwise, we
                // copy standard infos to graphic buffers if not already present (otherwise, we
                // may overwrite the actual intermediate value with a final value)
                // may overwrite the actual intermediate value with a final value)
+2 −0
Original line number Original line Diff line number Diff line
@@ -17,6 +17,7 @@
#ifndef C_CODEC_H_
#ifndef C_CODEC_H_
#define C_CODEC_H_
#define C_CODEC_H_


#include <atomic>
#include <chrono>
#include <chrono>
#include <list>
#include <list>
#include <memory>
#include <memory>
@@ -175,6 +176,7 @@ private:
    typedef CCodecConfig Config;
    typedef CCodecConfig Config;
    Mutexed<Config> mConfig;
    Mutexed<Config> mConfig;
    Mutexed<std::list<std::unique_ptr<C2Work>>> mWorkDoneQueue;
    Mutexed<std::list<std::unique_ptr<C2Work>>> mWorkDoneQueue;
    std::atomic_flag mSentConfigAfterResume;


    friend class CCodecCallbackImpl;
    friend class CCodecCallbackImpl;


+18 −18
Original line number Original line Diff line number Diff line
@@ -1277,6 +1277,24 @@ bool CCodecBufferChannel::handleWork(
        std::unique_ptr<C2Work> work,
        std::unique_ptr<C2Work> work,
        const sp<AMessage> &outputFormat,
        const sp<AMessage> &outputFormat,
        const C2StreamInitDataInfo::output *initData) {
        const C2StreamInitDataInfo::output *initData) {
    if (outputFormat != nullptr) {
        Mutexed<Output>::Locked output(mOutput);
        ALOGD("[%s] onWorkDone: output format changed to %s",
                mName, outputFormat->debugString().c_str());
        output->buffers->setFormat(outputFormat);

        AString mediaType;
        if (outputFormat->findString(KEY_MIME, &mediaType)
                && mediaType == MIMETYPE_AUDIO_RAW) {
            int32_t channelCount;
            int32_t sampleRate;
            if (outputFormat->findInt32(KEY_CHANNEL_COUNT, &channelCount)
                    && outputFormat->findInt32(KEY_SAMPLE_RATE, &sampleRate)) {
                output->buffers->updateSkipCutBuffer(sampleRate, channelCount);
            }
        }
    }

    if ((work->input.ordinal.frameIndex - mFirstValidFrameIndex.load()).peek() < 0) {
    if ((work->input.ordinal.frameIndex - mFirstValidFrameIndex.load()).peek() < 0) {
        // Discard frames from previous generation.
        // Discard frames from previous generation.
        ALOGD("[%s] Discard frames from previous generation.", mName);
        ALOGD("[%s] Discard frames from previous generation.", mName);
@@ -1454,24 +1472,6 @@ bool CCodecBufferChannel::handleWork(
        }
        }
    }
    }


    if (outputFormat != nullptr) {
        Mutexed<Output>::Locked output(mOutput);
        ALOGD("[%s] onWorkDone: output format changed to %s",
                mName, outputFormat->debugString().c_str());
        output->buffers->setFormat(outputFormat);

        AString mediaType;
        if (outputFormat->findString(KEY_MIME, &mediaType)
                && mediaType == MIMETYPE_AUDIO_RAW) {
            int32_t channelCount;
            int32_t sampleRate;
            if (outputFormat->findInt32(KEY_CHANNEL_COUNT, &channelCount)
                    && outputFormat->findInt32(KEY_SAMPLE_RATE, &sampleRate)) {
                output->buffers->updateSkipCutBuffer(sampleRate, channelCount);
            }
        }
    }

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