|
40 | 40 | #include "esp_a2dp_api.h" |
41 | 41 | #include "oi_codec_sbc.h" |
42 | 42 | #include "oi_status.h" |
| 43 | +#include "future.h" |
| 44 | +#include <assert.h> |
43 | 45 |
|
44 | 46 | #if (BTC_AV_SINK_INCLUDED == TRUE) |
45 | 47 |
|
@@ -119,6 +121,7 @@ static void btc_a2dp_sink_data_ready(UNUSED_ATTR void *context); |
119 | 121 |
|
120 | 122 | static tBTC_A2DP_SINK_CB btc_aa_snk_cb; |
121 | 123 | static int btc_a2dp_sink_state = BTC_A2DP_SINK_STATE_OFF; |
| 124 | +static future_t *btc_a2dp_sink_future = NULL; |
122 | 125 | static xTaskHandle btc_aa_snk_task_hdl = NULL; |
123 | 126 | static QueueHandle_t btc_aa_snk_data_queue = NULL; |
124 | 127 | static QueueHandle_t btc_aa_snk_ctrl_queue = NULL; |
@@ -285,7 +288,12 @@ void btc_a2dp_sink_shutdown(void) |
285 | 288 | APPL_TRACE_EVENT("## A2DP SINK STOP MEDIA THREAD ##\n"); |
286 | 289 |
|
287 | 290 | // 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); |
288 | 294 | 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; |
289 | 297 |
|
290 | 298 | vTaskDelete(btc_aa_snk_task_hdl); |
291 | 299 | btc_aa_snk_task_hdl = NULL; |
@@ -410,6 +418,9 @@ static void btc_a2dp_sink_data_ready(UNUSED_ATTR void *context) |
410 | 418 | } |
411 | 419 |
|
412 | 420 | 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 | + } |
413 | 424 | btc_a2dp_sink_handle_inc_media(p_msg); |
414 | 425 | p_msg = (tBT_SBC_HDR *)fixed_queue_try_dequeue(btc_aa_snk_cb.RxSbcQ); |
415 | 426 | if ( p_msg == NULL ) { |
@@ -693,6 +704,10 @@ UINT8 btc_a2dp_sink_enque_buf(BT_HDR *p_pkt) |
693 | 704 | { |
694 | 705 | tBT_SBC_HDR *p_msg; |
695 | 706 |
|
| 707 | + if (btc_a2dp_sink_state != BTC_A2DP_SINK_STATE_ON){ |
| 708 | + return 0; |
| 709 | + } |
| 710 | + |
696 | 711 | if (btc_aa_snk_cb.rx_flush == TRUE) { /* Flush enabled, do not enque*/ |
697 | 712 | return fixed_queue_length(btc_aa_snk_cb.RxSbcQ); |
698 | 713 | } |
@@ -754,16 +769,15 @@ static void btc_a2dp_sink_thread_init(UNUSED_ATTR void *context) |
754 | 769 |
|
755 | 770 | static void btc_a2dp_sink_thread_cleanup(UNUSED_ATTR void *context) |
756 | 771 | { |
757 | | - /* make sure no channels are restarted while shutting down */ |
758 | | - btc_a2dp_sink_state = BTC_A2DP_SINK_STATE_SHUTTING_DOWN; |
759 | | - |
760 | 772 | btc_a2dp_control_set_datachnl_stat(FALSE); |
761 | 773 | /* Clear task flag */ |
762 | 774 | btc_a2dp_sink_state = BTC_A2DP_SINK_STATE_OFF; |
763 | 775 |
|
764 | 776 | btc_a2dp_control_cleanup(); |
765 | 777 |
|
766 | 778 | fixed_queue_free(btc_aa_snk_cb.RxSbcQ, osi_free_func); |
| 779 | + |
| 780 | + future_ready(btc_a2dp_sink_future, NULL); |
767 | 781 | } |
768 | 782 |
|
769 | 783 | #endif /* BTC_AV_SINK_INCLUDED */ |
0 commit comments