From ae8ed8dad8134d41e39d8d8173c83a83a0c51419 Mon Sep 17 00:00:00 2001 From: Amey Inamdar Date: Thu, 12 Apr 2018 10:47:21 +0530 Subject: [PATCH] bt-a2dp: BT A2DP sink and source selection is now runtime Earlier they have to be selected at the compile time through sdkconfig. A2DP sink and source application tested with this change. Signed-off-by: Amey Inamdar --- components/bt/Kconfig | 14 ++------------ .../bluedroid/btc/profile/std/a2dp/btc_a2dp.c | 11 ++++++----- .../btc/profile/std/a2dp/btc_a2dp_control.c | 9 +++++---- .../btc/profile/std/a2dp/btc_a2dp_sink.c | 1 + .../bt/bluedroid/btc/profile/std/a2dp/btc_av.c | 17 +++++++++++++++++ .../bluedroid/btc/profile/std/include/btc_av.h | 12 ++++++++++++ .../bluedroid/common/include/common/bt_target.h | 8 +------- examples/bluetooth/a2dp_sink/sdkconfig.defaults | 2 -- .../bluetooth/a2dp_source/sdkconfig.defaults | 2 -- 9 files changed, 44 insertions(+), 32 deletions(-) diff --git a/components/bt/Kconfig b/components/bt/Kconfig index 37d660cf98..cc301947b4 100644 --- a/components/bt/Kconfig +++ b/components/bt/Kconfig @@ -120,24 +120,14 @@ config A2DP_ENABLE help Advanced Audio Distrubution Profile -choice A2DP_ROLE - prompt "A2DP ROLE config" - depends on A2DP_ENABLE - -config A2DP_SINK_ENABLE - bool "SINK" -config A2DP_SRC_ENABLE - bool "SOURCE" -endchoice - config A2DP_SINK_TASK_STACK_SIZE int "A2DP sink (audio stream decoding) task stack size" - depends on A2DP_ENABLE && A2DP_SINK_ENABLE + depends on A2DP_ENABLE default 2048 config A2DP_SOURCE_TASK_STACK_SIZE int "A2DP source (audio stream encoding) task stack size" - depends on A2DP_ENABLE && A2DP_SRC_ENABLE + depends on A2DP_ENABLE default 2048 config BT_SPP_ENABLED diff --git a/components/bt/bluedroid/btc/profile/std/a2dp/btc_a2dp.c b/components/bt/bluedroid/btc/profile/std/a2dp/btc_a2dp.c index 3987d05c87..43d8f93290 100644 --- a/components/bt/bluedroid/btc/profile/std/a2dp/btc_a2dp.c +++ b/components/bt/bluedroid/btc/profile/std/a2dp/btc_a2dp.c @@ -49,9 +49,10 @@ void btc_a2dp_on_init(void) void btc_a2dp_on_idle(void) { - APPL_TRACE_EVENT("## ON A2DP IDLE ## peer_sep = %d", btc_av_get_peer_sep()); + APPL_TRACE_EVENT("## ON A2DP IDLE ## peer_sep = %d, service id = %d", btc_av_get_peer_sep(), + btc_av_get_service_id()); #if BTC_AV_SRC_INCLUDED - if (btc_av_get_peer_sep() == AVDT_TSEP_SNK) { + if (btc_av_get_peer_sep() == AVDT_TSEP_SNK && btc_av_get_service_id() == BTA_A2DP_SOURCE_SERVICE_ID) { btc_a2dp_source_on_idle(); } #endif // BTC_AV_SRC_INCLUDED @@ -59,7 +60,7 @@ void btc_a2dp_on_idle(void) bta_av_co_init(); #if BTC_AV_SINK_INCLUDED - if (btc_av_get_peer_sep() == AVDT_TSEP_SRC) { + if (btc_av_get_peer_sep() == AVDT_TSEP_SRC && btc_av_get_service_id() == BTA_A2DP_SINK_SERVICE_ID) { btc_a2dp_sink_on_idle(); } #endif // BTC_AV_SINK_INCLUDED @@ -120,7 +121,7 @@ void btc_a2dp_on_stopped(tBTA_AV_SUSPEND *p_av) { APPL_TRACE_EVENT("## ON A2DP STOPPED ##"); #if BTC_AV_SINK_INCLUDED - if (btc_av_get_peer_sep() == AVDT_TSEP_SRC) { + if (btc_av_get_peer_sep() == AVDT_TSEP_SRC && btc_av_get_service_id() == BTA_A2DP_SINK_SERVICE_ID) { btc_a2dp_sink_on_stopped(p_av); return; } @@ -140,7 +141,7 @@ void btc_a2dp_on_suspended(tBTA_AV_SUSPEND *p_av) { APPL_TRACE_EVENT("## ON A2DP SUSPENDED ##"); #if BTC_AV_SINK_INCLUDED - if (btc_av_get_peer_sep() == AVDT_TSEP_SRC) { + if (btc_av_get_peer_sep() == AVDT_TSEP_SRC && btc_av_get_service_id() == BTA_A2DP_SINK_SERVICE_ID) { btc_a2dp_sink_on_suspended(p_av); return; } diff --git a/components/bt/bluedroid/btc/profile/std/a2dp/btc_a2dp_control.c b/components/bt/bluedroid/btc/profile/std/a2dp/btc_a2dp_control.c index 6c6f30f1a9..aca3f5d860 100644 --- a/components/bt/bluedroid/btc/profile/std/a2dp/btc_a2dp_control.c +++ b/components/bt/bluedroid/btc/profile/std/a2dp/btc_a2dp_control.c @@ -75,7 +75,7 @@ void btc_a2dp_control_command_ack(int status) static void btc_a2dp_datapath_open(void) { #if BTC_AV_SRC_INCLUDED - if (btc_av_get_peer_sep() == AVDT_TSEP_SNK) { + if (btc_av_get_peer_sep() == AVDT_TSEP_SNK && btc_av_get_service_id() == BTA_A2DP_SOURCE_SERVICE_ID) { /* Start the media task to encode SBC */ btc_a2dp_source_start_audio_req(); @@ -147,7 +147,7 @@ void btc_a2dp_control_media_ctrl(esp_a2d_media_ctrl_t ctrl) btc_a2dp_dispatch_datapath_evt(BTC_AV_DATAPATH_OPEN_EVT); #if (BTC_AV_SINK_INCLUDED == TRUE) - if (btc_av_get_peer_sep() == AVDT_TSEP_SRC) { + if (btc_av_get_peer_sep() == AVDT_TSEP_SRC && btc_av_get_service_id() == BTA_A2DP_SINK_SERVICE_ID) { btc_a2dp_control_command_ack(ESP_A2D_MEDIA_CTRL_ACK_SUCCESS); } #endif @@ -160,7 +160,8 @@ void btc_a2dp_control_media_ctrl(esp_a2d_media_ctrl_t ctrl) break; case ESP_A2D_MEDIA_CTRL_STOP: #if BTC_AV_SRC_INCLUDED - if (btc_av_get_peer_sep() == AVDT_TSEP_SNK && !btc_a2dp_source_is_streaming()) { + if (btc_av_get_peer_sep() == AVDT_TSEP_SNK && !btc_a2dp_source_is_streaming() && + btc_av_get_service_id() == BTA_A2DP_SOURCE_SERVICE_ID) { /* we are already stopped, just ack back*/ btc_a2dp_control_command_ack(ESP_A2D_MEDIA_CTRL_ACK_SUCCESS); break; @@ -168,7 +169,7 @@ void btc_a2dp_control_media_ctrl(esp_a2d_media_ctrl_t ctrl) #endif /* BTC_AV_SRC_INCLUDED */ btc_dispatch_sm_event(BTC_AV_STOP_STREAM_REQ_EVT, NULL, 0); #if (BTC_AV_SINK_INCLUDED == TRUE) - if (btc_av_get_peer_sep() == AVDT_TSEP_SRC) { + if (btc_av_get_peer_sep() == AVDT_TSEP_SRC && btc_av_get_service_id() == BTA_A2DP_SINK_SERVICE_ID) { btc_a2dp_control_command_ack(ESP_A2D_MEDIA_CTRL_ACK_SUCCESS); } #endif diff --git a/components/bt/bluedroid/btc/profile/std/a2dp/btc_a2dp_sink.c b/components/bt/bluedroid/btc/profile/std/a2dp/btc_a2dp_sink.c index e5747e62be..2722b3e9bd 100644 --- a/components/bt/bluedroid/btc/profile/std/a2dp/btc_a2dp_sink.c +++ b/components/bt/bluedroid/btc/profile/std/a2dp/btc_a2dp_sink.c @@ -588,6 +588,7 @@ static void btc_a2dp_sink_handle_inc_media(tBT_SBC_HDR *p_msg) UINT32 sbc_frame_len = p_msg->len - 1; availPcmBytes = 2 * sizeof(pcmData); + /* XXX: Check if the below check is correct, we are checking for peer to be sink when we are sink */ if (btc_av_get_peer_sep() == AVDT_TSEP_SNK || (btc_aa_snk_cb.rx_flush)) { APPL_TRACE_DEBUG(" State Changed happened in this tick "); return; diff --git a/components/bt/bluedroid/btc/profile/std/a2dp/btc_av.c b/components/bt/bluedroid/btc/profile/std/a2dp/btc_av.c index 0541111886..2911a0d7ce 100644 --- a/components/bt/bluedroid/btc/profile/std/a2dp/btc_av.c +++ b/components/bt/bluedroid/btc/profile/std/a2dp/btc_av.c @@ -72,6 +72,7 @@ typedef enum { ******************************************************************************/ typedef struct { + int service_id; tBTA_AV_HNDL bta_handle; bt_bdaddr_t peer_bda; btc_sm_handle_t sm_handle; @@ -957,6 +958,7 @@ static void btc_av_event_free_data(btc_sm_event_t event, void *p_data) static bt_status_t btc_av_init(int service_id) { if (btc_av_cb.sm_handle == NULL) { + btc_av_cb.service_id = service_id; bool stat = false; if (service_id == BTA_A2DP_SOURCE_SERVICE_ID) { #if BTC_AV_SRC_INCLUDED @@ -1265,6 +1267,21 @@ BOOLEAN btc_av_is_connected(void) return ((state == BTC_AV_STATE_OPENED) || (state == BTC_AV_STATE_STARTED)); } +/******************************************************************************* + * + * Function btc_av_get_service_id + * + * Description Get the current AV service ID. + * + * Returns The stream endpoint type: either BTA_A2DP_SOURCE_SERVICE_ID or + * BTA_A2DP_SINK_SERVICE_ID. + * + ******************************************************************************/ +uint8_t btc_av_get_service_id(void) +{ + return btc_av_cb.service_id; +} + /******************************************************************************* * * Function btc_av_get_peer_sep diff --git a/components/bt/bluedroid/btc/profile/std/include/btc_av.h b/components/bt/bluedroid/btc/profile/std/include/btc_av.h index 78cf7cf0d9..4f3554bb39 100644 --- a/components/bt/bluedroid/btc/profile/std/include/btc_av.h +++ b/components/bt/bluedroid/btc/profile/std/include/btc_av.h @@ -203,6 +203,18 @@ BOOLEAN btc_av_is_peer_edr(void); ********************************************************************************/ void btc_av_clear_remote_suspend_flag(void); +/******************************************************************************* + * + * Function btc_av_get_service_id + * + * Description Get the current AV service ID. + * + * Returns The stream endpoint type: either BTA_A2DP_SOURCE_SERVICE_ID or + * BTA_A2DP_SINK_SERVICE_ID. + * + ******************************************************************************/ +uint8_t btc_av_get_service_id(void); + #endif ///BTC_AV_INCLUDED == TRUE #endif /* __BTC_AV_H__ */ diff --git a/components/bt/bluedroid/common/include/common/bt_target.h b/components/bt/bluedroid/common/include/common/bt_target.h index 55b84b808f..9edb93dfd0 100644 --- a/components/bt/bluedroid/common/include/common/bt_target.h +++ b/components/bt/bluedroid/common/include/common/bt_target.h @@ -60,18 +60,12 @@ #define AVCT_INCLUDED TRUE #define AVRC_INCLUDED TRUE #define BTC_AV_INCLUDED TRUE -#endif /* CONFIG_A2DP_ENABLE */ - -#if CONFIG_A2DP_SINK_ENABLE #define BTA_AV_SINK_INCLUDED TRUE #define BTC_AV_SINK_INCLUDED TRUE #define SBC_DEC_INCLUDED TRUE -#endif /* CONFIG_A2DP_SINK_ENABLE */ - -#if CONFIG_A2DP_SRC_ENABLE #define BTC_AV_SRC_INCLUDED TRUE #define SBC_ENC_INCLUDED TRUE -#endif /* CONFIG_A2DP_SRC_ENABLE */ +#endif /* CONFIG_A2DP_ENABLE */ #if CONFIG_BT_SPP_ENABLED #define RFCOMM_INCLUDED TRUE diff --git a/examples/bluetooth/a2dp_sink/sdkconfig.defaults b/examples/bluetooth/a2dp_sink/sdkconfig.defaults index d99fa240cb..82779f66ef 100644 --- a/examples/bluetooth/a2dp_sink/sdkconfig.defaults +++ b/examples/bluetooth/a2dp_sink/sdkconfig.defaults @@ -4,8 +4,6 @@ CONFIG_BT_ENABLED=y CONFIG_BLUEDROID_ENABLED=y CONFIG_CLASSIC_BT_ENABLED=y CONFIG_A2DP_ENABLE=y -CONFIG_A2DP_SINK_ENABLE=y -CONFIG_A2DP_SRC_ENABLE= CONFIG_BT_SPP_ENABLED= CONFIG_GATTS_ENABLE= CONFIG_GATTC_ENABLE= diff --git a/examples/bluetooth/a2dp_source/sdkconfig.defaults b/examples/bluetooth/a2dp_source/sdkconfig.defaults index 1ec00447a9..6625f76f4d 100644 --- a/examples/bluetooth/a2dp_source/sdkconfig.defaults +++ b/examples/bluetooth/a2dp_source/sdkconfig.defaults @@ -4,8 +4,6 @@ CONFIG_BT_ENABLED=y CONFIG_BLUEDROID_ENABLED=y CONFIG_CLASSIC_BT_ENABLED=y CONFIG_A2DP_ENABLE=y -CONFIG_A2DP_SINK_ENABLE= -CONFIG_A2DP_SRC_ENABLE=y CONFIG_BT_SPP_ENABLED= CONFIG_GATTS_ENABLE= CONFIG_GATTC_ENABLE=