From 1d03398a645360d0b4f21cb0b13d0dd7919e51b3 Mon Sep 17 00:00:00 2001 From: baohongde Date: Mon, 12 Mar 2018 16:36:11 +0800 Subject: [PATCH] component/bt: Fix bug of a2dp cleanup bug when connected in v3.0 --- .../bluedroid/btc/profile/std/a2dp/btc_avk.c | 4 ++-- .../btc/profile/std/a2dp/btc_media_task.c | 23 +++++++++++++++---- 2 files changed, 21 insertions(+), 6 deletions(-) diff --git a/components/bt/bluedroid/btc/profile/std/a2dp/btc_avk.c b/components/bt/bluedroid/btc/profile/std/a2dp/btc_avk.c index 7c04cbfe09..5208ad30dc 100644 --- a/components/bt/bluedroid/btc/profile/std/a2dp/btc_avk.c +++ b/components/bt/bluedroid/btc/profile/std/a2dp/btc_avk.c @@ -1002,8 +1002,6 @@ static void btc_a2d_sink_deinit(void) { LOG_DEBUG("%s\n", __FUNCTION__); - btc_a2dp_stop_media_task(); - btc_dm_disable_service(BTA_A2DP_SOURCE_SERVICE_ID); #if (BTA_AV_SINK_INCLUDED == TRUE) btc_dm_disable_service(BTA_A2DP_SINK_SERVICE_ID); @@ -1012,6 +1010,8 @@ static void btc_a2d_sink_deinit(void) /* Also shut down the AV state machine */ btc_sm_shutdown(btc_av_cb.sm_handle); btc_av_cb.sm_handle = NULL; + + btc_a2dp_stop_media_task(); } /******************************************************************************* diff --git a/components/bt/bluedroid/btc/profile/std/a2dp/btc_media_task.c b/components/bt/bluedroid/btc/profile/std/a2dp/btc_media_task.c index 89f00d29de..e050159995 100644 --- a/components/bt/bluedroid/btc/profile/std/a2dp/btc_media_task.c +++ b/components/bt/bluedroid/btc/profile/std/a2dp/btc_media_task.c @@ -52,6 +52,8 @@ #include "bt_utils.h" #include "esp_a2dp_api.h" #include "mutex.h" +#include "future.h" +#include // #if (BTA_AV_SINK_INCLUDED == TRUE) #include "oi_codec_sbc.h" @@ -162,6 +164,7 @@ static void btc_media_thread_cleanup(UNUSED_ATTR void *context); static tBTC_MEDIA_CB btc_media_cb; static int media_task_running = MEDIA_TASK_STATE_OFF; +static future_t *media_task_future = NULL; static fixed_queue_t *btc_media_cmd_msg_queue = NULL; static xTaskHandle xBtcMediaTaskHandle = NULL; static QueueHandle_t xBtcMediaDataQueue = NULL; @@ -334,8 +337,13 @@ void btc_a2dp_stop_media_task(void) APPL_TRACE_EVENT("## A2DP STOP MEDIA THREAD ##\n"); // Exit thread + media_task_running = MEDIA_TASK_STATE_SHUTTING_DOWN; + media_task_future = future_new(); + assert(media_task_future); btc_media_ctrl_post(SIG_MEDIA_TASK_CLEAN_UP); - // TODO: wait until CLEAN up is done, then do task delete + future_await(media_task_future); + media_task_future = NULL; + vTaskDelete(xBtcMediaTaskHandle); xBtcMediaTaskHandle = NULL; @@ -535,6 +543,10 @@ static void btc_media_task_avk_data_ready(UNUSED_ATTR void *context) } while ((p_msg = (tBT_SBC_HDR *)fixed_queue_try_peek_first(btc_media_cb.RxSbcQ)) != NULL ) { + if (media_task_running != MEDIA_TASK_STATE_ON){ + return; + } + btc_media_task_handle_inc_media(p_msg); p_msg = (tBT_SBC_HDR *)fixed_queue_try_dequeue(btc_media_cb.RxSbcQ); if ( p_msg == NULL ) { @@ -560,14 +572,13 @@ static void btc_media_thread_init(UNUSED_ATTR void *context) static void btc_media_thread_cleanup(UNUSED_ATTR void *context) { - /* make sure no channels are restarted while shutting down */ - media_task_running = MEDIA_TASK_STATE_SHUTTING_DOWN; - btc_media_cb.data_channel_open = FALSE; /* Clear media task flag */ media_task_running = MEDIA_TASK_STATE_OFF; fixed_queue_free(btc_media_cb.RxSbcQ, osi_free_func); + + future_ready(media_task_future, NULL); } /******************************************************************************* @@ -902,6 +913,10 @@ UINT8 btc_media_sink_enque_buf(BT_HDR *p_pkt) { tBT_SBC_HDR *p_msg; + if (media_task_running != MEDIA_TASK_STATE_ON){ + return 0; + } + if (btc_media_cb.rx_flush == TRUE) { /* Flush enabled, do not enque*/ return fixed_queue_length(btc_media_cb.RxSbcQ); } -- 2.40.0