hal: Add change to fix speaker and headphone concurrency.
After the device switch from headset to the speaker, lag in playback
was observed.
The issue was seen because both the speaker and headphone was
configured using the native clock.
Add change to configure headphone to 48Khz sample rate before enabling
the use case on speaker.
Change-Id: I8ad1f2690e94a960f61fb7f36f49e8f6e5cace60
diff --git a/configs/holi/audio_platform_info.xml b/configs/holi/audio_platform_info.xml
index bb3673d..be986b3 100644
--- a/configs/holi/audio_platform_info.xml
+++ b/configs/holi/audio_platform_info.xml
@@ -133,6 +133,10 @@
<param key="true_32_bit" value="true"/>
<!-- In the below value string, the value indicates sidetone gain in dB -->
<param key="usb_sidetone_gain" value="35"/>
+ <!-- In the below value string, the value indicates whether the -->
+ <!-- target does not supports speaker and headphone working on -->
+ <!-- different fractional and integer sampling rate -->
+ <param key="spkr_hph_single_be_native_concurrency" value="true"/>
</config_params>
<gain_db_to_level_mapping>
<gain_level_map db="-59" level="5"/>
diff --git a/configs/holi/audio_platform_info_intcodec.xml b/configs/holi/audio_platform_info_intcodec.xml
index 33b1d0a..a032a92 100644
--- a/configs/holi/audio_platform_info_intcodec.xml
+++ b/configs/holi/audio_platform_info_intcodec.xml
@@ -110,6 +110,10 @@
<param key="native_audio_mode" value="multiple_mix_dsp"/>
<param key="hfp_pcm_dev_id" value="39"/>
<param key="input_mic_max_count" value="4"/>
+ <!-- In the below value string, the value indicates whether the -->
+ <!-- target does not supports speaker and headphone working on -->
+ <!-- different fractional and integer sampling rate -->
+ <param key="spkr_hph_single_be_native_concurrency" value="true"/>
</config_params>
<gain_db_to_level_mapping>
<gain_level_map db="-59" level="5"/>
diff --git a/configs/holi/audio_platform_info_qrd.xml b/configs/holi/audio_platform_info_qrd.xml
index 2d51fc3..f39273d 100644
--- a/configs/holi/audio_platform_info_qrd.xml
+++ b/configs/holi/audio_platform_info_qrd.xml
@@ -110,6 +110,10 @@
<param key="native_audio_mode" value="multiple_mix_dsp"/>
<param key="hfp_pcm_dev_id" value="39"/>
<param key="input_mic_max_count" value="2"/>
+ <!-- In the below value string, the value indicates whether the -->
+ <!-- target does not supports speaker and headphone working on -->
+ <!-- different fractional and integer sampling rate -->
+ <param key="spkr_hph_single_be_native_concurrency" value="true"/>
</config_params>
<gain_db_to_level_mapping>
<gain_level_map db="-59" level="5"/>
diff --git a/hal/audio_hw.c b/hal/audio_hw.c
index f441d3b..6da2652 100644
--- a/hal/audio_hw.c
+++ b/hal/audio_hw.c
@@ -935,6 +935,36 @@
adev->asrc_mode_enabled = false;
}
+static void check_and_configure_headphone(struct audio_device *adev,
+ struct audio_usecase *uc_info,
+ snd_device_t snd_device)
+{
+ struct listnode *node;
+ struct audio_usecase *usecase;
+ int new_backend_idx, usecase_backend_idx;
+ bool spkr_hph_single_be_native_concurrency;
+
+ new_backend_idx = platform_get_backend_index(snd_device);
+ spkr_hph_single_be_native_concurrency = platform_get_spkr_hph_single_be_native_concurrency_flag();
+ if ( spkr_hph_single_be_native_concurrency && (new_backend_idx == DEFAULT_CODEC_BACKEND)) {
+ list_for_each(node, &adev->usecase_list) {
+ usecase = node_to_item(node, struct audio_usecase, list);
+ if ((usecase->type != PCM_CAPTURE) && (usecase != uc_info)) {
+ usecase_backend_idx = platform_get_backend_index(usecase->out_snd_device);
+ if (((usecase_backend_idx == HEADPHONE_BACKEND) ||
+ (usecase_backend_idx == HEADPHONE_44_1_BACKEND)) &&
+ ((usecase->stream.out->sample_rate % OUTPUT_SAMPLING_RATE_44100) == 0)) {
+ disable_audio_route(adev, usecase);
+ disable_snd_device(adev, usecase->out_snd_device);
+ usecase->stream.out->sample_rate = DEFAULT_OUTPUT_SAMPLING_RATE;
+ enable_audio_route(adev, usecase);
+ enable_snd_device(adev, usecase->out_snd_device);
+ }
+ }
+ }
+ }
+}
+
/*
* - Enable ASRC mode for incoming mix path use case(Headphone backend)if Headphone
* 44.1 or Native DSD backends are enabled for any of current use case.
@@ -2968,6 +2998,7 @@
/* Enable new sound devices */
if (out_snd_device != SND_DEVICE_NONE) {
check_usecases_codec_backend(adev, usecase, out_snd_device);
+ check_and_configure_headphone(adev, usecase, out_snd_device);
if (platform_check_codec_asrc_support(adev->platform))
check_and_set_asrc_mode(adev, usecase, out_snd_device);
enable_snd_device(adev, out_snd_device);
diff --git a/hal/msm8974/platform.c b/hal/msm8974/platform.c
index 526a88f..8b88485 100644
--- a/hal/msm8974/platform.c
+++ b/hal/msm8974/platform.c
@@ -282,6 +282,7 @@
static native_audio_prop na_props = {0, 0, NATIVE_AUDIO_MODE_INVALID};
static bool supports_true_32_bit = false;
+static bool spkr_hph_single_be_native_concurrency = false;
static int max_be_dai_names = 0;
static const struct be_dai_name_struct *be_dai_name_table;
@@ -5159,6 +5160,27 @@
return ret;
}
+bool platform_get_spkr_hph_single_be_native_concurrency_flag()
+{
+ return spkr_hph_single_be_native_concurrency;
+}
+
+void spkr_hph_single_be_native_concurrency_params(struct str_parms *parms,
+ char *value, int len)
+{
+ int ret = 0;
+
+ ret = str_parms_get_str(parms, AUDIO_PARAMETER_SPKR_HPH_SINGLE_BE_NATIVE_CONCURRENCY,
+ value, len);
+ if (ret >= 0) {
+ if (value && !strncmp(value, "true", sizeof("true")))
+ spkr_hph_single_be_native_concurrency = true;
+ else
+ spkr_hph_single_be_native_concurrency = false;
+ str_parms_del(parms, AUDIO_PARAMETER_SPKR_HPH_SINGLE_BE_NATIVE_CONCURRENCY);
+ }
+}
+
void native_audio_get_params(struct str_parms *query,
struct str_parms *reply,
char *value, int len)
@@ -8427,6 +8449,7 @@
/* handle audio calibration parameters */
set_audiocal(platform, parms, value, len);
+ spkr_hph_single_be_native_concurrency_params(parms, value, len);
native_audio_set_params(platform, parms, value, len);
audio_extn_spkr_prot_set_parameters(parms, value, len);
audio_extn_usb_set_sidetone_gain(parms, value, len);
diff --git a/hal/msm8974/platform.h b/hal/msm8974/platform.h
index 415e4b0..1375c88 100644
--- a/hal/msm8974/platform.h
+++ b/hal/msm8974/platform.h
@@ -370,6 +370,8 @@
#define AUDIO_PARAMETER_KEY_TRUE_32_BIT "true_32_bit"
+#define AUDIO_PARAMETER_SPKR_HPH_SINGLE_BE_NATIVE_CONCURRENCY "spkr_hph_single_be_native_concurrency"
+
#define AUDIO_MAX_DSP_CHANNELS 32
#define ALL_SESSION_VSID 0xFFFFFFFF
diff --git a/hal/platform_api.h b/hal/platform_api.h
index f68d6e7..f58dce0 100644
--- a/hal/platform_api.h
+++ b/hal/platform_api.h
@@ -334,6 +334,7 @@
int platform_get_ext_disp_type(void *platform);
void platform_invalidate_hdmi_config(void *platform);
void platform_invalidate_backend_config(void * platform,snd_device_t snd_device);
+bool platform_get_spkr_hph_single_be_native_concurrency_flag();
#ifdef INSTANCE_ID_ENABLED
void platform_make_cal_cfg(acdb_audio_cal_cfg_t* cal, int acdb_dev_id,