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