Home | History | Annotate | Download | only in av
      1 /******************************************************************************
      2  *
      3  *  Copyright (C) 2004-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 private interface file for the BTA advanced audio/video.
     22  *
     23  ******************************************************************************/
     24 #ifndef BTA_AV_INT_H
     25 #define BTA_AV_INT_H
     26 
     27 #include "osi/include/list.h"
     28 #include "bta_sys.h"
     29 #include "bta_api.h"
     30 #include "bta_av_api.h"
     31 #include "avdt_api.h"
     32 #include "bta_av_co.h"
     33 
     34 #define BTA_AV_DEBUG TRUE
     35 /*****************************************************************************
     36 **  Constants
     37 *****************************************************************************/
     38 
     39 enum
     40 {
     41     /* these events are handled by the AV main state machine */
     42     BTA_AV_API_DISABLE_EVT = BTA_SYS_EVT_START(BTA_ID_AV),
     43     BTA_AV_API_REMOTE_CMD_EVT,
     44     BTA_AV_API_VENDOR_CMD_EVT,
     45     BTA_AV_API_VENDOR_RSP_EVT,
     46     BTA_AV_API_META_RSP_EVT,
     47     BTA_AV_API_RC_CLOSE_EVT,
     48     BTA_AV_AVRC_OPEN_EVT,
     49     BTA_AV_AVRC_MSG_EVT,
     50     BTA_AV_AVRC_NONE_EVT,
     51 
     52     /* these events are handled by the AV stream state machine */
     53     BTA_AV_API_OPEN_EVT,
     54     BTA_AV_API_CLOSE_EVT,
     55     BTA_AV_AP_START_EVT,        /* the following 2 events must be in the same order as the *API_*EVT */
     56     BTA_AV_AP_STOP_EVT,
     57     BTA_AV_API_RECONFIG_EVT,
     58     BTA_AV_API_PROTECT_REQ_EVT,
     59     BTA_AV_API_PROTECT_RSP_EVT,
     60     BTA_AV_API_RC_OPEN_EVT,
     61     BTA_AV_SRC_DATA_READY_EVT,
     62     BTA_AV_CI_SETCONFIG_OK_EVT,
     63     BTA_AV_CI_SETCONFIG_FAIL_EVT,
     64     BTA_AV_SDP_DISC_OK_EVT,
     65     BTA_AV_SDP_DISC_FAIL_EVT,
     66     BTA_AV_STR_DISC_OK_EVT,
     67     BTA_AV_STR_DISC_FAIL_EVT,
     68     BTA_AV_STR_GETCAP_OK_EVT,
     69     BTA_AV_STR_GETCAP_FAIL_EVT,
     70     BTA_AV_STR_OPEN_OK_EVT,
     71     BTA_AV_STR_OPEN_FAIL_EVT,
     72     BTA_AV_STR_START_OK_EVT,
     73     BTA_AV_STR_START_FAIL_EVT,
     74     BTA_AV_STR_CLOSE_EVT,
     75     BTA_AV_STR_CONFIG_IND_EVT,
     76     BTA_AV_STR_SECURITY_IND_EVT,
     77     BTA_AV_STR_SECURITY_CFM_EVT,
     78     BTA_AV_STR_WRITE_CFM_EVT,
     79     BTA_AV_STR_SUSPEND_CFM_EVT,
     80     BTA_AV_STR_RECONFIG_CFM_EVT,
     81     BTA_AV_AVRC_TIMER_EVT,
     82     BTA_AV_AVDT_CONNECT_EVT,
     83     BTA_AV_AVDT_DISCONNECT_EVT,
     84     BTA_AV_ROLE_CHANGE_EVT,
     85     BTA_AV_AVDT_DELAY_RPT_EVT,
     86     BTA_AV_ACP_CONNECT_EVT,
     87     BTA_AV_API_OFFLOAD_START_EVT,
     88     BTA_AV_API_OFFLOAD_START_RSP_EVT,
     89 
     90     /* these events are handled outside of the state machine */
     91     BTA_AV_API_ENABLE_EVT,
     92     BTA_AV_API_REGISTER_EVT,
     93     BTA_AV_API_DEREGISTER_EVT,
     94     BTA_AV_API_DISCONNECT_EVT,
     95     BTA_AV_CI_SRC_DATA_READY_EVT,
     96     BTA_AV_SIG_CHG_EVT,
     97     BTA_AV_SIGNALLING_TIMER_EVT,
     98     BTA_AV_SDP_AVRC_DISC_EVT,
     99     BTA_AV_AVRC_CLOSE_EVT,
    100     BTA_AV_CONN_CHG_EVT,
    101     BTA_AV_DEREG_COMP_EVT,
    102 #if (BTA_AV_SINK_INCLUDED == TRUE)
    103     BTA_AV_API_SINK_ENABLE_EVT,
    104 #endif
    105 #if (AVDT_REPORTING == TRUE)
    106     BTA_AV_AVDT_RPT_CONN_EVT,
    107 #endif
    108     BTA_AV_API_START_EVT,       /* the following 2 events must be in the same order as the *AP_*EVT */
    109     BTA_AV_API_STOP_EVT
    110 };
    111 
    112 /* events for AV control block state machine */
    113 #define BTA_AV_FIRST_SM_EVT     BTA_AV_API_DISABLE_EVT
    114 #define BTA_AV_LAST_SM_EVT      BTA_AV_AVRC_NONE_EVT
    115 
    116 /* events for AV stream control block state machine */
    117 #define BTA_AV_FIRST_SSM_EVT    BTA_AV_API_OPEN_EVT
    118 
    119 /* events that do not go through state machine */
    120 #define BTA_AV_FIRST_NSM_EVT    BTA_AV_API_ENABLE_EVT
    121 #define BTA_AV_LAST_NSM_EVT     BTA_AV_API_STOP_EVT
    122 
    123 /* API events passed to both SSMs (by bta_av_api_to_ssm) */
    124 #define BTA_AV_FIRST_A2S_API_EVT    BTA_AV_API_START_EVT
    125 #define BTA_AV_FIRST_A2S_SSM_EVT    BTA_AV_AP_START_EVT
    126 
    127 #define BTA_AV_LAST_EVT             BTA_AV_API_STOP_EVT
    128 
    129 /* maximum number of SEPS in stream discovery results */
    130 #define BTA_AV_NUM_SEPS         32
    131 
    132 /* initialization value for AVRC handle */
    133 #define BTA_AV_RC_HANDLE_NONE   0xFF
    134 
    135 /* size of database for service discovery */
    136 #define BTA_AV_DISC_BUF_SIZE        1000
    137 
    138 /* offset of media type in codec info byte array */
    139 #define BTA_AV_MEDIA_TYPE_IDX       1
    140 
    141 /* maximum length of AVDTP security data */
    142 #define BTA_AV_SECURITY_MAX_LEN     400
    143 
    144 /* check number of buffers queued at L2CAP when this amount of buffers are queued to L2CAP */
    145 #define BTA_AV_QUEUE_DATA_CHK_NUM   L2CAP_HIGH_PRI_MIN_XMIT_QUOTA
    146 
    147 /* the number of ACL links with AVDT */
    148 #define BTA_AV_NUM_LINKS            AVDT_NUM_LINKS
    149 
    150 #define BTA_AV_CO_ID_TO_BE_STREAM(p, u32) {*(p)++ = (UINT8)((u32) >> 16); *(p)++ = (UINT8)((u32) >> 8); *(p)++ = (UINT8)(u32); }
    151 #define BTA_AV_BE_STREAM_TO_CO_ID(u32, p) {u32 = (((UINT32)(*((p) + 2))) + (((UINT32)(*((p) + 1))) << 8) + (((UINT32)(*(p))) << 16)); (p) += 3;}
    152 
    153 /* these bits are defined for bta_av_cb.multi_av */
    154 #define BTA_AV_MULTI_AV_SUPPORTED   0x01
    155 #define BTA_AV_MULTI_AV_IN_USE      0x02
    156 
    157 
    158 /*****************************************************************************
    159 **  Data types
    160 *****************************************************************************/
    161 
    162 /* function types for call-out functions */
    163 typedef BOOLEAN (*tBTA_AV_CO_INIT) (UINT8 *p_codec_type, UINT8 *p_codec_info,
    164                                    UINT8 *p_num_protect, UINT8 *p_protect_info, UINT8 index);
    165 typedef void (*tBTA_AV_CO_DISC_RES) (tBTA_AV_HNDL hndl, UINT8 num_seps,
    166                                      UINT8 num_snk, UINT8 num_src, BD_ADDR addr, UINT16 uuid_local);
    167 typedef UINT8 (*tBTA_AV_CO_GETCFG) (tBTA_AV_HNDL hndl, tBTA_AV_CODEC codec_type,
    168                                      UINT8 *p_codec_info, UINT8 *p_sep_info_idx, UINT8 seid,
    169                                      UINT8 *p_num_protect, UINT8 *p_protect_info);
    170 typedef void (*tBTA_AV_CO_SETCFG) (tBTA_AV_HNDL hndl, tBTA_AV_CODEC codec_type,
    171                                      UINT8 *p_codec_info, UINT8 seid, BD_ADDR addr,
    172                                      UINT8 num_protect, UINT8 *p_protect_info,
    173                                      UINT8 t_local_sep, UINT8 avdt_handle);
    174 typedef void (*tBTA_AV_CO_OPEN) (tBTA_AV_HNDL hndl,
    175                                  tBTA_AV_CODEC codec_type, UINT8 *p_codec_info,
    176                                    UINT16 mtu);
    177 typedef void (*tBTA_AV_CO_CLOSE) (tBTA_AV_HNDL hndl, tBTA_AV_CODEC codec_type, UINT16 mtu);
    178 typedef void (*tBTA_AV_CO_START) (tBTA_AV_HNDL hndl, tBTA_AV_CODEC codec_type,UINT8 *p_codec_info, BOOLEAN *p_no_rtp_hdr);
    179 typedef void (*tBTA_AV_CO_STOP) (tBTA_AV_HNDL hndl, tBTA_AV_CODEC codec_type);
    180 typedef void * (*tBTA_AV_CO_DATAPATH) (tBTA_AV_CODEC codec_type,
    181                                        UINT32 *p_len, UINT32 *p_timestamp);
    182 typedef void (*tBTA_AV_CO_DELAY) (tBTA_AV_HNDL hndl, UINT16 delay);
    183 
    184 /* the call-out functions for one stream */
    185 typedef struct
    186 {
    187     tBTA_AV_CO_INIT     init;
    188     tBTA_AV_CO_DISC_RES disc_res;
    189     tBTA_AV_CO_GETCFG   getcfg;
    190     tBTA_AV_CO_SETCFG   setcfg;
    191     tBTA_AV_CO_OPEN     open;
    192     tBTA_AV_CO_CLOSE    close;
    193     tBTA_AV_CO_START    start;
    194     tBTA_AV_CO_STOP     stop;
    195     tBTA_AV_CO_DATAPATH data;
    196     tBTA_AV_CO_DELAY    delay;
    197 } tBTA_AV_CO_FUNCTS;
    198 
    199 /* data type for BTA_AV_API_ENABLE_EVT */
    200 typedef struct
    201 {
    202     BT_HDR              hdr;
    203     tBTA_AV_CBACK       *p_cback;
    204     tBTA_AV_FEAT        features;
    205     tBTA_SEC            sec_mask;
    206 } tBTA_AV_API_ENABLE;
    207 
    208 /* data type for BTA_AV_API_REG_EVT */
    209 typedef struct
    210 {
    211     BT_HDR              hdr;
    212     char                p_service_name[BTA_SERVICE_NAME_LEN+1];
    213     UINT8               app_id;
    214     tBTA_AV_DATA_CBACK       *p_app_data_cback;
    215     UINT16              service_uuid;
    216 } tBTA_AV_API_REG;
    217 
    218 
    219 enum
    220 {
    221     BTA_AV_RS_NONE,     /* straight API call */
    222     BTA_AV_RS_OK,       /* the role switch result - successful */
    223     BTA_AV_RS_FAIL,     /* the role switch result - failed */
    224     BTA_AV_RS_DONE      /* the role switch is done - continue */
    225 };
    226 typedef UINT8 tBTA_AV_RS_RES;
    227 /* data type for BTA_AV_API_OPEN_EVT */
    228 typedef struct
    229 {
    230     BT_HDR              hdr;
    231     BD_ADDR             bd_addr;
    232     BOOLEAN             use_rc;
    233     tBTA_SEC            sec_mask;
    234     tBTA_AV_RS_RES      switch_res;
    235     UINT16              uuid;  /* uuid of initiator */
    236 } tBTA_AV_API_OPEN;
    237 
    238 /* data type for BTA_AV_API_STOP_EVT */
    239 typedef struct
    240 {
    241     BT_HDR              hdr;
    242     BOOLEAN             suspend;
    243     BOOLEAN             flush;
    244 } tBTA_AV_API_STOP;
    245 
    246 /* data type for BTA_AV_API_DISCONNECT_EVT */
    247 typedef struct
    248 {
    249     BT_HDR              hdr;
    250     BD_ADDR             bd_addr;
    251 } tBTA_AV_API_DISCNT;
    252 
    253 /* data type for BTA_AV_API_PROTECT_REQ_EVT */
    254 typedef struct
    255 {
    256     BT_HDR              hdr;
    257     UINT8               *p_data;
    258     UINT16              len;
    259 } tBTA_AV_API_PROTECT_REQ;
    260 
    261 /* data type for BTA_AV_API_PROTECT_RSP_EVT */
    262 typedef struct
    263 {
    264     BT_HDR              hdr;
    265     UINT8               *p_data;
    266     UINT16              len;
    267     UINT8               error_code;
    268 } tBTA_AV_API_PROTECT_RSP;
    269 
    270 /* data type for BTA_AV_API_REMOTE_CMD_EVT */
    271 typedef struct
    272 {
    273     BT_HDR              hdr;
    274     tAVRC_MSG_PASS      msg;
    275     UINT8               label;
    276 } tBTA_AV_API_REMOTE_CMD;
    277 
    278 /* data type for BTA_AV_API_VENDOR_CMD_EVT and RSP */
    279 typedef struct
    280 {
    281     BT_HDR              hdr;
    282     tAVRC_MSG_VENDOR    msg;
    283     UINT8               label;
    284 } tBTA_AV_API_VENDOR;
    285 
    286 /* data type for BTA_AV_API_RC_OPEN_EVT */
    287 typedef struct
    288 {
    289     BT_HDR              hdr;
    290 } tBTA_AV_API_OPEN_RC;
    291 
    292 /* data type for BTA_AV_API_RC_CLOSE_EVT */
    293 typedef struct
    294 {
    295     BT_HDR              hdr;
    296 } tBTA_AV_API_CLOSE_RC;
    297 
    298 /* data type for BTA_AV_API_META_RSP_EVT */
    299 typedef struct
    300 {
    301     BT_HDR              hdr;
    302     BOOLEAN             is_rsp;
    303     UINT8               label;
    304     tBTA_AV_CODE        rsp_code;
    305     BT_HDR              *p_pkt;
    306 } tBTA_AV_API_META_RSP;
    307 
    308 
    309 /* data type for BTA_AV_API_RECONFIG_EVT */
    310 typedef struct
    311 {
    312     BT_HDR              hdr;
    313     UINT8               codec_info[AVDT_CODEC_SIZE];    /* codec configuration */
    314     UINT8               *p_protect_info;
    315     UINT8               num_protect;
    316     BOOLEAN             suspend;
    317     UINT8               sep_info_idx;
    318 } tBTA_AV_API_RCFG;
    319 
    320 /* data type for BTA_AV_CI_SETCONFIG_OK_EVT and BTA_AV_CI_SETCONFIG_FAIL_EVT */
    321 typedef struct
    322 {
    323     BT_HDR              hdr;
    324     tBTA_AV_HNDL        hndl;
    325     UINT8               err_code;
    326     UINT8               category;
    327     UINT8               num_seid;
    328     UINT8               *p_seid;
    329     BOOLEAN             recfg_needed;
    330     UINT8               avdt_handle;  /* local sep type for which this stream will be set up */
    331 } tBTA_AV_CI_SETCONFIG;
    332 
    333 /* data type for all stream events from AVDTP */
    334 typedef struct {
    335     BT_HDR              hdr;
    336     tAVDT_CFG           cfg;        /* configuration/capabilities parameters */
    337     tAVDT_CTRL          msg;        /* AVDTP callback message parameters */
    338     BD_ADDR             bd_addr;    /* bd address */
    339     UINT8               handle;
    340     UINT8               avdt_event;
    341     BOOLEAN             initiator; /* TRUE, if local device initiates the SUSPEND */
    342 } tBTA_AV_STR_MSG;
    343 
    344 /* data type for BTA_AV_AVRC_MSG_EVT */
    345 typedef struct
    346 {
    347     BT_HDR              hdr;
    348     tAVRC_MSG           msg;
    349     UINT8               handle;
    350     UINT8               label;
    351     UINT8               opcode;
    352 } tBTA_AV_RC_MSG;
    353 
    354 /* data type for BTA_AV_AVRC_OPEN_EVT, BTA_AV_AVRC_CLOSE_EVT */
    355 typedef struct
    356 {
    357     BT_HDR              hdr;
    358     BD_ADDR             peer_addr;
    359     UINT8               handle;
    360 } tBTA_AV_RC_CONN_CHG;
    361 
    362 /* data type for BTA_AV_CONN_CHG_EVT */
    363 typedef struct
    364 {
    365     BT_HDR              hdr;
    366     BD_ADDR             peer_addr;
    367     BOOLEAN             is_up;
    368 } tBTA_AV_CONN_CHG;
    369 
    370 /* data type for BTA_AV_ROLE_CHANGE_EVT */
    371 typedef struct
    372 {
    373     BT_HDR              hdr;
    374     UINT8               new_role;
    375     UINT8               hci_status;
    376 } tBTA_AV_ROLE_RES;
    377 
    378 /* data type for BTA_AV_SDP_DISC_OK_EVT */
    379 typedef struct
    380 {
    381     BT_HDR              hdr;
    382     UINT16              avdt_version;   /* AVDTP protocol version */
    383 } tBTA_AV_SDP_RES;
    384 
    385 /* data type for BTA_AV_API_OFFLOAD_RSP_EVT */
    386 typedef struct
    387 {
    388     BT_HDR              hdr;
    389     tBTA_AV_STATUS      status;
    390 } tBTA_AV_API_STATUS_RSP;
    391 
    392 
    393 /* type for SEP control block */
    394 typedef struct
    395 {
    396     UINT8               av_handle;         /* AVDTP handle */
    397     tBTA_AV_CODEC       codec_type;        /* codec type */
    398     UINT8               tsep;              /* SEP type of local SEP */
    399     tBTA_AV_DATA_CBACK  *p_app_data_cback; /* Application callback for media packets */
    400 } tBTA_AV_SEP;
    401 
    402 
    403 /* initiator/acceptor role for adaption */
    404 #define BTA_AV_ROLE_AD_INT          0x00       /* initiator */
    405 #define BTA_AV_ROLE_AD_ACP          0x01       /* acceptor */
    406 
    407 /* initiator/acceptor signaling roles */
    408 #define BTA_AV_ROLE_START_ACP       0x00
    409 #define BTA_AV_ROLE_START_INT       0x10    /* do not change this value */
    410 
    411 #define BTA_AV_ROLE_SUSPEND         0x20    /* suspending on start */
    412 #define BTA_AV_ROLE_SUSPEND_OPT     0x40    /* Suspend on Start option is set */
    413 
    414 /* union of all event datatypes */
    415 typedef union
    416 {
    417     BT_HDR                  hdr;
    418     tBTA_AV_API_ENABLE      api_enable;
    419     tBTA_AV_API_REG         api_reg;
    420     tBTA_AV_API_OPEN        api_open;
    421     tBTA_AV_API_STOP        api_stop;
    422     tBTA_AV_API_DISCNT      api_discnt;
    423     tBTA_AV_API_PROTECT_REQ api_protect_req;
    424     tBTA_AV_API_PROTECT_RSP api_protect_rsp;
    425     tBTA_AV_API_REMOTE_CMD  api_remote_cmd;
    426     tBTA_AV_API_VENDOR      api_vendor;
    427     tBTA_AV_API_RCFG        api_reconfig;
    428     tBTA_AV_CI_SETCONFIG    ci_setconfig;
    429     tBTA_AV_STR_MSG         str_msg;
    430     tBTA_AV_RC_MSG          rc_msg;
    431     tBTA_AV_RC_CONN_CHG     rc_conn_chg;
    432     tBTA_AV_CONN_CHG        conn_chg;
    433     tBTA_AV_ROLE_RES        role_res;
    434     tBTA_AV_SDP_RES         sdp_res;
    435     tBTA_AV_API_META_RSP    api_meta_rsp;
    436     tBTA_AV_API_STATUS_RSP  api_status_rsp;
    437 } tBTA_AV_DATA;
    438 
    439 typedef void (tBTA_AV_VDP_DATA_ACT)(void *p_scb);
    440 
    441 typedef struct
    442 {
    443     tBTA_AV_VDP_DATA_ACT    *p_act;
    444     UINT8                   *p_frame;
    445     UINT16                  buf_size;
    446     UINT32                  len;
    447     UINT32                  offset;
    448     UINT32                  timestamp;
    449 } tBTA_AV_VF_INFO;
    450 
    451 typedef union
    452 {
    453     tBTA_AV_VF_INFO     vdp;            /* used for video channels only */
    454     tBTA_AV_API_OPEN    open;           /* used only before open and role switch
    455                                            is needed on another AV channel */
    456 } tBTA_AV_Q_INFO;
    457 
    458 #define BTA_AV_Q_TAG_OPEN               0x01 /* after API_OPEN, before STR_OPENED */
    459 #define BTA_AV_Q_TAG_START              0x02 /* before start sending media packets */
    460 #define BTA_AV_Q_TAG_STREAM             0x03 /* during streaming */
    461 
    462 #define BTA_AV_WAIT_ACP_CAPS_ON         0x01 /* retriving the peer capabilities */
    463 #define BTA_AV_WAIT_ACP_CAPS_STARTED    0x02 /* started while retriving peer capabilities */
    464 #define BTA_AV_WAIT_ROLE_SW_RES_OPEN    0x04 /* waiting for role switch result after API_OPEN, before STR_OPENED */
    465 #define BTA_AV_WAIT_ROLE_SW_RES_START   0x08 /* waiting for role switch result before streaming */
    466 #define BTA_AV_WAIT_ROLE_SW_STARTED     0x10 /* started while waiting for role switch result */
    467 #define BTA_AV_WAIT_ROLE_SW_RETRY       0x20 /* set when retry on timeout */
    468 #define BTA_AV_WAIT_CHECK_RC            0x40 /* set when the timer is used by role switch */
    469 #define BTA_AV_WAIT_ROLE_SW_FAILED      0x80 /* role switch failed */
    470 
    471 #define BTA_AV_WAIT_ROLE_SW_BITS        (BTA_AV_WAIT_ROLE_SW_RES_OPEN|BTA_AV_WAIT_ROLE_SW_RES_START|BTA_AV_WAIT_ROLE_SW_STARTED|BTA_AV_WAIT_ROLE_SW_RETRY)
    472 
    473 /* Bitmap for collision, coll_mask */
    474 #define BTA_AV_COLL_INC_TMR             0x01 /* Timer is running for incoming L2C connection */
    475 #define BTA_AV_COLL_API_CALLED          0x02 /* API open was called while incoming timer is running */
    476 
    477 /* type for AV stream control block */
    478 typedef struct
    479 {
    480     const tBTA_AV_ACT   *p_act_tbl;     /* the action table for stream state machine */
    481     const tBTA_AV_CO_FUNCTS *p_cos;     /* the associated callout functions */
    482     BOOLEAN             sdp_discovery_started; /* variable to determine whether SDP is started */
    483     tBTA_AV_SEP         seps[BTA_AV_MAX_SEPS];
    484     tAVDT_CFG           *p_cap;         /* buffer used for get capabilities */
    485     list_t              *a2d_list;      /* used for audio channels only */
    486     tBTA_AV_Q_INFO      q_info;
    487     tAVDT_SEP_INFO      sep_info[BTA_AV_NUM_SEPS];      /* stream discovery results */
    488     tAVDT_CFG           cfg;            /* local SEP configuration */
    489     alarm_t             *avrc_ct_timer; /* delay timer for AVRC CT */
    490     BD_ADDR             peer_addr;      /* peer BD address */
    491     UINT16              l2c_cid;        /* L2CAP channel ID */
    492     UINT16              stream_mtu;     /* MTU of stream */
    493     UINT16              avdt_version;   /* the avdt version of peer device */
    494     tBTA_SEC            sec_mask;       /* security mask */
    495     tBTA_AV_CODEC       codec_type;     /* codec type */
    496     UINT8               media_type;     /* Media type */
    497     BOOLEAN             cong;           /* TRUE if AVDTP congested */
    498     tBTA_AV_STATUS      open_status;    /* open failure status */
    499     tBTA_AV_CHNL        chnl;           /* the channel: audio/video */
    500     tBTA_AV_HNDL        hndl;           /* the handle: ((hdi + 1)|chnl) */
    501     UINT16              cur_psc_mask;   /* Protocol service capabilities mask for current connection */
    502     UINT8               avdt_handle;    /* AVDTP handle */
    503     UINT8               hdi;            /* the index to SCB[] */
    504     UINT8               num_seps;       /* number of seps returned by stream discovery */
    505     UINT8               num_disc_snks;  /* number of discovered snks */
    506     UINT8               num_disc_srcs;  /* number of discovered srcs */
    507     UINT8               sep_info_idx;   /* current index into sep_info */
    508     UINT8               sep_idx;        /* current index into local seps[] */
    509     UINT8               rcfg_idx;       /* reconfig requested index into sep_info */
    510     UINT8               state;          /* state machine state */
    511     UINT8               avdt_label;     /* AVDTP label */
    512     UINT8               app_id;         /* application id */
    513     UINT8               num_recfg;      /* number of reconfigure sent */
    514     UINT8               role;
    515     UINT8               l2c_bufs;       /* the number of buffers queued to L2CAP */
    516     UINT8               rc_handle;      /* connected AVRCP handle */
    517     BOOLEAN             use_rc;         /* TRUE if AVRCP is allowed */
    518     BOOLEAN             started;        /* TRUE if stream started */
    519     UINT8               co_started;     /* non-zero, if stream started from call-out perspective */
    520     BOOLEAN             recfg_sup;      /* TRUE if the first attempt to reconfigure the stream was successfull, else False if command fails */
    521     BOOLEAN             suspend_sup;    /* TRUE if Suspend stream is supported, else FALSE if suspend command fails */
    522     BOOLEAN             deregistring;   /* TRUE if deregistering */
    523     BOOLEAN             sco_suspend;    /* TRUE if SUSPEND is issued automatically for SCO */
    524     UINT8               coll_mask;      /* Mask to check incoming and outgoing collision */
    525     tBTA_AV_API_OPEN    open_api;       /* Saved OPEN api message */
    526     UINT8               wait;           /* set 0x1, when getting Caps as ACP, set 0x2, when started */
    527     UINT8               q_tag;          /* identify the associated q_info union member */
    528     BOOLEAN             no_rtp_hdr;     /* TRUE if add no RTP header*/
    529     UINT16              uuid_int;       /*intended UUID of Initiator to connect to */
    530     BOOLEAN             offload_start_pending;
    531     BOOLEAN             skip_sdp;       /* Decides if sdp to be done prior to profile connection */
    532 } tBTA_AV_SCB;
    533 
    534 #define BTA_AV_RC_ROLE_MASK     0x10
    535 #define BTA_AV_RC_ROLE_INT      0x00
    536 #define BTA_AV_RC_ROLE_ACP      0x10
    537 
    538 #define BTA_AV_RC_CONN_MASK     0x20
    539 
    540 /* type for AV RCP control block */
    541 /* index to this control block is the rc handle */
    542 typedef struct
    543 {
    544     UINT8   status;
    545     UINT8   handle;
    546     UINT8   shdl;   /* stream handle (hdi + 1) */
    547     UINT8   lidx;   /* (index+1) to LCB */
    548     tBTA_AV_FEAT        peer_features;  /* peer features mask */
    549 } tBTA_AV_RCB;
    550 #define BTA_AV_NUM_RCB      (BTA_AV_NUM_STRS  + 2)
    551 
    552 enum
    553 {
    554     BTA_AV_LCB_FREE,
    555     BTA_AV_LCB_FIND
    556 };
    557 
    558 /* type for AV ACL Link control block */
    559 typedef struct
    560 {
    561     BD_ADDR             addr;           /* peer BD address */
    562     UINT8               conn_msk;       /* handle mask of connected stream handle */
    563     UINT8               lidx;           /* index + 1 */
    564 } tBTA_AV_LCB;
    565 
    566 /* type for stream state machine action functions */
    567 typedef void (*tBTA_AV_SACT)(tBTA_AV_SCB *p_scb, tBTA_AV_DATA *p_data);
    568 
    569 
    570 /* type for AV control block */
    571 typedef struct
    572 {
    573     tBTA_AV_SCB         *p_scb[BTA_AV_NUM_STRS];    /* stream control block */
    574     tSDP_DISCOVERY_DB   *p_disc_db;     /* pointer to discovery database */
    575     tBTA_AV_CBACK       *p_cback;       /* application callback function */
    576     tBTA_AV_RCB         rcb[BTA_AV_NUM_RCB];  /* RCB control block */
    577     tBTA_AV_LCB         lcb[BTA_AV_NUM_LINKS+1];  /* link control block */
    578     alarm_t             *link_signalling_timer;
    579     alarm_t             *accept_signalling_timer; /* timer to monitor signalling when accepting */
    580     UINT32              sdp_a2d_handle; /* SDP record handle for audio src */
    581 #if (BTA_AV_SINK_INCLUDED == TRUE)
    582     UINT32              sdp_a2d_snk_handle; /* SDP record handle for audio snk */
    583 #endif
    584     UINT32              sdp_vdp_handle; /* SDP record handle for video src */
    585     tBTA_AV_FEAT        features;       /* features mask */
    586     tBTA_SEC            sec_mask;       /* security mask */
    587     tBTA_AV_HNDL        handle;         /* the handle for SDP activity */
    588     BOOLEAN             disabling;      /* TRUE if api disabled called */
    589     UINT8               disc;           /* (hdi+1) or (rc_handle|BTA_AV_CHNL_MSK) if p_disc_db is in use */
    590     UINT8               state;          /* state machine state */
    591     UINT8               conn_rc;        /* handle mask of connected RCP channels */
    592     UINT8               conn_audio;     /* handle mask of connected audio channels */
    593     UINT8               conn_video;     /* handle mask of connected video channels */
    594     UINT8               conn_lcb;       /* index mask of used LCBs */
    595     UINT8               audio_open_cnt; /* number of connected audio channels */
    596     UINT8               reg_audio;      /* handle mask of registered audio channels */
    597     UINT8               reg_video;      /* handle mask of registered video channels */
    598     UINT8               rc_acp_handle;
    599     UINT8               rc_acp_idx;     /* (index + 1) to RCB */
    600     UINT8               rs_idx;         /* (index + 1) to SCB for the one waiting for RS on open */
    601     BOOLEAN             sco_occupied;   /* TRUE if SCO is being used or call is in progress */
    602     UINT8               audio_streams;  /* handle mask of streaming audio channels */
    603     UINT8               video_streams;  /* handle mask of streaming video channels */
    604 } tBTA_AV_CB;
    605 
    606 
    607 
    608 /*****************************************************************************
    609 **  Global data
    610 *****************************************************************************/
    611 
    612 /* control block declaration */
    613 #if BTA_DYNAMIC_MEMORY == FALSE
    614 extern tBTA_AV_CB bta_av_cb;
    615 #else
    616 extern tBTA_AV_CB *bta_av_cb_ptr;
    617 #define bta_av_cb (*bta_av_cb_ptr)
    618 #endif
    619 
    620 /* config struct */
    621 extern tBTA_AV_CFG *p_bta_av_cfg;
    622 extern const tBTA_AV_CFG bta_avk_cfg;
    623 extern const tBTA_AV_CFG bta_av_cfg;
    624 
    625 /* rc id config struct */
    626 extern UINT16 *p_bta_av_rc_id;
    627 extern UINT16 *p_bta_av_rc_id_ac;
    628 
    629 extern const tBTA_AV_SACT bta_av_a2d_action[];
    630 extern const tBTA_AV_CO_FUNCTS bta_av_a2d_cos;
    631 extern const tBTA_AV_SACT bta_av_vdp_action[];
    632 extern tAVDT_CTRL_CBACK * const bta_av_dt_cback[];
    633 extern void bta_av_stream_data_cback(UINT8 handle, BT_HDR *p_pkt, UINT32 time_stamp, UINT8 m_pt);
    634 
    635 /*****************************************************************************
    636 **  Function prototypes
    637 *****************************************************************************/
    638 /* utility functions */
    639 extern tBTA_AV_SCB *bta_av_hndl_to_scb(UINT16 handle);
    640 extern BOOLEAN bta_av_chk_start(tBTA_AV_SCB *p_scb);
    641 extern void bta_av_restore_switch (void);
    642 extern UINT16 bta_av_chk_mtu(tBTA_AV_SCB *p_scb, UINT16 mtu);
    643 extern void bta_av_conn_cback(UINT8 handle, BD_ADDR bd_addr, UINT8 event, tAVDT_CTRL *p_data);
    644 extern UINT8 bta_av_rc_create(tBTA_AV_CB *p_cb, UINT8 role, UINT8 shdl, UINT8 lidx);
    645 extern void bta_av_stream_chg(tBTA_AV_SCB *p_scb, BOOLEAN started);
    646 extern BOOLEAN bta_av_is_scb_opening (tBTA_AV_SCB *p_scb);
    647 extern BOOLEAN bta_av_is_scb_incoming (tBTA_AV_SCB *p_scb);
    648 extern void bta_av_set_scb_sst_init (tBTA_AV_SCB *p_scb);
    649 extern BOOLEAN bta_av_is_scb_init (tBTA_AV_SCB *p_scb);
    650 extern void bta_av_set_scb_sst_incoming (tBTA_AV_SCB *p_scb);
    651 extern tBTA_AV_LCB * bta_av_find_lcb(BD_ADDR addr, UINT8 op);
    652 
    653 
    654 /* main functions */
    655 extern void bta_av_api_deregister(tBTA_AV_DATA *p_data);
    656 extern void bta_av_dup_audio_buf(tBTA_AV_SCB *p_scb, BT_HDR *p_buf);
    657 extern void bta_av_sm_execute(tBTA_AV_CB *p_cb, UINT16 event, tBTA_AV_DATA *p_data);
    658 extern void bta_av_ssm_execute(tBTA_AV_SCB *p_scb, UINT16 event, tBTA_AV_DATA *p_data);
    659 extern BOOLEAN bta_av_hdl_event(BT_HDR *p_msg);
    660 #if (defined(BTA_AV_DEBUG) && BTA_AV_DEBUG == TRUE)
    661 extern char *bta_av_evt_code(UINT16 evt_code);
    662 #endif
    663 extern BOOLEAN bta_av_switch_if_needed(tBTA_AV_SCB *p_scb);
    664 extern BOOLEAN bta_av_link_role_ok(tBTA_AV_SCB *p_scb, UINT8 bits);
    665 extern BOOLEAN bta_av_is_rcfg_sst(tBTA_AV_SCB *p_scb);
    666 
    667 /* nsm action functions */
    668 extern void bta_av_api_disconnect(tBTA_AV_DATA *p_data);
    669 extern void bta_av_sig_chg(tBTA_AV_DATA *p_data);
    670 extern void bta_av_signalling_timer(tBTA_AV_DATA *p_data);
    671 extern void bta_av_rc_disc_done(tBTA_AV_DATA *p_data);
    672 extern void bta_av_rc_closed(tBTA_AV_DATA *p_data);
    673 extern void bta_av_rc_disc(UINT8 disc);
    674 extern void bta_av_conn_chg(tBTA_AV_DATA *p_data);
    675 extern void bta_av_dereg_comp(tBTA_AV_DATA *p_data);
    676 
    677 /* sm action functions */
    678 extern void bta_av_disable (tBTA_AV_CB *p_cb, tBTA_AV_DATA *p_data);
    679 extern void bta_av_rc_opened (tBTA_AV_CB *p_cb, tBTA_AV_DATA *p_data);
    680 extern void bta_av_rc_remote_cmd (tBTA_AV_CB *p_cb, tBTA_AV_DATA *p_data);
    681 extern void bta_av_rc_vendor_cmd (tBTA_AV_CB *p_cb, tBTA_AV_DATA *p_data);
    682 extern void bta_av_rc_vendor_rsp (tBTA_AV_CB *p_cb, tBTA_AV_DATA *p_data);
    683 extern void bta_av_rc_msg (tBTA_AV_CB *p_cb, tBTA_AV_DATA *p_data);
    684 extern void bta_av_rc_close (tBTA_AV_CB *p_cb, tBTA_AV_DATA *p_data);
    685 extern void bta_av_rc_meta_rsp (tBTA_AV_CB *p_cb, tBTA_AV_DATA *p_data);
    686 extern void bta_av_rc_free_rsp (tBTA_AV_CB *p_cb, tBTA_AV_DATA *p_data);
    687 extern void bta_av_rc_free_msg (tBTA_AV_CB *p_cb, tBTA_AV_DATA *p_data);
    688 
    689 extern tBTA_AV_RCB * bta_av_get_rcb_by_shdl(UINT8 shdl);
    690 extern void bta_av_del_rc(tBTA_AV_RCB *p_rcb);
    691 
    692 /* ssm action functions */
    693 extern void bta_av_do_disc_a2d (tBTA_AV_SCB *p_scb, tBTA_AV_DATA *p_data);
    694 extern void bta_av_cleanup (tBTA_AV_SCB *p_scb, tBTA_AV_DATA *p_data);
    695 extern void bta_av_free_sdb (tBTA_AV_SCB *p_scb, tBTA_AV_DATA *p_data);
    696 extern void bta_av_config_ind (tBTA_AV_SCB *p_scb, tBTA_AV_DATA *p_data);
    697 extern void bta_av_disconnect_req (tBTA_AV_SCB *p_scb, tBTA_AV_DATA *p_data);
    698 extern void bta_av_security_req (tBTA_AV_SCB *p_scb, tBTA_AV_DATA *p_data);
    699 extern void bta_av_security_rsp (tBTA_AV_SCB *p_scb, tBTA_AV_DATA *p_data);
    700 extern void bta_av_setconfig_rsp (tBTA_AV_SCB *p_scb, tBTA_AV_DATA *p_data);
    701 extern void bta_av_str_opened (tBTA_AV_SCB *p_scb, tBTA_AV_DATA *p_data);
    702 extern void bta_av_security_ind (tBTA_AV_SCB *p_scb, tBTA_AV_DATA *p_data);
    703 extern void bta_av_security_cfm (tBTA_AV_SCB *p_scb, tBTA_AV_DATA *p_data);
    704 extern void bta_av_do_close (tBTA_AV_SCB *p_scb, tBTA_AV_DATA *p_data);
    705 extern void bta_av_connect_req (tBTA_AV_SCB *p_scb, tBTA_AV_DATA *p_data);
    706 extern void bta_av_sdp_failed (tBTA_AV_SCB *p_scb, tBTA_AV_DATA *p_data);
    707 extern void bta_av_disc_results (tBTA_AV_SCB *p_scb, tBTA_AV_DATA *p_data);
    708 extern void bta_av_disc_res_as_acp (tBTA_AV_SCB *p_scb, tBTA_AV_DATA *p_data);
    709 extern void bta_av_open_failed (tBTA_AV_SCB *p_scb, tBTA_AV_DATA *p_data);
    710 extern void bta_av_getcap_results (tBTA_AV_SCB *p_scb, tBTA_AV_DATA *p_data);
    711 extern void bta_av_setconfig_rej (tBTA_AV_SCB *p_scb, tBTA_AV_DATA *p_data);
    712 extern void bta_av_discover_req (tBTA_AV_SCB *p_scb, tBTA_AV_DATA *p_data);
    713 extern void bta_av_conn_failed (tBTA_AV_SCB *p_scb, tBTA_AV_DATA *p_data);
    714 extern void bta_av_do_start (tBTA_AV_SCB *p_scb, tBTA_AV_DATA *p_data);
    715 extern void bta_av_str_stopped (tBTA_AV_SCB *p_scb, tBTA_AV_DATA *p_data);
    716 extern void bta_av_reconfig (tBTA_AV_SCB *p_scb, tBTA_AV_DATA *p_data);
    717 extern void bta_av_data_path (tBTA_AV_SCB *p_scb, tBTA_AV_DATA *p_data);
    718 extern void bta_av_start_ok (tBTA_AV_SCB *p_scb, tBTA_AV_DATA *p_data);
    719 extern void bta_av_start_failed (tBTA_AV_SCB *p_scb, tBTA_AV_DATA *p_data);
    720 extern void bta_av_str_closed (tBTA_AV_SCB *p_scb, tBTA_AV_DATA *p_data);
    721 extern void bta_av_clr_cong (tBTA_AV_SCB *p_scb, tBTA_AV_DATA *p_data);
    722 extern void bta_av_suspend_cfm (tBTA_AV_SCB *p_scb, tBTA_AV_DATA *p_data);
    723 extern void bta_av_rcfg_str_ok (tBTA_AV_SCB *p_scb, tBTA_AV_DATA *p_data);
    724 extern void bta_av_rcfg_failed (tBTA_AV_SCB *p_scb, tBTA_AV_DATA *p_data);
    725 extern void bta_av_rcfg_connect (tBTA_AV_SCB *p_scb, tBTA_AV_DATA *p_data);
    726 extern void bta_av_rcfg_discntd (tBTA_AV_SCB *p_scb, tBTA_AV_DATA *p_data);
    727 extern void bta_av_suspend_cont (tBTA_AV_SCB *p_scb, tBTA_AV_DATA *p_data);
    728 extern void bta_av_rcfg_cfm (tBTA_AV_SCB *p_scb, tBTA_AV_DATA *p_data);
    729 extern void bta_av_rcfg_open (tBTA_AV_SCB *p_scb, tBTA_AV_DATA *p_data);
    730 extern void bta_av_security_rej (tBTA_AV_SCB *p_scb, tBTA_AV_DATA *p_data);
    731 extern void bta_av_open_rc (tBTA_AV_SCB *p_scb, tBTA_AV_DATA *p_data);
    732 extern void bta_av_chk_2nd_start (tBTA_AV_SCB *p_scb, tBTA_AV_DATA *p_data);
    733 extern void bta_av_save_caps (tBTA_AV_SCB *p_scb, tBTA_AV_DATA *p_data);
    734 extern void bta_av_rej_conn (tBTA_AV_SCB *p_scb, tBTA_AV_DATA *p_data);
    735 extern void bta_av_rej_conn (tBTA_AV_SCB *p_scb, tBTA_AV_DATA *p_data);
    736 extern void bta_av_set_use_rc (tBTA_AV_SCB *p_scb, tBTA_AV_DATA *p_data);
    737 extern void bta_av_cco_close (tBTA_AV_SCB *p_scb, tBTA_AV_DATA *p_data);
    738 extern void bta_av_switch_role (tBTA_AV_SCB *p_scb, tBTA_AV_DATA *p_data);
    739 extern void bta_av_role_res (tBTA_AV_SCB *p_scb, tBTA_AV_DATA *p_data);
    740 extern void bta_av_delay_co (tBTA_AV_SCB *p_scb, tBTA_AV_DATA *p_data);
    741 extern void bta_av_open_at_inc (tBTA_AV_SCB *p_scb, tBTA_AV_DATA *p_data);
    742 extern void bta_av_offload_req (tBTA_AV_SCB *p_scb, tBTA_AV_DATA *p_data);
    743 extern void bta_av_offload_rsp (tBTA_AV_SCB *p_scb, tBTA_AV_DATA *p_data);
    744 
    745 
    746 /* ssm action functions - vdp specific */
    747 extern void bta_av_do_disc_vdp (tBTA_AV_SCB *p_scb, tBTA_AV_DATA *p_data);
    748 extern void bta_av_vdp_str_opened (tBTA_AV_SCB *p_scb, tBTA_AV_DATA *p_data);
    749 extern void bta_av_reg_vdp (tAVDT_CS *p_cs, char *p_service_name, void *p_data);
    750 
    751 #endif /* BTA_AV_INT_H */
    752