Merge branch 'feature/add_avdtp_delay_reporting' into 'master'

component_bt: add avdtp delay reporting

Closes BT-2308

See merge request espressif/esp-idf!17475
This commit is contained in:
Jiang Jiang Jian
2022-05-29 17:03:36 +08:00
26 changed files with 831 additions and 64 deletions
@@ -14,16 +14,24 @@
extern "C" {
#endif
/// Media codec types supported by A2DP
/**
* @brief Media codec types supported by A2DP.
*/
#define ESP_A2D_MCT_SBC (0) /*!< SBC */
#define ESP_A2D_MCT_M12 (0x01) /*!< MPEG-1, 2 Audio */
#define ESP_A2D_MCT_M24 (0x02) /*!< MPEG-2, 4 AAC */
#define ESP_A2D_MCT_ATRAC (0x04) /*!< ATRAC family */
#define ESP_A2D_MCT_NON_A2DP (0xff)
#define ESP_A2D_MCT_NON_A2DP (0xff) /*!< NON-A2DP */
typedef uint8_t esp_a2d_mct_t;
/** A2DP media codec capabilities union
/**
* @brief Protocol service capabilities. This value is a mask.
*/
#define ESP_A2D_PSC_DELAY_RPT (1<<0) /*!< Delay Report */
typedef uint16_t esp_a2d_psc_t;
/**
* @brief A2DP media codec capabilities union
*/
typedef struct {
esp_a2d_mct_t type; /*!< A2DP media codec type */
@@ -39,7 +47,9 @@ typedef struct {
} cie; /*!< A2DP codec information element */
} __attribute__((packed)) esp_a2d_mcc_t;
/// Bluetooth A2DP connection states
/**
* @brief Bluetooth A2DP connection states
*/
typedef enum {
ESP_A2D_CONNECTION_STATE_DISCONNECTED = 0, /*!< connection released */
ESP_A2D_CONNECTION_STATE_CONNECTING, /*!< connecting remote device */
@@ -47,27 +57,35 @@ typedef enum {
ESP_A2D_CONNECTION_STATE_DISCONNECTING /*!< disconnecting remote device */
} esp_a2d_connection_state_t;
/// Bluetooth A2DP disconnection reason
/**
* @brief Bluetooth A2DP disconnection reason
*/
typedef enum {
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 */
} esp_a2d_disc_rsn_t;
/// Bluetooth A2DP datapath states
/**
* @brief Bluetooth A2DP datapath states
*/
typedef enum {
ESP_A2D_AUDIO_STATE_REMOTE_SUSPEND = 0, /*!< audio stream datapath suspended by remote device */
ESP_A2D_AUDIO_STATE_STOPPED, /*!< audio stream datapath stopped */
ESP_A2D_AUDIO_STATE_STARTED, /*!< audio stream datapath started */
} esp_a2d_audio_state_t;
/// A2DP media control command acknowledgement code
/**
* @brief A2DP media control command acknowledgement code
*/
typedef enum {
ESP_A2D_MEDIA_CTRL_ACK_SUCCESS = 0, /*!< media control command is acknowledged with success */
ESP_A2D_MEDIA_CTRL_ACK_FAILURE, /*!< media control command is acknowledged with failure */
ESP_A2D_MEDIA_CTRL_ACK_BUSY, /*!< media control command is rejected, as previous command is not yet acknowledged */
} esp_a2d_media_ctrl_ack_t;
/// A2DP media control commands
/**
* @brief A2DP media control commands
*/
typedef enum {
ESP_A2D_MEDIA_CTRL_NONE = 0, /*!< Not for application use, use inside stack only. */
ESP_A2D_MEDIA_CTRL_CHECK_SRC_RDY, /*!< check whether AVDTP is connected, only used in A2DP source */
@@ -76,22 +94,40 @@ typedef enum {
ESP_A2D_MEDIA_CTRL_SUSPEND, /*!< command to suspend media transmission */
} esp_a2d_media_ctrl_t;
/// Bluetooth A2DP Initiation states
/**
* @brief Bluetooth A2DP Initiation states
*/
typedef enum {
ESP_A2D_DEINIT_SUCCESS = 0, /*!< A2DP profile deinit successful event */
ESP_A2D_INIT_SUCCESS /*!< A2DP profile deinit successful event */
} esp_a2d_init_state_t;
/// A2DP callback events
/**
* @brief Bluetooth A2DP set delay report value states
*/
typedef enum {
ESP_A2D_SET_SUCCESS = 0, /*!< A2DP profile set delay report value successful */
ESP_A2D_SET_INVALID_PARAMS /*!< A2DP profile set delay report value is invalid parameter */
} esp_a2d_set_delay_value_state_t;
/**
* @brief A2DP callback events
*/
typedef enum {
ESP_A2D_CONNECTION_STATE_EVT = 0, /*!< connection state changed event */
ESP_A2D_AUDIO_STATE_EVT, /*!< audio stream transmission state changed event */
ESP_A2D_AUDIO_CFG_EVT, /*!< audio codec is configured, only used for A2DP SINK */
ESP_A2D_MEDIA_CTRL_ACK_EVT, /*!< acknowledge event in response to media control commands */
ESP_A2D_PROF_STATE_EVT, /*!< indicate a2dp init&deinit complete */
ESP_A2D_SNK_PSC_CFG_EVT, /*!< protocol service capabilities configuredonly used for A2DP SINK */
ESP_A2D_SNK_SET_DELAY_VALUE_EVT, /*!< indicate a2dp sink set delay report value complete, only used for A2DP SINK */
ESP_A2D_SNK_GET_DELAY_VALUE_EVT, /*!< indicate a2dp sink get delay report value complete, only used for A2DP SINK */
ESP_A2D_REPORT_SNK_DELAY_VALUE_EVT, /*!< report delay value, only used for A2DP SRC */
} esp_a2d_cb_event_t;
/// A2DP state callback parameters
/**
* @brief A2DP state callback parameters
*/
typedef union {
/**
* @brief ESP_A2D_CONNECTION_STATE_EVT
@@ -125,12 +161,43 @@ typedef union {
esp_a2d_media_ctrl_t cmd; /*!< media control commands to acknowledge */
esp_a2d_media_ctrl_ack_t status; /*!< acknowledgement to media control commands */
} media_ctrl_stat; /*!< status in acknowledgement to media control commands */
/**
* @brief ESP_A2D_PROF_STATE_EVT
*/
struct a2d_prof_stat_param {
esp_a2d_init_state_t init_state; /*!< a2dp profile state param */
} a2d_prof_stat; /*!< status to indicate a2d prof init or deinit */
/**
* @brief ESP_A2D_SNK_PSC_CFG_EVT
*/
struct a2d_psc_cfg_param {
esp_a2d_psc_t psc_mask; /*!< protocol service capabilities configured */
} a2d_psc_cfg_stat; /*!< status to indicate protocol service capabilities configured */
/**
* @brief ESP_A2D_SNK_SET_DELAY_VALUE_EVT
*/
struct a2d_set_stat_param {
esp_a2d_set_delay_value_state_t set_state; /*!< a2dp profile state param */
uint16_t delay_value; /*!< delay report value */
} a2d_set_delay_value_stat; /*!< A2DP sink set delay report value status */
/**
* @brief ESP_A2D_SNK_GET_DELAY_VALUE_EVT
*/
struct a2d_get_stat_param {
uint16_t delay_value; /*!< delay report value */
} a2d_get_delay_value_stat; /*!< A2DP sink get delay report value status */
/**
* @brief ESP_A2D_REPORT_SNK_DELAY_VALUE_EVT
*/
struct a2d_report_delay_stat_param {
uint16_t delay_value; /*!< delay report value */
} a2d_report_delay_value_stat; /*!< A2DP source received sink report value status */
} esp_a2d_cb_param_t;
/**
@@ -261,6 +328,36 @@ esp_err_t esp_a2d_sink_connect(esp_bd_addr_t remote_bda);
*/
esp_err_t esp_a2d_sink_disconnect(esp_bd_addr_t remote_bda);
/**
*
* @brief Set delay reporting value. The delay value of sink is caused by buffering (including
* protocol stack and application layer), decoding and rendering. The default delay
* value is 120ms, if the set value is less than 120ms, the setting will fail. This API
* must be called after esp_a2d_sink_init() and before esp_a2d_sink_deinit().
*
* @param[in] delay_value: reporting value is in 1/10 millisecond
*
* @return
* - ESP_OK: delay value is sent to lower layer successfully
* - ESP_INVALID_STATE: if bluetooth stack is not yet enabled
* - ESP_FAIL: others
*
*/
esp_err_t esp_a2d_sink_set_delay_value(uint16_t delay_value);
/**
*
* @brief Get delay reporting value. This API must be called after
* esp_a2d_sink_init() and before esp_a2d_sink_deinit().
*
* @return
* - ESP_OK: if the request is sent successfully
* - ESP_INVALID_STATE: if bluetooth stack is not yet enabled
* - ESP_FAIL: others
*
*/
esp_err_t esp_a2d_sink_get_delay_value(void);
/**
*