audio policy: restrict spatialization criteria for stereo
Do not spatialize stereo audio if offload or direct mode
is explicitly requested or low latency performance is requested.
Bug: 303920722
Test: manual test with OboeTester
Change-Id: If1c008789dfa5a81416bf4be5d485021bd412dbf
diff --git a/services/audiopolicy/managerdefault/AudioPolicyManager.cpp b/services/audiopolicy/managerdefault/AudioPolicyManager.cpp
index 46e4d60..24744a6 100644
--- a/services/audiopolicy/managerdefault/AudioPolicyManager.cpp
+++ b/services/audiopolicy/managerdefault/AudioPolicyManager.cpp
@@ -1632,10 +1632,13 @@
*flags = (audio_output_flags_t)(*flags | AUDIO_OUTPUT_FLAG_ULTRASOUND);
}
+ // Use the spatializer output if the content can be spatialized, no preferred mixer
+ // was specified and offload or direct playback is not explicitly requested.
*isSpatialized = false;
if (mSpatializerOutput != nullptr
&& canBeSpatializedInt(attr, config, devices.toTypeAddrVector())
- && prefMixerConfigInfo == nullptr) {
+ && prefMixerConfigInfo == nullptr
+ && ((*flags & (AUDIO_OUTPUT_FLAG_COMPRESS_OFFLOAD | AUDIO_OUTPUT_FLAG_DIRECT)) == 0)) {
*isSpatialized = true;
return mSpatializerOutput->mIoHandle;
}
@@ -6001,7 +6004,8 @@
// The caller can have the audio config criteria ignored by either passing a null ptr or
// the AUDIO_CONFIG_INITIALIZER value.
// If an audio config is specified, current policy is to only allow spatialization for
- // some positional channel masks and PCM format
+ // some positional channel masks and PCM format and for stereo if low latency performance
+ // mode is not requested.
if (config != nullptr && *config != AUDIO_CONFIG_INITIALIZER) {
const bool channel_mask_spatialized =
@@ -6014,6 +6018,10 @@
if (!audio_is_linear_pcm(config->format)) {
return false;
}
+ if (config->channel_mask == AUDIO_CHANNEL_OUT_STEREO
+ && ((attr->flags & AUDIO_FLAG_LOW_LATENCY) != 0)) {
+ return false;
+ }
}
sp<IOProfile> profile =