使用play_bt_source_example例子,耳机主动发起重连时会失败 (AUD-6485)
现象和步骤:
-
使用play_bt_source_example例子,esp32开机主动扫描并且连接上耳机。 -
把耳机放到耳机盒子,连接会断开 -
把耳机从耳机盒子拿出来,这时耳机会主动发起连接。 -
这时,耳机会很快连接上esp32,但很快有会断开。
LOG如下:
*****************耳机放到盒子,断开连接
I (42710) BT_AVCT: AVCT_MsgReq I (42720) BT_AVCT: len: 5 I (42720) BT_AVCT: AVCT_MsgReq I (42720) BT_AVCT: len: 5 I (45230) BT_BTM: BTM_SetPowerMode: pm_id 128 BDA: a391c3f6 mode:0x0 I (45230) BT_L2CAP: L2CAP - Calling Disconnect_Ind_Cb(), CID: 0x0043 Conf Needed I (45230) BT_L2CAP: L2CA_DisconnectRsp() CID: 0x0043 I (45230) BT_AVCT: AVCT_RemoveConn I (45240) A2DP_STREAM: AVRC conn_state evt: state 0, [00:00:00:00:00:00] I (45300) BT_BTM: BTM_SetPowerMode: pm_id 128 BDA: a391c3f6 mode:0x0 I (45300) BT_L2CAP: L2CAP - Calling Disconnect_Ind_Cb(), CID: 0x0040 Conf Needed I (45300) BT_L2CAP: L2CA_DisconnectRsp() CID: 0x0040 I (45310) BT_BTM: BTM_SetLinkPolicy hold not supported (settings: 0x000d)
I (45310) BT_BTM: BTM_SetLinkPolicy park not supported (settings: 0x0005)
I (45320) BT_L2CAP: L2CA_SetDesireRole() new:x80, disallow_switch:0 I (45320) BT_L2CAP: L2CA_SetDesireRole() new:x0, disallow_switch:0 I (45330) BT_L2CAP: L2CA_SetDesireRole() new:x0, disallow_switch:0 W (45340) BT_APPL: bta_dm_act no entry for connected service cbs I (45340) BT_BTM: BTM_SetPowerMode: pm_id 128 BDA: a391c3f6 mode:0x0 I (45350) BT_L2CAP: L2CAP - Calling Disconnect_Ind_Cb(), CID: 0x0042 Conf Needed I (45360) BT_L2CAP: L2CA_DisconnectRsp() CID: 0x0042 I (45360) A2DP_STREAM: a2dp source disconnected W (45370) BLUETOOTH_SOURCE_EXAMPLE: [ * ] Bluetooth disconnected or suspended E (45370) BT_LOG: esp_a2d_media_ctrl 4
W (45370) BT_LOG: ESP_A2D_MEDIA_CTRL_STOP is deprecated, using ESP_A2D_MEDIA_CTRL_SUSPEND instead.
W (49360) BT_HCI: hci cmd send: disconnect: hdl 0x80, rsn:0x13 W (49510) BT_HCI: hcif disc complete: hdl 0x80, rsn 0x16 dev_find 1 I (49510) BT_L2CAP: L2CA_SetDesireRole() new:x0, disallow_switch:0
*****************耳机从盒子拿出来,耳机主动去连接32
I (63240) BT_BTM: btm_sec_set_peer_sec_caps: sm4: 0x11, rmt_support_for_secure_connections 0
I (63240) BT_BTM: btm_acl_created: pend:0
W (63240) BT_HCI: hcif conn complete: hdl 0x81, st 0x0 I (63250) BT_L2CAP: L2CA_SetDesireRole() new:x0, disallow_switch:0 I (63250) BT_BTM: BTM_InqDbRead: bd addr [b0f1a391c3f6]
I (63360) BT_BTM: BTM_SetPowerMode: pm_id 128 BDA: a391c3f6 mode:0x0 I (63360) BT_L2CAP: L2CAP - Calling Connect_Ind_Cb(), CID: 0x0040 I (63360) BT_L2CAP: L2CA_ErtmConnectRsp() CID: 0x0040 Result: 0 Status: 0 BDA: b0f1a391c3f6 p_ertm_info:0x0 I (63370) BT_L2CAP: L2CA_ConfigReq() CID 0x0040: fcr_present:0 (mode 0) mtu_present:1 (672) I (63390) BT_L2CAP: L2CA_ConfigRsp() CID: 0x0040 Result: 0 MTU present:0 Flush TO:0 FCR:0 FCS:0 I (63390) BT_L2CAP: L2CAP - Calling Config_Rsp_Cb(), CID: 0x0040 I (63530) BT_BTM: BTM_SetPowerMode: pm_id 128 BDA: a391c3f6 mode:0x0 I (63530) BT_L2CAP: L2CAP - Calling Disconnect_Ind_Cb(), CID: 0x0040 Conf Needed I (63530) BT_L2CAP: L2CA_DisconnectRsp() CID: 0x0040 W (64520) BT_HCI: hcif disc complete: hdl 0x81, rsn 0x16 dev_find 1 I (64520) BT_L2CAP: L2CA_SetDesireRole() new:x0, disallow_switch:0
连上后,会马上出现断开。
当蓝牙断开连接时将会执行periph_bluetooth_stop并break终止程序。如果你对example做了修改,可以提供修改后的代码
我们对该example做了如下的修改并尝试复现你的现象,但是重连后连接稳定,并未出现断连情况
/* Stop when the Bluetooth is disconnected or suspended */
if (msg.source_type == PERIPH_ID_BLUETOOTH
&& msg.source == (void *)bt_periph) {
if ((msg.cmd == PERIPH_BLUETOOTH_DISCONNECTED) || (msg.cmd == PERIPH_BLUETOOTH_AUDIO_SUSPENDED)) {
ESP_LOGW(TAG, "[ * ] Bluetooth disconnected or suspended");
esp_bt_gap_set_scan_mode(ESP_BT_CONNECTABLE, ESP_BT_GENERAL_DISCOVERABLE);
// periph_bluetooth_stop(bt_periph);
// break;
}
}
可以检查你的代码改动或更换其他耳机尝试
如果想要sink重新连接source后继续播放音乐,可在ADF中增加如下逻辑
--- a/components/bluetooth_service/bluetooth_service.c
+++ b/components/bluetooth_service/bluetooth_service.c
@@ -532,6 +532,15 @@ static void bt_a2d_source_cb(esp_a2d_cb_event_t event, esp_a2d_cb_param_t *param
case BT_SOURCE_STATE_DISCOVERED:
break;
case BT_SOURCE_STATE_UNCONNECTED:
+ // add to support a2d reconnection
+ if (param->conn_stat.state == ESP_A2D_CONNECTION_STATE_CONNECTED) {
+ ESP_LOGI(TAG, "a2dp connected");
+ ESP_LOGE(TAG,"param->conn_stat.state %x",param->conn_stat.state);
+ g_bt_service->source_a2d_state = BT_SOURCE_STATE_CONNECTED;
+ esp_a2d_media_ctrl(ESP_A2D_MEDIA_CTRL_CHECK_SRC_RDY);
+ } else {
+ ESP_LOGE(TAG,"param->conn_stat.state %x",param->conn_stat.state);
+ }