1 /******************************************************************************
2 *
3 * Copyright 2011-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 *
21 * This is the implementation of the API for the advanced audio/video (AV)
22 * subsystem of BTA, Broadcom's Bluetooth application layer for mobile
23 * phones.
24 *
25 ******************************************************************************/
26
27 #define LOG_TAG "bluetooth-a2dp"
28
29 #include "bta_av_api.h"
30
31 #include <bluetooth/log.h>
32
33 #include <cstddef>
34 #include <cstdint>
35 #include <cstring>
36
37 #include "avdt_api.h"
38 #include "avrc_defs.h"
39 #include "bta/av/bta_av_int.h"
40 #include "bta_api.h"
41 #include "bta_sys.h"
42 #include "btif/include/btif_av.h"
43 #include "internal_include/bt_target.h"
44 #include "osi/include/allocator.h"
45 #include "osi/include/compat.h"
46 #include "stack/include/bt_hdr.h"
47 #include "stack/include/bt_uuid16.h"
48 #include "types/raw_address.h"
49
50 using namespace bluetooth;
51
52 /*****************************************************************************
53 * Constants
54 ****************************************************************************/
55
56 static const tBTA_SYS_REG bta_av_reg = {bta_av_hdl_event, BTA_AvDisable};
57
58 /*******************************************************************************
59 *
60 * Function BTA_AvEnable
61 *
62 * Description Enable the advanced audio/video service. When the enable
63 * operation is complete the callback function will be
64 * called with a BTA_AV_ENABLE_EVT. This function must
65 * be called before other function in the AV API are
66 * called.
67 *
68 * Returns void
69 *
70 ******************************************************************************/
BTA_AvEnable(tBTA_AV_FEAT features,tBTA_AV_CBACK * p_cback)71 void BTA_AvEnable(tBTA_AV_FEAT features, tBTA_AV_CBACK* p_cback) {
72 tBTA_AV_API_ENABLE* p_buf = (tBTA_AV_API_ENABLE*)osi_malloc(sizeof(tBTA_AV_API_ENABLE));
73
74 /* register with BTA system manager */
75 bta_sys_register(BTA_ID_AV, &bta_av_reg);
76
77 p_buf->hdr.event = BTA_AV_API_ENABLE_EVT;
78 p_buf->p_cback = p_cback;
79 p_buf->features = features;
80
81 bta_sys_sendmsg(p_buf);
82 }
83
84 /*******************************************************************************
85 *
86 * Function BTA_AvDisable
87 *
88 * Description Disable the advanced audio/video service.
89 *
90 * Returns void
91 *
92 ******************************************************************************/
BTA_AvDisable(void)93 void BTA_AvDisable(void) {
94 BT_HDR_RIGID* p_buf = (BT_HDR_RIGID*)osi_malloc(sizeof(BT_HDR_RIGID));
95
96 bta_sys_deregister(BTA_ID_AV);
97 p_buf->event = BTA_AV_API_DISABLE_EVT;
98
99 bta_sys_sendmsg(p_buf);
100 }
101
102 /*******************************************************************************
103 *
104 * Function BTA_AvRegister
105 *
106 * Description Register the audio or video service to stack. When the
107 * operation is complete the callback function will be
108 * called with a BTA_AV_REGISTER_EVT. This function must
109 * be called before AVDT stream is open.
110 *
111 *
112 * Returns void
113 *
114 ******************************************************************************/
BTA_AvRegister(tBTA_AV_CHNL chnl,const char * p_service_name,uint8_t app_id,tBTA_AV_SINK_DATA_CBACK * p_sink_data_cback,uint16_t service_uuid)115 void BTA_AvRegister(tBTA_AV_CHNL chnl, const char* p_service_name, uint8_t app_id,
116 tBTA_AV_SINK_DATA_CBACK* p_sink_data_cback, uint16_t service_uuid) {
117 tBTA_AV_API_REG* p_buf = (tBTA_AV_API_REG*)osi_malloc(sizeof(tBTA_AV_API_REG));
118
119 p_buf->hdr.layer_specific = chnl;
120 p_buf->hdr.event = BTA_AV_API_REGISTER_EVT;
121 if (p_service_name) {
122 osi_strlcpy(p_buf->p_service_name, p_service_name, BTA_SERVICE_NAME_LEN);
123 } else {
124 p_buf->p_service_name[0] = 0;
125 }
126 p_buf->app_id = app_id;
127 p_buf->p_app_sink_data_cback = p_sink_data_cback;
128 p_buf->service_uuid = service_uuid;
129
130 bta_sys_sendmsg(p_buf);
131 }
132
133 /*******************************************************************************
134 *
135 * Function BTA_AvDeregister
136 *
137 * Description Deregister the audio or video service
138 *
139 * Returns void
140 *
141 ******************************************************************************/
BTA_AvDeregister(tBTA_AV_HNDL hndl)142 void BTA_AvDeregister(tBTA_AV_HNDL hndl) {
143 BT_HDR_RIGID* p_buf = (BT_HDR_RIGID*)osi_malloc(sizeof(BT_HDR_RIGID));
144
145 p_buf->layer_specific = hndl;
146 p_buf->event = BTA_AV_API_DEREGISTER_EVT;
147
148 bta_sys_sendmsg(p_buf);
149 }
150
151 /*******************************************************************************
152 *
153 * Function BTA_AvOpen
154 *
155 * Description Opens an advanced audio/video connection to a peer device.
156 * When connection is open callback function is called
157 * with a BTA_AV_OPEN_EVT.
158 *
159 * Returns void
160 *
161 ******************************************************************************/
BTA_AvOpen(const RawAddress & bd_addr,tBTA_AV_HNDL handle,bool use_rc,uint16_t uuid)162 void BTA_AvOpen(const RawAddress& bd_addr, tBTA_AV_HNDL handle, bool use_rc, uint16_t uuid) {
163 log::info("peer {} bta_handle:0x{:x} use_rc={} uuid=0x{:x}", bd_addr, handle, use_rc, uuid);
164
165 tBTA_AV_API_OPEN* p_buf = (tBTA_AV_API_OPEN*)osi_malloc(sizeof(tBTA_AV_API_OPEN));
166
167 p_buf->hdr.event = BTA_AV_API_OPEN_EVT;
168 p_buf->hdr.layer_specific = handle;
169 p_buf->bd_addr = bd_addr;
170 p_buf->use_rc = use_rc;
171 p_buf->switch_res = BTA_AV_RS_NONE;
172 p_buf->uuid = uuid;
173 if (btif_av_src_sink_coexist_enabled()) {
174 if (p_buf->uuid == AVDT_TSEP_SRC) {
175 p_buf->uuid = UUID_SERVCLASS_AUDIO_SOURCE;
176 p_buf->incoming = TRUE;
177 } else if (p_buf->uuid == AVDT_TSEP_SNK) {
178 p_buf->uuid = UUID_SERVCLASS_AUDIO_SINK;
179 p_buf->incoming = TRUE;
180 } else {
181 p_buf->incoming = FALSE;
182 }
183 }
184
185 bta_sys_sendmsg(p_buf);
186 }
187
188 /*******************************************************************************
189 *
190 * Function BTA_AvClose
191 *
192 * Description Close the current streams.
193 *
194 * Returns void
195 *
196 ******************************************************************************/
BTA_AvClose(tBTA_AV_HNDL handle)197 void BTA_AvClose(tBTA_AV_HNDL handle) {
198 log::info("bta_handle:0x{:x}", handle);
199
200 BT_HDR_RIGID* p_buf = (BT_HDR_RIGID*)osi_malloc(sizeof(BT_HDR_RIGID));
201
202 p_buf->event = BTA_AV_API_CLOSE_EVT;
203 p_buf->layer_specific = handle;
204
205 bta_sys_sendmsg(p_buf);
206 }
207
208 /*******************************************************************************
209 *
210 * Function BTA_AvDisconnect
211 *
212 * Description Close the connection to the address.
213 *
214 * Returns void
215 *
216 ******************************************************************************/
BTA_AvDisconnect(tBTA_AV_HNDL handle)217 void BTA_AvDisconnect(tBTA_AV_HNDL handle) {
218 log::info("bta_handle=0x{:x}", handle);
219
220 tBTA_AV_API_DISCNT* p_buf = (tBTA_AV_API_DISCNT*)osi_malloc(sizeof(tBTA_AV_API_DISCNT));
221
222 p_buf->hdr.event = BTA_AV_API_DISCONNECT_EVT;
223 p_buf->hdr.layer_specific = handle;
224
225 bta_sys_sendmsg(p_buf);
226 }
227
228 /*******************************************************************************
229 *
230 * Function BTA_AvStart
231 *
232 * Description Start audio/video stream data transfer.
233 *
234 * Returns void
235 *
236 ******************************************************************************/
BTA_AvStart(tBTA_AV_HNDL handle,bool use_latency_mode)237 void BTA_AvStart(tBTA_AV_HNDL handle, bool use_latency_mode) {
238 log::info("Starting audio/video stream data transfer bta_handle:{}, use_latency_mode:{}", handle,
239 use_latency_mode);
240
241 tBTA_AV_DO_START* p_buf = (tBTA_AV_DO_START*)osi_malloc(sizeof(tBTA_AV_DO_START));
242 p_buf->hdr.event = BTA_AV_AP_START_EVT;
243 p_buf->hdr.layer_specific = handle;
244 p_buf->use_latency_mode = use_latency_mode;
245
246 bta_sys_sendmsg(p_buf);
247 }
248
249 /*******************************************************************************
250 *
251 * Function BTA_AvOffloadStart
252 *
253 * Description Start a2dp audio offloading.
254 *
255 * Returns void
256 *
257 ******************************************************************************/
BTA_AvOffloadStart(tBTA_AV_HNDL hndl)258 void BTA_AvOffloadStart(tBTA_AV_HNDL hndl) {
259 log::info("bta_handle=0x{:x}", hndl);
260
261 BT_HDR_RIGID* p_buf = (BT_HDR_RIGID*)osi_malloc(sizeof(BT_HDR_RIGID));
262
263 p_buf->event = BTA_AV_API_OFFLOAD_START_EVT;
264 p_buf->layer_specific = hndl;
265
266 bta_sys_sendmsg(p_buf);
267 }
268
269 /*******************************************************************************
270 *
271 * Function BTA_AvStop
272 *
273 * Description Stop audio/video stream data transfer.
274 * If suspend is true, this function sends AVDT suspend signal
275 * to the connected peer(s).
276 *
277 * Returns void
278 *
279 ******************************************************************************/
BTA_AvStop(tBTA_AV_HNDL handle,bool suspend)280 void BTA_AvStop(tBTA_AV_HNDL handle, bool suspend) {
281 log::info("bta_handle=0x{:x} suspend={}", handle, suspend);
282
283 tBTA_AV_API_STOP* p_buf = (tBTA_AV_API_STOP*)osi_malloc(sizeof(tBTA_AV_API_STOP));
284
285 p_buf->hdr.event = BTA_AV_AP_STOP_EVT;
286 p_buf->hdr.layer_specific = handle;
287 p_buf->flush = true;
288 p_buf->suspend = suspend;
289 p_buf->reconfig_stop = false;
290
291 bta_sys_sendmsg(p_buf);
292 }
293
294 /*******************************************************************************
295 *
296 * Function BTA_AvReconfig
297 *
298 * Description Reconfigure the audio/video stream.
299 * If suspend is true, this function tries the
300 * suspend/reconfigure procedure first.
301 * If suspend is false or when suspend/reconfigure fails,
302 * this function closes and re-opens the AVDT connection.
303 *
304 * Returns void
305 *
306 ******************************************************************************/
BTA_AvReconfig(tBTA_AV_HNDL hndl,bool suspend,uint8_t sep_info_idx,uint8_t * p_codec_info,uint8_t num_protect,const uint8_t * p_protect_info)307 void BTA_AvReconfig(tBTA_AV_HNDL hndl, bool suspend, uint8_t sep_info_idx, uint8_t* p_codec_info,
308 uint8_t num_protect, const uint8_t* p_protect_info) {
309 log::info("bta_handle=0x{:x} suspend={} sep_info_idx={}", hndl, suspend, sep_info_idx);
310
311 tBTA_AV_API_RCFG* p_buf = (tBTA_AV_API_RCFG*)osi_malloc(sizeof(tBTA_AV_API_RCFG) + num_protect);
312
313 p_buf->hdr.layer_specific = hndl;
314 p_buf->hdr.event = BTA_AV_API_RECONFIG_EVT;
315 p_buf->num_protect = num_protect;
316 p_buf->suspend = suspend;
317 p_buf->sep_info_idx = sep_info_idx;
318 p_buf->p_protect_info = (uint8_t*)(p_buf + 1);
319 memcpy(p_buf->codec_info, p_codec_info, AVDT_CODEC_SIZE);
320 memcpy(p_buf->p_protect_info, p_protect_info, num_protect);
321
322 bta_sys_sendmsg(p_buf);
323 }
324
325 /*******************************************************************************
326 *
327 * Function BTA_AvProtectReq
328 *
329 * Description Send a content protection request. This function can only
330 * be used if AV is enabled with feature BTA_AV_FEAT_PROTECT.
331 *
332 * Returns void
333 *
334 ******************************************************************************/
BTA_AvProtectReq(tBTA_AV_HNDL hndl,uint8_t * p_data,uint16_t len)335 void BTA_AvProtectReq(tBTA_AV_HNDL hndl, uint8_t* p_data, uint16_t len) {
336 tBTA_AV_API_PROTECT_REQ* p_buf =
337 (tBTA_AV_API_PROTECT_REQ*)osi_malloc(sizeof(tBTA_AV_API_PROTECT_REQ) + len);
338
339 p_buf->hdr.layer_specific = hndl;
340 p_buf->hdr.event = BTA_AV_API_PROTECT_REQ_EVT;
341 p_buf->len = len;
342 if (p_data == NULL) {
343 p_buf->p_data = NULL;
344 } else {
345 p_buf->p_data = (uint8_t*)(p_buf + 1);
346 memcpy(p_buf->p_data, p_data, len);
347 }
348
349 bta_sys_sendmsg(p_buf);
350 }
351
352 /*******************************************************************************
353 *
354 * Function BTA_AvProtectRsp
355 *
356 * Description Send a content protection response. This function must
357 * be called if a BTA_AV_PROTECT_REQ_EVT is received.
358 * This function can only be used if AV is enabled with
359 * feature BTA_AV_FEAT_PROTECT.
360 *
361 * Returns void
362 *
363 ******************************************************************************/
BTA_AvProtectRsp(tBTA_AV_HNDL hndl,uint8_t error_code,uint8_t * p_data,uint16_t len)364 void BTA_AvProtectRsp(tBTA_AV_HNDL hndl, uint8_t error_code, uint8_t* p_data, uint16_t len) {
365 tBTA_AV_API_PROTECT_RSP* p_buf =
366 (tBTA_AV_API_PROTECT_RSP*)osi_malloc(sizeof(tBTA_AV_API_PROTECT_RSP) + len);
367
368 p_buf->hdr.layer_specific = hndl;
369 p_buf->hdr.event = BTA_AV_API_PROTECT_RSP_EVT;
370 p_buf->len = len;
371 p_buf->error_code = error_code;
372 if (p_data == NULL) {
373 p_buf->p_data = NULL;
374 } else {
375 p_buf->p_data = (uint8_t*)(p_buf + 1);
376 memcpy(p_buf->p_data, p_data, len);
377 }
378
379 bta_sys_sendmsg(p_buf);
380 }
381
382 /*******************************************************************************
383 *
384 * Function BTA_AvRemoteCmd
385 *
386 * Description Send a remote control command. This function can only
387 * be used if AV is enabled with feature BTA_AV_FEAT_RCCT.
388 *
389 * Returns void
390 *
391 ******************************************************************************/
BTA_AvRemoteCmd(uint8_t rc_handle,uint8_t label,tBTA_AV_RC rc_id,tBTA_AV_STATE key_state)392 void BTA_AvRemoteCmd(uint8_t rc_handle, uint8_t label, tBTA_AV_RC rc_id, tBTA_AV_STATE key_state) {
393 tBTA_AV_API_REMOTE_CMD* p_buf =
394 (tBTA_AV_API_REMOTE_CMD*)osi_malloc(sizeof(tBTA_AV_API_REMOTE_CMD));
395
396 p_buf->hdr.event = BTA_AV_API_REMOTE_CMD_EVT;
397 p_buf->hdr.layer_specific = rc_handle;
398 p_buf->msg.op_id = rc_id;
399 p_buf->msg.state = key_state;
400 p_buf->msg.p_pass_data = NULL;
401 p_buf->msg.pass_len = 0;
402 p_buf->label = label;
403
404 bta_sys_sendmsg(p_buf);
405 }
406
407 /*******************************************************************************
408 *
409 * Function BTA_AvRemoteVendorUniqueCmd
410 *
411 * Description Send a remote control command with Vendor Unique rc_id.
412 * This function can only be used if AV is enabled with
413 * feature BTA_AV_FEAT_RCCT.
414 *
415 * Returns void
416 *
417 ******************************************************************************/
BTA_AvRemoteVendorUniqueCmd(uint8_t rc_handle,uint8_t label,tBTA_AV_STATE key_state,uint8_t * p_msg,uint8_t buf_len)418 void BTA_AvRemoteVendorUniqueCmd(uint8_t rc_handle, uint8_t label, tBTA_AV_STATE key_state,
419 uint8_t* p_msg, uint8_t buf_len) {
420 tBTA_AV_API_REMOTE_CMD* p_buf =
421 (tBTA_AV_API_REMOTE_CMD*)osi_malloc(sizeof(tBTA_AV_API_REMOTE_CMD) + buf_len);
422
423 p_buf->label = label;
424 p_buf->hdr.event = BTA_AV_API_REMOTE_CMD_EVT;
425 p_buf->hdr.layer_specific = rc_handle;
426 p_buf->msg.op_id = AVRC_ID_VENDOR;
427 p_buf->msg.state = key_state;
428 p_buf->msg.pass_len = buf_len;
429 if (p_msg == NULL) {
430 p_buf->msg.p_pass_data = NULL;
431 } else {
432 p_buf->msg.p_pass_data = (uint8_t*)(p_buf + 1);
433 memcpy(p_buf->msg.p_pass_data, p_msg, buf_len);
434 }
435 bta_sys_sendmsg(p_buf);
436 }
437
438 /*******************************************************************************
439 *
440 * Function BTA_AvVendorCmd
441 *
442 * Description Send a vendor dependent remote control command. This
443 * function can only be used if AV is enabled with feature
444 * BTA_AV_FEAT_VENDOR.
445 *
446 * Returns void
447 *
448 ******************************************************************************/
BTA_AvVendorCmd(uint8_t rc_handle,uint8_t label,tBTA_AV_CODE cmd_code,uint8_t * p_data,uint16_t len)449 void BTA_AvVendorCmd(uint8_t rc_handle, uint8_t label, tBTA_AV_CODE cmd_code, uint8_t* p_data,
450 uint16_t len) {
451 tBTA_AV_API_VENDOR* p_buf = (tBTA_AV_API_VENDOR*)osi_malloc(sizeof(tBTA_AV_API_VENDOR) + len);
452
453 p_buf->hdr.event = BTA_AV_API_VENDOR_CMD_EVT;
454 p_buf->hdr.layer_specific = rc_handle;
455 p_buf->msg.hdr.ctype = cmd_code;
456 p_buf->msg.hdr.subunit_type = AVRC_SUB_PANEL;
457 p_buf->msg.hdr.subunit_id = 0;
458 p_buf->msg.company_id = p_bta_av_cfg->company_id;
459 p_buf->label = label;
460 p_buf->msg.vendor_len = len;
461 if (p_data == NULL) {
462 p_buf->msg.p_vendor_data = NULL;
463 } else {
464 p_buf->msg.p_vendor_data = (uint8_t*)(p_buf + 1);
465 memcpy(p_buf->msg.p_vendor_data, p_data, len);
466 }
467
468 bta_sys_sendmsg(p_buf);
469 }
470
471 /*******************************************************************************
472 *
473 * Function BTA_AvVendorRsp
474 *
475 * Description Send a vendor dependent remote control response.
476 * This function must be called if a BTA_AV_VENDOR_CMD_EVT
477 * is received. This function can only be used if AV is
478 * enabled with feature BTA_AV_FEAT_VENDOR.
479 *
480 * Returns void
481 *
482 ******************************************************************************/
BTA_AvVendorRsp(uint8_t rc_handle,uint8_t label,tBTA_AV_CODE rsp_code,uint8_t * p_data,uint16_t len,uint32_t company_id)483 void BTA_AvVendorRsp(uint8_t rc_handle, uint8_t label, tBTA_AV_CODE rsp_code, uint8_t* p_data,
484 uint16_t len, uint32_t company_id) {
485 tBTA_AV_API_VENDOR* p_buf = (tBTA_AV_API_VENDOR*)osi_malloc(sizeof(tBTA_AV_API_VENDOR) + len);
486
487 p_buf->hdr.event = BTA_AV_API_VENDOR_RSP_EVT;
488 p_buf->hdr.layer_specific = rc_handle;
489 p_buf->msg.hdr.ctype = rsp_code;
490 p_buf->msg.hdr.subunit_type = AVRC_SUB_PANEL;
491 p_buf->msg.hdr.subunit_id = 0;
492 if (company_id) {
493 p_buf->msg.company_id = company_id;
494 } else {
495 p_buf->msg.company_id = p_bta_av_cfg->company_id;
496 }
497 p_buf->label = label;
498 p_buf->msg.vendor_len = len;
499 if (p_data == NULL) {
500 p_buf->msg.p_vendor_data = NULL;
501 } else {
502 p_buf->msg.p_vendor_data = (uint8_t*)(p_buf + 1);
503 memcpy(p_buf->msg.p_vendor_data, p_data, len);
504 }
505
506 bta_sys_sendmsg(p_buf);
507 }
508
509 /*******************************************************************************
510 *
511 * Function BTA_AvOpenRc
512 *
513 * Description Open an AVRCP connection toward the device with the
514 * specified handle
515 *
516 * Returns void
517 *
518 ******************************************************************************/
BTA_AvOpenRc(tBTA_AV_HNDL handle)519 void BTA_AvOpenRc(tBTA_AV_HNDL handle) {
520 tBTA_AV_API_OPEN_RC* p_buf = (tBTA_AV_API_OPEN_RC*)osi_malloc(sizeof(tBTA_AV_API_OPEN_RC));
521
522 p_buf->hdr.event = BTA_AV_API_RC_OPEN_EVT;
523 p_buf->hdr.layer_specific = handle;
524
525 bta_sys_sendmsg(p_buf);
526 }
527
528 /*******************************************************************************
529 *
530 * Function BTA_AvCloseRc
531 *
532 * Description Close an AVRCP connection
533 *
534 * Returns void
535 *
536 ******************************************************************************/
BTA_AvCloseRc(uint8_t rc_handle)537 void BTA_AvCloseRc(uint8_t rc_handle) {
538 tBTA_AV_API_CLOSE_RC* p_buf = (tBTA_AV_API_CLOSE_RC*)osi_malloc(sizeof(tBTA_AV_API_CLOSE_RC));
539
540 p_buf->hdr.event = BTA_AV_API_RC_CLOSE_EVT;
541 p_buf->hdr.layer_specific = rc_handle;
542
543 bta_sys_sendmsg(p_buf);
544 }
545
546 /*******************************************************************************
547 *
548 * Function BTA_AvMetaRsp
549 *
550 * Description Send a Metadata/Advanced Control response. The message
551 * contained in p_pkt can be composed with AVRC utility
552 * functions.
553 * This function can only be used if AV is enabled with feature
554 * BTA_AV_FEAT_METADATA.
555 *
556 * Returns void
557 *
558 ******************************************************************************/
BTA_AvMetaRsp(uint8_t rc_handle,uint8_t label,tBTA_AV_CODE rsp_code,BT_HDR * p_pkt)559 void BTA_AvMetaRsp(uint8_t rc_handle, uint8_t label, tBTA_AV_CODE rsp_code, BT_HDR* p_pkt) {
560 tBTA_AV_API_META_RSP* p_buf = (tBTA_AV_API_META_RSP*)osi_malloc(sizeof(tBTA_AV_API_META_RSP));
561
562 p_buf->hdr.event = BTA_AV_API_META_RSP_EVT;
563 p_buf->hdr.layer_specific = rc_handle;
564 p_buf->rsp_code = rsp_code;
565 p_buf->p_pkt = p_pkt;
566 p_buf->is_rsp = true;
567 p_buf->label = label;
568
569 bta_sys_sendmsg(p_buf);
570 }
571
572 /*******************************************************************************
573 *
574 * Function BTA_AvMetaCmd
575 *
576 * Description Send a Metadata/Advanced Control command. The message
577 *contained
578 * in p_pkt can be composed with AVRC utility functions.
579 * This function can only be used if AV is enabled with feature
580 * BTA_AV_FEAT_METADATA.
581 * This message is sent only when the peer supports the TG
582 *role.
583 *8 The only command makes sense right now is the absolute
584 *volume command.
585 *
586 * Returns void
587 *
588 ******************************************************************************/
BTA_AvMetaCmd(uint8_t rc_handle,uint8_t label,tBTA_AV_CMD cmd_code,BT_HDR * p_pkt)589 void BTA_AvMetaCmd(uint8_t rc_handle, uint8_t label, tBTA_AV_CMD cmd_code, BT_HDR* p_pkt) {
590 tBTA_AV_API_META_RSP* p_buf = (tBTA_AV_API_META_RSP*)osi_malloc(sizeof(tBTA_AV_API_META_RSP));
591
592 p_buf->hdr.event = BTA_AV_API_META_RSP_EVT;
593 p_buf->hdr.layer_specific = rc_handle;
594 p_buf->p_pkt = p_pkt;
595 p_buf->rsp_code = cmd_code;
596 p_buf->is_rsp = false;
597 p_buf->label = label;
598
599 bta_sys_sendmsg(p_buf);
600 }
601
602 /*******************************************************************************
603 *
604 * Function BTA_AvSetLatency
605 *
606 * Description Set audio/video stream latency.
607 *
608 * Returns void
609 *
610 ******************************************************************************/
BTA_AvSetLatency(tBTA_AV_HNDL handle,bool is_low_latency)611 void BTA_AvSetLatency(tBTA_AV_HNDL handle, bool is_low_latency) {
612 log::info("Set audio/video stream low latency bta_handle:{}, is_low_latency:{}", handle,
613 is_low_latency);
614
615 tBTA_AV_API_SET_LATENCY* p_buf =
616 (tBTA_AV_API_SET_LATENCY*)osi_malloc(sizeof(tBTA_AV_API_SET_LATENCY));
617 p_buf->hdr.event = BTA_AV_API_SET_LATENCY_EVT;
618 p_buf->hdr.layer_specific = handle;
619 p_buf->is_low_latency = is_low_latency;
620
621 bta_sys_sendmsg(p_buf);
622 }
623
624 /*******************************************************************************
625 *
626 * Function BTA_AvSetPeerSep
627 *
628 * Description Set peer sep in order to delete wrong avrcp handle
629 * there are may be two avrcp handle at start, delete the
630 * wrong when a2dp connected
631 *
632 * Returns void
633 *
634 ******************************************************************************/
BTA_AvSetPeerSep(const RawAddress & bdaddr,uint8_t sep)635 void BTA_AvSetPeerSep(const RawAddress& bdaddr, uint8_t sep) {
636 tBTA_AV_API_PEER_SEP* p_buf = (tBTA_AV_API_PEER_SEP*)osi_malloc(sizeof(tBTA_AV_API_PEER_SEP));
637
638 p_buf->hdr.event = BTA_AV_API_PEER_SEP_EVT;
639 p_buf->addr = bdaddr;
640 p_buf->sep = sep;
641
642 bta_sys_sendmsg(p_buf);
643 }
644