hal: HFP support for setting sampling rate
- Add support for setting sampling rate using setparameter. This
is to support 8000 or 16000 sampling rate set from BT
Change-Id: Ia6c7e530df0ba0226e492937e1c9acc70f6c6d13
diff --git a/hal/audio_extn/hfp.c b/hal/audio_extn/hfp.c
index 6b0546a..4eb9d37 100644
--- a/hal/audio_extn/hfp.c
+++ b/hal/audio_extn/hfp.c
@@ -42,6 +42,7 @@
#ifdef HFP_ENABLED
#define AUDIO_PARAMETER_HFP_ENABLE "hfp_enable"
+#define AUDIO_PARAMETER_HFP_SET_SAMPLING_RATE "hfp_set_sampling_rate"
static int32_t start_hfp(struct audio_device *adev,
struct str_parms *parms);
@@ -55,6 +56,7 @@
struct pcm *hfp_pcm_tx;
bool is_hfp_running;
int hfp_volume;
+ audio_usecase_t ucid;
};
static struct hfp_module hfpmod = {
@@ -64,6 +66,7 @@
.hfp_pcm_tx = NULL,
.hfp_volume = 0,
.is_hfp_running = 0,
+ .ucid = USECASE_AUDIO_HFP_SCO,
};
static struct pcm_config pcm_config_hfp = {
.channels = 1,
@@ -86,7 +89,7 @@
ALOGD("%s: enter", __func__);
uc_info = (struct audio_usecase *)calloc(1, sizeof(struct audio_usecase));
- uc_info->id = USECASE_AUDIO_HFP_SCO;
+ uc_info->id = hfpmod.ucid;
uc_info->type = PCM_HFP_CALL;
uc_info->stream.out = adev->primary_output;
uc_info->devices = adev->primary_output->devices;
@@ -95,7 +98,7 @@
list_add_tail(&adev->usecase_list, &uc_info->list);
- select_devices(adev, USECASE_AUDIO_HFP_SCO);
+ select_devices(adev, hfpmod.ucid);
pcm_dev_rx_id = platform_get_pcm_device_id(uc_info->id, PCM_PLAYBACK);
pcm_dev_tx_id = platform_get_pcm_device_id(uc_info->id, PCM_CAPTURE);
@@ -193,10 +196,10 @@
hfpmod.hfp_pcm_tx = NULL;
}
- uc_info = get_usecase_from_list(adev, USECASE_AUDIO_HFP_SCO);
+ uc_info = get_usecase_from_list(adev, hfpmod.ucid);
if (uc_info == NULL) {
ALOGE("%s: Could not find the usecase (%d) in the list",
- __func__, USECASE_AUDIO_HFP_SCO);
+ __func__, hfpmod.ucid);
return -EINVAL;
}
@@ -217,6 +220,7 @@
void audio_extn_hfp_set_parameters(struct audio_device *adev, struct str_parms *parms)
{
int ret;
+ int rate;
char value[32]={0};
ret = str_parms_get_str(parms, AUDIO_PARAMETER_HFP_ENABLE, value,
@@ -227,5 +231,21 @@
else
stop_hfp(adev);
}
+ memset(value, 0, sizeof(value));
+ ret = str_parms_get_str(parms,AUDIO_PARAMETER_HFP_SET_SAMPLING_RATE, value,
+ sizeof(value));
+ if (ret >= 0) {
+ rate = atoi(value);
+ if (rate == 8000){
+ hfpmod.ucid = USECASE_AUDIO_HFP_SCO;
+ pcm_config_hfp.rate = rate;
+ }
+ else if (rate == 16000){
+ hfpmod.ucid = USECASE_AUDIO_HFP_SCO_WB;
+ pcm_config_hfp.rate = rate;
+ }
+ else
+ ALOGE("Unsupported rate..");
+ }
}
#endif /*HFP_ENABLED*/