From 1ae261dcdd97570f553ee36d28925f84aeed1639 Mon Sep 17 00:00:00 2001 From: weitianhua Date: Thu, 3 Dec 2020 20:06:06 +0800 Subject: [PATCH] Add init & deinit event for a2dp --- .../bluedroid/api/include/api/esp_a2dp_api.h | 25 ++++++++++++++++--- .../bluedroid/btc/profile/std/a2dp/btc_av.c | 13 +++++++++- .../classic_bt/a2dp_sink/main/bt_app_av.c | 12 ++++++++- .../coex/a2dp_gatts_coex/main/bt_app_av.c | 12 ++++++++- 4 files changed, 55 insertions(+), 7 deletions(-) diff --git a/components/bt/host/bluedroid/api/include/api/esp_a2dp_api.h b/components/bt/host/bluedroid/api/include/api/esp_a2dp_api.h index 8cb2607f57..3941f082a2 100644 --- a/components/bt/host/bluedroid/api/include/api/esp_a2dp_api.h +++ b/components/bt/host/bluedroid/api/include/api/esp_a2dp_api.h @@ -83,12 +83,19 @@ typedef enum { ESP_A2D_MEDIA_CTRL_SUSPEND, /*!< command to suspend media transmission */ } esp_a2d_media_ctrl_t; +/// Bluetooth A2DP Initiation states +typedef enum { + ESP_A2D_DEINIT_SUCCESS = 0, /*!< A2DP profile deinit successful event */ + ESP_A2D_INIT_SUCCESS /*!< A2DP profile deinit successful event */ +} esp_a2d_init_state_t; + /// A2DP callback events typedef enum { ESP_A2D_CONNECTION_STATE_EVT = 0, /*!< connection state changed event */ ESP_A2D_AUDIO_STATE_EVT, /*!< audio stream transmission state changed event */ ESP_A2D_AUDIO_CFG_EVT, /*!< audio codec is configured, only used for A2DP SINK */ ESP_A2D_MEDIA_CTRL_ACK_EVT, /*!< acknowledge event in response to media control commands */ + ESP_A2D_PROF_STATE_EVT, /*!< indicate a2dp init&deinit complete */ } esp_a2d_cb_event_t; /// A2DP state callback parameters @@ -125,6 +132,12 @@ typedef union { esp_a2d_media_ctrl_t cmd; /*!< media control commands to acknowledge */ esp_a2d_media_ctrl_ack_t status; /*!< acknowledgement to media control commands */ } media_ctrl_stat; /*!< status in acknowledgement to media control commands */ + /** + * @brief ESP_A2D_PROF_STATE_EVT + */ + struct a2d_prof_stat_param { + esp_a2d_init_state_t init_state; /*!< a2dp profile state param */ + } a2d_prof_stat; /*!< status to indicate a2d prof init or deinit */ } esp_a2d_cb_param_t; /** @@ -193,7 +206,8 @@ esp_err_t esp_a2d_sink_register_data_callback(esp_a2d_sink_data_cb_t callback); /** * * @brief Initialize the bluetooth A2DP sink module. This function should be called - * after esp_bluedroid_enable() completes successfully. Note: A2DP can work independently. + * after esp_bluedroid_enable() completes successfully, and ESP_A2D_PROF_STATE_EVT + * with ESP_A2D_INIT_SUCCESS will reported to the APP layer. Note: A2DP can work independently. * If you want to use AVRC together, you should initiate AVRC first. * * @return @@ -208,7 +222,8 @@ esp_err_t esp_a2d_sink_init(void); /** * * @brief De-initialize for A2DP sink module. This function - * should be called only after esp_bluedroid_enable() completes successfully + * should be called only after esp_bluedroid_enable() completes successfully, + * and ESP_A2D_PROF_STATE_EVT with ESP_A2D_DEINIT_SUCCESS will reported to APP layer. * * @return * - ESP_OK: success @@ -265,7 +280,8 @@ esp_err_t esp_a2d_media_ctrl(esp_a2d_media_ctrl_t ctrl); /** * * @brief Initialize the bluetooth A2DP source module. This function should be called - * after esp_bluedroid_enable() completes successfully. Note: A2DP can work independently. + * after esp_bluedroid_enable() completes successfully, and ESP_A2D_PROF_STATE_EVT + * with ESP_A2D_INIT_SUCCESS will reported to the APP layer. Note: A2DP can work independently. * If you want to use AVRC together, you should initiate AVRC first. * * @return @@ -280,7 +296,8 @@ esp_err_t esp_a2d_source_init(void); /** * * @brief De-initialize for A2DP source module. This function - * should be called only after esp_bluedroid_enable() completes successfully + * should be called only after esp_bluedroid_enable() completes successfully, + * and ESP_A2D_PROF_STATE_EVT with ESP_A2D_DEINIT_SUCCESS will reported to APP layer. * * @return * - ESP_OK: success diff --git a/components/bt/host/bluedroid/btc/profile/std/a2dp/btc_av.c b/components/bt/host/bluedroid/btc/profile/std/a2dp/btc_av.c index 0aeacd1916..0c3cc6ac75 100644 --- a/components/bt/host/bluedroid/btc/profile/std/a2dp/btc_av.c +++ b/components/bt/host/bluedroid/btc/profile/std/a2dp/btc_av.c @@ -1014,7 +1014,7 @@ static bt_status_t btc_av_init(int service_id) #endif g_a2dp_on_init = false; g_a2dp_on_deinit = true; - return BT_STATUS_FAIL; + goto av_init_fail; } /* Also initialize the AV state machine */ @@ -1030,9 +1030,15 @@ static bt_status_t btc_av_init(int service_id) btc_a2dp_on_init(); g_a2dp_on_init = true; g_a2dp_on_deinit = false; + + esp_a2d_cb_param_t param; + memset(¶m, 0, sizeof(esp_a2d_cb_param_t)); + param.a2d_prof_stat.init_state = ESP_A2D_INIT_SUCCESS; + btc_a2d_cb_to_app(ESP_A2D_PROF_STATE_EVT, ¶m); return BT_STATUS_SUCCESS; } +av_init_fail: return BT_STATUS_FAIL; } @@ -1099,6 +1105,11 @@ static void clean_up(int service_id) #endif g_a2dp_on_init = false; g_a2dp_on_deinit = true; + + esp_a2d_cb_param_t param; + memset(¶m, 0, sizeof(esp_a2d_cb_param_t)); + param.a2d_prof_stat.init_state = ESP_A2D_DEINIT_SUCCESS; + btc_a2d_cb_to_app(ESP_A2D_PROF_STATE_EVT, ¶m); } /******************************************************************************* diff --git a/examples/bluetooth/bluedroid/classic_bt/a2dp_sink/main/bt_app_av.c b/examples/bluetooth/bluedroid/classic_bt/a2dp_sink/main/bt_app_av.c index 17c2edbb3c..aa398cd471 100644 --- a/examples/bluetooth/bluedroid/classic_bt/a2dp_sink/main/bt_app_av.c +++ b/examples/bluetooth/bluedroid/classic_bt/a2dp_sink/main/bt_app_av.c @@ -57,7 +57,8 @@ void bt_app_a2d_cb(esp_a2d_cb_event_t event, esp_a2d_cb_param_t *param) switch (event) { case ESP_A2D_CONNECTION_STATE_EVT: case ESP_A2D_AUDIO_STATE_EVT: - case ESP_A2D_AUDIO_CFG_EVT: { + case ESP_A2D_AUDIO_CFG_EVT: + case ESP_A2D_PROF_STATE_EVT: { bt_app_work_dispatch(bt_av_hdl_a2d_evt, event, param, sizeof(esp_a2d_cb_param_t), NULL); break; } @@ -174,6 +175,15 @@ static void bt_av_hdl_a2d_evt(uint16_t event, void *p_param) } break; } + case ESP_A2D_PROF_STATE_EVT: { + a2d = (esp_a2d_cb_param_t *)(p_param); + if (ESP_A2D_INIT_SUCCESS == a2d->a2d_prof_stat.init_state) { + ESP_LOGI(BT_AV_TAG,"A2DP PROF STATE: Init Compl\n"); + } else { + ESP_LOGI(BT_AV_TAG,"A2DP PROF STATE: Deinit Compl\n"); + } + break; + } default: ESP_LOGE(BT_AV_TAG, "%s unhandled evt %d", __func__, event); break; diff --git a/examples/bluetooth/bluedroid/coex/a2dp_gatts_coex/main/bt_app_av.c b/examples/bluetooth/bluedroid/coex/a2dp_gatts_coex/main/bt_app_av.c index 17c2edbb3c..aa398cd471 100644 --- a/examples/bluetooth/bluedroid/coex/a2dp_gatts_coex/main/bt_app_av.c +++ b/examples/bluetooth/bluedroid/coex/a2dp_gatts_coex/main/bt_app_av.c @@ -57,7 +57,8 @@ void bt_app_a2d_cb(esp_a2d_cb_event_t event, esp_a2d_cb_param_t *param) switch (event) { case ESP_A2D_CONNECTION_STATE_EVT: case ESP_A2D_AUDIO_STATE_EVT: - case ESP_A2D_AUDIO_CFG_EVT: { + case ESP_A2D_AUDIO_CFG_EVT: + case ESP_A2D_PROF_STATE_EVT: { bt_app_work_dispatch(bt_av_hdl_a2d_evt, event, param, sizeof(esp_a2d_cb_param_t), NULL); break; } @@ -174,6 +175,15 @@ static void bt_av_hdl_a2d_evt(uint16_t event, void *p_param) } break; } + case ESP_A2D_PROF_STATE_EVT: { + a2d = (esp_a2d_cb_param_t *)(p_param); + if (ESP_A2D_INIT_SUCCESS == a2d->a2d_prof_stat.init_state) { + ESP_LOGI(BT_AV_TAG,"A2DP PROF STATE: Init Compl\n"); + } else { + ESP_LOGI(BT_AV_TAG,"A2DP PROF STATE: Deinit Compl\n"); + } + break; + } default: ESP_LOGE(BT_AV_TAG, "%s unhandled evt %d", __func__, event); break;