Loading media/codec2/sfplugin/CCodec.cpp +17 −4 Original line number Original line Diff line number Diff line Loading @@ -1286,7 +1286,8 @@ void CCodec::start() { { { Mutexed<Config>::Locked config(mConfig); Mutexed<Config>::Locked config(mConfig); inputFormat = config->mInputFormat; inputFormat = config->mInputFormat; outputFormat = config->mOutputFormat; // start triggers format dup outputFormat = config->mOutputFormat = config->mOutputFormat->dup(); if (config->mInputSurface) { if (config->mInputSurface) { err2 = config->mInputSurface->start(); err2 = config->mInputSurface->start(); } } Loading @@ -1295,6 +1296,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); Loading Loading @@ -1523,18 +1526,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); { { Loading Loading @@ -1730,7 +1741,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() Loading Loading @@ -1762,7 +1773,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) Loading media/codec2/sfplugin/CCodec.h +2 −0 Original line number Original line Diff line number Diff line Loading @@ -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> Loading Loading @@ -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; Loading media/codec2/sfplugin/CCodecBufferChannel.cpp +19 −19 Original line number Original line Diff line number Diff line Loading @@ -1072,7 +1072,7 @@ status_t CCodecBufferChannel::start( } else { } else { output->buffers.reset(new LinearOutputBuffers(mName)); output->buffers.reset(new LinearOutputBuffers(mName)); } } output->buffers->setFormat(outputFormat->dup()); output->buffers->setFormat(outputFormat); // Try to set output surface to created block pool if given. // Try to set output surface to created block pool if given. Loading Loading @@ -1276,6 +1276,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); Loading Loading @@ -1453,24 +1471,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; Loading Loading
media/codec2/sfplugin/CCodec.cpp +17 −4 Original line number Original line Diff line number Diff line Loading @@ -1286,7 +1286,8 @@ void CCodec::start() { { { Mutexed<Config>::Locked config(mConfig); Mutexed<Config>::Locked config(mConfig); inputFormat = config->mInputFormat; inputFormat = config->mInputFormat; outputFormat = config->mOutputFormat; // start triggers format dup outputFormat = config->mOutputFormat = config->mOutputFormat->dup(); if (config->mInputSurface) { if (config->mInputSurface) { err2 = config->mInputSurface->start(); err2 = config->mInputSurface->start(); } } Loading @@ -1295,6 +1296,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); Loading Loading @@ -1523,18 +1526,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); { { Loading Loading @@ -1730,7 +1741,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() Loading Loading @@ -1762,7 +1773,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) Loading
media/codec2/sfplugin/CCodec.h +2 −0 Original line number Original line Diff line number Diff line Loading @@ -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> Loading Loading @@ -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; Loading
media/codec2/sfplugin/CCodecBufferChannel.cpp +19 −19 Original line number Original line Diff line number Diff line Loading @@ -1072,7 +1072,7 @@ status_t CCodecBufferChannel::start( } else { } else { output->buffers.reset(new LinearOutputBuffers(mName)); output->buffers.reset(new LinearOutputBuffers(mName)); } } output->buffers->setFormat(outputFormat->dup()); output->buffers->setFormat(outputFormat); // Try to set output surface to created block pool if given. // Try to set output surface to created block pool if given. Loading Loading @@ -1276,6 +1276,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); Loading Loading @@ -1453,24 +1471,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; Loading