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