]> granicus.if.org Git - esp-idf/commitdiff
component/bt: A2DP API modification
authorwangmengyang <wangmengyang@espressif.com>
Thu, 1 Dec 2016 13:30:05 +0000 (21:30 +0800)
committerwangmengyang <wangmengyang@espressif.com>
Thu, 1 Dec 2016 13:30:05 +0000 (21:30 +0800)
1. add one API to register the A2DP callback functions

examples/09_a2dp/components/bluedroid_demos/app_project/SampleBtSdp.c
examples/09_a2dp/components/bluedroid_demos/btif/btif_avk.c
examples/09_a2dp/components/bluedroid_demos/include/esp_a2dp_api.h

index 123dc07cace871acd36836d5a817c2af903e8259..e4eb4d87362693e1409ef3a87d97f776c6abd756 100644 (file)
@@ -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);
index f4a0a2ea9dd5bbe6ef32972cd5a5e5d6affb12e1..d22d9042078597ba6650b41e9f6c2fbb28fab902 100644 (file)
@@ -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(&param.audio_cfg.remote_bda, &btif_av_cb.peer_bda, sizeof(esp_bd_addr_t));
             memcpy(&param.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;
 }
index f8cf666e182406eaa9c476ecde2c04994ce1e6d6..b1c3312287ee0e9e56e5559e33fa5b8a3ef130ca 100644 (file)
@@ -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);