hal: Fix for device check against wrong codec backend
Make sure out stream device is checked against out codec backend
device and in stream device against in codec backend. Checking out
device against in codec backend or vice versa leads to issues as
some out and in device ids are common except the bit in.
CRs-Fixed: 1088820
Change-Id: I1197411c287cf65d41ed1d16f300e962b677b832
diff --git a/hal/audio_hw.c b/hal/audio_hw.c
index e6dfb66..fb668d5 100644
--- a/hal/audio_hw.c
+++ b/hal/audio_hw.c
@@ -1089,10 +1089,19 @@
struct audio_usecase *usecase;
bool switch_device[AUDIO_USECASE_MAX];
int i, num_uc_to_switch = 0;
+ int backend_check_cond = AUDIO_DEVICE_OUT_ALL_CODEC_BACKEND;
bool force_routing = platform_check_and_set_capture_codec_backend_cfg(adev, uc_info,
snd_device);
ALOGD("%s:becf: force routing %d", __func__, force_routing);
+
+ /*
+ * Make sure out devices is checked against out codec backend device and
+ * also in devices against in codec backend. Checking out device against in
+ * codec backend or vice versa causes issues.
+ */
+ if (uc_info->type == PCM_CAPTURE)
+ backend_check_cond = AUDIO_DEVICE_IN_ALL_CODEC_BACKEND;
/*
* This function is to make sure that all the active capture usecases
* are always routed to the same input sound device.
@@ -1108,10 +1117,13 @@
list_for_each(node, &adev->usecase_list) {
usecase = node_to_item(node, struct audio_usecase, list);
+ /*
+ * TODO: Enhance below condition to handle BT sco/USB multi recording
+ */
if (usecase->type != PCM_PLAYBACK &&
usecase != uc_info &&
(usecase->in_snd_device != snd_device || force_routing) &&
- ((uc_info->devices & AUDIO_DEVICE_OUT_ALL_CODEC_BACKEND) &&
+ ((uc_info->devices & backend_check_cond) &&
(((usecase->devices & ~AUDIO_DEVICE_BIT_IN) & AUDIO_DEVICE_IN_ALL_CODEC_BACKEND) ||
(usecase->type == VOICE_CALL) || (usecase->type == VOIP_CALL))) &&
(usecase->id != USECASE_AUDIO_SPKR_CALIB_TX)) {
diff --git a/hal/msm8916/platform.c b/hal/msm8916/platform.c
index a6de6e9..c2bcbe0 100644
--- a/hal/msm8916/platform.c
+++ b/hal/msm8916/platform.c
@@ -2607,6 +2607,8 @@
if (backend_tag_table[snd_device] != NULL) {
if (strcmp(backend_tag_table[snd_device], "usb-headset-mic") == 0)
port = USB_AUDIO_TX_BACKEND;
+ else if (strstr(backend_tag_table[snd_device], "bt-sco") != NULL)
+ port = BT_SCO_TX_BACKEND;
}
} else {
ALOGW("%s:napb: Invalid device - %d ", __func__, snd_device);
@@ -3324,6 +3326,10 @@
{
struct platform_data *my_data = (struct platform_data *)platform;
struct audio_device *adev = my_data->adev;
+ /*
+ * TODO: active_input always points to last opened input. Source returned will
+ * be wrong if more than one active inputs are present.
+ */
audio_source_t source = (adev->active_input == NULL) ?
AUDIO_SOURCE_DEFAULT : adev->active_input->source;
@@ -4377,8 +4383,8 @@
__func__, bit_width, sample_rate, channels,backend_idx,
platform_get_snd_device_name(snd_device));
- if (bit_width !=
- my_data->current_backend_cfg[backend_idx].bit_width) {
+ if ((my_data->current_backend_cfg[backend_idx].bitwidth_mixer_ctl) &&
+ (bit_width != my_data->current_backend_cfg[backend_idx].bit_width)) {
struct mixer_ctl *ctl = NULL;
ctl = mixer_get_ctl_by_name(adev->mixer,
@@ -4416,7 +4422,8 @@
*/
// TODO: This has to be more dynamic based on policy file
- if ((sample_rate != my_data->current_backend_cfg[(int)backend_idx].sample_rate) &&
+ if ((my_data->current_backend_cfg[backend_idx].samplerate_mixer_ctl) &&
+ (sample_rate != my_data->current_backend_cfg[(int)backend_idx].sample_rate) &&
(my_data->hifi_audio)) {
/*
* sample rate update is needed only for hifi audio enabled platforms
diff --git a/hal/msm8916/platform.h b/hal/msm8916/platform.h
index a0ae7d0..24c793e 100644
--- a/hal/msm8916/platform.h
+++ b/hal/msm8916/platform.h
@@ -240,6 +240,7 @@
SLIMBUS_0_TX,
DEFAULT_CODEC_TX_BACKEND = SLIMBUS_0_TX,
USB_AUDIO_TX_BACKEND,
+ BT_SCO_TX_BACKEND,
MAX_CODEC_BACKENDS
};
diff --git a/hal/msm8974/platform.c b/hal/msm8974/platform.c
index 7bfc5de..81741fc 100644
--- a/hal/msm8974/platform.c
+++ b/hal/msm8974/platform.c
@@ -2370,6 +2370,8 @@
if (backend_tag_table[snd_device] != NULL) {
if (strcmp(backend_tag_table[snd_device], "usb-headset-mic") == 0)
port = USB_AUDIO_TX_BACKEND;
+ else if (strstr(backend_tag_table[snd_device], "bt-sco") != NULL)
+ port = BT_SCO_TX_BACKEND;
}
} else {
ALOGW("%s:napb: Invalid device - %d ", __func__, snd_device);
@@ -3025,6 +3027,10 @@
{
struct platform_data *my_data = (struct platform_data *)platform;
struct audio_device *adev = my_data->adev;
+ /*
+ * TODO: active_input always points to last opened input. Source returned will
+ * be wrong if more than one active inputs are present.
+ */
audio_source_t source = (adev->active_input == NULL) ?
AUDIO_SOURCE_DEFAULT : adev->active_input->source;
@@ -4357,8 +4363,8 @@
sample_rate, channels, backend_idx,
platform_get_snd_device_name(snd_device));
- if (bit_width !=
- my_data->current_backend_cfg[backend_idx].bit_width) {
+ if ((my_data->current_backend_cfg[backend_idx].bitwidth_mixer_ctl) &&
+ (bit_width != my_data->current_backend_cfg[backend_idx].bit_width)) {
struct mixer_ctl *ctl = NULL;
ctl = mixer_get_ctl_by_name(adev->mixer,
@@ -4392,8 +4398,8 @@
ret = 0;
}
- if (sample_rate !=
- my_data->current_backend_cfg[backend_idx].sample_rate) {
+ if ((my_data->current_backend_cfg[backend_idx].samplerate_mixer_ctl) &&
+ (sample_rate != my_data->current_backend_cfg[backend_idx].sample_rate)) {
char *rate_str = NULL;
struct mixer_ctl *ctl = NULL;
diff --git a/hal/msm8974/platform.h b/hal/msm8974/platform.h
index 6f55c2c..eb34293 100644
--- a/hal/msm8974/platform.h
+++ b/hal/msm8974/platform.h
@@ -231,6 +231,7 @@
SLIMBUS_0_TX,
DEFAULT_CODEC_TX_BACKEND = SLIMBUS_0_TX,
USB_AUDIO_TX_BACKEND,
+ BT_SCO_TX_BACKEND,
MAX_CODEC_BACKENDS
};