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 BTC_AV_SINK_API_SET_DELAY_VALUE_EVT, 66 BTC_AV_SINK_API_GET_DELAY_VALUE_EVT, 67 #endif /* BTC_AV_SINK_INCLUDED */ 68 #if BTC_AV_SRC_INCLUDED 69 BTC_AV_SRC_API_INIT_EVT, 70 BTC_AV_SRC_API_DEINIT_EVT, 71 BTC_AV_SRC_API_CONNECT_EVT, 72 BTC_AV_SRC_API_DISCONNECT_EVT, 73 BTC_AV_SRC_API_REG_DATA_CB_EVT, 74 #endif /* BTC_AV_SRC_INCLUDED */ 75 BTC_AV_API_MEDIA_CTRL_EVT, 76 } btc_av_act_t; 77 78 /* btc_av_args_t */ 79 typedef union { 80 #if BTC_AV_SINK_INCLUDED 81 // BTC_AV_SINK_CONFIG_REQ_EVT -- internal event 82 esp_a2d_mcc_t mcc; 83 // BTC_AV_SINK_API_CONNECT_EVT 84 bt_bdaddr_t connect; 85 // BTC_AV_SINK_API_DISCONNECT_EVT 86 bt_bdaddr_t disconn; 87 // BTC_AV_SINK_API_REG_DATA_CB_EVT 88 esp_a2d_sink_data_cb_t data_cb; 89 // BTC_AV_SINK_API_SET_DELAY_VALUE_EVT 90 uint16_t delay_value; 91 #endif /* BTC_AV_SINK_INCLUDED */ 92 #if BTC_AV_SRC_INCLUDED 93 // BTC_AV_SRC_API_REG_DATA_CB_EVT 94 esp_a2d_source_data_cb_t src_data_cb; 95 // BTC_AV_SRC_API_CONNECT 96 bt_bdaddr_t src_connect; 97 // BTC_AV_SRC_API_DISCONNECT_EVT 98 bt_bdaddr_t src_disconn; 99 #endif /* BTC_AV_SRC_INCLUDED */ 100 // BTC_AV_API_MEDIA_CTRL_EVT 101 esp_a2d_media_ctrl_t ctrl; 102 } btc_av_args_t; 103 104 /******************************************************************************* 105 ** BTC AV API 106 ********************************************************************************/ 107 108 void btc_a2dp_call_handler(btc_msg_t *msg); 109 110 void btc_a2dp_cb_handler(btc_msg_t *msg); 111 112 void btc_a2dp_sink_reg_data_cb(esp_a2d_sink_data_cb_t callback); 113 114 void btc_a2dp_src_reg_data_cb(esp_a2d_source_data_cb_t callback); 115 /******************************************************************************* 116 ** 117 ** Function btc_av_get_sm_handle 118 ** 119 ** Description Fetches current av SM handle 120 ** 121 ** Returns None 122 ** 123 *******************************************************************************/ 124 125 btc_sm_handle_t btc_av_get_sm_handle(void); 126 127 /******************************************************************************* 128 ** 129 ** Function btc_av_stream_ready 130 ** 131 ** Description Checks whether AV is ready for starting a stream 132 ** 133 ** Returns None 134 ** 135 *******************************************************************************/ 136 137 BOOLEAN btc_av_stream_ready(void); 138 139 /******************************************************************************* 140 ** 141 ** Function btc_av_stream_started_ready 142 ** 143 ** Description Checks whether AV ready for media start in streaming state 144 ** 145 ** Returns None 146 ** 147 *******************************************************************************/ 148 149 BOOLEAN btc_av_stream_started_ready(void); 150 151 /******************************************************************************* 152 ** 153 ** Function btc_dispatch_sm_event 154 ** 155 ** Description Send event to AV statemachine 156 ** 157 ** Returns None 158 ** 159 *******************************************************************************/ 160 161 /* used to pass events to AV statemachine from other tasks */ 162 void btc_dispatch_sm_event(btc_av_sm_event_t event, void *p_data, int len); 163 164 /******************************************************************************* 165 ** 166 ** Function btc_av_is_connected 167 ** 168 ** Description Checks if av has a connected sink 169 ** 170 ** Returns BOOLEAN 171 ** 172 *******************************************************************************/ 173 174 BOOLEAN btc_av_is_connected(void); 175 176 177 /******************************************************************************* 178 * 179 * Function btc_av_get_peer_sep 180 * 181 * Description Get the stream endpoint type. 182 * 183 * Returns The stream endpoint type: either AVDT_TSEP_SRC or 184 * AVDT_TSEP_SNK. 185 * 186 ******************************************************************************/ 187 188 uint8_t btc_av_get_peer_sep(void); 189 190 /******************************************************************************* 191 ** 192 ** Function btc_av_is_peer_edr 193 ** 194 ** Description Check if the connected a2dp device supports 195 ** EDR or not. Only when connected this function 196 ** will accurately provide a true capability of 197 ** remote peer. If not connected it will always be false. 198 ** 199 ** Returns TRUE if remote device is capable of EDR 200 ** 201 *******************************************************************************/ 202 203 BOOLEAN btc_av_is_peer_edr(void); 204 205 /****************************************************************************** 206 ** 207 ** Function btc_av_clear_remote_suspend_flag 208 ** 209 ** Description Clears remote suspended flag 210 ** 211 ** Returns Void 212 ********************************************************************************/ 213 void btc_av_clear_remote_suspend_flag(void); 214 215 /******************************************************************************* 216 * 217 * Function btc_av_get_service_id 218 * 219 * Description Get the current AV service ID. 220 * 221 * Returns The stream endpoint type: either BTA_A2DP_SOURCE_SERVICE_ID or 222 * BTA_A2DP_SINK_SERVICE_ID. 223 * 224 ******************************************************************************/ 225 uint8_t btc_av_get_service_id(void); 226 227 #endif ///BTC_AV_INCLUDED == TRUE 228 229 #endif /* __BTC_AV_H__ */ 230