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