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/services/audioflinger/MelReporter.cpp b/services/audioflinger/MelReporter.cpp
index c5c9652..1b2f6c3 100644
--- a/services/audioflinger/MelReporter.cpp
+++ b/services/audioflinger/MelReporter.cpp
@@ -174,12 +174,14 @@
}
}
- std::lock_guard _afl(mAudioFlinger.mLock);
- std::lock_guard _l(mLock);
- ALOGV("%s add patch handle %d to active devices", __func__, handle);
- startMelComputationForActivePatch_l(newPatch);
- newPatch.csdActive = true;
- mActiveMelPatches[handle] = newPatch;
+ if (!newPatch.deviceHandles.empty()) {
+ std::lock_guard _afl(mAudioFlinger.mLock);
+ std::lock_guard _l(mLock);
+ ALOGV("%s add patch handle %d to active devices", __func__, handle);
+ startMelComputationForActivePatch_l(newPatch);
+ newPatch.csdActive = true;
+ mActiveMelPatches[handle] = newPatch;
+ }
}
void AudioFlinger::MelReporter::startMelComputationForActivePatch_l(const ActiveMelPatch& patch) {
@@ -250,7 +252,7 @@
return;
}
- auto outputThread = mAudioFlinger.checkOutputThread_l(patch.streamHandle);
+ auto outputThread = mAudioFlinger.checkOutputThread_l(patch.streamHandle);
ALOGV("%s: stop MEL for stream id: %d", __func__, patch.streamHandle);
for (const auto& deviceId : patch.deviceHandles) {
@@ -264,7 +266,6 @@
}
}
- mSoundDoseManager->removeStreamProcessor(patch.streamHandle);
if (outputThread != nullptr) {
outputThread->stopMelComputation_l();
}