hal: set backend sample rate with default rate
During device switch from headphone-44.1 to headphone, afe
output sample rate for headphone still is set to 44.1Khz
due to stream output sample rate is 44.1Khz. This causes
afe sample rate mismatch with configured device.
Fix it by setting AFE at default sample rate when stream
rate mismatch with configured device, and resetting codec
config when device backend is different.
CRs-Fixed: 2206207
Change-Id: I3af8051595e721604bd7086632b6c34997c8ea65
diff --git a/hal/audio_hw.c b/hal/audio_hw.c
index 9ebe142..e186199 100644
--- a/hal/audio_hw.c
+++ b/hal/audio_hw.c
@@ -1361,7 +1361,9 @@
platform_get_snd_device_name(snd_device),
platform_get_snd_device_name(usecase->out_snd_device),
platform_check_backends_match(snd_device, usecase->out_snd_device));
- if ((usecase->type != PCM_CAPTURE) && (usecase != uc_info)) {
+ if ((usecase->type != PCM_CAPTURE) &&
+ (usecase->type != VOICE_CALL) &&
+ (usecase != uc_info)) {
uc_derive_snd_device = derive_playback_snd_device(adev->platform,
usecase, uc_info, snd_device);
if (((uc_derive_snd_device != usecase->out_snd_device) || force_routing) &&
diff --git a/hal/msm8974/platform.c b/hal/msm8974/platform.c
index 475e438..00c3a3e 100644
--- a/hal/msm8974/platform.c
+++ b/hal/msm8974/platform.c
@@ -6202,6 +6202,13 @@
/*this is populated by check_codec_backend_cfg hence set default value to false*/
backend_cfg.passthrough_enabled = false;
+ /*check if the stream sample 44.1Khz rate is supported of configured device sample rate. If not
+ open afe at default sample rate.
+ */
+ if (backend_idx != HEADPHONE_44_1_BACKEND &&
+ usecase->stream.out->sample_rate == OUTPUT_SAMPLING_RATE_44100)
+ backend_cfg.sample_rate = DEFAULT_OUTPUT_SAMPLING_RATE;
+
/* Set Backend sampling rate to 176.4 for DSD64 and
* 352.8Khz for DSD128.
* Set Bit Width to 16
@@ -6225,7 +6232,8 @@
for (i = 0; i < num_devices; i++) {
ALOGI("%s: new_snd_devices[%d] is %d", __func__, i, new_snd_devices[i]);
if ((platform_check_codec_backend_cfg(adev, usecase, new_snd_devices[i],
- &backend_cfg))) {
+ &backend_cfg)) ||
+ (!platform_check_backends_match(usecase->out_snd_device, snd_device))) {
ret = platform_set_codec_backend_cfg(adev, new_snd_devices[i],
backend_cfg);
if (!ret) {