CSD: Improve the MelProcessor lifecycle.
The MelProcessor lifecycle is now tied to the streaming thread
lifecycle. Whenever there are new patches and tracks for
sound dose we resume/pause the MEL calculation depending on
the track use case and device type.
Test: logging and dumpsys
Bug: 275370058
Change-Id: I9fb90df9ffb991f41f4209483bdafaf2b7474964
diff --git a/media/libnbaio/AudioStreamOutSink.cpp b/media/libnbaio/AudioStreamOutSink.cpp
index 8c54a3a..0ab5874 100644
--- a/media/libnbaio/AudioStreamOutSink.cpp
+++ b/media/libnbaio/AudioStreamOutSink.cpp
@@ -103,19 +103,24 @@
void AudioStreamOutSink::startMelComputation(const sp<audio_utils::MelProcessor>& processor)
{
ALOGV("%s start mel computation for device %d", __func__, processor->getDeviceId());
- mMelProcessor = processor;
- // update format for MEL computation
+
+ mMelProcessor.store(processor);
if (processor) {
- processor->updateAudioFormat(mFormat.mSampleRate, mFormat.mChannelCount, mFormat.mFormat);
+ // update format for MEL computation
+ processor->updateAudioFormat(mFormat.mSampleRate,
+ mFormat.mChannelCount,
+ mFormat.mFormat);
+ processor->resume();
}
+
}
void AudioStreamOutSink::stopMelComputation()
{
auto melProcessor = mMelProcessor.load();
if (melProcessor != nullptr) {
- ALOGV("%s stop mel computation for device %d", __func__, melProcessor->getDeviceId());
- mMelProcessor = nullptr;
+ ALOGV("%s pause mel computation for device %d", __func__, melProcessor->getDeviceId());
+ melProcessor->pause();
}
}