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 "gki.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 /******************************************************************************* 103 ** Public functions 104 *******************************************************************************/ 105 106 /******************************************************************************* 107 ** 108 ** Function btif_av_task 109 ** 110 ** Description 111 ** 112 ** Returns void 113 ** 114 *******************************************************************************/ 115 extern void btif_media_task(void); 116 117 /******************************************************************************* 118 ** 119 ** Function btif_media_task_enc_init_req 120 ** 121 ** Description Request to initialize the media task encoder 122 ** 123 ** Returns TRUE is success 124 ** 125 *******************************************************************************/ 126 extern BOOLEAN btif_media_task_enc_init_req(tBTIF_MEDIA_INIT_AUDIO * p_msg); 127 128 /******************************************************************************* 129 ** 130 ** Function btif_media_task_enc_update_req 131 ** 132 ** Description Request to update the media task encoder 133 ** 134 ** Returns TRUE is success 135 ** 136 *******************************************************************************/ 137 #if (BTA_AV_INCLUDED == TRUE) 138 extern BOOLEAN btif_media_task_enc_update_req(tBTIF_MEDIA_UPDATE_AUDIO * p_msg); 139 #endif 140 141 /******************************************************************************* 142 ** 143 ** Function btif_media_task_start_aa_req 144 ** 145 ** Description Request to start audio encoding task 146 ** 147 ** Returns TRUE is success 148 ** 149 *******************************************************************************/ 150 extern BOOLEAN btif_media_task_start_aa_req(void); 151 152 /******************************************************************************* 153 ** 154 ** Function btif_media_task_stop_aa_req 155 ** 156 ** Description Request to stop audio encoding task 157 ** 158 ** Returns TRUE is success 159 ** 160 *******************************************************************************/ 161 extern BOOLEAN btif_media_task_stop_aa_req(void); 162 163 /******************************************************************************* 164 ** 165 ** Function btif_media_task_aa_rx_flush_req 166 ** 167 ** Description Request to flush audio decoding pipe 168 ** 169 ** Returns TRUE is success 170 ** 171 *******************************************************************************/ 172 extern BOOLEAN btif_media_task_aa_rx_flush_req(void); 173 /******************************************************************************* 174 ** 175 ** Function btif_media_task_aa_tx_flush_req 176 ** 177 ** Description Request to flush audio encoding pipe 178 ** 179 ** Returns TRUE is success 180 ** 181 *******************************************************************************/ 182 extern BOOLEAN btif_media_task_aa_tx_flush_req(void); 183 184 /******************************************************************************* 185 ** 186 ** Function btif_media_aa_readbuf 187 ** 188 ** Description Read an audio GKI buffer from the BTIF media TX queue 189 ** 190 ** Returns pointer on a GKI aa buffer ready to send 191 ** 192 *******************************************************************************/ 193 extern BT_HDR *btif_media_aa_readbuf(void); 194 195 /******************************************************************************* 196 ** 197 ** Function btif_media_sink_enque_buf 198 ** 199 ** Description This function is called by the av_co to fill A2DP Sink Queue 200 ** 201 ** 202 ** Returns size of the queue 203 *******************************************************************************/ 204 UINT8 btif_media_sink_enque_buf(BT_HDR *p_buf); 205 206 207 208 /******************************************************************************* 209 ** 210 ** Function btif_media_aa_writebuf 211 ** 212 ** Description Enqueue a Advance Audio media GKI buffer to be processed by btif media task. 213 ** 214 ** Returns TRUE is success 215 ** 216 *******************************************************************************/ 217 extern void btif_media_aa_writebuf(BT_HDR *pBuf, UINT32 timestamp, UINT16 seq_num); 218 219 /******************************************************************************* 220 ** 221 ** Function btif_media_av_writebuf 222 ** 223 ** Description Enqueue a video media GKI buffer to be processed by btif media task. 224 ** 225 ** Returns TRUE is success 226 ** 227 *******************************************************************************/ 228 extern BOOLEAN btif_media_av_writebuf(UINT8 *p_media, UINT32 media_len, 229 UINT32 timestamp, UINT16 seq_num); 230 231 #if (BTA_AV_INCLUDED == TRUE) 232 /******************************************************************************* 233 ** 234 ** Function btif_media_task_audio_feeding_init_req 235 ** 236 ** Description Request to initialize audio feeding 237 ** 238 ** Returns TRUE is success 239 ** 240 *******************************************************************************/ 241 242 extern BOOLEAN btif_media_task_audio_feeding_init_req(tBTIF_MEDIA_INIT_AUDIO_FEEDING *p_msg); 243 #endif 244 245 /******************************************************************************* 246 ** 247 ** Function dump_codec_info 248 ** 249 ** Description Decode and display codec_info (for debug) 250 ** 251 ** Returns void 252 ** 253 *******************************************************************************/ 254 extern void dump_codec_info(unsigned char *p_codec); 255 256 /** 257 * Local adaptation helper functions between btif and media task 258 */ 259 260 bool btif_a2dp_start_media_task(void); 261 void btif_a2dp_stop_media_task(void); 262 263 void btif_a2dp_on_init(void); 264 void btif_a2dp_setup_codec(void); 265 void btif_a2dp_on_idle(void); 266 void btif_a2dp_on_open(void); 267 BOOLEAN btif_a2dp_on_started(tBTA_AV_START *p_av, BOOLEAN pending_start); 268 void btif_a2dp_ack_fail(void); 269 void btif_a2dp_on_stop_req(void); 270 void btif_a2dp_on_stopped(tBTA_AV_SUSPEND *p_av); 271 void btif_a2dp_on_suspend(void); 272 void btif_a2dp_on_suspended(tBTA_AV_SUSPEND *p_av); 273 void btif_a2dp_set_tx_flush(BOOLEAN enable); 274 void btif_a2dp_set_rx_flush(BOOLEAN enable); 275 void btif_media_check_iop_exceptions(UINT8 *peer_bda); 276 void btif_reset_decoder(UINT8 *p_av); 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