audio spatializer: more resource usage optimizations
Enable the spatializer effect, only when active AND spatialized tracks
are present on the spatializer mixer.
This is useful for the case where only one output mixer is available to
reach a particular device (e.g. A2DP) and this mixer is a spatializer
mixer. In this case, non spatialized tracks are the majority of the activity
on this mixer.
Also only create the head pose controller when the desired head tracking
mode is not static and there is a head pose sensor registered. The max
calculation interval is also changed so that no calculation happens
unless explicitely requested by the spatializer.
Bug: 227740874
Test: regular and spatial audio playback on a Bluetooth headphone with
LDAC codec.
Change-Id: Ib3197da54f47fca63f0e4a6c95546b56a7065b6f
diff --git a/services/audiopolicy/service/Spatializer.cpp b/services/audiopolicy/service/Spatializer.cpp
index 971aaa8..3b466d7 100644
--- a/services/audiopolicy/service/Spatializer.cpp
+++ b/services/audiopolicy/service/Spatializer.cpp
@@ -373,10 +373,8 @@
break;
}
- if (mPoseController != nullptr) {
- mPoseController->setDesiredMode(mDesiredHeadTrackingMode);
- checkSensorsState_l();
- }
+ checkPoseController_l();
+ checkSensorsState_l();
return Status::ok();
}
@@ -449,6 +447,7 @@
}
std::lock_guard lock(mLock);
mHeadSensor = sensorHandle;
+ checkPoseController_l();
checkSensorsState_l();
return Status::ok();
}
@@ -460,7 +459,9 @@
}
std::lock_guard lock(mLock);
mScreenSensor = sensorHandle;
- checkSensorsState_l();
+ if (mPoseController != nullptr) {
+ mPoseController->setScreenSensor(mScreenSensor);
+ }
return Status::ok();
}
@@ -654,25 +655,20 @@
return status;
}
- checkEngineState_l();
outputChanged = mOutput != output;
mOutput = output;
+ mNumActiveTracks = numActiveTracks;
+ checkEngineState_l();
if (mSupportsHeadTracking) {
- mPoseController = std::make_shared<SpatializerPoseController>(
- static_cast<SpatializerPoseController::Listener*>(this), 10ms, 1000ms);
- LOG_ALWAYS_FATAL_IF(mPoseController == nullptr,
- "%s could not allocate pose controller", __func__);
-
- mPoseController->setDesiredMode(mDesiredHeadTrackingMode);
- mNumActiveTracks = numActiveTracks;
+ checkPoseController_l();
checkSensorsState_l();
- mPoseController->setDisplayOrientation(mDisplayOrientation);
poseController = mPoseController;
}
callback = mSpatializerCallback;
}
if (poseController != nullptr) {
+ poseController->calculateAsync();
poseController->waitUntilCalculated();
}
@@ -747,6 +743,25 @@
}
}
+void Spatializer::checkPoseController_l() {
+ bool isControllerNeeded = mDesiredHeadTrackingMode != HeadTrackingMode::STATIC
+ && mHeadSensor != SpatializerPoseController::INVALID_SENSOR;
+
+ if (isControllerNeeded && mPoseController == nullptr) {
+ mPoseController = std::make_shared<SpatializerPoseController>(
+ static_cast<SpatializerPoseController::Listener*>(this),
+ 10ms, std::chrono::microseconds::max());
+ LOG_ALWAYS_FATAL_IF(mPoseController == nullptr,
+ "%s could not allocate pose controller", __func__);
+ mPoseController->setDisplayOrientation(mDisplayOrientation);
+ } else if (!isControllerNeeded && mPoseController != nullptr) {
+ mPoseController.reset();
+ }
+ if (mPoseController != nullptr) {
+ mPoseController->setDesiredMode(mDesiredHeadTrackingMode);
+ }
+}
+
void Spatializer::calculateHeadPose() {
ALOGV("%s", __func__);
std::lock_guard lock(mLock);