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