osi_alarm_t *app_alarm = NULL;
-static void btav_conn_state_cb(esp_a2d_connection_state_t state,
- esp_bd_addr_t *bd_addr)
+static void esp_a2d_cb(uint32_t event, void *param)
{
- LOG_ERROR("===esp_a2dp_conn_state_cb %d ===\n", state);
- (void) bd_addr;
-}
-
-static void btav_audio_state_cb(esp_a2d_audio_state_t state, esp_bd_addr_t *bd_addr)
-{
- LOG_ERROR("===esp_a2dp_audio_state_cb %d ===\n", state);
- (void) bd_addr;
-}
-
-static void btav_audio_cfg_cb(esp_bd_addr_t *bd_addr, uint32_t sample_rate, uint8_t channel_count)
-{
- LOG_ERROR("===esp_a2dp_audio_cfg_cb %d %d===\n", sample_rate, channel_count);
- (void) bd_addr;
+ esp_a2d_cb_param_t *p = (esp_a2d_cb_param_t *)param;
+ switch (event) {
+ case ESP_A2D_CONNECTION_STATE_EVT:
+ LOG_ERROR("===a2dp conn_state_cb %d ===\n", p->conn_stat.state);
+ break;
+ case ESP_A2D_AUDIO_STATE_EVT:
+ LOG_ERROR("===a2dp audio_state_cb %d ===\n", p->audio_stat.state);
+ break;
+ case ESP_A2D_AUDIO_CFG_EVT:
+ LOG_ERROR("===a2dp audio_cfg_cb type %d ===\n", p->audio_cfg.mcc.type);
+ break;
+ default:
+ LOG_ERROR("===a2dp invalid cb event: %d\n", event);
+ }
}
-static esp_a2d_callbacks_t btav_cbs = {
- btav_conn_state_cb,
- btav_audio_state_cb,
- btav_audio_cfg_cb
-};
-
static void btav_open_to(void *context)
{
(void)(context);
btav_set_device_class();
BTA_DmSetDeviceName(dev_name);
esp_bt_gap_set_scan_mode(BT_SCAN_MODE_CONNECTABLE_DISCOVERABLE);
- esp_a2d_sink_init(&btav_cbs);
- // btif_av_get_sink_interface()->init(&btav_cbs);
+ esp_a2d_sink_init(esp_a2d_cb);
// 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);
#include "bt_defs.h"
// #include <system/audio.h>
// #include "bt_av.h"
+#include "esp_bt_defs.h"
#include "esp_a2dp_api.h"
#include "allocator.h"
/*****************************************************************************
** Static variables
******************************************************************************/
-static esp_a2d_callbacks_t *bt_av_sink_callbacks = NULL;
+// 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};
// static TIMER_LIST_ENT tle_av_open_on_rc;
+#define BTIF_A2D_CB_TO_APP(_event, _param) do { \
+ if (bt_av_sink_callback) { \
+ bt_av_sink_callback(_event, _param); \
+ } \
+ } while (0)
+
/* both interface and media task needs to be ready to alloc incoming request */
-#define CHECK_BTAV_INIT() if ((bt_av_sink_callbacks == NULL) \
+#define CHECK_BTAV_INIT() if ((bt_av_sink_callback == NULL) \
|| (btif_av_cb.sm_handle == NULL))\
{\
BTIF_TRACE_WARNING("%s: BTAV not initialized\n", __FUNCTION__);\
******************************************************************************/
static void btif_report_connection_state(esp_a2d_connection_state_t state, bt_bdaddr_t *bd_addr)
{
- if (bt_av_sink_callbacks != NULL) {
- esp_bd_addr_t remote_bda;
- if (bd_addr) {
- memcpy(&remote_bda, bd_addr, sizeof(esp_bd_addr_t));
- } else {
- memset(&remote_bda, 0, sizeof(esp_bd_addr_t));
- }
- HAL_CBACK(bt_av_sink_callbacks, connection_state_cb, state, &remote_bda);
+ esp_a2d_cb_param_t param;
+ memset(¶m, 0, sizeof(esp_a2d_cb_param_t));
+
+ param.conn_stat.state = state;
+ if (bd_addr) {
+ memcpy(¶m.conn_stat.remote_bda, bd_addr, sizeof(esp_bd_addr_t));
}
+ BTIF_A2D_CB_TO_APP(ESP_A2D_CONNECTION_STATE_EVT, ¶m);
}
static void btif_report_audio_state(esp_a2d_audio_state_t state, bt_bdaddr_t *bd_addr)
{
- if (bt_av_sink_callbacks != NULL) {
- esp_bd_addr_t remote_bda;
- if (bd_addr) {
- memcpy(&remote_bda, bd_addr, sizeof(esp_bd_addr_t));
- } else {
- memset(&remote_bda, 0, sizeof(esp_bd_addr_t));
- }
- HAL_CBACK(bt_av_sink_callbacks, audio_state_cb, state, &remote_bda);
+ esp_a2d_cb_param_t param;
+ memset(¶m, 0, sizeof(esp_a2d_cb_param_t));
+
+ param.audio_stat.state = state;
+ if (bd_addr) {
+ memcpy(¶m.audio_stat.remote_bda, bd_addr, sizeof(esp_bd_addr_t));
}
+ BTIF_A2D_CB_TO_APP(ESP_A2D_AUDIO_STATE_EVT, ¶m);
}
/*****************************************************************************
} break;
case BTIF_AV_SINK_CONFIG_REQ_EVT: {
- esp_a2d_mcc_t mcc;
- // copy to avoid alignment problems
- memcpy(&mcc, p_data, sizeof(mcc));
- BTIF_TRACE_DEBUG("BTIF_AV_SINK_CONFIG_REQ_EVT SBC 0x%x %x %x %x\n", mcc.cie.sbc.oct[0], mcc.cie.sbc.oct[1], mcc.cie.sbc.oct[2], mcc.cie.sbc.oct[3]);
- if (btif_av_cb.peer_sep == AVDT_TSEP_SRC && bt_av_sink_callbacks != NULL) {
- esp_bd_addr_t remote_bda;
- memcpy(&remote_bda, &btif_av_cb.peer_bda, sizeof(esp_bd_addr_t));
- HAL_CBACK(bt_av_sink_callbacks, audio_config_cb, &remote_bda, &mcc);
+ if (btif_av_cb.peer_sep == AVDT_TSEP_SRC && bt_av_sink_callback != NULL) {
+ 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));
+ BTIF_A2D_CB_TO_APP(ESP_A2D_AUDIO_CFG_EVT, ¶m);
}
} break;
** Returns bt_status_t
**
*******************************************************************************/
-esp_err_t esp_a2d_sink_init(esp_a2d_callbacks_t *callbacks)
-// static bt_status_t init_sink(btav_callbacks_t *callbacks)
+esp_err_t esp_a2d_sink_init(esp_profile_cb_t callback)
{
BTIF_TRACE_EVENT("%s()\n", __func__);
bt_status_t status = btif_av_init();
if (status == BT_STATUS_SUCCESS) {
- bt_av_sink_callbacks = callbacks;
+ bt_av_sink_callback = callback;
}
return (status == BT_STATUS_SUCCESS) ? ESP_OK : ESP_FAIL;
{
BTIF_TRACE_EVENT("%s\n", __FUNCTION__);
- if (bt_av_sink_callbacks) {
- bt_av_sink_callbacks = NULL;
+ if (bt_av_sink_callback) {
+ bt_av_sink_callback = NULL;
cleanup();
}
}
ESP_A2D_AUDIO_STATE_STARTED,
} esp_a2d_audio_state_t;
-/** Callback for connection state change.
- * state will have one of the values from btav_connection_state_t
- */
-typedef void (* esp_a2d_connection_state_cb_t)(esp_a2d_connection_state_t state,
- esp_bd_addr_t *remote_bda);
-
-/** Callback for audiopath state change.
- * state will have one of the values from btav_audio_state_t
- */
-typedef void (* esp_a2d_audio_state_cb_t)(esp_a2d_audio_state_t state,
- esp_bd_addr_t *remote_bda);
-
-/** Callback for audio configuration change.
- * Used only for the A2DP sink interface.
- * state will have one of the values from btav_audio_state_t
- */
-typedef void (* esp_a2d_audio_config_cb_t)(esp_bd_addr_t *remote_bda,
- esp_a2d_mcc_t *mcc);
-
-/** BT-a2dp callback structure. */
-typedef struct {
- esp_a2d_connection_state_cb_t connection_state_cb;
- esp_a2d_audio_state_cb_t audio_state_cb;
- esp_a2d_audio_config_cb_t audio_config_cb;
-} esp_a2d_callbacks_t;
+typedef enum {
+ ESP_A2D_CONNECTION_STATE_EVT = 0, /*!< connection state changed */
+ ESP_A2D_AUDIO_STATE_EVT = 1, /*!< audio stream state changed */
+ ESP_A2D_AUDIO_CFG_EVT = 2 /*!< audio codec configuration received */
+} esp_a2d_cb_event_t;
+
+typedef union {
+ /*< ESP_A2D_CONNECTION_STATE_EVT */
+ struct a2d_conn_stat_param {
+ esp_a2d_connection_state_t state; /*!< one of values from esp_a2d_connection_state_t */
+ esp_bd_addr_t remote_bda;
+ } conn_stat;
+
+ /*< ESP_A2D_AUDIO_STATE_EVT */
+ struct a2d_audio_stat_param {
+ esp_a2d_audio_state_t state; /*!< one of the values from esp_a2d_audio_state_t */
+ esp_bd_addr_t remote_bda;
+ } audio_stat;
+
+ /*< ESP_A2D_AUDIO_CFG_EVT */
+ struct a2d_audio_cfg_param {
+ esp_bd_addr_t remote_bda;
+ esp_a2d_mcc_t mcc;
+ } audio_cfg;
+} esp_a2d_cb_param_t;
/**
* NOTE:
* and the Bluetooth stack.
*/
-typedef struct {
- int (* open)(void);
- void (* close)(void);
- int (* ioctl)(int cmd, void *param); // not used for now
- uint32_t (* write)(uint8_t *buf, uint32_t len);
-} esp_a2d_sink_audio_hal_t;
-
-#define ESP_A2D_AUDIO_HAL_IOC_WRITE_FLUSH (1) // ioctl command, which is not used for now
-
-
-/** Represents the A2DP sink interface.
+/**
+ * Represents the A2DP sink interface.
*/
-esp_err_t esp_a2d_sink_init(esp_a2d_callbacks_t *callbacks);
+esp_err_t esp_a2d_sink_init(esp_profile_cb_t callback);
esp_err_t esp_a2d_sink_connect(esp_bd_addr_t *remote_bda);