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