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@3287 4adac7df-926f-26a2-2b94-8c16560cd09d
This commit is contained in:
@ -8,13 +8,13 @@
|
||||
* be found in the AUTHORS file in the root of the source tree.
|
||||
*/
|
||||
|
||||
#include "acm_common_defs.h"
|
||||
#include "acm_neteq.h"
|
||||
#include "acm_celt.h"
|
||||
#include "trace.h"
|
||||
#include "webrtc_neteq.h"
|
||||
#include "webrtc_neteq_help_macros.h"
|
||||
// TODO(tlegrand): Add full paths.
|
||||
#include "webrtc/modules/audio_coding/main/source/acm_celt.h"
|
||||
|
||||
#include "webrtc/modules/audio_coding/main/source/acm_common_defs.h"
|
||||
#include "webrtc/modules/audio_coding/main/source/acm_neteq.h"
|
||||
#include "webrtc/modules/audio_coding/neteq/interface/webrtc_neteq.h"
|
||||
#include "webrtc/modules/audio_coding/neteq/interface/webrtc_neteq_help_macros.h"
|
||||
#include "webrtc/system_wrappers/interface/trace.h"
|
||||
|
||||
#ifdef WEBRTC_CODEC_CELT
|
||||
// NOTE! Celt is not included in the open-source package. Modify this file or
|
||||
@ -26,7 +26,7 @@ namespace webrtc {
|
||||
|
||||
#ifndef WEBRTC_CODEC_CELT
|
||||
|
||||
ACMCELT::ACMCELT(int16_t /* codecID */)
|
||||
ACMCELT::ACMCELT(int16_t /* codec_id */)
|
||||
: enc_inst_ptr_(NULL),
|
||||
dec_inst_ptr_(NULL),
|
||||
sampling_freq_(0),
|
||||
@ -40,29 +40,29 @@ ACMCELT::~ACMCELT() {
|
||||
return;
|
||||
}
|
||||
|
||||
int16_t ACMCELT::InternalEncode(uint8_t* /* bitStream */,
|
||||
int16_t* /* bitStreamLenByte */) {
|
||||
int16_t ACMCELT::InternalEncode(uint8_t* /* bitstream */,
|
||||
int16_t* /* bitstream_len_byte */) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
int16_t ACMCELT::DecodeSafe(uint8_t* /* bitStream */,
|
||||
int16_t /* bitStreamLenByte */,
|
||||
int16_t ACMCELT::DecodeSafe(uint8_t* /* bitstream */,
|
||||
int16_t /* bitstream_len_byte */,
|
||||
int16_t* /* audio */,
|
||||
int16_t* /* audioSamples */,
|
||||
WebRtc_Word8* /* speechType */) {
|
||||
int16_t* /* audio_samples */,
|
||||
WebRtc_Word8* /* speech_type */) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
int16_t ACMCELT::InternalInitEncoder(WebRtcACMCodecParams* /* codecParams */) {
|
||||
int16_t ACMCELT::InternalInitEncoder(WebRtcACMCodecParams* /* codec_params */) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
int16_t ACMCELT::InternalInitDecoder(WebRtcACMCodecParams* /* codecParams */) {
|
||||
int16_t ACMCELT::InternalInitDecoder(WebRtcACMCodecParams* /* codec_params */) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
int32_t ACMCELT::CodecDef(WebRtcNetEQ_CodecDef& /* codecDef */,
|
||||
const CodecInst& /* codecInst */) {
|
||||
int32_t ACMCELT::CodecDef(WebRtcNetEQ_CodecDef& /* codec_def */,
|
||||
const CodecInst& /* codec_inst */) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
@ -86,7 +86,7 @@ void ACMCELT::DestructDecoderSafe() {
|
||||
return;
|
||||
}
|
||||
|
||||
void ACMCELT::InternalDestructEncoderInst(void* /* ptrInst */) {
|
||||
void ACMCELT::InternalDestructEncoderInst(void* /* ptr_inst */) {
|
||||
return;
|
||||
}
|
||||
|
||||
@ -103,7 +103,7 @@ void ACMCELT::SplitStereoPacket(uint8_t* /*payload*/,
|
||||
|
||||
#else //===================== Actual Implementation =======================
|
||||
|
||||
ACMCELT::ACMCELT(int16_t codecID)
|
||||
ACMCELT::ACMCELT(int16_t codec_id)
|
||||
: enc_inst_ptr_(NULL),
|
||||
dec_inst_ptr_(NULL),
|
||||
sampling_freq_(32000), // Default sampling frequency.
|
||||
@ -111,7 +111,7 @@ ACMCELT::ACMCELT(int16_t codecID)
|
||||
channels_(1), // Default send mono.
|
||||
dec_channels_(1) { // Default receive mono.
|
||||
// TODO(tlegrand): remove later when ACMGenericCodec has a new constructor.
|
||||
_codecID = codecID;
|
||||
codec_id_ = codec_id;
|
||||
|
||||
return;
|
||||
}
|
||||
@ -128,52 +128,53 @@ ACMCELT::~ACMCELT() {
|
||||
return;
|
||||
}
|
||||
|
||||
int16_t ACMCELT::InternalEncode(uint8_t* bitStream, int16_t* bitStreamLenByte) {
|
||||
*bitStreamLenByte = 0;
|
||||
int16_t ACMCELT::InternalEncode(uint8_t* bitstream,
|
||||
int16_t* bitstream_len_byte) {
|
||||
*bitstream_len_byte = 0;
|
||||
|
||||
// Call Encoder.
|
||||
*bitStreamLenByte = WebRtcCelt_Encode(enc_inst_ptr_,
|
||||
&_inAudio[_inAudioIxRead],
|
||||
bitStream);
|
||||
*bitstream_len_byte = WebRtcCelt_Encode(enc_inst_ptr_,
|
||||
&in_audio_[in_audio_ix_read_],
|
||||
bitstream);
|
||||
|
||||
// Increment the read index this tell the caller that how far
|
||||
// we have gone forward in reading the audio buffer.
|
||||
_inAudioIxRead += _frameLenSmpl * channels_;
|
||||
in_audio_ix_read_ += frame_len_smpl_ * channels_;
|
||||
|
||||
if (*bitStreamLenByte < 0) {
|
||||
if (*bitstream_len_byte < 0) {
|
||||
// Error reported from the encoder.
|
||||
WEBRTC_TRACE(webrtc::kTraceError, webrtc::kTraceAudioCoding, _uniqueID,
|
||||
WEBRTC_TRACE(webrtc::kTraceError, webrtc::kTraceAudioCoding, unique_id_,
|
||||
"InternalEncode: Encode error for Celt");
|
||||
*bitStreamLenByte = 0;
|
||||
*bitstream_len_byte = 0;
|
||||
return -1;
|
||||
}
|
||||
|
||||
return *bitStreamLenByte;
|
||||
return *bitstream_len_byte;
|
||||
}
|
||||
|
||||
int16_t ACMCELT::DecodeSafe(uint8_t* /* bitStream */,
|
||||
int16_t /* bitStreamLenByte */,
|
||||
int16_t ACMCELT::DecodeSafe(uint8_t* /* bitstream */,
|
||||
int16_t /* bitstream_len_byte */,
|
||||
int16_t* /* audio */,
|
||||
int16_t* /* audioSamples */,
|
||||
WebRtc_Word8* /* speechType */) {
|
||||
int16_t* /* audio_samples */,
|
||||
WebRtc_Word8* /* speech_type */) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
int16_t ACMCELT::InternalInitEncoder(WebRtcACMCodecParams* codecParams) {
|
||||
int16_t ACMCELT::InternalInitEncoder(WebRtcACMCodecParams* codec_params) {
|
||||
// Set bitrate and check that it is within the valid range.
|
||||
int16_t status = SetBitRateSafe((codecParams->codecInstant).rate);
|
||||
int16_t status = SetBitRateSafe((codec_params->codec_inst).rate);
|
||||
if (status < 0) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
// If number of channels changed we need to re-create memory.
|
||||
if (codecParams->codecInstant.channels != channels_) {
|
||||
if (codec_params->codec_inst.channels != channels_) {
|
||||
WebRtcCelt_FreeEnc(enc_inst_ptr_);
|
||||
enc_inst_ptr_ = NULL;
|
||||
// Store new number of channels.
|
||||
channels_ = codecParams->codecInstant.channels;
|
||||
channels_ = codec_params->codec_inst.channels;
|
||||
if (WebRtcCelt_CreateEnc(&enc_inst_ptr_, channels_) < 0) {
|
||||
return -1;
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
@ -185,36 +186,36 @@ int16_t ACMCELT::InternalInitEncoder(WebRtcACMCodecParams* codecParams) {
|
||||
}
|
||||
}
|
||||
|
||||
int16_t ACMCELT::InternalInitDecoder(WebRtcACMCodecParams* codecParams) {
|
||||
int16_t ACMCELT::InternalInitDecoder(WebRtcACMCodecParams* codec_params) {
|
||||
// If number of channels changed we need to re-create memory.
|
||||
if (codecParams->codecInstant.channels != dec_channels_) {
|
||||
if (codec_params->codec_inst.channels != dec_channels_) {
|
||||
WebRtcCelt_FreeDec(dec_inst_ptr_);
|
||||
dec_inst_ptr_ = NULL;
|
||||
// Store new number of channels.
|
||||
dec_channels_ = codecParams->codecInstant.channels;
|
||||
dec_channels_ = codec_params->codec_inst.channels;
|
||||
if (WebRtcCelt_CreateDec(&dec_inst_ptr_, dec_channels_) < 0) {
|
||||
return -1;
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
// Initiate decoder, both master and slave parts.
|
||||
if (WebRtcCelt_DecoderInit(dec_inst_ptr_) < 0) {
|
||||
WEBRTC_TRACE(webrtc::kTraceError, webrtc::kTraceAudioCoding, _uniqueID,
|
||||
WEBRTC_TRACE(webrtc::kTraceError, webrtc::kTraceAudioCoding, unique_id_,
|
||||
"InternalInitDecoder: init decoder failed for Celt.");
|
||||
return -1;
|
||||
}
|
||||
if (WebRtcCelt_DecoderInitSlave(dec_inst_ptr_) < 0) {
|
||||
WEBRTC_TRACE(webrtc::kTraceError, webrtc::kTraceAudioCoding, _uniqueID,
|
||||
WEBRTC_TRACE(webrtc::kTraceError, webrtc::kTraceAudioCoding, unique_id_,
|
||||
"InternalInitDecoder: init decoder failed for Celt.");
|
||||
return -1;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
int32_t ACMCELT::CodecDef(WebRtcNetEQ_CodecDef& codecDef,
|
||||
const CodecInst& codecInst) {
|
||||
if (!_decoderInitialized) {
|
||||
WEBRTC_TRACE(webrtc::kTraceError, webrtc::kTraceAudioCoding, _uniqueID,
|
||||
int32_t ACMCELT::CodecDef(WebRtcNetEQ_CodecDef& codec_def,
|
||||
const CodecInst& codec_inst) {
|
||||
if (!decoder_initialized_) {
|
||||
WEBRTC_TRACE(webrtc::kTraceError, webrtc::kTraceAudioCoding, unique_id_,
|
||||
"CodecDef: Decoder uninitialized for Celt");
|
||||
return -1;
|
||||
}
|
||||
@ -223,20 +224,20 @@ int32_t ACMCELT::CodecDef(WebRtcNetEQ_CodecDef& codecDef,
|
||||
// "SET_CODEC_PAR" and "SET_CELT_FUNCTIONS" or "SET_CELTSLAVE_FUNCTIONS".
|
||||
// Then call NetEQ to add the codec to it's
|
||||
// database.
|
||||
if (codecInst.channels == 1) {
|
||||
SET_CODEC_PAR(codecDef, kDecoderCELT_32, codecInst.pltype, dec_inst_ptr_,
|
||||
if (codec_inst.channels == 1) {
|
||||
SET_CODEC_PAR(codec_def, kDecoderCELT_32, codec_inst.pltype, dec_inst_ptr_,
|
||||
32000);
|
||||
} else {
|
||||
SET_CODEC_PAR(codecDef, kDecoderCELT_32_2ch, codecInst.pltype,
|
||||
SET_CODEC_PAR(codec_def, kDecoderCELT_32_2ch, codec_inst.pltype,
|
||||
dec_inst_ptr_, 32000);
|
||||
}
|
||||
|
||||
// If this is the master of NetEQ, regular decoder will be added, otherwise
|
||||
// the slave decoder will be used.
|
||||
if (_isMaster) {
|
||||
SET_CELT_FUNCTIONS(codecDef);
|
||||
if (is_master_) {
|
||||
SET_CELT_FUNCTIONS(codec_def);
|
||||
} else {
|
||||
SET_CELTSLAVE_FUNCTIONS(codecDef);
|
||||
SET_CELTSLAVE_FUNCTIONS(codec_def);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
@ -246,18 +247,18 @@ ACMGenericCodec* ACMCELT::CreateInstance(void) {
|
||||
}
|
||||
|
||||
int16_t ACMCELT::InternalCreateEncoder() {
|
||||
if (WebRtcCelt_CreateEnc(&enc_inst_ptr_, _noChannels) < 0) {
|
||||
WEBRTC_TRACE(webrtc::kTraceError, webrtc::kTraceAudioCoding, _uniqueID,
|
||||
if (WebRtcCelt_CreateEnc(&enc_inst_ptr_, num_channels_) < 0) {
|
||||
WEBRTC_TRACE(webrtc::kTraceError, webrtc::kTraceAudioCoding, unique_id_,
|
||||
"InternalCreateEncoder: create encoder failed for Celt");
|
||||
return -1;
|
||||
}
|
||||
channels_ = _noChannels;
|
||||
channels_ = num_channels_;
|
||||
return 0;
|
||||
}
|
||||
|
||||
void ACMCELT::DestructEncoderSafe() {
|
||||
_encoderExist = false;
|
||||
_encoderInitialized = false;
|
||||
encoder_exist_ = false;
|
||||
encoder_initialized_ = false;
|
||||
if (enc_inst_ptr_ != NULL) {
|
||||
WebRtcCelt_FreeEnc(enc_inst_ptr_);
|
||||
enc_inst_ptr_ = NULL;
|
||||
@ -266,7 +267,7 @@ void ACMCELT::DestructEncoderSafe() {
|
||||
|
||||
int16_t ACMCELT::InternalCreateDecoder() {
|
||||
if (WebRtcCelt_CreateDec(&dec_inst_ptr_, dec_channels_) < 0) {
|
||||
WEBRTC_TRACE(webrtc::kTraceError, webrtc::kTraceAudioCoding, _uniqueID,
|
||||
WEBRTC_TRACE(webrtc::kTraceError, webrtc::kTraceAudioCoding, unique_id_,
|
||||
"InternalCreateDecoder: create decoder failed for Celt");
|
||||
return -1;
|
||||
}
|
||||
@ -275,17 +276,17 @@ int16_t ACMCELT::InternalCreateDecoder() {
|
||||
}
|
||||
|
||||
void ACMCELT::DestructDecoderSafe() {
|
||||
_decoderExist = false;
|
||||
_decoderInitialized = false;
|
||||
decoder_exist_ = false;
|
||||
decoder_initialized_ = false;
|
||||
if (dec_inst_ptr_ != NULL) {
|
||||
WebRtcCelt_FreeDec(dec_inst_ptr_);
|
||||
dec_inst_ptr_ = NULL;
|
||||
}
|
||||
}
|
||||
|
||||
void ACMCELT::InternalDestructEncoderInst(void* ptrInst) {
|
||||
if (ptrInst != NULL) {
|
||||
WebRtcCelt_FreeEnc(static_cast<CELT_encinst_t*>(ptrInst));
|
||||
void ACMCELT::InternalDestructEncoderInst(void* ptr_inst) {
|
||||
if (ptr_inst != NULL) {
|
||||
WebRtcCelt_FreeEnc(static_cast<CELT_encinst_t*>(ptr_inst));
|
||||
}
|
||||
return;
|
||||
}
|
||||
@ -304,13 +305,13 @@ int16_t ACMCELT::SetBitRateSafe(const int32_t rate) {
|
||||
if (WebRtcCelt_EncoderInit(enc_inst_ptr_, channels_, bitrate_) >= 0) {
|
||||
return 0;
|
||||
} else {
|
||||
WEBRTC_TRACE(webrtc::kTraceError, webrtc::kTraceAudioCoding, _uniqueID,
|
||||
WEBRTC_TRACE(webrtc::kTraceError, webrtc::kTraceAudioCoding, unique_id_,
|
||||
"SetBitRateSafe: Failed to initiate Celt with rate %d",
|
||||
rate);
|
||||
return -1;
|
||||
}
|
||||
} else {
|
||||
WEBRTC_TRACE(webrtc::kTraceError, webrtc::kTraceAudioCoding, _uniqueID,
|
||||
WEBRTC_TRACE(webrtc::kTraceError, webrtc::kTraceAudioCoding, unique_id_,
|
||||
"SetBitRateSafe: Invalid rate Celt, %d", rate);
|
||||
return -1;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user