From 04a7771f3378122b25334580bb47cf0f585199d5 Mon Sep 17 00:00:00 2001 From: weitianhua Date: Tue, 28 Jul 2020 22:10:50 +0800 Subject: [PATCH] Remove uneccessary macro Separate AVRC from A2DP when AVRC not Initialized --- .../bt/host/bluedroid/bta/av/bta_av_act.c | 7 +-- .../bt/host/bluedroid/bta/av/bta_av_main.c | 10 --- .../bluedroid/bta/include/bta/bta_av_api.h | 6 -- .../bluedroid/btc/profile/std/a2dp/btc_a2dp.c | 2 +- .../btc/profile/std/a2dp/btc_a2dp_source.c | 2 - .../bluedroid/btc/profile/std/a2dp/btc_av.c | 62 ++++++++++++------- .../bluedroid/btc/profile/std/avrc/btc_avrc.c | 6 ++ .../btc/profile/std/include/btc_av.h | 2 + 8 files changed, 52 insertions(+), 45 deletions(-) diff --git a/components/bt/host/bluedroid/bta/av/bta_av_act.c b/components/bt/host/bluedroid/bta/av/bta_av_act.c index bc5484add1..e3687da832 100644 --- a/components/bt/host/bluedroid/bta/av/bta_av_act.c +++ b/components/bt/host/bluedroid/bta/av/bta_av_act.c @@ -208,11 +208,8 @@ static void bta_av_rc_ctrl_cback(UINT8 handle, UINT8 event, UINT16 result, BD_AD UINT16 msg_event = 0; UNUSED(result); -#if (defined(BTA_AV_MIN_DEBUG_TRACES) && BTA_AV_MIN_DEBUG_TRACES == TRUE) - APPL_TRACE_EVENT("rc_ctrl handle: %d event=0x%x", handle, event); -#else - APPL_TRACE_EVENT("bta_av_rc_ctrl_cback handle: %d event=0x%x", handle, event); -#endif + APPL_TRACE_EVENT("%s handle: %d event: 0x%x",__func__, handle, event); + if (event == AVRC_OPEN_IND_EVT) { /* save handle of opened connection bta_av_cb.rc_handle = handle;*/ diff --git a/components/bt/host/bluedroid/bta/av/bta_av_main.c b/components/bt/host/bluedroid/bta/av/bta_av_main.c index 77d43c0425..335905c1e6 100644 --- a/components/bt/host/bluedroid/bta/av/bta_av_main.c +++ b/components/bt/host/bluedroid/bta/av/bta_av_main.c @@ -568,13 +568,8 @@ static void bta_av_api_register(tBTA_AV_DATA *p_data) if (bta_av_cb.features & (BTA_AV_FEAT_RCTG)) { /* register with no authorization; let AVDTP use authorization instead */ #if( defined BTA_AR_INCLUDED ) && (BTA_AR_INCLUDED == TRUE) -#if (BTA_AV_WITH_AVCTP_AUTHORIZATION == TRUE) - bta_ar_reg_avct(p_bta_av_cfg->avrc_mtu, p_bta_av_cfg->avrc_br_mtu, - bta_av_cb.sec_mask, BTA_ID_AV); -#else bta_ar_reg_avct(p_bta_av_cfg->avrc_mtu, p_bta_av_cfg->avrc_br_mtu, (UINT8)(bta_av_cb.sec_mask & (~BTA_SEC_AUTHORIZE)), BTA_ID_AV); -#endif if (p_data->api_reg.tsep == AVDT_TSEP_SRC) { bta_ar_reg_avrc(UUID_SERVCLASS_AV_REM_CTRL_TARGET, "AV Remote Control Target\n", NULL, p_bta_av_cfg->avrc_src_tg_cat, BTA_ID_AV); @@ -703,13 +698,8 @@ static void bta_av_api_register(tBTA_AV_DATA *p_data) /* if TG is not supported, we need to register to AVCT now */ if ((bta_av_cb.features & (BTA_AV_FEAT_RCTG)) == 0) { #if( defined BTA_AR_INCLUDED ) && (BTA_AR_INCLUDED == TRUE) -#if (BTA_AV_WITH_AVCTP_AUTHORIZATION == TRUE) - bta_ar_reg_avct(p_bta_av_cfg->avrc_mtu, p_bta_av_cfg->avrc_br_mtu, - bta_av_cb.sec_mask, BTA_ID_AV); -#else bta_ar_reg_avct(p_bta_av_cfg->avrc_mtu, p_bta_av_cfg->avrc_br_mtu, (UINT8)(bta_av_cb.sec_mask & (~BTA_SEC_AUTHORIZE)), BTA_ID_AV); -#endif #endif } #if( defined BTA_AR_INCLUDED ) && (BTA_AR_INCLUDED == TRUE) diff --git a/components/bt/host/bluedroid/bta/include/bta/bta_av_api.h b/components/bt/host/bluedroid/bta/include/bta/bta_av_api.h index 5efc2662c4..65d7e35cae 100644 --- a/components/bt/host/bluedroid/bta/include/bta/bta_av_api.h +++ b/components/bt/host/bluedroid/bta/include/bta/bta_av_api.h @@ -36,12 +36,6 @@ /***************************************************************************** ** Constants and data types *****************************************************************************/ -/* Set to TRUE if seperate authorization prompt desired for AVCTP besides A2DP authorization */ -/* Typically FALSE when AVRCP is used in conjunction with A2DP */ -#ifndef BTA_AV_WITH_AVCTP_AUTHORIZATION -#define BTA_AV_WITH_AVCTP_AUTHORIZATION FALSE -#endif - /* AV status values */ #define BTA_AV_SUCCESS 0 /* successful operation */ #define BTA_AV_FAIL 1 /* generic failure */ diff --git a/components/bt/host/bluedroid/btc/profile/std/a2dp/btc_a2dp.c b/components/bt/host/bluedroid/btc/profile/std/a2dp/btc_a2dp.c index 43d8f93290..b3561007a2 100644 --- a/components/bt/host/bluedroid/btc/profile/std/a2dp/btc_a2dp.c +++ b/components/bt/host/bluedroid/btc/profile/std/a2dp/btc_a2dp.c @@ -38,7 +38,7 @@ *******************************************************************************/ void btc_a2dp_on_init(void) { - //tput_mon(1, 0, 1); + BTC_TRACE_EVENT("A2DP Initialized."); } /***************************************************************************** diff --git a/components/bt/host/bluedroid/btc/profile/std/a2dp/btc_a2dp_source.c b/components/bt/host/bluedroid/btc/profile/std/a2dp/btc_a2dp_source.c index 7ddade158b..9e943c3cef 100644 --- a/components/bt/host/bluedroid/btc/profile/std/a2dp/btc_a2dp_source.c +++ b/components/bt/host/bluedroid/btc/profile/std/a2dp/btc_a2dp_source.c @@ -1216,8 +1216,6 @@ BOOLEAN btc_media_aa_read_feeding(void) /* Read Data from data channel */ nb_byte_read = btc_aa_src_data_read((uint8_t *)read_buffer, read_size); - //tput_mon(TRUE, nb_byte_read, FALSE); - if (nb_byte_read < read_size) { APPL_TRACE_WARNING("### UNDERRUN :: ONLY READ %d BYTES OUT OF %d ###", nb_byte_read, read_size); diff --git a/components/bt/host/bluedroid/btc/profile/std/a2dp/btc_av.c b/components/bt/host/bluedroid/btc/profile/std/a2dp/btc_av.c index 1126a5f6d5..22258c8836 100644 --- a/components/bt/host/bluedroid/btc/profile/std/a2dp/btc_av.c +++ b/components/bt/host/bluedroid/btc/profile/std/a2dp/btc_av.c @@ -101,7 +101,6 @@ typedef struct { ** Static variables ******************************************************************************/ btc_av_open_t av_open; -bool open_fail = false; #if A2D_DYNAMIC_MEMORY == FALSE static btc_av_cb_t btc_av_cb = {0}; @@ -327,6 +326,9 @@ static BOOLEAN btc_av_state_idle_handler(btc_sm_event_t event, void *p_data) case BTA_AV_REGISTER_EVT: btc_av_cb.bta_handle = ((tBTA_AV *)p_data)->registr.hndl; + // Init av_open struct and av_open_state + memset(&av_open, 0, sizeof(btc_av_open_t)); + open_fail = false; break; case BTA_AV_PENDING_EVT: @@ -334,14 +336,24 @@ static BOOLEAN btc_av_state_idle_handler(btc_sm_event_t event, void *p_data) if (event == BTC_AV_CONNECT_REQ_EVT) { memcpy(&btc_av_cb.peer_bda, &((btc_av_connect_req_t *)p_data)->target_bda, sizeof(bt_bdaddr_t)); - BTA_AvOpen(btc_av_cb.peer_bda.address, btc_av_cb.bta_handle, - TRUE, BTA_SEC_AUTHENTICATE, ((btc_av_connect_req_t *)p_data)->uuid); + if (av_with_rc) { + BTA_AvOpen(btc_av_cb.peer_bda.address, btc_av_cb.bta_handle, + TRUE, BTA_SEC_AUTHENTICATE, ((btc_av_connect_req_t *)p_data)->uuid); + } else { + BTA_AvOpen(btc_av_cb.peer_bda.address, btc_av_cb.bta_handle, + FALSE, BTA_SEC_AUTHENTICATE, ((btc_av_connect_req_t *)p_data)->uuid); + } } else if (event == BTA_AV_PENDING_EVT) { bdcpy(btc_av_cb.peer_bda.address, ((tBTA_AV *)p_data)->pend.bd_addr); UINT16 uuid = (btc_av_cb.service_id == BTA_A2DP_SOURCE_SERVICE_ID) ? UUID_SERVCLASS_AUDIO_SOURCE : UUID_SERVCLASS_AUDIO_SINK; - BTA_AvOpen(btc_av_cb.peer_bda.address, btc_av_cb.bta_handle, - TRUE, BTA_SEC_AUTHENTICATE, uuid); + if (av_with_rc) { + BTA_AvOpen(btc_av_cb.peer_bda.address, btc_av_cb.bta_handle, + TRUE, BTA_SEC_AUTHENTICATE, uuid); + } else { + BTA_AvOpen(btc_av_cb.peer_bda.address, btc_av_cb.bta_handle, + FALSE, BTA_SEC_AUTHENTICATE, uuid); + } } btc_sm_change_state(btc_av_cb.sm_handle, BTC_AV_STATE_OPENING); } break; @@ -353,15 +365,14 @@ static BOOLEAN btc_av_state_idle_handler(btc_sm_event_t event, void *p_data) case BTA_AV_RC_OPEN_EVT: /* IOP_FIX: Jabra 620 only does RC open without AV open whenever it connects. So - * as per the AV WP, an AVRC connection cannot exist without an AV connection. Therefore, - * we initiate an AV connection if an RC_OPEN_EVT is received when we are in AV_CLOSED state. - * We initiate the AV connection after a small 3s timeout to avoid any collisions from the - * headsets, as some headsets initiate the AVRC connection first and then - * immediately initiate the AV connection - * - * TODO: We may need to do this only on an AVRCP Play. FixMe - */ - + * as per the AV WP, an AVRC connection cannot exist without an AV connection. Therefore, + * we initiate an AV connection if an RC_OPEN_EVT is received when we are in AV_CLOSED state. + * We initiate the AV connection after a small 3s timeout to avoid any collisions from the + * headsets, as some headsets initiate the AVRC connection first and then + * immediately initiate the AV connection + * + * TODO: We may need to do this only on an AVRCP Play. FixMe + */ #if BTC_AV_SRC_INCLUDED BTC_TRACE_DEBUG("BTA_AV_RC_OPEN_EVT received w/o AV"); btc_av_cb.tle_av_open_on_rc = osi_alarm_new("AVconn", btc_initiate_av_open_tmr_hdlr, NULL, BTC_TIMEOUT_AV_OPEN_ON_RC_SECS * 1000); @@ -458,8 +469,12 @@ static BOOLEAN btc_av_state_opening_handler(btc_sm_event_t event, void *p_data) */ } else if (btc_av_cb.peer_sep == AVDT_TSEP_SRC && (p_bta_data->open.status == BTA_AV_SUCCESS)) { - /* Bring up AVRCP connection too */ - BTA_AvOpenRc(btc_av_cb.bta_handle); + /* Bring up AVRCP connection too if AVRC Initialized */ + if(av_with_rc) { + BTA_AvOpenRc(btc_av_cb.bta_handle); + } else { + BTC_TRACE_WARNING("AVRC not Init, not using it."); + } } btc_queue_advance(); } break; @@ -1273,11 +1288,16 @@ bt_status_t btc_av_execute_service(BOOLEAN b_enable, UINT8 tsep) /* Added BTA_AV_FEAT_NO_SCO_SSPD - this ensures that the BTA does not * auto-suspend av streaming on AG events(SCO or Call). The suspend shall * be initiated by the app/audioflinger layers */ - BTA_AvEnable(BTA_SEC_AUTHENTICATE, (BTA_AV_FEAT_NO_SCO_SSPD) - | BTA_AV_FEAT_RCTG | BTA_AV_FEAT_METADATA | BTA_AV_FEAT_VENDOR - | BTA_AV_FEAT_RCCT | BTA_AV_FEAT_ADV_CTRL, - bte_av_callback); - BTA_AvRegister(BTA_AV_CHNL_AUDIO, BTC_AV_SERVICE_NAME, 0, bte_av_media_callback, &bta_av_a2d_cos, &bta_avrc_cos, tsep); + if (av_with_rc) { + BTA_AvEnable(BTA_SEC_AUTHENTICATE, BTA_AV_FEAT_NO_SCO_SSPD | + BTA_AV_FEAT_RCTG | BTA_AV_FEAT_METADATA | BTA_AV_FEAT_VENDOR | + BTA_AV_FEAT_RCCT | BTA_AV_FEAT_ADV_CTRL, + bte_av_callback); + BTA_AvRegister(BTA_AV_CHNL_AUDIO, BTC_AV_SERVICE_NAME, 0, bte_av_media_callback, &bta_av_a2d_cos, &bta_avrc_cos, tsep); + } else { + BTA_AvEnable(BTA_SEC_AUTHENTICATE, BTA_AV_FEAT_NO_SCO_SSPD, bte_av_callback); + BTA_AvRegister(BTA_AV_CHNL_AUDIO, BTC_AV_SERVICE_NAME, 0, bte_av_media_callback, &bta_av_a2d_cos, NULL, tsep); + } } else { BTA_AvDeregister(btc_av_cb.bta_handle); BTA_AvDisable(); diff --git a/components/bt/host/bluedroid/btc/profile/std/avrc/btc_avrc.c b/components/bt/host/bluedroid/btc/profile/std/avrc/btc_avrc.c index 20ce222c26..b4a17cf818 100644 --- a/components/bt/host/bluedroid/btc/profile/std/avrc/btc_avrc.c +++ b/components/bt/host/bluedroid/btc/profile/std/avrc/btc_avrc.c @@ -1011,6 +1011,9 @@ static void btc_avrc_ct_init(void) return; } + // indicate that using A2DP with AVRC + av_with_rc = true; + /// initialize CT-specific resources s_rc_ct_init = BTC_RC_CT_INIT_MAGIC; @@ -1039,6 +1042,9 @@ static void btc_avrc_ct_deinit(void) return; } + // indicate that using A2DP with AVRC + av_with_rc = true; + /// deinit CT-specific resources s_rc_ct_init = 0; diff --git a/components/bt/host/bluedroid/btc/profile/std/include/btc_av.h b/components/bt/host/bluedroid/btc/profile/std/include/btc_av.h index cc546923e6..20e0e563aa 100644 --- a/components/bt/host/bluedroid/btc/profile/std/include/btc_av.h +++ b/components/bt/host/bluedroid/btc/profile/std/include/btc_av.h @@ -33,6 +33,8 @@ #include "bta/bta_av_api.h" #if (BTC_AV_INCLUDED == TRUE) +bool open_fail; +bool av_with_rc; /******************************************************************************* ** Type definitions for callback functions ********************************************************************************/