1 // Copyright 2015-2016 Espressif Systems (Shanghai) PTE LTD 2 // 3 // Licensed under the Apache License, Version 2.0 (the "License"); 4 // you may not use this file except in compliance with the License. 5 // You may obtain a copy of the License at 6 7 // http://www.apache.org/licenses/LICENSE-2.0 8 // 9 // Unless required by applicable law or agreed to in writing, software 10 // distributed under the License is distributed on an "AS IS" BASIS, 11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 // See the License for the specific language governing permissions and 13 // limitations under the License. 14 15 /******************************************************************************* 16 * 17 * Filename: btc_a2dp_source.h 18 * 19 *******************************************************************************/ 20 21 #ifndef __BTC_A2DP_SOURCE_H__ 22 #define __BTC_A2DP_SOURCE_H__ 23 24 #include <stdbool.h> 25 #include "common/bt_target.h" 26 #include "bta/bta_api.h" 27 #include "btc_av_api.h" 28 #include "esp_a2dp_api.h" 29 30 #if BTC_AV_SRC_INCLUDED 31 /******************************************************************************* 32 ** Data types 33 *******************************************************************************/ 34 35 /* tBTC_MEDIA_INIT_AUDIO msg structure */ 36 typedef struct { 37 BT_HDR hdr; 38 UINT16 SamplingFreq; /* 16k, 32k, 44.1k or 48k*/ 39 UINT8 ChannelMode; /* mono, dual, stereo or joint stereo*/ 40 UINT8 NumOfSubBands; /* 4 or 8 */ 41 UINT8 NumOfBlocks; /* 4, 8, 12 or 16*/ 42 UINT8 AllocationMethod; /* loudness or SNR*/ 43 UINT16 MtuSize; /* peer mtu size */ 44 } tBTC_MEDIA_INIT_AUDIO; 45 46 /* tBTC_MEDIA_UPDATE_AUDIO msg structure */ 47 typedef struct { 48 BT_HDR hdr; 49 UINT16 MinMtuSize; /* Minimum peer mtu size */ 50 UINT8 MaxBitPool; /* Maximum peer bitpool */ 51 UINT8 MinBitPool; /* Minimum peer bitpool */ 52 } tBTC_MEDIA_UPDATE_AUDIO; 53 54 /* tBTC_MEDIA_INIT_AUDIO_FEEDING msg structure */ 55 typedef struct { 56 BT_HDR hdr; 57 tBTC_AV_FEEDING_MODE feeding_mode; 58 tBTC_AV_MEDIA_FEEDINGS feeding; 59 } tBTC_MEDIA_INIT_AUDIO_FEEDING; 60 61 /******************************************************************************* 62 ** Public functions 63 *******************************************************************************/ 64 65 /******************************************************************************* 66 ** 67 ** Function btc_a2dp_source_startup 68 ** 69 ** Description Initialize and startup the A2DP source module. This function 70 ** should be called by the BTC AV state machine prior to using 71 ** the module 72 ** 73 ** Returns TRUE is success 74 ** 75 *******************************************************************************/ 76 bool btc_a2dp_source_startup(void); 77 78 /******************************************************************************* 79 ** 80 ** Function btc_a2dp_source_shutdown 81 ** 82 ** Description Shutdown and cleanup the A2DP source module. 83 ** 84 *******************************************************************************/ 85 void btc_a2dp_source_shutdown(void); 86 87 /******************************************************************************* 88 ** 89 ** Function btc_a2dp_source_enc_init_req 90 ** 91 ** Description Request to initialize the media task encoder 92 ** 93 ** Returns TRUE is success 94 ** 95 *******************************************************************************/ 96 BOOLEAN btc_a2dp_source_enc_init_req(tBTC_MEDIA_INIT_AUDIO *p_msg); 97 98 /******************************************************************************* 99 ** 100 ** Function btc_a2dp_source_enc_udpate_req 101 ** 102 ** Description Request to update the media task encoder 103 ** 104 ** Returns TRUE is success 105 ** 106 *******************************************************************************/ 107 BOOLEAN btc_a2dp_source_enc_update_req(tBTC_MEDIA_UPDATE_AUDIO *p_msg); 108 109 110 /******************************************************************************* 111 ** 112 ** Function btc_a2dp_source_start_audio_req 113 ** 114 ** Description Request to start audio encoding task 115 ** 116 ** Returns TRUE is success 117 ** 118 *******************************************************************************/ 119 BOOLEAN btc_a2dp_source_start_audio_req(void); 120 121 /******************************************************************************* 122 ** 123 ** Function btc_a2dp_source_stop_audio_req 124 ** 125 ** Description Request to stop audio encoding task 126 ** 127 ** Returns TRUE is success 128 ** 129 *******************************************************************************/ 130 BOOLEAN btc_a2dp_source_stop_audio_req(void); 131 132 /******************************************************************************* 133 ** 134 ** Function btc_a2dp_source_tx_flush_req 135 ** 136 ** Description Request to flush audio encoding pipe 137 ** 138 ** Returns TRUE is success 139 ** 140 *******************************************************************************/ 141 BOOLEAN btc_a2dp_source_tx_flush_req(void); 142 143 /******************************************************************************* 144 ** 145 ** Function btc_a2dp_source_audio_readbuf 146 ** 147 ** Description Read an audio buffer from the BTC media TX queue 148 ** 149 ** Returns pointer on a aa buffer ready to send 150 ** 151 *******************************************************************************/ 152 BT_HDR *btc_a2dp_source_audio_readbuf(void); 153 154 /******************************************************************************* 155 ** 156 ** Function btc_a2dp_source_audio_feeding_init_req 157 ** 158 ** Description Request to initialize audio feeding 159 ** 160 ** Returns TRUE if success 161 ** 162 *******************************************************************************/ 163 164 BOOLEAN btc_a2dp_source_audio_feeding_init_req(tBTC_MEDIA_INIT_AUDIO_FEEDING *p_msg); 165 166 /******************************************************************************* 167 ** 168 ** Function btc_a2dp_source_is_streaming 169 ** 170 ** Description Check whether A2DP source is in streaming state 171 ** 172 *******************************************************************************/ 173 bool btc_a2dp_source_is_streaming(void); 174 175 /******************************************************************************* 176 ** 177 ** Function btc_a2dp_source_is_task_shutting_down 178 ** 179 ** Description Check whether A2DP source media task is shutting down 180 ** 181 *******************************************************************************/ 182 bool btc_a2dp_source_is_task_shutting_down(void); 183 184 185 /******************************************************************************* 186 ** 187 ** Function btc_a2dp_source_on_idle 188 ** 189 ** Description Request 'idle' request from BTC AV state machine during 190 ** initialization 191 ** 192 *******************************************************************************/ 193 void btc_a2dp_source_on_idle(void); 194 195 /******************************************************************************* 196 ** 197 ** Function btc_a2dp_source_on_stopped 198 ** 199 ** Description Process 'stop' request from the BTC AV state machine to stop 200 ** A2DP streaming 201 ** 202 *******************************************************************************/ 203 void btc_a2dp_source_on_stopped(tBTA_AV_SUSPEND *p_av); 204 205 /******************************************************************************* 206 ** 207 ** Function btc_a2dp_source_on_suspended 208 ** 209 ** Description Process 'suspend' request from the BTC AV state machine to stop 210 ** A2DP streaming 211 ** 212 *******************************************************************************/ 213 void btc_a2dp_source_on_suspended(tBTA_AV_SUSPEND *p_av); 214 215 /******************************************************************************* 216 ** 217 ** Function btc_a2dp_source_setup_codec 218 ** 219 ** Description initialize the encoder parameters 220 ** 221 *******************************************************************************/ 222 void btc_a2dp_source_setup_codec(void); 223 224 /******************************************************************************* 225 ** 226 ** Function btc_a2dp_source_set_tx_flush 227 ** 228 ** Description enable/disable discarding of transmitted frames 229 ** 230 *******************************************************************************/ 231 void btc_a2dp_source_set_tx_flush(BOOLEAN enable); 232 233 /******************************************************************************* 234 ** 235 ** Function btc_a2dp_source_encoder_update 236 ** 237 ** Description update changed SBC encoder parameters 238 ** 239 *******************************************************************************/ 240 void btc_a2dp_source_encoder_update(void); 241 242 #endif /* #if BTC_AV_SRC_INCLUDED */ 243 244 #endif /* __BTC_A2DP_SOURCE_H__ */ 245