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

Change-Id: I420eab5e2187073b00fc6b50e589dff913da87af
gugelfrei
Automerger Merge Worker 4 years ago
commit fed70fb82c

@ -1295,6 +1295,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);
if (err2 != OK) {
mCallback->onError(err2, ACTION_CODE_FATAL);
@ -1523,18 +1525,26 @@ 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<Config>::Locked config(mConfig);
config->queryConfiguration(comp);
}
(void)mChannel->start(nullptr, nullptr);
{
@ -1730,7 +1740,7 @@ void CCodec::onMessageReceived(const sp<AMessage> &msg) {
// handle configuration changes in work done
Mutexed<Config>::Locked config(mConfig);
bool changed = false;
bool changed = !mSentConfigAfterResume.test_and_set();
Config::Watcher<C2StreamInitDataInfo::output> initData =
config->watch<C2StreamInitDataInfo::output>();
if (!work->worklets.empty()
@ -1762,7 +1772,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)

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

@ -1277,6 +1277,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);
@ -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;
if (worklet->output.flags & C2FrameData::FLAG_END_OF_STREAM) {
flags |= MediaCodec::BUFFER_FLAG_EOS;

Loading…
Cancel
Save