Skip to content

Commit c0eadc5

Browse files
blueMoodBHDespressif-bot
authored andcommitted
component/bt: Fix bug of a2dp sink cleanup bug when connected
1 parent a58a2b6 commit c0eadc5

File tree

2 files changed

+23
-7
lines changed

2 files changed

+23
-7
lines changed

components/bt/bluedroid/btc/profile/std/a2dp/btc_a2dp_sink.c

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,8 @@
4040
#include "esp_a2dp_api.h"
4141
#include "oi_codec_sbc.h"
4242
#include "oi_status.h"
43+
#include "future.h"
44+
#include <assert.h>
4345

4446
#if (BTC_AV_SINK_INCLUDED == TRUE)
4547

@@ -119,6 +121,7 @@ static void btc_a2dp_sink_data_ready(UNUSED_ATTR void *context);
119121

120122
static tBTC_A2DP_SINK_CB btc_aa_snk_cb;
121123
static int btc_a2dp_sink_state = BTC_A2DP_SINK_STATE_OFF;
124+
static future_t *btc_a2dp_sink_future = NULL;
122125
static xTaskHandle btc_aa_snk_task_hdl = NULL;
123126
static QueueHandle_t btc_aa_snk_data_queue = NULL;
124127
static QueueHandle_t btc_aa_snk_ctrl_queue = NULL;
@@ -285,7 +288,12 @@ void btc_a2dp_sink_shutdown(void)
285288
APPL_TRACE_EVENT("## A2DP SINK STOP MEDIA THREAD ##\n");
286289

287290
// Exit thread
291+
btc_a2dp_sink_state = BTC_A2DP_SINK_STATE_SHUTTING_DOWN;
292+
btc_a2dp_sink_future = future_new();
293+
assert(btc_a2dp_sink_future);
288294
btc_a2dp_sink_ctrl_post(BTC_MEDIA_TASK_SINK_CLEAN_UP, NULL);
295+
future_await(btc_a2dp_sink_future);
296+
btc_a2dp_sink_future = NULL;
289297

290298
vTaskDelete(btc_aa_snk_task_hdl);
291299
btc_aa_snk_task_hdl = NULL;
@@ -410,6 +418,9 @@ static void btc_a2dp_sink_data_ready(UNUSED_ATTR void *context)
410418
}
411419

412420
while ((p_msg = (tBT_SBC_HDR *)fixed_queue_try_peek_first(btc_aa_snk_cb.RxSbcQ)) != NULL ) {
421+
if (btc_a2dp_sink_state != BTC_A2DP_SINK_STATE_ON){
422+
return;
423+
}
413424
btc_a2dp_sink_handle_inc_media(p_msg);
414425
p_msg = (tBT_SBC_HDR *)fixed_queue_try_dequeue(btc_aa_snk_cb.RxSbcQ);
415426
if ( p_msg == NULL ) {
@@ -693,6 +704,10 @@ UINT8 btc_a2dp_sink_enque_buf(BT_HDR *p_pkt)
693704
{
694705
tBT_SBC_HDR *p_msg;
695706

707+
if (btc_a2dp_sink_state != BTC_A2DP_SINK_STATE_ON){
708+
return 0;
709+
}
710+
696711
if (btc_aa_snk_cb.rx_flush == TRUE) { /* Flush enabled, do not enque*/
697712
return fixed_queue_length(btc_aa_snk_cb.RxSbcQ);
698713
}
@@ -754,16 +769,15 @@ static void btc_a2dp_sink_thread_init(UNUSED_ATTR void *context)
754769

755770
static void btc_a2dp_sink_thread_cleanup(UNUSED_ATTR void *context)
756771
{
757-
/* make sure no channels are restarted while shutting down */
758-
btc_a2dp_sink_state = BTC_A2DP_SINK_STATE_SHUTTING_DOWN;
759-
760772
btc_a2dp_control_set_datachnl_stat(FALSE);
761773
/* Clear task flag */
762774
btc_a2dp_sink_state = BTC_A2DP_SINK_STATE_OFF;
763775

764776
btc_a2dp_control_cleanup();
765777

766778
fixed_queue_free(btc_aa_snk_cb.RxSbcQ, osi_free_func);
779+
780+
future_ready(btc_a2dp_sink_future, NULL);
767781
}
768782

769783
#endif /* BTC_AV_SINK_INCLUDED */

components/bt/bluedroid/btc/profile/std/a2dp/btc_av.c

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1022,10 +1022,6 @@ static void clean_up(int service_id)
10221022
#if BTC_AV_SRC_INCLUDED
10231023
btc_a2dp_source_shutdown();
10241024
#endif /* BTC_AV_SRC_INCLUDED */
1025-
} else if (service_id == BTA_A2DP_SINK_SERVICE_ID) {
1026-
#if BTC_AV_SINK_INCLUDED
1027-
btc_a2dp_sink_shutdown();
1028-
#endif /* BTC_AV_SINK_INCLUDED */
10291025
}
10301026

10311027
btc_dm_disable_service(BTA_A2DP_SOURCE_SERVICE_ID);
@@ -1037,6 +1033,12 @@ static void clean_up(int service_id)
10371033
/* Also shut down the AV state machine */
10381034
btc_sm_shutdown(btc_av_cb.sm_handle);
10391035
btc_av_cb.sm_handle = NULL;
1036+
1037+
if (service_id == BTA_A2DP_SINK_SERVICE_ID) {
1038+
#if BTC_AV_SINK_INCLUDED
1039+
btc_a2dp_sink_shutdown();
1040+
#endif /* BTC_AV_SINK_INCLUDED */
1041+
}
10401042
}
10411043

10421044
/*******************************************************************************

0 commit comments

Comments
 (0)