audio: optimize spatializer activation
Only enable the spatializer effect engine when the requested
level is not none and there are active playback clients.
Also set max update period to 1 second instead of 50ms when creating
the head pose controller as there is no need to wake so often if no
audio is processed by the spatializer effect.
Also add a missing forwarded of the head tracking mode to the engine
when the actual mode changes
Bug: 227740874
Test: make
Change-Id: I05a6f4e9edea319e300e98a33dc3a3fd78143466
diff --git a/services/audiopolicy/service/AudioPolicyService.cpp b/services/audiopolicy/service/AudioPolicyService.cpp
index c78a0b3..2b901a1 100644
--- a/services/audiopolicy/service/AudioPolicyService.cpp
+++ b/services/audiopolicy/service/AudioPolicyService.cpp
@@ -564,14 +564,21 @@
void AudioPolicyService::doOnUpdateActiveSpatializerTracks()
{
- Mutex::Autolock _l(mLock);
- if (mSpatializer == nullptr) {
- return;
+ sp<Spatializer> spatializer;
+ size_t activeClients;
+ {
+ Mutex::Autolock _l(mLock);
+ if (mSpatializer == nullptr) {
+ return;
+ }
+ spatializer = mSpatializer;
+ activeClients = countActiveClientsOnOutput_l(mSpatializer->getOutput());
}
- mSpatializer->updateActiveTracks(countActiveClientsOnOutput_l(mSpatializer->getOutput()));
+ if (spatializer != nullptr) {
+ spatializer->updateActiveTracks(activeClients);
+ }
}
-
status_t AudioPolicyService::clientCreateAudioPatch(const struct audio_patch *patch,
audio_patch_handle_t *handle,
int delayMs)