1 /******************************************************************************
2  *
3  *  Copyright 2009-2012 Broadcom Corporation
4  *
5  *  Licensed under the Apache License, Version 2.0 (the "License");
6  *  you may not use this file except in compliance with the License.
7  *  You may obtain a copy of the License at:
8  *
9  *  http://www.apache.org/licenses/LICENSE-2.0
10  *
11  *  Unless required by applicable law or agreed to in writing, software
12  *  distributed under the License is distributed on an "AS IS" BASIS,
13  *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  *  See the License for the specific language governing permissions and
15  *  limitations under the License.
16  *
17  ******************************************************************************/
18 
19 /**
20  * BTIF AV API functions accessed internally.
21  */
22 
23 #ifndef BTIF_AV_H
24 #define BTIF_AV_H
25 
26 #include <cstdint>
27 #include <vector>
28 
29 #include "include/hardware/bt_av.h"
30 #include "types/raw_address.h"
31 
32 // #include "bta/include/bta_av_api.h"
33 // #include "btif/include/btif_common.h"
34 
35 /**
36  * Enum to represent the type of local a2dp profile.
37  */
38 enum class A2dpType { kSource, kSink, kUnknown };
39 /**
40  * When the local device is A2DP source, get the address of the active peer.
41  */
42 RawAddress btif_av_source_active_peer(void);
43 
44 /**
45  * When the local device is A2DP sink, get the address of the active peer.
46  */
47 RawAddress btif_av_sink_active_peer(void);
48 
49 /**
50  * Check whether A2DP Sink is enabled.
51  */
52 bool btif_av_is_sink_enabled(void);
53 
54 /**
55  * Check whether A2DP Source is enabled.
56  */
57 bool btif_av_is_source_enabled(void);
58 
59 /**
60  * Start streaming.
61  * @param local_a2dp_type type of local a2dp profile.
62  */
63 void btif_av_stream_start(const A2dpType local_a2dp_type);
64 
65 /**
66  * Start streaming with latency setting.
67  */
68 void btif_av_stream_start_with_latency(bool use_latency_mode);
69 
70 /**
71  * Stop streaming.
72  *
73  * @param peer_address the peer address or RawAddress::kEmpty to stop all peers
74  */
75 void btif_av_stream_stop(const RawAddress& peer_address);
76 
77 /**
78  * Suspend streaming.
79  */
80 void btif_av_stream_suspend(void);
81 
82 /**
83  * Start offload streaming.
84  */
85 void btif_av_stream_start_offload(void);
86 
87 /**
88  * Check whether ready to start the A2DP stream.
89  * @param local_a2dp_type type of local a2dp profile.
90  */
91 bool btif_av_stream_ready(const A2dpType local_a2dp_type);
92 
93 /**
94  * Check whether the A2DP stream is in started state and ready
95  * for media start.
96  * @param local_a2dp_type type of local a2dp profile.
97  */
98 bool btif_av_stream_started_ready(const A2dpType local_a2dp_type);
99 
100 /**
101  * Check whether there is a connected peer (either Source or Sink)
102  * @param local_a2dp_type type of local a2dp profile.
103  */
104 bool btif_av_is_connected(const A2dpType local_a2dp_type);
105 
106 /**
107  * Get the Stream Endpoint Type of the Active peer.
108  * @param local_a2dp_type type of local a2dp profile.
109  *
110  * @return the stream endpoint type: either AVDT_TSEP_SRC or AVDT_TSEP_SNK
111  */
112 uint8_t btif_av_get_peer_sep(const A2dpType local_a2dp_type);
113 
114 /**
115  * Clear the remote suspended flag for the active peer.
116  * @param local_a2dp_type type of local a2dp profile.
117  */
118 void btif_av_clear_remote_suspend_flag(const A2dpType local_a2dp_type);
119 
120 /**
121  * Check whether the connected A2DP peer supports EDR.
122  *
123  * The value can be provided only if the remote peer is connected.
124  * Otherwise, the answer will be always false.
125  *
126  * @param peer_address the peer address
127  * @param local_a2dp_type type of local a2dp profile.
128  * @return true if the remote peer is capable of EDR
129  */
130 bool btif_av_is_peer_edr(const RawAddress& peer_address,
131                          const A2dpType local_a2dp_type);
132 
133 /**
134  * Check whether the connected A2DP peer supports 3 Mbps EDR.
135  *
136  * The value can be provided only if the remote peer is connected.
137  * Otherwise, the answer will be always false.
138  *
139  * @param peer_address the peer address
140  * @param local_a2dp_type type of local a2dp profile.
141  * @return true if the remote peer is capable of EDR and supports 3 Mbps
142  */
143 bool btif_av_peer_supports_3mbps(const RawAddress& peer_address,
144                                  const A2dpType local_a2dp_type);
145 
146 /**
147  * Check whether the mandatory codec is more preferred for this peer.
148  *
149  * @param peer_address the target peer address
150  * @param local_a2dp_type type of local a2dp profile.
151  * @return true if optional codecs are not preferred to be used
152  */
153 bool btif_av_peer_prefers_mandatory_codec(const RawAddress& peer_address,
154                                           const A2dpType local_a2dp_type);
155 
156 /**
157  * Report A2DP Source Codec State for a peer.
158  *
159  * @param peer_address the address of the peer to report
160  * @param codec_config the codec config to report
161  * @param codecs_local_capabilities the codecs local capabilities to report
162  * @param codecs_selectable_capabilities the codecs selectable capabilities
163  * to report
164  */
165 void btif_av_report_source_codec_state(
166     const RawAddress& peer_address,
167     const btav_a2dp_codec_config_t& codec_config,
168     const std::vector<btav_a2dp_codec_config_t>& codecs_local_capabilities,
169     const std::vector<btav_a2dp_codec_config_t>&
170         codecs_selectable_capabilities);
171 
172 /**
173  * Initialize / shut down the A2DP Source service.
174  *
175  * @param enable true to enable the A2DP Source service, false to disable it
176  * @return BT_STATUS_SUCCESS on success, BT_STATUS_FAIL otherwise
177  */
178 bt_status_t btif_av_source_execute_service(bool enable);
179 
180 /**
181  * Initialize / shut down the A2DP Sink service.
182  *
183  * @param enable true to enable the A2DP Sink service, false to disable it
184  * @return BT_STATUS_SUCCESS on success, BT_STATUS_FAIL otherwise
185  */
186 bt_status_t btif_av_sink_execute_service(bool enable);
187 
188 /**
189  * Peer ACL disconnected.
190  *
191  * @param peer_address the disconnected peer address
192  * @param local_a2dp_type type of local a2dp profile.
193  */
194 void btif_av_acl_disconnected(const RawAddress& peer_address,
195                               const A2dpType local_a2dp_type);
196 
197 /**
198  * Dump debug-related information for the BTIF AV module.
199  *
200  * @param fd the file descriptor to use for writing the ASCII formatted
201  * information
202  */
203 void btif_debug_av_dump(int fd);
204 
205 /**
206  * Set the audio delay for the stream.
207  *
208  * @param peer_address the address of the peer to report
209  * @param delay the delay to set in units of 1/10ms
210  * @param local_a2dp_type type of local a2dp profile.
211  */
212 void btif_av_set_audio_delay(const RawAddress& peer_address, uint16_t delay,
213                              const A2dpType local_a2dp_type);
214 
215 /**
216  * Get the audio delay for the stream.
217  * @param local_a2dp_type type of local a2dp profile.
218  */
219 uint16_t btif_av_get_audio_delay(const A2dpType local_a2dp_type);
220 
221 /**
222  * Reset the audio delay and count of audio bytes sent to zero.
223  */
224 void btif_av_reset_audio_delay(void);
225 
226 /**
227  * Called to disconnect peer device when
228  *  remote initiatied offload start failed
229  *
230  * @param peer_address to disconnect
231  *
232  */
233 void btif_av_src_disconnect_sink(const RawAddress& peer_address);
234 
235 /**
236  *  check A2DP offload support enabled
237  *  @param  none
238  */
239 bool btif_av_is_a2dp_offload_enabled(void);
240 
241 /**
242  *  check A2DP offload enabled and running
243  *  @param  none
244  */
245 bool btif_av_is_a2dp_offload_running(void);
246 
247 /**
248  * Check whether peer device is silenced
249  *
250  * @param peer_address to check
251  *
252  */
253 bool btif_av_is_peer_silenced(const RawAddress& peer_address);
254 
255 /**
256  * check the a2dp connect status
257  *
258  * @param peer_address : checked device address
259  * @param local_a2dp_type type of local a2dp profile.
260  *
261  */
262 bool btif_av_is_connected_addr(const RawAddress& peer_address,
263                                const A2dpType local_a2dp_type);
264 
265 /**
266  * Set the dynamic audio buffer size
267  *
268  * @param dynamic_audio_buffer_size to set
269  */
270 void btif_av_set_dynamic_audio_buffer_size(uint8_t dynamic_audio_buffer_size);
271 
272 /**
273  * Enable/disable the low latency
274  *
275  * @param is_low_latency to set
276  */
277 void btif_av_set_low_latency(bool is_low_latency);
278 
279 /**
280  * Initiate an AV connection after 3s timeout to peer audio sink
281  * @param handle bta handle
282  * @param peer_addr peer address
283  */
284 void btif_av_connect_sink_delayed(uint8_t handle,
285                                   const RawAddress& peer_address);
286 
287 /**
288  * Check whether A2DP Source is enabled.
289  */
290 extern bool btif_av_is_source_enabled(void);
291 extern bool btif_av_both_enable(void);
292 extern bool btif_av_src_sink_coexist_enabled(void);
293 extern bool btif_av_is_sink_enabled(void);
294 extern bool btif_av_is_connected_addr(const RawAddress& peer_address,
295                                       const A2dpType local_a2dp_type);
296 extern bool btif_av_peer_is_connected_sink(const RawAddress& peer_address);
297 extern bool btif_av_peer_is_connected_source(const RawAddress& peer_address);
298 extern bool btif_av_peer_is_sink(const RawAddress& peer_address);
299 extern bool btif_av_peer_is_source(const RawAddress& peer_address);
300 #endif /* BTIF_AV_H */
301