1 /* 2 * SPDX-FileCopyrightText: 2015-2022 Espressif Systems (Shanghai) CO LTD 3 * 4 * SPDX-License-Identifier: Apache-2.0 5 */ 6 7 8 /******************************************************************************* 9 * 10 * Filename: btc_av.h 11 * 12 * Description: Main API header file for all BTC AV functions accessed 13 * from internal stack. 14 * 15 *******************************************************************************/ 16 17 #ifndef __BTC_AV_H__ 18 #define __BTC_AV_H__ 19 20 #include "common/bt_target.h" 21 #include "esp_a2dp_api.h" 22 #include "btc/btc_task.h" 23 #include "btc/btc_common.h" 24 #include "btc/btc_sm.h" 25 #include "bta/bta_av_api.h" 26 27 #if (BTC_AV_INCLUDED == TRUE) 28 29 // global variable to inidcate avrc is initialized with a2dp 30 extern bool g_av_with_rc; 31 // global variable to indicate a2dp is initialized 32 extern bool g_a2dp_on_init; 33 // global variable to indicate a2dp is deinitialized 34 extern bool g_a2dp_on_deinit; 35 // global variable to indicate a2dp source deinitialization is ongoing 36 extern bool g_a2dp_source_ongoing_deinit; 37 // global variable to indicate a2dp sink deinitialization is ongoing 38 extern bool g_a2dp_sink_ongoing_deinit; 39 40 /******************************************************************************* 41 ** Type definitions for callback functions 42 ********************************************************************************/ 43 44 enum { 45 BTC_AV_DATAPATH_OPEN_EVT, // original UIPC_OPEN_EVT for data channel in bluedroid 46 BTC_AV_DATAPATH_MAX_EVT, 47 }; 48 49 typedef enum { 50 BTC_AV_CONNECT_REQ_EVT = BTA_AV_MAX_EVT, 51 BTC_AV_DISCONNECT_REQ_EVT, 52 BTC_AV_START_STREAM_REQ_EVT, 53 BTC_AV_STOP_STREAM_REQ_EVT, 54 BTC_AV_SUSPEND_STREAM_REQ_EVT, 55 BTC_AV_SINK_CONFIG_REQ_EVT, 56 } btc_av_sm_event_t; 57 58 typedef enum { 59 #if BTC_AV_SINK_INCLUDED 60 BTC_AV_SINK_API_INIT_EVT = 0, 61 BTC_AV_SINK_API_DEINIT_EVT, 62 BTC_AV_SINK_API_CONNECT_EVT, 63 BTC_AV_SINK_API_DISCONNECT_EVT, 64 BTC_AV_SINK_API_REG_DATA_CB_EVT, 65 #endif /* BTC_AV_SINK_INCLUDED */ 66 #if BTC_AV_SRC_INCLUDED 67 BTC_AV_SRC_API_INIT_EVT, 68 BTC_AV_SRC_API_DEINIT_EVT, 69 BTC_AV_SRC_API_CONNECT_EVT, 70 BTC_AV_SRC_API_DISCONNECT_EVT, 71 BTC_AV_SRC_API_REG_DATA_CB_EVT, 72 #endif /* BTC_AV_SRC_INCLUDED */ 73 BTC_AV_API_MEDIA_CTRL_EVT, 74 } btc_av_act_t; 75 76 /* btc_av_args_t */ 77 typedef union { 78 #if BTC_AV_SINK_INCLUDED 79 // BTC_AV_SINK_CONFIG_REQ_EVT -- internal event 80 esp_a2d_mcc_t mcc; 81 // BTC_AV_SINK_API_CONNECT_EVT 82 bt_bdaddr_t connect; 83 // BTC_AV_SINK_API_DISCONNECT_EVT 84 bt_bdaddr_t disconn; 85 // BTC_AV_SINK_API_REG_DATA_CB_EVT 86 esp_a2d_sink_data_cb_t data_cb; 87 #endif /* BTC_AV_SINK_INCLUDED */ 88 #if BTC_AV_SRC_INCLUDED 89 // BTC_AV_SRC_API_REG_DATA_CB_EVT 90 esp_a2d_source_data_cb_t src_data_cb; 91 // BTC_AV_SRC_API_CONNECT 92 bt_bdaddr_t src_connect; 93 // BTC_AV_SRC_API_DISCONNECT_EVT 94 bt_bdaddr_t src_disconn; 95 #endif /* BTC_AV_SRC_INCLUDED */ 96 // BTC_AV_API_MEDIA_CTRL_EVT 97 esp_a2d_media_ctrl_t ctrl; 98 } btc_av_args_t; 99 100 /******************************************************************************* 101 ** BTC AV API 102 ********************************************************************************/ 103 104 void btc_a2dp_call_handler(btc_msg_t *msg); 105 106 void btc_a2dp_cb_handler(btc_msg_t *msg); 107 108 void btc_a2dp_sink_reg_data_cb(esp_a2d_sink_data_cb_t callback); 109 110 void btc_a2dp_src_reg_data_cb(esp_a2d_source_data_cb_t callback); 111 /******************************************************************************* 112 ** 113 ** Function btc_av_get_sm_handle 114 ** 115 ** Description Fetches current av SM handle 116 ** 117 ** Returns None 118 ** 119 *******************************************************************************/ 120 121 btc_sm_handle_t btc_av_get_sm_handle(void); 122 123 /******************************************************************************* 124 ** 125 ** Function btc_av_stream_ready 126 ** 127 ** Description Checks whether AV is ready for starting a stream 128 ** 129 ** Returns None 130 ** 131 *******************************************************************************/ 132 133 BOOLEAN btc_av_stream_ready(void); 134 135 /******************************************************************************* 136 ** 137 ** Function btc_av_stream_started_ready 138 ** 139 ** Description Checks whether AV ready for media start in streaming state 140 ** 141 ** Returns None 142 ** 143 *******************************************************************************/ 144 145 BOOLEAN btc_av_stream_started_ready(void); 146 147 /******************************************************************************* 148 ** 149 ** Function btc_dispatch_sm_event 150 ** 151 ** Description Send event to AV statemachine 152 ** 153 ** Returns None 154 ** 155 *******************************************************************************/ 156 157 /* used to pass events to AV statemachine from other tasks */ 158 void btc_dispatch_sm_event(btc_av_sm_event_t event, void *p_data, int len); 159 160 /******************************************************************************* 161 ** 162 ** Function btc_av_is_connected 163 ** 164 ** Description Checks if av has a connected sink 165 ** 166 ** Returns BOOLEAN 167 ** 168 *******************************************************************************/ 169 170 BOOLEAN btc_av_is_connected(void); 171 172 173 /******************************************************************************* 174 * 175 * Function btc_av_get_peer_sep 176 * 177 * Description Get the stream endpoint type. 178 * 179 * Returns The stream endpoint type: either AVDT_TSEP_SRC or 180 * AVDT_TSEP_SNK. 181 * 182 ******************************************************************************/ 183 184 uint8_t btc_av_get_peer_sep(void); 185 186 /******************************************************************************* 187 ** 188 ** Function btc_av_is_peer_edr 189 ** 190 ** Description Check if the connected a2dp device supports 191 ** EDR or not. Only when connected this function 192 ** will accurately provide a true capability of 193 ** remote peer. If not connected it will always be false. 194 ** 195 ** Returns TRUE if remote device is capable of EDR 196 ** 197 *******************************************************************************/ 198 199 BOOLEAN btc_av_is_peer_edr(void); 200 201 /****************************************************************************** 202 ** 203 ** Function btc_av_clear_remote_suspend_flag 204 ** 205 ** Description Clears remote suspended flag 206 ** 207 ** Returns Void 208 ********************************************************************************/ 209 void btc_av_clear_remote_suspend_flag(void); 210 211 /******************************************************************************* 212 * 213 * Function btc_av_get_service_id 214 * 215 * Description Get the current AV service ID. 216 * 217 * Returns The stream endpoint type: either BTA_A2DP_SOURCE_SERVICE_ID or 218 * BTA_A2DP_SINK_SERVICE_ID. 219 * 220 ******************************************************************************/ 221 uint8_t btc_av_get_service_id(void); 222 223 #endif ///BTC_AV_INCLUDED == TRUE 224 225 #endif /* __BTC_AV_H__ */ 226