blob: 3951a94d54d8c4c6383b333a1d85e17607e4f019 [file] [log] [blame]
andrew@webrtc.orgb015cbe2012-10-22 18:19:231/*
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.org4c9b8192012-12-13 22:46:4314#include "webrtc/modules/audio_coding/main/interface/audio_coding_module_typedefs.h"
stefan@webrtc.orgec09fcb2013-09-18 12:34:0515#include "webrtc/modules/audio_coding/main/source/acm_common_defs.h"
turaj@webrtc.org4c9b8192012-12-13 22:46:4316#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.orgb015cbe2012-10-22 18:19:2319
20#define MAX_FRAME_SIZE_10MSEC 6
21
22// forward declaration
23struct WebRtcVadInst;
24struct WebRtcCngEncInst;
25
tina.legrand@webrtc.orgc0cf1db2012-11-05 09:35:5126namespace webrtc {
andrew@webrtc.orgb015cbe2012-10-22 18:19:2327
28// forward declaration
29struct CodecInst;
turaj@webrtc.orged0b4fb2013-09-13 23:06:5930
31namespace acm1 {
32
tina.legrand@webrtc.orgc0cf1db2012-11-05 09:35:5133class ACMNetEQ;
andrew@webrtc.orgb015cbe2012-10-22 18:19:2334
tina.legrand@webrtc.orgc0cf1db2012-11-05 09:35:5135class ACMGenericCodec {
36 public:
37 ///////////////////////////////////////////////////////////////////////////
38 // Constructor of the class
39 //
40 ACMGenericCodec();
andrew@webrtc.orgb015cbe2012-10-22 18:19:2341
tina.legrand@webrtc.orgc0cf1db2012-11-05 09:35:5142 ///////////////////////////////////////////////////////////////////////////
43 // Destructor of the class.
44 //
45 virtual ~ACMGenericCodec();
andrew@webrtc.orgb015cbe2012-10-22 18:19:2346
tina.legrand@webrtc.orgc0cf1db2012-11-05 09:35:5147 ///////////////////////////////////////////////////////////////////////////
48 // ACMGenericCodec* CreateInstance();
49 // The function will be used for FEC. It is not implemented yet.
50 //
51 virtual ACMGenericCodec* CreateInstance() = 0;
andrew@webrtc.orgb015cbe2012-10-22 18:19:2352
tina.legrand@webrtc.orgc0cf1db2012-11-05 09:35:5153 ///////////////////////////////////////////////////////////////////////////
pbos@webrtc.orgfbda0fc2013-04-09 00:28:0654 // int16_t Encode()
tina.legrand@webrtc.orgc0cf1db2012-11-05 09:35:5155 // 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.org4c9b8192012-12-13 22:46:4363 // and encoded by the encoder. The "*encoding_type" will be either
64 // "kActiveNormalEncode" or "kPassiveNormalEncode" if frame is active or
tina.legrand@webrtc.orgc0cf1db2012-11-05 09:35:5165 // 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.org4c9b8192012-12-13 22:46:4376 // -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.orgc0cf1db2012-11-05 09:35:5178 // bytes.
turaj@webrtc.org4c9b8192012-12-13 22:46:4379 // -timestamp : contains the RTP timestamp, this is the
tina.legrand@webrtc.orgc0cf1db2012-11-05 09:35:5180 // sampling time of the first sample encoded
81 // (measured in number of samples).
turaj@webrtc.org4c9b8192012-12-13 22:46:4382 // -encoding_type : contains the type of encoding applied on the
tina.legrand@webrtc.orgc0cf1db2012-11-05 09:35:5183 // 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.orgfbda0fc2013-04-09 00:28:06106 int16_t Encode(uint8_t* bitstream,
107 int16_t* bitstream_len_byte,
108 uint32_t* timestamp,
109 WebRtcACMEncodingType* encoding_type);
andrew@webrtc.orgb015cbe2012-10-22 18:19:23110
tina.legrand@webrtc.orgc0cf1db2012-11-05 09:35:51111 ///////////////////////////////////////////////////////////////////////////
pbos@webrtc.orgfbda0fc2013-04-09 00:28:06112 // int16_t Decode()
tina.legrand@webrtc.orgc0cf1db2012-11-05 09:35:51113 // 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.org4c9b8192012-12-13 22:46:43120 // -bitstream : a buffer where bit-stream will be read.
121 // -bitstream_len_byte : the length of the bit-stream in bytes.
tina.legrand@webrtc.orgc0cf1db2012-11-05 09:35:51122 //
123 // Outputs:
124 // -audio : pointer to a buffer where the audio will written.
turaj@webrtc.org4c9b8192012-12-13 22:46:43125 // -audio_samples : number of audio samples out of decoding the given
tina.legrand@webrtc.orgc0cf1db2012-11-05 09:35:51126 // bit-stream.
turaj@webrtc.org4c9b8192012-12-13 22:46:43127 // -speech_type : speech type (for future use).
tina.legrand@webrtc.orgc0cf1db2012-11-05 09:35:51128 //
129 // Return value:
130 // -1 if failed to decode,
131 // 0 if succeeded.
132 //
pbos@webrtc.orgfbda0fc2013-04-09 00:28:06133 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.orgb015cbe2012-10-22 18:19:23138
tina.legrand@webrtc.orgc0cf1db2012-11-05 09:35:51139 ///////////////////////////////////////////////////////////////////////////
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.org4c9b8192012-12-13 22:46:43154 //
pbos@webrtc.orgfbda0fc2013-04-09 00:28:06155 virtual void SplitStereoPacket(uint8_t* /* payload */,
156 int32_t* /* payload_length */) {}
andrew@webrtc.orgb015cbe2012-10-22 18:19:23157
tina.legrand@webrtc.orgc0cf1db2012-11-05 09:35:51158 ///////////////////////////////////////////////////////////////////////////
159 // bool EncoderInitialized();
160 //
161 // Return value:
162 // True if the encoder is successfully initialized,
163 // false otherwise.
164 //
165 bool EncoderInitialized();
andrew@webrtc.orgb015cbe2012-10-22 18:19:23166
tina.legrand@webrtc.orgc0cf1db2012-11-05 09:35:51167 ///////////////////////////////////////////////////////////////////////////
168 // bool DecoderInitialized();
169 //
170 // Return value:
171 // True if the decoder is successfully initialized,
172 // false otherwise.
173 //
174 bool DecoderInitialized();
andrew@webrtc.orgb015cbe2012-10-22 18:19:23175
tina.legrand@webrtc.orgc0cf1db2012-11-05 09:35:51176 ///////////////////////////////////////////////////////////////////////////
pbos@webrtc.orgfbda0fc2013-04-09 00:28:06177 // int16_t EncoderParams()
tina.legrand@webrtc.orgc0cf1db2012-11-05 09:35:51178 // It is called to get encoder parameters. It will call
179 // EncoderParamsSafe() in turn.
180 //
181 // Output:
turaj@webrtc.org4c9b8192012-12-13 22:46:43182 // -enc_params : a buffer where the encoder parameters is
tina.legrand@webrtc.orgc0cf1db2012-11-05 09:35:51183 // 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.orgfbda0fc2013-04-09 00:28:06190 int16_t EncoderParams(WebRtcACMCodecParams *enc_params);
andrew@webrtc.orgb015cbe2012-10-22 18:19:23191
tina.legrand@webrtc.orgc0cf1db2012-11-05 09:35:51192 ///////////////////////////////////////////////////////////////////////////
pbos@webrtc.orgfbda0fc2013-04-09 00:28:06193 // int16_t DecoderParams(...)
tina.legrand@webrtc.orgc0cf1db2012-11-05 09:35:51194 // It is called to get decoder parameters. It will call DecoderParamsSafe()
195 // in turn.
196 //
197 // Output:
turaj@webrtc.org4c9b8192012-12-13 22:46:43198 // -dec_params : a buffer where the decoder parameters is
tina.legrand@webrtc.orgc0cf1db2012-11-05 09:35:51199 // 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.org4c9b8192012-12-13 22:46:43207 bool DecoderParams(WebRtcACMCodecParams *dec_params,
pbos@webrtc.orgfbda0fc2013-04-09 00:28:06208 const uint8_t payload_type);
andrew@webrtc.orgb015cbe2012-10-22 18:19:23209
tina.legrand@webrtc.orgc0cf1db2012-11-05 09:35:51210 ///////////////////////////////////////////////////////////////////////////
pbos@webrtc.orgfbda0fc2013-04-09 00:28:06211 // int16_t InitEncoder(...)
tina.legrand@webrtc.orgc0cf1db2012-11-05 09:35:51212 // This function is called to initialize the encoder with the given
213 // parameters.
214 //
215 // Input:
turaj@webrtc.org4c9b8192012-12-13 22:46:43216 // -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.orgc0cf1db2012-11-05 09:35:51220 //
221 // Return value:
222 // 0 if could initialize successfully,
223 // -1 if failed to initialize.
224 //
225 //
pbos@webrtc.orgfbda0fc2013-04-09 00:28:06226 int16_t InitEncoder(WebRtcACMCodecParams* codec_params,
227 bool force_initialization);
andrew@webrtc.orgb015cbe2012-10-22 18:19:23228
tina.legrand@webrtc.orgc0cf1db2012-11-05 09:35:51229 ///////////////////////////////////////////////////////////////////////////
pbos@webrtc.orgfbda0fc2013-04-09 00:28:06230 // int16_t InitDecoder()
tina.legrand@webrtc.orgc0cf1db2012-11-05 09:35:51231 // 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.org4c9b8192012-12-13 22:46:43236 // -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.orgc0cf1db2012-11-05 09:35:51240 //
241 // Return value:
242 // 0 if could initialize successfully,
243 // -1 if failed to initialize.
244 //
245 //
pbos@webrtc.orgfbda0fc2013-04-09 00:28:06246 int16_t InitDecoder(WebRtcACMCodecParams* codec_params,
247 bool force_initialization);
andrew@webrtc.orgb015cbe2012-10-22 18:19:23248
tina.legrand@webrtc.orgc0cf1db2012-11-05 09:35:51249 ///////////////////////////////////////////////////////////////////////////
pbos@webrtc.orgfbda0fc2013-04-09 00:28:06250 // int32_t RegisterInNetEq(...)
tina.legrand@webrtc.orgc0cf1db2012-11-05 09:35:51251 // This function is called to register the decoder in NetEq, with the given
turaj@webrtc.org4c9b8192012-12-13 22:46:43252 // payload type.
tina.legrand@webrtc.orgc0cf1db2012-11-05 09:35:51253 //
254 // Inputs:
turaj@webrtc.org4c9b8192012-12-13 22:46:43255 // -neteq : pointer to NetEq Instance
256 // -codec_inst : instance with of the codec settings of the codec
tina.legrand@webrtc.orgc0cf1db2012-11-05 09:35:51257 //
258 // Return values
259 // -1 if failed to register,
260 // 0 if successfully initialized.
261 //
pbos@webrtc.orgfbda0fc2013-04-09 00:28:06262 int32_t RegisterInNetEq(ACMNetEQ* neteq, const CodecInst& codec_inst);
andrew@webrtc.orgb015cbe2012-10-22 18:19:23263
tina.legrand@webrtc.orgc0cf1db2012-11-05 09:35:51264 ///////////////////////////////////////////////////////////////////////////
pbos@webrtc.orgfbda0fc2013-04-09 00:28:06265 // int32_t Add10MsData(...)
tina.legrand@webrtc.orgc0cf1db2012-11-05 09:35:51266 // This function is called to add 10 ms of audio to the audio buffer of
267 // the codec.
268 //
269 // Inputs:
turaj@webrtc.org4c9b8192012-12-13 22:46:43270 // -timestamp : the timestamp of the 10 ms audio. the timestamp
tina.legrand@webrtc.orgc0cf1db2012-11-05 09:35:51271 // 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.org4c9b8192012-12-13 22:46:43277 // -audio_channel : 0 for mono, 1 for stereo (not supported yet)
tina.legrand@webrtc.orgc0cf1db2012-11-05 09:35:51278 //
279 // Return values:
280 // -1 if failed
281 // 0 otherwise.
282 //
pbos@webrtc.orgfbda0fc2013-04-09 00:28:06283 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.orgb015cbe2012-10-22 18:19:23287
tina.legrand@webrtc.orgc0cf1db2012-11-05 09:35:51288 ///////////////////////////////////////////////////////////////////////////
pbos@webrtc.orgfbda0fc2013-04-09 00:28:06289 // uint32_t NoMissedSamples()
tina.legrand@webrtc.orgc0cf1db2012-11-05 09:35:51290 // 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.orgfbda0fc2013-04-09 00:28:06298 uint32_t NoMissedSamples() const;
andrew@webrtc.orgb015cbe2012-10-22 18:19:23299
tina.legrand@webrtc.orgc0cf1db2012-11-05 09:35:51300 ///////////////////////////////////////////////////////////////////////////
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.orgb015cbe2012-10-22 18:19:23306
tina.legrand@webrtc.orgc0cf1db2012-11-05 09:35:51307 ///////////////////////////////////////////////////////////////////////////
pbos@webrtc.orgfbda0fc2013-04-09 00:28:06308 // int16_t SetBitRate()
tina.legrand@webrtc.orgc0cf1db2012-11-05 09:35:51309 // The function is called to set the encoding rate.
310 //
311 // Input:
turaj@webrtc.org4c9b8192012-12-13 22:46:43312 // -bitrate_bps : encoding rate in bits per second
tina.legrand@webrtc.orgc0cf1db2012-11-05 09:35:51313 //
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.orgfbda0fc2013-04-09 00:28:06319 int16_t SetBitRate(const int32_t bitrate_bps);
andrew@webrtc.orgb015cbe2012-10-22 18:19:23320
tina.legrand@webrtc.orgc0cf1db2012-11-05 09:35:51321 ///////////////////////////////////////////////////////////////////////////
322 // DestructEncoderInst()
323 // This API is used in conferencing. It will free the memory that is pointed
turaj@webrtc.org4c9b8192012-12-13 22:46:43324 // by |ptr_inst|. |ptr_inst| is a pointer to encoder instance, created and
tina.legrand@webrtc.orgc0cf1db2012-11-05 09:35:51325 // filled up by calling EncoderInst(...).
326 //
327 // Inputs:
turaj@webrtc.org4c9b8192012-12-13 22:46:43328 // -ptr_inst : pointer to an encoder instance to be deleted.
tina.legrand@webrtc.orgc0cf1db2012-11-05 09:35:51329 //
330 //
turaj@webrtc.org4c9b8192012-12-13 22:46:43331 void DestructEncoderInst(void* ptr_inst);
andrew@webrtc.orgb015cbe2012-10-22 18:19:23332
tina.legrand@webrtc.orgc0cf1db2012-11-05 09:35:51333 ///////////////////////////////////////////////////////////////////////////
pbos@webrtc.orgfbda0fc2013-04-09 00:28:06334 // int16_t AudioBuffer()
tina.legrand@webrtc.orgc0cf1db2012-11-05 09:35:51335 // 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.org4c9b8192012-12-13 22:46:43341 // -audio_buff : a pointer to WebRtcACMAudioBuff where the audio
tina.legrand@webrtc.orgc0cf1db2012-11-05 09:35:51342 // 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.orgfbda0fc2013-04-09 00:28:06348 int16_t AudioBuffer(WebRtcACMAudioBuff& audio_buff);
andrew@webrtc.orgb015cbe2012-10-22 18:19:23349
tina.legrand@webrtc.orgc0cf1db2012-11-05 09:35:51350 ///////////////////////////////////////////////////////////////////////////
pbos@webrtc.orgfbda0fc2013-04-09 00:28:06351 // uint32_t EarliestTimestamp()
tina.legrand@webrtc.orgc0cf1db2012-11-05 09:35:51352 // 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.orgfbda0fc2013-04-09 00:28:06358 uint32_t EarliestTimestamp() const;
andrew@webrtc.orgb015cbe2012-10-22 18:19:23359
tina.legrand@webrtc.orgc0cf1db2012-11-05 09:35:51360 ///////////////////////////////////////////////////////////////////////////
pbos@webrtc.orgfbda0fc2013-04-09 00:28:06361 // int16_t SetAudioBuffer()
tina.legrand@webrtc.orgc0cf1db2012-11-05 09:35:51362 // 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.orgfbda0fc2013-04-09 00:28:06369 int16_t SetAudioBuffer(WebRtcACMAudioBuff& audio_buff);
andrew@webrtc.orgb015cbe2012-10-22 18:19:23370
tina.legrand@webrtc.orgc0cf1db2012-11-05 09:35:51371 ///////////////////////////////////////////////////////////////////////////
pbos@webrtc.orgfbda0fc2013-04-09 00:28:06372 // int16_t SetVAD()
tina.legrand@webrtc.org584b6882013-08-27 07:33:51373 // This is called to set VAD & DTX. If the codec has internal DTX, it will
tina.legrand@webrtc.orgc0cf1db2012-11-05 09:35:51374 // 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.org584b6882013-08-27 07:33:51376 // 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.orgc0cf1db2012-11-05 09:35:51378 // 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.org584b6882013-08-27 07:33:51382 // Input/Output:
turaj@webrtc.org4c9b8192012-12-13 22:46:43383 // -enable_dtx : if true DTX will be enabled otherwise the DTX is
tina.legrand@webrtc.orgc0cf1db2012-11-05 09:35:51384 // 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.org4c9b8192012-12-13 22:46:43387 // -enable_vad : if true WebRtc-VAD is enabled, otherwise VAD is
tina.legrand@webrtc.orgc0cf1db2012-11-05 09:35:51388 // 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.org4c9b8192012-12-13 22:46:43391 // |enable_vad|.
tina.legrand@webrtc.orgc0cf1db2012-11-05 09:35:51392 // -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.org584b6882013-08-27 07:33:51398 int16_t SetVAD(bool* enable_dtx,
399 bool* enable_vad,
400 ACMVADMode* mode);
andrew@webrtc.orgb015cbe2012-10-22 18:19:23401
tina.legrand@webrtc.orgc0cf1db2012-11-05 09:35:51402 ///////////////////////////////////////////////////////////////////////////
pbos@webrtc.orgfbda0fc2013-04-09 00:28:06403 // int32_t ReplaceInternalDTX()
tina.legrand@webrtc.orgc0cf1db2012-11-05 09:35:51404 // 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.org4c9b8192012-12-13 22:46:43409 // -replace_internal_dtx : if true the internal DTX is replaced with WebRtc.
tina.legrand@webrtc.orgc0cf1db2012-11-05 09:35:51410 //
411 // Return value
412 // -1 if failed to replace internal DTX,
413 // 0 if succeeded.
414 //
pbos@webrtc.orgfbda0fc2013-04-09 00:28:06415 int32_t ReplaceInternalDTX(const bool replace_internal_dtx);
andrew@webrtc.orgb015cbe2012-10-22 18:19:23416
tina.legrand@webrtc.orgc0cf1db2012-11-05 09:35:51417 ///////////////////////////////////////////////////////////////////////////
pbos@webrtc.orgfbda0fc2013-04-09 00:28:06418 // int32_t IsInternalDTXReplaced()
tina.legrand@webrtc.orgc0cf1db2012-11-05 09:35:51419 // 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.org4c9b8192012-12-13 22:46:43424 // -internal_dtx_replaced: if true the internal DTX is replaced with WebRtc.
tina.legrand@webrtc.orgc0cf1db2012-11-05 09:35:51425 //
426 // Return value
427 // -1 if failed to check
428 // 0 if succeeded.
429 //
pbos@webrtc.orgfbda0fc2013-04-09 00:28:06430 int32_t IsInternalDTXReplaced(bool* internal_dtx_replaced);
andrew@webrtc.orgb015cbe2012-10-22 18:19:23431
tina.legrand@webrtc.orgc0cf1db2012-11-05 09:35:51432 ///////////////////////////////////////////////////////////////////////////
433 // void SetNetEqDecodeLock()
434 // Passes the NetEq lock to the codec.
435 //
436 // Input:
turaj@webrtc.org4c9b8192012-12-13 22:46:43437 // -neteq_decode_lock : pointer to the lock associated with NetEQ of ACM.
tina.legrand@webrtc.orgc0cf1db2012-11-05 09:35:51438 //
turaj@webrtc.org4c9b8192012-12-13 22:46:43439 void SetNetEqDecodeLock(RWLockWrapper* neteq_decode_lock) {
440 neteq_decode_lock_ = neteq_decode_lock;
tina.legrand@webrtc.orgc0cf1db2012-11-05 09:35:51441 }
andrew@webrtc.orgb015cbe2012-10-22 18:19:23442
tina.legrand@webrtc.orgc0cf1db2012-11-05 09:35:51443 ///////////////////////////////////////////////////////////////////////////
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.org4c9b8192012-12-13 22:46:43452 return has_internal_dtx_;
tina.legrand@webrtc.orgc0cf1db2012-11-05 09:35:51453 }
andrew@webrtc.orgb015cbe2012-10-22 18:19:23454
tina.legrand@webrtc.orgc0cf1db2012-11-05 09:35:51455 ///////////////////////////////////////////////////////////////////////////
pbos@webrtc.orgfbda0fc2013-04-09 00:28:06456 // int32_t GetEstimatedBandwidth()
tina.legrand@webrtc.orgc0cf1db2012-11-05 09:35:51457 // 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.orgfbda0fc2013-04-09 00:28:06464 int32_t GetEstimatedBandwidth();
andrew@webrtc.orgb015cbe2012-10-22 18:19:23465
tina.legrand@webrtc.orgc0cf1db2012-11-05 09:35:51466 ///////////////////////////////////////////////////////////////////////////
pbos@webrtc.orgfbda0fc2013-04-09 00:28:06467 // int32_t SetEstimatedBandwidth()
tina.legrand@webrtc.orgc0cf1db2012-11-05 09:35:51468 // 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.org4c9b8192012-12-13 22:46:43472 // -estimated_bandwidth: estimated bandwidth in bits/sec
tina.legrand@webrtc.orgc0cf1db2012-11-05 09:35:51473 //
474 // Return value:
475 // -1 if fails to set estimated bandwidth,
476 // 0 on success.
477 //
pbos@webrtc.orgfbda0fc2013-04-09 00:28:06478 int32_t SetEstimatedBandwidth(int32_t estimated_bandwidth);
andrew@webrtc.orgb015cbe2012-10-22 18:19:23479
tina.legrand@webrtc.orgc0cf1db2012-11-05 09:35:51480 ///////////////////////////////////////////////////////////////////////////
pbos@webrtc.orgfbda0fc2013-04-09 00:28:06481 // int32_t GetRedPayload()
tina.legrand@webrtc.orgc0cf1db2012-11-05 09:35:51482 // Used to get codec specific RED payload (if such is implemented).
483 // Currently only done in iSAC.
484 //
485 // Outputs:
turaj@webrtc.org4c9b8192012-12-13 22:46:43486 // -red_payload : a pointer to the data for RED payload.
487 // -payload_bytes : number of bytes in RED payload.
tina.legrand@webrtc.orgc0cf1db2012-11-05 09:35:51488 //
489 // Return value:
490 // -1 if fails to get codec specific RED,
491 // 0 if succeeded.
492 //
pbos@webrtc.orgfbda0fc2013-04-09 00:28:06493 int32_t GetRedPayload(uint8_t* red_payload,
494 int16_t* payload_bytes);
andrew@webrtc.orgb015cbe2012-10-22 18:19:23495
tina.legrand@webrtc.orgc0cf1db2012-11-05 09:35:51496 ///////////////////////////////////////////////////////////////////////////
pbos@webrtc.orgfbda0fc2013-04-09 00:28:06497 // int16_t ResetEncoder()
tina.legrand@webrtc.orgc0cf1db2012-11-05 09:35:51498 // 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.orgfbda0fc2013-04-09 00:28:06506 int16_t ResetEncoder();
andrew@webrtc.orgb015cbe2012-10-22 18:19:23507
tina.legrand@webrtc.orgc0cf1db2012-11-05 09:35:51508 ///////////////////////////////////////////////////////////////////////////
pbos@webrtc.orgfbda0fc2013-04-09 00:28:06509 // int16_t ResetEncoder()
tina.legrand@webrtc.orgc0cf1db2012-11-05 09:35:51510 // 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.orgfbda0fc2013-04-09 00:28:06517 int16_t ResetDecoder(int16_t payload_type);
andrew@webrtc.orgb015cbe2012-10-22 18:19:23518
tina.legrand@webrtc.orgc0cf1db2012-11-05 09:35:51519 ///////////////////////////////////////////////////////////////////////////
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.orgb015cbe2012-10-22 18:19:23527
tina.legrand@webrtc.orgc0cf1db2012-11-05 09:35:51528 ///////////////////////////////////////////////////////////////////////////
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.orgb015cbe2012-10-22 18:19:23537
tina.legrand@webrtc.orgc0cf1db2012-11-05 09:35:51538 ///////////////////////////////////////////////////////////////////////////
pbos@webrtc.orgfbda0fc2013-04-09 00:28:06539 // int16_t SamplesLeftToEncode()
tina.legrand@webrtc.orgc0cf1db2012-11-05 09:35:51540 // Returns the number of samples required to be able to do encoding.
541 //
542 // Return value:
543 // Number of samples.
544 //
pbos@webrtc.orgfbda0fc2013-04-09 00:28:06545 int16_t SamplesLeftToEncode();
andrew@webrtc.orgb015cbe2012-10-22 18:19:23546
tina.legrand@webrtc.orgc0cf1db2012-11-05 09:35:51547 ///////////////////////////////////////////////////////////////////////////
pbos@webrtc.orgfbda0fc2013-04-09 00:28:06548 // uint32_t LastEncodedTimestamp()
tina.legrand@webrtc.orgc0cf1db2012-11-05 09:35:51549 // Returns the timestamp of the last frame it encoded.
550 //
551 // Return value:
552 // Timestamp.
553 //
pbos@webrtc.orgfbda0fc2013-04-09 00:28:06554 uint32_t LastEncodedTimestamp() const;
andrew@webrtc.orgb015cbe2012-10-22 18:19:23555
tina.legrand@webrtc.orgc0cf1db2012-11-05 09:35:51556 ///////////////////////////////////////////////////////////////////////////
557 // SetUniqueID()
turaj@webrtc.org4c9b8192012-12-13 22:46:43558 // Set a unique ID for the codec to be used for tracing and debugging
tina.legrand@webrtc.orgc0cf1db2012-11-05 09:35:51559 //
560 // Input
561 // -id : A number to identify the codec.
562 //
pbos@webrtc.orgfbda0fc2013-04-09 00:28:06563 void SetUniqueID(const uint32_t id);
andrew@webrtc.orgb015cbe2012-10-22 18:19:23564
tina.legrand@webrtc.orgc0cf1db2012-11-05 09:35:51565 ///////////////////////////////////////////////////////////////////////////
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.orgb015cbe2012-10-22 18:19:23574
tina.legrand@webrtc.orgc0cf1db2012-11-05 09:35:51575 ///////////////////////////////////////////////////////////////////////////
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.org4c9b8192012-12-13 22:46:43579 // decoder for different flavors of the codec. One example is iSAC. there,
tina.legrand@webrtc.orgc0cf1db2012-11-05 09:35:51580 // 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.org4c9b8192012-12-13 22:46:43585 // Each time that we receive a new payload type, we call this function to
tina.legrand@webrtc.orgc0cf1db2012-11-05 09:35:51586 // 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.org4c9b8192012-12-13 22:46:43588 // sampling rate. The input parameter specifies the current flavor of the
tina.legrand@webrtc.orgc0cf1db2012-11-05 09:35:51589 // 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.org4c9b8192012-12-13 22:46:43593 // -codec_id : the ID of the codec associated with the
tina.legrand@webrtc.orgc0cf1db2012-11-05 09:35:51594 // 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.orgdd1b19d2013-07-31 15:54:00600 virtual int16_t UpdateDecoderSampFreq(int16_t /* codec_id */);
andrew@webrtc.orgb015cbe2012-10-22 18:19:23601
tina.legrand@webrtc.orgc0cf1db2012-11-05 09:35:51602 ///////////////////////////////////////////////////////////////////////////
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.org4c9b8192012-12-13 22:46:43612 // -samp_freq_hz : encoder sampling frequency.
tina.legrand@webrtc.orgc0cf1db2012-11-05 09:35:51613 //
614 // Return value:
615 // -1 if failed, or if this is meaningless for the given codec.
616 // 0 if succeeded.
617 //
pbos@webrtc.orgfbda0fc2013-04-09 00:28:06618 virtual int16_t UpdateEncoderSampFreq(
619 uint16_t samp_freq_hz);
andrew@webrtc.orgb015cbe2012-10-22 18:19:23620
tina.legrand@webrtc.orgc0cf1db2012-11-05 09:35:51621 ///////////////////////////////////////////////////////////////////////////
622 // EncoderSampFreq()
623 // Get the sampling frequency that the encoder (WebRtc wrapper) expects.
624 //
625 // Output:
turaj@webrtc.org4c9b8192012-12-13 22:46:43626 // -samp_freq_hz : sampling frequency, in Hertz, which the encoder
tina.legrand@webrtc.orgc0cf1db2012-11-05 09:35:51627 // 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.orgfbda0fc2013-04-09 00:28:06633 virtual int16_t EncoderSampFreq(uint16_t& samp_freq_hz);
andrew@webrtc.orgb015cbe2012-10-22 18:19:23634
tina.legrand@webrtc.orgc0cf1db2012-11-05 09:35:51635 ///////////////////////////////////////////////////////////////////////////
pbos@webrtc.orgfbda0fc2013-04-09 00:28:06636 // int32_t ConfigISACBandwidthEstimator()
tina.legrand@webrtc.orgc0cf1db2012-11-05 09:35:51637 // Call this function to configure the bandwidth estimator of ISAC.
turaj@webrtc.org4c9b8192012-12-13 22:46:43638 // During the adaptation of bit-rate, iSAC automatically adjusts the
tina.legrand@webrtc.orgc0cf1db2012-11-05 09:35:51639 // 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.org4c9b8192012-12-13 22:46:43647 // -init_frame_fize_ms : initial frame-size in milliseconds. For iSAC-wb
tina.legrand@webrtc.orgc0cf1db2012-11-05 09:35:51648 // 30 ms and 60 ms (default) are acceptable values,
649 // and for iSAC-swb 30 ms is the only acceptable
turaj@webrtc.org4c9b8192012-12-13 22:46:43650 // value. Zero indicates default value.
651 // -init_rate_bps : initial estimate of the bandwidth. Values
tina.legrand@webrtc.orgc0cf1db2012-11-05 09:35:51652 // between 10000 and 58000 are acceptable.
turaj@webrtc.org4c9b8192012-12-13 22:46:43653 // -enforce_frame_size : if true, the frame-size will not be adapted.
tina.legrand@webrtc.orgc0cf1db2012-11-05 09:35:51654 //
655 // Return value:
656 // -1 if failed to configure the bandwidth estimator,
657 // 0 if the configuration was successfully applied.
658 //
pbos@webrtc.orgfbda0fc2013-04-09 00:28:06659 virtual int32_t ConfigISACBandwidthEstimator(
660 const uint8_t init_frame_size_msec,
661 const uint16_t init_rate_bps,
turaj@webrtc.org4c9b8192012-12-13 22:46:43662 const bool enforce_frame_size);
andrew@webrtc.orgb015cbe2012-10-22 18:19:23663
tina.legrand@webrtc.orgc0cf1db2012-11-05 09:35:51664 ///////////////////////////////////////////////////////////////////////////
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.org4c9b8192012-12-13 22:46:43669 // (B < max_payload_len_bytes * 8) and (B/T < max_rate_bit_per_sec), c.f.
tina.legrand@webrtc.orgc0cf1db2012-11-05 09:35:51670 // SetISACMaxRate().
671 //
672 // Input:
turaj@webrtc.org4c9b8192012-12-13 22:46:43673 // -max_payload_len_bytes : maximum payload size in bytes.
tina.legrand@webrtc.orgc0cf1db2012-11-05 09:35:51674 //
675 // Return value:
turaj@webrtc.org4c9b8192012-12-13 22:46:43676 // -1 if failed to set the maximum payload-size.
677 // 0 if the given length is set successfully.
tina.legrand@webrtc.orgc0cf1db2012-11-05 09:35:51678 //
pbos@webrtc.orgfbda0fc2013-04-09 00:28:06679 virtual int32_t SetISACMaxPayloadSize(
680 const uint16_t max_payload_len_bytes);
andrew@webrtc.orgb015cbe2012-10-22 18:19:23681
tina.legrand@webrtc.orgc0cf1db2012-11-05 09:35:51682 ///////////////////////////////////////////////////////////////////////////
683 // SetISACMaxRate()
684 // Set the maximum instantaneous rate of iSAC. For a payload of B bits
turaj@webrtc.org4c9b8192012-12-13 22:46:43685 // 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.orgc0cf1db2012-11-05 09:35:51688 // c.f SetISACMaxPayloadSize().
689 //
690 // Input:
turaj@webrtc.org4c9b8192012-12-13 22:46:43691 // -max_rate_bps : maximum instantaneous bit-rate given in bits/sec.
tina.legrand@webrtc.orgc0cf1db2012-11-05 09:35:51692 //
693 // Return value:
694 // -1 if failed to set the maximum rate.
695 // 0 if the maximum rate is set successfully.
696 //
pbos@webrtc.orgfbda0fc2013-04-09 00:28:06697 virtual int32_t SetISACMaxRate(const uint32_t max_rate_bps);
andrew@webrtc.orgb015cbe2012-10-22 18:19:23698
tina.legrand@webrtc.orgc0cf1db2012-11-05 09:35:51699 ///////////////////////////////////////////////////////////////////////////
700 // SaveDecoderParamS()
701 // Save the parameters of decoder.
702 //
703 // Input:
turaj@webrtc.org4c9b8192012-12-13 22:46:43704 // -codec_params : pointer to a structure where the parameters of
tina.legrand@webrtc.orgc0cf1db2012-11-05 09:35:51705 // decoder is stored in.
706 //
turaj@webrtc.org4c9b8192012-12-13 22:46:43707 void SaveDecoderParam(const WebRtcACMCodecParams* codec_params);
andrew@webrtc.orgb015cbe2012-10-22 18:19:23708
pbos@webrtc.orgfbda0fc2013-04-09 00:28:06709 int32_t FrameSize() {
turaj@webrtc.org4c9b8192012-12-13 22:46:43710 return frame_len_smpl_;
tina.legrand@webrtc.orgc0cf1db2012-11-05 09:35:51711 }
andrew@webrtc.orgb015cbe2012-10-22 18:19:23712
turaj@webrtc.org4c9b8192012-12-13 22:46:43713 void SetIsMaster(bool is_master);
andrew@webrtc.orgb015cbe2012-10-22 18:19:23714
tina.legrand@webrtc.orgc0cf1db2012-11-05 09:35:51715 ///////////////////////////////////////////////////////////////////////////
716 // REDPayloadISAC()
717 // This is an iSAC-specific function. The function is called to get RED
turaj@webrtc.org1952f252012-12-03 22:13:31718 // payload from a default-encoder.
tina.legrand@webrtc.orgc0cf1db2012-11-05 09:35:51719 //
720 // Inputs:
turaj@webrtc.org4c9b8192012-12-13 22:46:43721 // -isac_rate : the target rate of the main payload. A RED
turaj@webrtc.org1952f252012-12-03 22:13:31722 // payload is generated according to the rate of
723 // main payload. Note that we are not specifying the
tina.legrand@webrtc.orgc0cf1db2012-11-05 09:35:51724 // rate of RED payload, but the main payload.
turaj@webrtc.org4c9b8192012-12-13 22:46:43725 // -isac_bw_estimate : bandwidth information should be inserted in
tina.legrand@webrtc.orgc0cf1db2012-11-05 09:35:51726 // RED payload.
727 //
728 // Output:
turaj@webrtc.org1952f252012-12-03 22:13:31729 // -payload : pointer to a buffer where the RED payload will
tina.legrand@webrtc.orgc0cf1db2012-11-05 09:35:51730 // written to.
turaj@webrtc.org4c9b8192012-12-13 22:46:43731 // -payload_len_bytes : a place-holder to write the length of the RED
tina.legrand@webrtc.orgc0cf1db2012-11-05 09:35:51732 // payload in Bytes.
733 //
734 // Return value:
turaj@webrtc.org4c9b8192012-12-13 22:46:43735 // -1 if an error occurs, otherwise the length of the payload (in Bytes)
tina.legrand@webrtc.orgc0cf1db2012-11-05 09:35:51736 // is returned.
737 //
pbos@webrtc.orgfbda0fc2013-04-09 00:28:06738 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.orgb015cbe2012-10-22 18:19:23742
tina.legrand@webrtc.orgc0cf1db2012-11-05 09:35:51743 ///////////////////////////////////////////////////////////////////////////
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.orgdd1b19d2013-07-31 15:54:00751 virtual bool IsTrueStereoCodec();
andrew@webrtc.orgb015cbe2012-10-22 18:19:23752
turaj@webrtc.org1952f252012-12-03 22:13:31753 ///////////////////////////////////////////////////////////////////////////
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.orgc0cf1db2012-11-05 09:35:51760 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.orgb015cbe2012-10-22 18:19:23768
tina.legrand@webrtc.orgc0cf1db2012-11-05 09:35:51769 ///////////////////////////////////////////////////////////////////////////
tina.legrand@webrtc.orgc0cf1db2012-11-05 09:35:51770 // See Decode() for the description of function, input(s)/output(s) and
771 // return value.
772 //
pbos@webrtc.orgfbda0fc2013-04-09 00:28:06773 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.orgb015cbe2012-10-22 18:19:23778
tina.legrand@webrtc.orgc0cf1db2012-11-05 09:35:51779 ///////////////////////////////////////////////////////////////////////////
780 // See Add10MsSafe() for the description of function, input(s)/output(s)
781 // and return value.
782 //
pbos@webrtc.orgfbda0fc2013-04-09 00:28:06783 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.orgb015cbe2012-10-22 18:19:23787
tina.legrand@webrtc.orgc0cf1db2012-11-05 09:35:51788 ///////////////////////////////////////////////////////////////////////////
789 // See RegisterInNetEq() for the description of function,
790 // input(s)/output(s) and return value.
791 //
pbos@webrtc.orgfbda0fc2013-04-09 00:28:06792 virtual int32_t CodecDef(WebRtcNetEQ_CodecDef& codec_def,
793 const CodecInst& codec_inst) = 0;
andrew@webrtc.orgb015cbe2012-10-22 18:19:23794
tina.legrand@webrtc.orgc0cf1db2012-11-05 09:35:51795 ///////////////////////////////////////////////////////////////////////////
796 // See EncoderParam() for the description of function, input(s)/output(s)
797 // and return value.
798 //
pbos@webrtc.orgfbda0fc2013-04-09 00:28:06799 int16_t EncoderParamsSafe(WebRtcACMCodecParams *enc_params);
andrew@webrtc.orgb015cbe2012-10-22 18:19:23800
tina.legrand@webrtc.orgc0cf1db2012-11-05 09:35:51801 ///////////////////////////////////////////////////////////////////////////
802 // See DecoderParam for the description of function, input(s)/output(s)
803 // and return value.
804 //
805 // Note:
turaj@webrtc.org4c9b8192012-12-13 22:46:43806 // Any Class where a single instance handle several flavors of the
tina.legrand@webrtc.orgc0cf1db2012-11-05 09:35:51807 // 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.org4c9b8192012-12-13 22:46:43815 virtual bool DecoderParamsSafe(WebRtcACMCodecParams *dec_params,
pbos@webrtc.orgfbda0fc2013-04-09 00:28:06816 const uint8_t payload_type);
andrew@webrtc.orgb015cbe2012-10-22 18:19:23817
tina.legrand@webrtc.orgc0cf1db2012-11-05 09:35:51818 ///////////////////////////////////////////////////////////////////////////
819 // See ResetEncoder() for the description of function, input(s)/output(s)
820 // and return value.
821 //
pbos@webrtc.orgfbda0fc2013-04-09 00:28:06822 int16_t ResetEncoderSafe();
andrew@webrtc.orgb015cbe2012-10-22 18:19:23823
tina.legrand@webrtc.orgc0cf1db2012-11-05 09:35:51824 ///////////////////////////////////////////////////////////////////////////
825 // See InitEncoder() for the description of function, input(s)/output(s)
826 // and return value.
827 //
pbos@webrtc.orgfbda0fc2013-04-09 00:28:06828 int16_t InitEncoderSafe(WebRtcACMCodecParams *codec_params,
829 bool force_initialization);
andrew@webrtc.orgb015cbe2012-10-22 18:19:23830
tina.legrand@webrtc.orgc0cf1db2012-11-05 09:35:51831 ///////////////////////////////////////////////////////////////////////////
832 // See InitDecoder() for the description of function, input(s)/output(s)
833 // and return value.
834 //
pbos@webrtc.orgfbda0fc2013-04-09 00:28:06835 int16_t InitDecoderSafe(WebRtcACMCodecParams *codec_params,
836 bool force_initialization);
andrew@webrtc.orgb015cbe2012-10-22 18:19:23837
tina.legrand@webrtc.orgc0cf1db2012-11-05 09:35:51838 ///////////////////////////////////////////////////////////////////////////
839 // See ResetDecoder() for the description of function, input(s)/output(s)
840 // and return value.
841 //
pbos@webrtc.orgfbda0fc2013-04-09 00:28:06842 int16_t ResetDecoderSafe(int16_t payload_type);
andrew@webrtc.orgb015cbe2012-10-22 18:19:23843
tina.legrand@webrtc.orgc0cf1db2012-11-05 09:35:51844 ///////////////////////////////////////////////////////////////////////////
845 // See DestructEncoder() for the description of function,
846 // input(s)/output(s) and return value.
847 //
848 virtual void DestructEncoderSafe() = 0;
andrew@webrtc.orgb015cbe2012-10-22 18:19:23849
tina.legrand@webrtc.orgc0cf1db2012-11-05 09:35:51850 ///////////////////////////////////////////////////////////////////////////
851 // See DestructDecoder() for the description of function,
852 // input(s)/output(s) and return value.
853 //
854 virtual void DestructDecoderSafe() = 0;
andrew@webrtc.orgb015cbe2012-10-22 18:19:23855
tina.legrand@webrtc.orgc0cf1db2012-11-05 09:35:51856 ///////////////////////////////////////////////////////////////////////////
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.orgfbda0fc2013-04-09 00:28:06862 virtual int16_t SetBitRateSafe(const int32_t bitrate_bps);
andrew@webrtc.orgb015cbe2012-10-22 18:19:23863
tina.legrand@webrtc.orgc0cf1db2012-11-05 09:35:51864 ///////////////////////////////////////////////////////////////////////////
865 // See GetEstimatedBandwidth() for the description of function,
866 // input(s)/output(s) and return value.
867 //
pbos@webrtc.orgfbda0fc2013-04-09 00:28:06868 virtual int32_t GetEstimatedBandwidthSafe();
andrew@webrtc.orgb015cbe2012-10-22 18:19:23869
tina.legrand@webrtc.orgc0cf1db2012-11-05 09:35:51870 ///////////////////////////////////////////////////////////////////////////
871 // See SetEstimatedBandwidth() for the description of function,
872 // input(s)/output(s) and return value.
873 //
pbos@webrtc.orgfbda0fc2013-04-09 00:28:06874 virtual int32_t SetEstimatedBandwidthSafe(
875 int32_t estimated_bandwidth);
andrew@webrtc.orgb015cbe2012-10-22 18:19:23876
tina.legrand@webrtc.orgc0cf1db2012-11-05 09:35:51877 ///////////////////////////////////////////////////////////////////////////
878 // See GetRedPayload() for the description of function, input(s)/output(s)
879 // and return value.
880 //
pbos@webrtc.orgfbda0fc2013-04-09 00:28:06881 virtual int32_t GetRedPayloadSafe(uint8_t* red_payload,
882 int16_t* payload_bytes);
andrew@webrtc.orgb015cbe2012-10-22 18:19:23883
tina.legrand@webrtc.orgc0cf1db2012-11-05 09:35:51884 ///////////////////////////////////////////////////////////////////////////
885 // See SetVAD() for the description of function, input(s)/output(s) and
886 // return value.
887 //
tina.legrand@webrtc.org584b6882013-08-27 07:33:51888 int16_t SetVADSafe(bool* enable_dtx,
889 bool* enable_vad,
890 ACMVADMode* mode);
andrew@webrtc.orgb015cbe2012-10-22 18:19:23891
tina.legrand@webrtc.orgc0cf1db2012-11-05 09:35:51892 ///////////////////////////////////////////////////////////////////////////
893 // See ReplaceInternalDTX() for the description of function, input and
894 // return value.
895 //
pbos@webrtc.orgfbda0fc2013-04-09 00:28:06896 virtual int32_t ReplaceInternalDTXSafe(const bool replace_internal_dtx);
andrew@webrtc.orgb015cbe2012-10-22 18:19:23897
tina.legrand@webrtc.orgc0cf1db2012-11-05 09:35:51898 ///////////////////////////////////////////////////////////////////////////
899 // See IsInternalDTXReplaced() for the description of function, input and
900 // return value.
901 //
pbos@webrtc.orgfbda0fc2013-04-09 00:28:06902 virtual int32_t IsInternalDTXReplacedSafe(bool* internal_dtx_replaced);
andrew@webrtc.orgb015cbe2012-10-22 18:19:23903
tina.legrand@webrtc.orgc0cf1db2012-11-05 09:35:51904 ///////////////////////////////////////////////////////////////////////////
pbos@webrtc.orgfbda0fc2013-04-09 00:28:06905 // int16_t CreateEncoder()
tina.legrand@webrtc.orgc0cf1db2012-11-05 09:35:51906 // Creates the encoder instance.
907 //
908 // Return value:
909 // -1 if failed,
910 // 0 if succeeded.
911 //
pbos@webrtc.orgfbda0fc2013-04-09 00:28:06912 int16_t CreateEncoder();
andrew@webrtc.orgb015cbe2012-10-22 18:19:23913
tina.legrand@webrtc.orgc0cf1db2012-11-05 09:35:51914 ///////////////////////////////////////////////////////////////////////////
pbos@webrtc.orgfbda0fc2013-04-09 00:28:06915 // int16_t CreateDecoder()
tina.legrand@webrtc.orgc0cf1db2012-11-05 09:35:51916 // Creates the decoder instance.
917 //
918 // Return value:
919 // -1 if failed,
920 // 0 if succeeded.
921 //
pbos@webrtc.orgfbda0fc2013-04-09 00:28:06922 int16_t CreateDecoder();
andrew@webrtc.orgb015cbe2012-10-22 18:19:23923
tina.legrand@webrtc.orgc0cf1db2012-11-05 09:35:51924 ///////////////////////////////////////////////////////////////////////////
pbos@webrtc.orgfbda0fc2013-04-09 00:28:06925 // int16_t EnableVAD();
tina.legrand@webrtc.orgc0cf1db2012-11-05 09:35:51926 // 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.orgfbda0fc2013-04-09 00:28:06937 int16_t EnableVAD(ACMVADMode mode);
andrew@webrtc.orgb015cbe2012-10-22 18:19:23938
tina.legrand@webrtc.orgc0cf1db2012-11-05 09:35:51939 ///////////////////////////////////////////////////////////////////////////
pbos@webrtc.orgfbda0fc2013-04-09 00:28:06940 // int16_t DisableVAD()
tina.legrand@webrtc.orgc0cf1db2012-11-05 09:35:51941 // Disables VAD.
942 //
943 // Return value:
944 // -1 if failed,
945 // 0 if succeeded.
946 //
pbos@webrtc.orgfbda0fc2013-04-09 00:28:06947 int16_t DisableVAD();
andrew@webrtc.orgb015cbe2012-10-22 18:19:23948
tina.legrand@webrtc.orgc0cf1db2012-11-05 09:35:51949 ///////////////////////////////////////////////////////////////////////////
pbos@webrtc.orgfbda0fc2013-04-09 00:28:06950 // int16_t EnableDTX()
tina.legrand@webrtc.orgc0cf1db2012-11-05 09:35:51951 // 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.orgfbda0fc2013-04-09 00:28:06958 virtual int16_t EnableDTX();
andrew@webrtc.orgb015cbe2012-10-22 18:19:23959
tina.legrand@webrtc.orgc0cf1db2012-11-05 09:35:51960 ///////////////////////////////////////////////////////////////////////////
pbos@webrtc.orgfbda0fc2013-04-09 00:28:06961 // int16_t DisableDTX()
tina.legrand@webrtc.orgc0cf1db2012-11-05 09:35:51962 // 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.orgfbda0fc2013-04-09 00:28:06969 virtual int16_t DisableDTX();
andrew@webrtc.orgb015cbe2012-10-22 18:19:23970
tina.legrand@webrtc.orgc0cf1db2012-11-05 09:35:51971 ///////////////////////////////////////////////////////////////////////////
pbos@webrtc.orgfbda0fc2013-04-09 00:28:06972 // int16_t InternalEncode()
tina.legrand@webrtc.orgc0cf1db2012-11-05 09:35:51973 // This is a codec-specific function called in EncodeSafe() to actually
974 // encode a frame of audio.
975 //
976 // Outputs:
turaj@webrtc.org4c9b8192012-12-13 22:46:43977 // -bitstream : pointer to a buffer where the bit-stream is
tina.legrand@webrtc.orgc0cf1db2012-11-05 09:35:51978 // written to.
turaj@webrtc.org4c9b8192012-12-13 22:46:43979 // -bitstream_len_byte : the length of the bit-stream in bytes,
tina.legrand@webrtc.orgc0cf1db2012-11-05 09:35:51980 // 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.orgfbda0fc2013-04-09 00:28:06986 virtual int16_t InternalEncode(uint8_t* bitstream,
987 int16_t* bitstream_len_byte) = 0;
andrew@webrtc.orgb015cbe2012-10-22 18:19:23988
tina.legrand@webrtc.orgc0cf1db2012-11-05 09:35:51989 ///////////////////////////////////////////////////////////////////////////
pbos@webrtc.orgfbda0fc2013-04-09 00:28:06990 // int16_t InternalInitEncoder()
tina.legrand@webrtc.orgc0cf1db2012-11-05 09:35:51991 // 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.org4c9b8192012-12-13 22:46:43996 // -codec_params : pointer to a structure that contains parameters to
tina.legrand@webrtc.orgc0cf1db2012-11-05 09:35:51997 // initialize encoder.
turaj@webrtc.org4c9b8192012-12-13 22:46:43998 // Set codec_params->codec_inst.rate to -1 for
tina.legrand@webrtc.orgc0cf1db2012-11-05 09:35:51999 // 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.orgfbda0fc2013-04-09 00:28:061008 virtual int16_t InternalInitEncoder(
turaj@webrtc.org4c9b8192012-12-13 22:46:431009 WebRtcACMCodecParams *codec_params) = 0;
andrew@webrtc.orgb015cbe2012-10-22 18:19:231010
tina.legrand@webrtc.orgc0cf1db2012-11-05 09:35:511011 ///////////////////////////////////////////////////////////////////////////
pbos@webrtc.orgfbda0fc2013-04-09 00:28:061012 // int16_t InternalInitDecoder()
tina.legrand@webrtc.orgc0cf1db2012-11-05 09:35:511013 // 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.org4c9b8192012-12-13 22:46:431018 // -codec_params : pointer to a structure that contains parameters to
tina.legrand@webrtc.orgc0cf1db2012-11-05 09:35:511019 // initialize encoder.
1020 //
1021 // Return value:
1022 // -1 if failed,
1023 // 0 if succeeded.
1024 //
pbos@webrtc.orgfbda0fc2013-04-09 00:28:061025 virtual int16_t InternalInitDecoder(
turaj@webrtc.org4c9b8192012-12-13 22:46:431026 WebRtcACMCodecParams *codec_params) = 0;
andrew@webrtc.orgb015cbe2012-10-22 18:19:231027
tina.legrand@webrtc.orgc0cf1db2012-11-05 09:35:511028 ///////////////////////////////////////////////////////////////////////////
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.org4c9b8192012-12-13 22:46:431034 // -num_samples : the number of overwritten samples is incremented
tina.legrand@webrtc.orgc0cf1db2012-11-05 09:35:511035 // by this value.
1036 //
pbos@webrtc.orgfbda0fc2013-04-09 00:28:061037 void IncreaseNoMissedSamples(const int16_t num_samples);
andrew@webrtc.orgb015cbe2012-10-22 18:19:231038
tina.legrand@webrtc.orgc0cf1db2012-11-05 09:35:511039 ///////////////////////////////////////////////////////////////////////////
pbos@webrtc.orgfbda0fc2013-04-09 00:28:061040 // int16_t InternalCreateEncoder()
tina.legrand@webrtc.orgc0cf1db2012-11-05 09:35:511041 // 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.orgfbda0fc2013-04-09 00:28:061049 virtual int16_t InternalCreateEncoder() = 0;
andrew@webrtc.orgb015cbe2012-10-22 18:19:231050
tina.legrand@webrtc.orgc0cf1db2012-11-05 09:35:511051 ///////////////////////////////////////////////////////////////////////////
pbos@webrtc.orgfbda0fc2013-04-09 00:28:061052 // int16_t InternalCreateDecoder()
tina.legrand@webrtc.orgc0cf1db2012-11-05 09:35:511053 // 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.orgfbda0fc2013-04-09 00:28:061061 virtual int16_t InternalCreateDecoder() = 0;
andrew@webrtc.orgb015cbe2012-10-22 18:19:231062
tina.legrand@webrtc.orgc0cf1db2012-11-05 09:35:511063 ///////////////////////////////////////////////////////////////////////////
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.org4c9b8192012-12-13 22:46:431068 // instance). This method is called to free the memory that |ptr_inst| is
tina.legrand@webrtc.orgc0cf1db2012-11-05 09:35:511069 // pointing to.
1070 //
1071 // Input:
turaj@webrtc.org4c9b8192012-12-13 22:46:431072 // -ptr_inst : pointer to encoder instance.
tina.legrand@webrtc.orgc0cf1db2012-11-05 09:35:511073 //
1074 // Return value:
1075 // -1 if failed,
1076 // 0 if succeeded.
1077 //
turaj@webrtc.org4c9b8192012-12-13 22:46:431078 virtual void InternalDestructEncoderInst(void* ptr_inst) = 0;
andrew@webrtc.orgb015cbe2012-10-22 18:19:231079
tina.legrand@webrtc.orgc0cf1db2012-11-05 09:35:511080 ///////////////////////////////////////////////////////////////////////////
pbos@webrtc.orgfbda0fc2013-04-09 00:28:061081 // int16_t InternalResetEncoder()
tina.legrand@webrtc.orgc0cf1db2012-11-05 09:35:511082 // 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.orgfbda0fc2013-04-09 00:28:061093 virtual int16_t InternalResetEncoder();
andrew@webrtc.orgb015cbe2012-10-22 18:19:231094
tina.legrand@webrtc.orgc0cf1db2012-11-05 09:35:511095 ///////////////////////////////////////////////////////////////////////////
pbos@webrtc.orgfbda0fc2013-04-09 00:28:061096 // int16_t ProcessFrameVADDTX()
tina.legrand@webrtc.orgc0cf1db2012-11-05 09:35:511097 // 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.org4c9b8192012-12-13 22:46:431102 // '*samples_processed' set to zero. There, the audio frame will be encoded
tina.legrand@webrtc.orgc0cf1db2012-11-05 09:35:511103 // 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.org4c9b8192012-12-13 22:46:431105 // which is EncodeSafe(), with "*samples_processed" equal to the number of
tina.legrand@webrtc.orgc0cf1db2012-11-05 09:35:511106 // samples in first block.
1107 //
1108 // Output:
turaj@webrtc.org4c9b8192012-12-13 22:46:431109 // -bitstream : pointer to a buffer where DTX frame, if
tina.legrand@webrtc.orgc0cf1db2012-11-05 09:35:511110 // generated, will be written to.
turaj@webrtc.org4c9b8192012-12-13 22:46:431111 // -bitstream_len_byte : contains the length of bit-stream in bytes, if
tina.legrand@webrtc.orgc0cf1db2012-11-05 09:35:511112 // generated. Zero if no bit-stream is generated.
turaj@webrtc.org4c9b8192012-12-13 22:46:431113 // -samples_processed : contains no of samples that actually CN has
tina.legrand@webrtc.orgc0cf1db2012-11-05 09:35:511114 // 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.org4c9b8192012-12-13 22:46:431118 // "*samples_processed" might be non-zero but
1119 // "*bitstream_len_byte" be zero.
tina.legrand@webrtc.orgc0cf1db2012-11-05 09:35:511120 //
1121 // Return value:
1122 // -1 if failed,
1123 // 0 if succeeded.
1124 //
pbos@webrtc.orgfbda0fc2013-04-09 00:28:061125 int16_t ProcessFrameVADDTX(uint8_t* bitstream,
1126 int16_t* bitstream_len_byte,
1127 int16_t* samples_processed);
andrew@webrtc.orgb015cbe2012-10-22 18:19:231128
tina.legrand@webrtc.orgc0cf1db2012-11-05 09:35:511129 ///////////////////////////////////////////////////////////////////////////
1130 // CanChangeEncodingParam()
1131 // Check if the codec parameters can be changed. In conferencing normally
turaj@webrtc.org4c9b8192012-12-13 22:46:431132 // codec parameters cannot be changed. The exception is bit-rate of isac.
tina.legrand@webrtc.orgc0cf1db2012-11-05 09:35:511133 //
1134 // return value:
1135 // -true if codec parameters are allowed to change.
turaj@webrtc.org4c9b8192012-12-13 22:46:431136 // -false otherwise.
tina.legrand@webrtc.orgc0cf1db2012-11-05 09:35:511137 //
turaj@webrtc.org4c9b8192012-12-13 22:46:431138 virtual bool CanChangeEncodingParam(CodecInst& codec_inst);
andrew@webrtc.orgb015cbe2012-10-22 18:19:231139
tina.legrand@webrtc.orgc0cf1db2012-11-05 09:35:511140 ///////////////////////////////////////////////////////////////////////////
1141 // CurrentRate()
1142 // Call to get the current encoding rate of the encoder. This function
turaj@webrtc.org4c9b8192012-12-13 22:46:431143 // should be overwritten for codecs which automatically change their
tina.legrand@webrtc.orgc0cf1db2012-11-05 09:35:511144 // target rate. One example is iSAC. The output of the function is the
1145 // current target rate.
1146 //
1147 // Output:
turaj@webrtc.org4c9b8192012-12-13 22:46:431148 // -rate_bps : the current target rate of the codec.
tina.legrand@webrtc.orgc0cf1db2012-11-05 09:35:511149 //
pbos@webrtc.orgdd1b19d2013-07-31 15:54:001150 virtual void CurrentRate(int32_t& /* rate_bps */);
andrew@webrtc.orgb015cbe2012-10-22 18:19:231151
turaj@webrtc.org4c9b8192012-12-13 22:46:431152 virtual void SaveDecoderParamSafe(const WebRtcACMCodecParams* codec_params);
andrew@webrtc.orgb015cbe2012-10-22 18:19:231153
turaj@webrtc.org4c9b8192012-12-13 22:46:431154 // &in_audio_[in_audio_ix_write_] always point to where new audio can be
tina.legrand@webrtc.orgc0cf1db2012-11-05 09:35:511155 // written to
pbos@webrtc.orgfbda0fc2013-04-09 00:28:061156 int16_t in_audio_ix_write_;
andrew@webrtc.orgb015cbe2012-10-22 18:19:231157
turaj@webrtc.org4c9b8192012-12-13 22:46:431158 // &in_audio_[in_audio_ix_read_] points to where audio has to be read from
pbos@webrtc.orgfbda0fc2013-04-09 00:28:061159 int16_t in_audio_ix_read_;
andrew@webrtc.orgb015cbe2012-10-22 18:19:231160
pbos@webrtc.orgfbda0fc2013-04-09 00:28:061161 int16_t in_timestamp_ix_write_;
andrew@webrtc.orgb015cbe2012-10-22 18:19:231162
tina.legrand@webrtc.orgc0cf1db2012-11-05 09:35:511163 // Where the audio is stored before encoding,
1164 // To save memory the following buffer can be allocated
turaj@webrtc.org4c9b8192012-12-13 22:46:431165 // dynamically for 80 ms depending on the sampling frequency
tina.legrand@webrtc.orgc0cf1db2012-11-05 09:35:511166 // of the codec.
pbos@webrtc.orgfbda0fc2013-04-09 00:28:061167 int16_t* in_audio_;
1168 uint32_t* in_timestamp_;
andrew@webrtc.orgb015cbe2012-10-22 18:19:231169
pbos@webrtc.orgfbda0fc2013-04-09 00:28:061170 int16_t frame_len_smpl_;
1171 uint16_t num_channels_;
andrew@webrtc.orgb015cbe2012-10-22 18:19:231172
tina.legrand@webrtc.orgc0cf1db2012-11-05 09:35:511173 // This will point to a static database of the supported codecs
pbos@webrtc.orgfbda0fc2013-04-09 00:28:061174 int16_t codec_id_;
andrew@webrtc.orgb015cbe2012-10-22 18:19:231175
turaj@webrtc.org4c9b8192012-12-13 22:46:431176 // 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.orgc0cf1db2012-11-05 09:35:511178 // at input buffer or due to encoding error
pbos@webrtc.orgfbda0fc2013-04-09 00:28:061179 uint32_t num_missed_samples_;
andrew@webrtc.orgb015cbe2012-10-22 18:19:231180
tina.legrand@webrtc.orgc0cf1db2012-11-05 09:35:511181 // True if the encoder instance created
turaj@webrtc.org4c9b8192012-12-13 22:46:431182 bool encoder_exist_;
1183 bool decoder_exist_;
1184 // True if the encoder instance initialized
1185 bool encoder_initialized_;
1186 bool decoder_initialized_;
andrew@webrtc.orgb015cbe2012-10-22 18:19:231187
turaj@webrtc.org4c9b8192012-12-13 22:46:431188 bool registered_in_neteq_;
andrew@webrtc.orgb015cbe2012-10-22 18:19:231189
tina.legrand@webrtc.orgc0cf1db2012-11-05 09:35:511190 // VAD/DTX
turaj@webrtc.org4c9b8192012-12-13 22:46:431191 bool has_internal_dtx_;
1192 WebRtcVadInst* ptr_vad_inst_;
1193 bool vad_enabled_;
1194 ACMVADMode vad_mode_;
pbos@webrtc.orgfbda0fc2013-04-09 00:28:061195 int16_t vad_label_[MAX_FRAME_SIZE_10MSEC];
turaj@webrtc.org4c9b8192012-12-13 22:46:431196 bool dtx_enabled_;
1197 WebRtcCngEncInst* ptr_dtx_inst_;
pbos@webrtc.orgfbda0fc2013-04-09 00:28:061198 uint8_t num_lpc_params_;
turaj@webrtc.org4c9b8192012-12-13 22:46:431199 bool sent_cn_previous_;
1200 bool is_master_;
1201 int16_t prev_frame_cng_;
andrew@webrtc.orgb015cbe2012-10-22 18:19:231202
turaj@webrtc.org4c9b8192012-12-13 22:46:431203 WebRtcACMCodecParams encoder_params_;
1204 WebRtcACMCodecParams decoder_params_;
andrew@webrtc.orgb015cbe2012-10-22 18:19:231205
turaj@webrtc.org4c9b8192012-12-13 22:46:431206 // Used as a global lock for all available decoders
tina.legrand@webrtc.orgc0cf1db2012-11-05 09:35:511207 // so that no decoder is used when NetEQ decodes.
turaj@webrtc.org4c9b8192012-12-13 22:46:431208 RWLockWrapper* neteq_decode_lock_;
tina.legrand@webrtc.orgc0cf1db2012-11-05 09:35:511209 // Used to lock wrapper internal data
1210 // such as buffers and state variables.
turaj@webrtc.org4c9b8192012-12-13 22:46:431211 RWLockWrapper& codec_wrapper_lock_;
andrew@webrtc.orgb015cbe2012-10-22 18:19:231212
pbos@webrtc.orgfbda0fc2013-04-09 00:28:061213 uint32_t last_encoded_timestamp_;
1214 uint32_t last_timestamp_;
turaj@webrtc.org4c9b8192012-12-13 22:46:431215 bool is_audio_buff_fresh_;
pbos@webrtc.orgfbda0fc2013-04-09 00:28:061216 uint32_t unique_id_;
andrew@webrtc.orgb015cbe2012-10-22 18:19:231217};
1218
turaj@webrtc.orged0b4fb2013-09-13 23:06:591219} // namespace acm1
1220
1221} // namespace webrtc
andrew@webrtc.orgb015cbe2012-10-22 18:19:231222
1223#endif // WEBRTC_MODULES_AUDIO_CODING_MAIN_SOURCE_ACM_GENERIC_CODEC_H_