esp_a2dp_api.h 7.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216
  1. // Copyright 2015-2016 Espressif Systems (Shanghai) PTE LTD
  2. //
  3. // Licensed under the Apache License, Version 2.0 (the "License");
  4. // you may not use this file except in compliance with the License.
  5. // You may obtain a copy of the License at
  6. // http://www.apache.org/licenses/LICENSE-2.0
  7. //
  8. // Unless required by applicable law or agreed to in writing, software
  9. // distributed under the License is distributed on an "AS IS" BASIS,
  10. // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  11. // See the License for the specific language governing permissions and
  12. // limitations under the License.
  13. #ifndef __ESP_A2DP_API_H__
  14. #define __ESP_A2DP_API_H__
  15. #include "esp_err.h"
  16. #include "esp_bt_defs.h"
  17. #ifdef __cplusplus
  18. extern "C" {
  19. #endif
  20. /// Media codec types supported by A2DP
  21. #define ESP_A2D_MCT_SBC (0) /*!< SBC */
  22. #define ESP_A2D_MCT_M12 (0x01) /*!< MPEG-1, 2 Audio */
  23. #define ESP_A2D_MCT_M24 (0x02) /*!< MPEG-2, 4 AAC */
  24. #define ESP_A2D_MCT_ATRAC (0x04) /*!< ATRAC family */
  25. #define ESP_A2D_MCT_NON_A2DP (0xff)
  26. typedef uint8_t esp_a2d_mct_t;
  27. /// A2DP media codec capabilities union
  28. typedef struct {
  29. esp_a2d_mct_t type; /*!< A2DP media codec type */
  30. #define ESP_A2D_CIE_LEN_SBC (4)
  31. #define ESP_A2D_CIE_LEN_M12 (4)
  32. #define ESP_A2D_CIE_LEN_M24 (6)
  33. #define ESP_A2D_CIE_LEN_ATRAC (7)
  34. union {
  35. uint8_t sbc[ESP_A2D_CIE_LEN_SBC];
  36. uint8_t m12[ESP_A2D_CIE_LEN_M12];
  37. uint8_t m24[ESP_A2D_CIE_LEN_M24];
  38. uint8_t atrac[ESP_A2D_CIE_LEN_ATRAC];
  39. } cie; /*!< A2DP codec information element */
  40. } __attribute__((packed)) esp_a2d_mcc_t;
  41. /// Bluetooth A2DP connection states
  42. typedef enum {
  43. ESP_A2D_CONNECTION_STATE_DISCONNECTED = 0, /*!< connection released */
  44. ESP_A2D_CONNECTION_STATE_CONNECTING, /*!< connecting remote device */
  45. ESP_A2D_CONNECTION_STATE_CONNECTED, /*!< connection established */
  46. ESP_A2D_CONNECTION_STATE_DISCONNECTING /*!< disconnecting remote device */
  47. } esp_a2d_connection_state_t;
  48. /// Bluetooth A2DP disconnection reason
  49. typedef enum {
  50. ESP_A2D_DISC_RSN_NORMAL = 0, /*!< Finished disconnection that is initiated by local or remote device */
  51. ESP_A2D_DISC_RSN_ABNORMAL /*!< Abnormal disconnection caused by signal loss */
  52. } esp_a2d_disc_rsn_t;
  53. /// Bluetooth A2DP datapath states
  54. typedef enum {
  55. ESP_A2D_AUDIO_STATE_REMOTE_SUSPEND = 0, /*!< audio stream datapath suspended by remote device */
  56. ESP_A2D_AUDIO_STATE_STOPPED, /*!< audio stream datapath stopped */
  57. ESP_A2D_AUDIO_STATE_STARTED, /*!< audio stream datapath started */
  58. } esp_a2d_audio_state_t;
  59. /// A2DP callback events
  60. typedef enum {
  61. ESP_A2D_CONNECTION_STATE_EVT = 0, /*!< connection state changed event */
  62. ESP_A2D_AUDIO_STATE_EVT = 1, /*!< audio stream transmission state changed event */
  63. ESP_A2D_AUDIO_CFG_EVT = 2 /*!< audio codec is configured */
  64. } esp_a2d_cb_event_t;
  65. /// A2DP state callback parameters
  66. typedef union {
  67. /**
  68. * @brief ESP_A2D_CONNECTION_STATE_EVT
  69. */
  70. struct a2d_conn_stat_param {
  71. esp_a2d_connection_state_t state; /*!< one of values from esp_a2d_connection_state_t */
  72. esp_bd_addr_t remote_bda; /*!< remote bluetooth device address */
  73. esp_a2d_disc_rsn_t disc_rsn; /*!< reason of disconnection for "DISCONNECTED" */
  74. } conn_stat; /*!< A2DP connection status */
  75. /**
  76. * @brief ESP_A2D_AUDIO_STATE_EVT
  77. */
  78. struct a2d_audio_stat_param {
  79. esp_a2d_audio_state_t state; /*!< one of the values from esp_a2d_audio_state_t */
  80. esp_bd_addr_t remote_bda; /*!< remote bluetooth device address */
  81. } audio_stat; /*!< audio stream playing state */
  82. /**
  83. * @brief ESP_A2D_AUDIO_CFG_EVT
  84. */
  85. struct a2d_audio_cfg_param {
  86. esp_bd_addr_t remote_bda; /*!< remote bluetooth device address */
  87. esp_a2d_mcc_t mcc; /*!< A2DP media codec capability information */
  88. } audio_cfg; /*!< media codec configuration infomation */
  89. } esp_a2d_cb_param_t;
  90. /**
  91. * @brief A2DP profile callback function type
  92. * @param event : Event type
  93. * @param param : Pointer to callback parameter
  94. */
  95. typedef void (* esp_a2d_cb_t)(esp_a2d_cb_event_t event, esp_a2d_cb_param_t *param);
  96. /**
  97. * @brief A2DP profile data callback function
  98. *
  99. * @param[in] buf : data received from A2DP source device and is PCM format decoder from SBC decoder;
  100. * buf references to a static memory block and can be overwritten by upcoming data
  101. *
  102. * @param[in] len : size(in bytes) in buf
  103. *
  104. */
  105. typedef void (* esp_a2d_data_cb_t)(const uint8_t *buf, uint32_t len);
  106. /**
  107. * @brief Register application callback function to A2DP module. This function should be called
  108. * only after esp_bluedroid_enable() completes successfully
  109. *
  110. * @param[in] callback: A2DP sink event callback function
  111. *
  112. * @return
  113. * - ESP_OK: success
  114. * - ESP_INVALID_STATE: if bluetooth stack is not yet enabled
  115. * - ESP_FAIL: if callback is a NULL function pointer
  116. *
  117. */
  118. esp_err_t esp_a2d_register_callback(esp_a2d_cb_t callback);
  119. /**
  120. * @brief Register A2DP sink data output function; For now the output is PCM data stream decoded
  121. * from SBC format. This function should be called only after esp_bluedroid_enable()
  122. * completes successfully
  123. *
  124. * @param[in] callback: A2DP data callback function
  125. *
  126. * @return
  127. * - ESP_OK: success
  128. * - ESP_INVALID_STATE: if bluetooth stack is not yet enabled
  129. * - ESP_FAIL: if callback is a NULL function pointer
  130. *
  131. */
  132. esp_err_t esp_a2d_register_data_callback(esp_a2d_data_cb_t callback);
  133. /**
  134. *
  135. * @brief Initialize the bluetooth A2DP sink module. This function should be called
  136. * after esp_bluedroid_enable() completes successfully
  137. *
  138. * @return
  139. * - ESP_OK: if the initialization request is sent successfully
  140. * - ESP_INVALID_STATE: if bluetooth stack is not yet enabled
  141. * - ESP_FAIL: others
  142. *
  143. */
  144. esp_err_t esp_a2d_sink_init(void);
  145. /**
  146. *
  147. * @brief De-initialize for A2DP sink module. This function
  148. * should be called only after esp_bluedroid_enable() completes successfully
  149. *
  150. * @return
  151. * - ESP_OK: success
  152. * - ESP_INVALID_STATE: if bluetooth stack is not yet enabled
  153. * - ESP_FAIL: others
  154. *
  155. */
  156. esp_err_t esp_a2d_sink_deinit(void);
  157. /**
  158. *
  159. * @brief Connect the remote bluetooth device bluetooth, must after esp_a2d_sink_init()
  160. *
  161. * @param[in] remote_bda: remote bluetooth device address
  162. *
  163. * @return
  164. * - ESP_OK: connect request is sent to lower layer
  165. * - ESP_INVALID_STATE: if bluetooth stack is not yet enabled
  166. * - ESP_FAIL: others
  167. *
  168. */
  169. esp_err_t esp_a2d_sink_connect(esp_bd_addr_t remote_bda);
  170. /**
  171. *
  172. * @brief Disconnect the remote bluetooth device
  173. *
  174. * @param[in] remote_bda: remote bluetooth device address
  175. * @return
  176. * - ESP_OK: disconnect request is sent to lower layer
  177. * - ESP_INVALID_STATE: if bluetooth stack is not yet enabled
  178. * - ESP_FAIL: others
  179. *
  180. */
  181. esp_err_t esp_a2d_sink_disconnect(esp_bd_addr_t remote_bda);
  182. #ifdef __cplusplus
  183. }
  184. #endif
  185. #endif /* __ESP_A2DP_API_H__ */