Merge branch 'bugfix/btdm_a2dp_sink_cleanup_bug' into 'master'

component/bt: Fix bug of a2dp sink cleanup bug when connected

See merge request idf/esp-idf!2041
This commit is contained in:
Jiang Jiang Jian 2018-03-15 15:04:39 +08:00
commit 488268d58b
2 changed files with 23 additions and 7 deletions

View file

@ -40,6 +40,8 @@
#include "esp_a2dp_api.h"
#include "oi_codec_sbc.h"
#include "oi_status.h"
#include "future.h"
#include <assert.h>
#if (BTC_AV_SINK_INCLUDED == TRUE)
@ -119,6 +121,7 @@ static void btc_a2dp_sink_data_ready(UNUSED_ATTR void *context);
static tBTC_A2DP_SINK_CB btc_aa_snk_cb;
static int btc_a2dp_sink_state = BTC_A2DP_SINK_STATE_OFF;
static future_t *btc_a2dp_sink_future = NULL;
static xTaskHandle btc_aa_snk_task_hdl = NULL;
static QueueHandle_t btc_aa_snk_data_queue = NULL;
static QueueHandle_t btc_aa_snk_ctrl_queue = NULL;
@ -285,7 +288,12 @@ void btc_a2dp_sink_shutdown(void)
APPL_TRACE_EVENT("## A2DP SINK STOP MEDIA THREAD ##\n");
// Exit thread
btc_a2dp_sink_state = BTC_A2DP_SINK_STATE_SHUTTING_DOWN;
btc_a2dp_sink_future = future_new();
assert(btc_a2dp_sink_future);
btc_a2dp_sink_ctrl_post(BTC_MEDIA_TASK_SINK_CLEAN_UP, NULL);
future_await(btc_a2dp_sink_future);
btc_a2dp_sink_future = NULL;
vTaskDelete(btc_aa_snk_task_hdl);
btc_aa_snk_task_hdl = NULL;
@ -410,6 +418,9 @@ static void btc_a2dp_sink_data_ready(UNUSED_ATTR void *context)
}
while ((p_msg = (tBT_SBC_HDR *)fixed_queue_try_peek_first(btc_aa_snk_cb.RxSbcQ)) != NULL ) {
if (btc_a2dp_sink_state != BTC_A2DP_SINK_STATE_ON){
return;
}
btc_a2dp_sink_handle_inc_media(p_msg);
p_msg = (tBT_SBC_HDR *)fixed_queue_try_dequeue(btc_aa_snk_cb.RxSbcQ);
if ( p_msg == NULL ) {
@ -693,6 +704,10 @@ UINT8 btc_a2dp_sink_enque_buf(BT_HDR *p_pkt)
{
tBT_SBC_HDR *p_msg;
if (btc_a2dp_sink_state != BTC_A2DP_SINK_STATE_ON){
return 0;
}
if (btc_aa_snk_cb.rx_flush == TRUE) { /* Flush enabled, do not enque*/
return fixed_queue_length(btc_aa_snk_cb.RxSbcQ);
}
@ -754,9 +769,6 @@ static void btc_a2dp_sink_thread_init(UNUSED_ATTR void *context)
static void btc_a2dp_sink_thread_cleanup(UNUSED_ATTR void *context)
{
/* make sure no channels are restarted while shutting down */
btc_a2dp_sink_state = BTC_A2DP_SINK_STATE_SHUTTING_DOWN;
btc_a2dp_control_set_datachnl_stat(FALSE);
/* Clear task flag */
btc_a2dp_sink_state = BTC_A2DP_SINK_STATE_OFF;
@ -764,6 +776,8 @@ static void btc_a2dp_sink_thread_cleanup(UNUSED_ATTR void *context)
btc_a2dp_control_cleanup();
fixed_queue_free(btc_aa_snk_cb.RxSbcQ, osi_free_func);
future_ready(btc_a2dp_sink_future, NULL);
}
#endif /* BTC_AV_SINK_INCLUDED */

View file

@ -1022,10 +1022,6 @@ static void clean_up(int service_id)
#if BTC_AV_SRC_INCLUDED
btc_a2dp_source_shutdown();
#endif /* BTC_AV_SRC_INCLUDED */
} else if (service_id == BTA_A2DP_SINK_SERVICE_ID) {
#if BTC_AV_SINK_INCLUDED
btc_a2dp_sink_shutdown();
#endif /* BTC_AV_SINK_INCLUDED */
}
btc_dm_disable_service(BTA_A2DP_SOURCE_SERVICE_ID);
@ -1037,6 +1033,12 @@ static void clean_up(int service_id)
/* Also shut down the AV state machine */
btc_sm_shutdown(btc_av_cb.sm_handle);
btc_av_cb.sm_handle = NULL;
if (service_id == BTA_A2DP_SINK_SERVICE_ID) {
#if BTC_AV_SINK_INCLUDED
btc_a2dp_sink_shutdown();
#endif /* BTC_AV_SINK_INCLUDED */
}
}
/*******************************************************************************