1 /******************************************************************************
3 * Copyright (C) 2004-2012 Broadcom Corporation
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:
9 * http://www.apache.org/licenses/LICENSE-2.0
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.
17 ******************************************************************************/
19 /******************************************************************************
21 * This file contains action functions for advanced audio/video main state
24 ******************************************************************************/
26 #include "bt_target.h"
27 #if defined(BTA_AV_INCLUDED) && (BTA_AV_INCLUDED == TRUE)
30 #include "bta_av_api.h"
31 #include "bta_av_int.h"
35 #include "allocator.h"
37 #if( defined BTA_AR_INCLUDED ) && (BTA_AR_INCLUDED == TRUE)
38 #include "bta_ar_api.h"
41 #define LOG_TAG "bt_bta_av"
42 // #include "osi/include/log.h"
45 /*****************************************************************************
47 *****************************************************************************/
48 /* the timer in milliseconds to wait for open req after setconfig for incoming connections */
49 #ifndef BTA_AV_SIG_TIME_VAL
50 #define BTA_AV_SIG_TIME_VAL 8000
53 /* In millisec to wait for signalling from SNK when it is initiated from SNK. */
54 /* If not, we will start signalling from SRC. */
55 #ifndef BTA_AV_ACP_SIG_TIME_VAL
56 #define BTA_AV_ACP_SIG_TIME_VAL 2000
59 static void bta_av_acp_sig_timer_cback (TIMER_LIST_ENT *p_tle);
61 /*******************************************************************************
63 ** Function bta_av_get_rcb_by_shdl
65 ** Description find the RCB associated with the given SCB handle.
67 ** Returns tBTA_AV_RCB
69 *******************************************************************************/
70 tBTA_AV_RCB *bta_av_get_rcb_by_shdl(UINT8 shdl)
72 tBTA_AV_RCB *p_rcb = NULL;
75 for (i = 0; i < BTA_AV_NUM_RCB; i++) {
76 if (bta_av_cb.rcb[i].shdl == shdl && bta_av_cb.rcb[i].handle != BTA_AV_RC_HANDLE_NONE) {
77 p_rcb = &bta_av_cb.rcb[i];
83 #define BTA_AV_STS_NO_RSP 0xFF /* a number not used by tAVRC_STS */
85 /*******************************************************************************
87 ** Function bta_av_del_rc
89 ** Description delete the given AVRC handle.
93 *******************************************************************************/
94 void bta_av_del_rc(tBTA_AV_RCB *p_rcb)
97 UINT8 rc_handle; /* connected AVRCP handle */
100 if (p_rcb->handle != BTA_AV_RC_HANDLE_NONE) {
102 /* Validate array index*/
103 if ((p_rcb->shdl - 1) < BTA_AV_NUM_STRS) {
104 p_scb = bta_av_cb.p_scb[p_rcb->shdl - 1];
107 APPL_TRACE_DEBUG("bta_av_del_rc shdl:%d, srch:%d rc_handle:%d", p_rcb->shdl,
108 p_scb->rc_handle, p_rcb->handle);
109 if (p_scb->rc_handle == p_rcb->handle) {
110 p_scb->rc_handle = BTA_AV_RC_HANDLE_NONE;
112 /* just in case the RC timer is active
113 if(bta_av_cb.features & BTA_AV_FEAT_RCCT && p_scb->chnl == BTA_AV_CHNL_AUDIO) */
114 bta_sys_stop_timer(&p_scb->timer);
118 APPL_TRACE_EVENT("bta_av_del_rc handle: %d status=0x%x, rc_acp_handle:%d, idx:%d",
119 p_rcb->handle, p_rcb->status, bta_av_cb.rc_acp_handle, bta_av_cb.rc_acp_idx);
120 rc_handle = p_rcb->handle;
121 if (!(p_rcb->status & BTA_AV_RC_CONN_MASK) ||
122 ((p_rcb->status & BTA_AV_RC_ROLE_MASK) == BTA_AV_RC_ROLE_INT) ) {
124 p_rcb->handle = BTA_AV_RC_HANDLE_NONE;
128 /* else ACP && connected. do not clear the handle yet */
129 AVRC_Close(rc_handle);
130 if (rc_handle == bta_av_cb.rc_acp_handle) {
131 bta_av_cb.rc_acp_handle = BTA_AV_RC_HANDLE_NONE;
133 APPL_TRACE_EVENT("end del_rc handle: %d status=0x%x, rc_acp_handle:%d, lidx:%d",
134 p_rcb->handle, p_rcb->status, bta_av_cb.rc_acp_handle, p_rcb->lidx);
139 /*******************************************************************************
141 ** Function bta_av_close_all_rc
143 ** Description close the all AVRC handle.
147 *******************************************************************************/
148 static void bta_av_close_all_rc(tBTA_AV_CB *p_cb)
152 for (i = 0; i < BTA_AV_NUM_RCB; i++) {
153 if ((p_cb->disabling == TRUE) || (bta_av_cb.rcb[i].shdl != 0)) {
154 bta_av_del_rc(&bta_av_cb.rcb[i]);
159 /*******************************************************************************
161 ** Function bta_av_del_sdp_rec
163 ** Description delete the given SDP record handle.
167 *******************************************************************************/
168 static void bta_av_del_sdp_rec(UINT32 *p_sdp_handle)
170 if (*p_sdp_handle != 0) {
171 SDP_DeleteRecord(*p_sdp_handle);
176 /*******************************************************************************
178 ** Function bta_av_avrc_sdp_cback
180 ** Description AVRCP service discovery callback.
184 *******************************************************************************/
185 static void bta_av_avrc_sdp_cback(UINT16 status)
190 if ((p_msg = (BT_HDR *) osi_malloc(sizeof(BT_HDR))) != NULL) {
191 p_msg->event = BTA_AV_SDP_AVRC_DISC_EVT;
192 bta_sys_sendmsg(p_msg);
196 /*******************************************************************************
198 ** Function bta_av_rc_ctrl_cback
200 ** Description AVRCP control callback.
204 *******************************************************************************/
205 static void bta_av_rc_ctrl_cback(UINT8 handle, UINT8 event, UINT16 result, BD_ADDR peer_addr)
207 tBTA_AV_RC_CONN_CHG *p_msg;
208 UINT16 msg_event = 0;
211 #if (defined(BTA_AV_MIN_DEBUG_TRACES) && BTA_AV_MIN_DEBUG_TRACES == TRUE)
212 APPL_TRACE_EVENT("rc_ctrl handle: %d event=0x%x", handle, event);
214 APPL_TRACE_EVENT("bta_av_rc_ctrl_cback handle: %d event=0x%x", handle, event);
216 if (event == AVRC_OPEN_IND_EVT) {
217 /* save handle of opened connection
218 bta_av_cb.rc_handle = handle;*/
220 msg_event = BTA_AV_AVRC_OPEN_EVT;
221 } else if (event == AVRC_CLOSE_IND_EVT) {
222 msg_event = BTA_AV_AVRC_CLOSE_EVT;
226 if ((p_msg = (tBTA_AV_RC_CONN_CHG *) osi_malloc(sizeof(tBTA_AV_RC_CONN_CHG))) != NULL) {
227 p_msg->hdr.event = msg_event;
228 p_msg->handle = handle;
230 bdcpy(p_msg->peer_addr, peer_addr);
232 bta_sys_sendmsg(p_msg);
237 /*******************************************************************************
239 ** Function bta_av_rc_msg_cback
241 ** Description AVRCP message callback.
245 *******************************************************************************/
246 static void bta_av_rc_msg_cback(UINT8 handle, UINT8 label, UINT8 opcode, tAVRC_MSG *p_msg)
248 UINT8 *p_data_src = NULL;
251 APPL_TRACE_DEBUG("%s handle: %u opcode=0x%x", __func__, handle, opcode);
253 /* Determine the size of the buffer we need */
254 if (opcode == AVRC_OP_VENDOR && p_msg->vendor.p_vendor_data != NULL) {
255 p_data_src = p_msg->vendor.p_vendor_data;
256 data_len = (UINT16) p_msg->vendor.vendor_len;
257 } else if (opcode == AVRC_OP_PASS_THRU && p_msg->pass.p_pass_data != NULL) {
258 p_data_src = p_msg->pass.p_pass_data;
259 data_len = (UINT16) p_msg->pass.pass_len;
262 /* Create a copy of the message */
263 tBTA_AV_RC_MSG *p_buf =
264 (tBTA_AV_RC_MSG *)osi_malloc((UINT16)(sizeof(tBTA_AV_RC_MSG) + data_len));
266 p_buf->hdr.event = BTA_AV_AVRC_MSG_EVT;
267 p_buf->handle = handle;
268 p_buf->label = label;
269 p_buf->opcode = opcode;
270 memcpy(&p_buf->msg, p_msg, sizeof(tAVRC_MSG));
271 /* Copy the data payload, and set the pointer to it */
272 if (p_data_src != NULL) {
273 UINT8 *p_data_dst = (UINT8 *)(p_buf + 1);
274 memcpy(p_data_dst, p_data_src, data_len);
275 if (opcode == AVRC_OP_VENDOR) {
276 p_buf->msg.vendor.p_vendor_data = p_data_dst;
277 } else if (opcode == AVRC_OP_PASS_THRU) {
278 p_buf->msg.pass.p_pass_data = p_data_dst;
281 bta_sys_sendmsg(p_buf);
285 /*******************************************************************************
287 ** Function bta_av_rc_create
289 ** Description alloc RCB and call AVRC_Open
291 ** Returns the created rc handle
293 *******************************************************************************/
294 UINT8 bta_av_rc_create(tBTA_AV_CB *p_cb, UINT8 role, UINT8 shdl, UINT8 lidx)
297 BD_ADDR_PTR bda = (BD_ADDR_PTR)bd_addr_any;
298 UINT8 status = BTA_AV_RC_ROLE_ACP;
299 tBTA_AV_SCB *p_scb = p_cb->p_scb[shdl - 1];
304 if (role == AVCT_INT) {
305 bda = p_scb->peer_addr;
306 status = BTA_AV_RC_ROLE_INT;
308 if ((p_rcb = bta_av_get_rcb_by_shdl(shdl)) != NULL ) {
309 APPL_TRACE_ERROR("bta_av_rc_create ACP handle exist for shdl:%d", shdl);
310 return p_rcb->handle;
314 ccb.p_ctrl_cback = bta_av_rc_ctrl_cback;
315 ccb.p_msg_cback = bta_av_rc_msg_cback;
316 ccb.company_id = p_bta_av_cfg->company_id;
318 /* note: BTA_AV_FEAT_RCTG = AVRC_CT_TARGET, BTA_AV_FEAT_RCCT = AVRC_CT_CONTROL */
319 ccb.control = p_cb->features & (BTA_AV_FEAT_RCTG | BTA_AV_FEAT_RCCT | AVRC_CT_PASSIVE);
322 if (AVRC_Open(&rc_handle, &ccb, bda) != AVRC_SUCCESS) {
323 return BTA_AV_RC_HANDLE_NONE;
327 p_rcb = &p_cb->rcb[i];
329 if (p_rcb->handle != BTA_AV_RC_HANDLE_NONE) {
330 APPL_TRACE_ERROR("bta_av_rc_create found duplicated handle:%d", rc_handle);
333 p_rcb->handle = rc_handle;
334 p_rcb->status = status;
337 p_rcb->peer_features = 0;
338 if (lidx == (BTA_AV_NUM_LINKS + 1)) {
339 /* this LIDX is reserved for the AVRCP ACP connection */
340 p_cb->rc_acp_handle = p_rcb->handle;
341 p_cb->rc_acp_idx = (i + 1);
342 APPL_TRACE_DEBUG("rc_acp_handle:%d idx:%d", p_cb->rc_acp_handle, p_cb->rc_acp_idx);
344 APPL_TRACE_DEBUG("create %d, role: %d, shdl:%d, rc_handle:%d, lidx:%d, status:0x%x",
345 i, role, shdl, p_rcb->handle, lidx, p_rcb->status);
350 /*******************************************************************************
352 ** Function bta_av_valid_group_navi_msg
354 ** Description Check if it is Group Navigation Msg for Metadata
356 ** Returns BTA_AV_RSP_ACCEPT or BTA_AV_RSP_NOT_IMPL.
358 *******************************************************************************/
359 static tBTA_AV_CODE bta_av_group_navi_supported(UINT8 len, UINT8 *p_data, BOOLEAN is_inquiry)
361 tBTA_AV_CODE ret = BTA_AV_RSP_NOT_IMPL;
362 UINT8 *p_ptr = p_data;
366 if (p_bta_av_cfg->avrc_group && len == BTA_GROUP_NAVI_MSG_OP_DATA_LEN) {
367 BTA_AV_BE_STREAM_TO_CO_ID(u32, p_ptr);
368 BE_STREAM_TO_UINT16(u16, p_ptr);
370 if (u32 == AVRC_CO_METADATA) {
372 if (u16 <= AVRC_PDU_PREV_GROUP) {
373 ret = BTA_AV_RSP_IMPL_STBL;
376 if (u16 <= AVRC_PDU_PREV_GROUP) {
377 ret = BTA_AV_RSP_ACCEPT;
379 ret = BTA_AV_RSP_REJ;
388 /*******************************************************************************
390 ** Function bta_av_op_supported
392 ** Description Check if remote control operation is supported.
394 ** Returns BTA_AV_RSP_ACCEPT of supported, BTA_AV_RSP_NOT_IMPL if not.
396 *******************************************************************************/
397 static tBTA_AV_CODE bta_av_op_supported(tBTA_AV_RC rc_id, BOOLEAN is_inquiry)
399 tBTA_AV_CODE ret_code = BTA_AV_RSP_NOT_IMPL;
401 if (p_bta_av_rc_id) {
403 if (p_bta_av_rc_id[rc_id >> 4] & (1 << (rc_id & 0x0F))) {
404 ret_code = BTA_AV_RSP_IMPL_STBL;
407 if (p_bta_av_rc_id[rc_id >> 4] & (1 << (rc_id & 0x0F))) {
408 ret_code = BTA_AV_RSP_ACCEPT;
409 } else if ((p_bta_av_cfg->rc_pass_rsp == BTA_AV_RSP_INTERIM) && p_bta_av_rc_id_ac) {
410 if (p_bta_av_rc_id_ac[rc_id >> 4] & (1 << (rc_id & 0x0F))) {
411 ret_code = BTA_AV_RSP_INTERIM;
420 /*******************************************************************************
422 ** Function bta_av_find_lcb
424 ** Description Given BD_addr, find the associated LCB.
426 ** Returns NULL, if not found.
428 *******************************************************************************/
429 tBTA_AV_LCB *bta_av_find_lcb(BD_ADDR addr, UINT8 op)
431 tBTA_AV_CB *p_cb = &bta_av_cb;
434 tBTA_AV_LCB *p_lcb = NULL;
436 for (xx = 0; xx < BTA_AV_NUM_LINKS; xx++) {
437 mask = 1 << xx; /* the used mask for this lcb */
438 if ((mask & p_cb->conn_lcb) && 0 == ( bdcmp(p_cb->lcb[xx].addr, addr))) {
439 p_lcb = &p_cb->lcb[xx];
440 if (op == BTA_AV_LCB_FREE) {
441 p_cb->conn_lcb &= ~mask; /* clear the connect mask */
442 APPL_TRACE_DEBUG("conn_lcb: 0x%x", p_cb->conn_lcb);
450 /*******************************************************************************
452 ** Function bta_av_rc_opened
454 ** Description Set AVRCP state to opened.
458 *******************************************************************************/
459 void bta_av_rc_opened(tBTA_AV_CB *p_cb, tBTA_AV_DATA *p_data)
461 tBTA_AV_RC_OPEN rc_open;
470 /* find the SCB & stop the timer */
471 for (i = 0; i < BTA_AV_NUM_STRS; i++) {
472 p_scb = p_cb->p_scb[i];
473 if (p_scb && bdcmp(p_scb->peer_addr, p_data->rc_conn_chg.peer_addr) == 0) {
474 p_scb->rc_handle = p_data->rc_conn_chg.handle;
475 APPL_TRACE_DEBUG("bta_av_rc_opened shdl:%d, srch %d", i + 1, p_scb->rc_handle);
477 LOG_INFO("%s allow incoming AVRCP connections:%d", __func__, p_scb->use_rc);
478 bta_sys_stop_timer(&p_scb->timer);
484 i = p_data->rc_conn_chg.handle;
485 if (p_cb->rcb[i].handle == BTA_AV_RC_HANDLE_NONE) {
486 APPL_TRACE_ERROR("not a valid handle:%d any more", i);
491 if (p_cb->rcb[i].lidx == (BTA_AV_NUM_LINKS + 1) && shdl != 0) {
492 /* rc is opened on the RC only ACP channel, but is for a specific
493 * SCB -> need to switch RCBs */
494 p_rcb = bta_av_get_rcb_by_shdl(shdl);
496 p_rcb->shdl = p_cb->rcb[i].shdl;
498 p_rcb->lidx = p_cb->rcb[i].lidx;
499 p_cb->rcb[i].lidx = tmp;
500 p_cb->rc_acp_handle = p_rcb->handle;
501 p_cb->rc_acp_idx = (p_rcb - p_cb->rcb) + 1;
502 APPL_TRACE_DEBUG("switching RCB rc_acp_handle:%d idx:%d",
503 p_cb->rc_acp_handle, p_cb->rc_acp_idx);
507 p_cb->rcb[i].shdl = shdl;
508 rc_open.rc_handle = i;
509 APPL_TRACE_ERROR("bta_av_rc_opened rcb[%d] shdl:%d lidx:%d/%d",
510 i, shdl, p_cb->rcb[i].lidx, p_cb->lcb[BTA_AV_NUM_LINKS].lidx);
511 p_cb->rcb[i].status |= BTA_AV_RC_CONN_MASK;
513 if (!shdl && 0 == p_cb->lcb[BTA_AV_NUM_LINKS].lidx) {
514 /* no associated SCB -> connected to an RC only device
515 * update the index to the extra LCB */
516 p_lcb = &p_cb->lcb[BTA_AV_NUM_LINKS];
517 bdcpy(p_lcb->addr, p_data->rc_conn_chg.peer_addr);
518 APPL_TRACE_DEBUG("rc_only bd_addr:%02x-%02x-%02x-%02x-%02x-%02x",
519 p_lcb->addr[0], p_lcb->addr[1],
520 p_lcb->addr[2], p_lcb->addr[3],
521 p_lcb->addr[4], p_lcb->addr[5]);
522 p_lcb->lidx = BTA_AV_NUM_LINKS + 1;
523 p_cb->rcb[i].lidx = p_lcb->lidx;
525 APPL_TRACE_ERROR("rcb[%d].lidx=%d, lcb.conn_msk=x%x",
526 i, p_cb->rcb[i].lidx, p_lcb->conn_msk);
527 disc = p_data->rc_conn_chg.handle | BTA_AV_CHNL_MSK;
530 bdcpy(rc_open.peer_addr, p_data->rc_conn_chg.peer_addr);
531 rc_open.peer_features = p_cb->rcb[i].peer_features;
532 rc_open.sdp_disc_done = TRUE;
533 rc_open.status = BTA_AV_SUCCESS;
534 APPL_TRACE_DEBUG("local features:x%x peer_features:x%x", p_cb->features,
535 rc_open.peer_features);
536 if (rc_open.peer_features == 0) {
537 /* we have not done SDP on peer RC capabilities.
538 * peer must have initiated the RC connection */
539 rc_open.peer_features = BTA_AV_FEAT_RCCT;
540 rc_open.sdp_disc_done = FALSE;
541 bta_av_rc_disc(disc);
543 (*p_cb->p_cback)(BTA_AV_RC_OPEN_EVT, (tBTA_AV *) &rc_open);
548 /*******************************************************************************
550 ** Function bta_av_rc_remote_cmd
552 ** Description Send an AVRCP remote control command.
556 *******************************************************************************/
557 void bta_av_rc_remote_cmd(tBTA_AV_CB *p_cb, tBTA_AV_DATA *p_data)
560 if (p_cb->features & BTA_AV_FEAT_RCCT) {
561 if (p_data->hdr.layer_specific < BTA_AV_NUM_RCB) {
562 p_rcb = &p_cb->rcb[p_data->hdr.layer_specific];
563 if (p_rcb->status & BTA_AV_RC_CONN_MASK) {
564 AVRC_PassCmd(p_rcb->handle, p_data->api_remote_cmd.label,
565 &p_data->api_remote_cmd.msg);
571 /*******************************************************************************
573 ** Function bta_av_rc_vendor_cmd
575 ** Description Send an AVRCP vendor specific command.
579 *******************************************************************************/
580 void bta_av_rc_vendor_cmd(tBTA_AV_CB *p_cb, tBTA_AV_DATA *p_data)
583 if ( (p_cb->features & (BTA_AV_FEAT_RCCT | BTA_AV_FEAT_VENDOR)) ==
584 (BTA_AV_FEAT_RCCT | BTA_AV_FEAT_VENDOR)) {
585 if (p_data->hdr.layer_specific < BTA_AV_NUM_RCB) {
586 p_rcb = &p_cb->rcb[p_data->hdr.layer_specific];
587 AVRC_VendorCmd(p_rcb->handle, p_data->api_vendor.label, &p_data->api_vendor.msg);
592 /*******************************************************************************
594 ** Function bta_av_rc_vendor_rsp
596 ** Description Send an AVRCP vendor specific response.
600 *******************************************************************************/
601 void bta_av_rc_vendor_rsp(tBTA_AV_CB *p_cb, tBTA_AV_DATA *p_data)
604 if ( (p_cb->features & (BTA_AV_FEAT_RCTG | BTA_AV_FEAT_VENDOR)) ==
605 (BTA_AV_FEAT_RCTG | BTA_AV_FEAT_VENDOR)) {
606 if (p_data->hdr.layer_specific < BTA_AV_NUM_RCB) {
607 p_rcb = &p_cb->rcb[p_data->hdr.layer_specific];
608 AVRC_VendorRsp(p_rcb->handle, p_data->api_vendor.label, &p_data->api_vendor.msg);
613 /*******************************************************************************
615 ** Function bta_av_rc_meta_rsp
617 ** Description Send an AVRCP metadata/advanced control command/response.
621 *******************************************************************************/
622 void bta_av_rc_meta_rsp(tBTA_AV_CB *p_cb, tBTA_AV_DATA *p_data)
625 BOOLEAN do_free = TRUE;
627 if ((p_cb->features & BTA_AV_FEAT_METADATA) && (p_data->hdr.layer_specific < BTA_AV_NUM_RCB)) {
628 if ((p_data->api_meta_rsp.is_rsp && (p_cb->features & BTA_AV_FEAT_RCTG)) ||
629 (!p_data->api_meta_rsp.is_rsp && (p_cb->features & BTA_AV_FEAT_RCCT)) ) {
630 p_rcb = &p_cb->rcb[p_data->hdr.layer_specific];
631 if (p_rcb->handle != BTA_AV_RC_HANDLE_NONE) {
632 AVRC_MsgReq(p_rcb->handle, p_data->api_meta_rsp.label,
633 p_data->api_meta_rsp.rsp_code,
634 p_data->api_meta_rsp.p_pkt);
641 osi_free (p_data->api_meta_rsp.p_pkt);
645 /*******************************************************************************
647 ** Function bta_av_rc_free_rsp
649 ** Description free an AVRCP metadata command buffer.
653 *******************************************************************************/
654 void bta_av_rc_free_rsp (tBTA_AV_CB *p_cb, tBTA_AV_DATA *p_data)
658 osi_free (p_data->api_meta_rsp.p_pkt);
661 /*******************************************************************************
663 ** Function bta_av_rc_meta_req
665 ** Description Send an AVRCP metadata command.
669 *******************************************************************************/
670 void bta_av_rc_free_msg (tBTA_AV_CB *p_cb, tBTA_AV_DATA *p_data)
678 /*******************************************************************************
680 ** Function bta_av_chk_notif_evt_id
682 ** Description make sure the requested player id is valid.
684 ** Returns BTA_AV_STS_NO_RSP, if no error
686 *******************************************************************************/
687 static tAVRC_STS bta_av_chk_notif_evt_id(tAVRC_MSG_VENDOR *p_vendor)
689 tAVRC_STS status = BTA_AV_STS_NO_RSP;
692 UINT8 *p = p_vendor->p_vendor_data + 2;
694 BE_STREAM_TO_UINT16 (u16, p);
695 /* double check the fixed length */
696 if ((u16 != 5) || (p_vendor->vendor_len != 9)) {
697 status = AVRC_STS_INTERNAL_ERR;
699 /* make sure the player_id is valid */
700 for (xx = 0; xx < p_bta_av_cfg->num_evt_ids; xx++) {
701 if (*p == p_bta_av_cfg->p_meta_evt_ids[xx]) {
705 if (xx == p_bta_av_cfg->num_evt_ids) {
706 status = AVRC_STS_BAD_PARAM;
713 /*******************************************************************************
715 ** Function bta_av_proc_meta_cmd
717 ** Description Process an AVRCP metadata command from the peer.
719 ** Returns TRUE to respond immediately
721 *******************************************************************************/
722 tBTA_AV_EVT bta_av_proc_meta_cmd(tAVRC_RESPONSE *p_rc_rsp, tBTA_AV_RC_MSG *p_msg, UINT8 *p_ctype)
724 tBTA_AV_EVT evt = BTA_AV_META_MSG_EVT;
727 tAVRC_MSG_VENDOR *p_vendor = &p_msg->msg.vendor;
729 #if (AVRC_METADATA_INCLUDED == TRUE)
731 pdu = *(p_vendor->p_vendor_data);
733 *p_ctype = AVRC_RSP_REJ;
734 /* Metadata messages only use PANEL sub-unit type */
735 if (p_vendor->hdr.subunit_type != AVRC_SUB_PANEL) {
736 APPL_TRACE_DEBUG("SUBUNIT must be PANEL");
739 p_vendor->hdr.ctype = BTA_AV_RSP_NOT_IMPL;
740 AVRC_VendorRsp(p_msg->handle, p_msg->label, &p_msg->msg.vendor);
741 } else if (!AVRC_IsValidAvcType(pdu, p_vendor->hdr.ctype) ) {
742 APPL_TRACE_DEBUG("Invalid pdu/ctype: 0x%x, %d", pdu, p_vendor->hdr.ctype);
743 /* reject invalid message without reporting to app */
745 p_rc_rsp->rsp.status = AVRC_STS_BAD_CMD;
748 case AVRC_PDU_GET_CAPABILITIES:
749 /* process GetCapabilities command without reporting the event to app */
751 u8 = *(p_vendor->p_vendor_data + 4);
752 p = p_vendor->p_vendor_data + 2;
753 p_rc_rsp->get_caps.capability_id = u8;
754 BE_STREAM_TO_UINT16 (u16, p);
755 if ((u16 != 1) || (p_vendor->vendor_len != 5)) {
756 p_rc_rsp->get_caps.status = AVRC_STS_INTERNAL_ERR;
758 p_rc_rsp->get_caps.status = AVRC_STS_NO_ERROR;
759 if (u8 == AVRC_CAP_COMPANY_ID) {
760 *p_ctype = AVRC_RSP_IMPL_STBL;
761 p_rc_rsp->get_caps.count = p_bta_av_cfg->num_co_ids;
762 memcpy(p_rc_rsp->get_caps.param.company_id, p_bta_av_cfg->p_meta_co_ids,
763 (p_bta_av_cfg->num_co_ids << 2));
764 } else if (u8 == AVRC_CAP_EVENTS_SUPPORTED) {
765 *p_ctype = AVRC_RSP_IMPL_STBL;
766 p_rc_rsp->get_caps.count = p_bta_av_cfg->num_evt_ids;
767 memcpy(p_rc_rsp->get_caps.param.event_id, p_bta_av_cfg->p_meta_evt_ids,
768 p_bta_av_cfg->num_evt_ids);
770 APPL_TRACE_DEBUG("Invalid capability ID: 0x%x", u8);
771 /* reject - unknown capability ID */
772 p_rc_rsp->get_caps.status = AVRC_STS_BAD_PARAM;
778 case AVRC_PDU_REGISTER_NOTIFICATION:
779 /* make sure the event_id is implemented */
780 p_rc_rsp->rsp.status = bta_av_chk_notif_evt_id (p_vendor);
781 if (p_rc_rsp->rsp.status != BTA_AV_STS_NO_RSP) {
789 APPL_TRACE_DEBUG("AVRCP 1.3 Metadata not supporteed. Reject command.");
790 /* reject invalid message without reporting to app */
792 p_rc_rsp->rsp.status = AVRC_STS_BAD_CMD;
799 /*******************************************************************************
801 ** Function bta_av_rc_msg
803 ** Description Process an AVRCP message from the peer.
807 *******************************************************************************/
808 void bta_av_rc_msg(tBTA_AV_CB *p_cb, tBTA_AV_DATA *p_data)
812 BT_HDR *p_pkt = NULL;
813 tAVRC_MSG_VENDOR *p_vendor = &p_data->rc_msg.msg.vendor;
814 BOOLEAN is_inquiry = ((p_data->rc_msg.msg.hdr.ctype == AVRC_CMD_SPEC_INQ) || p_data->rc_msg.msg.hdr.ctype == AVRC_CMD_GEN_INQ);
815 #if (AVRC_METADATA_INCLUDED == TRUE)
817 tAVRC_RESPONSE rc_rsp;
819 rc_rsp.rsp.status = BTA_AV_STS_NO_RSP;
822 if (p_data->rc_msg.opcode == AVRC_OP_PASS_THRU) {
823 /* if this is a pass thru command */
824 if ((p_data->rc_msg.msg.hdr.ctype == AVRC_CMD_CTRL) ||
825 (p_data->rc_msg.msg.hdr.ctype == AVRC_CMD_SPEC_INQ) ||
826 (p_data->rc_msg.msg.hdr.ctype == AVRC_CMD_GEN_INQ)
828 /* check if operation is supported */
829 if (p_data->rc_msg.msg.pass.op_id == AVRC_ID_VENDOR) {
830 p_data->rc_msg.msg.hdr.ctype = BTA_AV_RSP_NOT_IMPL;
831 #if (AVRC_METADATA_INCLUDED == TRUE)
832 if (p_cb->features & BTA_AV_FEAT_METADATA)
833 p_data->rc_msg.msg.hdr.ctype =
834 bta_av_group_navi_supported(p_data->rc_msg.msg.pass.pass_len,
835 p_data->rc_msg.msg.pass.p_pass_data, is_inquiry);
838 p_data->rc_msg.msg.hdr.ctype = bta_av_op_supported(p_data->rc_msg.msg.pass.op_id, is_inquiry);
841 APPL_TRACE_DEBUG("ctype %d", p_data->rc_msg.msg.hdr.ctype)
844 if (p_data->rc_msg.msg.hdr.ctype != BTA_AV_RSP_INTERIM) {
845 AVRC_PassRsp(p_data->rc_msg.handle, p_data->rc_msg.label, &p_data->rc_msg.msg.pass);
848 /* set up for callback if supported */
849 if (p_data->rc_msg.msg.hdr.ctype == BTA_AV_RSP_ACCEPT || p_data->rc_msg.msg.hdr.ctype == BTA_AV_RSP_INTERIM) {
850 evt = BTA_AV_REMOTE_CMD_EVT;
851 av.remote_cmd.rc_id = p_data->rc_msg.msg.pass.op_id;
852 av.remote_cmd.key_state = p_data->rc_msg.msg.pass.state;
853 av.remote_cmd.p_data = p_data->rc_msg.msg.pass.p_pass_data;
854 av.remote_cmd.len = p_data->rc_msg.msg.pass.pass_len;
855 memcpy(&av.remote_cmd.hdr, &p_data->rc_msg.msg.hdr, sizeof (tAVRC_HDR));
856 av.remote_cmd.label = p_data->rc_msg.label;
859 /* else if this is a pass thru response */
860 else if (p_data->rc_msg.msg.hdr.ctype >= AVRC_RSP_ACCEPT) {
861 /* set up for callback */
862 evt = BTA_AV_REMOTE_RSP_EVT;
863 av.remote_rsp.rc_id = p_data->rc_msg.msg.pass.op_id;
864 av.remote_rsp.key_state = p_data->rc_msg.msg.pass.state;
865 av.remote_rsp.rsp_code = p_data->rc_msg.msg.hdr.ctype;
866 av.remote_rsp.label = p_data->rc_msg.label;
868 /* must be a bad ctype -> reject*/
870 p_data->rc_msg.msg.hdr.ctype = BTA_AV_RSP_REJ;
871 AVRC_PassRsp(p_data->rc_msg.handle, p_data->rc_msg.label, &p_data->rc_msg.msg.pass);
874 /* else if this is a vendor specific command or response */
875 else if (p_data->rc_msg.opcode == AVRC_OP_VENDOR) {
876 /* set up for callback */
877 av.vendor_cmd.code = p_data->rc_msg.msg.hdr.ctype;
878 av.vendor_cmd.company_id = p_vendor->company_id;
879 av.vendor_cmd.label = p_data->rc_msg.label;
880 av.vendor_cmd.p_data = p_vendor->p_vendor_data;
881 av.vendor_cmd.len = p_vendor->vendor_len;
883 /* if configured to support vendor specific and it's a command */
884 if ((p_cb->features & BTA_AV_FEAT_VENDOR) &&
885 p_data->rc_msg.msg.hdr.ctype <= AVRC_CMD_GEN_INQ) {
886 #if (AVRC_METADATA_INCLUDED == TRUE)
887 if ((p_cb->features & BTA_AV_FEAT_METADATA) &&
888 (p_vendor->company_id == AVRC_CO_METADATA)) {
889 av.meta_msg.p_msg = &p_data->rc_msg.msg;
890 evt = bta_av_proc_meta_cmd (&rc_rsp, &p_data->rc_msg, &ctype);
893 evt = BTA_AV_VENDOR_CMD_EVT;
895 /* else if configured to support vendor specific and it's a response */
896 else if ((p_cb->features & BTA_AV_FEAT_VENDOR) &&
897 p_data->rc_msg.msg.hdr.ctype >= AVRC_RSP_ACCEPT) {
898 #if (AVRC_METADATA_INCLUDED == TRUE)
899 if ((p_cb->features & BTA_AV_FEAT_METADATA) &&
900 (p_vendor->company_id == AVRC_CO_METADATA)) {
901 av.meta_msg.p_msg = &p_data->rc_msg.msg;
902 evt = BTA_AV_META_MSG_EVT;
905 evt = BTA_AV_VENDOR_RSP_EVT;
908 /* else if not configured to support vendor specific and it's a command */
909 else if (!(p_cb->features & BTA_AV_FEAT_VENDOR) &&
910 p_data->rc_msg.msg.hdr.ctype <= AVRC_CMD_GEN_INQ) {
911 if (p_data->rc_msg.msg.vendor.p_vendor_data[0] == AVRC_PDU_INVALID) {
913 p_data->rc_msg.msg.hdr.ctype = BTA_AV_RSP_REJ;
914 p_data->rc_msg.msg.vendor.p_vendor_data[4] = AVRC_STS_BAD_CMD;
916 p_data->rc_msg.msg.hdr.ctype = BTA_AV_RSP_NOT_IMPL;
918 AVRC_VendorRsp(p_data->rc_msg.handle, p_data->rc_msg.label, &p_data->rc_msg.msg.vendor);
921 #if (AVRC_METADATA_INCLUDED == TRUE)
922 if (evt == 0 && rc_rsp.rsp.status != BTA_AV_STS_NO_RSP) {
924 rc_rsp.rsp.opcode = p_data->rc_msg.opcode;
925 AVRC_BldResponse (0, &rc_rsp, &p_pkt);
928 AVRC_MsgReq (p_data->rc_msg.handle, p_data->rc_msg.label, ctype, p_pkt);
935 av.remote_cmd.rc_handle = p_data->rc_msg.handle;
936 (*p_cb->p_cback)(evt, &av);
940 /*******************************************************************************
942 ** Function bta_av_rc_close
944 ** Description close the specified AVRC handle.
948 *******************************************************************************/
949 void bta_av_rc_close (tBTA_AV_CB *p_cb, tBTA_AV_DATA *p_data)
951 UINT16 handle = p_data->hdr.layer_specific;
955 if (handle < BTA_AV_NUM_RCB) {
956 p_rcb = &p_cb->rcb[handle];
958 APPL_TRACE_DEBUG("bta_av_rc_close handle: %d, status=0x%x", p_rcb->handle, p_rcb->status);
959 if (p_rcb->handle != BTA_AV_RC_HANDLE_NONE) {
961 p_scb = bta_av_cb.p_scb[p_rcb->shdl - 1];
963 /* just in case the RC timer is active
964 if(bta_av_cb.features & BTA_AV_FEAT_RCCT &&
965 p_scb->chnl == BTA_AV_CHNL_AUDIO) */
966 bta_sys_stop_timer(&p_scb->timer);
970 AVRC_Close(p_rcb->handle);
975 /*******************************************************************************
977 ** Function bta_av_get_shdl
979 ** Returns The index to p_scb[]
981 *******************************************************************************/
982 static UINT8 bta_av_get_shdl(tBTA_AV_SCB *p_scb)
986 /* find the SCB & stop the timer */
987 for (i = 0; i < BTA_AV_NUM_STRS; i++) {
988 if (p_scb == bta_av_cb.p_scb[i]) {
996 /*******************************************************************************
998 ** Function bta_av_stream_chg
1000 ** Description audio streaming status changed.
1004 *******************************************************************************/
1005 void bta_av_stream_chg(tBTA_AV_SCB *p_scb, BOOLEAN started)
1010 BOOLEAN no_streams = FALSE;
1011 tBTA_AV_SCB *p_scbi;
1013 started_msk = BTA_AV_HNDL_TO_MSK(p_scb->hdi);
1014 APPL_TRACE_DEBUG ("bta_av_stream_chg started:%d started_msk:x%x chnl:x%x", started,
1015 started_msk, p_scb->chnl);
1016 if (BTA_AV_CHNL_AUDIO == p_scb->chnl) {
1017 p_streams = &bta_av_cb.audio_streams;
1019 p_streams = &bta_av_cb.video_streams;
1023 /* Let L2CAP know this channel is processed with high priority */
1024 L2CA_SetAclPriority(p_scb->peer_addr, L2CAP_PRIORITY_HIGH);
1025 (*p_streams) |= started_msk;
1027 (*p_streams) &= ~started_msk;
1032 if (BTA_AV_CHNL_AUDIO == p_scb->chnl) {
1033 if (bta_av_cb.video_streams == 0) {
1038 if ( bta_av_cb.audio_streams ) {
1039 for (; i < BTA_AV_NUM_STRS; i++) {
1040 p_scbi = bta_av_cb.p_scb[i];
1041 /* scb is used and started */
1042 if ( p_scbi && (bta_av_cb.audio_streams & BTA_AV_HNDL_TO_MSK(i))
1043 && bdcmp(p_scbi->peer_addr, p_scb->peer_addr) == 0) {
1052 APPL_TRACE_DEBUG ("no_streams:%d i:%d, audio_streams:x%x, video_streams:x%x", no_streams, i,
1053 bta_av_cb.audio_streams, bta_av_cb.video_streams);
1055 /* Let L2CAP know this channel is processed with low priority */
1056 L2CA_SetAclPriority(p_scb->peer_addr, L2CAP_PRIORITY_NORMAL);
1062 /*******************************************************************************
1064 ** Function bta_av_conn_chg
1066 ** Description connetion status changed.
1067 ** Open an AVRCP acceptor channel, if new conn.
1071 *******************************************************************************/
1072 void bta_av_conn_chg(tBTA_AV_DATA *p_data)
1074 tBTA_AV_CB *p_cb = &bta_av_cb;
1075 tBTA_AV_SCB *p_scb = NULL;
1076 tBTA_AV_SCB *p_scbi;
1081 int index = (p_data->hdr.layer_specific & BTA_AV_HNDL_MSK) - 1;
1083 tBTA_AV_LCB *p_lcb_rc;
1084 tBTA_AV_RCB *p_rcb, *p_rcb2;
1085 BOOLEAN chk_restore = FALSE;
1087 /* Validate array index*/
1088 if (index < BTA_AV_NUM_STRS) {
1089 p_scb = p_cb->p_scb[index];
1091 mask = BTA_AV_HNDL_TO_MSK(index);
1092 p_lcb = bta_av_find_lcb(p_data->conn_chg.peer_addr, BTA_AV_LCB_FIND);
1093 conn_msk = 1 << (index + 1);
1094 if (p_data->conn_chg.is_up) {
1095 /* set the conned mask for this channel */
1098 p_lcb->conn_msk |= conn_msk;
1099 for (i = 0; i < BTA_AV_NUM_RCB; i++) {
1100 if (bta_av_cb.rcb[i].lidx == p_lcb->lidx) {
1101 bta_av_cb.rcb[i].shdl = index + 1;
1102 APPL_TRACE_DEBUG("conn_chg up[%d]: %d, status=0x%x, shdl:%d, lidx:%d", i,
1103 bta_av_cb.rcb[i].handle, bta_av_cb.rcb[i].status,
1104 bta_av_cb.rcb[i].shdl, bta_av_cb.rcb[i].lidx);
1109 if (p_scb->chnl == BTA_AV_CHNL_AUDIO) {
1110 old_msk = p_cb->conn_audio;
1111 p_cb->conn_audio |= mask;
1113 old_msk = p_cb->conn_video;
1114 p_cb->conn_video |= mask;
1117 if ((old_msk & mask) == 0) {
1118 /* increase the audio open count, if not set yet */
1119 bta_av_cb.audio_open_cnt++;
1123 APPL_TRACE_DEBUG("rc_acp_handle:%d rc_acp_idx:%d", p_cb->rc_acp_handle, p_cb->rc_acp_idx);
1124 /* check if the AVRCP ACP channel is already connected */
1125 if (p_lcb && p_cb->rc_acp_handle != BTA_AV_RC_HANDLE_NONE && p_cb->rc_acp_idx) {
1126 p_lcb_rc = &p_cb->lcb[BTA_AV_NUM_LINKS];
1127 APPL_TRACE_DEBUG("rc_acp is connected && conn_chg on same addr p_lcb_rc->conn_msk:x%x",
1128 p_lcb_rc->conn_msk);
1129 /* check if the RC is connected to the scb addr */
1130 APPL_TRACE_DEBUG ("p_lcb_rc->addr: %02x:%02x:%02x:%02x:%02x:%02x",
1131 p_lcb_rc->addr[0], p_lcb_rc->addr[1], p_lcb_rc->addr[2], p_lcb_rc->addr[3],
1132 p_lcb_rc->addr[4], p_lcb_rc->addr[5]);
1133 APPL_TRACE_DEBUG ("conn_chg.peer_addr: %02x:%02x:%02x:%02x:%02x:%02x",
1134 p_data->conn_chg.peer_addr[0], p_data->conn_chg.peer_addr[1],
1135 p_data->conn_chg.peer_addr[2],
1136 p_data->conn_chg.peer_addr[3], p_data->conn_chg.peer_addr[4],
1137 p_data->conn_chg.peer_addr[5]);
1138 if (p_lcb_rc->conn_msk && bdcmp(p_lcb_rc->addr, p_data->conn_chg.peer_addr) == 0) {
1139 /* AVRCP is already connected.
1140 * need to update the association betwen SCB and RCB */
1141 p_lcb_rc->conn_msk = 0; /* indicate RC ONLY is not connected */
1143 p_scb->rc_handle = p_cb->rc_acp_handle;
1144 p_rcb = &p_cb->rcb[p_cb->rc_acp_idx - 1];
1145 p_rcb->shdl = bta_av_get_shdl(p_scb);
1146 APPL_TRACE_DEBUG("update rc_acp shdl:%d/%d srch:%d", index + 1, p_rcb->shdl,
1149 p_rcb2 = bta_av_get_rcb_by_shdl(p_rcb->shdl);
1151 /* found the RCB that was created to associated with this SCB */
1152 p_cb->rc_acp_handle = p_rcb2->handle;
1153 p_cb->rc_acp_idx = (p_rcb2 - p_cb->rcb) + 1;
1154 APPL_TRACE_DEBUG("new rc_acp_handle:%d, idx:%d", p_cb->rc_acp_handle,
1156 p_rcb2->lidx = (BTA_AV_NUM_LINKS + 1);
1157 APPL_TRACE_DEBUG("rc2 handle:%d lidx:%d/%d", p_rcb2->handle, p_rcb2->lidx,
1158 p_cb->lcb[p_rcb2->lidx - 1].lidx);
1160 p_rcb->lidx = p_lcb->lidx;
1161 APPL_TRACE_DEBUG("rc handle:%d lidx:%d/%d", p_rcb->handle, p_rcb->lidx,
1162 p_cb->lcb[p_rcb->lidx - 1].lidx);
1167 if ((p_cb->conn_audio & mask) && bta_av_cb.audio_open_cnt) {
1168 /* this channel is still marked as open. decrease the count */
1169 bta_av_cb.audio_open_cnt--;
1172 /* clear the conned mask for this channel */
1173 p_cb->conn_audio &= ~mask;
1174 p_cb->conn_video &= ~mask;
1176 /* the stream is closed.
1177 * clear the peer address, so it would not mess up the AVRCP for the next round of operation */
1178 bdcpy(p_scb->peer_addr, bd_addr_null);
1179 if (p_scb->chnl == BTA_AV_CHNL_AUDIO) {
1181 p_lcb->conn_msk &= ~conn_msk;
1183 /* audio channel is down. make sure the INT channel is down */
1184 /* just in case the RC timer is active
1185 if(p_cb->features & BTA_AV_FEAT_RCCT) */
1187 bta_sys_stop_timer(&p_scb->timer);
1189 /* one audio channel goes down. check if we need to restore high priority */
1194 APPL_TRACE_DEBUG("bta_av_conn_chg shdl:%d", index + 1);
1195 for (i = 0; i < BTA_AV_NUM_RCB; i++) {
1196 APPL_TRACE_DEBUG("conn_chg dn[%d]: %d, status=0x%x, shdl:%d, lidx:%d", i,
1197 bta_av_cb.rcb[i].handle, bta_av_cb.rcb[i].status,
1198 bta_av_cb.rcb[i].shdl, bta_av_cb.rcb[i].lidx);
1199 if (bta_av_cb.rcb[i].shdl == index + 1) {
1200 bta_av_del_rc(&bta_av_cb.rcb[i]);
1205 if (p_cb->conn_audio == 0 && p_cb->conn_video == 0) {
1206 /* if both channels are not connected,
1207 * close all RC channels */
1208 bta_av_close_all_rc(p_cb);
1211 /* if the AVRCP is no longer listening, create the listening channel */
1212 if (bta_av_cb.rc_acp_handle == BTA_AV_RC_HANDLE_NONE && bta_av_cb.features & BTA_AV_FEAT_RCTG) {
1213 bta_av_rc_create(&bta_av_cb, AVCT_ACP, 0, BTA_AV_NUM_LINKS + 1);
1217 APPL_TRACE_DEBUG("bta_av_conn_chg audio:%x video:%x up:%d conn_msk:0x%x chk_restore:%d audio_open_cnt:%d",
1218 p_cb->conn_audio, p_cb->conn_video, p_data->conn_chg.is_up, conn_msk, chk_restore, p_cb->audio_open_cnt);
1221 if (p_cb->audio_open_cnt == 1) {
1222 /* one audio channel goes down and there's one audio channel remains open.
1223 * restore the switch role in default link policy */
1224 bta_sys_set_default_policy(BTA_ID_AV, HCI_ENABLE_MASTER_SLAVE_SWITCH);
1225 /* allow role switch, if this is the last connection */
1226 bta_av_restore_switch();
1228 if (p_cb->audio_open_cnt) {
1229 /* adjust flush timeout settings to longer period */
1230 for (i = 0; i < BTA_AV_NUM_STRS; i++) {
1231 p_scbi = bta_av_cb.p_scb[i];
1232 if (p_scbi && p_scbi->chnl == BTA_AV_CHNL_AUDIO && p_scbi->co_started) {
1233 /* may need to update the flush timeout of this already started stream */
1234 if (p_scbi->co_started != bta_av_cb.audio_open_cnt) {
1235 p_scbi->co_started = bta_av_cb.audio_open_cnt;
1236 L2CA_SetFlushTimeout(p_scbi->peer_addr, p_bta_av_cfg->p_audio_flush_to[p_scbi->co_started - 1] );
1244 /*******************************************************************************
1246 ** Function bta_av_disable
1248 ** Description disable AV.
1252 *******************************************************************************/
1253 void bta_av_disable(tBTA_AV_CB *p_cb, tBTA_AV_DATA *p_data)
1259 p_cb->disabling = TRUE;
1261 bta_av_close_all_rc(p_cb);
1263 utl_freebuf((void **) &p_cb->p_disc_db);
1265 /* disable audio/video - de-register all channels,
1266 * expect BTA_AV_DEREG_COMP_EVT when deregister is complete */
1267 for (xx = 0; xx < BTA_AV_NUM_STRS; xx++) {
1268 hdr.layer_specific = xx + 1;
1269 bta_av_api_deregister((tBTA_AV_DATA *)&hdr);
1273 /*******************************************************************************
1275 ** Function bta_av_api_disconnect
1281 *******************************************************************************/
1282 void bta_av_api_disconnect(tBTA_AV_DATA *p_data)
1284 AVDT_DisconnectReq(p_data->api_discnt.bd_addr, bta_av_conn_cback);
1285 bta_sys_stop_timer(&bta_av_cb.sig_tmr);
1288 /*******************************************************************************
1290 ** Function bta_av_sig_chg
1292 ** Description process AVDT signal channel up/down.
1296 *******************************************************************************/
1297 void bta_av_sig_chg(tBTA_AV_DATA *p_data)
1299 UINT16 event = p_data->str_msg.hdr.layer_specific;
1300 tBTA_AV_CB *p_cb = &bta_av_cb;
1303 tBTA_AV_LCB *p_lcb = NULL;
1305 APPL_TRACE_DEBUG("bta_av_sig_chg event: %d", event);
1306 if (event == AVDT_CONNECT_IND_EVT) {
1307 p_lcb = bta_av_find_lcb(p_data->str_msg.bd_addr, BTA_AV_LCB_FIND);
1309 /* if the address does not have an LCB yet, alloc one */
1310 for (xx = 0; xx < BTA_AV_NUM_LINKS; xx++) {
1312 APPL_TRACE_DEBUG("conn_lcb: 0x%x", p_cb->conn_lcb);
1314 /* look for a p_lcb with its p_scb registered */
1315 if ((!(mask & p_cb->conn_lcb)) && (p_cb->p_scb[xx] != NULL)) {
1316 p_lcb = &p_cb->lcb[xx];
1317 p_lcb->lidx = xx + 1;
1318 bdcpy(p_lcb->addr, p_data->str_msg.bd_addr);
1319 p_lcb->conn_msk = 0; /* clear the connect mask */
1320 /* start listening when the signal channel is open */
1321 if (p_cb->features & BTA_AV_FEAT_RCTG) {
1322 bta_av_rc_create(p_cb, AVCT_ACP, 0, p_lcb->lidx);
1324 /* this entry is not used yet. */
1325 p_cb->conn_lcb |= mask; /* mark it as used */
1326 APPL_TRACE_DEBUG("start sig timer %d", p_data->hdr.offset);
1327 if (p_data->hdr.offset == AVDT_ACP) {
1328 APPL_TRACE_DEBUG("Incoming L2CAP acquired, set state as incoming");
1329 bdcpy(p_cb->p_scb[xx]->peer_addr, p_data->str_msg.bd_addr);
1330 p_cb->p_scb[xx]->use_rc = TRUE; /* allowing RC for incoming connection */
1331 bta_av_ssm_execute(p_cb->p_scb[xx], BTA_AV_ACP_CONNECT_EVT, p_data);
1333 /* The Pending Event should be sent as soon as the L2CAP signalling channel
1334 * is set up, which is NOW. Earlier this was done only after
1335 * BTA_AV_SIG_TIME_VAL milliseconds.
1336 * The following function shall send the event and start the recurring timer
1338 bta_av_sig_timer(NULL);
1340 /* Possible collision : need to avoid outgoing processing while the timer is running */
1341 p_cb->p_scb[xx]->coll_mask = BTA_AV_COLL_INC_TMR;
1343 p_cb->acp_sig_tmr.param = (UINT32)xx;
1344 p_cb->acp_sig_tmr.p_cback = (TIMER_CBACK *)&bta_av_acp_sig_timer_cback;
1345 bta_sys_start_timer(&p_cb->acp_sig_tmr, 0, BTA_AV_ACP_SIG_TIME_VAL);
1351 /* check if we found something */
1352 if (xx == BTA_AV_NUM_LINKS) {
1353 /* We do not have scb for this avdt connection. */
1354 /* Silently close the connection. */
1355 APPL_TRACE_ERROR("av scb not available for avdt connection");
1356 AVDT_DisconnectReq (p_data->str_msg.bd_addr, NULL);
1361 #if( defined BTA_AR_INCLUDED ) && (BTA_AR_INCLUDED == TRUE)
1362 else if (event == BTA_AR_AVDT_CONN_EVT) {
1363 bta_sys_stop_timer(&bta_av_cb.sig_tmr);
1368 p_lcb = bta_av_find_lcb(p_data->str_msg.bd_addr, BTA_AV_LCB_FREE);
1369 if (p_lcb && p_lcb->conn_msk) {
1370 APPL_TRACE_DEBUG("conn_msk: 0x%x", p_lcb->conn_msk);
1372 for (xx = 0; xx < BTA_AV_NUM_STRS; xx++) {
1373 mask = 1 << (xx + 1);
1374 if ((mask & p_lcb->conn_msk) && (p_cb->p_scb[xx]) &&
1375 (bdcmp(p_cb->p_scb[xx]->peer_addr, p_data->str_msg.bd_addr) == 0)) {
1376 p_cb->p_scb[xx]->disc_rsn = p_data->str_msg.hdr.offset;
1377 bta_av_ssm_execute(p_cb->p_scb[xx], BTA_AV_AVDT_DISCONNECT_EVT, NULL);
1382 APPL_TRACE_DEBUG("conn_lcb: 0x%x", p_cb->conn_lcb);
1385 /*******************************************************************************
1387 ** Function bta_av_sig_timer
1389 ** Description process the signal channel timer. This timer is started
1390 ** when the AVDTP signal channel is connected. If no profile
1391 ** is connected, the timer goes off every BTA_AV_SIG_TIME_VAL
1395 *******************************************************************************/
1396 void bta_av_sig_timer(tBTA_AV_DATA *p_data)
1398 tBTA_AV_CB *p_cb = &bta_av_cb;
1401 tBTA_AV_LCB *p_lcb = NULL;
1405 APPL_TRACE_DEBUG("bta_av_sig_timer");
1406 for (xx = 0; xx < BTA_AV_NUM_LINKS; xx++) {
1408 if (mask & p_cb->conn_lcb) {
1409 /* this entry is used. check if it is connected */
1410 p_lcb = &p_cb->lcb[xx];
1411 if (!p_lcb->conn_msk) {
1412 bta_sys_start_timer(&p_cb->sig_tmr, BTA_AV_SIG_TIMER_EVT, BTA_AV_SIG_TIME_VAL);
1413 bdcpy(pend.bd_addr, p_lcb->addr);
1414 (*p_cb->p_cback)(BTA_AV_PENDING_EVT, (tBTA_AV *) &pend);
1420 /*******************************************************************************
1422 ** Function bta_av_acp_sig_timer_cback
1424 ** Description Process the timeout when SRC is accepting connection
1425 ** and SNK did not start signalling.
1429 *******************************************************************************/
1430 static void bta_av_acp_sig_timer_cback (TIMER_LIST_ENT *p_tle)
1432 UINT8 inx = (UINT8)p_tle->param;
1433 tBTA_AV_CB *p_cb = &bta_av_cb;
1434 tBTA_AV_SCB *p_scb = NULL;
1435 tBTA_AV_API_OPEN *p_buf;
1436 if (inx < BTA_AV_NUM_STRS) {
1437 p_scb = p_cb->p_scb[inx];
1440 APPL_TRACE_DEBUG("bta_av_acp_sig_timer_cback, coll_mask = 0x%02X", p_scb->coll_mask);
1442 if (p_scb->coll_mask & BTA_AV_COLL_INC_TMR) {
1443 p_scb->coll_mask &= ~BTA_AV_COLL_INC_TMR;
1445 if (bta_av_is_scb_opening(p_scb)) {
1446 if (p_scb->p_disc_db) {
1447 /* We are still doing SDP. Run the timer again. */
1448 p_scb->coll_mask |= BTA_AV_COLL_INC_TMR;
1450 p_cb->acp_sig_tmr.param = (UINT32)inx;
1451 p_cb->acp_sig_tmr.p_cback = (TIMER_CBACK *)&bta_av_acp_sig_timer_cback;
1452 bta_sys_start_timer(&p_cb->acp_sig_tmr, 0, BTA_AV_ACP_SIG_TIME_VAL);
1454 /* SNK did not start signalling, resume signalling process. */
1455 bta_av_discover_req (p_scb, NULL);
1457 } else if (bta_av_is_scb_incoming(p_scb)) {
1458 /* Stay in incoming state if SNK does not start signalling */
1460 /* API open was called right after SNK opened L2C connection. */
1461 if (p_scb->coll_mask & BTA_AV_COLL_API_CALLED) {
1462 p_scb->coll_mask &= ~BTA_AV_COLL_API_CALLED;
1464 /* BTA_AV_API_OPEN_EVT */
1465 if ((p_buf = (tBTA_AV_API_OPEN *) osi_malloc(sizeof(tBTA_AV_API_OPEN))) != NULL) {
1466 memcpy(p_buf, &(p_scb->open_api), sizeof(tBTA_AV_API_OPEN));
1467 bta_sys_sendmsg(p_buf);
1475 /*******************************************************************************
1477 ** Function bta_av_check_peer_features
1479 ** Description check supported features on the peer device from the SDP record
1480 ** and return the feature mask
1482 ** Returns tBTA_AV_FEAT peer device feature mask
1484 *******************************************************************************/
1485 tBTA_AV_FEAT bta_av_check_peer_features (UINT16 service_uuid)
1487 tBTA_AV_FEAT peer_features = 0;
1488 tBTA_AV_CB *p_cb = &bta_av_cb;
1489 tSDP_DISC_REC *p_rec = NULL;
1490 tSDP_DISC_ATTR *p_attr;
1491 UINT16 peer_rc_version = 0;
1492 UINT16 categories = 0;
1494 APPL_TRACE_DEBUG("bta_av_check_peer_features service_uuid:x%x", service_uuid);
1495 /* loop through all records we found */
1497 /* get next record; if none found, we're done */
1498 if ((p_rec = SDP_FindServiceInDb(p_cb->p_disc_db, service_uuid, p_rec)) == NULL) {
1502 if (( SDP_FindAttributeInRec(p_rec, ATTR_ID_SERVICE_CLASS_ID_LIST)) != NULL) {
1503 /* find peer features */
1504 if (SDP_FindServiceInDb(p_cb->p_disc_db, UUID_SERVCLASS_AV_REMOTE_CONTROL, NULL)) {
1505 peer_features |= BTA_AV_FEAT_RCCT;
1507 if (SDP_FindServiceInDb(p_cb->p_disc_db, UUID_SERVCLASS_AV_REM_CTRL_TARGET, NULL)) {
1508 peer_features |= BTA_AV_FEAT_RCTG;
1512 if (( SDP_FindAttributeInRec(p_rec, ATTR_ID_BT_PROFILE_DESC_LIST)) != NULL) {
1513 /* get profile version (if failure, version parameter is not updated) */
1514 SDP_FindProfileVersionInRec(p_rec, UUID_SERVCLASS_AV_REMOTE_CONTROL, &peer_rc_version);
1515 APPL_TRACE_DEBUG("peer_rc_version 0x%x", peer_rc_version);
1517 if (peer_rc_version >= AVRC_REV_1_3) {
1518 peer_features |= (BTA_AV_FEAT_VENDOR | BTA_AV_FEAT_METADATA);
1521 if (peer_rc_version >= AVRC_REV_1_4) {
1522 peer_features |= (BTA_AV_FEAT_ADV_CTRL);
1523 /* get supported categories */
1524 if ((p_attr = SDP_FindAttributeInRec(p_rec,
1525 ATTR_ID_SUPPORTED_FEATURES)) != NULL) {
1526 categories = p_attr->attr_value.v.u16;
1527 if (categories & AVRC_SUPF_CT_BROWSE) {
1528 peer_features |= (BTA_AV_FEAT_BROWSE);
1534 APPL_TRACE_DEBUG("peer_features:x%x", peer_features);
1535 return peer_features;
1538 /*******************************************************************************
1540 ** Function bta_av_rc_disc_done
1542 ** Description Handle AVRCP service discovery results. If matching
1543 ** service found, open AVRCP connection.
1547 *******************************************************************************/
1548 void bta_av_rc_disc_done(tBTA_AV_DATA *p_data)
1550 tBTA_AV_CB *p_cb = &bta_av_cb;
1551 tBTA_AV_SCB *p_scb = NULL;
1553 tBTA_AV_RC_OPEN rc_open;
1554 tBTA_AV_RC_FEAT rc_feat;
1556 tBTA_AV_FEAT peer_features; /* peer features mask */
1559 APPL_TRACE_DEBUG("bta_av_rc_disc_done disc:x%x", p_cb->disc);
1564 if ((p_cb->disc & BTA_AV_CHNL_MSK) == BTA_AV_CHNL_MSK) {
1565 /* this is the rc handle/index to tBTA_AV_RCB */
1566 rc_handle = p_cb->disc & (~BTA_AV_CHNL_MSK);
1568 /* Validate array index*/
1569 if (((p_cb->disc & BTA_AV_HNDL_MSK) - 1) < BTA_AV_NUM_STRS) {
1570 p_scb = p_cb->p_scb[(p_cb->disc & BTA_AV_HNDL_MSK) - 1];
1573 rc_handle = p_scb->rc_handle;
1580 APPL_TRACE_DEBUG("rc_handle %d", rc_handle);
1581 /* check peer version and whether support CT and TG role */
1582 peer_features = bta_av_check_peer_features (UUID_SERVCLASS_AV_REMOTE_CONTROL);
1583 if ((p_cb->features & BTA_AV_FEAT_ADV_CTRL) && ((peer_features & BTA_AV_FEAT_ADV_CTRL) == 0)) {
1584 /* if we support advance control and peer does not, check their support on TG role
1585 * some implementation uses 1.3 on CT ans 1.4 on TG */
1586 peer_features |= bta_av_check_peer_features (UUID_SERVCLASS_AV_REM_CTRL_TARGET);
1590 utl_freebuf((void **) &p_cb->p_disc_db);
1592 APPL_TRACE_DEBUG("peer_features 0x%x, features 0x%x", peer_features, p_cb->features);
1594 /* if we have no rc connection */
1595 if (rc_handle == BTA_AV_RC_HANDLE_NONE) {
1597 /* if peer remote control service matches ours and USE_RC is TRUE */
1598 if ((((p_cb->features & BTA_AV_FEAT_RCCT) && (peer_features & BTA_AV_FEAT_RCTG)) ||
1599 ((p_cb->features & BTA_AV_FEAT_RCTG) && (peer_features & BTA_AV_FEAT_RCCT))) ) {
1600 p_lcb = bta_av_find_lcb(p_scb->peer_addr, BTA_AV_LCB_FIND);
1602 rc_handle = bta_av_rc_create(p_cb, AVCT_INT, (UINT8)(p_scb->hdi + 1), p_lcb->lidx);
1603 p_cb->rcb[rc_handle].peer_features = peer_features;
1605 #if (BT_USE_TRACES == TRUE || BT_TRACE_APPL == TRUE)
1607 APPL_TRACE_ERROR("can not find LCB!!");
1610 } else if (p_scb->use_rc) {
1611 /* can not find AVRC on peer device. report failure */
1612 p_scb->use_rc = FALSE;
1613 bdcpy(rc_open.peer_addr, p_scb->peer_addr);
1614 rc_open.peer_features = 0;
1615 rc_open.sdp_disc_done = FALSE;
1616 rc_open.status = BTA_AV_FAIL_SDP;
1617 (*p_cb->p_cback)(BTA_AV_RC_OPEN_EVT, (tBTA_AV *) &rc_open);
1621 p_cb->rcb[rc_handle].peer_features = peer_features;
1622 rc_feat.rc_handle = rc_handle;
1623 rc_feat.peer_features = peer_features;
1624 (*p_cb->p_cback)(BTA_AV_RC_FEAT_EVT, (tBTA_AV *) &rc_feat);
1628 /*******************************************************************************
1630 ** Function bta_av_rc_closed
1632 ** Description Set AVRCP state to closed.
1636 *******************************************************************************/
1637 void bta_av_rc_closed(tBTA_AV_DATA *p_data)
1639 tBTA_AV_CB *p_cb = &bta_av_cb;
1640 tBTA_AV_RC_CLOSE rc_close;
1641 tBTA_AV_RC_CONN_CHG *p_msg = (tBTA_AV_RC_CONN_CHG *)p_data;
1645 BOOLEAN conn = FALSE;
1648 rc_close.rc_handle = BTA_AV_RC_HANDLE_NONE;
1650 APPL_TRACE_DEBUG("bta_av_rc_closed rc_handle:%d", p_msg->handle);
1651 for (i = 0; i < BTA_AV_NUM_RCB; i++) {
1652 p_rcb = &p_cb->rcb[i];
1653 APPL_TRACE_DEBUG("bta_av_rc_closed rcb[%d] rc_handle:%d, status=0x%x", i, p_rcb->handle, p_rcb->status);
1654 if (p_rcb->handle == p_msg->handle) {
1655 rc_close.rc_handle = i;
1656 p_rcb->status &= ~BTA_AV_RC_CONN_MASK;
1657 p_rcb->peer_features = 0;
1658 APPL_TRACE_DEBUG(" shdl:%d, lidx:%d", p_rcb->shdl, p_rcb->lidx);
1660 if ((p_rcb->shdl - 1) < BTA_AV_NUM_STRS) {
1661 p_scb = bta_av_cb.p_scb[p_rcb->shdl - 1];
1664 bdcpy(rc_close.peer_addr, p_scb->peer_addr);
1665 if (p_scb->rc_handle == p_rcb->handle) {
1666 p_scb->rc_handle = BTA_AV_RC_HANDLE_NONE;
1668 APPL_TRACE_DEBUG("shdl:%d, srch:%d", p_rcb->shdl, p_scb->rc_handle);
1671 } else if (p_rcb->lidx == (BTA_AV_NUM_LINKS + 1) ) {
1672 /* if the RCB uses the extra LCB, use the addr for event and clean it */
1673 p_lcb = &p_cb->lcb[BTA_AV_NUM_LINKS];
1674 bdcpy(rc_close.peer_addr, p_msg->peer_addr);
1675 APPL_TRACE_DEBUG("rc_only closed bd_addr:%02x-%02x-%02x-%02x-%02x-%02x",
1676 p_msg->peer_addr[0], p_msg->peer_addr[1],
1677 p_msg->peer_addr[2], p_msg->peer_addr[3],
1678 p_msg->peer_addr[4], p_msg->peer_addr[5]);
1679 p_lcb->conn_msk = 0;
1684 if ((p_rcb->status & BTA_AV_RC_ROLE_MASK) == BTA_AV_RC_ROLE_INT) {
1685 /* AVCT CCB is deallocated */
1686 p_rcb->handle = BTA_AV_RC_HANDLE_NONE;
1689 /* AVCT CCB is still there. dealloc */
1690 bta_av_del_rc(p_rcb);
1692 /* if the AVRCP is no longer listening, create the listening channel */
1693 if (bta_av_cb.rc_acp_handle == BTA_AV_RC_HANDLE_NONE && bta_av_cb.features & BTA_AV_FEAT_RCTG) {
1694 bta_av_rc_create(&bta_av_cb, AVCT_ACP, 0, BTA_AV_NUM_LINKS + 1);
1697 } else if ((p_rcb->handle != BTA_AV_RC_HANDLE_NONE) && (p_rcb->status & BTA_AV_RC_CONN_MASK)) {
1698 /* at least one channel is still connected */
1704 /* no AVRC channels are connected, go back to INIT state */
1705 bta_av_sm_execute(p_cb, BTA_AV_AVRC_NONE_EVT, NULL);
1708 if (rc_close.rc_handle == BTA_AV_RC_HANDLE_NONE) {
1709 rc_close.rc_handle = p_msg->handle;
1710 bdcpy(rc_close.peer_addr, p_msg->peer_addr);
1712 (*p_cb->p_cback)(BTA_AV_RC_CLOSE_EVT, (tBTA_AV *) &rc_close);
1715 /*******************************************************************************
1717 ** Function bta_av_rc_disc
1719 ** Description start AVRC SDP discovery.
1723 *******************************************************************************/
1724 void bta_av_rc_disc(UINT8 disc)
1726 tBTA_AV_CB *p_cb = &bta_av_cb;
1727 tAVRC_SDP_DB_PARAMS db_params;
1728 UINT16 attr_list[] = {ATTR_ID_SERVICE_CLASS_ID_LIST,
1729 ATTR_ID_BT_PROFILE_DESC_LIST,
1730 ATTR_ID_SUPPORTED_FEATURES
1734 UINT8 *p_addr = NULL;
1737 APPL_TRACE_DEBUG("bta_av_rc_disc 0x%x, %d", disc, bta_av_cb.disc);
1738 if ((bta_av_cb.disc != 0) || (disc == 0)) {
1742 if ((disc & BTA_AV_CHNL_MSK) == BTA_AV_CHNL_MSK) {
1743 /* this is the rc handle/index to tBTA_AV_RCB */
1744 rc_handle = disc & (~BTA_AV_CHNL_MSK);
1745 if (p_cb->rcb[rc_handle].lidx) {
1746 p_addr = p_cb->lcb[p_cb->rcb[rc_handle].lidx - 1].addr;
1749 hdi = (disc & BTA_AV_HNDL_MSK) - 1;
1750 p_scb = p_cb->p_scb[hdi];
1753 APPL_TRACE_DEBUG("rc_handle %d", p_scb->rc_handle);
1754 p_addr = p_scb->peer_addr;
1759 /* allocate discovery database */
1760 if (p_cb->p_disc_db == NULL) {
1761 p_cb->p_disc_db = (tSDP_DISCOVERY_DB *) osi_malloc(BTA_AV_DISC_BUF_SIZE);
1764 if (p_cb->p_disc_db) {
1765 /* set up parameters */
1766 db_params.db_len = BTA_AV_DISC_BUF_SIZE;
1767 db_params.num_attr = 3;
1768 db_params.p_db = p_cb->p_disc_db;
1769 db_params.p_attrs = attr_list;
1771 /* searching for UUID_SERVCLASS_AV_REMOTE_CONTROL gets both TG and CT */
1772 if (AVRC_FindService(UUID_SERVCLASS_AV_REMOTE_CONTROL, p_addr, &db_params,
1773 bta_av_avrc_sdp_cback) == AVRC_SUCCESS) {
1775 APPL_TRACE_DEBUG("disc %d", p_cb->disc);
1781 /*******************************************************************************
1783 ** Function bta_av_dereg_comp
1785 ** Description deregister complete. free the stream control block.
1789 *******************************************************************************/
1790 void bta_av_dereg_comp(tBTA_AV_DATA *p_data)
1792 tBTA_AV_CB *p_cb = &bta_av_cb;
1798 /* find the stream control block */
1799 p_scb = bta_av_hndl_to_scb(p_data->hdr.layer_specific);
1802 APPL_TRACE_DEBUG("deregistered %d(h%d)", p_scb->chnl, p_scb->hndl);
1803 mask = BTA_AV_HNDL_TO_MSK(p_scb->hdi);
1804 if (p_scb->chnl == BTA_AV_CHNL_AUDIO) {
1805 p_cb->reg_audio &= ~mask;
1806 if ((p_cb->conn_audio & mask) && bta_av_cb.audio_open_cnt) {
1807 /* this channel is still marked as open. decrease the count */
1808 bta_av_cb.audio_open_cnt--;
1810 p_cb->conn_audio &= ~mask;
1812 if (p_scb->q_tag == BTA_AV_Q_TAG_STREAM && p_scb->a2d_list) {
1813 /* make sure no buffers are in a2d_list */
1814 while (!list_is_empty(p_scb->a2d_list)) {
1815 p_buf = (BT_HDR *)list_front(p_scb->a2d_list);
1816 list_remove(p_scb->a2d_list, p_buf);
1821 /* remove the A2DP SDP record, if no more audio stream is left */
1822 if (!p_cb->reg_audio) {
1823 #if( defined BTA_AR_INCLUDED ) && (BTA_AR_INCLUDED == TRUE)
1824 bta_ar_dereg_avrc (UUID_SERVCLASS_AV_REMOTE_CONTROL, BTA_ID_AV);
1826 bta_av_del_sdp_rec(&p_cb->sdp_a2d_handle);
1827 bta_sys_remove_uuid(UUID_SERVCLASS_AUDIO_SOURCE);
1829 #if (BTA_AV_SINK_INCLUDED == TRUE)
1830 bta_av_del_sdp_rec(&p_cb->sdp_a2d_snk_handle);
1831 bta_sys_remove_uuid(UUID_SERVCLASS_AUDIO_SINK);
1835 p_cb->reg_video &= ~mask;
1836 /* make sure that this channel is not connected */
1837 p_cb->conn_video &= ~mask;
1838 /* remove the VDP SDP record, (only one video stream at most) */
1839 bta_av_del_sdp_rec(&p_cb->sdp_vdp_handle);
1840 bta_sys_remove_uuid(UUID_SERVCLASS_VIDEO_SOURCE);
1843 /* make sure that the timer is not active */
1844 bta_sys_stop_timer(&p_scb->timer);
1845 utl_freebuf((void **)&p_cb->p_scb[p_scb->hdi]);
1848 APPL_TRACE_DEBUG("audio 0x%x, video: 0x%x, disable:%d",
1849 p_cb->reg_audio, p_cb->reg_video, p_cb->disabling);
1850 /* if no stream control block is active */
1851 if ((p_cb->reg_audio + p_cb->reg_video) == 0) {
1852 #if( defined BTA_AR_INCLUDED ) && (BTA_AR_INCLUDED == TRUE)
1853 /* deregister from AVDT */
1854 bta_ar_dereg_avdt(BTA_ID_AV);
1856 /* deregister from AVCT */
1857 bta_ar_dereg_avrc (UUID_SERVCLASS_AV_REM_CTRL_TARGET, BTA_ID_AV);
1858 bta_ar_dereg_avct(BTA_ID_AV);
1861 if (p_cb->disabling) {
1862 p_cb->disabling = FALSE;
1863 bta_av_cb.features = 0;
1866 /* Clear the Capturing service class bit */
1867 cod.service = BTM_COD_SERVICE_CAPTURING;
1868 utl_set_device_class(&cod, BTA_UTL_CLR_COD_SERVICE_CLASS);
1871 #endif /* BTA_AV_INCLUDED */