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

Commit 576c8c44 authored by TreeHugger Robot's avatar TreeHugger Robot Committed by Android (Google) Code Review
Browse files

Merge "CCodec: make config consistent before/after flush"

parents 7109a82f e75a5da4
Loading
Loading
Loading
Loading
+16 −3
Original line number Diff line number Diff line
@@ -1323,6 +1323,8 @@ void CCodec::start() {
        mCallback->onError(err2, ACTION_CODE_FATAL);
        return;
    }
    // We're not starting after flush.
    (void)mSentConfigAfterResume.test_and_set();
    err2 = mChannel->start(inputFormat, outputFormat, buffersBoundToCodec);
    if (err2 != OK) {
        mCallback->onError(err2, ACTION_CODE_FATAL);
@@ -1555,18 +1557,27 @@ void CCodec::flush() {
}

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

    mSentConfigAfterResume.clear();
    {
        Mutexed<std::unique_ptr<Config>>::Locked configLocked(mConfig);
        const std::unique_ptr<Config> &config = *configLocked;
        config->queryConfiguration(comp);
    }

    (void)mChannel->start(nullptr, nullptr, [&]{
        Mutexed<std::unique_ptr<Config>>::Locked configLocked(mConfig);
        const std::unique_ptr<Config> &config = *configLocked;
@@ -1770,7 +1781,7 @@ void CCodec::onMessageReceived(const sp<AMessage> &msg) {
            // handle configuration changes in work done
            Mutexed<std::unique_ptr<Config>>::Locked configLocked(mConfig);
            const std::unique_ptr<Config> &config = *configLocked;
            bool changed = false;
            bool changed = !mSentConfigAfterResume.test_and_set();
            Config::Watcher<C2StreamInitDataInfo::output> initData =
                config->watch<C2StreamInitDataInfo::output>();
            if (!work->worklets.empty()
@@ -1802,7 +1813,9 @@ void CCodec::onMessageReceived(const sp<AMessage> &msg) {
                    ++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
                // may overwrite the actual intermediate value with a final value)
+18 −18
Original line number Diff line number Diff line
@@ -1457,6 +1457,24 @@ bool CCodecBufferChannel::handleWork(
        std::unique_ptr<C2Work> work,
        const sp<AMessage> &outputFormat,
        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) {
        // Discard frames from previous generation.
        ALOGD("[%s] Discard frames from previous generation.", mName);
@@ -1634,24 +1652,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;
    if (worklet->output.flags & C2FrameData::FLAG_END_OF_STREAM) {
        flags |= MediaCodec::BUFFER_FLAG_EOS;
+2 −0
Original line number Diff line number Diff line
@@ -17,6 +17,7 @@
#ifndef C_CODEC_H_
#define C_CODEC_H_

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

    friend class CCodecCallbackImpl;