uint16_t uuid;
} btif_av_connect_req_t;
-typedef struct {
- int sample_rate;
- int channel_count;
-} btif_av_sink_config_req_t;
-
/*****************************************************************************
** Static variables
******************************************************************************/
-static esp_a2dp_callbacks_t *bt_av_sink_callbacks = NULL;
+static esp_a2d_callbacks_t *bt_av_sink_callbacks = NULL;
static btif_av_cb_t btif_av_cb = {0};
// static TIMER_LIST_ENT tle_av_open_on_rc;
/*****************************************************************************
** Static functions
******************************************************************************/
-static void btif_report_connection_state(esp_a2dp_connection_state_t state, bt_bdaddr_t *bd_addr)
+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;
}
}
-static void btif_report_audio_state(esp_a2dp_audio_state_t state, bt_bdaddr_t *bd_addr)
+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;
switch (event) {
case BTIF_SM_ENTER_EVT:
/* inform the application that we are entering connecting state */
- btif_report_connection_state(ESP_A2DP_CONNECTION_STATE_CONNECTING, &(btif_av_cb.peer_bda));
+ btif_report_connection_state(ESP_A2D_CONNECTION_STATE_CONNECTING, &(btif_av_cb.peer_bda));
break;
case BTIF_SM_EXIT_EVT:
case BTA_AV_REJECT_EVT:
BTIF_TRACE_DEBUG(" Received BTA_AV_REJECT_EVT \n");
- btif_report_connection_state(ESP_A2DP_CONNECTION_STATE_DISCONNECTED, &(btif_av_cb.peer_bda));
+ btif_report_connection_state(ESP_A2D_CONNECTION_STATE_DISCONNECTED, &(btif_av_cb.peer_bda));
btif_sm_change_state(btif_av_cb.sm_handle, BTIF_AV_STATE_IDLE);
break;
case BTA_AV_OPEN_EVT: {
tBTA_AV *p_bta_data = (tBTA_AV *)p_data;
- esp_a2dp_connection_state_t state;
+ esp_a2d_connection_state_t state;
btif_sm_state_t av_state;
BTIF_TRACE_DEBUG("status:%d, edr 0x%x\n", p_bta_data->open.status,
p_bta_data->open.edr);
if (p_bta_data->open.status == BTA_AV_SUCCESS) {
- state = ESP_A2DP_CONNECTION_STATE_CONNECTED;
+ state = ESP_A2D_CONNECTION_STATE_CONNECTED;
av_state = BTIF_AV_STATE_OPENED;
btif_av_cb.edr = p_bta_data->open.edr;
} else {
BTIF_TRACE_WARNING("BTA_AV_OPEN_EVT::FAILED status: %d\n",
p_bta_data->open.status );
- state = ESP_A2DP_CONNECTION_STATE_DISCONNECTED;
+ state = ESP_A2D_CONNECTION_STATE_DISCONNECTED;
av_state = BTIF_AV_STATE_IDLE;
}
} break;
case BTIF_AV_SINK_CONFIG_REQ_EVT: {
- btif_av_sink_config_req_t req;
+ esp_a2d_mcc_t mcc;
// copy to avoid alignment problems
- memcpy(&req, p_data, sizeof(req));
-
- BTIF_TRACE_WARNING("BTIF_AV_SINK_CONFIG_REQ_EVT %d %d\n", req.sample_rate,
- req.channel_count);
+ 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,
- req.sample_rate, req.channel_count);
+ HAL_CBACK(bt_av_sink_callbacks, audio_config_cb, &remote_bda, &mcc);
}
} break;
break;
} else {
BTIF_TRACE_DEBUG("%s: Moved from idle by Incoming Connection request\n", __func__);
- btif_report_connection_state(ESP_A2DP_CONNECTION_STATE_DISCONNECTED, (bt_bdaddr_t *)p_data);
+ btif_report_connection_state(ESP_A2D_CONNECTION_STATE_DISCONNECTED, (bt_bdaddr_t *)p_data);
btif_queue_advance();
break;
}
case BTA_AV_CLOSE_EVT:
/* inform the application that we are disconnecting */
- btif_report_connection_state(ESP_A2DP_CONNECTION_STATE_DISCONNECTED, &(btif_av_cb.peer_bda));
+ btif_report_connection_state(ESP_A2D_CONNECTION_STATE_DISCONNECTED, &(btif_av_cb.peer_bda));
btif_sm_change_state(btif_av_cb.sm_handle, BTIF_AV_STATE_IDLE);
break;
BTA_AvClose(btif_av_cb.bta_handle);
/* inform the application that we are disconnecting */
- btif_report_connection_state(ESP_A2DP_CONNECTION_STATE_DISCONNECTING, &(btif_av_cb.peer_bda));
+ btif_report_connection_state(ESP_A2D_CONNECTION_STATE_DISCONNECTING, &(btif_av_cb.peer_bda));
break;
case BTA_AV_CLOSE_EVT:
btif_a2dp_on_stopped(NULL);
/* inform the application that we are disconnected */
- btif_report_connection_state(ESP_A2DP_CONNECTION_STATE_DISCONNECTED, &(btif_av_cb.peer_bda));
+ btif_report_connection_state(ESP_A2D_CONNECTION_STATE_DISCONNECTED, &(btif_av_cb.peer_bda));
/* change state to idle, send acknowledgement if start is pending */
if (btif_av_cb.flags & BTIF_AV_FLAG_PENDING_START) {
BTIF_TRACE_DEBUG("%s: Ignore BTIF_AV_CONNECT_REQ_EVT for same device\n", __func__);
} else {
BTIF_TRACE_DEBUG("%s: Moved to opened by Other Incoming Conn req\n", __func__);
- btif_report_connection_state(ESP_A2DP_CONNECTION_STATE_DISCONNECTED,
+ btif_report_connection_state(ESP_A2D_CONNECTION_STATE_DISCONNECTED,
(bt_bdaddr_t *)p_data);
}
btif_queue_advance();
/* we are again in started state, clear any remote suspend flags */
btif_av_cb.flags &= ~BTIF_AV_FLAG_REMOTE_SUSPEND;
- btif_report_audio_state(ESP_A2DP_AUDIO_STATE_STARTED, &(btif_av_cb.peer_bda));
+ btif_report_audio_state(ESP_A2D_AUDIO_STATE_STARTED, &(btif_av_cb.peer_bda));
/* increase the a2dp consumer task priority temporarily when start
** audio playing, to avoid overflow the audio packet queue. */
BTA_AvClose(btif_av_cb.bta_handle);
/* inform the application that we are disconnecting */
- btif_report_connection_state(ESP_A2DP_CONNECTION_STATE_DISCONNECTING, &(btif_av_cb.peer_bda));
+ btif_report_connection_state(ESP_A2D_CONNECTION_STATE_DISCONNECTING, &(btif_av_cb.peer_bda));
/* wait in closing state until fully closed */
btif_sm_change_state(btif_av_cb.sm_handle, BTIF_AV_STATE_CLOSING);
btif_av_cb.flags |= BTIF_AV_FLAG_REMOTE_SUSPEND;
}
- btif_report_audio_state(ESP_A2DP_AUDIO_STATE_REMOTE_SUSPEND, &(btif_av_cb.peer_bda));
+ btif_report_audio_state(ESP_A2D_AUDIO_STATE_REMOTE_SUSPEND, &(btif_av_cb.peer_bda));
} else {
- btif_report_audio_state(ESP_A2DP_AUDIO_STATE_STOPPED, &(btif_av_cb.peer_bda));
+ btif_report_audio_state(ESP_A2D_AUDIO_STATE_STOPPED, &(btif_av_cb.peer_bda));
}
btif_sm_change_state(btif_av_cb.sm_handle, BTIF_AV_STATE_OPENED);
btif_av_cb.flags |= BTIF_AV_FLAG_PENDING_STOP;
btif_a2dp_on_stopped(&p_av->suspend);
- btif_report_audio_state(ESP_A2DP_AUDIO_STATE_STOPPED, &(btif_av_cb.peer_bda));
+ btif_report_audio_state(ESP_A2D_AUDIO_STATE_STOPPED, &(btif_av_cb.peer_bda));
/* if stop was successful, change state to open */
if (p_av->suspend.status == BTA_AV_SUCCESS) {
btif_a2dp_on_stopped(NULL);
/* inform the application that we are disconnected */
- btif_report_connection_state(ESP_A2DP_CONNECTION_STATE_DISCONNECTED, &(btif_av_cb.peer_bda));
+ btif_report_connection_state(ESP_A2D_CONNECTION_STATE_DISCONNECTED, &(btif_av_cb.peer_bda));
btif_sm_change_state(btif_av_cb.sm_handle, BTIF_AV_STATE_IDLE);
break;
UINT8 que_len;
tA2D_STATUS a2d_status;
tA2D_SBC_CIE sbc_cie;
- btif_av_sink_config_req_t config_req;
+ esp_a2d_mcc_t mcc;
if (event == BTA_AV_MEDIA_DATA_EVT) { /* Switch to BTIF_MEDIA context */
state = btif_sm_get_state(btif_av_cb.sm_handle);
/* send a command to BT Media Task */
btif_reset_decoder((UINT8 *)p_data);
+ /* currently only supportes SBC */
a2d_status = A2D_ParsSbcInfo(&sbc_cie, (UINT8 *)p_data, FALSE);
if (a2d_status == A2D_SUCCESS) {
+ mcc.type = ESP_A2D_MCT_SBC;
+ memcpy(&mcc.cie, (uint8_t *)p_data + 3, ESP_A2D_CIE_LEN_SBC);
/* Switch to BTIF context */
- config_req.sample_rate = btif_a2dp_get_track_frequency(sbc_cie.samp_freq);
- config_req.channel_count = btif_a2dp_get_track_channel_count(sbc_cie.ch_mode);
btif_transfer_context(btif_av_handle_event, BTIF_AV_SINK_CONFIG_REQ_EVT,
- (char *)&config_req, sizeof(config_req), NULL);
+ (char *)&mcc, sizeof(mcc), NULL);
} else {
APPL_TRACE_ERROR("ERROR dump_codec_info A2D_ParsSbcInfo fail:%d\n", a2d_status);
}
** Returns bt_status_t
**
*******************************************************************************/
-esp_err_t esp_a2dp_sink_init(esp_a2dp_callbacks_t *callbacks)
+esp_err_t esp_a2d_sink_init(esp_a2d_callbacks_t *callbacks)
// static bt_status_t init_sink(btav_callbacks_t *callbacks)
{
BTIF_TRACE_EVENT("%s()\n", __func__);
}
#endif
-esp_err_t esp_a2dp_sink_connect(esp_bd_addr_t *remote_bda)
+esp_err_t esp_a2d_sink_connect(esp_bd_addr_t *remote_bda)
// static bt_status_t sink_connect_src(bt_bdaddr_t *bd_addr)
{
BTIF_TRACE_EVENT("%s\n", __FUNCTION__);
(char *)bd_addr, sizeof(bt_bdaddr_t), NULL);
}
-esp_err_t esp_a2dp_sink_disconnect(esp_bd_addr_t *remote_bda)
+esp_err_t esp_a2d_sink_disconnect(esp_bd_addr_t *remote_bda)
{
bt_status_t stat;
bt_bdaddr_t bd_addr;
}
#endif
-void esp_a2dp_sink_deinit(void)
+void esp_a2d_sink_deinit(void)
{
BTIF_TRACE_EVENT("%s\n", __FUNCTION__);
#include "esp_err.h"
#include "esp_bt_defs.h"
-/* Codec types */
-#define ESP_A2DP_CODEC_SBC (0)
-#define ESP_A2DP_CODEC_M12 (0x01)
-#define ESP_A2DP_CODEC_M24 (0x02)
-#define ESP_A2DP_CODEC_ATRAC (0x04)
-#define ESP_A2DP_CODEC_NON_A2DP (0xff)
-typedef uint8_t esp_a2dp_codec_type_t;
+/* Media codec types */
+#define ESP_A2D_MCT_SBC (0)
+#define ESP_A2D_MCT_M12 (0x01)
+#define ESP_A2D_MCT_M24 (0x02)
+#define ESP_A2D_MCT_ATRAC (0x04)
+#define ESP_A2D_MCT_NON_A2DP (0xff)
+typedef uint8_t esp_a2d_mct_t;
/* codec specific information element */
+#define ESP_A2D_CIE_LEN_SBC (4)
+#define ESP_A2D_CIE_LEN_M12 (4)
+#define ESP_A2D_CIE_LEN_M24 (6)
+#define ESP_A2D_CIE_LEN_ATRAC (7)
+
typedef struct {
- uint8_t oct[4];
-} esp_sbc_cie_t;
+ uint8_t oct[ESP_A2D_CIE_LEN_SBC];
+} esp_a2d_cie_sbc_t;
typedef struct {
- uint8_t oct[4];
-} esp_mpeg12_audio_cie_t;
+ uint8_t oct[ESP_A2D_CIE_LEN_M12];
+} esp_a2d_cie_m12_t;
typedef struct {
- uint8_t oct[6];
-} esp_mpeg24_aac_cie_t;
+ uint8_t oct[ESP_A2D_CIE_LEN_M24];
+} esp_a2d_cie_m24_t;
typedef struct {
- uint8_t oct[7];
-} esp_atrac_cie_t;
+ uint8_t oct[ESP_A2D_CIE_LEN_ATRAC];
+} esp_a2d_cie_atrac_t;
+/* media codec capabilities */
typedef struct {
- esp_a2dp_codec_type_t type; /* A2DP codec type*/
+ esp_a2d_mct_t type; /* A2DP media codec type*/
union {
- esp_sbc_cie_t sbc;
- esp_mpeg12_audio_cie_t mpeg12;
- esp_mpeg24_aac_cie_t mpeg24;
- esp_atrac_cie_t atrac;
+ esp_a2d_cie_sbc_t sbc;
+ esp_a2d_cie_m12_t m12;
+ esp_a2d_cie_m24_t m24;
+ esp_a2d_cie_atrac_t atrac;
} cie;
-} esp_a2dp_codec_cfg_t;
+} esp_a2d_mcc_t;
/* Bluetooth A2DP connection states */
typedef enum {
- ESP_A2DP_CONNECTION_STATE_DISCONNECTED = 0,
- ESP_A2DP_CONNECTION_STATE_CONNECTING,
- ESP_A2DP_CONNECTION_STATE_CONNECTED,
- ESP_A2DP_CONNECTION_STATE_DISCONNECTING
-} esp_a2dp_connection_state_t;
+ ESP_A2D_CONNECTION_STATE_DISCONNECTED = 0,
+ ESP_A2D_CONNECTION_STATE_CONNECTING,
+ ESP_A2D_CONNECTION_STATE_CONNECTED,
+ ESP_A2D_CONNECTION_STATE_DISCONNECTING
+} esp_a2d_connection_state_t;
/* Bluetooth A2DP datapath states */
typedef enum {
- ESP_A2DP_AUDIO_STATE_REMOTE_SUSPEND = 0,
- ESP_A2DP_AUDIO_STATE_STOPPED,
- ESP_A2DP_AUDIO_STATE_STARTED,
-} esp_a2dp_audio_state_t;
+ ESP_A2D_AUDIO_STATE_REMOTE_SUSPEND = 0,
+ ESP_A2D_AUDIO_STATE_STOPPED,
+ 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_a2dp_connection_state_cb_t)(esp_a2dp_connection_state_t state,
+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_a2dp_audio_state_cb_t)(esp_a2dp_audio_state_t state,
+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
- * sample_rate: sample rate in Hz
- * channel_count: number of channels (1 for mono, 2 for stereo)
*/
-/*
-typedef void (* esp_a2dp_audio_config_cb_t)(esp_bd_addr_t *remote_bda,
- esp_a2dp_codec_cfg_t *cfg);
-*/
-typedef void (* esp_a2dp_audio_config_cb_t)(esp_bd_addr_t *remote_bda,
- uint32_t sample_rate, uint8_t channel_count); // TODO: to be modified
+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_a2dp_connection_state_cb_t connection_state_cb;
- esp_a2dp_audio_state_cb_t audio_state_cb;
- esp_a2dp_audio_config_cb_t audio_config_cb;
-} esp_a2dp_callbacks_t;
-
+ 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;
/**
* NOTE:
void (* close)(void);
int (* ioctl)(int cmd, void *param); // not used for now
uint32_t (* write)(uint8_t *buf, uint32_t len);
-} esp_a2dp_sink_audio_hal_t;
+} esp_a2d_sink_audio_hal_t;
-#define ESP_A2DP_AUDIO_HAL_IOC_WRITE_FLUSH (1) // ioctl command, which is not used for now
+#define ESP_A2D_AUDIO_HAL_IOC_WRITE_FLUSH (1) // ioctl command, which is not used for now
/** Represents the A2DP sink interface.
*/
-esp_err_t esp_a2dp_sink_init(esp_a2dp_callbacks_t *callbacks);
+esp_err_t esp_a2d_sink_init(esp_a2d_callbacks_t *callbacks);
-esp_err_t esp_a2dp_sink_connect(esp_bd_addr_t *remote_bda);
+esp_err_t esp_a2d_sink_connect(esp_bd_addr_t *remote_bda);
-esp_err_t esp_a2dp_sink_disconnect(esp_bd_addr_t *remote_bda);
+esp_err_t esp_a2d_sink_disconnect(esp_bd_addr_t *remote_bda);
-void esp_a2dp_sink_deinit(void);
+void esp_a2d_sink_deinit(void);
#endif /* __ESP_A2DP_API_H__ */