Reformatting ACM. All changes are bit-exact in this CL.
TEST=VoE auto-test, audio_coding_module_test;
only 15 ms of teststereo_out_1.pcm is not bit-exact with output file of the head revision
Review URL: https://webrtc-codereview.appspot.com/937035
git-svn-id: http://webrtc.googlecode.com/svn/trunk/webrtc@3287 4adac7df-926f-26a2-2b94-8c16560cd09d
diff --git a/modules/audio_coding/main/source/acm_generic_codec.cc b/modules/audio_coding/main/source/acm_generic_codec.cc
index c39edcd..7d84658 100644
--- a/modules/audio_coding/main/source/acm_generic_codec.cc
+++ b/modules/audio_coding/main/source/acm_generic_codec.cc
@@ -8,16 +8,17 @@
* be found in the AUTHORS file in the root of the source tree.
*/
+#include "webrtc/modules/audio_coding/main/source/acm_generic_codec.h"
+
#include <assert.h>
#include <string.h>
-#include "acm_codec_database.h"
-#include "acm_common_defs.h"
-#include "acm_generic_codec.h"
-#include "acm_neteq.h"
-#include "trace.h"
-#include "webrtc_vad.h"
-#include "webrtc_cng.h"
+#include "webrtc/common_audio/vad/include/webrtc_vad.h"
+#include "webrtc/modules/audio_coding/codecs/cng/include/webrtc_cng.h"
+#include "webrtc/modules/audio_coding/main/source/acm_codec_database.h"
+#include "webrtc/modules/audio_coding/main/source/acm_common_defs.h"
+#include "webrtc/modules/audio_coding/main/source/acm_neteq.h"
+#include "webrtc/system_wrappers/interface/trace.h"
namespace webrtc {
@@ -36,285 +37,289 @@
// if a proper initialization has happened. Another approach is
// to initialize to a default codec that we are sure is always included.
ACMGenericCodec::ACMGenericCodec()
- : _inAudioIxWrite(0),
- _inAudioIxRead(0),
- _inTimestampIxWrite(0),
- _inAudio(NULL),
- _inTimestamp(NULL),
- _frameLenSmpl(-1), // invalid value
- _noChannels(1),
- _codecID(-1), // invalid value
- _noMissedSamples(0),
- _encoderExist(false),
- _decoderExist(false),
- _encoderInitialized(false),
- _decoderInitialized(false),
- _registeredInNetEq(false),
- _hasInternalDTX(false),
- _ptrVADInst(NULL),
- _vadEnabled(false),
- _vadMode(VADNormal),
- _dtxEnabled(false),
- _ptrDTXInst(NULL),
- _numLPCParams(kNewCNGNumPLCParams),
- _sentCNPrevious(false),
- _isMaster(true),
- _prev_frame_cng(0),
- _netEqDecodeLock(NULL),
- _codecWrapperLock(*RWLockWrapper::CreateRWLock()),
- _lastEncodedTimestamp(0),
- _lastTimestamp(0xD87F3F9F),
- _isAudioBuffFresh(true),
- _uniqueID(0) {
+ : in_audio_ix_write_(0),
+ in_audio_ix_read_(0),
+ in_timestamp_ix_write_(0),
+ in_audio_(NULL),
+ in_timestamp_(NULL),
+ frame_len_smpl_(-1), // invalid value
+ num_channels_(1),
+ codec_id_(-1), // invalid value
+ num_missed_samples_(0),
+ encoder_exist_(false),
+ decoder_exist_(false),
+ encoder_initialized_(false),
+ decoder_initialized_(false),
+ registered_in_neteq_(false),
+ has_internal_dtx_(false),
+ ptr_vad_inst_(NULL),
+ vad_enabled_(false),
+ vad_mode_(VADNormal),
+ dtx_enabled_(false),
+ ptr_dtx_inst_(NULL),
+ num_lpc_params_(kNewCNGNumPLCParams),
+ sent_cn_previous_(false),
+ is_master_(true),
+ prev_frame_cng_(0),
+ neteq_decode_lock_(NULL),
+ codec_wrapper_lock_(*RWLockWrapper::CreateRWLock()),
+ last_encoded_timestamp_(0),
+ last_timestamp_(0xD87F3F9F),
+ is_audio_buff_fresh_(true),
+ unique_id_(0) {
// Initialize VAD vector.
for (int i = 0; i < MAX_FRAME_SIZE_10MSEC; i++) {
- _vadLabel[i] = 0;
+ vad_label_[i] = 0;
}
// Nullify memory for encoder and decoder, and set payload type to an
// invalid value.
- memset(&_encoderParams, 0, sizeof(WebRtcACMCodecParams));
- _encoderParams.codecInstant.pltype = -1;
- memset(&_decoderParams, 0, sizeof(WebRtcACMCodecParams));
- _decoderParams.codecInstant.pltype = -1;
+ memset(&encoder_params_, 0, sizeof(WebRtcACMCodecParams));
+ encoder_params_.codec_inst.pltype = -1;
+ memset(&decoder_params_, 0, sizeof(WebRtcACMCodecParams));
+ decoder_params_.codec_inst.pltype = -1;
}
ACMGenericCodec::~ACMGenericCodec() {
// Check all the members which are pointers, and if they are not NULL
// delete/free them.
- if (_ptrVADInst != NULL) {
- WebRtcVad_Free(_ptrVADInst);
- _ptrVADInst = NULL;
+ if (ptr_vad_inst_ != NULL) {
+ WebRtcVad_Free(ptr_vad_inst_);
+ ptr_vad_inst_ = NULL;
}
- if (_inAudio != NULL) {
- delete[] _inAudio;
- _inAudio = NULL;
+ if (in_audio_ != NULL) {
+ delete[] in_audio_;
+ in_audio_ = NULL;
}
- if (_inTimestamp != NULL) {
- delete[] _inTimestamp;
- _inTimestamp = NULL;
+ if (in_timestamp_ != NULL) {
+ delete[] in_timestamp_;
+ in_timestamp_ = NULL;
}
- if (_ptrDTXInst != NULL) {
- WebRtcCng_FreeEnc(_ptrDTXInst);
- _ptrDTXInst = NULL;
+ if (ptr_dtx_inst_ != NULL) {
+ WebRtcCng_FreeEnc(ptr_dtx_inst_);
+ ptr_dtx_inst_ = NULL;
}
- delete &_codecWrapperLock;
+ delete &codec_wrapper_lock_;
}
int32_t ACMGenericCodec::Add10MsData(const uint32_t timestamp,
const int16_t* data,
- const uint16_t lengthSmpl,
- const uint8_t audioChannel) {
- WriteLockScoped wl(_codecWrapperLock);
- return Add10MsDataSafe(timestamp, data, lengthSmpl, audioChannel);
+ const uint16_t length_smpl,
+ const uint8_t audio_channel) {
+ WriteLockScoped wl(codec_wrapper_lock_);
+ return Add10MsDataSafe(timestamp, data, length_smpl, audio_channel);
}
int32_t ACMGenericCodec::Add10MsDataSafe(const uint32_t timestamp,
const int16_t* data,
- const uint16_t lengthSmpl,
- const uint8_t audioChannel) {
+ const uint16_t length_smpl,
+ const uint8_t audio_channel) {
// The codec expects to get data in correct sampling rate. Get the sampling
// frequency of the codec.
- uint16_t plFreqHz;
- if (EncoderSampFreq(plFreqHz) < 0) {
- // _codecID is not correct, perhaps the codec is not initialized yet.
+ uint16_t plfreq_hz;
+ if (EncoderSampFreq(plfreq_hz) < 0) {
return -1;
}
// Sanity check to make sure the length of the input corresponds to 10 ms.
- if ((plFreqHz / 100) != lengthSmpl) {
+ if ((plfreq_hz / 100) != length_smpl) {
// This is not 10 ms of audio, given the sampling frequency of the codec.
return -1;
}
- if (_lastTimestamp == timestamp) {
+ if (last_timestamp_ == timestamp) {
// Same timestamp as the last time, overwrite.
- if ((_inAudioIxWrite >= lengthSmpl * audioChannel) &&
- (_inTimestampIxWrite > 0)) {
- _inAudioIxWrite -= lengthSmpl * audioChannel;
- _inTimestampIxWrite--;
- WEBRTC_TRACE(webrtc::kTraceDebug, webrtc::kTraceAudioCoding, _uniqueID,
- "Adding 10ms with previous timestamp, overwriting the previous 10ms");
+ if ((in_audio_ix_write_ >= length_smpl * audio_channel) &&
+ (in_timestamp_ix_write_ > 0)) {
+ in_audio_ix_write_ -= length_smpl * audio_channel;
+ in_timestamp_ix_write_--;
+ WEBRTC_TRACE(webrtc::kTraceDebug, webrtc::kTraceAudioCoding, unique_id_,
+ "Adding 10ms with previous timestamp, overwriting the "
+ "previous 10ms");
} else {
- WEBRTC_TRACE(webrtc::kTraceDebug, webrtc::kTraceAudioCoding, _uniqueID,
+ WEBRTC_TRACE(webrtc::kTraceDebug, webrtc::kTraceAudioCoding, unique_id_,
"Adding 10ms with previous timestamp, this will sound bad");
}
}
- _lastTimestamp = timestamp;
+ last_timestamp_ = timestamp;
// If the data exceeds the buffer size, we throw away the oldest data and
// add the newly received 10 msec at the end.
- if ((_inAudioIxWrite + lengthSmpl * audioChannel) > AUDIO_BUFFER_SIZE_W16) {
+ if ((in_audio_ix_write_ + length_smpl * audio_channel) >
+ AUDIO_BUFFER_SIZE_W16) {
// Get the number of samples to be overwritten.
- int16_t missedSamples = _inAudioIxWrite + lengthSmpl * audioChannel -
+ int16_t missed_samples = in_audio_ix_write_ + length_smpl * audio_channel -
AUDIO_BUFFER_SIZE_W16;
// Move the data (overwrite the old data).
- memmove(_inAudio, _inAudio + missedSamples,
- (AUDIO_BUFFER_SIZE_W16 - lengthSmpl * audioChannel) *
+ memmove(in_audio_, in_audio_ + missed_samples,
+ (AUDIO_BUFFER_SIZE_W16 - length_smpl * audio_channel) *
sizeof(int16_t));
// Copy the new data.
- memcpy(_inAudio + (AUDIO_BUFFER_SIZE_W16 - lengthSmpl * audioChannel), data,
- lengthSmpl * audioChannel * sizeof(int16_t));
+ memcpy(in_audio_ + (AUDIO_BUFFER_SIZE_W16 - length_smpl * audio_channel),
+ data, length_smpl * audio_channel * sizeof(int16_t));
// Get the number of 10 ms blocks which are overwritten.
- int16_t missed10MsecBlocks =static_cast<int16_t>(
- (missedSamples / audioChannel * 100) / plFreqHz);
+ int16_t missed_10ms_blocks =static_cast<int16_t>(
+ (missed_samples / audio_channel * 100) / plfreq_hz);
// Move the timestamps.
- memmove(_inTimestamp, _inTimestamp + missed10MsecBlocks,
- (_inTimestampIxWrite - missed10MsecBlocks) * sizeof(uint32_t));
- _inTimestampIxWrite -= missed10MsecBlocks;
- _inTimestamp[_inTimestampIxWrite] = timestamp;
- _inTimestampIxWrite++;
+ memmove(in_timestamp_, in_timestamp_ + missed_10ms_blocks,
+ (in_timestamp_ix_write_ - missed_10ms_blocks) * sizeof(uint32_t));
+ in_timestamp_ix_write_ -= missed_10ms_blocks;
+ in_timestamp_[in_timestamp_ix_write_] = timestamp;
+ in_timestamp_ix_write_++;
// Buffer is full.
- _inAudioIxWrite = AUDIO_BUFFER_SIZE_W16;
- IncreaseNoMissedSamples(missedSamples);
- _isAudioBuffFresh = false;
- return -missedSamples;
+ in_audio_ix_write_ = AUDIO_BUFFER_SIZE_W16;
+ IncreaseNoMissedSamples(missed_samples);
+ is_audio_buff_fresh_ = false;
+ return -missed_samples;
}
// Store the input data in our data buffer.
- memcpy(_inAudio + _inAudioIxWrite, data,
- lengthSmpl * audioChannel * sizeof(int16_t));
- _inAudioIxWrite += lengthSmpl * audioChannel;
+ memcpy(in_audio_ + in_audio_ix_write_, data,
+ length_smpl * audio_channel * sizeof(int16_t));
+ in_audio_ix_write_ += length_smpl * audio_channel;
- assert(_inTimestampIxWrite < TIMESTAMP_BUFFER_SIZE_W32);
- assert(_inTimestampIxWrite >= 0);
+ assert(in_timestamp_ix_write_ < TIMESTAMP_BUFFER_SIZE_W32);
+ assert(in_timestamp_ix_write_ >= 0);
- _inTimestamp[_inTimestampIxWrite] = timestamp;
- _inTimestampIxWrite++;
- _isAudioBuffFresh = false;
+ in_timestamp_[in_timestamp_ix_write_] = timestamp;
+ in_timestamp_ix_write_++;
+ is_audio_buff_fresh_ = false;
return 0;
}
bool ACMGenericCodec::HasFrameToEncode() const {
- ReadLockScoped lockCodec(_codecWrapperLock);
- if (_inAudioIxWrite < _frameLenSmpl * _noChannels)
+ ReadLockScoped lockCodec(codec_wrapper_lock_);
+ if (in_audio_ix_write_ < frame_len_smpl_ * num_channels_)
return false;
return true;
}
-int16_t ACMGenericCodec::Encode(uint8_t* bitStream,
- int16_t* bitStreamLenByte,
- uint32_t* timeStamp,
- WebRtcACMEncodingType* encodingType) {
+int16_t ACMGenericCodec::Encode(uint8_t* bitstream,
+ int16_t* bitstream_len_byte,
+ uint32_t* timestamp,
+ WebRtcACMEncodingType* encoding_type) {
if (!HasFrameToEncode()) {
// There is not enough audio
- *timeStamp = 0;
- *bitStreamLenByte = 0;
+ *timestamp = 0;
+ *bitstream_len_byte = 0;
// Doesn't really matter what this parameter set to
- *encodingType = kNoEncoding;
+ *encoding_type = kNoEncoding;
return 0;
}
- WriteLockScoped lockCodec(_codecWrapperLock);
- ReadLockScoped lockNetEq(*_netEqDecodeLock);
+ WriteLockScoped lockCodec(codec_wrapper_lock_);
+ ReadLockScoped lockNetEq(*neteq_decode_lock_);
// Not all codecs accept the whole frame to be pushed into encoder at once.
// Some codecs needs to be feed with a specific number of samples different
// from the frame size. If this is the case, |myBasicCodingBlockSmpl| will
// report a number different from 0, and we will loop over calls to encoder
// further down, until we have encode a complete frame.
- const int16_t myBasicCodingBlockSmpl = ACMCodecDB::BasicCodingBlock(_codecID);
- if (myBasicCodingBlockSmpl < 0 || !_encoderInitialized || !_encoderExist) {
+ const int16_t my_basic_coding_block_smpl =
+ ACMCodecDB::BasicCodingBlock(codec_id_);
+ if (my_basic_coding_block_smpl < 0 || !encoder_initialized_ ||
+ !encoder_exist_) {
// This should not happen, but in case it does, report no encoding done.
- *timeStamp = 0;
- *bitStreamLenByte = 0;
- *encodingType = kNoEncoding;
- WEBRTC_TRACE(webrtc::kTraceError, webrtc::kTraceAudioCoding, _uniqueID,
+ *timestamp = 0;
+ *bitstream_len_byte = 0;
+ *encoding_type = kNoEncoding;
+ WEBRTC_TRACE(webrtc::kTraceError, webrtc::kTraceAudioCoding, unique_id_,
"EncodeSafe: error, basic coding sample block is negative");
return -1;
}
// This makes the internal encoder read from the beginning of the buffer.
- _inAudioIxRead = 0;
- *timeStamp = _inTimestamp[0];
+ in_audio_ix_read_ = 0;
+ *timestamp = in_timestamp_[0];
- // Process the audio through VAD. The function will set |_vadLabels|.
- // If VAD is disabled all entries in |_vadLabels| are set to ONE (active).
+ // Process the audio through VAD. The function will set |_vad_labels|.
+ // If VAD is disabled all entries in |_vad_labels| are set to ONE (active).
int16_t status = 0;
- int16_t dtxProcessedSamples = 0;
- status = ProcessFrameVADDTX(bitStream, bitStreamLenByte,
- &dtxProcessedSamples);
+ int16_t dtx_processed_samples = 0;
+ status = ProcessFrameVADDTX(bitstream, bitstream_len_byte,
+ &dtx_processed_samples);
if (status < 0) {
- *timeStamp = 0;
- *bitStreamLenByte = 0;
- *encodingType = kNoEncoding;
+ *timestamp = 0;
+ *bitstream_len_byte = 0;
+ *encoding_type = kNoEncoding;
} else {
- if (dtxProcessedSamples > 0) {
+ if (dtx_processed_samples > 0) {
// Dtx have processed some samples, and even if a bit-stream is generated
// we should not do any encoding (normally there won't be enough data).
// Setting the following makes sure that the move of audio data and
// timestamps done correctly.
- _inAudioIxRead = dtxProcessedSamples;
+ in_audio_ix_read_ = dtx_processed_samples;
// This will let the owner of ACMGenericCodec to know that the
// generated bit-stream is DTX to use correct payload type.
- uint16_t sampFreqHz;
- EncoderSampFreq(sampFreqHz);
- if (sampFreqHz == 8000) {
- *encodingType = kPassiveDTXNB;
- } else if (sampFreqHz == 16000) {
- *encodingType = kPassiveDTXWB;
- } else if (sampFreqHz == 32000) {
- *encodingType = kPassiveDTXSWB;
- } else if (sampFreqHz == 48000) {
- *encodingType = kPassiveDTXFB;
+ uint16_t samp_freq_hz;
+ EncoderSampFreq(samp_freq_hz);
+ if (samp_freq_hz == 8000) {
+ *encoding_type = kPassiveDTXNB;
+ } else if (samp_freq_hz == 16000) {
+ *encoding_type = kPassiveDTXWB;
+ } else if (samp_freq_hz == 32000) {
+ *encoding_type = kPassiveDTXSWB;
+ } else if (samp_freq_hz == 48000) {
+ *encoding_type = kPassiveDTXFB;
} else {
status = -1;
- WEBRTC_TRACE(webrtc::kTraceError, webrtc::kTraceAudioCoding, _uniqueID,
+ WEBRTC_TRACE(webrtc::kTraceError, webrtc::kTraceAudioCoding, unique_id_,
"EncodeSafe: Wrong sampling frequency for DTX.");
}
// Transport empty frame if we have an empty bitstream.
- if ((*bitStreamLenByte == 0) &&
- (_sentCNPrevious || ((_inAudioIxWrite - _inAudioIxRead) <= 0))) {
+ if ((*bitstream_len_byte == 0) &&
+ (sent_cn_previous_ ||
+ ((in_audio_ix_write_ - in_audio_ix_read_) <= 0))) {
// Makes sure we transmit an empty frame.
- *bitStreamLenByte = 1;
- *encodingType = kNoEncoding;
+ *bitstream_len_byte = 1;
+ *encoding_type = kNoEncoding;
}
- _sentCNPrevious = true;
+ sent_cn_previous_ = true;
} else {
// We should encode the audio frame. Either VAD and/or DTX is off, or the
// audio was considered "active".
- _sentCNPrevious = false;
- if (myBasicCodingBlockSmpl == 0) {
+ sent_cn_previous_ = false;
+ if (my_basic_coding_block_smpl == 0) {
// This codec can handle all allowed frame sizes as basic coding block.
- status = InternalEncode(bitStream, bitStreamLenByte);
+ status = InternalEncode(bitstream, bitstream_len_byte);
if (status < 0) {
// TODO(tlegrand): Maybe reseting the encoder to be fresh for the next
// frame.
WEBRTC_TRACE(webrtc::kTraceError, webrtc::kTraceAudioCoding,
- _uniqueID, "EncodeSafe: error in internalEncode");
- *bitStreamLenByte = 0;
- *encodingType = kNoEncoding;
+ unique_id_, "EncodeSafe: error in internal_encode");
+ *bitstream_len_byte = 0;
+ *encoding_type = kNoEncoding;
}
} else {
// A basic-coding-block for this codec is defined so we loop over the
// audio with the steps of the basic-coding-block.
- int16_t tmpBitStreamLenByte;
+ int16_t tmp_bitstream_len_byte;
// Reset the variables which will be incremented in the loop.
- *bitStreamLenByte = 0;
+ *bitstream_len_byte = 0;
bool done = false;
while (!done) {
- status = InternalEncode(&bitStream[*bitStreamLenByte],
- &tmpBitStreamLenByte);
- *bitStreamLenByte += tmpBitStreamLenByte;
+ status = InternalEncode(&bitstream[*bitstream_len_byte],
+ &tmp_bitstream_len_byte);
+ *bitstream_len_byte += tmp_bitstream_len_byte;
// Guard Against errors and too large payloads.
- if ((status < 0) || (*bitStreamLenByte > MAX_PAYLOAD_SIZE_BYTE)) {
+ if ((status < 0) || (*bitstream_len_byte > MAX_PAYLOAD_SIZE_BYTE)) {
// Error has happened, and even if we are in the middle of a full
// frame we have to exit. Before exiting, whatever bits are in the
// buffer are probably corrupted, so we ignore them.
- *bitStreamLenByte = 0;
- *encodingType = kNoEncoding;
+ *bitstream_len_byte = 0;
+ *encoding_type = kNoEncoding;
// We might have come here because of the second condition.
status = -1;
WEBRTC_TRACE(webrtc::kTraceError, webrtc::kTraceAudioCoding,
- _uniqueID, "EncodeSafe: error in InternalEncode");
+ unique_id_, "EncodeSafe: error in InternalEncode");
// break from the loop
break;
}
@@ -322,18 +327,18 @@
// TODO(andrew): This should be multiplied by the number of
// channels, right?
// http://code.google.com/p/webrtc/issues/detail?id=714
- done = _inAudioIxRead >= _frameLenSmpl;
+ done = in_audio_ix_read_ >= frame_len_smpl_;
}
}
if (status >= 0) {
- *encodingType = (_vadLabel[0] == 1) ? kActiveNormalEncoded :
+ *encoding_type = (vad_label_[0] == 1) ? kActiveNormalEncoded :
kPassiveNormalEncoded;
// Transport empty frame if we have an empty bitstream.
- if ((*bitStreamLenByte == 0) &&
- ((_inAudioIxWrite - _inAudioIxRead) <= 0)) {
+ if ((*bitstream_len_byte == 0) &&
+ ((in_audio_ix_write_ - in_audio_ix_read_) <= 0)) {
// Makes sure we transmit an empty frame.
- *bitStreamLenByte = 1;
- *encodingType = kNoEncoding;
+ *bitstream_len_byte = 1;
+ *encoding_type = kNoEncoding;
}
}
}
@@ -341,148 +346,148 @@
// Move the timestamp buffer according to the number of 10 ms blocks
// which are read.
- uint16_t sampFreqHz;
- EncoderSampFreq(sampFreqHz);
- int16_t num10MsecBlocks = static_cast<int16_t>(
- (_inAudioIxRead / _noChannels * 100) / sampFreqHz);
- if (_inTimestampIxWrite > num10MsecBlocks) {
- memmove(_inTimestamp, _inTimestamp + num10MsecBlocks,
- (_inTimestampIxWrite - num10MsecBlocks) * sizeof(int32_t));
+ uint16_t samp_freq_hz;
+ EncoderSampFreq(samp_freq_hz);
+ int16_t num_10ms_blocks = static_cast<int16_t>(
+ (in_audio_ix_read_ / num_channels_ * 100) / samp_freq_hz);
+ if (in_timestamp_ix_write_ > num_10ms_blocks) {
+ memmove(in_timestamp_, in_timestamp_ + num_10ms_blocks,
+ (in_timestamp_ix_write_ - num_10ms_blocks) * sizeof(int32_t));
}
- _inTimestampIxWrite -= num10MsecBlocks;
+ in_timestamp_ix_write_ -= num_10ms_blocks;
// Remove encoded audio and move next audio to be encoded to the beginning
// of the buffer. Accordingly, adjust the read and write indices.
- if (_inAudioIxRead < _inAudioIxWrite) {
- memmove(_inAudio, &_inAudio[_inAudioIxRead],
- (_inAudioIxWrite - _inAudioIxRead) * sizeof(int16_t));
+ if (in_audio_ix_read_ < in_audio_ix_write_) {
+ memmove(in_audio_, &in_audio_[in_audio_ix_read_],
+ (in_audio_ix_write_ - in_audio_ix_read_) * sizeof(int16_t));
}
- _inAudioIxWrite -= _inAudioIxRead;
- _inAudioIxRead = 0;
- _lastEncodedTimestamp = *timeStamp;
- return (status < 0) ? (-1) : (*bitStreamLenByte);
+ in_audio_ix_write_ -= in_audio_ix_read_;
+ in_audio_ix_read_ = 0;
+ last_encoded_timestamp_ = *timestamp;
+ return (status < 0) ? (-1) : (*bitstream_len_byte);
}
-int16_t ACMGenericCodec::Decode(uint8_t* bitStream,
- int16_t bitStreamLenByte,
+int16_t ACMGenericCodec::Decode(uint8_t* bitstream,
+ int16_t bitstream_len_byte,
int16_t* audio,
- int16_t* audioSamples,
- int8_t* speechType) {
- WriteLockScoped wl(_codecWrapperLock);
- return DecodeSafe(bitStream, bitStreamLenByte, audio, audioSamples,
- speechType);
+ int16_t* audio_samples,
+ int8_t* speech_type) {
+ WriteLockScoped wl(codec_wrapper_lock_);
+ return DecodeSafe(bitstream, bitstream_len_byte, audio, audio_samples,
+ speech_type);
}
bool ACMGenericCodec::EncoderInitialized() {
- ReadLockScoped rl(_codecWrapperLock);
- return _encoderInitialized;
+ ReadLockScoped rl(codec_wrapper_lock_);
+ return encoder_initialized_;
}
bool ACMGenericCodec::DecoderInitialized() {
- ReadLockScoped rl(_codecWrapperLock);
- return _decoderInitialized;
+ ReadLockScoped rl(codec_wrapper_lock_);
+ return decoder_initialized_;
}
-int32_t ACMGenericCodec::RegisterInNetEq(ACMNetEQ* netEq,
- const CodecInst& codecInst) {
- WebRtcNetEQ_CodecDef codecDef;
- WriteLockScoped wl(_codecWrapperLock);
+int32_t ACMGenericCodec::RegisterInNetEq(ACMNetEQ* neteq,
+ const CodecInst& codec_inst) {
+ WebRtcNetEQ_CodecDef codec_def;
+ WriteLockScoped wl(codec_wrapper_lock_);
- if (CodecDef(codecDef, codecInst) < 0) {
+ if (CodecDef(codec_def, codec_inst) < 0) {
// Failed to register the decoder.
- WEBRTC_TRACE(webrtc::kTraceError, webrtc::kTraceAudioCoding, _uniqueID,
+ WEBRTC_TRACE(webrtc::kTraceError, webrtc::kTraceAudioCoding, unique_id_,
"RegisterInNetEq: error, failed to register");
- _registeredInNetEq = false;
+ registered_in_neteq_ = false;
return -1;
} else {
- if (netEq->AddCodec(&codecDef, _isMaster) < 0) {
- WEBRTC_TRACE(webrtc::kTraceError, webrtc::kTraceAudioCoding, _uniqueID,
+ if (neteq->AddCodec(&codec_def, is_master_) < 0) {
+ WEBRTC_TRACE(webrtc::kTraceError, webrtc::kTraceAudioCoding, unique_id_,
"RegisterInNetEq: error, failed to add codec");
- _registeredInNetEq = false;
+ registered_in_neteq_ = false;
return -1;
}
// Succeeded registering the decoder.
- _registeredInNetEq = true;
+ registered_in_neteq_ = true;
return 0;
}
}
-int16_t ACMGenericCodec::EncoderParams(WebRtcACMCodecParams* encParams) {
- ReadLockScoped rl(_codecWrapperLock);
- return EncoderParamsSafe(encParams);
+int16_t ACMGenericCodec::EncoderParams(WebRtcACMCodecParams* enc_params) {
+ ReadLockScoped rl(codec_wrapper_lock_);
+ return EncoderParamsSafe(enc_params);
}
-int16_t ACMGenericCodec::EncoderParamsSafe(WebRtcACMCodecParams* encParams) {
+int16_t ACMGenericCodec::EncoderParamsSafe(WebRtcACMCodecParams* enc_params) {
// Codec parameters are valid only if the encoder is initialized.
- if (_encoderInitialized) {
- int32_t currentRate;
- memcpy(encParams, &_encoderParams, sizeof(WebRtcACMCodecParams));
- currentRate = encParams->codecInstant.rate;
- CurrentRate(currentRate);
- encParams->codecInstant.rate = currentRate;
+ if (encoder_initialized_) {
+ int32_t current_rate;
+ memcpy(enc_params, &encoder_params_, sizeof(WebRtcACMCodecParams));
+ current_rate = enc_params->codec_inst.rate;
+ CurrentRate(current_rate);
+ enc_params->codec_inst.rate = current_rate;
return 0;
} else {
- encParams->codecInstant.plname[0] = '\0';
- encParams->codecInstant.pltype = -1;
- encParams->codecInstant.pacsize = 0;
- encParams->codecInstant.rate = 0;
- WEBRTC_TRACE(webrtc::kTraceError, webrtc::kTraceAudioCoding, _uniqueID,
+ enc_params->codec_inst.plname[0] = '\0';
+ enc_params->codec_inst.pltype = -1;
+ enc_params->codec_inst.pacsize = 0;
+ enc_params->codec_inst.rate = 0;
+ WEBRTC_TRACE(webrtc::kTraceError, webrtc::kTraceAudioCoding, unique_id_,
"EncoderParamsSafe: error, encoder not initialized");
return -1;
}
}
-bool ACMGenericCodec::DecoderParams(WebRtcACMCodecParams* decParams,
- const uint8_t payloadType) {
- ReadLockScoped rl(_codecWrapperLock);
- return DecoderParamsSafe(decParams, payloadType);
+bool ACMGenericCodec::DecoderParams(WebRtcACMCodecParams* dec_params,
+ const uint8_t payload_type) {
+ ReadLockScoped rl(codec_wrapper_lock_);
+ return DecoderParamsSafe(dec_params, payload_type);
}
-bool ACMGenericCodec::DecoderParamsSafe(WebRtcACMCodecParams* decParams,
- const uint8_t payloadType) {
+bool ACMGenericCodec::DecoderParamsSafe(WebRtcACMCodecParams* dec_params,
+ const uint8_t payload_type) {
// Decoder parameters are valid only if decoder is initialized.
- if (_decoderInitialized) {
- if (payloadType == _decoderParams.codecInstant.pltype) {
- memcpy(decParams, &_decoderParams, sizeof(WebRtcACMCodecParams));
+ if (decoder_initialized_) {
+ if (payload_type == decoder_params_.codec_inst.pltype) {
+ memcpy(dec_params, &decoder_params_, sizeof(WebRtcACMCodecParams));
return true;
}
}
- decParams->codecInstant.plname[0] = '\0';
- decParams->codecInstant.pltype = -1;
- decParams->codecInstant.pacsize = 0;
- decParams->codecInstant.rate = 0;
+ dec_params->codec_inst.plname[0] = '\0';
+ dec_params->codec_inst.pltype = -1;
+ dec_params->codec_inst.pacsize = 0;
+ dec_params->codec_inst.rate = 0;
return false;
}
int16_t ACMGenericCodec::ResetEncoder() {
- WriteLockScoped lockCodec(_codecWrapperLock);
- ReadLockScoped lockNetEq(*_netEqDecodeLock);
+ WriteLockScoped lockCodec(codec_wrapper_lock_);
+ ReadLockScoped lockNetEq(*neteq_decode_lock_);
return ResetEncoderSafe();
}
int16_t ACMGenericCodec::ResetEncoderSafe() {
- if (!_encoderExist || !_encoderInitialized) {
+ if (!encoder_exist_ || !encoder_initialized_) {
// We don't reset if encoder doesn't exists or isn't initialized yet.
return 0;
}
- _inAudioIxWrite = 0;
- _inAudioIxRead = 0;
- _inTimestampIxWrite = 0;
- _noMissedSamples = 0;
- _isAudioBuffFresh = true;
- memset(_inAudio, 0, AUDIO_BUFFER_SIZE_W16 * sizeof(int16_t));
- memset(_inTimestamp, 0, TIMESTAMP_BUFFER_SIZE_W32 * sizeof(int32_t));
+ in_audio_ix_write_ = 0;
+ in_audio_ix_read_ = 0;
+ in_timestamp_ix_write_ = 0;
+ num_missed_samples_ = 0;
+ is_audio_buff_fresh_ = true;
+ memset(in_audio_, 0, AUDIO_BUFFER_SIZE_W16 * sizeof(int16_t));
+ memset(in_timestamp_, 0, TIMESTAMP_BUFFER_SIZE_W32 * sizeof(int32_t));
// Store DTX/VAD parameters.
- bool enableVAD = _vadEnabled;
- bool enableDTX = _dtxEnabled;
- ACMVADMode mode = _vadMode;
+ bool enable_vad = vad_enabled_;
+ bool enable_dtx = dtx_enabled_;
+ ACMVADMode mode = vad_mode_;
// Reset the encoder.
if (InternalResetEncoder() < 0) {
- WEBRTC_TRACE(webrtc::kTraceError, webrtc::kTraceAudioCoding, _uniqueID,
+ WEBRTC_TRACE(webrtc::kTraceError, webrtc::kTraceAudioCoding, unique_id_,
"ResetEncoderSafe: error in reset encoder");
return -1;
}
@@ -492,243 +497,245 @@
DisableVAD();
// Set DTX/VAD.
- return SetVADSafe(enableDTX, enableVAD, mode);
+ return SetVADSafe(enable_dtx, enable_vad, mode);
}
int16_t ACMGenericCodec::InternalResetEncoder() {
// Call the codecs internal encoder initialization/reset function.
- return InternalInitEncoder(&_encoderParams);
+ return InternalInitEncoder(&encoder_params_);
}
-int16_t ACMGenericCodec::InitEncoder(WebRtcACMCodecParams* codecParams,
- bool forceInitialization) {
- WriteLockScoped lockCodec(_codecWrapperLock);
- ReadLockScoped lockNetEq(*_netEqDecodeLock);
- return InitEncoderSafe(codecParams, forceInitialization);
+int16_t ACMGenericCodec::InitEncoder(WebRtcACMCodecParams* codec_params,
+ bool force_initialization) {
+ WriteLockScoped lockCodec(codec_wrapper_lock_);
+ ReadLockScoped lockNetEq(*neteq_decode_lock_);
+ return InitEncoderSafe(codec_params, force_initialization);
}
-int16_t ACMGenericCodec::InitEncoderSafe(WebRtcACMCodecParams* codecParams,
- bool forceInitialization) {
+int16_t ACMGenericCodec::InitEncoderSafe(WebRtcACMCodecParams* codec_params,
+ bool force_initialization) {
// Check if we got a valid set of parameters.
int mirrorID;
- int codecNumber = ACMCodecDB::CodecNumber(&(codecParams->codecInstant),
- &mirrorID);
- if (codecNumber < 0) {
- WEBRTC_TRACE(webrtc::kTraceError, webrtc::kTraceAudioCoding, _uniqueID,
+ int codec_number = ACMCodecDB::CodecNumber(&(codec_params->codec_inst),
+ &mirrorID);
+ if (codec_number < 0) {
+ WEBRTC_TRACE(webrtc::kTraceError, webrtc::kTraceAudioCoding, unique_id_,
"InitEncoderSafe: error, codec number negative");
return -1;
}
// Check if the parameters are for this codec.
- if ((_codecID >= 0) && (_codecID != codecNumber) && (_codecID != mirrorID)) {
- // The current codec is not the same as the one given by codecParams.
- WEBRTC_TRACE(webrtc::kTraceError, webrtc::kTraceAudioCoding, _uniqueID,
- "InitEncoderSafe: current codec is not the same as the one given by "
- "codecParams");
+ if ((codec_id_ >= 0) && (codec_id_ != codec_number) &&
+ (codec_id_ != mirrorID)) {
+ // The current codec is not the same as the one given by codec_params.
+ WEBRTC_TRACE(webrtc::kTraceError, webrtc::kTraceAudioCoding, unique_id_,
+ "InitEncoderSafe: current codec is not the same as the one "
+ "given by codec_params");
return -1;
}
- if (!CanChangeEncodingParam(codecParams->codecInstant)) {
- WEBRTC_TRACE(webrtc::kTraceError, webrtc::kTraceAudioCoding, _uniqueID,
+ if (!CanChangeEncodingParam(codec_params->codec_inst)) {
+ WEBRTC_TRACE(webrtc::kTraceError, webrtc::kTraceAudioCoding, unique_id_,
"InitEncoderSafe: cannot change encoding parameters");
return -1;
}
- if (_encoderInitialized && !forceInitialization) {
+ if (encoder_initialized_ && !force_initialization) {
// The encoder is already initialized, and we don't want to force
// initialization.
return 0;
}
int16_t status;
- if (!_encoderExist) {
+ if (!encoder_exist_) {
// New encoder, start with creating.
- _encoderInitialized = false;
+ encoder_initialized_ = false;
status = CreateEncoder();
if (status < 0) {
- WEBRTC_TRACE(webrtc::kTraceError, webrtc::kTraceAudioCoding, _uniqueID,
+ WEBRTC_TRACE(webrtc::kTraceError, webrtc::kTraceAudioCoding, unique_id_,
"InitEncoderSafe: cannot create encoder");
return -1;
} else {
- _encoderExist = true;
+ encoder_exist_ = true;
}
}
- _frameLenSmpl = (codecParams->codecInstant).pacsize;
- _noChannels = codecParams->codecInstant.channels;
- status = InternalInitEncoder(codecParams);
+ frame_len_smpl_ = (codec_params->codec_inst).pacsize;
+ num_channels_ = codec_params->codec_inst.channels;
+ status = InternalInitEncoder(codec_params);
if (status < 0) {
- WEBRTC_TRACE(webrtc::kTraceError, webrtc::kTraceAudioCoding, _uniqueID,
+ WEBRTC_TRACE(webrtc::kTraceError, webrtc::kTraceAudioCoding, unique_id_,
"InitEncoderSafe: error in init encoder");
- _encoderInitialized = false;
+ encoder_initialized_ = false;
return -1;
} else {
// Store encoder parameters.
- memcpy(&_encoderParams, codecParams, sizeof(WebRtcACMCodecParams));
- _encoderInitialized = true;
- if (_inAudio == NULL) {
- _inAudio = new int16_t[AUDIO_BUFFER_SIZE_W16];
- if (_inAudio == NULL) {
+ memcpy(&encoder_params_, codec_params, sizeof(WebRtcACMCodecParams));
+ encoder_initialized_ = true;
+ if (in_audio_ == NULL) {
+ in_audio_ = new int16_t[AUDIO_BUFFER_SIZE_W16];
+ if (in_audio_ == NULL) {
return -1;
}
- memset(_inAudio, 0, AUDIO_BUFFER_SIZE_W16 * sizeof(int16_t));
+ memset(in_audio_, 0, AUDIO_BUFFER_SIZE_W16 * sizeof(int16_t));
}
- if (_inTimestamp == NULL) {
- _inTimestamp = new uint32_t[TIMESTAMP_BUFFER_SIZE_W32];
- if (_inTimestamp == NULL) {
+ if (in_timestamp_ == NULL) {
+ in_timestamp_ = new uint32_t[TIMESTAMP_BUFFER_SIZE_W32];
+ if (in_timestamp_ == NULL) {
return -1;
}
- memset(_inTimestamp, 0, sizeof(uint32_t) * TIMESTAMP_BUFFER_SIZE_W32);
+ memset(in_timestamp_, 0, sizeof(uint32_t) * TIMESTAMP_BUFFER_SIZE_W32);
}
- _isAudioBuffFresh = true;
+ is_audio_buff_fresh_ = true;
}
- status = SetVADSafe(codecParams->enableDTX, codecParams->enableVAD,
- codecParams->vadMode);
+ status = SetVADSafe(codec_params->enable_dtx, codec_params->enable_vad,
+ codec_params->vad_mode);
return status;
}
// TODO(tlegrand): Remove the function CanChangeEncodingParam. Returns true
// for all codecs.
-bool ACMGenericCodec::CanChangeEncodingParam(CodecInst& /*codecInst*/) {
+bool ACMGenericCodec::CanChangeEncodingParam(CodecInst& /*codec_inst*/) {
return true;
}
-int16_t ACMGenericCodec::InitDecoder(WebRtcACMCodecParams* codecParams,
- bool forceInitialization) {
- WriteLockScoped lockCodc(_codecWrapperLock);
- WriteLockScoped lockNetEq(*_netEqDecodeLock);
- return InitDecoderSafe(codecParams, forceInitialization);
+int16_t ACMGenericCodec::InitDecoder(WebRtcACMCodecParams* codec_params,
+ bool force_initialization) {
+ WriteLockScoped lockCodc(codec_wrapper_lock_);
+ WriteLockScoped lockNetEq(*neteq_decode_lock_);
+ return InitDecoderSafe(codec_params, force_initialization);
}
-int16_t ACMGenericCodec::InitDecoderSafe(WebRtcACMCodecParams* codecParams,
- bool forceInitialization) {
- int mirrorID;
+int16_t ACMGenericCodec::InitDecoderSafe(WebRtcACMCodecParams* codec_params,
+ bool force_initialization) {
+ int mirror_id;
// Check if we got a valid set of parameters.
- int codecNumber = ACMCodecDB::ReceiverCodecNumber(&codecParams->codecInstant,
- &mirrorID);
- if (codecNumber < 0) {
- WEBRTC_TRACE(webrtc::kTraceError, webrtc::kTraceAudioCoding, _uniqueID,
+ int codec_number = ACMCodecDB::ReceiverCodecNumber(&codec_params->codec_inst,
+ &mirror_id);
+ if (codec_number < 0) {
+ WEBRTC_TRACE(webrtc::kTraceError, webrtc::kTraceAudioCoding, unique_id_,
"InitDecoderSafe: error, invalid codec number");
return -1;
}
// Check if the parameters are for this codec.
- if ((_codecID >= 0) && (_codecID != codecNumber) && (_codecID != mirrorID)) {
- WEBRTC_TRACE(webrtc::kTraceError, webrtc::kTraceAudioCoding, _uniqueID,
- "InitDecoderSafe: current codec is not the same as the one given "
- "by codecParams");
- // The current codec is not the same as the one given by codecParams.
+ if ((codec_id_ >= 0) && (codec_id_ != codec_number) &&
+ (codec_id_ != mirror_id)) {
+ WEBRTC_TRACE(webrtc::kTraceError, webrtc::kTraceAudioCoding, unique_id_,
+ "InitDecoderSafe: current codec is not the same as the one "
+ "given by codec_params");
+ // The current codec is not the same as the one given by codec_params.
return -1;
}
- if (_decoderInitialized && !forceInitialization) {
+ if (decoder_initialized_ && !force_initialization) {
// The decoder is already initialized, and we don't want to force
// initialization.
return 0;
}
int16_t status;
- if (!_decoderExist) {
+ if (!decoder_exist_) {
// New decoder, start with creating.
- _decoderInitialized = false;
+ decoder_initialized_ = false;
status = CreateDecoder();
if (status < 0) {
- WEBRTC_TRACE(webrtc::kTraceError, webrtc::kTraceAudioCoding, _uniqueID,
+ WEBRTC_TRACE(webrtc::kTraceError, webrtc::kTraceAudioCoding, unique_id_,
"InitDecoderSafe: cannot create decoder");
return -1;
} else {
- _decoderExist = true;
+ decoder_exist_ = true;
}
}
- status = InternalInitDecoder(codecParams);
+ status = InternalInitDecoder(codec_params);
if (status < 0) {
- WEBRTC_TRACE(webrtc::kTraceError, webrtc::kTraceAudioCoding, _uniqueID,
+ WEBRTC_TRACE(webrtc::kTraceError, webrtc::kTraceAudioCoding, unique_id_,
"InitDecoderSafe: cannot init decoder");
- _decoderInitialized = false;
+ decoder_initialized_ = false;
return -1;
} else {
// Store decoder parameters.
- SaveDecoderParamSafe(codecParams);
- _decoderInitialized = true;
+ SaveDecoderParamSafe(codec_params);
+ decoder_initialized_ = true;
}
return 0;
}
-int16_t ACMGenericCodec::ResetDecoder(int16_t payloadType) {
- WriteLockScoped lockCodec(_codecWrapperLock);
- WriteLockScoped lockNetEq(*_netEqDecodeLock);
- return ResetDecoderSafe(payloadType);
+int16_t ACMGenericCodec::ResetDecoder(int16_t payload_type) {
+ WriteLockScoped lockCodec(codec_wrapper_lock_);
+ WriteLockScoped lockNetEq(*neteq_decode_lock_);
+ return ResetDecoderSafe(payload_type);
}
-int16_t ACMGenericCodec::ResetDecoderSafe(int16_t payloadType) {
- WebRtcACMCodecParams decoderParams;
- if (!_decoderExist || !_decoderInitialized) {
+int16_t ACMGenericCodec::ResetDecoderSafe(int16_t payload_type) {
+ WebRtcACMCodecParams decoder_params;
+ if (!decoder_exist_ || !decoder_initialized_) {
return 0;
}
// Initialization of the decoder should work for all the codec. For codecs
// that needs to keep some states an overloading implementation of
// |DecoderParamsSafe| exists.
- DecoderParamsSafe(&decoderParams, static_cast<uint8_t>(payloadType));
- return InternalInitDecoder(&decoderParams);
+ DecoderParamsSafe(&decoder_params, static_cast<uint8_t>(payload_type));
+ return InternalInitDecoder(&decoder_params);
}
void ACMGenericCodec::ResetNoMissedSamples() {
- WriteLockScoped cs(_codecWrapperLock);
- _noMissedSamples = 0;
+ WriteLockScoped cs(codec_wrapper_lock_);
+ num_missed_samples_ = 0;
}
-void ACMGenericCodec::IncreaseNoMissedSamples(const int16_t noSamples) {
- _noMissedSamples += noSamples;
+void ACMGenericCodec::IncreaseNoMissedSamples(const int16_t num_samples) {
+ num_missed_samples_ += num_samples;
}
// Get the number of missed samples, this can be public.
uint32_t ACMGenericCodec::NoMissedSamples() const {
- ReadLockScoped cs(_codecWrapperLock);
- return _noMissedSamples;
+ ReadLockScoped cs(codec_wrapper_lock_);
+ return num_missed_samples_;
}
void ACMGenericCodec::DestructEncoder() {
- WriteLockScoped wl(_codecWrapperLock);
+ WriteLockScoped wl(codec_wrapper_lock_);
// Disable VAD and delete the instance.
- if (_ptrVADInst != NULL) {
- WebRtcVad_Free(_ptrVADInst);
- _ptrVADInst = NULL;
+ if (ptr_vad_inst_ != NULL) {
+ WebRtcVad_Free(ptr_vad_inst_);
+ ptr_vad_inst_ = NULL;
}
- _vadEnabled = false;
- _vadMode = VADNormal;
+ vad_enabled_ = false;
+ vad_mode_ = VADNormal;
// Disable DTX and delete the instance.
- _dtxEnabled = false;
- if (_ptrDTXInst != NULL) {
- WebRtcCng_FreeEnc(_ptrDTXInst);
- _ptrDTXInst = NULL;
+ dtx_enabled_ = false;
+ if (ptr_dtx_inst_ != NULL) {
+ WebRtcCng_FreeEnc(ptr_dtx_inst_);
+ ptr_dtx_inst_ = NULL;
}
- _numLPCParams = kNewCNGNumPLCParams;
+ num_lpc_params_ = kNewCNGNumPLCParams;
DestructEncoderSafe();
}
void ACMGenericCodec::DestructDecoder() {
- WriteLockScoped wl(_codecWrapperLock);
- _decoderParams.codecInstant.pltype = -1;
+ WriteLockScoped wl(codec_wrapper_lock_);
+ decoder_params_.codec_inst.pltype = -1;
DestructDecoderSafe();
}
-int16_t ACMGenericCodec::SetBitRate(const int32_t bitRateBPS) {
- WriteLockScoped wl(_codecWrapperLock);
- return SetBitRateSafe(bitRateBPS);
+int16_t ACMGenericCodec::SetBitRate(const int32_t bitrate_bps) {
+ WriteLockScoped wl(codec_wrapper_lock_);
+ return SetBitRateSafe(bitrate_bps);
}
-int16_t ACMGenericCodec::SetBitRateSafe(const int32_t bitRateBPS) {
+int16_t ACMGenericCodec::SetBitRateSafe(const int32_t bitrate_bps) {
// If the codec can change the bit-rate this function is overloaded.
// Otherwise the only acceptable value is the one that is in the database.
- CodecInst codecParams;
- if (ACMCodecDB::Codec(_codecID, &codecParams) < 0) {
- WEBRTC_TRACE(webrtc::kTraceError, webrtc::kTraceAudioCoding, _uniqueID,
+ CodecInst codec_params;
+ if (ACMCodecDB::Codec(codec_id_, &codec_params) < 0) {
+ WEBRTC_TRACE(webrtc::kTraceError, webrtc::kTraceAudioCoding, unique_id_,
"SetBitRateSafe: error in ACMCodecDB::Codec");
return -1;
}
- if (codecParams.rate != bitRateBPS) {
- WEBRTC_TRACE(webrtc::kTraceError, webrtc::kTraceAudioCoding, _uniqueID,
+ if (codec_params.rate != bitrate_bps) {
+ WEBRTC_TRACE(webrtc::kTraceError, webrtc::kTraceAudioCoding, unique_id_,
"SetBitRateSafe: rate value is not acceptable");
return -1;
} else {
@@ -738,7 +745,7 @@
// iSAC specific functions:
int32_t ACMGenericCodec::GetEstimatedBandwidth() {
- WriteLockScoped wl(_codecWrapperLock);
+ WriteLockScoped wl(codec_wrapper_lock_);
return GetEstimatedBandwidthSafe();
}
@@ -747,157 +754,159 @@
return -1;
}
-int32_t ACMGenericCodec::SetEstimatedBandwidth(int32_t estimatedBandwidth) {
- WriteLockScoped wl(_codecWrapperLock);
- return SetEstimatedBandwidthSafe(estimatedBandwidth);
+int32_t ACMGenericCodec::SetEstimatedBandwidth(int32_t estimated_bandwidth) {
+ WriteLockScoped wl(codec_wrapper_lock_);
+ return SetEstimatedBandwidthSafe(estimated_bandwidth);
}
int32_t ACMGenericCodec::SetEstimatedBandwidthSafe(
- int32_t /*estimatedBandwidth*/) {
+ int32_t /*estimated_bandwidth*/) {
// All codecs but iSAC will return -1.
return -1;
}
// End of iSAC specific functions.
-int32_t ACMGenericCodec::GetRedPayload(uint8_t* redPayload,
- int16_t* payloadBytes) {
- WriteLockScoped wl(_codecWrapperLock);
- return GetRedPayloadSafe(redPayload, payloadBytes);
+int32_t ACMGenericCodec::GetRedPayload(uint8_t* red_payload,
+ int16_t* payload_bytes) {
+ WriteLockScoped wl(codec_wrapper_lock_);
+ return GetRedPayloadSafe(red_payload, payload_bytes);
}
-int32_t ACMGenericCodec::GetRedPayloadSafe(uint8_t* /* redPayload */,
- int16_t* /* payloadBytes */) {
+int32_t ACMGenericCodec::GetRedPayloadSafe(uint8_t* /* red_payload */,
+ int16_t* /* payload_bytes */) {
return -1; // Do nothing by default.
}
int16_t ACMGenericCodec::CreateEncoder() {
int16_t status = 0;
- if (!_encoderExist) {
+ if (!encoder_exist_) {
status = InternalCreateEncoder();
// We just created the codec and obviously it is not initialized.
- _encoderInitialized = false;
+ encoder_initialized_ = false;
}
if (status < 0) {
- WEBRTC_TRACE(webrtc::kTraceError, webrtc::kTraceAudioCoding, _uniqueID,
+ WEBRTC_TRACE(webrtc::kTraceError, webrtc::kTraceAudioCoding, unique_id_,
"CreateEncoder: error in internal create encoder");
- _encoderExist = false;
+ encoder_exist_ = false;
} else {
- _encoderExist = true;
+ encoder_exist_ = true;
}
return status;
}
int16_t ACMGenericCodec::CreateDecoder() {
int16_t status = 0;
- if (!_decoderExist) {
+ if (!decoder_exist_) {
status = InternalCreateDecoder();
// Decoder just created and obviously it is not initialized.
- _decoderInitialized = false;
+ decoder_initialized_ = false;
}
if (status < 0) {
- WEBRTC_TRACE(webrtc::kTraceError, webrtc::kTraceAudioCoding, _uniqueID,
+ WEBRTC_TRACE(webrtc::kTraceError, webrtc::kTraceAudioCoding, unique_id_,
"CreateDecoder: error in internal create decoder");
- _decoderExist = false;
+ decoder_exist_ = false;
} else {
- _decoderExist = true;
+ decoder_exist_ = true;
}
return status;
}
-void ACMGenericCodec::DestructEncoderInst(void* ptrInst) {
- if (ptrInst != NULL) {
- WriteLockScoped lockCodec(_codecWrapperLock);
- ReadLockScoped lockNetEq(*_netEqDecodeLock);
- InternalDestructEncoderInst(ptrInst);
+void ACMGenericCodec::DestructEncoderInst(void* ptr_inst) {
+ if (ptr_inst != NULL) {
+ WriteLockScoped lockCodec(codec_wrapper_lock_);
+ ReadLockScoped lockNetEq(*neteq_decode_lock_);
+ InternalDestructEncoderInst(ptr_inst);
}
}
// Get the current audio buffer including read and write states, and timestamps.
-int16_t ACMGenericCodec::AudioBuffer(WebRtcACMAudioBuff& audioBuff) {
- ReadLockScoped cs(_codecWrapperLock);
- memcpy(audioBuff.inAudio, _inAudio,
+int16_t ACMGenericCodec::AudioBuffer(WebRtcACMAudioBuff& audio_buff) {
+ ReadLockScoped cs(codec_wrapper_lock_);
+ memcpy(audio_buff.in_audio, in_audio_,
AUDIO_BUFFER_SIZE_W16 * sizeof(int16_t));
- audioBuff.inAudioIxRead = _inAudioIxRead;
- audioBuff.inAudioIxWrite = _inAudioIxWrite;
- memcpy(audioBuff.inTimestamp, _inTimestamp,
+ audio_buff.in_audio_ix_read = in_audio_ix_read_;
+ audio_buff.in_audio_ix_write = in_audio_ix_write_;
+ memcpy(audio_buff.in_timestamp, in_timestamp_,
TIMESTAMP_BUFFER_SIZE_W32 * sizeof(uint32_t));
- audioBuff.inTimestampIxWrite = _inTimestampIxWrite;
- audioBuff.lastTimestamp = _lastTimestamp;
+ audio_buff.in_timestamp_ix_write = in_timestamp_ix_write_;
+ audio_buff.last_timestamp = last_timestamp_;
return 0;
}
// Set the audio buffer.
-int16_t ACMGenericCodec::SetAudioBuffer(WebRtcACMAudioBuff& audioBuff) {
- WriteLockScoped cs(_codecWrapperLock);
- memcpy(_inAudio, audioBuff.inAudio,
+int16_t ACMGenericCodec::SetAudioBuffer(WebRtcACMAudioBuff& audio_buff) {
+ WriteLockScoped cs(codec_wrapper_lock_);
+ memcpy(in_audio_, audio_buff.in_audio,
AUDIO_BUFFER_SIZE_W16 * sizeof(int16_t));
- _inAudioIxRead = audioBuff.inAudioIxRead;
- _inAudioIxWrite = audioBuff.inAudioIxWrite;
- memcpy(_inTimestamp, audioBuff.inTimestamp,
+ in_audio_ix_read_ = audio_buff.in_audio_ix_read;
+ in_audio_ix_write_ = audio_buff.in_audio_ix_write;
+ memcpy(in_timestamp_, audio_buff.in_timestamp,
TIMESTAMP_BUFFER_SIZE_W32 * sizeof(uint32_t));
- _inTimestampIxWrite = audioBuff.inTimestampIxWrite;
- _lastTimestamp = audioBuff.lastTimestamp;
- _isAudioBuffFresh = false;
+ in_timestamp_ix_write_ = audio_buff.in_timestamp_ix_write;
+ last_timestamp_ = audio_buff.last_timestamp;
+ is_audio_buff_fresh_ = false;
return 0;
}
uint32_t ACMGenericCodec::LastEncodedTimestamp() const {
- ReadLockScoped cs(_codecWrapperLock);
- return _lastEncodedTimestamp;
+ ReadLockScoped cs(codec_wrapper_lock_);
+ return last_encoded_timestamp_;
}
uint32_t ACMGenericCodec::EarliestTimestamp() const {
- ReadLockScoped cs(_codecWrapperLock);
- return _inTimestamp[0];
+ ReadLockScoped cs(codec_wrapper_lock_);
+ return in_timestamp_[0];
}
-int16_t ACMGenericCodec::SetVAD(const bool enableDTX, const bool enableVAD,
+int16_t ACMGenericCodec::SetVAD(const bool enable_dtx,
+ const bool enable_vad,
const ACMVADMode mode) {
- WriteLockScoped cs(_codecWrapperLock);
- return SetVADSafe(enableDTX, enableVAD, mode);
+ WriteLockScoped cs(codec_wrapper_lock_);
+ return SetVADSafe(enable_dtx, enable_vad, mode);
}
-int16_t ACMGenericCodec::SetVADSafe(const bool enableDTX, const bool enableVAD,
+int16_t ACMGenericCodec::SetVADSafe(const bool enable_dtx,
+ const bool enable_vad,
const ACMVADMode mode) {
- if (enableDTX) {
+ if (enable_dtx) {
// Make G729 AnnexB a special case.
- if (!STR_CASE_CMP(_encoderParams.codecInstant.plname, "G729")
- && !_hasInternalDTX) {
+ if (!STR_CASE_CMP(encoder_params_.codec_inst.plname, "G729")
+ && !has_internal_dtx_) {
if (ACMGenericCodec::EnableDTX() < 0) {
- WEBRTC_TRACE(webrtc::kTraceError, webrtc::kTraceAudioCoding, _uniqueID,
+ WEBRTC_TRACE(webrtc::kTraceError, webrtc::kTraceAudioCoding, unique_id_,
"SetVADSafe: error in enable DTX");
return -1;
}
} else {
if (EnableDTX() < 0) {
- WEBRTC_TRACE(webrtc::kTraceError, webrtc::kTraceAudioCoding, _uniqueID,
+ WEBRTC_TRACE(webrtc::kTraceError, webrtc::kTraceAudioCoding, unique_id_,
"SetVADSafe: error in enable DTX");
return -1;
}
}
- if (_hasInternalDTX) {
+ if (has_internal_dtx_) {
// Codec has internal DTX, practically we don't need WebRtc VAD, however,
// we let the user to turn it on if they need call-backs on silence.
// Store VAD mode for future even if VAD is off.
- _vadMode = mode;
- return (enableVAD) ? EnableVAD(mode) : DisableVAD();
+ vad_mode_ = mode;
+ return (enable_vad) ? EnableVAD(mode) : DisableVAD();
} else {
// Codec does not have internal DTX so enabling DTX requires an active
- // VAD. 'enableDTX == true' overwrites VAD status.
+ // VAD. 'enable_dtx == true' overwrites VAD status.
if (EnableVAD(mode) < 0) {
// If we cannot create VAD we have to disable DTX.
- if (!_vadEnabled) {
+ if (!vad_enabled_) {
DisableDTX();
}
- WEBRTC_TRACE(webrtc::kTraceError, webrtc::kTraceAudioCoding, _uniqueID,
+ WEBRTC_TRACE(webrtc::kTraceError, webrtc::kTraceAudioCoding, unique_id_,
"SetVADSafe: error in enable VAD");
return -1;
}
// Return '1', to let the caller know VAD was turned on, even if the
// function was called with VAD='false'.
- if (enableVAD == false) {
+ if (enable_vad == false) {
return 1;
} else {
return 0;
@@ -905,145 +914,146 @@
}
} else {
// Make G729 AnnexB a special case.
- if (!STR_CASE_CMP(_encoderParams.codecInstant.plname, "G729")
- && !_hasInternalDTX) {
+ if (!STR_CASE_CMP(encoder_params_.codec_inst.plname, "G729")
+ && !has_internal_dtx_) {
ACMGenericCodec::DisableDTX();
} else {
DisableDTX();
}
- return (enableVAD) ? EnableVAD(mode) : DisableVAD();
+ return (enable_vad) ? EnableVAD(mode) : DisableVAD();
}
}
int16_t ACMGenericCodec::EnableDTX() {
- if (_hasInternalDTX) {
+ if (has_internal_dtx_) {
// We should not be here if we have internal DTX this function should be
// overloaded by the derived class in this case.
return -1;
}
- if (!_dtxEnabled) {
- if (WebRtcCng_CreateEnc(&_ptrDTXInst) < 0) {
- _ptrDTXInst = NULL;
+ if (!dtx_enabled_) {
+ if (WebRtcCng_CreateEnc(&ptr_dtx_inst_) < 0) {
+ ptr_dtx_inst_ = NULL;
return -1;
}
- uint16_t freqHz;
- EncoderSampFreq(freqHz);
- if (WebRtcCng_InitEnc(_ptrDTXInst, freqHz, kCngSidIntervalMsec,
- _numLPCParams) < 0) {
+ uint16_t freq_hz;
+ EncoderSampFreq(freq_hz);
+ if (WebRtcCng_InitEnc(ptr_dtx_inst_, freq_hz, kCngSidIntervalMsec,
+ num_lpc_params_) < 0) {
// Couldn't initialize, has to return -1, and free the memory.
- WebRtcCng_FreeEnc(_ptrDTXInst);
- _ptrDTXInst = NULL;
+ WebRtcCng_FreeEnc(ptr_dtx_inst_);
+ ptr_dtx_inst_ = NULL;
return -1;
}
- _dtxEnabled = true;
+ dtx_enabled_ = true;
}
return 0;
}
int16_t ACMGenericCodec::DisableDTX() {
- if (_hasInternalDTX) {
+ if (has_internal_dtx_) {
// We should not be here if we have internal DTX this function should be
// overloaded by the derived class in this case.
return -1;
}
- if (_ptrDTXInst != NULL) {
- WebRtcCng_FreeEnc(_ptrDTXInst);
- _ptrDTXInst = NULL;
+ if (ptr_dtx_inst_ != NULL) {
+ WebRtcCng_FreeEnc(ptr_dtx_inst_);
+ ptr_dtx_inst_ = NULL;
}
- _dtxEnabled = false;
+ dtx_enabled_ = false;
return 0;
}
int16_t ACMGenericCodec::EnableVAD(ACMVADMode mode) {
if ((mode < VADNormal) || (mode > VADVeryAggr)) {
- WEBRTC_TRACE(webrtc::kTraceError, webrtc::kTraceAudioCoding, _uniqueID,
+ WEBRTC_TRACE(webrtc::kTraceError, webrtc::kTraceAudioCoding, unique_id_,
"EnableVAD: error in VAD mode range");
return -1;
}
- if (!_vadEnabled) {
- if (WebRtcVad_Create(&_ptrVADInst) < 0) {
- _ptrVADInst = NULL;
- WEBRTC_TRACE(webrtc::kTraceError, webrtc::kTraceAudioCoding, _uniqueID,
+ if (!vad_enabled_) {
+ if (WebRtcVad_Create(&ptr_vad_inst_) < 0) {
+ ptr_vad_inst_ = NULL;
+ WEBRTC_TRACE(webrtc::kTraceError, webrtc::kTraceAudioCoding, unique_id_,
"EnableVAD: error in create VAD");
return -1;
}
- if (WebRtcVad_Init(_ptrVADInst) < 0) {
- WebRtcVad_Free(_ptrVADInst);
- _ptrVADInst = NULL;
- WEBRTC_TRACE(webrtc::kTraceError, webrtc::kTraceAudioCoding, _uniqueID,
+ if (WebRtcVad_Init(ptr_vad_inst_) < 0) {
+ WebRtcVad_Free(ptr_vad_inst_);
+ ptr_vad_inst_ = NULL;
+ WEBRTC_TRACE(webrtc::kTraceError, webrtc::kTraceAudioCoding, unique_id_,
"EnableVAD: error in init VAD");
return -1;
}
}
// Set the VAD mode to the given value.
- if (WebRtcVad_set_mode(_ptrVADInst, mode) < 0) {
+ if (WebRtcVad_set_mode(ptr_vad_inst_, mode) < 0) {
// We failed to set the mode and we have to return -1. If we already have a
- // working VAD (_vadEnabled == true) then we leave it to work. Otherwise,
+ // working VAD (vad_enabled_ == true) then we leave it to work. Otherwise,
// the following will be executed.
- if (!_vadEnabled) {
+ if (!vad_enabled_) {
// We just created the instance but cannot set the mode we have to free
// the memory.
- WebRtcVad_Free(_ptrVADInst);
- _ptrVADInst = NULL;
+ WebRtcVad_Free(ptr_vad_inst_);
+ ptr_vad_inst_ = NULL;
}
- WEBRTC_TRACE(webrtc::kTraceDebug, webrtc::kTraceAudioCoding, _uniqueID,
+ WEBRTC_TRACE(webrtc::kTraceDebug, webrtc::kTraceAudioCoding, unique_id_,
"EnableVAD: failed to set the VAD mode");
return -1;
}
- _vadMode = mode;
- _vadEnabled = true;
+ vad_mode_ = mode;
+ vad_enabled_ = true;
return 0;
}
int16_t ACMGenericCodec::DisableVAD() {
- if (_ptrVADInst != NULL) {
- WebRtcVad_Free(_ptrVADInst);
- _ptrVADInst = NULL;
+ if (ptr_vad_inst_ != NULL) {
+ WebRtcVad_Free(ptr_vad_inst_);
+ ptr_vad_inst_ = NULL;
}
- _vadEnabled = false;
+ vad_enabled_ = false;
return 0;
}
-int32_t ACMGenericCodec::ReplaceInternalDTX(const bool replaceInternalDTX) {
- WriteLockScoped cs(_codecWrapperLock);
- return ReplaceInternalDTXSafe(replaceInternalDTX);
+int32_t ACMGenericCodec::ReplaceInternalDTX(const bool replace_internal_dtx) {
+ WriteLockScoped cs(codec_wrapper_lock_);
+ return ReplaceInternalDTXSafe(replace_internal_dtx);
}
int32_t ACMGenericCodec::ReplaceInternalDTXSafe(
- const bool /* replaceInternalDTX */) {
+ const bool /* replace_internal_dtx */) {
return -1;
}
-int32_t ACMGenericCodec::IsInternalDTXReplaced(bool* internalDTXReplaced) {
- WriteLockScoped cs(_codecWrapperLock);
- return IsInternalDTXReplacedSafe(internalDTXReplaced);
+int32_t ACMGenericCodec::IsInternalDTXReplaced(bool* internal_dtx_replaced) {
+ WriteLockScoped cs(codec_wrapper_lock_);
+ return IsInternalDTXReplacedSafe(internal_dtx_replaced);
}
-int32_t ACMGenericCodec::IsInternalDTXReplacedSafe(bool* internalDTXReplaced) {
- *internalDTXReplaced = false;
+int32_t ACMGenericCodec::IsInternalDTXReplacedSafe(
+ bool* internal_dtx_replaced) {
+ *internal_dtx_replaced = false;
return 0;
}
-int16_t ACMGenericCodec::ProcessFrameVADDTX(uint8_t* bitStream,
- int16_t* bitStreamLenByte,
- int16_t* samplesProcessed) {
- if (!_vadEnabled) {
- // VAD not enabled, set all vadLable[] to 1 (speech detected).
+int16_t ACMGenericCodec::ProcessFrameVADDTX(uint8_t* bitstream,
+ int16_t* bitstream_len_byte,
+ int16_t* samples_processed) {
+ if (!vad_enabled_) {
+ // VAD not enabled, set all |vad_lable_[]| to 1 (speech detected).
for (int n = 0; n < MAX_FRAME_SIZE_10MSEC; n++) {
- _vadLabel[n] = 1;
+ vad_label_[n] = 1;
}
- *samplesProcessed = 0;
+ *samples_processed = 0;
return 0;
}
- uint16_t freqHz;
- EncoderSampFreq(freqHz);
+ uint16_t freq_hz;
+ EncoderSampFreq(freq_hz);
// Calculate number of samples in 10 ms blocks, and number ms in one frame.
- int16_t samplesIn10Msec = static_cast<int16_t>(freqHz / 100);
- int32_t frameLenMsec = static_cast<int32_t>(_frameLenSmpl) * 1000 / freqHz;
+ int16_t samples_in_10ms = static_cast<int16_t>(freq_hz / 100);
+ int32_t frame_len_ms = static_cast<int32_t>(frame_len_smpl_) * 1000 / freq_hz;
int16_t status;
// Vector for storing maximum 30 ms of mono audio at 48 kHz.
@@ -1051,43 +1061,44 @@
// Calculate number of VAD-blocks to process, and number of samples in each
// block.
- int noSamplesToProcess[2];
- if (frameLenMsec == 40) {
+ int num_samples_to_process[2];
+ if (frame_len_ms == 40) {
// 20 ms in each VAD block.
- noSamplesToProcess[0] = noSamplesToProcess[1] = 2 * samplesIn10Msec;
+ num_samples_to_process[0] = num_samples_to_process[1] = 2 * samples_in_10ms;
} else {
// For 10-30 ms framesizes, second VAD block will be size zero ms,
// for 50 and 60 ms first VAD block will be 30 ms.
- noSamplesToProcess[0] =
- (frameLenMsec > 30) ? 3 * samplesIn10Msec : _frameLenSmpl;
- noSamplesToProcess[1] = _frameLenSmpl - noSamplesToProcess[0];
+ num_samples_to_process[0] =
+ (frame_len_ms > 30) ? 3 * samples_in_10ms : frame_len_smpl_;
+ num_samples_to_process[1] = frame_len_smpl_ - num_samples_to_process[0];
}
- int offSet = 0;
- int loops = (noSamplesToProcess[1] > 0) ? 2 : 1;
+ int offset = 0;
+ int loops = (num_samples_to_process[1] > 0) ? 2 : 1;
for (int i = 0; i < loops; i++) {
+ // TODO(turajs): Do we need to care about VAD together with stereo?
// If stereo, calculate mean of the two channels.
- if (_noChannels == 2) {
- for (int j = 0; j < noSamplesToProcess[i]; j++) {
- audio[j] = (_inAudio[(offSet + j) * 2] +
- _inAudio[(offSet + j) * 2 + 1]) / 2;
+ if (num_channels_ == 2) {
+ for (int j = 0; j < num_samples_to_process[i]; j++) {
+ audio[j] = (in_audio_[(offset + j) * 2] +
+ in_audio_[(offset + j) * 2 + 1]) / 2;
}
- offSet = noSamplesToProcess[0];
+ offset = num_samples_to_process[0];
} else {
- // Mono, copy data from _inAudio to continue work on.
- memcpy(audio, _inAudio, sizeof(int16_t) * noSamplesToProcess[i]);
+ // Mono, copy data from in_audio_ to continue work on.
+ memcpy(audio, in_audio_, sizeof(int16_t) * num_samples_to_process[i]);
}
// Call VAD.
- status = static_cast<int16_t>(WebRtcVad_Process(_ptrVADInst,
- static_cast<int>(freqHz),
+ status = static_cast<int16_t>(WebRtcVad_Process(ptr_vad_inst_,
+ static_cast<int>(freq_hz),
audio,
- noSamplesToProcess[i]));
- _vadLabel[i] = status;
+ num_samples_to_process[i]));
+ vad_label_[i] = status;
if (status < 0) {
// This will force that the data be removed from the buffer.
- *samplesProcessed += noSamplesToProcess[i];
+ *samples_processed += num_samples_to_process[i];
return -1;
}
@@ -1095,41 +1106,41 @@
// first part of a frame gets the VAD decision "inactive". Otherwise DTX
// might say it is time to transmit SID frame, but we will encode the whole
// frame, because the first part is active.
- *samplesProcessed = 0;
- if ((status == 0) && (i == 0) && _dtxEnabled && !_hasInternalDTX) {
- int16_t bitStreamLen;
- int num10MsecFrames = noSamplesToProcess[i] / samplesIn10Msec;
- *bitStreamLenByte = 0;
- for (int n = 0; n < num10MsecFrames; n++) {
+ *samples_processed = 0;
+ if ((status == 0) && (i == 0) && dtx_enabled_ && !has_internal_dtx_) {
+ int16_t bitstream_len;
+ int num_10ms_frames = num_samples_to_process[i] / samples_in_10ms;
+ *bitstream_len_byte = 0;
+ for (int n = 0; n < num_10ms_frames; n++) {
// This block is (passive) && (vad enabled). If first CNG after
// speech, force SID by setting last parameter to "1".
- status = WebRtcCng_Encode(_ptrDTXInst, &audio[n * samplesIn10Msec],
- samplesIn10Msec, bitStream, &bitStreamLen,
- !_prev_frame_cng);
+ status = WebRtcCng_Encode(ptr_dtx_inst_, &audio[n * samples_in_10ms],
+ samples_in_10ms, bitstream, &bitstream_len,
+ !prev_frame_cng_);
if (status < 0) {
return -1;
}
// Update previous frame was CNG.
- _prev_frame_cng = 1;
+ prev_frame_cng_ = 1;
- *samplesProcessed += samplesIn10Msec * _noChannels;
+ *samples_processed += samples_in_10ms * num_channels_;
- // |bitStreamLen| will only be > 0 once per 100 ms.
- *bitStreamLenByte += bitStreamLen;
+ // |bitstream_len_byte| will only be > 0 once per 100 ms.
+ *bitstream_len_byte += bitstream_len;
}
// Check if all samples got processed by the DTX.
- if (*samplesProcessed != noSamplesToProcess[i] * _noChannels) {
+ if (*samples_processed != num_samples_to_process[i] * num_channels_) {
// Set to zero since something went wrong. Shouldn't happen.
- *samplesProcessed = 0;
+ *samples_processed = 0;
}
} else {
// Update previous frame was not CNG.
- _prev_frame_cng = 0;
+ prev_frame_cng_ = 0;
}
- if (*samplesProcessed > 0) {
+ if (*samples_processed > 0) {
// The block contains inactive speech, and is processed by DTX.
// Discontinue running VAD.
break;
@@ -1140,85 +1151,88 @@
}
int16_t ACMGenericCodec::SamplesLeftToEncode() {
- ReadLockScoped rl(_codecWrapperLock);
- return (_frameLenSmpl <= _inAudioIxWrite) ? 0 :
- (_frameLenSmpl - _inAudioIxWrite);
+ ReadLockScoped rl(codec_wrapper_lock_);
+ return (frame_len_smpl_ <= in_audio_ix_write_) ? 0 :
+ (frame_len_smpl_ - in_audio_ix_write_);
}
void ACMGenericCodec::SetUniqueID(const uint32_t id) {
- _uniqueID = id;
+ unique_id_ = id;
}
bool ACMGenericCodec::IsAudioBufferFresh() const {
- ReadLockScoped rl(_codecWrapperLock);
- return _isAudioBuffFresh;
+ ReadLockScoped rl(codec_wrapper_lock_);
+ return is_audio_buff_fresh_;
}
// This function is replaced by codec specific functions for some codecs.
-int16_t ACMGenericCodec::EncoderSampFreq(uint16_t& sampFreqHz) {
+int16_t ACMGenericCodec::EncoderSampFreq(uint16_t& samp_freq_hz) {
int32_t f;
- f = ACMCodecDB::CodecFreq(_codecID);
+ f = ACMCodecDB::CodecFreq(codec_id_);
if (f < 0) {
- WEBRTC_TRACE(webrtc::kTraceError, webrtc::kTraceAudioCoding, _uniqueID,
+ WEBRTC_TRACE(webrtc::kTraceError, webrtc::kTraceAudioCoding, unique_id_,
"EncoderSampFreq: codec frequency is negative");
return -1;
} else {
- sampFreqHz = static_cast<uint16_t>(f);
+ samp_freq_hz = static_cast<uint16_t>(f);
return 0;
}
}
int32_t ACMGenericCodec::ConfigISACBandwidthEstimator(
- const uint8_t /* initFrameSizeMsec */,
- const uint16_t /* initRateBitPerSec */,
- const bool /* enforceFrameSize */) {
- WEBRTC_TRACE(webrtc::kTraceWarning, webrtc::kTraceAudioCoding, _uniqueID,
- "The send-codec is not iSAC, failed to config iSAC bandwidth estimator.");
+ const uint8_t /* init_frame_size_msec */,
+ const uint16_t /* init_rate_bit_per_sec */,
+ const bool /* enforce_frame_size */) {
+ WEBRTC_TRACE(webrtc::kTraceWarning, webrtc::kTraceAudioCoding, unique_id_,
+ "The send-codec is not iSAC, failed to config iSAC bandwidth "
+ "estimator.");
return -1;
}
-int32_t ACMGenericCodec::SetISACMaxRate(const uint32_t /* maxRateBitPerSec */) {
- WEBRTC_TRACE(webrtc::kTraceWarning, webrtc::kTraceAudioCoding, _uniqueID,
+int32_t ACMGenericCodec::SetISACMaxRate(
+ const uint32_t /* max_rate_bit_per_sec */) {
+ WEBRTC_TRACE(webrtc::kTraceWarning, webrtc::kTraceAudioCoding, unique_id_,
"The send-codec is not iSAC, failed to set iSAC max rate.");
return -1;
}
int32_t ACMGenericCodec::SetISACMaxPayloadSize(
- const uint16_t /* maxPayloadLenBytes */) {
- WEBRTC_TRACE(webrtc::kTraceWarning, webrtc::kTraceAudioCoding, _uniqueID,
- "The send-codec is not iSAC, failed to set iSAC max payload-size.");
+ const uint16_t /* max_payload_len_bytes */) {
+ WEBRTC_TRACE(webrtc::kTraceWarning, webrtc::kTraceAudioCoding, unique_id_,
+ "The send-codec is not iSAC, failed to set iSAC max "
+ "payload-size.");
return -1;
}
void ACMGenericCodec::SaveDecoderParam(
- const WebRtcACMCodecParams* codecParams) {
- WriteLockScoped wl(_codecWrapperLock);
- SaveDecoderParamSafe(codecParams);
+ const WebRtcACMCodecParams* codec_params) {
+ WriteLockScoped wl(codec_wrapper_lock_);
+ SaveDecoderParamSafe(codec_params);
}
void ACMGenericCodec::SaveDecoderParamSafe(
- const WebRtcACMCodecParams* codecParams) {
- memcpy(&_decoderParams, codecParams, sizeof(WebRtcACMCodecParams));
+ const WebRtcACMCodecParams* codec_params) {
+ memcpy(&decoder_params_, codec_params, sizeof(WebRtcACMCodecParams));
}
int16_t ACMGenericCodec::UpdateEncoderSampFreq(
- uint16_t /* encoderSampFreqHz */) {
- WEBRTC_TRACE(webrtc::kTraceError, webrtc::kTraceAudioCoding, _uniqueID,
- "It is asked for a change in smapling frequency while the current "
- "send-codec supports only one sampling rate.");
+ uint16_t /* samp_freq_hz */) {
+ WEBRTC_TRACE(webrtc::kTraceError, webrtc::kTraceAudioCoding, unique_id_,
+ "It is asked for a change in smapling frequency while the "
+ "current send-codec supports only one sampling rate.");
return -1;
}
-void ACMGenericCodec::SetIsMaster(bool isMaster) {
- WriteLockScoped wl(_codecWrapperLock);
- _isMaster = isMaster;
+void ACMGenericCodec::SetIsMaster(bool is_master) {
+ WriteLockScoped wl(codec_wrapper_lock_);
+ is_master_ = is_master;
}
-int16_t ACMGenericCodec::REDPayloadISAC(const int32_t /* isacRate */,
- const int16_t /* isacBwEstimate */,
+int16_t ACMGenericCodec::REDPayloadISAC(const int32_t /* isac_rate */,
+ const int16_t /* isac_bw_estimate */,
uint8_t* /* payload */,
- int16_t* /* payloadLenBytes */) {
- WEBRTC_TRACE(webrtc::kTraceError, webrtc::kTraceAudioCoding, _uniqueID,
+ int16_t* /* payload_len_bytes */) {
+ WEBRTC_TRACE(webrtc::kTraceError, webrtc::kTraceAudioCoding, unique_id_,
"Error: REDPayloadISAC is an iSAC specific function");
return -1;
}