13f39c00d9875d7e09062725757b789f4da375ef9turaj@webrtc.org/*
23f39c00d9875d7e09062725757b789f4da375ef9turaj@webrtc.org *  Copyright (c) 2012 The WebRTC project authors. All Rights Reserved.
33f39c00d9875d7e09062725757b789f4da375ef9turaj@webrtc.org *
43f39c00d9875d7e09062725757b789f4da375ef9turaj@webrtc.org *  Use of this source code is governed by a BSD-style license
53f39c00d9875d7e09062725757b789f4da375ef9turaj@webrtc.org *  that can be found in the LICENSE file in the root of the source
63f39c00d9875d7e09062725757b789f4da375ef9turaj@webrtc.org *  tree. An additional intellectual property rights grant can be found
73f39c00d9875d7e09062725757b789f4da375ef9turaj@webrtc.org *  in the file PATENTS.  All contributing project authors may
83f39c00d9875d7e09062725757b789f4da375ef9turaj@webrtc.org *  be found in the AUTHORS file in the root of the source tree.
93f39c00d9875d7e09062725757b789f4da375ef9turaj@webrtc.org */
103f39c00d9875d7e09062725757b789f4da375ef9turaj@webrtc.org
11ed0b4fb2f28fa291e726fc1cf6852611f2176392turaj@webrtc.org#ifndef WEBRTC_MODULES_AUDIO_CODING_MAIN_ACM2_ACM_GENERIC_CODEC_H_
12ed0b4fb2f28fa291e726fc1cf6852611f2176392turaj@webrtc.org#define WEBRTC_MODULES_AUDIO_CODING_MAIN_ACM2_ACM_GENERIC_CODEC_H_
133f39c00d9875d7e09062725757b789f4da375ef9turaj@webrtc.org
14d54aa969545bd9c5ccc0077dd6645e742bf11418pbos@webrtc.org#include "webrtc/base/thread_annotations.h"
153f39c00d9875d7e09062725757b789f4da375ef9turaj@webrtc.org#include "webrtc/modules/audio_coding/main/interface/audio_coding_module_typedefs.h"
16ed0b4fb2f28fa291e726fc1cf6852611f2176392turaj@webrtc.org#include "webrtc/modules/audio_coding/main/acm2/acm_common_defs.h"
17e5abc854f3dc47de16067c2a41476c39b7626722henrik.lundin@webrtc.org#include "webrtc/modules/audio_coding/neteq/interface/neteq.h"
18e5abc854f3dc47de16067c2a41476c39b7626722henrik.lundin@webrtc.org#include "webrtc/modules/audio_coding/neteq/interface/audio_decoder.h"
193f39c00d9875d7e09062725757b789f4da375ef9turaj@webrtc.org#include "webrtc/system_wrappers/interface/rw_lock_wrapper.h"
203f39c00d9875d7e09062725757b789f4da375ef9turaj@webrtc.org#include "webrtc/system_wrappers/interface/trace.h"
213f39c00d9875d7e09062725757b789f4da375ef9turaj@webrtc.org
223f39c00d9875d7e09062725757b789f4da375ef9turaj@webrtc.org#define MAX_FRAME_SIZE_10MSEC 6
233f39c00d9875d7e09062725757b789f4da375ef9turaj@webrtc.org
243f39c00d9875d7e09062725757b789f4da375ef9turaj@webrtc.org// forward declaration
253f39c00d9875d7e09062725757b789f4da375ef9turaj@webrtc.orgstruct WebRtcVadInst;
263f39c00d9875d7e09062725757b789f4da375ef9turaj@webrtc.orgstruct WebRtcCngEncInst;
273f39c00d9875d7e09062725757b789f4da375ef9turaj@webrtc.org
283f39c00d9875d7e09062725757b789f4da375ef9turaj@webrtc.orgnamespace webrtc {
293f39c00d9875d7e09062725757b789f4da375ef9turaj@webrtc.org
300a1c75a50d10621f70d5921c5b8b9c0eb144bb42turaj@webrtc.orgstruct WebRtcACMCodecParams;
313f39c00d9875d7e09062725757b789f4da375ef9turaj@webrtc.orgstruct CodecInst;
320a1c75a50d10621f70d5921c5b8b9c0eb144bb42turaj@webrtc.org
330a1c75a50d10621f70d5921c5b8b9c0eb144bb42turaj@webrtc.orgnamespace acm2 {
340a1c75a50d10621f70d5921c5b8b9c0eb144bb42turaj@webrtc.org
350a1c75a50d10621f70d5921c5b8b9c0eb144bb42turaj@webrtc.org// forward declaration
363f39c00d9875d7e09062725757b789f4da375ef9turaj@webrtc.orgclass AcmReceiver;
373f39c00d9875d7e09062725757b789f4da375ef9turaj@webrtc.org
383f39c00d9875d7e09062725757b789f4da375ef9turaj@webrtc.orgclass ACMGenericCodec {
393f39c00d9875d7e09062725757b789f4da375ef9turaj@webrtc.org public:
403f39c00d9875d7e09062725757b789f4da375ef9turaj@webrtc.org  ///////////////////////////////////////////////////////////////////////////
413f39c00d9875d7e09062725757b789f4da375ef9turaj@webrtc.org  // Constructor of the class
423f39c00d9875d7e09062725757b789f4da375ef9turaj@webrtc.org  //
433f39c00d9875d7e09062725757b789f4da375ef9turaj@webrtc.org  ACMGenericCodec();
443f39c00d9875d7e09062725757b789f4da375ef9turaj@webrtc.org
453f39c00d9875d7e09062725757b789f4da375ef9turaj@webrtc.org  ///////////////////////////////////////////////////////////////////////////
463f39c00d9875d7e09062725757b789f4da375ef9turaj@webrtc.org  // Destructor of the class.
473f39c00d9875d7e09062725757b789f4da375ef9turaj@webrtc.org  //
483f39c00d9875d7e09062725757b789f4da375ef9turaj@webrtc.org  virtual ~ACMGenericCodec();
493f39c00d9875d7e09062725757b789f4da375ef9turaj@webrtc.org
503f39c00d9875d7e09062725757b789f4da375ef9turaj@webrtc.org  ///////////////////////////////////////////////////////////////////////////
513f39c00d9875d7e09062725757b789f4da375ef9turaj@webrtc.org  // ACMGenericCodec* CreateInstance();
523f39c00d9875d7e09062725757b789f4da375ef9turaj@webrtc.org  // The function will be used for FEC. It is not implemented yet.
533f39c00d9875d7e09062725757b789f4da375ef9turaj@webrtc.org  //
543f39c00d9875d7e09062725757b789f4da375ef9turaj@webrtc.org  virtual ACMGenericCodec* CreateInstance() = 0;
553f39c00d9875d7e09062725757b789f4da375ef9turaj@webrtc.org
563f39c00d9875d7e09062725757b789f4da375ef9turaj@webrtc.org  ///////////////////////////////////////////////////////////////////////////
573f39c00d9875d7e09062725757b789f4da375ef9turaj@webrtc.org  // int16_t Encode()
583f39c00d9875d7e09062725757b789f4da375ef9turaj@webrtc.org  // The function is called to perform an encoding of the audio stored in
593f39c00d9875d7e09062725757b789f4da375ef9turaj@webrtc.org  // audio buffer. An encoding is performed only if enough audio, i.e. equal
603f39c00d9875d7e09062725757b789f4da375ef9turaj@webrtc.org  // to the frame-size of the codec, exist. The audio frame will be processed
613f39c00d9875d7e09062725757b789f4da375ef9turaj@webrtc.org  // by VAD and CN/DTX if required. There are few different cases.
623f39c00d9875d7e09062725757b789f4da375ef9turaj@webrtc.org  //
633f39c00d9875d7e09062725757b789f4da375ef9turaj@webrtc.org  // A) Neither VAD nor DTX is active; the frame is encoded by the encoder.
643f39c00d9875d7e09062725757b789f4da375ef9turaj@webrtc.org  //
653f39c00d9875d7e09062725757b789f4da375ef9turaj@webrtc.org  // B) VAD is enabled but not DTX; in this case the audio is processed by VAD
663f39c00d9875d7e09062725757b789f4da375ef9turaj@webrtc.org  //    and encoded by the encoder. The "*encoding_type" will be either
673f39c00d9875d7e09062725757b789f4da375ef9turaj@webrtc.org  //    "kActiveNormalEncode" or "kPassiveNormalEncode" if frame is active or
683f39c00d9875d7e09062725757b789f4da375ef9turaj@webrtc.org  //    passive, respectively.
693f39c00d9875d7e09062725757b789f4da375ef9turaj@webrtc.org  //
703f39c00d9875d7e09062725757b789f4da375ef9turaj@webrtc.org  // C) DTX is enabled; if the codec has internal VAD/DTX we just encode the
713f39c00d9875d7e09062725757b789f4da375ef9turaj@webrtc.org  //    frame by the encoder. Otherwise, the frame is passed through VAD and
723f39c00d9875d7e09062725757b789f4da375ef9turaj@webrtc.org  //    if identified as passive, then it will be processed by CN/DTX. If the
733f39c00d9875d7e09062725757b789f4da375ef9turaj@webrtc.org  //    frame is active it will be encoded by the encoder.
743f39c00d9875d7e09062725757b789f4da375ef9turaj@webrtc.org  //
753f39c00d9875d7e09062725757b789f4da375ef9turaj@webrtc.org  // This function acquires the appropriate locks and calls EncodeSafe() for
763f39c00d9875d7e09062725757b789f4da375ef9turaj@webrtc.org  // the actual processing.
773f39c00d9875d7e09062725757b789f4da375ef9turaj@webrtc.org  //
783f39c00d9875d7e09062725757b789f4da375ef9turaj@webrtc.org  // Outputs:
793f39c00d9875d7e09062725757b789f4da375ef9turaj@webrtc.org  //   -bitstream          : a buffer where bit-stream will be written to.
803f39c00d9875d7e09062725757b789f4da375ef9turaj@webrtc.org  //   -bitstream_len_byte : contains the length of the bit-stream in
813f39c00d9875d7e09062725757b789f4da375ef9turaj@webrtc.org  //                         bytes.
823f39c00d9875d7e09062725757b789f4da375ef9turaj@webrtc.org  //   -timestamp          : contains the RTP timestamp, this is the
833f39c00d9875d7e09062725757b789f4da375ef9turaj@webrtc.org  //                         sampling time of the first sample encoded
843f39c00d9875d7e09062725757b789f4da375ef9turaj@webrtc.org  //                         (measured in number of samples).
853f39c00d9875d7e09062725757b789f4da375ef9turaj@webrtc.org  //   -encoding_type       : contains the type of encoding applied on the
863f39c00d9875d7e09062725757b789f4da375ef9turaj@webrtc.org  //                         audio samples. The alternatives are
873f39c00d9875d7e09062725757b789f4da375ef9turaj@webrtc.org  //                         (c.f. acm_common_types.h)
883f39c00d9875d7e09062725757b789f4da375ef9turaj@webrtc.org  //                         -kNoEncoding:
893f39c00d9875d7e09062725757b789f4da375ef9turaj@webrtc.org  //                            there was not enough data to encode. or
903f39c00d9875d7e09062725757b789f4da375ef9turaj@webrtc.org  //                            some error has happened that we could
913f39c00d9875d7e09062725757b789f4da375ef9turaj@webrtc.org  //                            not do encoding.
923f39c00d9875d7e09062725757b789f4da375ef9turaj@webrtc.org  //                         -kActiveNormalEncoded:
933f39c00d9875d7e09062725757b789f4da375ef9turaj@webrtc.org  //                            the audio frame is active and encoded by
943f39c00d9875d7e09062725757b789f4da375ef9turaj@webrtc.org  //                            the given codec.
953f39c00d9875d7e09062725757b789f4da375ef9turaj@webrtc.org  //                         -kPassiveNormalEncoded:
963f39c00d9875d7e09062725757b789f4da375ef9turaj@webrtc.org  //                            the audio frame is passive but coded with
973f39c00d9875d7e09062725757b789f4da375ef9turaj@webrtc.org  //                            the given codec (NO DTX).
983f39c00d9875d7e09062725757b789f4da375ef9turaj@webrtc.org  //                         -kPassiveDTXWB:
993f39c00d9875d7e09062725757b789f4da375ef9turaj@webrtc.org  //                            The audio frame is passive and used
1003f39c00d9875d7e09062725757b789f4da375ef9turaj@webrtc.org  //                            wide-band CN to encode.
1013f39c00d9875d7e09062725757b789f4da375ef9turaj@webrtc.org  //                         -kPassiveDTXNB:
1023f39c00d9875d7e09062725757b789f4da375ef9turaj@webrtc.org  //                            The audio frame is passive and used
1033f39c00d9875d7e09062725757b789f4da375ef9turaj@webrtc.org  //                            narrow-band CN to encode.
1043f39c00d9875d7e09062725757b789f4da375ef9turaj@webrtc.org  //
1053f39c00d9875d7e09062725757b789f4da375ef9turaj@webrtc.org  // Return value:
1063f39c00d9875d7e09062725757b789f4da375ef9turaj@webrtc.org  //   -1 if error is occurred, otherwise the length of the bit-stream in
1073f39c00d9875d7e09062725757b789f4da375ef9turaj@webrtc.org  //      bytes.
1083f39c00d9875d7e09062725757b789f4da375ef9turaj@webrtc.org  //
1093f39c00d9875d7e09062725757b789f4da375ef9turaj@webrtc.org  int16_t Encode(uint8_t* bitstream,
1103f39c00d9875d7e09062725757b789f4da375ef9turaj@webrtc.org                 int16_t* bitstream_len_byte,
1113f39c00d9875d7e09062725757b789f4da375ef9turaj@webrtc.org                 uint32_t* timestamp,
1123f39c00d9875d7e09062725757b789f4da375ef9turaj@webrtc.org                 WebRtcACMEncodingType* encoding_type);
1133f39c00d9875d7e09062725757b789f4da375ef9turaj@webrtc.org
1143f39c00d9875d7e09062725757b789f4da375ef9turaj@webrtc.org  ///////////////////////////////////////////////////////////////////////////
1153f39c00d9875d7e09062725757b789f4da375ef9turaj@webrtc.org  // bool EncoderInitialized();
1163f39c00d9875d7e09062725757b789f4da375ef9turaj@webrtc.org  //
1173f39c00d9875d7e09062725757b789f4da375ef9turaj@webrtc.org  // Return value:
1183f39c00d9875d7e09062725757b789f4da375ef9turaj@webrtc.org  //   True if the encoder is successfully initialized,
1193f39c00d9875d7e09062725757b789f4da375ef9turaj@webrtc.org  //   false otherwise.
1203f39c00d9875d7e09062725757b789f4da375ef9turaj@webrtc.org  //
1213f39c00d9875d7e09062725757b789f4da375ef9turaj@webrtc.org  bool EncoderInitialized();
1223f39c00d9875d7e09062725757b789f4da375ef9turaj@webrtc.org
1233f39c00d9875d7e09062725757b789f4da375ef9turaj@webrtc.org  ///////////////////////////////////////////////////////////////////////////
1243f39c00d9875d7e09062725757b789f4da375ef9turaj@webrtc.org  // int16_t EncoderParams()
1253f39c00d9875d7e09062725757b789f4da375ef9turaj@webrtc.org  // It is called to get encoder parameters. It will call
1263f39c00d9875d7e09062725757b789f4da375ef9turaj@webrtc.org  // EncoderParamsSafe() in turn.
1273f39c00d9875d7e09062725757b789f4da375ef9turaj@webrtc.org  //
1283f39c00d9875d7e09062725757b789f4da375ef9turaj@webrtc.org  // Output:
1293f39c00d9875d7e09062725757b789f4da375ef9turaj@webrtc.org  //   -enc_params         : a buffer where the encoder parameters is
1303f39c00d9875d7e09062725757b789f4da375ef9turaj@webrtc.org  //                         written to. If the encoder is not
1313f39c00d9875d7e09062725757b789f4da375ef9turaj@webrtc.org  //                         initialized this buffer is filled with
1323f39c00d9875d7e09062725757b789f4da375ef9turaj@webrtc.org  //                         invalid values
1333f39c00d9875d7e09062725757b789f4da375ef9turaj@webrtc.org  // Return value:
1343f39c00d9875d7e09062725757b789f4da375ef9turaj@webrtc.org  //   -1 if the encoder is not initialized,
1353f39c00d9875d7e09062725757b789f4da375ef9turaj@webrtc.org  //    0 otherwise.
1363f39c00d9875d7e09062725757b789f4da375ef9turaj@webrtc.org  //
1373f39c00d9875d7e09062725757b789f4da375ef9turaj@webrtc.org  int16_t EncoderParams(WebRtcACMCodecParams* enc_params);
1383f39c00d9875d7e09062725757b789f4da375ef9turaj@webrtc.org
1393f39c00d9875d7e09062725757b789f4da375ef9turaj@webrtc.org  ///////////////////////////////////////////////////////////////////////////
1403f39c00d9875d7e09062725757b789f4da375ef9turaj@webrtc.org  // int16_t InitEncoder(...)
1413f39c00d9875d7e09062725757b789f4da375ef9turaj@webrtc.org  // This function is called to initialize the encoder with the given
1423f39c00d9875d7e09062725757b789f4da375ef9turaj@webrtc.org  // parameters.
1433f39c00d9875d7e09062725757b789f4da375ef9turaj@webrtc.org  //
1443f39c00d9875d7e09062725757b789f4da375ef9turaj@webrtc.org  // Input:
1453f39c00d9875d7e09062725757b789f4da375ef9turaj@webrtc.org  //   -codec_params        : parameters of encoder.
1463f39c00d9875d7e09062725757b789f4da375ef9turaj@webrtc.org  //   -force_initialization: if false the initialization is invoked only if
1473f39c00d9875d7e09062725757b789f4da375ef9turaj@webrtc.org  //                          the encoder is not initialized. If true the
1483f39c00d9875d7e09062725757b789f4da375ef9turaj@webrtc.org  //                          encoder is forced to (re)initialize.
1493f39c00d9875d7e09062725757b789f4da375ef9turaj@webrtc.org  //
1503f39c00d9875d7e09062725757b789f4da375ef9turaj@webrtc.org  // Return value:
1513f39c00d9875d7e09062725757b789f4da375ef9turaj@webrtc.org  //   0 if could initialize successfully,
1523f39c00d9875d7e09062725757b789f4da375ef9turaj@webrtc.org  //  -1 if failed to initialize.
1533f39c00d9875d7e09062725757b789f4da375ef9turaj@webrtc.org  //
1543f39c00d9875d7e09062725757b789f4da375ef9turaj@webrtc.org  //
1553f39c00d9875d7e09062725757b789f4da375ef9turaj@webrtc.org  int16_t InitEncoder(WebRtcACMCodecParams* codec_params,
1563f39c00d9875d7e09062725757b789f4da375ef9turaj@webrtc.org                      bool force_initialization);
1573f39c00d9875d7e09062725757b789f4da375ef9turaj@webrtc.org
1583f39c00d9875d7e09062725757b789f4da375ef9turaj@webrtc.org  ///////////////////////////////////////////////////////////////////////////
1593f39c00d9875d7e09062725757b789f4da375ef9turaj@webrtc.org  // int32_t Add10MsData(...)
1603f39c00d9875d7e09062725757b789f4da375ef9turaj@webrtc.org  // This function is called to add 10 ms of audio to the audio buffer of
1613f39c00d9875d7e09062725757b789f4da375ef9turaj@webrtc.org  // the codec.
1623f39c00d9875d7e09062725757b789f4da375ef9turaj@webrtc.org  //
1633f39c00d9875d7e09062725757b789f4da375ef9turaj@webrtc.org  // Inputs:
1643f39c00d9875d7e09062725757b789f4da375ef9turaj@webrtc.org  //   -timestamp          : the timestamp of the 10 ms audio. the timestamp
1653f39c00d9875d7e09062725757b789f4da375ef9turaj@webrtc.org  //                         is the sampling time of the
1663f39c00d9875d7e09062725757b789f4da375ef9turaj@webrtc.org  //                         first sample measured in number of samples.
1673f39c00d9875d7e09062725757b789f4da375ef9turaj@webrtc.org  //   -data               : a buffer that contains the audio. The codec
1683f39c00d9875d7e09062725757b789f4da375ef9turaj@webrtc.org  //                         expects to get the audio in correct sampling
1693f39c00d9875d7e09062725757b789f4da375ef9turaj@webrtc.org  //                         frequency
1703f39c00d9875d7e09062725757b789f4da375ef9turaj@webrtc.org  //   -length             : the length of the audio buffer
1713f39c00d9875d7e09062725757b789f4da375ef9turaj@webrtc.org  //   -audio_channel      : 0 for mono, 1 for stereo (not supported yet)
1723f39c00d9875d7e09062725757b789f4da375ef9turaj@webrtc.org  //
1733f39c00d9875d7e09062725757b789f4da375ef9turaj@webrtc.org  // Return values:
1743f39c00d9875d7e09062725757b789f4da375ef9turaj@webrtc.org  //   -1 if failed
1753f39c00d9875d7e09062725757b789f4da375ef9turaj@webrtc.org  //    0 otherwise.
1763f39c00d9875d7e09062725757b789f4da375ef9turaj@webrtc.org  //
1773f39c00d9875d7e09062725757b789f4da375ef9turaj@webrtc.org  int32_t Add10MsData(const uint32_t timestamp,
1783f39c00d9875d7e09062725757b789f4da375ef9turaj@webrtc.org                      const int16_t* data,
1793f39c00d9875d7e09062725757b789f4da375ef9turaj@webrtc.org                      const uint16_t length,
1803f39c00d9875d7e09062725757b789f4da375ef9turaj@webrtc.org                      const uint8_t audio_channel);
1813f39c00d9875d7e09062725757b789f4da375ef9turaj@webrtc.org
1823f39c00d9875d7e09062725757b789f4da375ef9turaj@webrtc.org  ///////////////////////////////////////////////////////////////////////////
1833f39c00d9875d7e09062725757b789f4da375ef9turaj@webrtc.org  // uint32_t NoMissedSamples()
1843f39c00d9875d7e09062725757b789f4da375ef9turaj@webrtc.org  // This function returns the number of samples which are overwritten in
1853f39c00d9875d7e09062725757b789f4da375ef9turaj@webrtc.org  // the audio buffer. The audio samples are overwritten if the input audio
1863f39c00d9875d7e09062725757b789f4da375ef9turaj@webrtc.org  // buffer is full, but Add10MsData() is called. (We might remove this
1873f39c00d9875d7e09062725757b789f4da375ef9turaj@webrtc.org  // function if it is not used)
1883f39c00d9875d7e09062725757b789f4da375ef9turaj@webrtc.org  //
1893f39c00d9875d7e09062725757b789f4da375ef9turaj@webrtc.org  // Return Value:
1903f39c00d9875d7e09062725757b789f4da375ef9turaj@webrtc.org  //   Number of samples which are overwritten.
1913f39c00d9875d7e09062725757b789f4da375ef9turaj@webrtc.org  //
1923f39c00d9875d7e09062725757b789f4da375ef9turaj@webrtc.org  uint32_t NoMissedSamples() const;
1933f39c00d9875d7e09062725757b789f4da375ef9turaj@webrtc.org
1943f39c00d9875d7e09062725757b789f4da375ef9turaj@webrtc.org  ///////////////////////////////////////////////////////////////////////////
1953f39c00d9875d7e09062725757b789f4da375ef9turaj@webrtc.org  // void ResetNoMissedSamples()
1963f39c00d9875d7e09062725757b789f4da375ef9turaj@webrtc.org  // This function resets the number of overwritten samples to zero.
1973f39c00d9875d7e09062725757b789f4da375ef9turaj@webrtc.org  // (We might remove this function if we remove NoMissedSamples())
1983f39c00d9875d7e09062725757b789f4da375ef9turaj@webrtc.org  //
1993f39c00d9875d7e09062725757b789f4da375ef9turaj@webrtc.org  void ResetNoMissedSamples();
2003f39c00d9875d7e09062725757b789f4da375ef9turaj@webrtc.org
2013f39c00d9875d7e09062725757b789f4da375ef9turaj@webrtc.org  ///////////////////////////////////////////////////////////////////////////
2023f39c00d9875d7e09062725757b789f4da375ef9turaj@webrtc.org  // int16_t SetBitRate()
2033f39c00d9875d7e09062725757b789f4da375ef9turaj@webrtc.org  // The function is called to set the encoding rate.
2043f39c00d9875d7e09062725757b789f4da375ef9turaj@webrtc.org  //
2053f39c00d9875d7e09062725757b789f4da375ef9turaj@webrtc.org  // Input:
2063f39c00d9875d7e09062725757b789f4da375ef9turaj@webrtc.org  //   -bitrate_bps        : encoding rate in bits per second
2073f39c00d9875d7e09062725757b789f4da375ef9turaj@webrtc.org  //
2083f39c00d9875d7e09062725757b789f4da375ef9turaj@webrtc.org  // Return value:
2093f39c00d9875d7e09062725757b789f4da375ef9turaj@webrtc.org  //   -1 if failed to set the rate, due to invalid input or given
2103f39c00d9875d7e09062725757b789f4da375ef9turaj@webrtc.org  //      codec is not rate-adjustable.
2113f39c00d9875d7e09062725757b789f4da375ef9turaj@webrtc.org  //    0 if the rate is adjusted successfully
2123f39c00d9875d7e09062725757b789f4da375ef9turaj@webrtc.org  //
2133f39c00d9875d7e09062725757b789f4da375ef9turaj@webrtc.org  int16_t SetBitRate(const int32_t bitrate_bps);
2143f39c00d9875d7e09062725757b789f4da375ef9turaj@webrtc.org
2153f39c00d9875d7e09062725757b789f4da375ef9turaj@webrtc.org  ///////////////////////////////////////////////////////////////////////////
2163f39c00d9875d7e09062725757b789f4da375ef9turaj@webrtc.org  // uint32_t EarliestTimestamp()
2173f39c00d9875d7e09062725757b789f4da375ef9turaj@webrtc.org  // Returns the timestamp of the first 10 ms in audio buffer. This is used
2183f39c00d9875d7e09062725757b789f4da375ef9turaj@webrtc.org  // to identify if a synchronization of two encoders is required.
2193f39c00d9875d7e09062725757b789f4da375ef9turaj@webrtc.org  //
2203f39c00d9875d7e09062725757b789f4da375ef9turaj@webrtc.org  // Return value:
2213f39c00d9875d7e09062725757b789f4da375ef9turaj@webrtc.org  //   timestamp of the first 10 ms audio in the audio buffer.
2223f39c00d9875d7e09062725757b789f4da375ef9turaj@webrtc.org  //
2233f39c00d9875d7e09062725757b789f4da375ef9turaj@webrtc.org  uint32_t EarliestTimestamp() const;
2243f39c00d9875d7e09062725757b789f4da375ef9turaj@webrtc.org
2253f39c00d9875d7e09062725757b789f4da375ef9turaj@webrtc.org  ///////////////////////////////////////////////////////////////////////////
2263f39c00d9875d7e09062725757b789f4da375ef9turaj@webrtc.org  // int16_t SetVAD()
227717267a7047e1ab0d15ce0f3df2a543a7d9acc73turaj@webrtc.org  // This is called to set VAD & DTX. If the codec has internal DTX, it will
2283f39c00d9875d7e09062725757b789f4da375ef9turaj@webrtc.org  // be used. If DTX is enabled and the codec does not have internal DTX,
2293f39c00d9875d7e09062725757b789f4da375ef9turaj@webrtc.org  // WebRtc-VAD will be used to decide if the frame is active. If DTX is
230717267a7047e1ab0d15ce0f3df2a543a7d9acc73turaj@webrtc.org  // disabled but VAD is enabled, the audio is passed through VAD to label it
2313f39c00d9875d7e09062725757b789f4da375ef9turaj@webrtc.org  // as active or passive, but the frame is  encoded normally. However the
2323f39c00d9875d7e09062725757b789f4da375ef9turaj@webrtc.org  // bit-stream is labeled properly so that ACM::Process() can use this
2333f39c00d9875d7e09062725757b789f4da375ef9turaj@webrtc.org  // information. In case of failure, the previous states of the VAD & DTX
2343f39c00d9875d7e09062725757b789f4da375ef9turaj@webrtc.org  // are kept.
2353f39c00d9875d7e09062725757b789f4da375ef9turaj@webrtc.org  //
236717267a7047e1ab0d15ce0f3df2a543a7d9acc73turaj@webrtc.org  // Inputs/Output:
2373f39c00d9875d7e09062725757b789f4da375ef9turaj@webrtc.org  //   -enable_dtx         : if true DTX will be enabled otherwise the DTX is
2383f39c00d9875d7e09062725757b789f4da375ef9turaj@webrtc.org  //                         disabled. If codec has internal DTX that will be
2393f39c00d9875d7e09062725757b789f4da375ef9turaj@webrtc.org  //                         used, otherwise WebRtc-CNG is used. In the latter
2403f39c00d9875d7e09062725757b789f4da375ef9turaj@webrtc.org  //                         case VAD is automatically activated.
2413f39c00d9875d7e09062725757b789f4da375ef9turaj@webrtc.org  //   -enable_vad         : if true WebRtc-VAD is enabled, otherwise VAD is
2423f39c00d9875d7e09062725757b789f4da375ef9turaj@webrtc.org  //                         disabled, except for the case that DTX is enabled
2433f39c00d9875d7e09062725757b789f4da375ef9turaj@webrtc.org  //                         but codec doesn't have internal DTX. In this case
2443f39c00d9875d7e09062725757b789f4da375ef9turaj@webrtc.org  //                         VAD is enabled regardless of the value of
2453f39c00d9875d7e09062725757b789f4da375ef9turaj@webrtc.org  //                         |enable_vad|.
2463f39c00d9875d7e09062725757b789f4da375ef9turaj@webrtc.org  //   -mode               : this specifies the aggressiveness of VAD.
2473f39c00d9875d7e09062725757b789f4da375ef9turaj@webrtc.org  //
2483f39c00d9875d7e09062725757b789f4da375ef9turaj@webrtc.org  // Return value
2493f39c00d9875d7e09062725757b789f4da375ef9turaj@webrtc.org  //   -1 if failed to set DTX & VAD as specified,
2503f39c00d9875d7e09062725757b789f4da375ef9turaj@webrtc.org  //    0 if succeeded.
2513f39c00d9875d7e09062725757b789f4da375ef9turaj@webrtc.org  //
252717267a7047e1ab0d15ce0f3df2a543a7d9acc73turaj@webrtc.org  int16_t SetVAD(bool* enable_dtx, bool* enable_vad, ACMVADMode* mode);
2533f39c00d9875d7e09062725757b789f4da375ef9turaj@webrtc.org
2543f39c00d9875d7e09062725757b789f4da375ef9turaj@webrtc.org  ///////////////////////////////////////////////////////////////////////////
2553f39c00d9875d7e09062725757b789f4da375ef9turaj@webrtc.org  // int32_t ReplaceInternalDTX()
2563f39c00d9875d7e09062725757b789f4da375ef9turaj@webrtc.org  // This is called to replace the codec internal DTX with WebRtc DTX.
2573f39c00d9875d7e09062725757b789f4da375ef9turaj@webrtc.org  // This is only valid for G729 where the user has possibility to replace
2583f39c00d9875d7e09062725757b789f4da375ef9turaj@webrtc.org  // AnnexB with WebRtc DTX. For other codecs this function has no effect.
2593f39c00d9875d7e09062725757b789f4da375ef9turaj@webrtc.org  //
2603f39c00d9875d7e09062725757b789f4da375ef9turaj@webrtc.org  // Input:
2613f39c00d9875d7e09062725757b789f4da375ef9turaj@webrtc.org  //   -replace_internal_dtx : if true the internal DTX is replaced with WebRtc.
2623f39c00d9875d7e09062725757b789f4da375ef9turaj@webrtc.org  //
2633f39c00d9875d7e09062725757b789f4da375ef9turaj@webrtc.org  // Return value
2643f39c00d9875d7e09062725757b789f4da375ef9turaj@webrtc.org  //   -1 if failed to replace internal DTX,
2653f39c00d9875d7e09062725757b789f4da375ef9turaj@webrtc.org  //    0 if succeeded.
2663f39c00d9875d7e09062725757b789f4da375ef9turaj@webrtc.org  //
2673f39c00d9875d7e09062725757b789f4da375ef9turaj@webrtc.org  int32_t ReplaceInternalDTX(const bool replace_internal_dtx);
2683f39c00d9875d7e09062725757b789f4da375ef9turaj@webrtc.org
2693f39c00d9875d7e09062725757b789f4da375ef9turaj@webrtc.org  ///////////////////////////////////////////////////////////////////////////
2703f39c00d9875d7e09062725757b789f4da375ef9turaj@webrtc.org  // int32_t IsInternalDTXReplaced()
2713f39c00d9875d7e09062725757b789f4da375ef9turaj@webrtc.org  // This is called to check if the codec internal DTX is replaced by WebRtc
2723f39c00d9875d7e09062725757b789f4da375ef9turaj@webrtc.org  // DTX. This is only valid for G729 where the user has possibility to replace
2733f39c00d9875d7e09062725757b789f4da375ef9turaj@webrtc.org  // AnnexB with WebRtc DTX. For other codecs this function has no effect.
2743f39c00d9875d7e09062725757b789f4da375ef9turaj@webrtc.org  //
2753f39c00d9875d7e09062725757b789f4da375ef9turaj@webrtc.org  // Output:
2763f39c00d9875d7e09062725757b789f4da375ef9turaj@webrtc.org  //   -internal_dtx_replaced: if true the internal DTX is replaced with WebRtc.
2773f39c00d9875d7e09062725757b789f4da375ef9turaj@webrtc.org  //
2783f39c00d9875d7e09062725757b789f4da375ef9turaj@webrtc.org  // Return value
2793f39c00d9875d7e09062725757b789f4da375ef9turaj@webrtc.org  //   -1 if failed to check
2803f39c00d9875d7e09062725757b789f4da375ef9turaj@webrtc.org  //    0 if succeeded.
2813f39c00d9875d7e09062725757b789f4da375ef9turaj@webrtc.org  //
2823f39c00d9875d7e09062725757b789f4da375ef9turaj@webrtc.org  int32_t IsInternalDTXReplaced(bool* internal_dtx_replaced);
2833f39c00d9875d7e09062725757b789f4da375ef9turaj@webrtc.org
2843f39c00d9875d7e09062725757b789f4da375ef9turaj@webrtc.org  ///////////////////////////////////////////////////////////////////////////
2853f39c00d9875d7e09062725757b789f4da375ef9turaj@webrtc.org  // bool HasInternalDTX()
2863f39c00d9875d7e09062725757b789f4da375ef9turaj@webrtc.org  // Used to check if the codec has internal DTX.
2873f39c00d9875d7e09062725757b789f4da375ef9turaj@webrtc.org  //
2883f39c00d9875d7e09062725757b789f4da375ef9turaj@webrtc.org  // Return value:
2893f39c00d9875d7e09062725757b789f4da375ef9turaj@webrtc.org  //   true if the codec has an internal DTX, e.g. G729,
2903f39c00d9875d7e09062725757b789f4da375ef9turaj@webrtc.org  //   false otherwise.
2913f39c00d9875d7e09062725757b789f4da375ef9turaj@webrtc.org  //
29247b4b9d94cafb22e19bc8a6e6ca83b0568dcb973henrik.lundin@webrtc.org  bool HasInternalDTX() const {
29347b4b9d94cafb22e19bc8a6e6ca83b0568dcb973henrik.lundin@webrtc.org    ReadLockScoped rl(codec_wrapper_lock_);
29447b4b9d94cafb22e19bc8a6e6ca83b0568dcb973henrik.lundin@webrtc.org    return has_internal_dtx_;
29547b4b9d94cafb22e19bc8a6e6ca83b0568dcb973henrik.lundin@webrtc.org  }
2963f39c00d9875d7e09062725757b789f4da375ef9turaj@webrtc.org
2973f39c00d9875d7e09062725757b789f4da375ef9turaj@webrtc.org  ///////////////////////////////////////////////////////////////////////////
2983f39c00d9875d7e09062725757b789f4da375ef9turaj@webrtc.org  // int32_t GetEstimatedBandwidth()
2993f39c00d9875d7e09062725757b789f4da375ef9turaj@webrtc.org  // Used to get decoder estimated bandwidth. Only iSAC will provide a value.
3003f39c00d9875d7e09062725757b789f4da375ef9turaj@webrtc.org  //
3013f39c00d9875d7e09062725757b789f4da375ef9turaj@webrtc.org  //
3023f39c00d9875d7e09062725757b789f4da375ef9turaj@webrtc.org  // Return value:
3033f39c00d9875d7e09062725757b789f4da375ef9turaj@webrtc.org  //   -1 if fails to get decoder estimated bandwidth,
3043f39c00d9875d7e09062725757b789f4da375ef9turaj@webrtc.org  //    >0 estimated bandwidth in bits/sec.
3053f39c00d9875d7e09062725757b789f4da375ef9turaj@webrtc.org  //
3063f39c00d9875d7e09062725757b789f4da375ef9turaj@webrtc.org  int32_t GetEstimatedBandwidth();
3073f39c00d9875d7e09062725757b789f4da375ef9turaj@webrtc.org
3083f39c00d9875d7e09062725757b789f4da375ef9turaj@webrtc.org  ///////////////////////////////////////////////////////////////////////////
3093f39c00d9875d7e09062725757b789f4da375ef9turaj@webrtc.org  // int32_t SetEstimatedBandwidth()
3103f39c00d9875d7e09062725757b789f4da375ef9turaj@webrtc.org  // Used to set estiamted bandwidth sent out of band from other side. Only
3113f39c00d9875d7e09062725757b789f4da375ef9turaj@webrtc.org  // iSAC will have use for the value.
3123f39c00d9875d7e09062725757b789f4da375ef9turaj@webrtc.org  //
3133f39c00d9875d7e09062725757b789f4da375ef9turaj@webrtc.org  // Input:
3143f39c00d9875d7e09062725757b789f4da375ef9turaj@webrtc.org  //       -estimated_bandwidth:    estimated bandwidth in bits/sec
3153f39c00d9875d7e09062725757b789f4da375ef9turaj@webrtc.org  //
3163f39c00d9875d7e09062725757b789f4da375ef9turaj@webrtc.org  // Return value:
3173f39c00d9875d7e09062725757b789f4da375ef9turaj@webrtc.org  //   -1 if fails to set estimated bandwidth,
3183f39c00d9875d7e09062725757b789f4da375ef9turaj@webrtc.org  //    0 on success.
3193f39c00d9875d7e09062725757b789f4da375ef9turaj@webrtc.org  //
3203f39c00d9875d7e09062725757b789f4da375ef9turaj@webrtc.org  int32_t SetEstimatedBandwidth(int32_t estimated_bandwidth);
3213f39c00d9875d7e09062725757b789f4da375ef9turaj@webrtc.org
3223f39c00d9875d7e09062725757b789f4da375ef9turaj@webrtc.org  ///////////////////////////////////////////////////////////////////////////
3233f39c00d9875d7e09062725757b789f4da375ef9turaj@webrtc.org  // int32_t GetRedPayload()
3243f39c00d9875d7e09062725757b789f4da375ef9turaj@webrtc.org  // Used to get codec specific RED payload (if such is implemented).
3253f39c00d9875d7e09062725757b789f4da375ef9turaj@webrtc.org  // Currently only done in iSAC.
3263f39c00d9875d7e09062725757b789f4da375ef9turaj@webrtc.org  //
3273f39c00d9875d7e09062725757b789f4da375ef9turaj@webrtc.org  // Outputs:
3283f39c00d9875d7e09062725757b789f4da375ef9turaj@webrtc.org  //   -red_payload       : a pointer to the data for RED payload.
3293f39c00d9875d7e09062725757b789f4da375ef9turaj@webrtc.org  //   -payload_bytes     : number of bytes in RED payload.
3303f39c00d9875d7e09062725757b789f4da375ef9turaj@webrtc.org  //
3313f39c00d9875d7e09062725757b789f4da375ef9turaj@webrtc.org  // Return value:
3323f39c00d9875d7e09062725757b789f4da375ef9turaj@webrtc.org  //   -1 if fails to get codec specific RED,
3333f39c00d9875d7e09062725757b789f4da375ef9turaj@webrtc.org  //    0 if succeeded.
3343f39c00d9875d7e09062725757b789f4da375ef9turaj@webrtc.org  //
3353f39c00d9875d7e09062725757b789f4da375ef9turaj@webrtc.org  int32_t GetRedPayload(uint8_t* red_payload, int16_t* payload_bytes);
3363f39c00d9875d7e09062725757b789f4da375ef9turaj@webrtc.org
3373f39c00d9875d7e09062725757b789f4da375ef9turaj@webrtc.org  ///////////////////////////////////////////////////////////////////////////
3383f39c00d9875d7e09062725757b789f4da375ef9turaj@webrtc.org  // int16_t ResetEncoder()
3393f39c00d9875d7e09062725757b789f4da375ef9turaj@webrtc.org  // By calling this function you would re-initialize the encoder with the
3403f39c00d9875d7e09062725757b789f4da375ef9turaj@webrtc.org  // current parameters. All the settings, e.g. VAD/DTX, frame-size... should
3413f39c00d9875d7e09062725757b789f4da375ef9turaj@webrtc.org  // remain unchanged. (In case of iSAC we don't want to lose BWE history.)
3423f39c00d9875d7e09062725757b789f4da375ef9turaj@webrtc.org  //
3433f39c00d9875d7e09062725757b789f4da375ef9turaj@webrtc.org  // Return value
3443f39c00d9875d7e09062725757b789f4da375ef9turaj@webrtc.org  //   -1 if failed,
3453f39c00d9875d7e09062725757b789f4da375ef9turaj@webrtc.org  //    0 if succeeded.
3463f39c00d9875d7e09062725757b789f4da375ef9turaj@webrtc.org  //
3473f39c00d9875d7e09062725757b789f4da375ef9turaj@webrtc.org  int16_t ResetEncoder();
3483f39c00d9875d7e09062725757b789f4da375ef9turaj@webrtc.org
3493f39c00d9875d7e09062725757b789f4da375ef9turaj@webrtc.org  ///////////////////////////////////////////////////////////////////////////
3503f39c00d9875d7e09062725757b789f4da375ef9turaj@webrtc.org  // void DestructEncoder()
3513f39c00d9875d7e09062725757b789f4da375ef9turaj@webrtc.org  // This function is called to delete the encoder instance, if possible, to
3523f39c00d9875d7e09062725757b789f4da375ef9turaj@webrtc.org  // have a fresh start. For codecs where encoder and decoder share the same
3533f39c00d9875d7e09062725757b789f4da375ef9turaj@webrtc.org  // instance we cannot delete the encoder and instead we will initialize the
3543f39c00d9875d7e09062725757b789f4da375ef9turaj@webrtc.org  // encoder. We also delete VAD and DTX if they have been created.
3553f39c00d9875d7e09062725757b789f4da375ef9turaj@webrtc.org  //
3563f39c00d9875d7e09062725757b789f4da375ef9turaj@webrtc.org  void DestructEncoder();
3573f39c00d9875d7e09062725757b789f4da375ef9turaj@webrtc.org
3583f39c00d9875d7e09062725757b789f4da375ef9turaj@webrtc.org  ///////////////////////////////////////////////////////////////////////////
3593f39c00d9875d7e09062725757b789f4da375ef9turaj@webrtc.org  // int16_t SamplesLeftToEncode()
3603f39c00d9875d7e09062725757b789f4da375ef9turaj@webrtc.org  // Returns the number of samples required to be able to do encoding.
3613f39c00d9875d7e09062725757b789f4da375ef9turaj@webrtc.org  //
3623f39c00d9875d7e09062725757b789f4da375ef9turaj@webrtc.org  // Return value:
3633f39c00d9875d7e09062725757b789f4da375ef9turaj@webrtc.org  //   Number of samples.
3643f39c00d9875d7e09062725757b789f4da375ef9turaj@webrtc.org  //
3653f39c00d9875d7e09062725757b789f4da375ef9turaj@webrtc.org  int16_t SamplesLeftToEncode();
3663f39c00d9875d7e09062725757b789f4da375ef9turaj@webrtc.org
3673f39c00d9875d7e09062725757b789f4da375ef9turaj@webrtc.org  ///////////////////////////////////////////////////////////////////////////
3683f39c00d9875d7e09062725757b789f4da375ef9turaj@webrtc.org  // SetUniqueID()
3693f39c00d9875d7e09062725757b789f4da375ef9turaj@webrtc.org  // Set a unique ID for the codec to be used for tracing and debugging
3703f39c00d9875d7e09062725757b789f4da375ef9turaj@webrtc.org  //
3713f39c00d9875d7e09062725757b789f4da375ef9turaj@webrtc.org  // Input
3723f39c00d9875d7e09062725757b789f4da375ef9turaj@webrtc.org  //   -id                 : A number to identify the codec.
3733f39c00d9875d7e09062725757b789f4da375ef9turaj@webrtc.org  //
3743f39c00d9875d7e09062725757b789f4da375ef9turaj@webrtc.org  void SetUniqueID(const uint32_t id);
3753f39c00d9875d7e09062725757b789f4da375ef9turaj@webrtc.org
3763f39c00d9875d7e09062725757b789f4da375ef9turaj@webrtc.org  ///////////////////////////////////////////////////////////////////////////
3773f39c00d9875d7e09062725757b789f4da375ef9turaj@webrtc.org  // UpdateDecoderSampFreq()
3783f39c00d9875d7e09062725757b789f4da375ef9turaj@webrtc.org  // For most of the codecs this function does nothing. It must be
3793f39c00d9875d7e09062725757b789f4da375ef9turaj@webrtc.org  // implemented for those codecs that one codec instance serves as the
3803f39c00d9875d7e09062725757b789f4da375ef9turaj@webrtc.org  // decoder for different flavors of the codec. One example is iSAC. there,
3813f39c00d9875d7e09062725757b789f4da375ef9turaj@webrtc.org  // iSAC 16 kHz and iSAC 32 kHz are treated as two different codecs with
3823f39c00d9875d7e09062725757b789f4da375ef9turaj@webrtc.org  // different payload types, however, there is only one iSAC instance to
3833f39c00d9875d7e09062725757b789f4da375ef9turaj@webrtc.org  // decode. The reason for that is we would like to decode and encode with
3843f39c00d9875d7e09062725757b789f4da375ef9turaj@webrtc.org  // the same codec instance for bandwidth estimator to work.
3853f39c00d9875d7e09062725757b789f4da375ef9turaj@webrtc.org  //
3863f39c00d9875d7e09062725757b789f4da375ef9turaj@webrtc.org  // Each time that we receive a new payload type, we call this function to
3873f39c00d9875d7e09062725757b789f4da375ef9turaj@webrtc.org  // prepare the decoder associated with the new payload. Normally, decoders
3883f39c00d9875d7e09062725757b789f4da375ef9turaj@webrtc.org  // doesn't have to do anything. For iSAC the decoder has to change it's
3893f39c00d9875d7e09062725757b789f4da375ef9turaj@webrtc.org  // sampling rate. The input parameter specifies the current flavor of the
3903f39c00d9875d7e09062725757b789f4da375ef9turaj@webrtc.org  // codec in codec database. For instance, if we just got a SWB payload then
3913f39c00d9875d7e09062725757b789f4da375ef9turaj@webrtc.org  // the input parameter is ACMCodecDB::isacswb.
3923f39c00d9875d7e09062725757b789f4da375ef9turaj@webrtc.org  //
3933f39c00d9875d7e09062725757b789f4da375ef9turaj@webrtc.org  // Input:
3943f39c00d9875d7e09062725757b789f4da375ef9turaj@webrtc.org  //   -codec_id           : the ID of the codec associated with the
3953f39c00d9875d7e09062725757b789f4da375ef9turaj@webrtc.org  //                         payload type that we just received.
3963f39c00d9875d7e09062725757b789f4da375ef9turaj@webrtc.org  //
3973f39c00d9875d7e09062725757b789f4da375ef9turaj@webrtc.org  // Return value:
3983f39c00d9875d7e09062725757b789f4da375ef9turaj@webrtc.org  //    0 if succeeded in updating the decoder.
3993f39c00d9875d7e09062725757b789f4da375ef9turaj@webrtc.org  //   -1 if failed to update.
4003f39c00d9875d7e09062725757b789f4da375ef9turaj@webrtc.org  //
4013f39c00d9875d7e09062725757b789f4da375ef9turaj@webrtc.org  virtual int16_t UpdateDecoderSampFreq(int16_t /* codec_id */) { return 0; }
4023f39c00d9875d7e09062725757b789f4da375ef9turaj@webrtc.org
4033f39c00d9875d7e09062725757b789f4da375ef9turaj@webrtc.org  ///////////////////////////////////////////////////////////////////////////
4043f39c00d9875d7e09062725757b789f4da375ef9turaj@webrtc.org  // UpdateEncoderSampFreq()
4053f39c00d9875d7e09062725757b789f4da375ef9turaj@webrtc.org  // Call this function to update the encoder sampling frequency. This
4063f39c00d9875d7e09062725757b789f4da375ef9turaj@webrtc.org  // is for codecs where one payload-name supports several encoder sampling
4073f39c00d9875d7e09062725757b789f4da375ef9turaj@webrtc.org  // frequencies. Otherwise, to change the sampling frequency we need to
4083f39c00d9875d7e09062725757b789f4da375ef9turaj@webrtc.org  // register new codec. ACM will consider that as registration of a new
4093f39c00d9875d7e09062725757b789f4da375ef9turaj@webrtc.org  // codec, not a change in parameter. For iSAC, switching from WB to SWB
4103f39c00d9875d7e09062725757b789f4da375ef9turaj@webrtc.org  // is treated as a change in parameter. Therefore, we need this function.
4113f39c00d9875d7e09062725757b789f4da375ef9turaj@webrtc.org  //
4123f39c00d9875d7e09062725757b789f4da375ef9turaj@webrtc.org  // Input:
4133f39c00d9875d7e09062725757b789f4da375ef9turaj@webrtc.org  //   -samp_freq_hz        : encoder sampling frequency.
4143f39c00d9875d7e09062725757b789f4da375ef9turaj@webrtc.org  //
4153f39c00d9875d7e09062725757b789f4da375ef9turaj@webrtc.org  // Return value:
4163f39c00d9875d7e09062725757b789f4da375ef9turaj@webrtc.org  //   -1 if failed, or if this is meaningless for the given codec.
4173f39c00d9875d7e09062725757b789f4da375ef9turaj@webrtc.org  //    0 if succeeded.
4183f39c00d9875d7e09062725757b789f4da375ef9turaj@webrtc.org  //
41947b4b9d94cafb22e19bc8a6e6ca83b0568dcb973henrik.lundin@webrtc.org  virtual int16_t UpdateEncoderSampFreq(uint16_t samp_freq_hz)
42047b4b9d94cafb22e19bc8a6e6ca83b0568dcb973henrik.lundin@webrtc.org      EXCLUSIVE_LOCKS_REQUIRED(codec_wrapper_lock_);
4213f39c00d9875d7e09062725757b789f4da375ef9turaj@webrtc.org
4223f39c00d9875d7e09062725757b789f4da375ef9turaj@webrtc.org  ///////////////////////////////////////////////////////////////////////////
4233f39c00d9875d7e09062725757b789f4da375ef9turaj@webrtc.org  // EncoderSampFreq()
4243f39c00d9875d7e09062725757b789f4da375ef9turaj@webrtc.org  // Get the sampling frequency that the encoder (WebRtc wrapper) expects.
4253f39c00d9875d7e09062725757b789f4da375ef9turaj@webrtc.org  //
4263f39c00d9875d7e09062725757b789f4da375ef9turaj@webrtc.org  // Output:
4273f39c00d9875d7e09062725757b789f4da375ef9turaj@webrtc.org  //   -samp_freq_hz       : sampling frequency, in Hertz, which the encoder
4283f39c00d9875d7e09062725757b789f4da375ef9turaj@webrtc.org  //                         should be fed with.
4293f39c00d9875d7e09062725757b789f4da375ef9turaj@webrtc.org  //
4303f39c00d9875d7e09062725757b789f4da375ef9turaj@webrtc.org  // Return value:
4313f39c00d9875d7e09062725757b789f4da375ef9turaj@webrtc.org  //   -1 if failed to output sampling rate.
4323f39c00d9875d7e09062725757b789f4da375ef9turaj@webrtc.org  //    0 if the sample rate is returned successfully.
4333f39c00d9875d7e09062725757b789f4da375ef9turaj@webrtc.org  //
43447b4b9d94cafb22e19bc8a6e6ca83b0568dcb973henrik.lundin@webrtc.org  virtual int16_t EncoderSampFreq(uint16_t* samp_freq_hz)
43547b4b9d94cafb22e19bc8a6e6ca83b0568dcb973henrik.lundin@webrtc.org      SHARED_LOCKS_REQUIRED(codec_wrapper_lock_);
4363f39c00d9875d7e09062725757b789f4da375ef9turaj@webrtc.org
4373f39c00d9875d7e09062725757b789f4da375ef9turaj@webrtc.org  ///////////////////////////////////////////////////////////////////////////
4383f39c00d9875d7e09062725757b789f4da375ef9turaj@webrtc.org  // int32_t ConfigISACBandwidthEstimator()
4393f39c00d9875d7e09062725757b789f4da375ef9turaj@webrtc.org  // Call this function to configure the bandwidth estimator of ISAC.
4403f39c00d9875d7e09062725757b789f4da375ef9turaj@webrtc.org  // During the adaptation of bit-rate, iSAC automatically adjusts the
4413f39c00d9875d7e09062725757b789f4da375ef9turaj@webrtc.org  // frame-size (either 30 or 60 ms) to save on RTP header. The initial
4423f39c00d9875d7e09062725757b789f4da375ef9turaj@webrtc.org  // frame-size can be specified by the first argument. The configuration also
4433f39c00d9875d7e09062725757b789f4da375ef9turaj@webrtc.org  // regards the initial estimate of bandwidths. The estimator starts from
4443f39c00d9875d7e09062725757b789f4da375ef9turaj@webrtc.org  // this point and converges to the actual bottleneck. This is given by the
4453f39c00d9875d7e09062725757b789f4da375ef9turaj@webrtc.org  // second parameter. Furthermore, it is also possible to control the
4463f39c00d9875d7e09062725757b789f4da375ef9turaj@webrtc.org  // adaptation of frame-size. This is specified by the last parameter.
4473f39c00d9875d7e09062725757b789f4da375ef9turaj@webrtc.org  //
4483f39c00d9875d7e09062725757b789f4da375ef9turaj@webrtc.org  // Input:
4493f39c00d9875d7e09062725757b789f4da375ef9turaj@webrtc.org  //   -init_frame_fize_ms : initial frame-size in milliseconds. For iSAC-wb
4503f39c00d9875d7e09062725757b789f4da375ef9turaj@webrtc.org  //                         30 ms and 60 ms (default) are acceptable values,
4513f39c00d9875d7e09062725757b789f4da375ef9turaj@webrtc.org  //                         and for iSAC-swb 30 ms is the only acceptable
4523f39c00d9875d7e09062725757b789f4da375ef9turaj@webrtc.org  //                         value. Zero indicates default value.
4533f39c00d9875d7e09062725757b789f4da375ef9turaj@webrtc.org  //   -init_rate_bps      : initial estimate of the bandwidth. Values
4543f39c00d9875d7e09062725757b789f4da375ef9turaj@webrtc.org  //                         between 10000 and 58000 are acceptable.
4553f39c00d9875d7e09062725757b789f4da375ef9turaj@webrtc.org  //   -enforce_frame_size : if true, the frame-size will not be adapted.
4563f39c00d9875d7e09062725757b789f4da375ef9turaj@webrtc.org  //
4573f39c00d9875d7e09062725757b789f4da375ef9turaj@webrtc.org  // Return value:
4583f39c00d9875d7e09062725757b789f4da375ef9turaj@webrtc.org  //   -1 if failed to configure the bandwidth estimator,
4593f39c00d9875d7e09062725757b789f4da375ef9turaj@webrtc.org  //    0 if the configuration was successfully applied.
4603f39c00d9875d7e09062725757b789f4da375ef9turaj@webrtc.org  //
4613f39c00d9875d7e09062725757b789f4da375ef9turaj@webrtc.org  virtual int32_t ConfigISACBandwidthEstimator(
4623f39c00d9875d7e09062725757b789f4da375ef9turaj@webrtc.org      const uint8_t init_frame_size_msec,
4633f39c00d9875d7e09062725757b789f4da375ef9turaj@webrtc.org      const uint16_t init_rate_bps,
4643f39c00d9875d7e09062725757b789f4da375ef9turaj@webrtc.org      const bool enforce_frame_size);
4653f39c00d9875d7e09062725757b789f4da375ef9turaj@webrtc.org
4663f39c00d9875d7e09062725757b789f4da375ef9turaj@webrtc.org  ///////////////////////////////////////////////////////////////////////////
4673f39c00d9875d7e09062725757b789f4da375ef9turaj@webrtc.org  // SetISACMaxPayloadSize()
4683f39c00d9875d7e09062725757b789f4da375ef9turaj@webrtc.org  // Set the maximum payload size of iSAC packets. No iSAC payload,
4693f39c00d9875d7e09062725757b789f4da375ef9turaj@webrtc.org  // regardless of its frame-size, may exceed the given limit. For
4703f39c00d9875d7e09062725757b789f4da375ef9turaj@webrtc.org  // an iSAC payload of size B bits and frame-size T sec we have;
4713f39c00d9875d7e09062725757b789f4da375ef9turaj@webrtc.org  // (B < max_payload_len_bytes * 8) and (B/T < max_rate_bit_per_sec), c.f.
4723f39c00d9875d7e09062725757b789f4da375ef9turaj@webrtc.org  // SetISACMaxRate().
4733f39c00d9875d7e09062725757b789f4da375ef9turaj@webrtc.org  //
4743f39c00d9875d7e09062725757b789f4da375ef9turaj@webrtc.org  // Input:
4753f39c00d9875d7e09062725757b789f4da375ef9turaj@webrtc.org  //   -max_payload_len_bytes : maximum payload size in bytes.
4763f39c00d9875d7e09062725757b789f4da375ef9turaj@webrtc.org  //
4773f39c00d9875d7e09062725757b789f4da375ef9turaj@webrtc.org  // Return value:
4783f39c00d9875d7e09062725757b789f4da375ef9turaj@webrtc.org  //   -1 if failed to set the maximum  payload-size.
4793f39c00d9875d7e09062725757b789f4da375ef9turaj@webrtc.org  //    0 if the given length is set successfully.
4803f39c00d9875d7e09062725757b789f4da375ef9turaj@webrtc.org  //
4813f39c00d9875d7e09062725757b789f4da375ef9turaj@webrtc.org  virtual int32_t SetISACMaxPayloadSize(const uint16_t max_payload_len_bytes);
4823f39c00d9875d7e09062725757b789f4da375ef9turaj@webrtc.org
4833f39c00d9875d7e09062725757b789f4da375ef9turaj@webrtc.org  ///////////////////////////////////////////////////////////////////////////
4843f39c00d9875d7e09062725757b789f4da375ef9turaj@webrtc.org  // SetISACMaxRate()
4853f39c00d9875d7e09062725757b789f4da375ef9turaj@webrtc.org  // Set the maximum instantaneous rate of iSAC. For a payload of B bits
4863f39c00d9875d7e09062725757b789f4da375ef9turaj@webrtc.org  // with a frame-size of T sec the instantaneous rate is B/T bits per
4873f39c00d9875d7e09062725757b789f4da375ef9turaj@webrtc.org  // second. Therefore, (B/T < max_rate_bit_per_sec) and
4883f39c00d9875d7e09062725757b789f4da375ef9turaj@webrtc.org  // (B < max_payload_len_bytes * 8) are always satisfied for iSAC payloads,
4893f39c00d9875d7e09062725757b789f4da375ef9turaj@webrtc.org  // c.f SetISACMaxPayloadSize().
4903f39c00d9875d7e09062725757b789f4da375ef9turaj@webrtc.org  //
4913f39c00d9875d7e09062725757b789f4da375ef9turaj@webrtc.org  // Input:
4923f39c00d9875d7e09062725757b789f4da375ef9turaj@webrtc.org  //   -max_rate_bps       : maximum instantaneous bit-rate given in bits/sec.
4933f39c00d9875d7e09062725757b789f4da375ef9turaj@webrtc.org  //
4943f39c00d9875d7e09062725757b789f4da375ef9turaj@webrtc.org  // Return value:
4953f39c00d9875d7e09062725757b789f4da375ef9turaj@webrtc.org  //   -1 if failed to set the maximum rate.
4963f39c00d9875d7e09062725757b789f4da375ef9turaj@webrtc.org  //    0 if the maximum rate is set successfully.
4973f39c00d9875d7e09062725757b789f4da375ef9turaj@webrtc.org  //
4983f39c00d9875d7e09062725757b789f4da375ef9turaj@webrtc.org  virtual int32_t SetISACMaxRate(const uint32_t max_rate_bps);
4993f39c00d9875d7e09062725757b789f4da375ef9turaj@webrtc.org
5003f39c00d9875d7e09062725757b789f4da375ef9turaj@webrtc.org  ///////////////////////////////////////////////////////////////////////////
5013f39c00d9875d7e09062725757b789f4da375ef9turaj@webrtc.org  // REDPayloadISAC()
5023f39c00d9875d7e09062725757b789f4da375ef9turaj@webrtc.org  // This is an iSAC-specific function. The function is called to get RED
5033f39c00d9875d7e09062725757b789f4da375ef9turaj@webrtc.org  // payload from a default-encoder.
5043f39c00d9875d7e09062725757b789f4da375ef9turaj@webrtc.org  //
5053f39c00d9875d7e09062725757b789f4da375ef9turaj@webrtc.org  // Inputs:
5063f39c00d9875d7e09062725757b789f4da375ef9turaj@webrtc.org  //   -isac_rate          : the target rate of the main payload. A RED
5073f39c00d9875d7e09062725757b789f4da375ef9turaj@webrtc.org  //                         payload is generated according to the rate of
5083f39c00d9875d7e09062725757b789f4da375ef9turaj@webrtc.org  //                         main payload. Note that we are not specifying the
5093f39c00d9875d7e09062725757b789f4da375ef9turaj@webrtc.org  //                         rate of RED payload, but the main payload.
5103f39c00d9875d7e09062725757b789f4da375ef9turaj@webrtc.org  //   -isac_bw_estimate   : bandwidth information should be inserted in
5113f39c00d9875d7e09062725757b789f4da375ef9turaj@webrtc.org  //                         RED payload.
5123f39c00d9875d7e09062725757b789f4da375ef9turaj@webrtc.org  //
5133f39c00d9875d7e09062725757b789f4da375ef9turaj@webrtc.org  // Output:
5143f39c00d9875d7e09062725757b789f4da375ef9turaj@webrtc.org  //   -payload            : pointer to a buffer where the RED payload will
5153f39c00d9875d7e09062725757b789f4da375ef9turaj@webrtc.org  //                         written to.
5163f39c00d9875d7e09062725757b789f4da375ef9turaj@webrtc.org  //   -payload_len_bytes  : a place-holder to write the length of the RED
5173f39c00d9875d7e09062725757b789f4da375ef9turaj@webrtc.org  //                         payload in Bytes.
5183f39c00d9875d7e09062725757b789f4da375ef9turaj@webrtc.org  //
5193f39c00d9875d7e09062725757b789f4da375ef9turaj@webrtc.org  // Return value:
5203f39c00d9875d7e09062725757b789f4da375ef9turaj@webrtc.org  //   -1 if an error occurs, otherwise the length of the payload (in Bytes)
5213f39c00d9875d7e09062725757b789f4da375ef9turaj@webrtc.org  //   is returned.
5223f39c00d9875d7e09062725757b789f4da375ef9turaj@webrtc.org  //
5233f39c00d9875d7e09062725757b789f4da375ef9turaj@webrtc.org  virtual int16_t REDPayloadISAC(const int32_t isac_rate,
5243f39c00d9875d7e09062725757b789f4da375ef9turaj@webrtc.org                                 const int16_t isac_bw_estimate,
5253f39c00d9875d7e09062725757b789f4da375ef9turaj@webrtc.org                                 uint8_t* payload,
5263f39c00d9875d7e09062725757b789f4da375ef9turaj@webrtc.org                                 int16_t* payload_len_bytes);
5273f39c00d9875d7e09062725757b789f4da375ef9turaj@webrtc.org
5283f39c00d9875d7e09062725757b789f4da375ef9turaj@webrtc.org  ///////////////////////////////////////////////////////////////////////////
529b0aac71bfeb5b06083a9664434d936e091f54d91minyue@webrtc.org  // int SetOpusMaxPlaybackRate()
530b0aac71bfeb5b06083a9664434d936e091f54d91minyue@webrtc.org  // Sets maximum playback rate the receiver will render, if the codec is Opus.
531b0aac71bfeb5b06083a9664434d936e091f54d91minyue@webrtc.org  // This is to tell Opus that it is enough to code the input audio up to a
532b0aac71bfeb5b06083a9664434d936e091f54d91minyue@webrtc.org  // bandwidth. Opus can take this information to optimize the bit rate and
533b0aac71bfeb5b06083a9664434d936e091f54d91minyue@webrtc.org  // increase the computation efficiency.
5341bfd54032a8e60b993fb3b32c15ba9c55184c86bminyue@webrtc.org  //
5351bfd54032a8e60b993fb3b32c15ba9c55184c86bminyue@webrtc.org  // Input:
536b0aac71bfeb5b06083a9664434d936e091f54d91minyue@webrtc.org  //   -frequency_hz      : maximum playback rate in Hz.
5371bfd54032a8e60b993fb3b32c15ba9c55184c86bminyue@webrtc.org  //
5381bfd54032a8e60b993fb3b32c15ba9c55184c86bminyue@webrtc.org  // Return value:
5391bfd54032a8e60b993fb3b32c15ba9c55184c86bminyue@webrtc.org  //   -1 if failed or on codecs other than Opus
5401bfd54032a8e60b993fb3b32c15ba9c55184c86bminyue@webrtc.org  //    0 if succeeded.
5411bfd54032a8e60b993fb3b32c15ba9c55184c86bminyue@webrtc.org  //
542b0aac71bfeb5b06083a9664434d936e091f54d91minyue@webrtc.org  virtual int SetOpusMaxPlaybackRate(int /* frequency_hz */);
5431bfd54032a8e60b993fb3b32c15ba9c55184c86bminyue@webrtc.org
5441bfd54032a8e60b993fb3b32c15ba9c55184c86bminyue@webrtc.org  ///////////////////////////////////////////////////////////////////////////
5453f39c00d9875d7e09062725757b789f4da375ef9turaj@webrtc.org  // HasFrameToEncode()
5463f39c00d9875d7e09062725757b789f4da375ef9turaj@webrtc.org  // Returns true if there is enough audio buffered for encoding, such that
5473f39c00d9875d7e09062725757b789f4da375ef9turaj@webrtc.org  // calling Encode() will return a payload.
5483f39c00d9875d7e09062725757b789f4da375ef9turaj@webrtc.org  //
5493f39c00d9875d7e09062725757b789f4da375ef9turaj@webrtc.org  bool HasFrameToEncode() const;
5503f39c00d9875d7e09062725757b789f4da375ef9turaj@webrtc.org
5513f39c00d9875d7e09062725757b789f4da375ef9turaj@webrtc.org  //
5523f39c00d9875d7e09062725757b789f4da375ef9turaj@webrtc.org  // Returns pointer to the AudioDecoder class of this codec. A codec which
5533f39c00d9875d7e09062725757b789f4da375ef9turaj@webrtc.org  // should own its own decoder (e.g. iSAC which need same instance for encoding
5543f39c00d9875d7e09062725757b789f4da375ef9turaj@webrtc.org  // and decoding, or a codec which should access decoder instance for specific
5553f39c00d9875d7e09062725757b789f4da375ef9turaj@webrtc.org  // decoder setting) should implement this method. This method is called if
5563f39c00d9875d7e09062725757b789f4da375ef9turaj@webrtc.org  // and only if the ACMCodecDB::codec_settings[codec_id].owns_decoder is true.
5573f39c00d9875d7e09062725757b789f4da375ef9turaj@webrtc.org  //
5583f39c00d9875d7e09062725757b789f4da375ef9turaj@webrtc.org  virtual AudioDecoder* Decoder(int /* codec_id */) { return NULL; }
5593f39c00d9875d7e09062725757b789f4da375ef9turaj@webrtc.org
56091c0a2592faf1e68f658c98e5faa1acef7124d1aminyue@webrtc.org  ///////////////////////////////////////////////////////////////////////////
56191c0a2592faf1e68f658c98e5faa1acef7124d1aminyue@webrtc.org  // bool HasInternalFEC()
56291c0a2592faf1e68f658c98e5faa1acef7124d1aminyue@webrtc.org  // Used to check if the codec has internal FEC.
56391c0a2592faf1e68f658c98e5faa1acef7124d1aminyue@webrtc.org  //
56491c0a2592faf1e68f658c98e5faa1acef7124d1aminyue@webrtc.org  // Return value:
56591c0a2592faf1e68f658c98e5faa1acef7124d1aminyue@webrtc.org  //   true if the codec has an internal FEC, e.g. Opus.
56691c0a2592faf1e68f658c98e5faa1acef7124d1aminyue@webrtc.org  //   false otherwise.
56791c0a2592faf1e68f658c98e5faa1acef7124d1aminyue@webrtc.org  //
56847b4b9d94cafb22e19bc8a6e6ca83b0568dcb973henrik.lundin@webrtc.org  bool HasInternalFEC() const {
56947b4b9d94cafb22e19bc8a6e6ca83b0568dcb973henrik.lundin@webrtc.org    ReadLockScoped rl(codec_wrapper_lock_);
57047b4b9d94cafb22e19bc8a6e6ca83b0568dcb973henrik.lundin@webrtc.org    return has_internal_fec_;
57147b4b9d94cafb22e19bc8a6e6ca83b0568dcb973henrik.lundin@webrtc.org  }
57291c0a2592faf1e68f658c98e5faa1acef7124d1aminyue@webrtc.org
57391c0a2592faf1e68f658c98e5faa1acef7124d1aminyue@webrtc.org  ///////////////////////////////////////////////////////////////////////////
57491c0a2592faf1e68f658c98e5faa1acef7124d1aminyue@webrtc.org  // int SetFEC();
57591c0a2592faf1e68f658c98e5faa1acef7124d1aminyue@webrtc.org  // Sets the codec internal FEC. No effects on codecs that do not provide
57691c0a2592faf1e68f658c98e5faa1acef7124d1aminyue@webrtc.org  // internal FEC.
57791c0a2592faf1e68f658c98e5faa1acef7124d1aminyue@webrtc.org  //
57891c0a2592faf1e68f658c98e5faa1acef7124d1aminyue@webrtc.org  // Input:
57991c0a2592faf1e68f658c98e5faa1acef7124d1aminyue@webrtc.org  //   -enable_fec         : if true FEC will be enabled otherwise the FEC is
58091c0a2592faf1e68f658c98e5faa1acef7124d1aminyue@webrtc.org  //                         disabled.
58191c0a2592faf1e68f658c98e5faa1acef7124d1aminyue@webrtc.org  //
58291c0a2592faf1e68f658c98e5faa1acef7124d1aminyue@webrtc.org  // Return value:
58391c0a2592faf1e68f658c98e5faa1acef7124d1aminyue@webrtc.org  //   -1 if failed, or the codec does not support FEC
58491c0a2592faf1e68f658c98e5faa1acef7124d1aminyue@webrtc.org  //    0 if succeeded.
58591c0a2592faf1e68f658c98e5faa1acef7124d1aminyue@webrtc.org  //
58691c0a2592faf1e68f658c98e5faa1acef7124d1aminyue@webrtc.org  virtual int SetFEC(bool /* enable_fec */) { return -1; }
58791c0a2592faf1e68f658c98e5faa1acef7124d1aminyue@webrtc.org
58891c0a2592faf1e68f658c98e5faa1acef7124d1aminyue@webrtc.org  ///////////////////////////////////////////////////////////////////////////
58991c0a2592faf1e68f658c98e5faa1acef7124d1aminyue@webrtc.org  // int SetPacketLossRate()
59091c0a2592faf1e68f658c98e5faa1acef7124d1aminyue@webrtc.org  // Sets expected packet loss rate for encoding. Some encoders provide packet
59191c0a2592faf1e68f658c98e5faa1acef7124d1aminyue@webrtc.org  // loss gnostic encoding to make stream less sensitive to packet losses,
59291c0a2592faf1e68f658c98e5faa1acef7124d1aminyue@webrtc.org  // through e.g., FEC. No effects on codecs that do not provide such encoding.
59391c0a2592faf1e68f658c98e5faa1acef7124d1aminyue@webrtc.org  //
59491c0a2592faf1e68f658c98e5faa1acef7124d1aminyue@webrtc.org  // Input:
59591c0a2592faf1e68f658c98e5faa1acef7124d1aminyue@webrtc.org  //   -loss_rate          : expected packet loss rate (0 -- 100 inclusive).
59691c0a2592faf1e68f658c98e5faa1acef7124d1aminyue@webrtc.org  //
59791c0a2592faf1e68f658c98e5faa1acef7124d1aminyue@webrtc.org  // Return value:
5984260aa20c4157dc3d9c522ddd65041027b7544d1minyue@webrtc.org  //   -1 if failed,
5994260aa20c4157dc3d9c522ddd65041027b7544d1minyue@webrtc.org  //    0 if succeeded or packet loss rate is ignored.
60091c0a2592faf1e68f658c98e5faa1acef7124d1aminyue@webrtc.org  //
6014260aa20c4157dc3d9c522ddd65041027b7544d1minyue@webrtc.org  virtual int SetPacketLossRate(int /* loss_rate */) { return 0; }
60291c0a2592faf1e68f658c98e5faa1acef7124d1aminyue@webrtc.org
6033f39c00d9875d7e09062725757b789f4da375ef9turaj@webrtc.org protected:
6043f39c00d9875d7e09062725757b789f4da375ef9turaj@webrtc.org  ///////////////////////////////////////////////////////////////////////////
6053f39c00d9875d7e09062725757b789f4da375ef9turaj@webrtc.org  // All the functions with FunctionNameSafe(...) contain the actual
6063f39c00d9875d7e09062725757b789f4da375ef9turaj@webrtc.org  // implementation of FunctionName(...). FunctionName() acquires an
6073f39c00d9875d7e09062725757b789f4da375ef9turaj@webrtc.org  // appropriate lock and calls FunctionNameSafe() to do the actual work.
6083f39c00d9875d7e09062725757b789f4da375ef9turaj@webrtc.org  // Therefore, for the description of functionality, input/output arguments
6093f39c00d9875d7e09062725757b789f4da375ef9turaj@webrtc.org  // and return value we refer to FunctionName()
6103f39c00d9875d7e09062725757b789f4da375ef9turaj@webrtc.org  //
6113f39c00d9875d7e09062725757b789f4da375ef9turaj@webrtc.org
6123f39c00d9875d7e09062725757b789f4da375ef9turaj@webrtc.org  ///////////////////////////////////////////////////////////////////////////
6133f39c00d9875d7e09062725757b789f4da375ef9turaj@webrtc.org  // See Add10MsSafe() for the description of function, input(s)/output(s)
6143f39c00d9875d7e09062725757b789f4da375ef9turaj@webrtc.org  // and return value.
6153f39c00d9875d7e09062725757b789f4da375ef9turaj@webrtc.org  //
6163f39c00d9875d7e09062725757b789f4da375ef9turaj@webrtc.org  virtual int32_t Add10MsDataSafe(const uint32_t timestamp,
6173f39c00d9875d7e09062725757b789f4da375ef9turaj@webrtc.org                                  const int16_t* data,
6183f39c00d9875d7e09062725757b789f4da375ef9turaj@webrtc.org                                  const uint16_t length,
6190c145390636e0936dadd96d9c34087577e69d95ahenrik.lundin@webrtc.org                                  const uint8_t audio_channel)
6200c145390636e0936dadd96d9c34087577e69d95ahenrik.lundin@webrtc.org      EXCLUSIVE_LOCKS_REQUIRED(codec_wrapper_lock_);
6213f39c00d9875d7e09062725757b789f4da375ef9turaj@webrtc.org
6223f39c00d9875d7e09062725757b789f4da375ef9turaj@webrtc.org  ///////////////////////////////////////////////////////////////////////////
6233f39c00d9875d7e09062725757b789f4da375ef9turaj@webrtc.org  // See EncoderParam() for the description of function, input(s)/output(s)
6243f39c00d9875d7e09062725757b789f4da375ef9turaj@webrtc.org  // and return value.
6253f39c00d9875d7e09062725757b789f4da375ef9turaj@webrtc.org  //
62647b4b9d94cafb22e19bc8a6e6ca83b0568dcb973henrik.lundin@webrtc.org  int16_t EncoderParamsSafe(WebRtcACMCodecParams* enc_params)
62747b4b9d94cafb22e19bc8a6e6ca83b0568dcb973henrik.lundin@webrtc.org      SHARED_LOCKS_REQUIRED(codec_wrapper_lock_);
6283f39c00d9875d7e09062725757b789f4da375ef9turaj@webrtc.org
6293f39c00d9875d7e09062725757b789f4da375ef9turaj@webrtc.org  ///////////////////////////////////////////////////////////////////////////
6303f39c00d9875d7e09062725757b789f4da375ef9turaj@webrtc.org  // See ResetEncoder() for the description of function, input(s)/output(s)
6313f39c00d9875d7e09062725757b789f4da375ef9turaj@webrtc.org  // and return value.
6323f39c00d9875d7e09062725757b789f4da375ef9turaj@webrtc.org  //
6330c145390636e0936dadd96d9c34087577e69d95ahenrik.lundin@webrtc.org  int16_t ResetEncoderSafe() EXCLUSIVE_LOCKS_REQUIRED(codec_wrapper_lock_);
6343f39c00d9875d7e09062725757b789f4da375ef9turaj@webrtc.org
6353f39c00d9875d7e09062725757b789f4da375ef9turaj@webrtc.org  ///////////////////////////////////////////////////////////////////////////
6363f39c00d9875d7e09062725757b789f4da375ef9turaj@webrtc.org  // See InitEncoder() for the description of function, input(s)/output(s)
6373f39c00d9875d7e09062725757b789f4da375ef9turaj@webrtc.org  // and return value.
6383f39c00d9875d7e09062725757b789f4da375ef9turaj@webrtc.org  //
6393f39c00d9875d7e09062725757b789f4da375ef9turaj@webrtc.org  int16_t InitEncoderSafe(WebRtcACMCodecParams* codec_params,
6400c145390636e0936dadd96d9c34087577e69d95ahenrik.lundin@webrtc.org                          bool force_initialization)
6410c145390636e0936dadd96d9c34087577e69d95ahenrik.lundin@webrtc.org      EXCLUSIVE_LOCKS_REQUIRED(codec_wrapper_lock_);
6423f39c00d9875d7e09062725757b789f4da375ef9turaj@webrtc.org
6433f39c00d9875d7e09062725757b789f4da375ef9turaj@webrtc.org  ///////////////////////////////////////////////////////////////////////////
6443f39c00d9875d7e09062725757b789f4da375ef9turaj@webrtc.org  // See InitDecoder() for the description of function, input(s)/output(s)
6453f39c00d9875d7e09062725757b789f4da375ef9turaj@webrtc.org  // and return value.
6463f39c00d9875d7e09062725757b789f4da375ef9turaj@webrtc.org  //
6473f39c00d9875d7e09062725757b789f4da375ef9turaj@webrtc.org  int16_t InitDecoderSafe(WebRtcACMCodecParams* codec_params,
6483f39c00d9875d7e09062725757b789f4da375ef9turaj@webrtc.org                          bool force_initialization);
6493f39c00d9875d7e09062725757b789f4da375ef9turaj@webrtc.org
6503f39c00d9875d7e09062725757b789f4da375ef9turaj@webrtc.org  ///////////////////////////////////////////////////////////////////////////
6513f39c00d9875d7e09062725757b789f4da375ef9turaj@webrtc.org  // See DestructEncoder() for the description of function,
6523f39c00d9875d7e09062725757b789f4da375ef9turaj@webrtc.org  // input(s)/output(s) and return value.
6533f39c00d9875d7e09062725757b789f4da375ef9turaj@webrtc.org  //
65447b4b9d94cafb22e19bc8a6e6ca83b0568dcb973henrik.lundin@webrtc.org  virtual void DestructEncoderSafe()
65547b4b9d94cafb22e19bc8a6e6ca83b0568dcb973henrik.lundin@webrtc.org      EXCLUSIVE_LOCKS_REQUIRED(codec_wrapper_lock_) = 0;
6563f39c00d9875d7e09062725757b789f4da375ef9turaj@webrtc.org
6573f39c00d9875d7e09062725757b789f4da375ef9turaj@webrtc.org  ///////////////////////////////////////////////////////////////////////////
6583f39c00d9875d7e09062725757b789f4da375ef9turaj@webrtc.org  // See SetBitRate() for the description of function, input(s)/output(s)
6593f39c00d9875d7e09062725757b789f4da375ef9turaj@webrtc.org  // and return value.
6603f39c00d9875d7e09062725757b789f4da375ef9turaj@webrtc.org  //
6613f39c00d9875d7e09062725757b789f4da375ef9turaj@webrtc.org  // Any codec that can change the bit-rate has to implement this.
6623f39c00d9875d7e09062725757b789f4da375ef9turaj@webrtc.org  //
66347b4b9d94cafb22e19bc8a6e6ca83b0568dcb973henrik.lundin@webrtc.org  virtual int16_t SetBitRateSafe(const int32_t bitrate_bps)
66447b4b9d94cafb22e19bc8a6e6ca83b0568dcb973henrik.lundin@webrtc.org      EXCLUSIVE_LOCKS_REQUIRED(codec_wrapper_lock_);
6653f39c00d9875d7e09062725757b789f4da375ef9turaj@webrtc.org
6663f39c00d9875d7e09062725757b789f4da375ef9turaj@webrtc.org  ///////////////////////////////////////////////////////////////////////////
6673f39c00d9875d7e09062725757b789f4da375ef9turaj@webrtc.org  // See GetEstimatedBandwidth() for the description of function,
6683f39c00d9875d7e09062725757b789f4da375ef9turaj@webrtc.org  // input(s)/output(s) and return value.
6693f39c00d9875d7e09062725757b789f4da375ef9turaj@webrtc.org  //
6703f39c00d9875d7e09062725757b789f4da375ef9turaj@webrtc.org  virtual int32_t GetEstimatedBandwidthSafe();
6713f39c00d9875d7e09062725757b789f4da375ef9turaj@webrtc.org
6723f39c00d9875d7e09062725757b789f4da375ef9turaj@webrtc.org  ///////////////////////////////////////////////////////////////////////////
6733f39c00d9875d7e09062725757b789f4da375ef9turaj@webrtc.org  // See SetEstimatedBandwidth() for the description of function,
6743f39c00d9875d7e09062725757b789f4da375ef9turaj@webrtc.org  // input(s)/output(s) and return value.
6753f39c00d9875d7e09062725757b789f4da375ef9turaj@webrtc.org  //
6763f39c00d9875d7e09062725757b789f4da375ef9turaj@webrtc.org  virtual int32_t SetEstimatedBandwidthSafe(int32_t estimated_bandwidth);
6773f39c00d9875d7e09062725757b789f4da375ef9turaj@webrtc.org
6783f39c00d9875d7e09062725757b789f4da375ef9turaj@webrtc.org  ///////////////////////////////////////////////////////////////////////////
6793f39c00d9875d7e09062725757b789f4da375ef9turaj@webrtc.org  // See GetRedPayload() for the description of function, input(s)/output(s)
6803f39c00d9875d7e09062725757b789f4da375ef9turaj@webrtc.org  // and return value.
6813f39c00d9875d7e09062725757b789f4da375ef9turaj@webrtc.org  //
6823f39c00d9875d7e09062725757b789f4da375ef9turaj@webrtc.org  virtual int32_t GetRedPayloadSafe(uint8_t* red_payload,
6833f39c00d9875d7e09062725757b789f4da375ef9turaj@webrtc.org                                    int16_t* payload_bytes);
6843f39c00d9875d7e09062725757b789f4da375ef9turaj@webrtc.org
6853f39c00d9875d7e09062725757b789f4da375ef9turaj@webrtc.org  ///////////////////////////////////////////////////////////////////////////
6863f39c00d9875d7e09062725757b789f4da375ef9turaj@webrtc.org  // See SetVAD() for the description of function, input(s)/output(s) and
6873f39c00d9875d7e09062725757b789f4da375ef9turaj@webrtc.org  // return value.
6883f39c00d9875d7e09062725757b789f4da375ef9turaj@webrtc.org  //
6890c145390636e0936dadd96d9c34087577e69d95ahenrik.lundin@webrtc.org  int16_t SetVADSafe(bool* enable_dtx, bool* enable_vad, ACMVADMode* mode)
6900c145390636e0936dadd96d9c34087577e69d95ahenrik.lundin@webrtc.org      EXCLUSIVE_LOCKS_REQUIRED(codec_wrapper_lock_);
6913f39c00d9875d7e09062725757b789f4da375ef9turaj@webrtc.org
6923f39c00d9875d7e09062725757b789f4da375ef9turaj@webrtc.org  ///////////////////////////////////////////////////////////////////////////
6933f39c00d9875d7e09062725757b789f4da375ef9turaj@webrtc.org  // See ReplaceInternalDTX() for the description of function, input and
6943f39c00d9875d7e09062725757b789f4da375ef9turaj@webrtc.org  // return value.
6953f39c00d9875d7e09062725757b789f4da375ef9turaj@webrtc.org  //
6963f39c00d9875d7e09062725757b789f4da375ef9turaj@webrtc.org  virtual int32_t ReplaceInternalDTXSafe(const bool replace_internal_dtx);
6973f39c00d9875d7e09062725757b789f4da375ef9turaj@webrtc.org
6983f39c00d9875d7e09062725757b789f4da375ef9turaj@webrtc.org  ///////////////////////////////////////////////////////////////////////////
6993f39c00d9875d7e09062725757b789f4da375ef9turaj@webrtc.org  // See IsInternalDTXReplaced() for the description of function, input and
7003f39c00d9875d7e09062725757b789f4da375ef9turaj@webrtc.org  // return value.
7013f39c00d9875d7e09062725757b789f4da375ef9turaj@webrtc.org  //
7023f39c00d9875d7e09062725757b789f4da375ef9turaj@webrtc.org  virtual int32_t IsInternalDTXReplacedSafe(bool* internal_dtx_replaced);
7033f39c00d9875d7e09062725757b789f4da375ef9turaj@webrtc.org
7043f39c00d9875d7e09062725757b789f4da375ef9turaj@webrtc.org  ///////////////////////////////////////////////////////////////////////////
7053f39c00d9875d7e09062725757b789f4da375ef9turaj@webrtc.org  // int16_t CreateEncoder()
7063f39c00d9875d7e09062725757b789f4da375ef9turaj@webrtc.org  // Creates the encoder instance.
7073f39c00d9875d7e09062725757b789f4da375ef9turaj@webrtc.org  //
7083f39c00d9875d7e09062725757b789f4da375ef9turaj@webrtc.org  // Return value:
7093f39c00d9875d7e09062725757b789f4da375ef9turaj@webrtc.org  //   -1 if failed,
7103f39c00d9875d7e09062725757b789f4da375ef9turaj@webrtc.org  //    0 if succeeded.
7113f39c00d9875d7e09062725757b789f4da375ef9turaj@webrtc.org  //
71247b4b9d94cafb22e19bc8a6e6ca83b0568dcb973henrik.lundin@webrtc.org  int16_t CreateEncoder() EXCLUSIVE_LOCKS_REQUIRED(codec_wrapper_lock_);
7133f39c00d9875d7e09062725757b789f4da375ef9turaj@webrtc.org
7143f39c00d9875d7e09062725757b789f4da375ef9turaj@webrtc.org  ///////////////////////////////////////////////////////////////////////////
7153f39c00d9875d7e09062725757b789f4da375ef9turaj@webrtc.org  // int16_t EnableVAD();
7163f39c00d9875d7e09062725757b789f4da375ef9turaj@webrtc.org  // Enables VAD with the given mode. The VAD instance will be created if
7173f39c00d9875d7e09062725757b789f4da375ef9turaj@webrtc.org  // it does not exists.
7183f39c00d9875d7e09062725757b789f4da375ef9turaj@webrtc.org  //
7193f39c00d9875d7e09062725757b789f4da375ef9turaj@webrtc.org  // Input:
7203f39c00d9875d7e09062725757b789f4da375ef9turaj@webrtc.org  //   -mode               : VAD mode c.f. audio_coding_module_typedefs.h for
7213f39c00d9875d7e09062725757b789f4da375ef9turaj@webrtc.org  //                         the options.
7223f39c00d9875d7e09062725757b789f4da375ef9turaj@webrtc.org  //
7233f39c00d9875d7e09062725757b789f4da375ef9turaj@webrtc.org  // Return value:
7243f39c00d9875d7e09062725757b789f4da375ef9turaj@webrtc.org  //   -1 if failed,
7253f39c00d9875d7e09062725757b789f4da375ef9turaj@webrtc.org  //    0 if succeeded.
7263f39c00d9875d7e09062725757b789f4da375ef9turaj@webrtc.org  //
7270c145390636e0936dadd96d9c34087577e69d95ahenrik.lundin@webrtc.org  int16_t EnableVAD(ACMVADMode mode)
7280c145390636e0936dadd96d9c34087577e69d95ahenrik.lundin@webrtc.org      EXCLUSIVE_LOCKS_REQUIRED(codec_wrapper_lock_);
7293f39c00d9875d7e09062725757b789f4da375ef9turaj@webrtc.org
7303f39c00d9875d7e09062725757b789f4da375ef9turaj@webrtc.org  ///////////////////////////////////////////////////////////////////////////
7313f39c00d9875d7e09062725757b789f4da375ef9turaj@webrtc.org  // int16_t DisableVAD()
7323f39c00d9875d7e09062725757b789f4da375ef9turaj@webrtc.org  // Disables VAD.
7333f39c00d9875d7e09062725757b789f4da375ef9turaj@webrtc.org  //
7343f39c00d9875d7e09062725757b789f4da375ef9turaj@webrtc.org  // Return value:
7353f39c00d9875d7e09062725757b789f4da375ef9turaj@webrtc.org  //   -1 if failed,
7363f39c00d9875d7e09062725757b789f4da375ef9turaj@webrtc.org  //    0 if succeeded.
7373f39c00d9875d7e09062725757b789f4da375ef9turaj@webrtc.org  //
7380c145390636e0936dadd96d9c34087577e69d95ahenrik.lundin@webrtc.org  int16_t DisableVAD() EXCLUSIVE_LOCKS_REQUIRED(codec_wrapper_lock_);
7393f39c00d9875d7e09062725757b789f4da375ef9turaj@webrtc.org
7403f39c00d9875d7e09062725757b789f4da375ef9turaj@webrtc.org  ///////////////////////////////////////////////////////////////////////////
7413f39c00d9875d7e09062725757b789f4da375ef9turaj@webrtc.org  // int16_t EnableDTX()
7423f39c00d9875d7e09062725757b789f4da375ef9turaj@webrtc.org  // Enables DTX. This method should be overwritten for codecs which have
7433f39c00d9875d7e09062725757b789f4da375ef9turaj@webrtc.org  // internal DTX.
7443f39c00d9875d7e09062725757b789f4da375ef9turaj@webrtc.org  //
7453f39c00d9875d7e09062725757b789f4da375ef9turaj@webrtc.org  // Return value:
7463f39c00d9875d7e09062725757b789f4da375ef9turaj@webrtc.org  //   -1 if failed,
7473f39c00d9875d7e09062725757b789f4da375ef9turaj@webrtc.org  //    0 if succeeded.
7483f39c00d9875d7e09062725757b789f4da375ef9turaj@webrtc.org  //
7490c145390636e0936dadd96d9c34087577e69d95ahenrik.lundin@webrtc.org  virtual int16_t EnableDTX() EXCLUSIVE_LOCKS_REQUIRED(codec_wrapper_lock_);
7503f39c00d9875d7e09062725757b789f4da375ef9turaj@webrtc.org
7513f39c00d9875d7e09062725757b789f4da375ef9turaj@webrtc.org  ///////////////////////////////////////////////////////////////////////////
7523f39c00d9875d7e09062725757b789f4da375ef9turaj@webrtc.org  // int16_t DisableDTX()
7533f39c00d9875d7e09062725757b789f4da375ef9turaj@webrtc.org  // Disables usage of DTX. This method should be overwritten for codecs which
7543f39c00d9875d7e09062725757b789f4da375ef9turaj@webrtc.org  // have internal DTX.
7553f39c00d9875d7e09062725757b789f4da375ef9turaj@webrtc.org  //
7563f39c00d9875d7e09062725757b789f4da375ef9turaj@webrtc.org  // Return value:
7573f39c00d9875d7e09062725757b789f4da375ef9turaj@webrtc.org  //   -1 if failed,
7583f39c00d9875d7e09062725757b789f4da375ef9turaj@webrtc.org  //    0 if succeeded.
7593f39c00d9875d7e09062725757b789f4da375ef9turaj@webrtc.org  //
7600c145390636e0936dadd96d9c34087577e69d95ahenrik.lundin@webrtc.org  virtual int16_t DisableDTX() EXCLUSIVE_LOCKS_REQUIRED(codec_wrapper_lock_);
7613f39c00d9875d7e09062725757b789f4da375ef9turaj@webrtc.org
7623f39c00d9875d7e09062725757b789f4da375ef9turaj@webrtc.org  ///////////////////////////////////////////////////////////////////////////
7633f39c00d9875d7e09062725757b789f4da375ef9turaj@webrtc.org  // int16_t InternalEncode()
7643f39c00d9875d7e09062725757b789f4da375ef9turaj@webrtc.org  // This is a codec-specific function called in EncodeSafe() to actually
7653f39c00d9875d7e09062725757b789f4da375ef9turaj@webrtc.org  // encode a frame of audio.
7663f39c00d9875d7e09062725757b789f4da375ef9turaj@webrtc.org  //
7673f39c00d9875d7e09062725757b789f4da375ef9turaj@webrtc.org  // Outputs:
7683f39c00d9875d7e09062725757b789f4da375ef9turaj@webrtc.org  //   -bitstream          : pointer to a buffer where the bit-stream is
7693f39c00d9875d7e09062725757b789f4da375ef9turaj@webrtc.org  //                         written to.
7703f39c00d9875d7e09062725757b789f4da375ef9turaj@webrtc.org  //   -bitstream_len_byte : the length of the bit-stream in bytes,
7713f39c00d9875d7e09062725757b789f4da375ef9turaj@webrtc.org  //                         a negative value indicates error.
7723f39c00d9875d7e09062725757b789f4da375ef9turaj@webrtc.org  //
7733f39c00d9875d7e09062725757b789f4da375ef9turaj@webrtc.org  // Return value:
7743f39c00d9875d7e09062725757b789f4da375ef9turaj@webrtc.org  //   -1 if failed,
7753f39c00d9875d7e09062725757b789f4da375ef9turaj@webrtc.org  //   otherwise the length of the bit-stream is returned.
7763f39c00d9875d7e09062725757b789f4da375ef9turaj@webrtc.org  //
7773f39c00d9875d7e09062725757b789f4da375ef9turaj@webrtc.org  virtual int16_t InternalEncode(uint8_t* bitstream,
77847b4b9d94cafb22e19bc8a6e6ca83b0568dcb973henrik.lundin@webrtc.org                                 int16_t* bitstream_len_byte)
77947b4b9d94cafb22e19bc8a6e6ca83b0568dcb973henrik.lundin@webrtc.org      EXCLUSIVE_LOCKS_REQUIRED(codec_wrapper_lock_) = 0;
7803f39c00d9875d7e09062725757b789f4da375ef9turaj@webrtc.org
7813f39c00d9875d7e09062725757b789f4da375ef9turaj@webrtc.org  ///////////////////////////////////////////////////////////////////////////
7823f39c00d9875d7e09062725757b789f4da375ef9turaj@webrtc.org  // int16_t InternalInitEncoder()
7833f39c00d9875d7e09062725757b789f4da375ef9turaj@webrtc.org  // This is a codec-specific function called in InitEncoderSafe(), it has to
7843f39c00d9875d7e09062725757b789f4da375ef9turaj@webrtc.org  // do all codec-specific operation to initialize the encoder given the
7853f39c00d9875d7e09062725757b789f4da375ef9turaj@webrtc.org  // encoder parameters.
7863f39c00d9875d7e09062725757b789f4da375ef9turaj@webrtc.org  //
7873f39c00d9875d7e09062725757b789f4da375ef9turaj@webrtc.org  // Input:
7883f39c00d9875d7e09062725757b789f4da375ef9turaj@webrtc.org  //   -codec_params       : pointer to a structure that contains parameters to
7893f39c00d9875d7e09062725757b789f4da375ef9turaj@webrtc.org  //                         initialize encoder.
7903f39c00d9875d7e09062725757b789f4da375ef9turaj@webrtc.org  //                         Set codec_params->codec_inst.rate to -1 for
7913f39c00d9875d7e09062725757b789f4da375ef9turaj@webrtc.org  //                         iSAC to operate in adaptive mode.
7923f39c00d9875d7e09062725757b789f4da375ef9turaj@webrtc.org  //                         (to do: if frame-length is -1 frame-length will be
7933f39c00d9875d7e09062725757b789f4da375ef9turaj@webrtc.org  //                         automatically adjusted, otherwise, given
7943f39c00d9875d7e09062725757b789f4da375ef9turaj@webrtc.org  //                         frame-length is forced)
7953f39c00d9875d7e09062725757b789f4da375ef9turaj@webrtc.org  //
7963f39c00d9875d7e09062725757b789f4da375ef9turaj@webrtc.org  // Return value:
7973f39c00d9875d7e09062725757b789f4da375ef9turaj@webrtc.org  //   -1 if failed,
7983f39c00d9875d7e09062725757b789f4da375ef9turaj@webrtc.org  //    0 if succeeded.
7993f39c00d9875d7e09062725757b789f4da375ef9turaj@webrtc.org  //
80047b4b9d94cafb22e19bc8a6e6ca83b0568dcb973henrik.lundin@webrtc.org  virtual int16_t InternalInitEncoder(WebRtcACMCodecParams* codec_params)
80147b4b9d94cafb22e19bc8a6e6ca83b0568dcb973henrik.lundin@webrtc.org      EXCLUSIVE_LOCKS_REQUIRED(codec_wrapper_lock_) = 0;
8023f39c00d9875d7e09062725757b789f4da375ef9turaj@webrtc.org
8033f39c00d9875d7e09062725757b789f4da375ef9turaj@webrtc.org  ///////////////////////////////////////////////////////////////////////////
8043f39c00d9875d7e09062725757b789f4da375ef9turaj@webrtc.org  // void IncreaseNoMissedSamples()
8053f39c00d9875d7e09062725757b789f4da375ef9turaj@webrtc.org  // This method is called to increase the number of samples that are
8063f39c00d9875d7e09062725757b789f4da375ef9turaj@webrtc.org  // overwritten in the audio buffer.
8073f39c00d9875d7e09062725757b789f4da375ef9turaj@webrtc.org  //
8083f39c00d9875d7e09062725757b789f4da375ef9turaj@webrtc.org  // Input:
8093f39c00d9875d7e09062725757b789f4da375ef9turaj@webrtc.org  //   -num_samples        : the number of overwritten samples is incremented
8103f39c00d9875d7e09062725757b789f4da375ef9turaj@webrtc.org  //                         by this value.
8113f39c00d9875d7e09062725757b789f4da375ef9turaj@webrtc.org  //
81247b4b9d94cafb22e19bc8a6e6ca83b0568dcb973henrik.lundin@webrtc.org  void IncreaseNoMissedSamples(const int16_t num_samples)
81347b4b9d94cafb22e19bc8a6e6ca83b0568dcb973henrik.lundin@webrtc.org      EXCLUSIVE_LOCKS_REQUIRED(codec_wrapper_lock_);
8143f39c00d9875d7e09062725757b789f4da375ef9turaj@webrtc.org
8153f39c00d9875d7e09062725757b789f4da375ef9turaj@webrtc.org  ///////////////////////////////////////////////////////////////////////////
8163f39c00d9875d7e09062725757b789f4da375ef9turaj@webrtc.org  // int16_t InternalCreateEncoder()
8173f39c00d9875d7e09062725757b789f4da375ef9turaj@webrtc.org  // This is a codec-specific method called in CreateEncoderSafe() it is
8183f39c00d9875d7e09062725757b789f4da375ef9turaj@webrtc.org  // supposed to perform all codec-specific operations to create encoder
8193f39c00d9875d7e09062725757b789f4da375ef9turaj@webrtc.org  // instance.
8203f39c00d9875d7e09062725757b789f4da375ef9turaj@webrtc.org  //
8213f39c00d9875d7e09062725757b789f4da375ef9turaj@webrtc.org  // Return value:
8223f39c00d9875d7e09062725757b789f4da375ef9turaj@webrtc.org  //   -1 if failed,
8233f39c00d9875d7e09062725757b789f4da375ef9turaj@webrtc.org  //    0 if succeeded.
8243f39c00d9875d7e09062725757b789f4da375ef9turaj@webrtc.org  //
8253f39c00d9875d7e09062725757b789f4da375ef9turaj@webrtc.org  virtual int16_t InternalCreateEncoder() = 0;
8263f39c00d9875d7e09062725757b789f4da375ef9turaj@webrtc.org
8273f39c00d9875d7e09062725757b789f4da375ef9turaj@webrtc.org  ///////////////////////////////////////////////////////////////////////////
8283f39c00d9875d7e09062725757b789f4da375ef9turaj@webrtc.org  // int16_t InternalResetEncoder()
8293f39c00d9875d7e09062725757b789f4da375ef9turaj@webrtc.org  // This method is called to reset the states of encoder. However, the
8303f39c00d9875d7e09062725757b789f4da375ef9turaj@webrtc.org  // current parameters, e.g. frame-length, should remain as they are. For
8313f39c00d9875d7e09062725757b789f4da375ef9turaj@webrtc.org  // most of the codecs a re-initialization of the encoder is what needs to
8323f39c00d9875d7e09062725757b789f4da375ef9turaj@webrtc.org  // be down. But for iSAC we like to keep the BWE history so we cannot
8333f39c00d9875d7e09062725757b789f4da375ef9turaj@webrtc.org  // re-initialize. As soon as such an API is implemented in iSAC this method
8343f39c00d9875d7e09062725757b789f4da375ef9turaj@webrtc.org  // has to be overwritten in ACMISAC class.
8353f39c00d9875d7e09062725757b789f4da375ef9turaj@webrtc.org  //
8363f39c00d9875d7e09062725757b789f4da375ef9turaj@webrtc.org  // Return value:
8373f39c00d9875d7e09062725757b789f4da375ef9turaj@webrtc.org  //   -1 if failed,
8383f39c00d9875d7e09062725757b789f4da375ef9turaj@webrtc.org  //    0 if succeeded.
8393f39c00d9875d7e09062725757b789f4da375ef9turaj@webrtc.org  //
84047b4b9d94cafb22e19bc8a6e6ca83b0568dcb973henrik.lundin@webrtc.org  virtual int16_t InternalResetEncoder()
84147b4b9d94cafb22e19bc8a6e6ca83b0568dcb973henrik.lundin@webrtc.org      EXCLUSIVE_LOCKS_REQUIRED(codec_wrapper_lock_);
8423f39c00d9875d7e09062725757b789f4da375ef9turaj@webrtc.org
8433f39c00d9875d7e09062725757b789f4da375ef9turaj@webrtc.org  ///////////////////////////////////////////////////////////////////////////
8443f39c00d9875d7e09062725757b789f4da375ef9turaj@webrtc.org  // int16_t ProcessFrameVADDTX()
8453f39c00d9875d7e09062725757b789f4da375ef9turaj@webrtc.org  // This function is called when a full frame of audio is available. It will
8463f39c00d9875d7e09062725757b789f4da375ef9turaj@webrtc.org  // break the audio frame into blocks such that each block could be processed
8473f39c00d9875d7e09062725757b789f4da375ef9turaj@webrtc.org  // by VAD & CN/DTX. If a frame is divided into two blocks then there are two
8483f39c00d9875d7e09062725757b789f4da375ef9turaj@webrtc.org  // cases. First, the first block is active, the second block will not be
8493f39c00d9875d7e09062725757b789f4da375ef9turaj@webrtc.org  // processed by CN/DTX but only by VAD and return to caller with
8503f39c00d9875d7e09062725757b789f4da375ef9turaj@webrtc.org  // '*samples_processed' set to zero. There, the audio frame will be encoded
8513f39c00d9875d7e09062725757b789f4da375ef9turaj@webrtc.org  // by the encoder. Second, the first block is inactive and is processed by
8523f39c00d9875d7e09062725757b789f4da375ef9turaj@webrtc.org  // CN/DTX, then we stop processing the next block and return to the caller
8533f39c00d9875d7e09062725757b789f4da375ef9turaj@webrtc.org  // which is EncodeSafe(), with "*samples_processed" equal to the number of
8543f39c00d9875d7e09062725757b789f4da375ef9turaj@webrtc.org  // samples in first block.
8553f39c00d9875d7e09062725757b789f4da375ef9turaj@webrtc.org  //
8563f39c00d9875d7e09062725757b789f4da375ef9turaj@webrtc.org  // Output:
8573f39c00d9875d7e09062725757b789f4da375ef9turaj@webrtc.org  //   -bitstream          : pointer to a buffer where DTX frame, if
8583f39c00d9875d7e09062725757b789f4da375ef9turaj@webrtc.org  //                         generated, will be written to.
8593f39c00d9875d7e09062725757b789f4da375ef9turaj@webrtc.org  //   -bitstream_len_byte : contains the length of bit-stream in bytes, if
8603f39c00d9875d7e09062725757b789f4da375ef9turaj@webrtc.org  //                         generated. Zero if no bit-stream is generated.
8613f39c00d9875d7e09062725757b789f4da375ef9turaj@webrtc.org  //   -samples_processed  : contains no of samples that actually CN has
8623f39c00d9875d7e09062725757b789f4da375ef9turaj@webrtc.org  //                         processed. Those samples processed by CN will not
8633f39c00d9875d7e09062725757b789f4da375ef9turaj@webrtc.org  //                         be encoded by the encoder, obviously. If
8643f39c00d9875d7e09062725757b789f4da375ef9turaj@webrtc.org  //                         contains zero, it means that the frame has been
8653f39c00d9875d7e09062725757b789f4da375ef9turaj@webrtc.org  //                         identified as active by VAD. Note that
8663f39c00d9875d7e09062725757b789f4da375ef9turaj@webrtc.org  //                         "*samples_processed" might be non-zero but
8673f39c00d9875d7e09062725757b789f4da375ef9turaj@webrtc.org  //                         "*bitstream_len_byte" be zero.
8683f39c00d9875d7e09062725757b789f4da375ef9turaj@webrtc.org  //
8693f39c00d9875d7e09062725757b789f4da375ef9turaj@webrtc.org  // Return value:
8703f39c00d9875d7e09062725757b789f4da375ef9turaj@webrtc.org  //   -1 if failed,
8713f39c00d9875d7e09062725757b789f4da375ef9turaj@webrtc.org  //    0 if succeeded.
8723f39c00d9875d7e09062725757b789f4da375ef9turaj@webrtc.org  //
8733f39c00d9875d7e09062725757b789f4da375ef9turaj@webrtc.org  int16_t ProcessFrameVADDTX(uint8_t* bitstream,
8743f39c00d9875d7e09062725757b789f4da375ef9turaj@webrtc.org                             int16_t* bitstream_len_byte,
8750c145390636e0936dadd96d9c34087577e69d95ahenrik.lundin@webrtc.org                             int16_t* samples_processed)
8760c145390636e0936dadd96d9c34087577e69d95ahenrik.lundin@webrtc.org      EXCLUSIVE_LOCKS_REQUIRED(codec_wrapper_lock_);
8773f39c00d9875d7e09062725757b789f4da375ef9turaj@webrtc.org
8783f39c00d9875d7e09062725757b789f4da375ef9turaj@webrtc.org  ///////////////////////////////////////////////////////////////////////////
8793f39c00d9875d7e09062725757b789f4da375ef9turaj@webrtc.org  // CurrentRate()
8803f39c00d9875d7e09062725757b789f4da375ef9turaj@webrtc.org  // Call to get the current encoding rate of the encoder. This function
8813f39c00d9875d7e09062725757b789f4da375ef9turaj@webrtc.org  // should be overwritten for codecs which automatically change their
8823f39c00d9875d7e09062725757b789f4da375ef9turaj@webrtc.org  // target rate. One example is iSAC. The output of the function is the
8833f39c00d9875d7e09062725757b789f4da375ef9turaj@webrtc.org  // current target rate.
8843f39c00d9875d7e09062725757b789f4da375ef9turaj@webrtc.org  //
8853f39c00d9875d7e09062725757b789f4da375ef9turaj@webrtc.org  // Output:
8863f39c00d9875d7e09062725757b789f4da375ef9turaj@webrtc.org  //   -rate_bps           : the current target rate of the codec.
8873f39c00d9875d7e09062725757b789f4da375ef9turaj@webrtc.org  //
8883f39c00d9875d7e09062725757b789f4da375ef9turaj@webrtc.org  virtual void CurrentRate(int32_t* /* rate_bps */) {}
8893f39c00d9875d7e09062725757b789f4da375ef9turaj@webrtc.org
8903f39c00d9875d7e09062725757b789f4da375ef9turaj@webrtc.org  // &in_audio_[in_audio_ix_write_] always point to where new audio can be
8913f39c00d9875d7e09062725757b789f4da375ef9turaj@webrtc.org  // written to
89247b4b9d94cafb22e19bc8a6e6ca83b0568dcb973henrik.lundin@webrtc.org  int16_t in_audio_ix_write_ GUARDED_BY(codec_wrapper_lock_);
8933f39c00d9875d7e09062725757b789f4da375ef9turaj@webrtc.org
8943f39c00d9875d7e09062725757b789f4da375ef9turaj@webrtc.org  // &in_audio_[in_audio_ix_read_] points to where audio has to be read from
89547b4b9d94cafb22e19bc8a6e6ca83b0568dcb973henrik.lundin@webrtc.org  int16_t in_audio_ix_read_ GUARDED_BY(codec_wrapper_lock_);
8963f39c00d9875d7e09062725757b789f4da375ef9turaj@webrtc.org
89747b4b9d94cafb22e19bc8a6e6ca83b0568dcb973henrik.lundin@webrtc.org  int16_t in_timestamp_ix_write_ GUARDED_BY(codec_wrapper_lock_);
8983f39c00d9875d7e09062725757b789f4da375ef9turaj@webrtc.org
8993f39c00d9875d7e09062725757b789f4da375ef9turaj@webrtc.org  // Where the audio is stored before encoding,
9003f39c00d9875d7e09062725757b789f4da375ef9turaj@webrtc.org  // To save memory the following buffer can be allocated
9013f39c00d9875d7e09062725757b789f4da375ef9turaj@webrtc.org  // dynamically for 80 ms depending on the sampling frequency
9023f39c00d9875d7e09062725757b789f4da375ef9turaj@webrtc.org  // of the codec.
90347b4b9d94cafb22e19bc8a6e6ca83b0568dcb973henrik.lundin@webrtc.org  int16_t* in_audio_ GUARDED_BY(codec_wrapper_lock_);
90447b4b9d94cafb22e19bc8a6e6ca83b0568dcb973henrik.lundin@webrtc.org  uint32_t* in_timestamp_ GUARDED_BY(codec_wrapper_lock_);
9053f39c00d9875d7e09062725757b789f4da375ef9turaj@webrtc.org
90647b4b9d94cafb22e19bc8a6e6ca83b0568dcb973henrik.lundin@webrtc.org  int16_t frame_len_smpl_ GUARDED_BY(codec_wrapper_lock_);
90747b4b9d94cafb22e19bc8a6e6ca83b0568dcb973henrik.lundin@webrtc.org  uint16_t num_channels_ GUARDED_BY(codec_wrapper_lock_);
9083f39c00d9875d7e09062725757b789f4da375ef9turaj@webrtc.org
9093f39c00d9875d7e09062725757b789f4da375ef9turaj@webrtc.org  // This will point to a static database of the supported codecs
91047b4b9d94cafb22e19bc8a6e6ca83b0568dcb973henrik.lundin@webrtc.org  int16_t codec_id_ GUARDED_BY(codec_wrapper_lock_);
9113f39c00d9875d7e09062725757b789f4da375ef9turaj@webrtc.org
9123f39c00d9875d7e09062725757b789f4da375ef9turaj@webrtc.org  // This will account for the number of samples  were not encoded
9133f39c00d9875d7e09062725757b789f4da375ef9turaj@webrtc.org  // the case is rare, either samples are missed due to overwrite
9143f39c00d9875d7e09062725757b789f4da375ef9turaj@webrtc.org  // at input buffer or due to encoding error
91547b4b9d94cafb22e19bc8a6e6ca83b0568dcb973henrik.lundin@webrtc.org  uint32_t num_missed_samples_ GUARDED_BY(codec_wrapper_lock_);
9163f39c00d9875d7e09062725757b789f4da375ef9turaj@webrtc.org
9173f39c00d9875d7e09062725757b789f4da375ef9turaj@webrtc.org  // True if the encoder instance created
91847b4b9d94cafb22e19bc8a6e6ca83b0568dcb973henrik.lundin@webrtc.org  bool encoder_exist_ GUARDED_BY(codec_wrapper_lock_);
9193f39c00d9875d7e09062725757b789f4da375ef9turaj@webrtc.org
9203f39c00d9875d7e09062725757b789f4da375ef9turaj@webrtc.org  // True if the encoder instance initialized
92147b4b9d94cafb22e19bc8a6e6ca83b0568dcb973henrik.lundin@webrtc.org  bool encoder_initialized_ GUARDED_BY(codec_wrapper_lock_);
9223f39c00d9875d7e09062725757b789f4da375ef9turaj@webrtc.org
92347b4b9d94cafb22e19bc8a6e6ca83b0568dcb973henrik.lundin@webrtc.org  const bool registered_in_neteq_
92447b4b9d94cafb22e19bc8a6e6ca83b0568dcb973henrik.lundin@webrtc.org      GUARDED_BY(codec_wrapper_lock_);  // TODO(henrik.lundin) Remove?
9253f39c00d9875d7e09062725757b789f4da375ef9turaj@webrtc.org
9263f39c00d9875d7e09062725757b789f4da375ef9turaj@webrtc.org  // VAD/DTX
92747b4b9d94cafb22e19bc8a6e6ca83b0568dcb973henrik.lundin@webrtc.org  bool has_internal_dtx_ GUARDED_BY(codec_wrapper_lock_);
9280c145390636e0936dadd96d9c34087577e69d95ahenrik.lundin@webrtc.org  WebRtcVadInst* ptr_vad_inst_ GUARDED_BY(codec_wrapper_lock_);
9290c145390636e0936dadd96d9c34087577e69d95ahenrik.lundin@webrtc.org  bool vad_enabled_ GUARDED_BY(codec_wrapper_lock_);
9300c145390636e0936dadd96d9c34087577e69d95ahenrik.lundin@webrtc.org  ACMVADMode vad_mode_ GUARDED_BY(codec_wrapper_lock_);
9310c145390636e0936dadd96d9c34087577e69d95ahenrik.lundin@webrtc.org  int16_t vad_label_[MAX_FRAME_SIZE_10MSEC] GUARDED_BY(codec_wrapper_lock_);
9320c145390636e0936dadd96d9c34087577e69d95ahenrik.lundin@webrtc.org  bool dtx_enabled_ GUARDED_BY(codec_wrapper_lock_);
9330c145390636e0936dadd96d9c34087577e69d95ahenrik.lundin@webrtc.org  WebRtcCngEncInst* ptr_dtx_inst_ GUARDED_BY(codec_wrapper_lock_);
9340c145390636e0936dadd96d9c34087577e69d95ahenrik.lundin@webrtc.org  uint8_t num_lpc_params_               // TODO(henrik.lundin) Delete and
9350c145390636e0936dadd96d9c34087577e69d95ahenrik.lundin@webrtc.org      GUARDED_BY(codec_wrapper_lock_);  // replace with kNewCNGNumLPCParams.
9360c145390636e0936dadd96d9c34087577e69d95ahenrik.lundin@webrtc.org  bool sent_cn_previous_ GUARDED_BY(codec_wrapper_lock_);
9370c145390636e0936dadd96d9c34087577e69d95ahenrik.lundin@webrtc.org  int16_t prev_frame_cng_ GUARDED_BY(codec_wrapper_lock_);
9383f39c00d9875d7e09062725757b789f4da375ef9turaj@webrtc.org
93991c0a2592faf1e68f658c98e5faa1acef7124d1aminyue@webrtc.org  // FEC.
94047b4b9d94cafb22e19bc8a6e6ca83b0568dcb973henrik.lundin@webrtc.org  bool has_internal_fec_ GUARDED_BY(codec_wrapper_lock_);
94191c0a2592faf1e68f658c98e5faa1acef7124d1aminyue@webrtc.org
94247b4b9d94cafb22e19bc8a6e6ca83b0568dcb973henrik.lundin@webrtc.org  WebRtcACMCodecParams encoder_params_ GUARDED_BY(codec_wrapper_lock_);
9433f39c00d9875d7e09062725757b789f4da375ef9turaj@webrtc.org
9443f39c00d9875d7e09062725757b789f4da375ef9turaj@webrtc.org  // Used to lock wrapper internal data
9453f39c00d9875d7e09062725757b789f4da375ef9turaj@webrtc.org  // such as buffers and state variables.
9463f39c00d9875d7e09062725757b789f4da375ef9turaj@webrtc.org  RWLockWrapper& codec_wrapper_lock_;
9473f39c00d9875d7e09062725757b789f4da375ef9turaj@webrtc.org
9480c145390636e0936dadd96d9c34087577e69d95ahenrik.lundin@webrtc.org  uint32_t last_timestamp_ GUARDED_BY(codec_wrapper_lock_);
9493f39c00d9875d7e09062725757b789f4da375ef9turaj@webrtc.org  uint32_t unique_id_;
9503f39c00d9875d7e09062725757b789f4da375ef9turaj@webrtc.org};
9513f39c00d9875d7e09062725757b789f4da375ef9turaj@webrtc.org
9520a1c75a50d10621f70d5921c5b8b9c0eb144bb42turaj@webrtc.org}  // namespace acm2
9530a1c75a50d10621f70d5921c5b8b9c0eb144bb42turaj@webrtc.org
9543f39c00d9875d7e09062725757b789f4da375ef9turaj@webrtc.org}  // namespace webrtc
9553f39c00d9875d7e09062725757b789f4da375ef9turaj@webrtc.org
956ed0b4fb2f28fa291e726fc1cf6852611f2176392turaj@webrtc.org#endif  // WEBRTC_MODULES_AUDIO_CODING_MAIN_ACM2_ACM_GENERIC_CODEC_H_
957