2016-12-27 05:48:07 +00:00
|
|
|
// Copyright 2015-2016 Espressif Systems (Shanghai) PTE LTD
|
|
|
|
//
|
|
|
|
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
// you may not use this file except in compliance with the License.
|
|
|
|
// You may obtain a copy of the License at
|
|
|
|
|
|
|
|
// http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
//
|
|
|
|
// Unless required by applicable law or agreed to in writing, software
|
|
|
|
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
// See the License for the specific language governing permissions and
|
|
|
|
// limitations under the License.
|
|
|
|
|
2016-12-01 06:57:44 +00:00
|
|
|
#ifndef __ESP_A2DP_API_H__
|
|
|
|
#define __ESP_A2DP_API_H__
|
|
|
|
|
|
|
|
#include "esp_err.h"
|
|
|
|
#include "esp_bt_defs.h"
|
|
|
|
|
2017-03-09 11:03:34 +00:00
|
|
|
#ifdef __cplusplus
|
|
|
|
extern "C" {
|
|
|
|
#endif
|
|
|
|
|
2016-12-26 14:02:40 +00:00
|
|
|
/// 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 */
|
2016-12-01 11:48:51 +00:00
|
|
|
#define ESP_A2D_MCT_NON_A2DP (0xff)
|
2017-03-18 06:55:31 +00:00
|
|
|
|
2016-12-01 11:48:51 +00:00
|
|
|
typedef uint8_t esp_a2d_mct_t;
|
2016-12-01 06:57:44 +00:00
|
|
|
|
2017-03-18 06:55:31 +00:00
|
|
|
/// A2DP media codec capabilities union
|
2016-12-01 06:57:44 +00:00
|
|
|
typedef struct {
|
2017-03-18 06:55:31 +00:00
|
|
|
esp_a2d_mct_t type; /*!< A2DP media codec type */
|
2016-12-26 14:02:40 +00:00
|
|
|
#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)
|
2016-12-01 06:57:44 +00:00
|
|
|
union {
|
2017-03-18 06:55:31 +00:00
|
|
|
uint8_t sbc[ESP_A2D_CIE_LEN_SBC];
|
|
|
|
uint8_t m12[ESP_A2D_CIE_LEN_M12];
|
|
|
|
uint8_t m24[ESP_A2D_CIE_LEN_M24];
|
|
|
|
uint8_t atrac[ESP_A2D_CIE_LEN_ATRAC];
|
|
|
|
} cie; /*!< A2DP codec information element */
|
|
|
|
} __attribute__((packed)) esp_a2d_mcc_t;
|
2016-12-01 06:57:44 +00:00
|
|
|
|
2016-12-26 14:02:40 +00:00
|
|
|
/// Bluetooth A2DP connection states
|
2016-12-01 06:57:44 +00:00
|
|
|
typedef enum {
|
2017-03-09 11:03:34 +00:00
|
|
|
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 */
|
2016-12-01 11:48:51 +00:00
|
|
|
} esp_a2d_connection_state_t;
|
2016-12-01 06:57:44 +00:00
|
|
|
|
2017-02-23 06:30:08 +00:00
|
|
|
/// Bluetooth A2DP disconnection reason
|
|
|
|
typedef enum {
|
2017-03-09 11:03:34 +00:00
|
|
|
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 */
|
2017-02-23 06:30:08 +00:00
|
|
|
} esp_a2d_disc_rsn_t;
|
|
|
|
|
2016-12-26 14:02:40 +00:00
|
|
|
/// Bluetooth A2DP datapath states
|
2016-12-01 06:57:44 +00:00
|
|
|
typedef enum {
|
2017-03-09 11:03:34 +00:00
|
|
|
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 */
|
2016-12-01 11:48:51 +00:00
|
|
|
} esp_a2d_audio_state_t;
|
2016-12-01 06:57:44 +00:00
|
|
|
|
2016-12-26 14:02:40 +00:00
|
|
|
/// A2DP callback events
|
2016-12-01 13:13:27 +00:00
|
|
|
typedef enum {
|
2017-03-09 11:03:34 +00:00
|
|
|
ESP_A2D_CONNECTION_STATE_EVT = 0, /*!< connection state changed event */
|
|
|
|
ESP_A2D_AUDIO_STATE_EVT = 1, /*!< audio stream transmission state changed event */
|
|
|
|
ESP_A2D_AUDIO_CFG_EVT = 2 /*!< audio codec is configured */
|
2016-12-01 13:13:27 +00:00
|
|
|
} esp_a2d_cb_event_t;
|
|
|
|
|
2016-12-26 14:02:40 +00:00
|
|
|
/// A2DP state callback parameters
|
2016-12-01 13:13:27 +00:00
|
|
|
typedef union {
|
2017-03-18 06:55:31 +00:00
|
|
|
/**
|
|
|
|
* @brief ESP_A2D_CONNECTION_STATE_EVT
|
|
|
|
*/
|
2016-12-01 13:13:27 +00:00
|
|
|
struct a2d_conn_stat_param {
|
2017-03-09 11:03:34 +00:00
|
|
|
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" */
|
2017-03-18 06:55:31 +00:00
|
|
|
} conn_stat; /*!< A2DP connection status */
|
2016-12-01 13:13:27 +00:00
|
|
|
|
2017-03-18 06:55:31 +00:00
|
|
|
/**
|
|
|
|
* @brief ESP_A2D_AUDIO_STATE_EVT
|
|
|
|
*/
|
2016-12-01 13:13:27 +00:00
|
|
|
struct a2d_audio_stat_param {
|
2017-03-09 11:03:34 +00:00
|
|
|
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 */
|
2017-03-18 06:55:31 +00:00
|
|
|
} audio_stat; /*!< audio stream playing state */
|
2016-12-01 13:13:27 +00:00
|
|
|
|
2017-03-18 06:55:31 +00:00
|
|
|
/**
|
|
|
|
* @brief ESP_A2D_AUDIO_CFG_EVT
|
|
|
|
*/
|
2016-12-01 13:13:27 +00:00
|
|
|
struct a2d_audio_cfg_param {
|
2017-03-09 11:03:34 +00:00
|
|
|
esp_bd_addr_t remote_bda; /*!< remote bluetooth device address */
|
|
|
|
esp_a2d_mcc_t mcc; /*!< A2DP media codec capability information */
|
2017-03-18 06:55:31 +00:00
|
|
|
} audio_cfg; /*!< media codec configuration infomation */
|
2016-12-01 13:13:27 +00:00
|
|
|
} esp_a2d_cb_param_t;
|
2016-12-01 06:57:44 +00:00
|
|
|
|
2017-01-17 02:36:26 +00:00
|
|
|
/**
|
2017-03-09 11:03:34 +00:00
|
|
|
* @brief A2DP profile callback function type
|
2017-01-17 02:36:26 +00:00
|
|
|
* @param event : Event type
|
2017-03-09 11:03:34 +00:00
|
|
|
* @param param : Pointer to callback parameter
|
2017-01-17 02:36:26 +00:00
|
|
|
*/
|
|
|
|
typedef void (* esp_a2d_cb_t)(esp_a2d_cb_event_t event, esp_a2d_cb_param_t *param);
|
|
|
|
|
2016-12-01 06:57:44 +00:00
|
|
|
/**
|
2017-03-09 11:03:34 +00:00
|
|
|
* @brief A2DP profile data callback function
|
|
|
|
*
|
|
|
|
* @param[in] 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 data
|
|
|
|
*
|
|
|
|
* @param[in] len : size(in bytes) in buf
|
2016-12-26 14:02:40 +00:00
|
|
|
*
|
2016-12-01 06:57:44 +00:00
|
|
|
*/
|
2016-12-26 14:02:40 +00:00
|
|
|
typedef void (* esp_a2d_data_cb_t)(const uint8_t *buf, uint32_t len);
|
|
|
|
|
2016-12-01 06:57:44 +00:00
|
|
|
|
2016-12-01 13:13:27 +00:00
|
|
|
/**
|
2017-03-09 11:03:34 +00:00
|
|
|
* @brief Register application callback function to A2DP module. This function should be called
|
|
|
|
* only after esp_bluedroid_enable() completes successfully
|
2016-12-26 14:02:40 +00:00
|
|
|
*
|
|
|
|
* @param[in] callback: A2DP sink event callback function
|
|
|
|
*
|
|
|
|
* @return
|
|
|
|
* - ESP_OK: success
|
2017-03-09 11:03:34 +00:00
|
|
|
* - ESP_INVALID_STATE: if bluetooth stack is not yet enabled
|
|
|
|
* - ESP_FAIL: if callback is a NULL function pointer
|
2016-12-26 14:02:40 +00:00
|
|
|
*
|
2016-12-01 06:57:44 +00:00
|
|
|
*/
|
2017-01-17 02:36:26 +00:00
|
|
|
esp_err_t esp_a2d_register_callback(esp_a2d_cb_t callback);
|
2016-12-01 13:30:05 +00:00
|
|
|
|
2016-12-26 14:02:40 +00:00
|
|
|
|
|
|
|
/**
|
2017-03-09 11:03:34 +00:00
|
|
|
* @brief 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
|
2016-12-26 14:02:40 +00:00
|
|
|
*
|
|
|
|
* @param[in] callback: A2DP data callback function
|
|
|
|
*
|
|
|
|
* @return
|
|
|
|
* - ESP_OK: success
|
2017-03-09 11:03:34 +00:00
|
|
|
* - ESP_INVALID_STATE: if bluetooth stack is not yet enabled
|
|
|
|
* - ESP_FAIL: if callback is a NULL function pointer
|
2016-12-26 14:02:40 +00:00
|
|
|
*
|
|
|
|
*/
|
2017-03-13 06:54:02 +00:00
|
|
|
esp_err_t esp_a2d_register_data_callback(esp_a2d_data_cb_t callback);
|
2016-12-02 06:39:03 +00:00
|
|
|
|
2016-12-01 06:57:44 +00:00
|
|
|
|
2016-12-26 14:02:40 +00:00
|
|
|
/**
|
|
|
|
*
|
2017-03-09 11:03:34 +00:00
|
|
|
* @brief Initialize the bluetooth A2DP sink module. This function should be called
|
|
|
|
* after esp_bluedroid_enable() completes successfully
|
2016-12-26 14:02:40 +00:00
|
|
|
*
|
|
|
|
* @return
|
2017-03-09 11:03:34 +00:00
|
|
|
* - ESP_OK: if the initialization request is sent successfully
|
|
|
|
* - ESP_INVALID_STATE: if bluetooth stack is not yet enabled
|
2016-12-26 14:02:40 +00:00
|
|
|
* - ESP_FAIL: others
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
esp_err_t esp_a2d_sink_init(void);
|
2016-12-01 06:57:44 +00:00
|
|
|
|
|
|
|
|
2016-12-26 14:02:40 +00:00
|
|
|
/**
|
|
|
|
*
|
2017-03-09 11:03:34 +00:00
|
|
|
* @brief De-initialize for A2DP sink module. This function
|
|
|
|
* should be called only after esp_bluedroid_enable() completes successfully
|
2016-12-26 14:02:40 +00:00
|
|
|
*
|
2017-03-07 13:15:54 +00:00
|
|
|
* @return
|
|
|
|
* - ESP_OK: success
|
2017-03-09 11:03:34 +00:00
|
|
|
* - ESP_INVALID_STATE: if bluetooth stack is not yet enabled
|
2017-03-07 13:15:54 +00:00
|
|
|
* - ESP_FAIL: others
|
|
|
|
*
|
2016-12-26 14:02:40 +00:00
|
|
|
*/
|
2017-03-07 13:15:54 +00:00
|
|
|
esp_err_t esp_a2d_sink_deinit(void);
|
2016-12-01 06:57:44 +00:00
|
|
|
|
2016-12-26 14:02:40 +00:00
|
|
|
|
2017-02-23 06:30:08 +00:00
|
|
|
/**
|
|
|
|
*
|
2017-03-09 11:03:34 +00:00
|
|
|
* @brief Connect the remote bluetooth device bluetooth, must after esp_a2d_sink_init()
|
|
|
|
*
|
|
|
|
* @param[in] remote_bda: remote bluetooth device address
|
2017-02-23 06:30:08 +00:00
|
|
|
*
|
|
|
|
* @return
|
|
|
|
* - ESP_OK: connect request is sent to lower layer
|
2017-03-09 11:03:34 +00:00
|
|
|
* - ESP_INVALID_STATE: if bluetooth stack is not yet enabled
|
2017-02-23 06:30:08 +00:00
|
|
|
* - ESP_FAIL: others
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
esp_err_t esp_a2d_sink_connect(esp_bd_addr_t remote_bda);
|
|
|
|
|
|
|
|
|
2016-12-26 14:02:40 +00:00
|
|
|
/**
|
|
|
|
*
|
2017-03-09 11:03:34 +00:00
|
|
|
* @brief Disconnect the remote bluetooth device
|
2016-12-26 14:02:40 +00:00
|
|
|
*
|
2017-03-09 11:03:34 +00:00
|
|
|
* @param[in] remote_bda: remote bluetooth device address
|
2016-12-26 14:02:40 +00:00
|
|
|
* @return
|
|
|
|
* - ESP_OK: disconnect request is sent to lower layer
|
2017-03-09 11:03:34 +00:00
|
|
|
* - ESP_INVALID_STATE: if bluetooth stack is not yet enabled
|
2016-12-26 14:02:40 +00:00
|
|
|
* - ESP_FAIL: others
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
esp_err_t esp_a2d_sink_disconnect(esp_bd_addr_t remote_bda);
|
|
|
|
|
2017-03-09 11:03:34 +00:00
|
|
|
#ifdef __cplusplus
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
2016-12-01 06:57:44 +00:00
|
|
|
#endif /* __ESP_A2DP_API_H__ */
|