hal: Add support to handle A2DP codec config
Add support in audio HAL to respond for A2DP codec
config query from framework.
Bug: 79476124
Test: music playback over BT A2DP
Change-Id: I1dd010d7a723ef289efb0e825d094c7d64e06ee3
diff --git a/hal/audio_extn/a2dp.c b/hal/audio_extn/a2dp.c
index 8dc4a26..16f4826 100644
--- a/hal/audio_extn/a2dp.c
+++ b/hal/audio_extn/a2dp.c
@@ -1370,7 +1370,6 @@
ALOGD("%s: calling Bluetooth module stream start", __func__);
/* This call indicates Bluetooth IPC lib to start playback */
ret = a2dp.audio_stream_start();
- ALOGE("%s: Bluetooth controller start return = %d", __func__, ret);
if (ret != 0 ) {
ALOGE("%s: Bluetooth controller start failed", __func__);
a2dp.a2dp_started = false;
@@ -1457,16 +1456,17 @@
return 0;
}
-void audio_extn_a2dp_set_parameters(struct str_parms *parms)
+int audio_extn_a2dp_set_parameters(struct str_parms *parms, bool *reconfig)
{
- int ret, val;
+ int ret = 0, val;
char value[32] = {0};
struct audio_usecase *uc_info;
struct listnode *node;
if (a2dp.is_a2dp_offload_enabled == false) {
ALOGV("%s: No supported encoders identified,ignoring A2DP setparam", __func__);
- return;
+ ret = -EINVAL;
+ goto param_handled;
}
ret = str_parms_get_str(parms, AUDIO_PARAMETER_DEVICE_CONNECT, value,
@@ -1562,8 +1562,20 @@
}
goto param_handled;
}
+
+ ret = str_parms_get_str(parms, AUDIO_PARAMETER_RECONFIG_A2DP, value,
+ sizeof(value));
+ if (ret >= 0) {
+ if (a2dp.is_a2dp_offload_enabled &&
+ a2dp.bt_state != A2DP_STATE_DISCONNECTED) {
+ *reconfig = true;
+ }
+ goto param_handled;
+ }
+
param_handled:
ALOGV("%s: end of A2DP setparam", __func__);
+ return ret;
}
void audio_extn_a2dp_set_handoff_mode(bool is_on)
@@ -1664,4 +1676,21 @@
}
return latency;
}
+
+int audio_extn_a2dp_get_parameters(struct str_parms *query,
+ struct str_parms *reply)
+{
+ int ret, val = 0;
+ char value[32]={0};
+
+ ret = str_parms_get_str(query, AUDIO_PARAMETER_A2DP_RECONFIG_SUPPORTED,
+ value, sizeof(value));
+ if (ret >= 0) {
+ val = a2dp.is_a2dp_offload_enabled;
+ str_parms_add_int(reply, AUDIO_PARAMETER_A2DP_RECONFIG_SUPPORTED, val);
+ ALOGV("%s: called ... isReconfigA2dpSupported %d", __func__, val);
+ }
+
+ return 0;
+}
#endif // A2DP_OFFLOAD_ENABLED
diff --git a/hal/audio_extn/audio_extn.h b/hal/audio_extn/audio_extn.h
index 054beea..b1c701d 100644
--- a/hal/audio_extn/audio_extn.h
+++ b/hal/audio_extn/audio_extn.h
@@ -147,7 +147,8 @@
#define audio_extn_a2dp_init(adev) (0)
#define audio_extn_a2dp_start_playback() (0)
#define audio_extn_a2dp_stop_playback() (0)
-#define audio_extn_a2dp_set_parameters(parms) (0)
+#define audio_extn_a2dp_set_parameters(parms, reconfig) (0)
+#define audio_extn_a2dp_get_parameters(query, reply) (0)
#define audio_extn_a2dp_is_force_device_switch() (0)
#define audio_extn_a2dp_set_handoff_mode(is_on) (0)
#define audio_extn_a2dp_get_sample_rate(sample_rate) (0)
@@ -158,7 +159,9 @@
void audio_extn_a2dp_init(void *adev);
int audio_extn_a2dp_start_playback();
int audio_extn_a2dp_stop_playback();
-void audio_extn_a2dp_set_parameters(struct str_parms *parms);
+int audio_extn_a2dp_set_parameters(struct str_parms *parms, bool *reconfig);
+int audio_extn_a2dp_get_parameters(struct str_parms *query,
+ struct str_parms *reply);
bool audio_extn_a2dp_is_force_device_switch();
void audio_extn_a2dp_set_handoff_mode(bool is_on);
void audio_extn_a2dp_get_sample_rate(int *sample_rate);
diff --git a/hal/audio_hw.c b/hal/audio_hw.c
index 8a2562f..62b9cc2 100644
--- a/hal/audio_hw.c
+++ b/hal/audio_hw.c
@@ -4643,6 +4643,7 @@
int val;
int ret;
int status = 0;
+ bool a2dp_reconfig = false;
ALOGV("%s: enter: %s", __func__, kvpairs);
@@ -4741,18 +4742,16 @@
}
audio_extn_hfp_set_parameters(adev, parms);
- audio_extn_a2dp_set_parameters(parms);
audio_extn_ma_set_parameters(adev, parms);
- // reconfigure should be done only after updating A2DP state in audio extension
- ret = str_parms_get_str(parms,"reconfigA2dp", value, sizeof(value));
- if (ret >= 0) {
+ status = audio_extn_a2dp_set_parameters(parms, &a2dp_reconfig);
+ if (status >= 0 && a2dp_reconfig) {
struct audio_usecase *usecase;
struct listnode *node;
list_for_each(node, &adev->usecase_list) {
usecase = node_to_item(node, struct audio_usecase, list);
if ((usecase->type == PCM_PLAYBACK) &&
- (usecase->devices & AUDIO_DEVICE_OUT_BLUETOOTH_A2DP)) {
+ (usecase->devices & AUDIO_DEVICE_OUT_ALL_A2DP)) {
ALOGD("%s: reconfigure A2DP... forcing device switch", __func__);
pthread_mutex_unlock(&adev->lock);
@@ -4786,6 +4785,8 @@
pthread_mutex_lock(&adev->lock);
voice_get_parameters(adev, query, reply);
+ audio_extn_a2dp_get_parameters(query, reply);
+
str = str_parms_to_str(reply);
str_parms_destroy(query);
str_parms_destroy(reply);