hal: Prevent superfluous device tear down on routing change
For playback usecases routing change, audio HAL disables sound device
if existing sound device does not match derived sound device and
enables the derived sound device. It does not check whether existing
sound device is a combination multiple devices and if one of those
devices matches with the derived sound device.
With scenarios like ringtone over speaker-and-bt-a2dp followed by
a2dp playback, we disable and re-enable bt-a2dp. This is unneeded
if a2dp backend is already active. Handle such scenarios by
disabling only devices that do not match the derived sound device.
CRs-Fixed: 2319384
Change-Id: I171fbead85746a2a34632f7580f56ef40505665c
diff --git a/hal/audio_hw.c b/hal/audio_hw.c
index 904b369..3e3f72f 100644
--- a/hal/audio_hw.c
+++ b/hal/audio_hw.c
@@ -1330,7 +1330,8 @@
bool switch_device[AUDIO_USECASE_MAX];
snd_device_t uc_derive_snd_device;
snd_device_t derive_snd_device[AUDIO_USECASE_MAX];
- int i, num_uc_to_switch = 0;
+ snd_device_t split_snd_devices[SND_DEVICE_OUT_END];
+ int i, num_uc_to_switch = 0, num_devices = 0;
int status = 0;
bool force_restart_session = false;
/*
@@ -1412,7 +1413,20 @@
list_for_each(node, &adev->usecase_list) {
usecase = node_to_item(node, struct audio_usecase, list);
if (switch_device[usecase->id]) {
- disable_snd_device(adev, usecase->out_snd_device);
+ /* Check if sound device to be switched can be split and if any
+ of the split devices match with derived sound device */
+ platform_split_snd_device(adev->platform, usecase->out_snd_device,
+ &num_devices, split_snd_devices);
+ if (num_devices > 1) {
+ for (i = 0; i < num_devices; i++) {
+ /* Disable devices that do not match with derived sound device */
+ if (split_snd_devices[i] != derive_snd_device[usecase->id]) {
+ disable_snd_device(adev, split_snd_devices[i]);
+ }
+ }
+ } else {
+ disable_snd_device(adev, usecase->out_snd_device);
+ }
}
}