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