From 2233b5d25ef007e3b579149be6ac672a0092a941 Mon Sep 17 00:00:00 2001 From: xiongweichao Date: Tue, 25 Aug 2020 20:15:32 +0800 Subject: [PATCH 1/2] 1.fix test case dummy 2.fix sink send media control ESP_A2D_MEDIA_CHECK_SRC_RDY --- .../btc/profile/std/a2dp/btc_a2dp_control.c | 57 ++++++++++++------- 1 file changed, 38 insertions(+), 19 deletions(-) diff --git a/components/bt/bluedroid/btc/profile/std/a2dp/btc_a2dp_control.c b/components/bt/bluedroid/btc/profile/std/a2dp/btc_a2dp_control.c index d5e1b1ca80..df5775f72c 100644 --- a/components/bt/bluedroid/btc/profile/std/a2dp/btc_a2dp_control.c +++ b/components/bt/bluedroid/btc/profile/std/a2dp/btc_a2dp_control.c @@ -29,6 +29,7 @@ #include "btc_a2dp_sink.h" #include "btc_a2dp_source.h" #include "esp_a2dp_api.h" +#include "btc_avrc.h" #if BTC_AV_INCLUDED @@ -59,11 +60,13 @@ static inline void a2dp_cmd_acknowledge(int cmd, int status) void btc_a2dp_control_command_ack(int status) { - /* sanity check */ + /* sanity check if (btc_aa_ctrl_cb.a2dp_cmd_pending == ESP_A2D_MEDIA_CTRL_NONE) { APPL_TRACE_ERROR("warning : no command pending, ignore ack"); return; - } + } + */ + /* clear pending */ int cmd = btc_aa_ctrl_cb.a2dp_cmd_pending; @@ -126,19 +129,25 @@ void btc_a2dp_control_media_ctrl(esp_a2d_media_ctrl_t ctrl) switch (ctrl) { case ESP_A2D_MEDIA_CTRL_CHECK_SRC_RDY: -#if BTC_AV_SRC_INCLUDED - if (btc_a2dp_source_is_task_shutting_down()) { - btc_a2dp_control_command_ack(ESP_A2D_MEDIA_CTRL_ACK_FAILURE); - } else if ((btc_av_stream_ready() == TRUE) || - (btc_av_stream_started_ready() == TRUE)) { - /* check whether av is ready to setup a2dp datapath */ - btc_a2dp_control_command_ack(ESP_A2D_MEDIA_CTRL_ACK_SUCCESS); +//#if BTC_AV_SRC_INCLUDED + if (btc_av_get_service_id() == BTA_A2DP_SOURCE_SERVICE_ID) { + if (btc_a2dp_source_is_task_shutting_down()) { + btc_a2dp_control_command_ack(ESP_A2D_MEDIA_CTRL_ACK_FAILURE); + } else if ((btc_av_stream_ready() == TRUE) || + (btc_av_stream_started_ready() == TRUE)) { + /* check whether av is ready to setup a2dp datapath */ + btc_a2dp_control_command_ack(ESP_A2D_MEDIA_CTRL_ACK_SUCCESS); + } else { + btc_a2dp_control_command_ack(ESP_A2D_MEDIA_CTRL_ACK_FAILURE); + } } else { btc_a2dp_control_command_ack(ESP_A2D_MEDIA_CTRL_ACK_FAILURE); } -#else /* BTC_AV_SRC_INCLUDED */ - btc_a2dp_control_command_ack(ESP_A2D_MEDIA_CTRL_ACK_FAILURE); -#endif /* #if BTC_AV_SRC_INCLUDED */ +//#else /* BTC_AV_SRC_INCLUDED */ + //if (btc_av_get_service_id() == BTA_A2DP_SINK_SERVICE_ID) { + //btc_a2dp_control_command_ack(ESP_A2D_MEDIA_CTRL_ACK_FAILURE); + //} / +//#endif /* #if BTC_AV_SRC_INCLUDED */ break; case ESP_A2D_MEDIA_CTRL_START: if (btc_av_stream_ready() == TRUE ) { @@ -161,34 +170,44 @@ void btc_a2dp_control_media_ctrl(esp_a2d_media_ctrl_t ctrl) case ESP_A2D_MEDIA_CTRL_STOP: #if BTC_AV_SRC_INCLUDED if (btc_av_get_peer_sep() == AVDT_TSEP_SNK && !btc_a2dp_source_is_streaming() && - btc_av_get_service_id() == BTA_A2DP_SOURCE_SERVICE_ID) { + btc_av_get_service_id() == BTA_A2DP_SOURCE_SERVICE_ID && btc_av_is_peer_edr() == TRUE) { /* we are already stopped, just ack back*/ - btc_a2dp_control_command_ack(ESP_A2D_MEDIA_CTRL_ACK_SUCCESS); + btc_a2dp_control_command_ack(ESP_A2D_MEDIA_CTRL_ACK_SUCCESS); break; + /* check if connect a2dp */ + } else if (btc_av_is_peer_edr() == FALSE){ + btc_a2dp_control_command_ack(ESP_A2D_MEDIA_CTRL_ACK_FAILURE); } #endif /* BTC_AV_SRC_INCLUDED */ btc_dispatch_sm_event(BTC_AV_STOP_STREAM_REQ_EVT, NULL, 0); #if (BTC_AV_SINK_INCLUDED == TRUE) - if (btc_av_get_peer_sep() == AVDT_TSEP_SRC && btc_av_get_service_id() == BTA_A2DP_SINK_SERVICE_ID) { + if (btc_av_get_peer_sep() == AVDT_TSEP_SRC && btc_av_get_service_id() == BTA_A2DP_SINK_SERVICE_ID && + btc_av_is_peer_edr() == TRUE) { btc_a2dp_control_command_ack(ESP_A2D_MEDIA_CTRL_ACK_SUCCESS); + } else if (btc_av_is_peer_edr() == FALSE){ + btc_a2dp_control_command_ack(ESP_A2D_MEDIA_CTRL_ACK_FAILURE); } #endif break; - case ESP_A2D_MEDIA_CTRL_SUSPEND: /* local suspend */ if (btc_av_stream_started_ready()) { btc_dispatch_sm_event(BTC_AV_SUSPEND_STREAM_REQ_EVT, NULL, 0); #if (BTC_AV_SINK_INCLUDED == TRUE) - if (btc_av_get_peer_sep() == AVDT_TSEP_SRC && btc_av_get_service_id() == BTA_A2DP_SINK_SERVICE_ID) { + if (btc_av_get_peer_sep() == AVDT_TSEP_SRC && btc_av_get_service_id() == BTA_A2DP_SINK_SERVICE_ID && + btc_av_is_peer_edr() == TRUE) { btc_a2dp_control_command_ack(ESP_A2D_MEDIA_CTRL_ACK_SUCCESS); + } else if (btc_av_is_peer_edr() == FALSE) { + btc_a2dp_control_command_ack(ESP_A2D_MEDIA_CTRL_ACK_FAILURE); } -#endif - } else { +#endif + } else if (btc_av_is_peer_edr() == TRUE){ /* we are not in started state; just ack back ok. This can happen if we are remotely suspended; clear REMOTE SUSPEND Flag */ btc_av_clear_remote_suspend_flag(); btc_a2dp_control_command_ack(ESP_A2D_MEDIA_CTRL_ACK_SUCCESS); + } else { + btc_a2dp_control_command_ack(ESP_A2D_MEDIA_CTRL_ACK_FAILURE); } break; From 3c0aee85957ff129c002e2a6b24725cf01bd1ab6 Mon Sep 17 00:00:00 2001 From: xiongweichao Date: Wed, 26 Aug 2020 16:56:46 +0800 Subject: [PATCH 2/2] 1.revert dummy command 2.fix send MEDIA_CTRL command in disconnect --- .../bluedroid/api/include/api/esp_a2dp_api.h | 2 +- .../btc/profile/std/a2dp/btc_a2dp_control.c | 45 +++++++------------ 2 files changed, 18 insertions(+), 29 deletions(-) diff --git a/components/bt/bluedroid/api/include/api/esp_a2dp_api.h b/components/bt/bluedroid/api/include/api/esp_a2dp_api.h index 3b002a405f..96aad492b5 100644 --- a/components/bt/bluedroid/api/include/api/esp_a2dp_api.h +++ b/components/bt/bluedroid/api/include/api/esp_a2dp_api.h @@ -76,7 +76,7 @@ typedef enum { /// A2DP media control commands typedef enum { - ESP_A2D_MEDIA_CTRL_NONE = 0, /*!< dummy command */ + ESP_A2D_MEDIA_CTRL_NONE = 0, /*!< Not for application use, use inside stack only. */ ESP_A2D_MEDIA_CTRL_CHECK_SRC_RDY, /*!< check whether AVDTP is connected, only used in A2DP source */ ESP_A2D_MEDIA_CTRL_START, /*!< command to set up media transmission channel */ ESP_A2D_MEDIA_CTRL_STOP, /*!< command to stop media transmission */ diff --git a/components/bt/bluedroid/btc/profile/std/a2dp/btc_a2dp_control.c b/components/bt/bluedroid/btc/profile/std/a2dp/btc_a2dp_control.c index df5775f72c..732ab503f8 100644 --- a/components/bt/bluedroid/btc/profile/std/a2dp/btc_a2dp_control.c +++ b/components/bt/bluedroid/btc/profile/std/a2dp/btc_a2dp_control.c @@ -29,7 +29,6 @@ #include "btc_a2dp_sink.h" #include "btc_a2dp_source.h" #include "esp_a2dp_api.h" -#include "btc_avrc.h" #if BTC_AV_INCLUDED @@ -60,13 +59,11 @@ static inline void a2dp_cmd_acknowledge(int cmd, int status) void btc_a2dp_control_command_ack(int status) { - /* sanity check + /* sanity check */ if (btc_aa_ctrl_cb.a2dp_cmd_pending == ESP_A2D_MEDIA_CTRL_NONE) { APPL_TRACE_ERROR("warning : no command pending, ignore ack"); return; - } - */ - + } /* clear pending */ int cmd = btc_aa_ctrl_cb.a2dp_cmd_pending; @@ -129,7 +126,7 @@ void btc_a2dp_control_media_ctrl(esp_a2d_media_ctrl_t ctrl) switch (ctrl) { case ESP_A2D_MEDIA_CTRL_CHECK_SRC_RDY: -//#if BTC_AV_SRC_INCLUDED +#if BTC_AV_SRC_INCLUDED if (btc_av_get_service_id() == BTA_A2DP_SOURCE_SERVICE_ID) { if (btc_a2dp_source_is_task_shutting_down()) { btc_a2dp_control_command_ack(ESP_A2D_MEDIA_CTRL_ACK_FAILURE); @@ -139,15 +136,13 @@ void btc_a2dp_control_media_ctrl(esp_a2d_media_ctrl_t ctrl) btc_a2dp_control_command_ack(ESP_A2D_MEDIA_CTRL_ACK_SUCCESS); } else { btc_a2dp_control_command_ack(ESP_A2D_MEDIA_CTRL_ACK_FAILURE); - } + } } else { btc_a2dp_control_command_ack(ESP_A2D_MEDIA_CTRL_ACK_FAILURE); } -//#else /* BTC_AV_SRC_INCLUDED */ - //if (btc_av_get_service_id() == BTA_A2DP_SINK_SERVICE_ID) { - //btc_a2dp_control_command_ack(ESP_A2D_MEDIA_CTRL_ACK_FAILURE); - //} / -//#endif /* #if BTC_AV_SRC_INCLUDED */ +#else /* BTC_AV_SRC_INCLUDED */ + btc_a2dp_control_command_ack(ESP_A2D_MEDIA_CTRL_ACK_FAILURE); +#endif /* #if BTC_AV_SRC_INCLUDED */ break; case ESP_A2D_MEDIA_CTRL_START: if (btc_av_stream_ready() == TRUE ) { @@ -168,24 +163,22 @@ void btc_a2dp_control_media_ctrl(esp_a2d_media_ctrl_t ctrl) } break; case ESP_A2D_MEDIA_CTRL_STOP: + if (btc_av_is_connected() == FALSE) { + btc_a2dp_control_command_ack(ESP_A2D_MEDIA_CTRL_ACK_FAILURE); + break; + } #if BTC_AV_SRC_INCLUDED if (btc_av_get_peer_sep() == AVDT_TSEP_SNK && !btc_a2dp_source_is_streaming() && - btc_av_get_service_id() == BTA_A2DP_SOURCE_SERVICE_ID && btc_av_is_peer_edr() == TRUE) { + btc_av_get_service_id() == BTA_A2DP_SOURCE_SERVICE_ID) { /* we are already stopped, just ack back*/ - btc_a2dp_control_command_ack(ESP_A2D_MEDIA_CTRL_ACK_SUCCESS); + btc_a2dp_control_command_ack(ESP_A2D_MEDIA_CTRL_ACK_SUCCESS); break; - /* check if connect a2dp */ - } else if (btc_av_is_peer_edr() == FALSE){ - btc_a2dp_control_command_ack(ESP_A2D_MEDIA_CTRL_ACK_FAILURE); } #endif /* BTC_AV_SRC_INCLUDED */ btc_dispatch_sm_event(BTC_AV_STOP_STREAM_REQ_EVT, NULL, 0); #if (BTC_AV_SINK_INCLUDED == TRUE) - if (btc_av_get_peer_sep() == AVDT_TSEP_SRC && btc_av_get_service_id() == BTA_A2DP_SINK_SERVICE_ID && - btc_av_is_peer_edr() == TRUE) { + if (btc_av_get_peer_sep() == AVDT_TSEP_SRC && btc_av_get_service_id() == BTA_A2DP_SINK_SERVICE_ID) { btc_a2dp_control_command_ack(ESP_A2D_MEDIA_CTRL_ACK_SUCCESS); - } else if (btc_av_is_peer_edr() == FALSE){ - btc_a2dp_control_command_ack(ESP_A2D_MEDIA_CTRL_ACK_FAILURE); } #endif break; @@ -194,14 +187,11 @@ void btc_a2dp_control_media_ctrl(esp_a2d_media_ctrl_t ctrl) if (btc_av_stream_started_ready()) { btc_dispatch_sm_event(BTC_AV_SUSPEND_STREAM_REQ_EVT, NULL, 0); #if (BTC_AV_SINK_INCLUDED == TRUE) - if (btc_av_get_peer_sep() == AVDT_TSEP_SRC && btc_av_get_service_id() == BTA_A2DP_SINK_SERVICE_ID && - btc_av_is_peer_edr() == TRUE) { + if (btc_av_get_peer_sep() == AVDT_TSEP_SRC && btc_av_get_service_id() == BTA_A2DP_SINK_SERVICE_ID) { btc_a2dp_control_command_ack(ESP_A2D_MEDIA_CTRL_ACK_SUCCESS); - } else if (btc_av_is_peer_edr() == FALSE) { - btc_a2dp_control_command_ack(ESP_A2D_MEDIA_CTRL_ACK_FAILURE); } -#endif - } else if (btc_av_is_peer_edr() == TRUE){ +#endif + } else if (btc_av_is_connected() == TRUE) { /* we are not in started state; just ack back ok. This can happen if we are remotely suspended; clear REMOTE SUSPEND Flag */ btc_av_clear_remote_suspend_flag(); @@ -210,7 +200,6 @@ void btc_a2dp_control_media_ctrl(esp_a2d_media_ctrl_t ctrl) btc_a2dp_control_command_ack(ESP_A2D_MEDIA_CTRL_ACK_FAILURE); } break; - default : APPL_TRACE_ERROR("### A2DP-MEDIA EVENT %u NOT HANDLED ###", ctrl); btc_a2dp_control_command_ack(ESP_A2D_MEDIA_CTRL_ACK_FAILURE);