diff --git a/examples/09_a2dp/components/bluedroid_demos/app_project/SampleBtSdp.c b/examples/09_a2dp/components/bluedroid_demos/app_project/SampleBtSdp.c index 123dc07ca..e4eb4d873 100644 --- a/examples/09_a2dp/components/bluedroid_demos/app_project/SampleBtSdp.c +++ b/examples/09_a2dp/components/bluedroid_demos/app_project/SampleBtSdp.c @@ -85,7 +85,8 @@ static void bt_app_stack_evt(UINT16 event, char *p_param) btav_set_device_class(); BTA_DmSetDeviceName(dev_name); esp_bt_gap_set_scan_mode(BT_SCAN_MODE_CONNECTABLE_DISCOVERABLE); - esp_a2d_sink_init(esp_a2d_cb); + esp_a2d_register_callback(esp_a2d_cb); + esp_a2d_sink_init(); // app_alarm = osi_alarm_new("app_alarm", bt_sdp_add_record_to, NULL, 1000, false); app_alarm = osi_alarm_new("app_alarm", btav_open_to, NULL, 1000, false); diff --git a/examples/09_a2dp/components/bluedroid_demos/btif/btif_avk.c b/examples/09_a2dp/components/bluedroid_demos/btif/btif_avk.c index f4a0a2ea9..d22d90420 100644 --- a/examples/09_a2dp/components/bluedroid_demos/btif/btif_avk.c +++ b/examples/09_a2dp/components/bluedroid_demos/btif/btif_avk.c @@ -95,7 +95,7 @@ typedef struct { /***************************************************************************** ** Static variables ******************************************************************************/ -// static esp_a2d_callbacks_t *bt_av_sink_callbacks = NULL; + static esp_profile_cb_t bt_av_sink_callback = NULL; static btif_av_cb_t btif_av_cb = {0}; @@ -108,8 +108,7 @@ static btif_av_cb_t btif_av_cb = {0}; } while (0) /* both interface and media task needs to be ready to alloc incoming request */ -#define CHECK_BTAV_INIT() if ((bt_av_sink_callback == NULL) \ - || (btif_av_cb.sm_handle == NULL))\ +#define CHECK_BTAV_INIT() if (btif_av_cb.sm_handle == NULL)\ {\ BTIF_TRACE_WARNING("%s: BTAV not initialized\n", __FUNCTION__);\ return ESP_ERR_INVALID_STATE;\ @@ -374,7 +373,7 @@ static BOOLEAN btif_av_state_opening_handler(btif_sm_event_t event, void *p_data } break; case BTIF_AV_SINK_CONFIG_REQ_EVT: { - if (btif_av_cb.peer_sep == AVDT_TSEP_SRC && bt_av_sink_callback != NULL) { + if (btif_av_cb.peer_sep == AVDT_TSEP_SRC) { esp_a2d_cb_param_t param; memcpy(¶m.audio_cfg.remote_bda, &btif_av_cb.peer_bda, sizeof(esp_bd_addr_t)); memcpy(¶m.audio_cfg.mcc, p_data, sizeof(esp_a2d_mcc_t)); @@ -972,6 +971,22 @@ static bt_status_t init_src(btav_callbacks_t *callbacks) } #endif + +/** + * + * Function register A2DP callback + * + * Description Initializes the AV interface for sink mode + * + * Returns bt_status_t + * + */ +esp_err_t esp_a2d_register_callback(esp_profile_cb_t callback) +{ + // TODO: add concurrency protection + bt_av_sink_callback = callback; +} + /******************************************************************************* ** ** Function init_sink @@ -981,14 +996,11 @@ static bt_status_t init_src(btav_callbacks_t *callbacks) ** Returns bt_status_t ** *******************************************************************************/ -esp_err_t esp_a2d_sink_init(esp_profile_cb_t callback) +esp_err_t esp_a2d_sink_init(void) { BTIF_TRACE_EVENT("%s()\n", __func__); bt_status_t status = btif_av_init(); - if (status == BT_STATUS_SUCCESS) { - bt_av_sink_callback = callback; - } return (status == BT_STATUS_SUCCESS) ? ESP_OK : ESP_FAIL; } diff --git a/examples/09_a2dp/components/bluedroid_demos/include/esp_a2dp_api.h b/examples/09_a2dp/components/bluedroid_demos/include/esp_a2dp_api.h index f8cf666e1..b1c331228 100644 --- a/examples/09_a2dp/components/bluedroid_demos/include/esp_a2dp_api.h +++ b/examples/09_a2dp/components/bluedroid_demos/include/esp_a2dp_api.h @@ -95,7 +95,9 @@ typedef union { /** * Represents the A2DP sink interface. */ -esp_err_t esp_a2d_sink_init(esp_profile_cb_t callback); +esp_err_t esp_a2d_register_callback(esp_profile_cb_t callback); + +esp_err_t esp_a2d_sink_init(void); esp_err_t esp_a2d_sink_connect(esp_bd_addr_t *remote_bda);