andrew@webrtc.org | b015cbe | 2012-10-22 18:19:23 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (c) 2012 The WebRTC project authors. All Rights Reserved. |
| 3 | * |
| 4 | * Use of this source code is governed by a BSD-style license |
| 5 | * that can be found in the LICENSE file in the root of the source |
| 6 | * tree. An additional intellectual property rights grant can be found |
| 7 | * in the file PATENTS. All contributing project authors may |
| 8 | * be found in the AUTHORS file in the root of the source tree. |
| 9 | */ |
| 10 | |
| 11 | #ifndef WEBRTC_MODULES_AUDIO_CODING_MAIN_SOURCE_ACM_GENERIC_CODEC_H_ |
| 12 | #define WEBRTC_MODULES_AUDIO_CODING_MAIN_SOURCE_ACM_GENERIC_CODEC_H_ |
| 13 | |
turaj@webrtc.org | 4c9b819 | 2012-12-13 22:46:43 | [diff] [blame] | 14 | #include "webrtc/modules/audio_coding/main/interface/audio_coding_module_typedefs.h" |
stefan@webrtc.org | ec09fcb | 2013-09-18 12:34:05 | [diff] [blame^] | 15 | #include "webrtc/modules/audio_coding/main/source/acm_common_defs.h" |
turaj@webrtc.org | 4c9b819 | 2012-12-13 22:46:43 | [diff] [blame] | 16 | #include "webrtc/modules/audio_coding/neteq/interface/webrtc_neteq.h" |
| 17 | #include "webrtc/system_wrappers/interface/rw_lock_wrapper.h" |
| 18 | #include "webrtc/system_wrappers/interface/trace.h" |
andrew@webrtc.org | b015cbe | 2012-10-22 18:19:23 | [diff] [blame] | 19 | |
| 20 | #define MAX_FRAME_SIZE_10MSEC 6 |
| 21 | |
| 22 | // forward declaration |
| 23 | struct WebRtcVadInst; |
| 24 | struct WebRtcCngEncInst; |
| 25 | |
tina.legrand@webrtc.org | c0cf1db | 2012-11-05 09:35:51 | [diff] [blame] | 26 | namespace webrtc { |
andrew@webrtc.org | b015cbe | 2012-10-22 18:19:23 | [diff] [blame] | 27 | |
| 28 | // forward declaration |
| 29 | struct CodecInst; |
turaj@webrtc.org | ed0b4fb | 2013-09-13 23:06:59 | [diff] [blame] | 30 | |
| 31 | namespace acm1 { |
| 32 | |
tina.legrand@webrtc.org | c0cf1db | 2012-11-05 09:35:51 | [diff] [blame] | 33 | class ACMNetEQ; |
andrew@webrtc.org | b015cbe | 2012-10-22 18:19:23 | [diff] [blame] | 34 | |
tina.legrand@webrtc.org | c0cf1db | 2012-11-05 09:35:51 | [diff] [blame] | 35 | class ACMGenericCodec { |
| 36 | public: |
| 37 | /////////////////////////////////////////////////////////////////////////// |
| 38 | // Constructor of the class |
| 39 | // |
| 40 | ACMGenericCodec(); |
andrew@webrtc.org | b015cbe | 2012-10-22 18:19:23 | [diff] [blame] | 41 | |
tina.legrand@webrtc.org | c0cf1db | 2012-11-05 09:35:51 | [diff] [blame] | 42 | /////////////////////////////////////////////////////////////////////////// |
| 43 | // Destructor of the class. |
| 44 | // |
| 45 | virtual ~ACMGenericCodec(); |
andrew@webrtc.org | b015cbe | 2012-10-22 18:19:23 | [diff] [blame] | 46 | |
tina.legrand@webrtc.org | c0cf1db | 2012-11-05 09:35:51 | [diff] [blame] | 47 | /////////////////////////////////////////////////////////////////////////// |
| 48 | // ACMGenericCodec* CreateInstance(); |
| 49 | // The function will be used for FEC. It is not implemented yet. |
| 50 | // |
| 51 | virtual ACMGenericCodec* CreateInstance() = 0; |
andrew@webrtc.org | b015cbe | 2012-10-22 18:19:23 | [diff] [blame] | 52 | |
tina.legrand@webrtc.org | c0cf1db | 2012-11-05 09:35:51 | [diff] [blame] | 53 | /////////////////////////////////////////////////////////////////////////// |
pbos@webrtc.org | fbda0fc | 2013-04-09 00:28:06 | [diff] [blame] | 54 | // int16_t Encode() |
tina.legrand@webrtc.org | c0cf1db | 2012-11-05 09:35:51 | [diff] [blame] | 55 | // The function is called to perform an encoding of the audio stored in |
| 56 | // audio buffer. An encoding is performed only if enough audio, i.e. equal |
| 57 | // to the frame-size of the codec, exist. The audio frame will be processed |
| 58 | // by VAD and CN/DTX if required. There are few different cases. |
| 59 | // |
| 60 | // A) Neither VAD nor DTX is active; the frame is encoded by the encoder. |
| 61 | // |
| 62 | // B) VAD is enabled but not DTX; in this case the audio is processed by VAD |
turaj@webrtc.org | 4c9b819 | 2012-12-13 22:46:43 | [diff] [blame] | 63 | // and encoded by the encoder. The "*encoding_type" will be either |
| 64 | // "kActiveNormalEncode" or "kPassiveNormalEncode" if frame is active or |
tina.legrand@webrtc.org | c0cf1db | 2012-11-05 09:35:51 | [diff] [blame] | 65 | // passive, respectively. |
| 66 | // |
| 67 | // C) DTX is enabled; if the codec has internal VAD/DTX we just encode the |
| 68 | // frame by the encoder. Otherwise, the frame is passed through VAD and |
| 69 | // if identified as passive, then it will be processed by CN/DTX. If the |
| 70 | // frame is active it will be encoded by the encoder. |
| 71 | // |
| 72 | // This function acquires the appropriate locks and calls EncodeSafe() for |
| 73 | // the actual processing. |
| 74 | // |
| 75 | // Outputs: |
turaj@webrtc.org | 4c9b819 | 2012-12-13 22:46:43 | [diff] [blame] | 76 | // -bitstream : a buffer where bit-stream will be written to. |
| 77 | // -bitstream_len_byte : contains the length of the bit-stream in |
tina.legrand@webrtc.org | c0cf1db | 2012-11-05 09:35:51 | [diff] [blame] | 78 | // bytes. |
turaj@webrtc.org | 4c9b819 | 2012-12-13 22:46:43 | [diff] [blame] | 79 | // -timestamp : contains the RTP timestamp, this is the |
tina.legrand@webrtc.org | c0cf1db | 2012-11-05 09:35:51 | [diff] [blame] | 80 | // sampling time of the first sample encoded |
| 81 | // (measured in number of samples). |
turaj@webrtc.org | 4c9b819 | 2012-12-13 22:46:43 | [diff] [blame] | 82 | // -encoding_type : contains the type of encoding applied on the |
tina.legrand@webrtc.org | c0cf1db | 2012-11-05 09:35:51 | [diff] [blame] | 83 | // audio samples. The alternatives are |
| 84 | // (c.f. acm_common_types.h) |
| 85 | // -kNoEncoding: |
| 86 | // there was not enough data to encode. or |
| 87 | // some error has happened that we could |
| 88 | // not do encoding. |
| 89 | // -kActiveNormalEncoded: |
| 90 | // the audio frame is active and encoded by |
| 91 | // the given codec. |
| 92 | // -kPassiveNormalEncoded: |
| 93 | // the audio frame is passive but coded with |
| 94 | // the given codec (NO DTX). |
| 95 | // -kPassiveDTXWB: |
| 96 | // The audio frame is passive and used |
| 97 | // wide-band CN to encode. |
| 98 | // -kPassiveDTXNB: |
| 99 | // The audio frame is passive and used |
| 100 | // narrow-band CN to encode. |
| 101 | // |
| 102 | // Return value: |
| 103 | // -1 if error is occurred, otherwise the length of the bit-stream in |
| 104 | // bytes. |
| 105 | // |
pbos@webrtc.org | fbda0fc | 2013-04-09 00:28:06 | [diff] [blame] | 106 | int16_t Encode(uint8_t* bitstream, |
| 107 | int16_t* bitstream_len_byte, |
| 108 | uint32_t* timestamp, |
| 109 | WebRtcACMEncodingType* encoding_type); |
andrew@webrtc.org | b015cbe | 2012-10-22 18:19:23 | [diff] [blame] | 110 | |
tina.legrand@webrtc.org | c0cf1db | 2012-11-05 09:35:51 | [diff] [blame] | 111 | /////////////////////////////////////////////////////////////////////////// |
pbos@webrtc.org | fbda0fc | 2013-04-09 00:28:06 | [diff] [blame] | 112 | // int16_t Decode() |
tina.legrand@webrtc.org | c0cf1db | 2012-11-05 09:35:51 | [diff] [blame] | 113 | // This function is used to decode a given bit-stream, without engaging |
| 114 | // NetEQ. |
| 115 | // |
| 116 | // This function acquires the appropriate locks and calls DecodeSafe() for |
| 117 | // the actual processing. Please note that this is not functional yet. |
| 118 | // |
| 119 | // Inputs: |
turaj@webrtc.org | 4c9b819 | 2012-12-13 22:46:43 | [diff] [blame] | 120 | // -bitstream : a buffer where bit-stream will be read. |
| 121 | // -bitstream_len_byte : the length of the bit-stream in bytes. |
tina.legrand@webrtc.org | c0cf1db | 2012-11-05 09:35:51 | [diff] [blame] | 122 | // |
| 123 | // Outputs: |
| 124 | // -audio : pointer to a buffer where the audio will written. |
turaj@webrtc.org | 4c9b819 | 2012-12-13 22:46:43 | [diff] [blame] | 125 | // -audio_samples : number of audio samples out of decoding the given |
tina.legrand@webrtc.org | c0cf1db | 2012-11-05 09:35:51 | [diff] [blame] | 126 | // bit-stream. |
turaj@webrtc.org | 4c9b819 | 2012-12-13 22:46:43 | [diff] [blame] | 127 | // -speech_type : speech type (for future use). |
tina.legrand@webrtc.org | c0cf1db | 2012-11-05 09:35:51 | [diff] [blame] | 128 | // |
| 129 | // Return value: |
| 130 | // -1 if failed to decode, |
| 131 | // 0 if succeeded. |
| 132 | // |
pbos@webrtc.org | fbda0fc | 2013-04-09 00:28:06 | [diff] [blame] | 133 | int16_t Decode(uint8_t* bitstream, |
| 134 | int16_t bitstream_len_byte, |
| 135 | int16_t* audio, |
| 136 | int16_t* audio_samples, |
| 137 | int8_t* speech_type); |
andrew@webrtc.org | b015cbe | 2012-10-22 18:19:23 | [diff] [blame] | 138 | |
tina.legrand@webrtc.org | c0cf1db | 2012-11-05 09:35:51 | [diff] [blame] | 139 | /////////////////////////////////////////////////////////////////////////// |
| 140 | // void SplitStereoPacket() |
| 141 | // This function is used to split stereo payloads in left and right channel. |
| 142 | // Codecs which has stereo support has there own implementation of the |
| 143 | // function. |
| 144 | // |
| 145 | // Input/Output: |
| 146 | // -payload : a vector with the received payload data. |
| 147 | // The function will reorder the data so that |
| 148 | // first half holds the left channel data, and the |
| 149 | // second half the right channel data. |
| 150 | // -payload_length : length of payload in bytes. Will be changed to |
| 151 | // twice the input in case of true stereo, where |
| 152 | // we simply copy the data and return it both for |
| 153 | // left channel and right channel decoding. |
turaj@webrtc.org | 4c9b819 | 2012-12-13 22:46:43 | [diff] [blame] | 154 | // |
pbos@webrtc.org | fbda0fc | 2013-04-09 00:28:06 | [diff] [blame] | 155 | virtual void SplitStereoPacket(uint8_t* /* payload */, |
| 156 | int32_t* /* payload_length */) {} |
andrew@webrtc.org | b015cbe | 2012-10-22 18:19:23 | [diff] [blame] | 157 | |
tina.legrand@webrtc.org | c0cf1db | 2012-11-05 09:35:51 | [diff] [blame] | 158 | /////////////////////////////////////////////////////////////////////////// |
| 159 | // bool EncoderInitialized(); |
| 160 | // |
| 161 | // Return value: |
| 162 | // True if the encoder is successfully initialized, |
| 163 | // false otherwise. |
| 164 | // |
| 165 | bool EncoderInitialized(); |
andrew@webrtc.org | b015cbe | 2012-10-22 18:19:23 | [diff] [blame] | 166 | |
tina.legrand@webrtc.org | c0cf1db | 2012-11-05 09:35:51 | [diff] [blame] | 167 | /////////////////////////////////////////////////////////////////////////// |
| 168 | // bool DecoderInitialized(); |
| 169 | // |
| 170 | // Return value: |
| 171 | // True if the decoder is successfully initialized, |
| 172 | // false otherwise. |
| 173 | // |
| 174 | bool DecoderInitialized(); |
andrew@webrtc.org | b015cbe | 2012-10-22 18:19:23 | [diff] [blame] | 175 | |
tina.legrand@webrtc.org | c0cf1db | 2012-11-05 09:35:51 | [diff] [blame] | 176 | /////////////////////////////////////////////////////////////////////////// |
pbos@webrtc.org | fbda0fc | 2013-04-09 00:28:06 | [diff] [blame] | 177 | // int16_t EncoderParams() |
tina.legrand@webrtc.org | c0cf1db | 2012-11-05 09:35:51 | [diff] [blame] | 178 | // It is called to get encoder parameters. It will call |
| 179 | // EncoderParamsSafe() in turn. |
| 180 | // |
| 181 | // Output: |
turaj@webrtc.org | 4c9b819 | 2012-12-13 22:46:43 | [diff] [blame] | 182 | // -enc_params : a buffer where the encoder parameters is |
tina.legrand@webrtc.org | c0cf1db | 2012-11-05 09:35:51 | [diff] [blame] | 183 | // written to. If the encoder is not |
| 184 | // initialized this buffer is filled with |
| 185 | // invalid values |
| 186 | // Return value: |
| 187 | // -1 if the encoder is not initialized, |
| 188 | // 0 otherwise. |
| 189 | // |
pbos@webrtc.org | fbda0fc | 2013-04-09 00:28:06 | [diff] [blame] | 190 | int16_t EncoderParams(WebRtcACMCodecParams *enc_params); |
andrew@webrtc.org | b015cbe | 2012-10-22 18:19:23 | [diff] [blame] | 191 | |
tina.legrand@webrtc.org | c0cf1db | 2012-11-05 09:35:51 | [diff] [blame] | 192 | /////////////////////////////////////////////////////////////////////////// |
pbos@webrtc.org | fbda0fc | 2013-04-09 00:28:06 | [diff] [blame] | 193 | // int16_t DecoderParams(...) |
tina.legrand@webrtc.org | c0cf1db | 2012-11-05 09:35:51 | [diff] [blame] | 194 | // It is called to get decoder parameters. It will call DecoderParamsSafe() |
| 195 | // in turn. |
| 196 | // |
| 197 | // Output: |
turaj@webrtc.org | 4c9b819 | 2012-12-13 22:46:43 | [diff] [blame] | 198 | // -dec_params : a buffer where the decoder parameters is |
tina.legrand@webrtc.org | c0cf1db | 2012-11-05 09:35:51 | [diff] [blame] | 199 | // written to. If the decoder is not initialized |
| 200 | // this buffer is filled with invalid values |
| 201 | // |
| 202 | // Return value: |
| 203 | // -1 if the decoder is not initialized, |
| 204 | // 0 otherwise. |
| 205 | // |
| 206 | // |
turaj@webrtc.org | 4c9b819 | 2012-12-13 22:46:43 | [diff] [blame] | 207 | bool DecoderParams(WebRtcACMCodecParams *dec_params, |
pbos@webrtc.org | fbda0fc | 2013-04-09 00:28:06 | [diff] [blame] | 208 | const uint8_t payload_type); |
andrew@webrtc.org | b015cbe | 2012-10-22 18:19:23 | [diff] [blame] | 209 | |
tina.legrand@webrtc.org | c0cf1db | 2012-11-05 09:35:51 | [diff] [blame] | 210 | /////////////////////////////////////////////////////////////////////////// |
pbos@webrtc.org | fbda0fc | 2013-04-09 00:28:06 | [diff] [blame] | 211 | // int16_t InitEncoder(...) |
tina.legrand@webrtc.org | c0cf1db | 2012-11-05 09:35:51 | [diff] [blame] | 212 | // This function is called to initialize the encoder with the given |
| 213 | // parameters. |
| 214 | // |
| 215 | // Input: |
turaj@webrtc.org | 4c9b819 | 2012-12-13 22:46:43 | [diff] [blame] | 216 | // -codec_params : parameters of encoder. |
| 217 | // -force_initialization: if false the initialization is invoked only if |
| 218 | // the encoder is not initialized. If true the |
| 219 | // encoder is forced to (re)initialize. |
tina.legrand@webrtc.org | c0cf1db | 2012-11-05 09:35:51 | [diff] [blame] | 220 | // |
| 221 | // Return value: |
| 222 | // 0 if could initialize successfully, |
| 223 | // -1 if failed to initialize. |
| 224 | // |
| 225 | // |
pbos@webrtc.org | fbda0fc | 2013-04-09 00:28:06 | [diff] [blame] | 226 | int16_t InitEncoder(WebRtcACMCodecParams* codec_params, |
| 227 | bool force_initialization); |
andrew@webrtc.org | b015cbe | 2012-10-22 18:19:23 | [diff] [blame] | 228 | |
tina.legrand@webrtc.org | c0cf1db | 2012-11-05 09:35:51 | [diff] [blame] | 229 | /////////////////////////////////////////////////////////////////////////// |
pbos@webrtc.org | fbda0fc | 2013-04-09 00:28:06 | [diff] [blame] | 230 | // int16_t InitDecoder() |
tina.legrand@webrtc.org | c0cf1db | 2012-11-05 09:35:51 | [diff] [blame] | 231 | // This function is called to initialize the decoder with the given |
| 232 | // parameters. (c.f. acm_common_defs.h & common_types.h for the |
| 233 | // definition of the structure) |
| 234 | // |
| 235 | // Input: |
turaj@webrtc.org | 4c9b819 | 2012-12-13 22:46:43 | [diff] [blame] | 236 | // -codec_params : parameters of decoder. |
| 237 | // -force_initialization: if false the initialization is invoked only |
| 238 | // if the decoder is not initialized. If true |
| 239 | // the encoder is forced to(re)initialize. |
tina.legrand@webrtc.org | c0cf1db | 2012-11-05 09:35:51 | [diff] [blame] | 240 | // |
| 241 | // Return value: |
| 242 | // 0 if could initialize successfully, |
| 243 | // -1 if failed to initialize. |
| 244 | // |
| 245 | // |
pbos@webrtc.org | fbda0fc | 2013-04-09 00:28:06 | [diff] [blame] | 246 | int16_t InitDecoder(WebRtcACMCodecParams* codec_params, |
| 247 | bool force_initialization); |
andrew@webrtc.org | b015cbe | 2012-10-22 18:19:23 | [diff] [blame] | 248 | |
tina.legrand@webrtc.org | c0cf1db | 2012-11-05 09:35:51 | [diff] [blame] | 249 | /////////////////////////////////////////////////////////////////////////// |
pbos@webrtc.org | fbda0fc | 2013-04-09 00:28:06 | [diff] [blame] | 250 | // int32_t RegisterInNetEq(...) |
tina.legrand@webrtc.org | c0cf1db | 2012-11-05 09:35:51 | [diff] [blame] | 251 | // This function is called to register the decoder in NetEq, with the given |
turaj@webrtc.org | 4c9b819 | 2012-12-13 22:46:43 | [diff] [blame] | 252 | // payload type. |
tina.legrand@webrtc.org | c0cf1db | 2012-11-05 09:35:51 | [diff] [blame] | 253 | // |
| 254 | // Inputs: |
turaj@webrtc.org | 4c9b819 | 2012-12-13 22:46:43 | [diff] [blame] | 255 | // -neteq : pointer to NetEq Instance |
| 256 | // -codec_inst : instance with of the codec settings of the codec |
tina.legrand@webrtc.org | c0cf1db | 2012-11-05 09:35:51 | [diff] [blame] | 257 | // |
| 258 | // Return values |
| 259 | // -1 if failed to register, |
| 260 | // 0 if successfully initialized. |
| 261 | // |
pbos@webrtc.org | fbda0fc | 2013-04-09 00:28:06 | [diff] [blame] | 262 | int32_t RegisterInNetEq(ACMNetEQ* neteq, const CodecInst& codec_inst); |
andrew@webrtc.org | b015cbe | 2012-10-22 18:19:23 | [diff] [blame] | 263 | |
tina.legrand@webrtc.org | c0cf1db | 2012-11-05 09:35:51 | [diff] [blame] | 264 | /////////////////////////////////////////////////////////////////////////// |
pbos@webrtc.org | fbda0fc | 2013-04-09 00:28:06 | [diff] [blame] | 265 | // int32_t Add10MsData(...) |
tina.legrand@webrtc.org | c0cf1db | 2012-11-05 09:35:51 | [diff] [blame] | 266 | // This function is called to add 10 ms of audio to the audio buffer of |
| 267 | // the codec. |
| 268 | // |
| 269 | // Inputs: |
turaj@webrtc.org | 4c9b819 | 2012-12-13 22:46:43 | [diff] [blame] | 270 | // -timestamp : the timestamp of the 10 ms audio. the timestamp |
tina.legrand@webrtc.org | c0cf1db | 2012-11-05 09:35:51 | [diff] [blame] | 271 | // is the sampling time of the |
| 272 | // first sample measured in number of samples. |
| 273 | // -data : a buffer that contains the audio. The codec |
| 274 | // expects to get the audio in correct sampling |
| 275 | // frequency |
| 276 | // -length : the length of the audio buffer |
turaj@webrtc.org | 4c9b819 | 2012-12-13 22:46:43 | [diff] [blame] | 277 | // -audio_channel : 0 for mono, 1 for stereo (not supported yet) |
tina.legrand@webrtc.org | c0cf1db | 2012-11-05 09:35:51 | [diff] [blame] | 278 | // |
| 279 | // Return values: |
| 280 | // -1 if failed |
| 281 | // 0 otherwise. |
| 282 | // |
pbos@webrtc.org | fbda0fc | 2013-04-09 00:28:06 | [diff] [blame] | 283 | int32_t Add10MsData(const uint32_t timestamp, |
| 284 | const int16_t* data, |
| 285 | const uint16_t length, |
| 286 | const uint8_t audio_channel); |
andrew@webrtc.org | b015cbe | 2012-10-22 18:19:23 | [diff] [blame] | 287 | |
tina.legrand@webrtc.org | c0cf1db | 2012-11-05 09:35:51 | [diff] [blame] | 288 | /////////////////////////////////////////////////////////////////////////// |
pbos@webrtc.org | fbda0fc | 2013-04-09 00:28:06 | [diff] [blame] | 289 | // uint32_t NoMissedSamples() |
tina.legrand@webrtc.org | c0cf1db | 2012-11-05 09:35:51 | [diff] [blame] | 290 | // This function returns the number of samples which are overwritten in |
| 291 | // the audio buffer. The audio samples are overwritten if the input audio |
| 292 | // buffer is full, but Add10MsData() is called. (We might remove this |
| 293 | // function if it is not used) |
| 294 | // |
| 295 | // Return Value: |
| 296 | // Number of samples which are overwritten. |
| 297 | // |
pbos@webrtc.org | fbda0fc | 2013-04-09 00:28:06 | [diff] [blame] | 298 | uint32_t NoMissedSamples() const; |
andrew@webrtc.org | b015cbe | 2012-10-22 18:19:23 | [diff] [blame] | 299 | |
tina.legrand@webrtc.org | c0cf1db | 2012-11-05 09:35:51 | [diff] [blame] | 300 | /////////////////////////////////////////////////////////////////////////// |
| 301 | // void ResetNoMissedSamples() |
| 302 | // This function resets the number of overwritten samples to zero. |
| 303 | // (We might remove this function if we remove NoMissedSamples()) |
| 304 | // |
| 305 | void ResetNoMissedSamples(); |
andrew@webrtc.org | b015cbe | 2012-10-22 18:19:23 | [diff] [blame] | 306 | |
tina.legrand@webrtc.org | c0cf1db | 2012-11-05 09:35:51 | [diff] [blame] | 307 | /////////////////////////////////////////////////////////////////////////// |
pbos@webrtc.org | fbda0fc | 2013-04-09 00:28:06 | [diff] [blame] | 308 | // int16_t SetBitRate() |
tina.legrand@webrtc.org | c0cf1db | 2012-11-05 09:35:51 | [diff] [blame] | 309 | // The function is called to set the encoding rate. |
| 310 | // |
| 311 | // Input: |
turaj@webrtc.org | 4c9b819 | 2012-12-13 22:46:43 | [diff] [blame] | 312 | // -bitrate_bps : encoding rate in bits per second |
tina.legrand@webrtc.org | c0cf1db | 2012-11-05 09:35:51 | [diff] [blame] | 313 | // |
| 314 | // Return value: |
| 315 | // -1 if failed to set the rate, due to invalid input or given |
| 316 | // codec is not rate-adjustable. |
| 317 | // 0 if the rate is adjusted successfully |
| 318 | // |
pbos@webrtc.org | fbda0fc | 2013-04-09 00:28:06 | [diff] [blame] | 319 | int16_t SetBitRate(const int32_t bitrate_bps); |
andrew@webrtc.org | b015cbe | 2012-10-22 18:19:23 | [diff] [blame] | 320 | |
tina.legrand@webrtc.org | c0cf1db | 2012-11-05 09:35:51 | [diff] [blame] | 321 | /////////////////////////////////////////////////////////////////////////// |
| 322 | // DestructEncoderInst() |
| 323 | // This API is used in conferencing. It will free the memory that is pointed |
turaj@webrtc.org | 4c9b819 | 2012-12-13 22:46:43 | [diff] [blame] | 324 | // by |ptr_inst|. |ptr_inst| is a pointer to encoder instance, created and |
tina.legrand@webrtc.org | c0cf1db | 2012-11-05 09:35:51 | [diff] [blame] | 325 | // filled up by calling EncoderInst(...). |
| 326 | // |
| 327 | // Inputs: |
turaj@webrtc.org | 4c9b819 | 2012-12-13 22:46:43 | [diff] [blame] | 328 | // -ptr_inst : pointer to an encoder instance to be deleted. |
tina.legrand@webrtc.org | c0cf1db | 2012-11-05 09:35:51 | [diff] [blame] | 329 | // |
| 330 | // |
turaj@webrtc.org | 4c9b819 | 2012-12-13 22:46:43 | [diff] [blame] | 331 | void DestructEncoderInst(void* ptr_inst); |
andrew@webrtc.org | b015cbe | 2012-10-22 18:19:23 | [diff] [blame] | 332 | |
tina.legrand@webrtc.org | c0cf1db | 2012-11-05 09:35:51 | [diff] [blame] | 333 | /////////////////////////////////////////////////////////////////////////// |
pbos@webrtc.org | fbda0fc | 2013-04-09 00:28:06 | [diff] [blame] | 334 | // int16_t AudioBuffer() |
tina.legrand@webrtc.org | c0cf1db | 2012-11-05 09:35:51 | [diff] [blame] | 335 | // This is used when synchronization of codecs is required. There are cases |
| 336 | // that the audio buffers of two codecs have to be synched. By calling this |
| 337 | // function on can get the audio buffer and other related parameters, such |
| 338 | // as timestamps... |
| 339 | // |
| 340 | // Output: |
turaj@webrtc.org | 4c9b819 | 2012-12-13 22:46:43 | [diff] [blame] | 341 | // -audio_buff : a pointer to WebRtcACMAudioBuff where the audio |
tina.legrand@webrtc.org | c0cf1db | 2012-11-05 09:35:51 | [diff] [blame] | 342 | // buffer of this codec will be written to. |
| 343 | // |
| 344 | // Return value: |
| 345 | // -1 if fails to copy the audio buffer, |
| 346 | // 0 if succeeded. |
| 347 | // |
pbos@webrtc.org | fbda0fc | 2013-04-09 00:28:06 | [diff] [blame] | 348 | int16_t AudioBuffer(WebRtcACMAudioBuff& audio_buff); |
andrew@webrtc.org | b015cbe | 2012-10-22 18:19:23 | [diff] [blame] | 349 | |
tina.legrand@webrtc.org | c0cf1db | 2012-11-05 09:35:51 | [diff] [blame] | 350 | /////////////////////////////////////////////////////////////////////////// |
pbos@webrtc.org | fbda0fc | 2013-04-09 00:28:06 | [diff] [blame] | 351 | // uint32_t EarliestTimestamp() |
tina.legrand@webrtc.org | c0cf1db | 2012-11-05 09:35:51 | [diff] [blame] | 352 | // Returns the timestamp of the first 10 ms in audio buffer. This is used |
| 353 | // to identify if a synchronization of two encoders is required. |
| 354 | // |
| 355 | // Return value: |
| 356 | // timestamp of the first 10 ms audio in the audio buffer. |
| 357 | // |
pbos@webrtc.org | fbda0fc | 2013-04-09 00:28:06 | [diff] [blame] | 358 | uint32_t EarliestTimestamp() const; |
andrew@webrtc.org | b015cbe | 2012-10-22 18:19:23 | [diff] [blame] | 359 | |
tina.legrand@webrtc.org | c0cf1db | 2012-11-05 09:35:51 | [diff] [blame] | 360 | /////////////////////////////////////////////////////////////////////////// |
pbos@webrtc.org | fbda0fc | 2013-04-09 00:28:06 | [diff] [blame] | 361 | // int16_t SetAudioBuffer() |
tina.legrand@webrtc.org | c0cf1db | 2012-11-05 09:35:51 | [diff] [blame] | 362 | // This function is called to set the audio buffer and the associated |
| 363 | // parameters to a given value. |
| 364 | // |
| 365 | // Return value: |
| 366 | // -1 if fails to copy the audio buffer, |
| 367 | // 0 if succeeded. |
| 368 | // |
pbos@webrtc.org | fbda0fc | 2013-04-09 00:28:06 | [diff] [blame] | 369 | int16_t SetAudioBuffer(WebRtcACMAudioBuff& audio_buff); |
andrew@webrtc.org | b015cbe | 2012-10-22 18:19:23 | [diff] [blame] | 370 | |
tina.legrand@webrtc.org | c0cf1db | 2012-11-05 09:35:51 | [diff] [blame] | 371 | /////////////////////////////////////////////////////////////////////////// |
pbos@webrtc.org | fbda0fc | 2013-04-09 00:28:06 | [diff] [blame] | 372 | // int16_t SetVAD() |
tina.legrand@webrtc.org | 584b688 | 2013-08-27 07:33:51 | [diff] [blame] | 373 | // This is called to set VAD & DTX. If the codec has internal DTX, it will |
tina.legrand@webrtc.org | c0cf1db | 2012-11-05 09:35:51 | [diff] [blame] | 374 | // be used. If DTX is enabled and the codec does not have internal DTX, |
| 375 | // WebRtc-VAD will be used to decide if the frame is active. If DTX is |
tina.legrand@webrtc.org | 584b688 | 2013-08-27 07:33:51 | [diff] [blame] | 376 | // disabled but VAD is enabled the audio is passed through VAD to label it |
| 377 | // as active or passive, but the frame is encoded normally. However the |
tina.legrand@webrtc.org | c0cf1db | 2012-11-05 09:35:51 | [diff] [blame] | 378 | // bit-stream is labeled properly so that ACM::Process() can use this |
| 379 | // information. In case of failure, the previous states of the VAD & DTX |
| 380 | // are kept. |
| 381 | // |
tina.legrand@webrtc.org | 584b688 | 2013-08-27 07:33:51 | [diff] [blame] | 382 | // Input/Output: |
turaj@webrtc.org | 4c9b819 | 2012-12-13 22:46:43 | [diff] [blame] | 383 | // -enable_dtx : if true DTX will be enabled otherwise the DTX is |
tina.legrand@webrtc.org | c0cf1db | 2012-11-05 09:35:51 | [diff] [blame] | 384 | // disabled. If codec has internal DTX that will be |
| 385 | // used, otherwise WebRtc-CNG is used. In the latter |
| 386 | // case VAD is automatically activated. |
turaj@webrtc.org | 4c9b819 | 2012-12-13 22:46:43 | [diff] [blame] | 387 | // -enable_vad : if true WebRtc-VAD is enabled, otherwise VAD is |
tina.legrand@webrtc.org | c0cf1db | 2012-11-05 09:35:51 | [diff] [blame] | 388 | // disabled, except for the case that DTX is enabled |
| 389 | // but codec doesn't have internal DTX. In this case |
| 390 | // VAD is enabled regardless of the value of |
turaj@webrtc.org | 4c9b819 | 2012-12-13 22:46:43 | [diff] [blame] | 391 | // |enable_vad|. |
tina.legrand@webrtc.org | c0cf1db | 2012-11-05 09:35:51 | [diff] [blame] | 392 | // -mode : this specifies the aggressiveness of VAD. |
| 393 | // |
| 394 | // Return value |
| 395 | // -1 if failed to set DTX & VAD as specified, |
| 396 | // 0 if succeeded. |
| 397 | // |
tina.legrand@webrtc.org | 584b688 | 2013-08-27 07:33:51 | [diff] [blame] | 398 | int16_t SetVAD(bool* enable_dtx, |
| 399 | bool* enable_vad, |
| 400 | ACMVADMode* mode); |
andrew@webrtc.org | b015cbe | 2012-10-22 18:19:23 | [diff] [blame] | 401 | |
tina.legrand@webrtc.org | c0cf1db | 2012-11-05 09:35:51 | [diff] [blame] | 402 | /////////////////////////////////////////////////////////////////////////// |
pbos@webrtc.org | fbda0fc | 2013-04-09 00:28:06 | [diff] [blame] | 403 | // int32_t ReplaceInternalDTX() |
tina.legrand@webrtc.org | c0cf1db | 2012-11-05 09:35:51 | [diff] [blame] | 404 | // This is called to replace the codec internal DTX with WebRtc DTX. |
| 405 | // This is only valid for G729 where the user has possibility to replace |
| 406 | // AnnexB with WebRtc DTX. For other codecs this function has no effect. |
| 407 | // |
| 408 | // Input: |
turaj@webrtc.org | 4c9b819 | 2012-12-13 22:46:43 | [diff] [blame] | 409 | // -replace_internal_dtx : if true the internal DTX is replaced with WebRtc. |
tina.legrand@webrtc.org | c0cf1db | 2012-11-05 09:35:51 | [diff] [blame] | 410 | // |
| 411 | // Return value |
| 412 | // -1 if failed to replace internal DTX, |
| 413 | // 0 if succeeded. |
| 414 | // |
pbos@webrtc.org | fbda0fc | 2013-04-09 00:28:06 | [diff] [blame] | 415 | int32_t ReplaceInternalDTX(const bool replace_internal_dtx); |
andrew@webrtc.org | b015cbe | 2012-10-22 18:19:23 | [diff] [blame] | 416 | |
tina.legrand@webrtc.org | c0cf1db | 2012-11-05 09:35:51 | [diff] [blame] | 417 | /////////////////////////////////////////////////////////////////////////// |
pbos@webrtc.org | fbda0fc | 2013-04-09 00:28:06 | [diff] [blame] | 418 | // int32_t IsInternalDTXReplaced() |
tina.legrand@webrtc.org | c0cf1db | 2012-11-05 09:35:51 | [diff] [blame] | 419 | // This is called to check if the codec internal DTX is replaced by WebRtc |
| 420 | // DTX. This is only valid for G729 where the user has possibility to replace |
| 421 | // AnnexB with WebRtc DTX. For other codecs this function has no effect. |
| 422 | // |
| 423 | // Output: |
turaj@webrtc.org | 4c9b819 | 2012-12-13 22:46:43 | [diff] [blame] | 424 | // -internal_dtx_replaced: if true the internal DTX is replaced with WebRtc. |
tina.legrand@webrtc.org | c0cf1db | 2012-11-05 09:35:51 | [diff] [blame] | 425 | // |
| 426 | // Return value |
| 427 | // -1 if failed to check |
| 428 | // 0 if succeeded. |
| 429 | // |
pbos@webrtc.org | fbda0fc | 2013-04-09 00:28:06 | [diff] [blame] | 430 | int32_t IsInternalDTXReplaced(bool* internal_dtx_replaced); |
andrew@webrtc.org | b015cbe | 2012-10-22 18:19:23 | [diff] [blame] | 431 | |
tina.legrand@webrtc.org | c0cf1db | 2012-11-05 09:35:51 | [diff] [blame] | 432 | /////////////////////////////////////////////////////////////////////////// |
| 433 | // void SetNetEqDecodeLock() |
| 434 | // Passes the NetEq lock to the codec. |
| 435 | // |
| 436 | // Input: |
turaj@webrtc.org | 4c9b819 | 2012-12-13 22:46:43 | [diff] [blame] | 437 | // -neteq_decode_lock : pointer to the lock associated with NetEQ of ACM. |
tina.legrand@webrtc.org | c0cf1db | 2012-11-05 09:35:51 | [diff] [blame] | 438 | // |
turaj@webrtc.org | 4c9b819 | 2012-12-13 22:46:43 | [diff] [blame] | 439 | void SetNetEqDecodeLock(RWLockWrapper* neteq_decode_lock) { |
| 440 | neteq_decode_lock_ = neteq_decode_lock; |
tina.legrand@webrtc.org | c0cf1db | 2012-11-05 09:35:51 | [diff] [blame] | 441 | } |
andrew@webrtc.org | b015cbe | 2012-10-22 18:19:23 | [diff] [blame] | 442 | |
tina.legrand@webrtc.org | c0cf1db | 2012-11-05 09:35:51 | [diff] [blame] | 443 | /////////////////////////////////////////////////////////////////////////// |
| 444 | // bool HasInternalDTX() |
| 445 | // Used to check if the codec has internal DTX. |
| 446 | // |
| 447 | // Return value: |
| 448 | // true if the codec has an internal DTX, e.g. G729, |
| 449 | // false otherwise. |
| 450 | // |
| 451 | bool HasInternalDTX() const { |
turaj@webrtc.org | 4c9b819 | 2012-12-13 22:46:43 | [diff] [blame] | 452 | return has_internal_dtx_; |
tina.legrand@webrtc.org | c0cf1db | 2012-11-05 09:35:51 | [diff] [blame] | 453 | } |
andrew@webrtc.org | b015cbe | 2012-10-22 18:19:23 | [diff] [blame] | 454 | |
tina.legrand@webrtc.org | c0cf1db | 2012-11-05 09:35:51 | [diff] [blame] | 455 | /////////////////////////////////////////////////////////////////////////// |
pbos@webrtc.org | fbda0fc | 2013-04-09 00:28:06 | [diff] [blame] | 456 | // int32_t GetEstimatedBandwidth() |
tina.legrand@webrtc.org | c0cf1db | 2012-11-05 09:35:51 | [diff] [blame] | 457 | // Used to get decoder estimated bandwidth. Only iSAC will provide a value. |
| 458 | // |
| 459 | // |
| 460 | // Return value: |
| 461 | // -1 if fails to get decoder estimated bandwidth, |
| 462 | // >0 estimated bandwidth in bits/sec. |
| 463 | // |
pbos@webrtc.org | fbda0fc | 2013-04-09 00:28:06 | [diff] [blame] | 464 | int32_t GetEstimatedBandwidth(); |
andrew@webrtc.org | b015cbe | 2012-10-22 18:19:23 | [diff] [blame] | 465 | |
tina.legrand@webrtc.org | c0cf1db | 2012-11-05 09:35:51 | [diff] [blame] | 466 | /////////////////////////////////////////////////////////////////////////// |
pbos@webrtc.org | fbda0fc | 2013-04-09 00:28:06 | [diff] [blame] | 467 | // int32_t SetEstimatedBandwidth() |
tina.legrand@webrtc.org | c0cf1db | 2012-11-05 09:35:51 | [diff] [blame] | 468 | // Used to set estiamted bandwidth sent out of band from other side. Only |
| 469 | // iSAC will have use for the value. |
| 470 | // |
| 471 | // Input: |
turaj@webrtc.org | 4c9b819 | 2012-12-13 22:46:43 | [diff] [blame] | 472 | // -estimated_bandwidth: estimated bandwidth in bits/sec |
tina.legrand@webrtc.org | c0cf1db | 2012-11-05 09:35:51 | [diff] [blame] | 473 | // |
| 474 | // Return value: |
| 475 | // -1 if fails to set estimated bandwidth, |
| 476 | // 0 on success. |
| 477 | // |
pbos@webrtc.org | fbda0fc | 2013-04-09 00:28:06 | [diff] [blame] | 478 | int32_t SetEstimatedBandwidth(int32_t estimated_bandwidth); |
andrew@webrtc.org | b015cbe | 2012-10-22 18:19:23 | [diff] [blame] | 479 | |
tina.legrand@webrtc.org | c0cf1db | 2012-11-05 09:35:51 | [diff] [blame] | 480 | /////////////////////////////////////////////////////////////////////////// |
pbos@webrtc.org | fbda0fc | 2013-04-09 00:28:06 | [diff] [blame] | 481 | // int32_t GetRedPayload() |
tina.legrand@webrtc.org | c0cf1db | 2012-11-05 09:35:51 | [diff] [blame] | 482 | // Used to get codec specific RED payload (if such is implemented). |
| 483 | // Currently only done in iSAC. |
| 484 | // |
| 485 | // Outputs: |
turaj@webrtc.org | 4c9b819 | 2012-12-13 22:46:43 | [diff] [blame] | 486 | // -red_payload : a pointer to the data for RED payload. |
| 487 | // -payload_bytes : number of bytes in RED payload. |
tina.legrand@webrtc.org | c0cf1db | 2012-11-05 09:35:51 | [diff] [blame] | 488 | // |
| 489 | // Return value: |
| 490 | // -1 if fails to get codec specific RED, |
| 491 | // 0 if succeeded. |
| 492 | // |
pbos@webrtc.org | fbda0fc | 2013-04-09 00:28:06 | [diff] [blame] | 493 | int32_t GetRedPayload(uint8_t* red_payload, |
| 494 | int16_t* payload_bytes); |
andrew@webrtc.org | b015cbe | 2012-10-22 18:19:23 | [diff] [blame] | 495 | |
tina.legrand@webrtc.org | c0cf1db | 2012-11-05 09:35:51 | [diff] [blame] | 496 | /////////////////////////////////////////////////////////////////////////// |
pbos@webrtc.org | fbda0fc | 2013-04-09 00:28:06 | [diff] [blame] | 497 | // int16_t ResetEncoder() |
tina.legrand@webrtc.org | c0cf1db | 2012-11-05 09:35:51 | [diff] [blame] | 498 | // By calling this function you would re-initialize the encoder with the |
| 499 | // current parameters. All the settings, e.g. VAD/DTX, frame-size... should |
| 500 | // remain unchanged. (In case of iSAC we don't want to lose BWE history.) |
| 501 | // |
| 502 | // Return value |
| 503 | // -1 if failed, |
| 504 | // 0 if succeeded. |
| 505 | // |
pbos@webrtc.org | fbda0fc | 2013-04-09 00:28:06 | [diff] [blame] | 506 | int16_t ResetEncoder(); |
andrew@webrtc.org | b015cbe | 2012-10-22 18:19:23 | [diff] [blame] | 507 | |
tina.legrand@webrtc.org | c0cf1db | 2012-11-05 09:35:51 | [diff] [blame] | 508 | /////////////////////////////////////////////////////////////////////////// |
pbos@webrtc.org | fbda0fc | 2013-04-09 00:28:06 | [diff] [blame] | 509 | // int16_t ResetEncoder() |
tina.legrand@webrtc.org | c0cf1db | 2012-11-05 09:35:51 | [diff] [blame] | 510 | // By calling this function you would re-initialize the decoder with the |
| 511 | // current parameters. |
| 512 | // |
| 513 | // Return value |
| 514 | // -1 if failed, |
| 515 | // 0 if succeeded. |
| 516 | // |
pbos@webrtc.org | fbda0fc | 2013-04-09 00:28:06 | [diff] [blame] | 517 | int16_t ResetDecoder(int16_t payload_type); |
andrew@webrtc.org | b015cbe | 2012-10-22 18:19:23 | [diff] [blame] | 518 | |
tina.legrand@webrtc.org | c0cf1db | 2012-11-05 09:35:51 | [diff] [blame] | 519 | /////////////////////////////////////////////////////////////////////////// |
| 520 | // void DestructEncoder() |
| 521 | // This function is called to delete the encoder instance, if possible, to |
| 522 | // have a fresh start. For codecs where encoder and decoder share the same |
| 523 | // instance we cannot delete the encoder and instead we will initialize the |
| 524 | // encoder. We also delete VAD and DTX if they have been created. |
| 525 | // |
| 526 | void DestructEncoder(); |
andrew@webrtc.org | b015cbe | 2012-10-22 18:19:23 | [diff] [blame] | 527 | |
tina.legrand@webrtc.org | c0cf1db | 2012-11-05 09:35:51 | [diff] [blame] | 528 | /////////////////////////////////////////////////////////////////////////// |
| 529 | // void DestructDecoder() |
| 530 | // This function is called to delete the decoder instance, if possible, to |
| 531 | // have a fresh start. For codecs where encoder and decoder share the same |
| 532 | // instance we cannot delete the encoder and instead we will initialize the |
| 533 | // decoder. Before deleting decoder instance it has to be removed from the |
| 534 | // NetEq list. |
| 535 | // |
| 536 | void DestructDecoder(); |
andrew@webrtc.org | b015cbe | 2012-10-22 18:19:23 | [diff] [blame] | 537 | |
tina.legrand@webrtc.org | c0cf1db | 2012-11-05 09:35:51 | [diff] [blame] | 538 | /////////////////////////////////////////////////////////////////////////// |
pbos@webrtc.org | fbda0fc | 2013-04-09 00:28:06 | [diff] [blame] | 539 | // int16_t SamplesLeftToEncode() |
tina.legrand@webrtc.org | c0cf1db | 2012-11-05 09:35:51 | [diff] [blame] | 540 | // Returns the number of samples required to be able to do encoding. |
| 541 | // |
| 542 | // Return value: |
| 543 | // Number of samples. |
| 544 | // |
pbos@webrtc.org | fbda0fc | 2013-04-09 00:28:06 | [diff] [blame] | 545 | int16_t SamplesLeftToEncode(); |
andrew@webrtc.org | b015cbe | 2012-10-22 18:19:23 | [diff] [blame] | 546 | |
tina.legrand@webrtc.org | c0cf1db | 2012-11-05 09:35:51 | [diff] [blame] | 547 | /////////////////////////////////////////////////////////////////////////// |
pbos@webrtc.org | fbda0fc | 2013-04-09 00:28:06 | [diff] [blame] | 548 | // uint32_t LastEncodedTimestamp() |
tina.legrand@webrtc.org | c0cf1db | 2012-11-05 09:35:51 | [diff] [blame] | 549 | // Returns the timestamp of the last frame it encoded. |
| 550 | // |
| 551 | // Return value: |
| 552 | // Timestamp. |
| 553 | // |
pbos@webrtc.org | fbda0fc | 2013-04-09 00:28:06 | [diff] [blame] | 554 | uint32_t LastEncodedTimestamp() const; |
andrew@webrtc.org | b015cbe | 2012-10-22 18:19:23 | [diff] [blame] | 555 | |
tina.legrand@webrtc.org | c0cf1db | 2012-11-05 09:35:51 | [diff] [blame] | 556 | /////////////////////////////////////////////////////////////////////////// |
| 557 | // SetUniqueID() |
turaj@webrtc.org | 4c9b819 | 2012-12-13 22:46:43 | [diff] [blame] | 558 | // Set a unique ID for the codec to be used for tracing and debugging |
tina.legrand@webrtc.org | c0cf1db | 2012-11-05 09:35:51 | [diff] [blame] | 559 | // |
| 560 | // Input |
| 561 | // -id : A number to identify the codec. |
| 562 | // |
pbos@webrtc.org | fbda0fc | 2013-04-09 00:28:06 | [diff] [blame] | 563 | void SetUniqueID(const uint32_t id); |
andrew@webrtc.org | b015cbe | 2012-10-22 18:19:23 | [diff] [blame] | 564 | |
tina.legrand@webrtc.org | c0cf1db | 2012-11-05 09:35:51 | [diff] [blame] | 565 | /////////////////////////////////////////////////////////////////////////// |
| 566 | // IsAudioBufferFresh() |
| 567 | // Specifies if ever audio is injected to this codec. |
| 568 | // |
| 569 | // Return value |
| 570 | // -true; no audio is feed into this codec |
| 571 | // -false; audio has already been fed to the codec. |
| 572 | // |
| 573 | bool IsAudioBufferFresh() const; |
andrew@webrtc.org | b015cbe | 2012-10-22 18:19:23 | [diff] [blame] | 574 | |
tina.legrand@webrtc.org | c0cf1db | 2012-11-05 09:35:51 | [diff] [blame] | 575 | /////////////////////////////////////////////////////////////////////////// |
| 576 | // UpdateDecoderSampFreq() |
| 577 | // For most of the codecs this function does nothing. It must be |
| 578 | // implemented for those codecs that one codec instance serves as the |
turaj@webrtc.org | 4c9b819 | 2012-12-13 22:46:43 | [diff] [blame] | 579 | // decoder for different flavors of the codec. One example is iSAC. there, |
tina.legrand@webrtc.org | c0cf1db | 2012-11-05 09:35:51 | [diff] [blame] | 580 | // iSAC 16 kHz and iSAC 32 kHz are treated as two different codecs with |
| 581 | // different payload types, however, there is only one iSAC instance to |
| 582 | // decode. The reason for that is we would like to decode and encode with |
| 583 | // the same codec instance for bandwidth estimator to work. |
| 584 | // |
turaj@webrtc.org | 4c9b819 | 2012-12-13 22:46:43 | [diff] [blame] | 585 | // Each time that we receive a new payload type, we call this function to |
tina.legrand@webrtc.org | c0cf1db | 2012-11-05 09:35:51 | [diff] [blame] | 586 | // prepare the decoder associated with the new payload. Normally, decoders |
| 587 | // doesn't have to do anything. For iSAC the decoder has to change it's |
turaj@webrtc.org | 4c9b819 | 2012-12-13 22:46:43 | [diff] [blame] | 588 | // sampling rate. The input parameter specifies the current flavor of the |
tina.legrand@webrtc.org | c0cf1db | 2012-11-05 09:35:51 | [diff] [blame] | 589 | // codec in codec database. For instance, if we just got a SWB payload then |
| 590 | // the input parameter is ACMCodecDB::isacswb. |
| 591 | // |
| 592 | // Input: |
turaj@webrtc.org | 4c9b819 | 2012-12-13 22:46:43 | [diff] [blame] | 593 | // -codec_id : the ID of the codec associated with the |
tina.legrand@webrtc.org | c0cf1db | 2012-11-05 09:35:51 | [diff] [blame] | 594 | // payload type that we just received. |
| 595 | // |
| 596 | // Return value: |
| 597 | // 0 if succeeded in updating the decoder. |
| 598 | // -1 if failed to update. |
| 599 | // |
pbos@webrtc.org | dd1b19d | 2013-07-31 15:54:00 | [diff] [blame] | 600 | virtual int16_t UpdateDecoderSampFreq(int16_t /* codec_id */); |
andrew@webrtc.org | b015cbe | 2012-10-22 18:19:23 | [diff] [blame] | 601 | |
tina.legrand@webrtc.org | c0cf1db | 2012-11-05 09:35:51 | [diff] [blame] | 602 | /////////////////////////////////////////////////////////////////////////// |
| 603 | // UpdateEncoderSampFreq() |
| 604 | // Call this function to update the encoder sampling frequency. This |
| 605 | // is for codecs where one payload-name supports several encoder sampling |
| 606 | // frequencies. Otherwise, to change the sampling frequency we need to |
| 607 | // register new codec. ACM will consider that as registration of a new |
| 608 | // codec, not a change in parameter. For iSAC, switching from WB to SWB |
| 609 | // is treated as a change in parameter. Therefore, we need this function. |
| 610 | // |
| 611 | // Input: |
turaj@webrtc.org | 4c9b819 | 2012-12-13 22:46:43 | [diff] [blame] | 612 | // -samp_freq_hz : encoder sampling frequency. |
tina.legrand@webrtc.org | c0cf1db | 2012-11-05 09:35:51 | [diff] [blame] | 613 | // |
| 614 | // Return value: |
| 615 | // -1 if failed, or if this is meaningless for the given codec. |
| 616 | // 0 if succeeded. |
| 617 | // |
pbos@webrtc.org | fbda0fc | 2013-04-09 00:28:06 | [diff] [blame] | 618 | virtual int16_t UpdateEncoderSampFreq( |
| 619 | uint16_t samp_freq_hz); |
andrew@webrtc.org | b015cbe | 2012-10-22 18:19:23 | [diff] [blame] | 620 | |
tina.legrand@webrtc.org | c0cf1db | 2012-11-05 09:35:51 | [diff] [blame] | 621 | /////////////////////////////////////////////////////////////////////////// |
| 622 | // EncoderSampFreq() |
| 623 | // Get the sampling frequency that the encoder (WebRtc wrapper) expects. |
| 624 | // |
| 625 | // Output: |
turaj@webrtc.org | 4c9b819 | 2012-12-13 22:46:43 | [diff] [blame] | 626 | // -samp_freq_hz : sampling frequency, in Hertz, which the encoder |
tina.legrand@webrtc.org | c0cf1db | 2012-11-05 09:35:51 | [diff] [blame] | 627 | // should be fed with. |
| 628 | // |
| 629 | // Return value: |
| 630 | // -1 if failed to output sampling rate. |
| 631 | // 0 if the sample rate is returned successfully. |
| 632 | // |
pbos@webrtc.org | fbda0fc | 2013-04-09 00:28:06 | [diff] [blame] | 633 | virtual int16_t EncoderSampFreq(uint16_t& samp_freq_hz); |
andrew@webrtc.org | b015cbe | 2012-10-22 18:19:23 | [diff] [blame] | 634 | |
tina.legrand@webrtc.org | c0cf1db | 2012-11-05 09:35:51 | [diff] [blame] | 635 | /////////////////////////////////////////////////////////////////////////// |
pbos@webrtc.org | fbda0fc | 2013-04-09 00:28:06 | [diff] [blame] | 636 | // int32_t ConfigISACBandwidthEstimator() |
tina.legrand@webrtc.org | c0cf1db | 2012-11-05 09:35:51 | [diff] [blame] | 637 | // Call this function to configure the bandwidth estimator of ISAC. |
turaj@webrtc.org | 4c9b819 | 2012-12-13 22:46:43 | [diff] [blame] | 638 | // During the adaptation of bit-rate, iSAC automatically adjusts the |
tina.legrand@webrtc.org | c0cf1db | 2012-11-05 09:35:51 | [diff] [blame] | 639 | // frame-size (either 30 or 60 ms) to save on RTP header. The initial |
| 640 | // frame-size can be specified by the first argument. The configuration also |
| 641 | // regards the initial estimate of bandwidths. The estimator starts from |
| 642 | // this point and converges to the actual bottleneck. This is given by the |
| 643 | // second parameter. Furthermore, it is also possible to control the |
| 644 | // adaptation of frame-size. This is specified by the last parameter. |
| 645 | // |
| 646 | // Input: |
turaj@webrtc.org | 4c9b819 | 2012-12-13 22:46:43 | [diff] [blame] | 647 | // -init_frame_fize_ms : initial frame-size in milliseconds. For iSAC-wb |
tina.legrand@webrtc.org | c0cf1db | 2012-11-05 09:35:51 | [diff] [blame] | 648 | // 30 ms and 60 ms (default) are acceptable values, |
| 649 | // and for iSAC-swb 30 ms is the only acceptable |
turaj@webrtc.org | 4c9b819 | 2012-12-13 22:46:43 | [diff] [blame] | 650 | // value. Zero indicates default value. |
| 651 | // -init_rate_bps : initial estimate of the bandwidth. Values |
tina.legrand@webrtc.org | c0cf1db | 2012-11-05 09:35:51 | [diff] [blame] | 652 | // between 10000 and 58000 are acceptable. |
turaj@webrtc.org | 4c9b819 | 2012-12-13 22:46:43 | [diff] [blame] | 653 | // -enforce_frame_size : if true, the frame-size will not be adapted. |
tina.legrand@webrtc.org | c0cf1db | 2012-11-05 09:35:51 | [diff] [blame] | 654 | // |
| 655 | // Return value: |
| 656 | // -1 if failed to configure the bandwidth estimator, |
| 657 | // 0 if the configuration was successfully applied. |
| 658 | // |
pbos@webrtc.org | fbda0fc | 2013-04-09 00:28:06 | [diff] [blame] | 659 | virtual int32_t ConfigISACBandwidthEstimator( |
| 660 | const uint8_t init_frame_size_msec, |
| 661 | const uint16_t init_rate_bps, |
turaj@webrtc.org | 4c9b819 | 2012-12-13 22:46:43 | [diff] [blame] | 662 | const bool enforce_frame_size); |
andrew@webrtc.org | b015cbe | 2012-10-22 18:19:23 | [diff] [blame] | 663 | |
tina.legrand@webrtc.org | c0cf1db | 2012-11-05 09:35:51 | [diff] [blame] | 664 | /////////////////////////////////////////////////////////////////////////// |
| 665 | // SetISACMaxPayloadSize() |
| 666 | // Set the maximum payload size of iSAC packets. No iSAC payload, |
| 667 | // regardless of its frame-size, may exceed the given limit. For |
| 668 | // an iSAC payload of size B bits and frame-size T sec we have; |
turaj@webrtc.org | 4c9b819 | 2012-12-13 22:46:43 | [diff] [blame] | 669 | // (B < max_payload_len_bytes * 8) and (B/T < max_rate_bit_per_sec), c.f. |
tina.legrand@webrtc.org | c0cf1db | 2012-11-05 09:35:51 | [diff] [blame] | 670 | // SetISACMaxRate(). |
| 671 | // |
| 672 | // Input: |
turaj@webrtc.org | 4c9b819 | 2012-12-13 22:46:43 | [diff] [blame] | 673 | // -max_payload_len_bytes : maximum payload size in bytes. |
tina.legrand@webrtc.org | c0cf1db | 2012-11-05 09:35:51 | [diff] [blame] | 674 | // |
| 675 | // Return value: |
turaj@webrtc.org | 4c9b819 | 2012-12-13 22:46:43 | [diff] [blame] | 676 | // -1 if failed to set the maximum payload-size. |
| 677 | // 0 if the given length is set successfully. |
tina.legrand@webrtc.org | c0cf1db | 2012-11-05 09:35:51 | [diff] [blame] | 678 | // |
pbos@webrtc.org | fbda0fc | 2013-04-09 00:28:06 | [diff] [blame] | 679 | virtual int32_t SetISACMaxPayloadSize( |
| 680 | const uint16_t max_payload_len_bytes); |
andrew@webrtc.org | b015cbe | 2012-10-22 18:19:23 | [diff] [blame] | 681 | |
tina.legrand@webrtc.org | c0cf1db | 2012-11-05 09:35:51 | [diff] [blame] | 682 | /////////////////////////////////////////////////////////////////////////// |
| 683 | // SetISACMaxRate() |
| 684 | // Set the maximum instantaneous rate of iSAC. For a payload of B bits |
turaj@webrtc.org | 4c9b819 | 2012-12-13 22:46:43 | [diff] [blame] | 685 | // with a frame-size of T sec the instantaneous rate is B/T bits per |
| 686 | // second. Therefore, (B/T < max_rate_bit_per_sec) and |
| 687 | // (B < max_payload_len_bytes * 8) are always satisfied for iSAC payloads, |
tina.legrand@webrtc.org | c0cf1db | 2012-11-05 09:35:51 | [diff] [blame] | 688 | // c.f SetISACMaxPayloadSize(). |
| 689 | // |
| 690 | // Input: |
turaj@webrtc.org | 4c9b819 | 2012-12-13 22:46:43 | [diff] [blame] | 691 | // -max_rate_bps : maximum instantaneous bit-rate given in bits/sec. |
tina.legrand@webrtc.org | c0cf1db | 2012-11-05 09:35:51 | [diff] [blame] | 692 | // |
| 693 | // Return value: |
| 694 | // -1 if failed to set the maximum rate. |
| 695 | // 0 if the maximum rate is set successfully. |
| 696 | // |
pbos@webrtc.org | fbda0fc | 2013-04-09 00:28:06 | [diff] [blame] | 697 | virtual int32_t SetISACMaxRate(const uint32_t max_rate_bps); |
andrew@webrtc.org | b015cbe | 2012-10-22 18:19:23 | [diff] [blame] | 698 | |
tina.legrand@webrtc.org | c0cf1db | 2012-11-05 09:35:51 | [diff] [blame] | 699 | /////////////////////////////////////////////////////////////////////////// |
| 700 | // SaveDecoderParamS() |
| 701 | // Save the parameters of decoder. |
| 702 | // |
| 703 | // Input: |
turaj@webrtc.org | 4c9b819 | 2012-12-13 22:46:43 | [diff] [blame] | 704 | // -codec_params : pointer to a structure where the parameters of |
tina.legrand@webrtc.org | c0cf1db | 2012-11-05 09:35:51 | [diff] [blame] | 705 | // decoder is stored in. |
| 706 | // |
turaj@webrtc.org | 4c9b819 | 2012-12-13 22:46:43 | [diff] [blame] | 707 | void SaveDecoderParam(const WebRtcACMCodecParams* codec_params); |
andrew@webrtc.org | b015cbe | 2012-10-22 18:19:23 | [diff] [blame] | 708 | |
pbos@webrtc.org | fbda0fc | 2013-04-09 00:28:06 | [diff] [blame] | 709 | int32_t FrameSize() { |
turaj@webrtc.org | 4c9b819 | 2012-12-13 22:46:43 | [diff] [blame] | 710 | return frame_len_smpl_; |
tina.legrand@webrtc.org | c0cf1db | 2012-11-05 09:35:51 | [diff] [blame] | 711 | } |
andrew@webrtc.org | b015cbe | 2012-10-22 18:19:23 | [diff] [blame] | 712 | |
turaj@webrtc.org | 4c9b819 | 2012-12-13 22:46:43 | [diff] [blame] | 713 | void SetIsMaster(bool is_master); |
andrew@webrtc.org | b015cbe | 2012-10-22 18:19:23 | [diff] [blame] | 714 | |
tina.legrand@webrtc.org | c0cf1db | 2012-11-05 09:35:51 | [diff] [blame] | 715 | /////////////////////////////////////////////////////////////////////////// |
| 716 | // REDPayloadISAC() |
| 717 | // This is an iSAC-specific function. The function is called to get RED |
turaj@webrtc.org | 1952f25 | 2012-12-03 22:13:31 | [diff] [blame] | 718 | // payload from a default-encoder. |
tina.legrand@webrtc.org | c0cf1db | 2012-11-05 09:35:51 | [diff] [blame] | 719 | // |
| 720 | // Inputs: |
turaj@webrtc.org | 4c9b819 | 2012-12-13 22:46:43 | [diff] [blame] | 721 | // -isac_rate : the target rate of the main payload. A RED |
turaj@webrtc.org | 1952f25 | 2012-12-03 22:13:31 | [diff] [blame] | 722 | // payload is generated according to the rate of |
| 723 | // main payload. Note that we are not specifying the |
tina.legrand@webrtc.org | c0cf1db | 2012-11-05 09:35:51 | [diff] [blame] | 724 | // rate of RED payload, but the main payload. |
turaj@webrtc.org | 4c9b819 | 2012-12-13 22:46:43 | [diff] [blame] | 725 | // -isac_bw_estimate : bandwidth information should be inserted in |
tina.legrand@webrtc.org | c0cf1db | 2012-11-05 09:35:51 | [diff] [blame] | 726 | // RED payload. |
| 727 | // |
| 728 | // Output: |
turaj@webrtc.org | 1952f25 | 2012-12-03 22:13:31 | [diff] [blame] | 729 | // -payload : pointer to a buffer where the RED payload will |
tina.legrand@webrtc.org | c0cf1db | 2012-11-05 09:35:51 | [diff] [blame] | 730 | // written to. |
turaj@webrtc.org | 4c9b819 | 2012-12-13 22:46:43 | [diff] [blame] | 731 | // -payload_len_bytes : a place-holder to write the length of the RED |
tina.legrand@webrtc.org | c0cf1db | 2012-11-05 09:35:51 | [diff] [blame] | 732 | // payload in Bytes. |
| 733 | // |
| 734 | // Return value: |
turaj@webrtc.org | 4c9b819 | 2012-12-13 22:46:43 | [diff] [blame] | 735 | // -1 if an error occurs, otherwise the length of the payload (in Bytes) |
tina.legrand@webrtc.org | c0cf1db | 2012-11-05 09:35:51 | [diff] [blame] | 736 | // is returned. |
| 737 | // |
pbos@webrtc.org | fbda0fc | 2013-04-09 00:28:06 | [diff] [blame] | 738 | virtual int16_t REDPayloadISAC(const int32_t isac_rate, |
| 739 | const int16_t isac_bw_estimate, |
| 740 | uint8_t* payload, |
| 741 | int16_t* payload_len_bytes); |
andrew@webrtc.org | b015cbe | 2012-10-22 18:19:23 | [diff] [blame] | 742 | |
tina.legrand@webrtc.org | c0cf1db | 2012-11-05 09:35:51 | [diff] [blame] | 743 | /////////////////////////////////////////////////////////////////////////// |
| 744 | // IsTrueStereoCodec() |
| 745 | // Call to see if current encoder is a true stereo codec. This function |
| 746 | // should be overwritten for codecs which are true stereo codecs |
| 747 | // Return value: |
| 748 | // -true if stereo codec |
| 749 | // -false if not stereo codec. |
| 750 | // |
pbos@webrtc.org | dd1b19d | 2013-07-31 15:54:00 | [diff] [blame] | 751 | virtual bool IsTrueStereoCodec(); |
andrew@webrtc.org | b015cbe | 2012-10-22 18:19:23 | [diff] [blame] | 752 | |
turaj@webrtc.org | 1952f25 | 2012-12-03 22:13:31 | [diff] [blame] | 753 | /////////////////////////////////////////////////////////////////////////// |
| 754 | // HasFrameToEncode() |
| 755 | // Returns true if there is enough audio buffered for encoding, such that |
| 756 | // calling Encode() will return a payload. |
| 757 | // |
| 758 | bool HasFrameToEncode() const; |
| 759 | |
tina.legrand@webrtc.org | c0cf1db | 2012-11-05 09:35:51 | [diff] [blame] | 760 | protected: |
| 761 | /////////////////////////////////////////////////////////////////////////// |
| 762 | // All the functions with FunctionNameSafe(...) contain the actual |
| 763 | // implementation of FunctionName(...). FunctionName() acquires an |
| 764 | // appropriate lock and calls FunctionNameSafe() to do the actual work. |
| 765 | // Therefore, for the description of functionality, input/output arguments |
| 766 | // and return value we refer to FunctionName() |
| 767 | // |
andrew@webrtc.org | b015cbe | 2012-10-22 18:19:23 | [diff] [blame] | 768 | |
tina.legrand@webrtc.org | c0cf1db | 2012-11-05 09:35:51 | [diff] [blame] | 769 | /////////////////////////////////////////////////////////////////////////// |
tina.legrand@webrtc.org | c0cf1db | 2012-11-05 09:35:51 | [diff] [blame] | 770 | // See Decode() for the description of function, input(s)/output(s) and |
| 771 | // return value. |
| 772 | // |
pbos@webrtc.org | fbda0fc | 2013-04-09 00:28:06 | [diff] [blame] | 773 | virtual int16_t DecodeSafe(uint8_t* bitstream, |
| 774 | int16_t bitstream_len_byte, |
| 775 | int16_t* audio, |
| 776 | int16_t* audio_samples, |
| 777 | int8_t* speech_type) = 0; |
andrew@webrtc.org | b015cbe | 2012-10-22 18:19:23 | [diff] [blame] | 778 | |
tina.legrand@webrtc.org | c0cf1db | 2012-11-05 09:35:51 | [diff] [blame] | 779 | /////////////////////////////////////////////////////////////////////////// |
| 780 | // See Add10MsSafe() for the description of function, input(s)/output(s) |
| 781 | // and return value. |
| 782 | // |
pbos@webrtc.org | fbda0fc | 2013-04-09 00:28:06 | [diff] [blame] | 783 | virtual int32_t Add10MsDataSafe(const uint32_t timestamp, |
| 784 | const int16_t* data, |
| 785 | const uint16_t length, |
| 786 | const uint8_t audio_channel); |
andrew@webrtc.org | b015cbe | 2012-10-22 18:19:23 | [diff] [blame] | 787 | |
tina.legrand@webrtc.org | c0cf1db | 2012-11-05 09:35:51 | [diff] [blame] | 788 | /////////////////////////////////////////////////////////////////////////// |
| 789 | // See RegisterInNetEq() for the description of function, |
| 790 | // input(s)/output(s) and return value. |
| 791 | // |
pbos@webrtc.org | fbda0fc | 2013-04-09 00:28:06 | [diff] [blame] | 792 | virtual int32_t CodecDef(WebRtcNetEQ_CodecDef& codec_def, |
| 793 | const CodecInst& codec_inst) = 0; |
andrew@webrtc.org | b015cbe | 2012-10-22 18:19:23 | [diff] [blame] | 794 | |
tina.legrand@webrtc.org | c0cf1db | 2012-11-05 09:35:51 | [diff] [blame] | 795 | /////////////////////////////////////////////////////////////////////////// |
| 796 | // See EncoderParam() for the description of function, input(s)/output(s) |
| 797 | // and return value. |
| 798 | // |
pbos@webrtc.org | fbda0fc | 2013-04-09 00:28:06 | [diff] [blame] | 799 | int16_t EncoderParamsSafe(WebRtcACMCodecParams *enc_params); |
andrew@webrtc.org | b015cbe | 2012-10-22 18:19:23 | [diff] [blame] | 800 | |
tina.legrand@webrtc.org | c0cf1db | 2012-11-05 09:35:51 | [diff] [blame] | 801 | /////////////////////////////////////////////////////////////////////////// |
| 802 | // See DecoderParam for the description of function, input(s)/output(s) |
| 803 | // and return value. |
| 804 | // |
| 805 | // Note: |
turaj@webrtc.org | 4c9b819 | 2012-12-13 22:46:43 | [diff] [blame] | 806 | // Any Class where a single instance handle several flavors of the |
tina.legrand@webrtc.org | c0cf1db | 2012-11-05 09:35:51 | [diff] [blame] | 807 | // same codec, therefore, several payload types are associated with |
| 808 | // the same instance have to implement this function. |
| 809 | // |
| 810 | // Currently only iSAC is implementing it. A single iSAC instance is |
| 811 | // used for decoding both WB & SWB stream. At one moment both WB & SWB |
| 812 | // can be registered as receive codec. Hence two payloads are associated |
| 813 | // with a single codec instance. |
| 814 | // |
turaj@webrtc.org | 4c9b819 | 2012-12-13 22:46:43 | [diff] [blame] | 815 | virtual bool DecoderParamsSafe(WebRtcACMCodecParams *dec_params, |
pbos@webrtc.org | fbda0fc | 2013-04-09 00:28:06 | [diff] [blame] | 816 | const uint8_t payload_type); |
andrew@webrtc.org | b015cbe | 2012-10-22 18:19:23 | [diff] [blame] | 817 | |
tina.legrand@webrtc.org | c0cf1db | 2012-11-05 09:35:51 | [diff] [blame] | 818 | /////////////////////////////////////////////////////////////////////////// |
| 819 | // See ResetEncoder() for the description of function, input(s)/output(s) |
| 820 | // and return value. |
| 821 | // |
pbos@webrtc.org | fbda0fc | 2013-04-09 00:28:06 | [diff] [blame] | 822 | int16_t ResetEncoderSafe(); |
andrew@webrtc.org | b015cbe | 2012-10-22 18:19:23 | [diff] [blame] | 823 | |
tina.legrand@webrtc.org | c0cf1db | 2012-11-05 09:35:51 | [diff] [blame] | 824 | /////////////////////////////////////////////////////////////////////////// |
| 825 | // See InitEncoder() for the description of function, input(s)/output(s) |
| 826 | // and return value. |
| 827 | // |
pbos@webrtc.org | fbda0fc | 2013-04-09 00:28:06 | [diff] [blame] | 828 | int16_t InitEncoderSafe(WebRtcACMCodecParams *codec_params, |
| 829 | bool force_initialization); |
andrew@webrtc.org | b015cbe | 2012-10-22 18:19:23 | [diff] [blame] | 830 | |
tina.legrand@webrtc.org | c0cf1db | 2012-11-05 09:35:51 | [diff] [blame] | 831 | /////////////////////////////////////////////////////////////////////////// |
| 832 | // See InitDecoder() for the description of function, input(s)/output(s) |
| 833 | // and return value. |
| 834 | // |
pbos@webrtc.org | fbda0fc | 2013-04-09 00:28:06 | [diff] [blame] | 835 | int16_t InitDecoderSafe(WebRtcACMCodecParams *codec_params, |
| 836 | bool force_initialization); |
andrew@webrtc.org | b015cbe | 2012-10-22 18:19:23 | [diff] [blame] | 837 | |
tina.legrand@webrtc.org | c0cf1db | 2012-11-05 09:35:51 | [diff] [blame] | 838 | /////////////////////////////////////////////////////////////////////////// |
| 839 | // See ResetDecoder() for the description of function, input(s)/output(s) |
| 840 | // and return value. |
| 841 | // |
pbos@webrtc.org | fbda0fc | 2013-04-09 00:28:06 | [diff] [blame] | 842 | int16_t ResetDecoderSafe(int16_t payload_type); |
andrew@webrtc.org | b015cbe | 2012-10-22 18:19:23 | [diff] [blame] | 843 | |
tina.legrand@webrtc.org | c0cf1db | 2012-11-05 09:35:51 | [diff] [blame] | 844 | /////////////////////////////////////////////////////////////////////////// |
| 845 | // See DestructEncoder() for the description of function, |
| 846 | // input(s)/output(s) and return value. |
| 847 | // |
| 848 | virtual void DestructEncoderSafe() = 0; |
andrew@webrtc.org | b015cbe | 2012-10-22 18:19:23 | [diff] [blame] | 849 | |
tina.legrand@webrtc.org | c0cf1db | 2012-11-05 09:35:51 | [diff] [blame] | 850 | /////////////////////////////////////////////////////////////////////////// |
| 851 | // See DestructDecoder() for the description of function, |
| 852 | // input(s)/output(s) and return value. |
| 853 | // |
| 854 | virtual void DestructDecoderSafe() = 0; |
andrew@webrtc.org | b015cbe | 2012-10-22 18:19:23 | [diff] [blame] | 855 | |
tina.legrand@webrtc.org | c0cf1db | 2012-11-05 09:35:51 | [diff] [blame] | 856 | /////////////////////////////////////////////////////////////////////////// |
| 857 | // See SetBitRate() for the description of function, input(s)/output(s) |
| 858 | // and return value. |
| 859 | // |
| 860 | // Any codec that can change the bit-rate has to implement this. |
| 861 | // |
pbos@webrtc.org | fbda0fc | 2013-04-09 00:28:06 | [diff] [blame] | 862 | virtual int16_t SetBitRateSafe(const int32_t bitrate_bps); |
andrew@webrtc.org | b015cbe | 2012-10-22 18:19:23 | [diff] [blame] | 863 | |
tina.legrand@webrtc.org | c0cf1db | 2012-11-05 09:35:51 | [diff] [blame] | 864 | /////////////////////////////////////////////////////////////////////////// |
| 865 | // See GetEstimatedBandwidth() for the description of function, |
| 866 | // input(s)/output(s) and return value. |
| 867 | // |
pbos@webrtc.org | fbda0fc | 2013-04-09 00:28:06 | [diff] [blame] | 868 | virtual int32_t GetEstimatedBandwidthSafe(); |
andrew@webrtc.org | b015cbe | 2012-10-22 18:19:23 | [diff] [blame] | 869 | |
tina.legrand@webrtc.org | c0cf1db | 2012-11-05 09:35:51 | [diff] [blame] | 870 | /////////////////////////////////////////////////////////////////////////// |
| 871 | // See SetEstimatedBandwidth() for the description of function, |
| 872 | // input(s)/output(s) and return value. |
| 873 | // |
pbos@webrtc.org | fbda0fc | 2013-04-09 00:28:06 | [diff] [blame] | 874 | virtual int32_t SetEstimatedBandwidthSafe( |
| 875 | int32_t estimated_bandwidth); |
andrew@webrtc.org | b015cbe | 2012-10-22 18:19:23 | [diff] [blame] | 876 | |
tina.legrand@webrtc.org | c0cf1db | 2012-11-05 09:35:51 | [diff] [blame] | 877 | /////////////////////////////////////////////////////////////////////////// |
| 878 | // See GetRedPayload() for the description of function, input(s)/output(s) |
| 879 | // and return value. |
| 880 | // |
pbos@webrtc.org | fbda0fc | 2013-04-09 00:28:06 | [diff] [blame] | 881 | virtual int32_t GetRedPayloadSafe(uint8_t* red_payload, |
| 882 | int16_t* payload_bytes); |
andrew@webrtc.org | b015cbe | 2012-10-22 18:19:23 | [diff] [blame] | 883 | |
tina.legrand@webrtc.org | c0cf1db | 2012-11-05 09:35:51 | [diff] [blame] | 884 | /////////////////////////////////////////////////////////////////////////// |
| 885 | // See SetVAD() for the description of function, input(s)/output(s) and |
| 886 | // return value. |
| 887 | // |
tina.legrand@webrtc.org | 584b688 | 2013-08-27 07:33:51 | [diff] [blame] | 888 | int16_t SetVADSafe(bool* enable_dtx, |
| 889 | bool* enable_vad, |
| 890 | ACMVADMode* mode); |
andrew@webrtc.org | b015cbe | 2012-10-22 18:19:23 | [diff] [blame] | 891 | |
tina.legrand@webrtc.org | c0cf1db | 2012-11-05 09:35:51 | [diff] [blame] | 892 | /////////////////////////////////////////////////////////////////////////// |
| 893 | // See ReplaceInternalDTX() for the description of function, input and |
| 894 | // return value. |
| 895 | // |
pbos@webrtc.org | fbda0fc | 2013-04-09 00:28:06 | [diff] [blame] | 896 | virtual int32_t ReplaceInternalDTXSafe(const bool replace_internal_dtx); |
andrew@webrtc.org | b015cbe | 2012-10-22 18:19:23 | [diff] [blame] | 897 | |
tina.legrand@webrtc.org | c0cf1db | 2012-11-05 09:35:51 | [diff] [blame] | 898 | /////////////////////////////////////////////////////////////////////////// |
| 899 | // See IsInternalDTXReplaced() for the description of function, input and |
| 900 | // return value. |
| 901 | // |
pbos@webrtc.org | fbda0fc | 2013-04-09 00:28:06 | [diff] [blame] | 902 | virtual int32_t IsInternalDTXReplacedSafe(bool* internal_dtx_replaced); |
andrew@webrtc.org | b015cbe | 2012-10-22 18:19:23 | [diff] [blame] | 903 | |
tina.legrand@webrtc.org | c0cf1db | 2012-11-05 09:35:51 | [diff] [blame] | 904 | /////////////////////////////////////////////////////////////////////////// |
pbos@webrtc.org | fbda0fc | 2013-04-09 00:28:06 | [diff] [blame] | 905 | // int16_t CreateEncoder() |
tina.legrand@webrtc.org | c0cf1db | 2012-11-05 09:35:51 | [diff] [blame] | 906 | // Creates the encoder instance. |
| 907 | // |
| 908 | // Return value: |
| 909 | // -1 if failed, |
| 910 | // 0 if succeeded. |
| 911 | // |
pbos@webrtc.org | fbda0fc | 2013-04-09 00:28:06 | [diff] [blame] | 912 | int16_t CreateEncoder(); |
andrew@webrtc.org | b015cbe | 2012-10-22 18:19:23 | [diff] [blame] | 913 | |
tina.legrand@webrtc.org | c0cf1db | 2012-11-05 09:35:51 | [diff] [blame] | 914 | /////////////////////////////////////////////////////////////////////////// |
pbos@webrtc.org | fbda0fc | 2013-04-09 00:28:06 | [diff] [blame] | 915 | // int16_t CreateDecoder() |
tina.legrand@webrtc.org | c0cf1db | 2012-11-05 09:35:51 | [diff] [blame] | 916 | // Creates the decoder instance. |
| 917 | // |
| 918 | // Return value: |
| 919 | // -1 if failed, |
| 920 | // 0 if succeeded. |
| 921 | // |
pbos@webrtc.org | fbda0fc | 2013-04-09 00:28:06 | [diff] [blame] | 922 | int16_t CreateDecoder(); |
andrew@webrtc.org | b015cbe | 2012-10-22 18:19:23 | [diff] [blame] | 923 | |
tina.legrand@webrtc.org | c0cf1db | 2012-11-05 09:35:51 | [diff] [blame] | 924 | /////////////////////////////////////////////////////////////////////////// |
pbos@webrtc.org | fbda0fc | 2013-04-09 00:28:06 | [diff] [blame] | 925 | // int16_t EnableVAD(); |
tina.legrand@webrtc.org | c0cf1db | 2012-11-05 09:35:51 | [diff] [blame] | 926 | // Enables VAD with the given mode. The VAD instance will be created if |
| 927 | // it does not exists. |
| 928 | // |
| 929 | // Input: |
| 930 | // -mode : VAD mode c.f. audio_coding_module_typedefs.h for |
| 931 | // the options. |
| 932 | // |
| 933 | // Return value: |
| 934 | // -1 if failed, |
| 935 | // 0 if succeeded. |
| 936 | // |
pbos@webrtc.org | fbda0fc | 2013-04-09 00:28:06 | [diff] [blame] | 937 | int16_t EnableVAD(ACMVADMode mode); |
andrew@webrtc.org | b015cbe | 2012-10-22 18:19:23 | [diff] [blame] | 938 | |
tina.legrand@webrtc.org | c0cf1db | 2012-11-05 09:35:51 | [diff] [blame] | 939 | /////////////////////////////////////////////////////////////////////////// |
pbos@webrtc.org | fbda0fc | 2013-04-09 00:28:06 | [diff] [blame] | 940 | // int16_t DisableVAD() |
tina.legrand@webrtc.org | c0cf1db | 2012-11-05 09:35:51 | [diff] [blame] | 941 | // Disables VAD. |
| 942 | // |
| 943 | // Return value: |
| 944 | // -1 if failed, |
| 945 | // 0 if succeeded. |
| 946 | // |
pbos@webrtc.org | fbda0fc | 2013-04-09 00:28:06 | [diff] [blame] | 947 | int16_t DisableVAD(); |
andrew@webrtc.org | b015cbe | 2012-10-22 18:19:23 | [diff] [blame] | 948 | |
tina.legrand@webrtc.org | c0cf1db | 2012-11-05 09:35:51 | [diff] [blame] | 949 | /////////////////////////////////////////////////////////////////////////// |
pbos@webrtc.org | fbda0fc | 2013-04-09 00:28:06 | [diff] [blame] | 950 | // int16_t EnableDTX() |
tina.legrand@webrtc.org | c0cf1db | 2012-11-05 09:35:51 | [diff] [blame] | 951 | // Enables DTX. This method should be overwritten for codecs which have |
| 952 | // internal DTX. |
| 953 | // |
| 954 | // Return value: |
| 955 | // -1 if failed, |
| 956 | // 0 if succeeded. |
| 957 | // |
pbos@webrtc.org | fbda0fc | 2013-04-09 00:28:06 | [diff] [blame] | 958 | virtual int16_t EnableDTX(); |
andrew@webrtc.org | b015cbe | 2012-10-22 18:19:23 | [diff] [blame] | 959 | |
tina.legrand@webrtc.org | c0cf1db | 2012-11-05 09:35:51 | [diff] [blame] | 960 | /////////////////////////////////////////////////////////////////////////// |
pbos@webrtc.org | fbda0fc | 2013-04-09 00:28:06 | [diff] [blame] | 961 | // int16_t DisableDTX() |
tina.legrand@webrtc.org | c0cf1db | 2012-11-05 09:35:51 | [diff] [blame] | 962 | // Disables usage of DTX. This method should be overwritten for codecs which |
| 963 | // have internal DTX. |
| 964 | // |
| 965 | // Return value: |
| 966 | // -1 if failed, |
| 967 | // 0 if succeeded. |
| 968 | // |
pbos@webrtc.org | fbda0fc | 2013-04-09 00:28:06 | [diff] [blame] | 969 | virtual int16_t DisableDTX(); |
andrew@webrtc.org | b015cbe | 2012-10-22 18:19:23 | [diff] [blame] | 970 | |
tina.legrand@webrtc.org | c0cf1db | 2012-11-05 09:35:51 | [diff] [blame] | 971 | /////////////////////////////////////////////////////////////////////////// |
pbos@webrtc.org | fbda0fc | 2013-04-09 00:28:06 | [diff] [blame] | 972 | // int16_t InternalEncode() |
tina.legrand@webrtc.org | c0cf1db | 2012-11-05 09:35:51 | [diff] [blame] | 973 | // This is a codec-specific function called in EncodeSafe() to actually |
| 974 | // encode a frame of audio. |
| 975 | // |
| 976 | // Outputs: |
turaj@webrtc.org | 4c9b819 | 2012-12-13 22:46:43 | [diff] [blame] | 977 | // -bitstream : pointer to a buffer where the bit-stream is |
tina.legrand@webrtc.org | c0cf1db | 2012-11-05 09:35:51 | [diff] [blame] | 978 | // written to. |
turaj@webrtc.org | 4c9b819 | 2012-12-13 22:46:43 | [diff] [blame] | 979 | // -bitstream_len_byte : the length of the bit-stream in bytes, |
tina.legrand@webrtc.org | c0cf1db | 2012-11-05 09:35:51 | [diff] [blame] | 980 | // a negative value indicates error. |
| 981 | // |
| 982 | // Return value: |
| 983 | // -1 if failed, |
| 984 | // otherwise the length of the bit-stream is returned. |
| 985 | // |
pbos@webrtc.org | fbda0fc | 2013-04-09 00:28:06 | [diff] [blame] | 986 | virtual int16_t InternalEncode(uint8_t* bitstream, |
| 987 | int16_t* bitstream_len_byte) = 0; |
andrew@webrtc.org | b015cbe | 2012-10-22 18:19:23 | [diff] [blame] | 988 | |
tina.legrand@webrtc.org | c0cf1db | 2012-11-05 09:35:51 | [diff] [blame] | 989 | /////////////////////////////////////////////////////////////////////////// |
pbos@webrtc.org | fbda0fc | 2013-04-09 00:28:06 | [diff] [blame] | 990 | // int16_t InternalInitEncoder() |
tina.legrand@webrtc.org | c0cf1db | 2012-11-05 09:35:51 | [diff] [blame] | 991 | // This is a codec-specific function called in InitEncoderSafe(), it has to |
| 992 | // do all codec-specific operation to initialize the encoder given the |
| 993 | // encoder parameters. |
| 994 | // |
| 995 | // Input: |
turaj@webrtc.org | 4c9b819 | 2012-12-13 22:46:43 | [diff] [blame] | 996 | // -codec_params : pointer to a structure that contains parameters to |
tina.legrand@webrtc.org | c0cf1db | 2012-11-05 09:35:51 | [diff] [blame] | 997 | // initialize encoder. |
turaj@webrtc.org | 4c9b819 | 2012-12-13 22:46:43 | [diff] [blame] | 998 | // Set codec_params->codec_inst.rate to -1 for |
tina.legrand@webrtc.org | c0cf1db | 2012-11-05 09:35:51 | [diff] [blame] | 999 | // iSAC to operate in adaptive mode. |
| 1000 | // (to do: if frame-length is -1 frame-length will be |
| 1001 | // automatically adjusted, otherwise, given |
| 1002 | // frame-length is forced) |
| 1003 | // |
| 1004 | // Return value: |
| 1005 | // -1 if failed, |
| 1006 | // 0 if succeeded. |
| 1007 | // |
pbos@webrtc.org | fbda0fc | 2013-04-09 00:28:06 | [diff] [blame] | 1008 | virtual int16_t InternalInitEncoder( |
turaj@webrtc.org | 4c9b819 | 2012-12-13 22:46:43 | [diff] [blame] | 1009 | WebRtcACMCodecParams *codec_params) = 0; |
andrew@webrtc.org | b015cbe | 2012-10-22 18:19:23 | [diff] [blame] | 1010 | |
tina.legrand@webrtc.org | c0cf1db | 2012-11-05 09:35:51 | [diff] [blame] | 1011 | /////////////////////////////////////////////////////////////////////////// |
pbos@webrtc.org | fbda0fc | 2013-04-09 00:28:06 | [diff] [blame] | 1012 | // int16_t InternalInitDecoder() |
tina.legrand@webrtc.org | c0cf1db | 2012-11-05 09:35:51 | [diff] [blame] | 1013 | // This is a codec-specific function called in InitDecoderSafe(), it has to |
| 1014 | // do all codec-specific operation to initialize the decoder given the |
| 1015 | // decoder parameters. |
| 1016 | // |
| 1017 | // Input: |
turaj@webrtc.org | 4c9b819 | 2012-12-13 22:46:43 | [diff] [blame] | 1018 | // -codec_params : pointer to a structure that contains parameters to |
tina.legrand@webrtc.org | c0cf1db | 2012-11-05 09:35:51 | [diff] [blame] | 1019 | // initialize encoder. |
| 1020 | // |
| 1021 | // Return value: |
| 1022 | // -1 if failed, |
| 1023 | // 0 if succeeded. |
| 1024 | // |
pbos@webrtc.org | fbda0fc | 2013-04-09 00:28:06 | [diff] [blame] | 1025 | virtual int16_t InternalInitDecoder( |
turaj@webrtc.org | 4c9b819 | 2012-12-13 22:46:43 | [diff] [blame] | 1026 | WebRtcACMCodecParams *codec_params) = 0; |
andrew@webrtc.org | b015cbe | 2012-10-22 18:19:23 | [diff] [blame] | 1027 | |
tina.legrand@webrtc.org | c0cf1db | 2012-11-05 09:35:51 | [diff] [blame] | 1028 | /////////////////////////////////////////////////////////////////////////// |
| 1029 | // void IncreaseNoMissedSamples() |
| 1030 | // This method is called to increase the number of samples that are |
| 1031 | // overwritten in the audio buffer. |
| 1032 | // |
| 1033 | // Input: |
turaj@webrtc.org | 4c9b819 | 2012-12-13 22:46:43 | [diff] [blame] | 1034 | // -num_samples : the number of overwritten samples is incremented |
tina.legrand@webrtc.org | c0cf1db | 2012-11-05 09:35:51 | [diff] [blame] | 1035 | // by this value. |
| 1036 | // |
pbos@webrtc.org | fbda0fc | 2013-04-09 00:28:06 | [diff] [blame] | 1037 | void IncreaseNoMissedSamples(const int16_t num_samples); |
andrew@webrtc.org | b015cbe | 2012-10-22 18:19:23 | [diff] [blame] | 1038 | |
tina.legrand@webrtc.org | c0cf1db | 2012-11-05 09:35:51 | [diff] [blame] | 1039 | /////////////////////////////////////////////////////////////////////////// |
pbos@webrtc.org | fbda0fc | 2013-04-09 00:28:06 | [diff] [blame] | 1040 | // int16_t InternalCreateEncoder() |
tina.legrand@webrtc.org | c0cf1db | 2012-11-05 09:35:51 | [diff] [blame] | 1041 | // This is a codec-specific method called in CreateEncoderSafe() it is |
| 1042 | // supposed to perform all codec-specific operations to create encoder |
| 1043 | // instance. |
| 1044 | // |
| 1045 | // Return value: |
| 1046 | // -1 if failed, |
| 1047 | // 0 if succeeded. |
| 1048 | // |
pbos@webrtc.org | fbda0fc | 2013-04-09 00:28:06 | [diff] [blame] | 1049 | virtual int16_t InternalCreateEncoder() = 0; |
andrew@webrtc.org | b015cbe | 2012-10-22 18:19:23 | [diff] [blame] | 1050 | |
tina.legrand@webrtc.org | c0cf1db | 2012-11-05 09:35:51 | [diff] [blame] | 1051 | /////////////////////////////////////////////////////////////////////////// |
pbos@webrtc.org | fbda0fc | 2013-04-09 00:28:06 | [diff] [blame] | 1052 | // int16_t InternalCreateDecoder() |
tina.legrand@webrtc.org | c0cf1db | 2012-11-05 09:35:51 | [diff] [blame] | 1053 | // This is a codec-specific method called in CreateDecoderSafe() it is |
| 1054 | // supposed to perform all codec-specific operations to create decoder |
| 1055 | // instance. |
| 1056 | // |
| 1057 | // Return value: |
| 1058 | // -1 if failed, |
| 1059 | // 0 if succeeded. |
| 1060 | // |
pbos@webrtc.org | fbda0fc | 2013-04-09 00:28:06 | [diff] [blame] | 1061 | virtual int16_t InternalCreateDecoder() = 0; |
andrew@webrtc.org | b015cbe | 2012-10-22 18:19:23 | [diff] [blame] | 1062 | |
tina.legrand@webrtc.org | c0cf1db | 2012-11-05 09:35:51 | [diff] [blame] | 1063 | /////////////////////////////////////////////////////////////////////////// |
| 1064 | // void InternalDestructEncoderInst() |
| 1065 | // This is a codec-specific method, used in conferencing, called from |
| 1066 | // DestructEncoderInst(). The input argument is pointer to encoder instance |
| 1067 | // (codec instance for codecs that encoder and decoder share the same |
turaj@webrtc.org | 4c9b819 | 2012-12-13 22:46:43 | [diff] [blame] | 1068 | // instance). This method is called to free the memory that |ptr_inst| is |
tina.legrand@webrtc.org | c0cf1db | 2012-11-05 09:35:51 | [diff] [blame] | 1069 | // pointing to. |
| 1070 | // |
| 1071 | // Input: |
turaj@webrtc.org | 4c9b819 | 2012-12-13 22:46:43 | [diff] [blame] | 1072 | // -ptr_inst : pointer to encoder instance. |
tina.legrand@webrtc.org | c0cf1db | 2012-11-05 09:35:51 | [diff] [blame] | 1073 | // |
| 1074 | // Return value: |
| 1075 | // -1 if failed, |
| 1076 | // 0 if succeeded. |
| 1077 | // |
turaj@webrtc.org | 4c9b819 | 2012-12-13 22:46:43 | [diff] [blame] | 1078 | virtual void InternalDestructEncoderInst(void* ptr_inst) = 0; |
andrew@webrtc.org | b015cbe | 2012-10-22 18:19:23 | [diff] [blame] | 1079 | |
tina.legrand@webrtc.org | c0cf1db | 2012-11-05 09:35:51 | [diff] [blame] | 1080 | /////////////////////////////////////////////////////////////////////////// |
pbos@webrtc.org | fbda0fc | 2013-04-09 00:28:06 | [diff] [blame] | 1081 | // int16_t InternalResetEncoder() |
tina.legrand@webrtc.org | c0cf1db | 2012-11-05 09:35:51 | [diff] [blame] | 1082 | // This method is called to reset the states of encoder. However, the |
| 1083 | // current parameters, e.g. frame-length, should remain as they are. For |
| 1084 | // most of the codecs a re-initialization of the encoder is what needs to |
| 1085 | // be down. But for iSAC we like to keep the BWE history so we cannot |
| 1086 | // re-initialize. As soon as such an API is implemented in iSAC this method |
| 1087 | // has to be overwritten in ACMISAC class. |
| 1088 | // |
| 1089 | // Return value: |
| 1090 | // -1 if failed, |
| 1091 | // 0 if succeeded. |
| 1092 | // |
pbos@webrtc.org | fbda0fc | 2013-04-09 00:28:06 | [diff] [blame] | 1093 | virtual int16_t InternalResetEncoder(); |
andrew@webrtc.org | b015cbe | 2012-10-22 18:19:23 | [diff] [blame] | 1094 | |
tina.legrand@webrtc.org | c0cf1db | 2012-11-05 09:35:51 | [diff] [blame] | 1095 | /////////////////////////////////////////////////////////////////////////// |
pbos@webrtc.org | fbda0fc | 2013-04-09 00:28:06 | [diff] [blame] | 1096 | // int16_t ProcessFrameVADDTX() |
tina.legrand@webrtc.org | c0cf1db | 2012-11-05 09:35:51 | [diff] [blame] | 1097 | // This function is called when a full frame of audio is available. It will |
| 1098 | // break the audio frame into blocks such that each block could be processed |
| 1099 | // by VAD & CN/DTX. If a frame is divided into two blocks then there are two |
| 1100 | // cases. First, the first block is active, the second block will not be |
| 1101 | // processed by CN/DTX but only by VAD and return to caller with |
turaj@webrtc.org | 4c9b819 | 2012-12-13 22:46:43 | [diff] [blame] | 1102 | // '*samples_processed' set to zero. There, the audio frame will be encoded |
tina.legrand@webrtc.org | c0cf1db | 2012-11-05 09:35:51 | [diff] [blame] | 1103 | // by the encoder. Second, the first block is inactive and is processed by |
| 1104 | // CN/DTX, then we stop processing the next block and return to the caller |
turaj@webrtc.org | 4c9b819 | 2012-12-13 22:46:43 | [diff] [blame] | 1105 | // which is EncodeSafe(), with "*samples_processed" equal to the number of |
tina.legrand@webrtc.org | c0cf1db | 2012-11-05 09:35:51 | [diff] [blame] | 1106 | // samples in first block. |
| 1107 | // |
| 1108 | // Output: |
turaj@webrtc.org | 4c9b819 | 2012-12-13 22:46:43 | [diff] [blame] | 1109 | // -bitstream : pointer to a buffer where DTX frame, if |
tina.legrand@webrtc.org | c0cf1db | 2012-11-05 09:35:51 | [diff] [blame] | 1110 | // generated, will be written to. |
turaj@webrtc.org | 4c9b819 | 2012-12-13 22:46:43 | [diff] [blame] | 1111 | // -bitstream_len_byte : contains the length of bit-stream in bytes, if |
tina.legrand@webrtc.org | c0cf1db | 2012-11-05 09:35:51 | [diff] [blame] | 1112 | // generated. Zero if no bit-stream is generated. |
turaj@webrtc.org | 4c9b819 | 2012-12-13 22:46:43 | [diff] [blame] | 1113 | // -samples_processed : contains no of samples that actually CN has |
tina.legrand@webrtc.org | c0cf1db | 2012-11-05 09:35:51 | [diff] [blame] | 1114 | // processed. Those samples processed by CN will not |
| 1115 | // be encoded by the encoder, obviously. If |
| 1116 | // contains zero, it means that the frame has been |
| 1117 | // identified as active by VAD. Note that |
turaj@webrtc.org | 4c9b819 | 2012-12-13 22:46:43 | [diff] [blame] | 1118 | // "*samples_processed" might be non-zero but |
| 1119 | // "*bitstream_len_byte" be zero. |
tina.legrand@webrtc.org | c0cf1db | 2012-11-05 09:35:51 | [diff] [blame] | 1120 | // |
| 1121 | // Return value: |
| 1122 | // -1 if failed, |
| 1123 | // 0 if succeeded. |
| 1124 | // |
pbos@webrtc.org | fbda0fc | 2013-04-09 00:28:06 | [diff] [blame] | 1125 | int16_t ProcessFrameVADDTX(uint8_t* bitstream, |
| 1126 | int16_t* bitstream_len_byte, |
| 1127 | int16_t* samples_processed); |
andrew@webrtc.org | b015cbe | 2012-10-22 18:19:23 | [diff] [blame] | 1128 | |
tina.legrand@webrtc.org | c0cf1db | 2012-11-05 09:35:51 | [diff] [blame] | 1129 | /////////////////////////////////////////////////////////////////////////// |
| 1130 | // CanChangeEncodingParam() |
| 1131 | // Check if the codec parameters can be changed. In conferencing normally |
turaj@webrtc.org | 4c9b819 | 2012-12-13 22:46:43 | [diff] [blame] | 1132 | // codec parameters cannot be changed. The exception is bit-rate of isac. |
tina.legrand@webrtc.org | c0cf1db | 2012-11-05 09:35:51 | [diff] [blame] | 1133 | // |
| 1134 | // return value: |
| 1135 | // -true if codec parameters are allowed to change. |
turaj@webrtc.org | 4c9b819 | 2012-12-13 22:46:43 | [diff] [blame] | 1136 | // -false otherwise. |
tina.legrand@webrtc.org | c0cf1db | 2012-11-05 09:35:51 | [diff] [blame] | 1137 | // |
turaj@webrtc.org | 4c9b819 | 2012-12-13 22:46:43 | [diff] [blame] | 1138 | virtual bool CanChangeEncodingParam(CodecInst& codec_inst); |
andrew@webrtc.org | b015cbe | 2012-10-22 18:19:23 | [diff] [blame] | 1139 | |
tina.legrand@webrtc.org | c0cf1db | 2012-11-05 09:35:51 | [diff] [blame] | 1140 | /////////////////////////////////////////////////////////////////////////// |
| 1141 | // CurrentRate() |
| 1142 | // Call to get the current encoding rate of the encoder. This function |
turaj@webrtc.org | 4c9b819 | 2012-12-13 22:46:43 | [diff] [blame] | 1143 | // should be overwritten for codecs which automatically change their |
tina.legrand@webrtc.org | c0cf1db | 2012-11-05 09:35:51 | [diff] [blame] | 1144 | // target rate. One example is iSAC. The output of the function is the |
| 1145 | // current target rate. |
| 1146 | // |
| 1147 | // Output: |
turaj@webrtc.org | 4c9b819 | 2012-12-13 22:46:43 | [diff] [blame] | 1148 | // -rate_bps : the current target rate of the codec. |
tina.legrand@webrtc.org | c0cf1db | 2012-11-05 09:35:51 | [diff] [blame] | 1149 | // |
pbos@webrtc.org | dd1b19d | 2013-07-31 15:54:00 | [diff] [blame] | 1150 | virtual void CurrentRate(int32_t& /* rate_bps */); |
andrew@webrtc.org | b015cbe | 2012-10-22 18:19:23 | [diff] [blame] | 1151 | |
turaj@webrtc.org | 4c9b819 | 2012-12-13 22:46:43 | [diff] [blame] | 1152 | virtual void SaveDecoderParamSafe(const WebRtcACMCodecParams* codec_params); |
andrew@webrtc.org | b015cbe | 2012-10-22 18:19:23 | [diff] [blame] | 1153 | |
turaj@webrtc.org | 4c9b819 | 2012-12-13 22:46:43 | [diff] [blame] | 1154 | // &in_audio_[in_audio_ix_write_] always point to where new audio can be |
tina.legrand@webrtc.org | c0cf1db | 2012-11-05 09:35:51 | [diff] [blame] | 1155 | // written to |
pbos@webrtc.org | fbda0fc | 2013-04-09 00:28:06 | [diff] [blame] | 1156 | int16_t in_audio_ix_write_; |
andrew@webrtc.org | b015cbe | 2012-10-22 18:19:23 | [diff] [blame] | 1157 | |
turaj@webrtc.org | 4c9b819 | 2012-12-13 22:46:43 | [diff] [blame] | 1158 | // &in_audio_[in_audio_ix_read_] points to where audio has to be read from |
pbos@webrtc.org | fbda0fc | 2013-04-09 00:28:06 | [diff] [blame] | 1159 | int16_t in_audio_ix_read_; |
andrew@webrtc.org | b015cbe | 2012-10-22 18:19:23 | [diff] [blame] | 1160 | |
pbos@webrtc.org | fbda0fc | 2013-04-09 00:28:06 | [diff] [blame] | 1161 | int16_t in_timestamp_ix_write_; |
andrew@webrtc.org | b015cbe | 2012-10-22 18:19:23 | [diff] [blame] | 1162 | |
tina.legrand@webrtc.org | c0cf1db | 2012-11-05 09:35:51 | [diff] [blame] | 1163 | // Where the audio is stored before encoding, |
| 1164 | // To save memory the following buffer can be allocated |
turaj@webrtc.org | 4c9b819 | 2012-12-13 22:46:43 | [diff] [blame] | 1165 | // dynamically for 80 ms depending on the sampling frequency |
tina.legrand@webrtc.org | c0cf1db | 2012-11-05 09:35:51 | [diff] [blame] | 1166 | // of the codec. |
pbos@webrtc.org | fbda0fc | 2013-04-09 00:28:06 | [diff] [blame] | 1167 | int16_t* in_audio_; |
| 1168 | uint32_t* in_timestamp_; |
andrew@webrtc.org | b015cbe | 2012-10-22 18:19:23 | [diff] [blame] | 1169 | |
pbos@webrtc.org | fbda0fc | 2013-04-09 00:28:06 | [diff] [blame] | 1170 | int16_t frame_len_smpl_; |
| 1171 | uint16_t num_channels_; |
andrew@webrtc.org | b015cbe | 2012-10-22 18:19:23 | [diff] [blame] | 1172 | |
tina.legrand@webrtc.org | c0cf1db | 2012-11-05 09:35:51 | [diff] [blame] | 1173 | // This will point to a static database of the supported codecs |
pbos@webrtc.org | fbda0fc | 2013-04-09 00:28:06 | [diff] [blame] | 1174 | int16_t codec_id_; |
andrew@webrtc.org | b015cbe | 2012-10-22 18:19:23 | [diff] [blame] | 1175 | |
turaj@webrtc.org | 4c9b819 | 2012-12-13 22:46:43 | [diff] [blame] | 1176 | // This will account for the number of samples were not encoded |
| 1177 | // the case is rare, either samples are missed due to overwrite |
tina.legrand@webrtc.org | c0cf1db | 2012-11-05 09:35:51 | [diff] [blame] | 1178 | // at input buffer or due to encoding error |
pbos@webrtc.org | fbda0fc | 2013-04-09 00:28:06 | [diff] [blame] | 1179 | uint32_t num_missed_samples_; |
andrew@webrtc.org | b015cbe | 2012-10-22 18:19:23 | [diff] [blame] | 1180 | |
tina.legrand@webrtc.org | c0cf1db | 2012-11-05 09:35:51 | [diff] [blame] | 1181 | // True if the encoder instance created |
turaj@webrtc.org | 4c9b819 | 2012-12-13 22:46:43 | [diff] [blame] | 1182 | bool encoder_exist_; |
| 1183 | bool decoder_exist_; |
| 1184 | // True if the encoder instance initialized |
| 1185 | bool encoder_initialized_; |
| 1186 | bool decoder_initialized_; |
andrew@webrtc.org | b015cbe | 2012-10-22 18:19:23 | [diff] [blame] | 1187 | |
turaj@webrtc.org | 4c9b819 | 2012-12-13 22:46:43 | [diff] [blame] | 1188 | bool registered_in_neteq_; |
andrew@webrtc.org | b015cbe | 2012-10-22 18:19:23 | [diff] [blame] | 1189 | |
tina.legrand@webrtc.org | c0cf1db | 2012-11-05 09:35:51 | [diff] [blame] | 1190 | // VAD/DTX |
turaj@webrtc.org | 4c9b819 | 2012-12-13 22:46:43 | [diff] [blame] | 1191 | bool has_internal_dtx_; |
| 1192 | WebRtcVadInst* ptr_vad_inst_; |
| 1193 | bool vad_enabled_; |
| 1194 | ACMVADMode vad_mode_; |
pbos@webrtc.org | fbda0fc | 2013-04-09 00:28:06 | [diff] [blame] | 1195 | int16_t vad_label_[MAX_FRAME_SIZE_10MSEC]; |
turaj@webrtc.org | 4c9b819 | 2012-12-13 22:46:43 | [diff] [blame] | 1196 | bool dtx_enabled_; |
| 1197 | WebRtcCngEncInst* ptr_dtx_inst_; |
pbos@webrtc.org | fbda0fc | 2013-04-09 00:28:06 | [diff] [blame] | 1198 | uint8_t num_lpc_params_; |
turaj@webrtc.org | 4c9b819 | 2012-12-13 22:46:43 | [diff] [blame] | 1199 | bool sent_cn_previous_; |
| 1200 | bool is_master_; |
| 1201 | int16_t prev_frame_cng_; |
andrew@webrtc.org | b015cbe | 2012-10-22 18:19:23 | [diff] [blame] | 1202 | |
turaj@webrtc.org | 4c9b819 | 2012-12-13 22:46:43 | [diff] [blame] | 1203 | WebRtcACMCodecParams encoder_params_; |
| 1204 | WebRtcACMCodecParams decoder_params_; |
andrew@webrtc.org | b015cbe | 2012-10-22 18:19:23 | [diff] [blame] | 1205 | |
turaj@webrtc.org | 4c9b819 | 2012-12-13 22:46:43 | [diff] [blame] | 1206 | // Used as a global lock for all available decoders |
tina.legrand@webrtc.org | c0cf1db | 2012-11-05 09:35:51 | [diff] [blame] | 1207 | // so that no decoder is used when NetEQ decodes. |
turaj@webrtc.org | 4c9b819 | 2012-12-13 22:46:43 | [diff] [blame] | 1208 | RWLockWrapper* neteq_decode_lock_; |
tina.legrand@webrtc.org | c0cf1db | 2012-11-05 09:35:51 | [diff] [blame] | 1209 | // Used to lock wrapper internal data |
| 1210 | // such as buffers and state variables. |
turaj@webrtc.org | 4c9b819 | 2012-12-13 22:46:43 | [diff] [blame] | 1211 | RWLockWrapper& codec_wrapper_lock_; |
andrew@webrtc.org | b015cbe | 2012-10-22 18:19:23 | [diff] [blame] | 1212 | |
pbos@webrtc.org | fbda0fc | 2013-04-09 00:28:06 | [diff] [blame] | 1213 | uint32_t last_encoded_timestamp_; |
| 1214 | uint32_t last_timestamp_; |
turaj@webrtc.org | 4c9b819 | 2012-12-13 22:46:43 | [diff] [blame] | 1215 | bool is_audio_buff_fresh_; |
pbos@webrtc.org | fbda0fc | 2013-04-09 00:28:06 | [diff] [blame] | 1216 | uint32_t unique_id_; |
andrew@webrtc.org | b015cbe | 2012-10-22 18:19:23 | [diff] [blame] | 1217 | }; |
| 1218 | |
turaj@webrtc.org | ed0b4fb | 2013-09-13 23:06:59 | [diff] [blame] | 1219 | } // namespace acm1 |
| 1220 | |
| 1221 | } // namespace webrtc |
andrew@webrtc.org | b015cbe | 2012-10-22 18:19:23 | [diff] [blame] | 1222 | |
| 1223 | #endif // WEBRTC_MODULES_AUDIO_CODING_MAIN_SOURCE_ACM_GENERIC_CODEC_H_ |