Bluetooth A2DP API¶
Overview¶
Application Example¶
Check bluetooth folder in ESP-IDF examples, which contains the following application:
- This is a A2DP sink client demo. This demo can be discovered and connected by A2DP source device and receive the audio stream from remote device - bluetooth/a2dp_sink
API Reference¶
Header File¶
Functions¶
-
esp_err_t
esp_a2d_register_callback(esp_a2d_cb_t callback)¶ Register application callback function to A2DP module. This function should be called only after esp_bluedroid_enable() completes successfully.
- Return
- ESP_OK: success
- ESP_INVALID_STATE: if bluetooth stack is not yet enabled
- ESP_FAIL: if callback is a NULL function pointer
- Parameters
callback: A2DP sink event callback function
-
esp_err_t
esp_a2d_register_data_callback(esp_a2d_data_cb_t callback)¶ Register A2DP sink data output function; For now the output is PCM data stream decoded from SBC format. This function should be called only after esp_bluedroid_enable() completes successfully, used only by A2DP sink. The callback is invoked in the context of A2DP sink task whose stack size is configurable through menuconfig.
- Return
- ESP_OK: success
- ESP_INVALID_STATE: if bluetooth stack is not yet enabled
- ESP_FAIL: if callback is a NULL function pointer
- Parameters
callback: A2DP data callback function
-
esp_err_t
esp_a2d_sink_init(void)¶ Initialize the bluetooth A2DP sink module. This function should be called after esp_bluedroid_enable() completes successfully.
- Return
- ESP_OK: if the initialization request is sent successfully
- ESP_INVALID_STATE: if bluetooth stack is not yet enabled
- ESP_FAIL: others
-
esp_err_t
esp_a2d_sink_deinit(void)¶ De-initialize for A2DP sink module. This function should be called only after esp_bluedroid_enable() completes successfully.
- Return
- ESP_OK: success
- ESP_INVALID_STATE: if bluetooth stack is not yet enabled
- ESP_FAIL: others
-
esp_err_t
esp_a2d_sink_connect(esp_bd_addr_t remote_bda)¶ Connect the remote bluetooth device bluetooth, must after esp_a2d_sink_init()
- Return
- ESP_OK: connect request is sent to lower layer
- ESP_INVALID_STATE: if bluetooth stack is not yet enabled
- ESP_FAIL: others
- Parameters
remote_bda: remote bluetooth device address
-
esp_err_t
esp_a2d_sink_disconnect(esp_bd_addr_t remote_bda)¶ Disconnect the remote bluetooth device.
- Return
- ESP_OK: disconnect request is sent to lower layer
- ESP_INVALID_STATE: if bluetooth stack is not yet enabled
- ESP_FAIL: others
- Parameters
remote_bda: remote bluetooth device address
Unions¶
-
union
esp_a2d_cb_param_t¶ - #include <esp_a2dp_api.h>
A2DP state callback parameters.
Public Members
-
struct esp_a2d_cb_param_t::a2d_conn_stat_param
conn_stat¶ A2DP connection status
-
struct esp_a2d_cb_param_t::a2d_audio_stat_param
audio_stat¶ audio stream playing state
-
struct esp_a2d_cb_param_t::a2d_audio_cfg_param
audio_cfg¶ media codec configuration infomation
-
struct
a2d_audio_cfg_param¶ - #include <esp_a2dp_api.h>
ESP_A2D_AUDIO_CFG_EVT.
Public Members
-
esp_bd_addr_t
remote_bda¶ remote bluetooth device address
-
esp_a2d_mcc_t
mcc¶ A2DP media codec capability information
-
esp_bd_addr_t
-
struct
a2d_audio_stat_param¶ - #include <esp_a2dp_api.h>
ESP_A2D_AUDIO_STATE_EVT.
Public Members
-
esp_a2d_audio_state_t
state¶ one of the values from esp_a2d_audio_state_t
-
esp_bd_addr_t
remote_bda¶ remote bluetooth device address
-
esp_a2d_audio_state_t
-
struct
a2d_conn_stat_param¶ - #include <esp_a2dp_api.h>
ESP_A2D_CONNECTION_STATE_EVT.
Public Members
-
esp_a2d_connection_state_t
state¶ one of values from esp_a2d_connection_state_t
-
esp_bd_addr_t
remote_bda¶ remote bluetooth device address
-
esp_a2d_disc_rsn_t
disc_rsn¶ reason of disconnection for “DISCONNECTED”
-
esp_a2d_connection_state_t
-
struct esp_a2d_cb_param_t::a2d_conn_stat_param
Structures¶
-
struct
esp_a2d_mcc_t¶ A2DP media codec capabilities union.
Public Members
-
esp_a2d_mct_t
type¶ A2DP media codec type
-
union esp_a2d_mcc_t::[anonymous]
cie¶ A2DP codec information element
-
esp_a2d_mct_t
Macros¶
-
ESP_A2D_MCT_SBC¶ Media codec types supported by A2DP.
SBC
-
ESP_A2D_MCT_M12¶ MPEG-1, 2 Audio
-
ESP_A2D_MCT_M24¶ MPEG-2, 4 AAC
-
ESP_A2D_MCT_ATRAC¶ ATRAC family
-
ESP_A2D_MCT_NON_A2DP¶
-
ESP_A2D_CIE_LEN_SBC¶
-
ESP_A2D_CIE_LEN_M12¶
-
ESP_A2D_CIE_LEN_M24¶
-
ESP_A2D_CIE_LEN_ATRAC¶
Type Definitions¶
-
typedef uint8_t
esp_a2d_mct_t¶
-
typedef void (*
esp_a2d_cb_t)(esp_a2d_cb_event_t event, esp_a2d_cb_param_t *param)¶ A2DP profile callback function type.
- Parameters
event: : Event typeparam: : Pointer to callback parameter
-
typedef void (*
esp_a2d_data_cb_t)(const uint8_t *buf, uint32_t len)¶ A2DP profile data callback function.
- Parameters
buf: : data received from A2DP source device and is PCM format decoder from SBC decoder; buf references to a static memory block and can be overwritten by upcoming datalen: : size(in bytes) in buf
Enumerations¶
-
enum
esp_a2d_connection_state_t¶ Bluetooth A2DP connection states.
Values:
-
ESP_A2D_CONNECTION_STATE_DISCONNECTED= 0¶ connection released
-
ESP_A2D_CONNECTION_STATE_CONNECTING¶ connecting remote device
-
ESP_A2D_CONNECTION_STATE_CONNECTED¶ connection established
-
ESP_A2D_CONNECTION_STATE_DISCONNECTING¶ disconnecting remote device
-
-
enum
esp_a2d_disc_rsn_t¶ Bluetooth A2DP disconnection reason.
Values:
-
ESP_A2D_DISC_RSN_NORMAL= 0¶ Finished disconnection that is initiated by local or remote device
-
ESP_A2D_DISC_RSN_ABNORMAL¶ Abnormal disconnection caused by signal loss
-