Home | History | Annotate | Download | only in include
      1 /******************************************************************************
      2  *
      3  *  Copyright (C) 2009-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  *  Filename:      btif_media.h
     22  *
     23  *  Description:   This is the audio module for the BTIF system.
     24  *
     25  *******************************************************************************/
     26 
     27 #ifndef BTIF_MEDIA_H
     28 #define BTIF_MEDIA_H
     29 
     30 #include "bta_api.h"
     31 #include "bd.h"
     32 #include "gki.h"
     33 #include "btif_av_api.h"
     34 #include "audio_a2dp_hw.h"
     35 
     36 /*******************************************************************************
     37  **  Constants
     38  *******************************************************************************/
     39 
     40 /* Generic part */
     41 #define BTIF_SUCCESS                         0
     42 
     43 /**
     44  * AV (Audio Video source) Errors
     45  */
     46 #define BTIF_ERROR_SRV_AV_NOT_ENABLED        700     /* AV is not enabled */
     47 #define BTIF_ERROR_SRV_AV_FEEDING_NOT_SUPPORTED 701  /* Requested Feeding not supported */
     48 #define BTIF_ERROR_SRV_AV_BUSY               702     /* Another operation ongoing */
     49 #define BTIF_ERROR_SRV_AV_NOT_OPENED         703     /* No AV link opened */
     50 #define BTIF_ERROR_SRV_AV_NOT_STARTED        704     /* AV is not started */
     51 #define BTIF_ERROR_SRV_AV_CP_NOT_SUPPORTED   705     /* Content protection is not supported by all headsets */
     52 
     53 /* Transcoding definition for TxTranscoding and RxTranscoding */
     54 #define BTIF_MEDIA_TRSCD_OFF             0
     55 #define BTIF_MEDIA_TRSCD_PCM_2_SBC       1  /* Tx */
     56 
     57 
     58 /*******************************************************************************
     59  **  Data types
     60  *******************************************************************************/
     61 
     62 typedef int tBTIF_STATUS;
     63 
     64 /* tBTIF_MEDIA_INIT_AUDIO msg structure */
     65 typedef struct
     66 {
     67         BT_HDR hdr;
     68         UINT16 SamplingFreq; /* 16k, 32k, 44.1k or 48k*/
     69         UINT8 ChannelMode; /* mono, dual, stereo or joint stereo*/
     70         UINT8 NumOfSubBands; /* 4 or 8 */
     71         UINT8 NumOfBlocks; /* 4, 8, 12 or 16*/
     72         UINT8 AllocationMethod; /* loudness or SNR*/
     73         UINT16 MtuSize; /* peer mtu size */
     74 } tBTIF_MEDIA_INIT_AUDIO;
     75 
     76 #if (BTA_AV_INCLUDED == TRUE)
     77 /* tBTIF_MEDIA_UPDATE_AUDIO msg structure */
     78 typedef struct
     79 {
     80         BT_HDR hdr;
     81         UINT16 MinMtuSize; /* Minimum peer mtu size */
     82         UINT8 MaxBitPool; /* Maximum peer bitpool */
     83         UINT8 MinBitPool; /* Minimum peer bitpool */
     84 } tBTIF_MEDIA_UPDATE_AUDIO;
     85 
     86 /* tBTIF_MEDIA_INIT_AUDIO_FEEDING msg structure */
     87 typedef struct
     88 {
     89         BT_HDR hdr;
     90         tBTIF_AV_FEEDING_MODE feeding_mode;
     91         tBTIF_AV_MEDIA_FEEDINGS feeding;
     92 } tBTIF_MEDIA_INIT_AUDIO_FEEDING;
     93 
     94 typedef struct
     95 {
     96         BT_HDR hdr;
     97         UINT8 codec_info[AVDT_CODEC_SIZE];
     98 } tBTIF_MEDIA_SINK_CFG_UPDATE;
     99 #endif
    100 
    101 /*******************************************************************************
    102  **  Public functions
    103  *******************************************************************************/
    104 
    105 /*******************************************************************************
    106  **
    107  ** Function         btif_av_task
    108  **
    109  ** Description
    110  **
    111  ** Returns          void
    112  **
    113  *******************************************************************************/
    114 extern int btif_media_task(void *p);
    115 
    116 /*******************************************************************************
    117  **
    118  ** Function         btif_media_task_enc_init_req
    119  **
    120  ** Description      Request to initialize the media task encoder
    121  **
    122  ** Returns          TRUE is success
    123  **
    124  *******************************************************************************/
    125 extern BOOLEAN btif_media_task_enc_init_req(tBTIF_MEDIA_INIT_AUDIO * p_msg);
    126 
    127 /*******************************************************************************
    128  **
    129  ** Function         btif_media_task_enc_update_req
    130  **
    131  ** Description      Request to update the media task encoder
    132  **
    133  ** Returns          TRUE is success
    134  **
    135  *******************************************************************************/
    136 #if (BTA_AV_INCLUDED == TRUE)
    137 extern BOOLEAN btif_media_task_enc_update_req(tBTIF_MEDIA_UPDATE_AUDIO * p_msg);
    138 #endif
    139 
    140 /*******************************************************************************
    141  **
    142  ** Function         btif_media_task_start_aa_req
    143  **
    144  ** Description      Request to start audio encoding task
    145  **
    146  ** Returns          TRUE is success
    147  **
    148  *******************************************************************************/
    149 extern BOOLEAN btif_media_task_start_aa_req(void);
    150 
    151 /*******************************************************************************
    152  **
    153  ** Function         btif_media_task_stop_aa_req
    154  **
    155  ** Description      Request to stop audio encoding task
    156  **
    157  ** Returns          TRUE is success
    158  **
    159  *******************************************************************************/
    160 extern BOOLEAN btif_media_task_stop_aa_req(void);
    161 
    162 /*******************************************************************************
    163  **
    164  ** Function         btif_media_task_aa_rx_flush_req
    165  **
    166  ** Description      Request to flush audio decoding pipe
    167  **
    168  ** Returns          TRUE is success
    169  **
    170  *******************************************************************************/
    171 extern BOOLEAN btif_media_task_aa_rx_flush_req(void);
    172 /*******************************************************************************
    173  **
    174  ** Function         btif_media_task_aa_tx_flush_req
    175  **
    176  ** Description      Request to flush audio encoding pipe
    177  **
    178  ** Returns          TRUE is success
    179  **
    180  *******************************************************************************/
    181 extern BOOLEAN btif_media_task_aa_tx_flush_req(void);
    182 
    183 /*******************************************************************************
    184  **
    185  ** Function         btif_media_aa_readbuf
    186  **
    187  ** Description      Read an audio GKI buffer from the BTIF media TX queue
    188  **
    189  ** Returns          pointer on a GKI aa buffer ready to send
    190  **
    191  *******************************************************************************/
    192 extern BT_HDR *btif_media_aa_readbuf(void);
    193 
    194 /*******************************************************************************
    195  **
    196  ** Function         btif_media_sink_enque_buf
    197  **
    198  ** Description      This function is called by the av_co to fill A2DP Sink Queue
    199  **
    200  **
    201  ** Returns          size of the queue
    202  *******************************************************************************/
    203  UINT8 btif_media_sink_enque_buf(BT_HDR *p_buf);
    204 
    205 
    206 
    207 /*******************************************************************************
    208  **
    209  ** Function         btif_media_aa_writebuf
    210  **
    211  ** Description      Enqueue a Advance Audio media GKI buffer to be processed by btif media task.
    212  **
    213  ** Returns          TRUE is success
    214  **
    215  *******************************************************************************/
    216 extern void btif_media_aa_writebuf(BT_HDR *pBuf, UINT32 timestamp, UINT16 seq_num);
    217 
    218 /*******************************************************************************
    219  **
    220  ** Function         btif_media_av_writebuf
    221  **
    222  ** Description      Enqueue a video media GKI buffer to be processed by btif media task.
    223  **
    224  ** Returns          TRUE is success
    225  **
    226  *******************************************************************************/
    227 extern BOOLEAN btif_media_av_writebuf(UINT8 *p_media, UINT32 media_len,
    228                                      UINT32 timestamp, UINT16 seq_num);
    229 
    230 #if (BTA_AV_INCLUDED == TRUE)
    231 /*******************************************************************************
    232  **
    233  ** Function         btif_media_task_audio_feeding_init_req
    234  **
    235  ** Description      Request to initialize audio feeding
    236  **
    237  ** Returns          TRUE is success
    238  **
    239  *******************************************************************************/
    240 
    241 extern BOOLEAN btif_media_task_audio_feeding_init_req(tBTIF_MEDIA_INIT_AUDIO_FEEDING *p_msg);
    242 #endif
    243 
    244 /*******************************************************************************
    245  **
    246  ** Function         dump_codec_info
    247  **
    248  ** Description      Decode and display codec_info (for debug)
    249  **
    250  ** Returns          void
    251  **
    252  *******************************************************************************/
    253 extern void dump_codec_info(unsigned char *p_codec);
    254 
    255 /**
    256  * Local adaptation helper functions between btif and media task
    257  */
    258 
    259 int btif_a2dp_start_media_task(void);
    260 void btif_a2dp_stop_media_task(void);
    261 
    262 void btif_a2dp_on_init(void);
    263 void btif_a2dp_setup_codec(void);
    264 void btif_a2dp_on_idle(void);
    265 void btif_a2dp_on_open(void);
    266 BOOLEAN btif_a2dp_on_started(tBTA_AV_START *p_av, BOOLEAN pending_start);
    267 void btif_a2dp_ack_fail(void);
    268 void btif_a2dp_on_stop_req(void);
    269 void btif_a2dp_on_stopped(tBTA_AV_SUSPEND *p_av);
    270 void btif_a2dp_on_suspend(void);
    271 void btif_a2dp_on_suspended(tBTA_AV_SUSPEND *p_av);
    272 void btif_a2dp_set_tx_flush(BOOLEAN enable);
    273 void btif_a2dp_set_rx_flush(BOOLEAN enable);
    274 void btif_media_check_iop_exceptions(UINT8 *peer_bda);
    275 void btif_reset_decoder(UINT8 *p_av);
    276 BOOLEAN btif_media_task_start_decoding_req(void);
    277 
    278 int btif_a2dp_get_track_frequency(UINT8 frequency);
    279 int btif_a2dp_get_track_channel_count(UINT8 channeltype);
    280 void btif_a2dp_set_peer_sep(UINT8 sep);
    281 
    282 #endif
    283