hal: Send A2DP backend config for each routed stream
There exists a corner case where A2DP backend config is not
sent after BE is closed and reopened leading to slimbus
running at default rate. This happens because A2DP snd_device
is already active, hence backend config for A2DP is not sent.
However, audio route is disabled and enabled i.e. BE is closed
and reopened. Thus, slimbus is configured at 8 KHz which is a
problem for A2DP.
Fix this by sending backend config for each stream that gets
routed to A2DP and A2DP snd_device is enabled.
Change-Id: I3edfcaaac9d0bc81f7be4090f8057f3947b1e5d0
diff --git a/hal/audio_extn/a2dp.c b/hal/audio_extn/a2dp.c
index 4bd9125..105c88d 100644
--- a/hal/audio_extn/a2dp.c
+++ b/hal/audio_extn/a2dp.c
@@ -1303,6 +1303,14 @@
return is_configured;
}
+bool a2dp_set_source_backend_cfg()
+{
+ if (a2dp.a2dp_source_started && !a2dp.a2dp_source_suspended)
+ return a2dp_set_backend_cfg(SOURCE);
+
+ return false;
+}
+
bool configure_aac_dec_format(audio_aac_dec_config_t *aac_bt_cfg)
{
struct mixer_ctl *ctl_dec_data = NULL, *ctrl_bit_format = NULL;
diff --git a/hal/audio_extn/audio_extn.c b/hal/audio_extn/audio_extn.c
index d53db94..c51a0ee 100644
--- a/hal/audio_extn/audio_extn.c
+++ b/hal/audio_extn/audio_extn.c
@@ -4641,6 +4641,9 @@
typedef int (*a2dp_stop_capture_t)();
static a2dp_stop_capture_t a2dp_stop_capture;
+typedef bool (*a2dp_set_source_backend_cfg_t)();
+static a2dp_set_source_backend_cfg_t a2dp_set_source_backend_cfg;
+
typedef int (*sco_start_configuration_t)();
static sco_start_configuration_t sco_start_configuration;
@@ -4695,7 +4698,10 @@
!(a2dp_start_capture =
(a2dp_start_capture_t)dlsym(a2dp_lib_handle, "a2dp_start_capture")) ||
!(a2dp_stop_capture =
- (a2dp_stop_capture_t)dlsym(a2dp_lib_handle, "a2dp_stop_capture"))) {
+ (a2dp_stop_capture_t)dlsym(a2dp_lib_handle, "a2dp_stop_capture")) ||
+ !(a2dp_set_source_backend_cfg =
+ (a2dp_set_source_backend_cfg_t)dlsym(
+ a2dp_lib_handle, "a2dp_set_source_backend_cfg"))) {
ALOGE("%s: dlsym failed", __func__);
goto feature_disabled;
}
@@ -4733,6 +4739,7 @@
a2dp_source_is_suspended = NULL;
a2dp_start_capture = NULL;
a2dp_stop_capture = NULL;
+ a2dp_set_source_backend_cfg = NULL;
ALOGW(":: %s: ---- Feature A2DP_OFFLOAD is disabled ----", __func__);
return -ENOSYS;
@@ -4831,6 +4838,12 @@
return (a2dp_stop_capture ? a2dp_stop_capture() : 0);
}
+bool audio_extn_a2dp_set_source_backend_cfg()
+{
+ return (a2dp_set_source_backend_cfg ?
+ a2dp_set_source_backend_cfg() : false);
+}
+
int audio_extn_sco_start_configuration()
{
return (sco_start_configuration? sco_start_configuration() : 0);
diff --git a/hal/audio_extn/audio_extn.h b/hal/audio_extn/audio_extn.h
index 0e4b9b0..853b034 100644
--- a/hal/audio_extn/audio_extn.h
+++ b/hal/audio_extn/audio_extn.h
@@ -327,6 +327,7 @@
bool audio_extn_a2dp_source_is_suspended();
int audio_extn_a2dp_start_capture();
int audio_extn_a2dp_stop_capture();
+bool audio_extn_a2dp_set_source_backend_cfg();
int audio_extn_sco_start_configuration();
void audio_extn_sco_reset_configuration();
diff --git a/hal/audio_hw.c b/hal/audio_hw.c
index 12e89dc..e8e71da 100644
--- a/hal/audio_hw.c
+++ b/hal/audio_hw.c
@@ -1385,6 +1385,11 @@
new_snd_devices) != 0)) {
ALOGV("%s: snd_device(%d: %s) is already active",
__func__, snd_device, device_name);
+ /* Set backend config for A2DP to ensure slimbus configuration
+ is correct if A2DP is already active and backend is closed
+ and re-opened */
+ if (snd_device == SND_DEVICE_OUT_BT_A2DP)
+ audio_extn_a2dp_set_source_backend_cfg();
return 0;
}