APM: use preferred config for device when it is available.
When a device is connected, the device configuration, which includes
sample rate, channel mask and format is selected, is picked at the
highest values to ensure the best experience. This configuration will be
used as the device configuration when creating audio patch. When
bit-perfect playback is active, the configuration should not be the
highest one. Instead, it should be the same as the bit-perfect
configuration. In that case, adding the concept of preferred
configuration, which will be set when bit-perfect playback is active.
The device will use preferred configuration when it is available.
Bug: 251215866
Test: manually
Change-Id: I58f8fd14c3b0f7cf10daba51d3c7c74713f19991
diff --git a/services/audiopolicy/managerdefault/AudioPolicyManager.cpp b/services/audiopolicy/managerdefault/AudioPolicyManager.cpp
index 135548f..7e5319c 100644
--- a/services/audiopolicy/managerdefault/AudioPolicyManager.cpp
+++ b/services/audiopolicy/managerdefault/AudioPolicyManager.cpp
@@ -6747,6 +6747,12 @@
closingOutput->stop();
}
closingOutput->close();
+ if ((closingOutput->getFlags().output & AUDIO_OUTPUT_FLAG_BIT_PERFECT)
+ == AUDIO_OUTPUT_FLAG_BIT_PERFECT) {
+ for (const auto device : closingOutput->devices()) {
+ device->setPreferredConfig(nullptr);
+ }
+ }
removeOutput(output);
mPreviousOutputs = mOutputs;
@@ -8361,6 +8367,12 @@
ALOGE("%s failed to open output %d", __func__, status);
return nullptr;
}
+ if ((flags & AUDIO_OUTPUT_FLAG_BIT_PERFECT) == AUDIO_OUTPUT_FLAG_BIT_PERFECT) {
+ auto portConfig = desc->getConfig();
+ for (const auto& device : devices) {
+ device->setPreferredConfig(&portConfig);
+ }
+ }
// Here is where the out_set_parameters() for card & device gets called
sp<DeviceDescriptor> device = devices.getDeviceForOpening();