Reformating files in audio coding module.

This CL format the ramaining files on the audio coding module. No other changes are done, except for fixing a few long lines and TODOs without owner.

BUG=issue1024

Review URL: https://webrtc-codereview.appspot.com/928012

git-svn-id: http://webrtc.googlecode.com/svn/trunk@3042 4adac7df-926f-26a2-2b94-8c16560cd09d
This commit is contained in:
tina.legrand@webrtc.org 2012-11-05 09:35:51 +00:00
parent a56d759723
commit f7fa6276e2
26 changed files with 5715 additions and 7532 deletions

View File

@ -16,25 +16,10 @@
#include "webrtc_neteq_help_macros.h"
#ifdef WEBRTC_CODEC_G729
// NOTE! G.729 is not included in the open-source package. The following
// interface file is needed:
//
// /modules/audio_coding/codecs/g729/main/interface/g729_interface.h
//
// The API in the header file should match the one below.
//
// int16_t WebRtcG729_CreateEnc(G729_encinst_t_** inst);
// int16_t WebRtcG729_CreateDec(G729_decinst_t_** inst);
// int16_t WebRtcG729_FreeEnc(G729_encinst_t_* inst);
// int16_t WebRtcG729_FreeDec(G729_decinst_t_* inst);
// int16_t WebRtcG729_Encode(G729_encinst_t_* encInst, int16_t* input,
// int16_t len, int16_t* output);
// int16_t WebRtcG729_EncoderInit(G729_encinst_t_* encInst, int16_t mode);
// int16_t WebRtcG729_Decode(G729_decinst_t_* decInst);
// int16_t WebRtcG729_DecodeBwe(G729_decinst_t_* decInst, int16_t* input);
// int16_t WebRtcG729_DecodePlc(G729_decinst_t_* decInst);
// int16_t WebRtcG729_DecoderInit(G729_decinst_t_* decInst);
#include "g729_interface.h"
// NOTE! G.729 is not included in the open-source package. Modify this file
// or your codec API to match the function calls and names of used G.729 API
// file.
#include "g729_interface.h"
#endif
namespace webrtc {
@ -47,469 +32,329 @@ ACMG729::ACMG729(WebRtc_Word16 /* codecID */)
return;
}
ACMG729::~ACMG729()
{
return;
ACMG729::~ACMG729() {
return;
}
WebRtc_Word16
ACMG729::InternalEncode(
WebRtc_UWord8* /* bitStream */,
WebRtc_Word16* /* bitStreamLenByte */)
{
return -1;
WebRtc_Word16 ACMG729::InternalEncode(WebRtc_UWord8* /* bitStream */,
WebRtc_Word16* /* bitStreamLenByte */) {
return -1;
}
WebRtc_Word16
ACMG729::EnableDTX()
{
return -1;
WebRtc_Word16 ACMG729::EnableDTX() {
return -1;
}
WebRtc_Word16
ACMG729::DisableDTX()
{
return -1;
WebRtc_Word16 ACMG729::DisableDTX() {
return -1;
}
WebRtc_Word32
ACMG729::ReplaceInternalDTXSafe(
const bool /*replaceInternalDTX*/)
{
return -1;
WebRtc_Word32 ACMG729::ReplaceInternalDTXSafe(
const bool /*replaceInternalDTX*/) {
return -1;
}
WebRtc_Word32
ACMG729::IsInternalDTXReplacedSafe(
bool* /* internalDTXReplaced */)
{
return -1;
WebRtc_Word32 ACMG729::IsInternalDTXReplacedSafe(
bool* /* internalDTXReplaced */) {
return -1;
}
WebRtc_Word16
ACMG729::DecodeSafe(
WebRtc_UWord8* /* bitStream */,
WebRtc_Word16 /* bitStreamLenByte */,
WebRtc_Word16* /* audio */,
WebRtc_Word16* /* audioSamples */,
WebRtc_Word8* /* speechType */)
{
return -1;
WebRtc_Word16 ACMG729::DecodeSafe(WebRtc_UWord8* /* bitStream */,
WebRtc_Word16 /* bitStreamLenByte */,
WebRtc_Word16* /* audio */,
WebRtc_Word16* /* audioSamples */,
WebRtc_Word8* /* speechType */) {
return -1;
}
WebRtc_Word16
ACMG729::InternalInitEncoder(
WebRtcACMCodecParams* /* codecParams */)
{
return -1;
WebRtc_Word16 ACMG729::InternalInitEncoder(
WebRtcACMCodecParams* /* codecParams */) {
return -1;
}
WebRtc_Word16
ACMG729::InternalInitDecoder(
WebRtcACMCodecParams* /* codecParams */)
{
return -1;
WebRtc_Word16 ACMG729::InternalInitDecoder(
WebRtcACMCodecParams* /* codecParams */) {
return -1;
}
WebRtc_Word32
ACMG729::CodecDef(
WebRtcNetEQ_CodecDef& /* codecDef */,
const CodecInst& /* codecInst */)
{
return -1;
WebRtc_Word32 ACMG729::CodecDef(WebRtcNetEQ_CodecDef& /* codecDef */,
const CodecInst& /* codecInst */) {
return -1;
}
ACMGenericCodec*
ACMG729::CreateInstance(void)
{
return NULL;
ACMGenericCodec* ACMG729::CreateInstance(void) {
return NULL;
}
WebRtc_Word16
ACMG729::InternalCreateEncoder()
{
return -1;
WebRtc_Word16 ACMG729::InternalCreateEncoder() {
return -1;
}
void
ACMG729::DestructEncoderSafe()
{
return;
void ACMG729::DestructEncoderSafe() {
return;
}
WebRtc_Word16
ACMG729::InternalCreateDecoder()
{
return -1;
WebRtc_Word16 ACMG729::InternalCreateDecoder() {
return -1;
}
void
ACMG729::DestructDecoderSafe()
{
return;
void ACMG729::DestructDecoderSafe() {
return;
}
void
ACMG729::InternalDestructEncoderInst(
void* /* ptrInst */)
{
return;
void ACMG729::InternalDestructEncoderInst(void* /* ptrInst */) {
return;
}
#else //===================== Actual Implementation =======================
ACMG729::ACMG729(
WebRtc_Word16 codecID):
_encoderInstPtr(NULL),
_decoderInstPtr(NULL)
{
_codecID = codecID;
_hasInternalDTX = true;
return;
ACMG729::ACMG729(WebRtc_Word16 codecID)
: _encoderInstPtr(NULL),
_decoderInstPtr(NULL) {
_codecID = codecID;
_hasInternalDTX = true;
return;
}
ACMG729::~ACMG729()
{
if(_encoderInstPtr != NULL)
{
// Delete encoder memory
WebRtcG729_FreeEnc(_encoderInstPtr);
_encoderInstPtr = NULL;
}
if(_decoderInstPtr != NULL)
{
// Delete decoder memory
WebRtcG729_FreeDec(_decoderInstPtr);
_decoderInstPtr = NULL;
}
return;
ACMG729::~ACMG729() {
if (_encoderInstPtr != NULL) {
// Delete encoder memory
WebRtcG729_FreeEnc(_encoderInstPtr);
_encoderInstPtr = NULL;
}
if (_decoderInstPtr != NULL) {
// Delete decoder memory
WebRtcG729_FreeDec(_decoderInstPtr);
_decoderInstPtr = NULL;
}
return;
}
WebRtc_Word16 ACMG729::InternalEncode(WebRtc_UWord8* bitStream,
WebRtc_Word16* bitStreamLenByte) {
// Initialize before entering the loop
WebRtc_Word16 noEncodedSamples = 0;
WebRtc_Word16 tmpLenByte = 0;
WebRtc_Word16 vadDecision = 0;
*bitStreamLenByte = 0;
while (noEncodedSamples < _frameLenSmpl) {
// Call G.729 encoder with pointer to encoder memory, input
// audio, number of samples and bitsream
tmpLenByte = WebRtcG729_Encode(
_encoderInstPtr, &_inAudio[_inAudioIxRead], 80,
(WebRtc_Word16*) (&(bitStream[*bitStreamLenByte])));
WebRtc_Word16
ACMG729::InternalEncode(
WebRtc_UWord8* bitStream,
WebRtc_Word16* bitStreamLenByte)
{
// Initialize before entering the loop
WebRtc_Word16 noEncodedSamples = 0;
WebRtc_Word16 tmpLenByte = 0;
WebRtc_Word16 vadDecision = 0;
*bitStreamLenByte = 0;
while(noEncodedSamples < _frameLenSmpl)
{
// Call G.729 encoder with pointer to encoder memory, input
// audio, number of samples and bitsream
tmpLenByte = WebRtcG729_Encode(_encoderInstPtr,
&_inAudio[_inAudioIxRead], 80,
(WebRtc_Word16*)(&(bitStream[*bitStreamLenByte])));
// increment the read index this tell the caller that how far
// we have gone forward in reading the audio buffer
_inAudioIxRead += 80;
// increment the read index this tell the caller that how far
// we have gone forward in reading the audio buffer
_inAudioIxRead += 80;
// sanity check
if(tmpLenByte < 0)
{
// error has happened
*bitStreamLenByte = 0;
return -1;
}
// increment number of written bytes
*bitStreamLenByte += tmpLenByte;
switch(tmpLenByte)
{
case 0:
{
if(0 == noEncodedSamples)
{
// this is the first 10 ms in this packet and there is
// no data generated, perhaps DTX is enabled and the
// codec is not generating any bit-stream for this 10 ms.
// we do not continue encoding this frame.
return 0;
}
break;
}
case 2:
{
// check if G.729 internal DTX is enabled
if(_hasInternalDTX && _dtxEnabled)
{
vadDecision = 0;
for(WebRtc_Word16 n = 0; n < MAX_FRAME_SIZE_10MSEC; n++)
{
_vadLabel[n] = vadDecision;
}
}
// we got a SID and have to send out this packet no matter
// how much audio we have encoded
return *bitStreamLenByte;
}
case 10:
{
vadDecision = 1;
// this is a valid length just continue encoding
break;
}
default:
{
return -1;
}
}
// update number of encoded samples
noEncodedSamples += 80;
// sanity check
if (tmpLenByte < 0) {
// error has happened
*bitStreamLenByte = 0;
return -1;
}
// update VAD decision vector
if(_hasInternalDTX && !vadDecision && _dtxEnabled)
{
for(WebRtc_Word16 n = 0; n < MAX_FRAME_SIZE_10MSEC; n++)
{
// increment number of written bytes
*bitStreamLenByte += tmpLenByte;
switch (tmpLenByte) {
case 0: {
if (0 == noEncodedSamples) {
// this is the first 10 ms in this packet and there is
// no data generated, perhaps DTX is enabled and the
// codec is not generating any bit-stream for this 10 ms.
// we do not continue encoding this frame.
return 0;
}
break;
}
case 2: {
// check if G.729 internal DTX is enabled
if (_hasInternalDTX && _dtxEnabled) {
vadDecision = 0;
for (WebRtc_Word16 n = 0; n < MAX_FRAME_SIZE_10MSEC; n++) {
_vadLabel[n] = vadDecision;
}
}
}
// done encoding, return number of encoded bytes
return *bitStreamLenByte;
}
WebRtc_Word16
ACMG729::EnableDTX()
{
if(_dtxEnabled)
{
// DTX already enabled, do nothing
return 0;
}
else if(_encoderExist)
{
// Re-init the G.729 encoder to turn on DTX
if(WebRtcG729_EncoderInit(_encoderInstPtr, 1) < 0)
{
return -1;
}
_dtxEnabled = true;
return 0;
}
else
{
// we got a SID and have to send out this packet no matter
// how much audio we have encoded
return *bitStreamLenByte;
}
case 10: {
vadDecision = 1;
// this is a valid length just continue encoding
break;
}
default: {
return -1;
}
}
// update number of encoded samples
noEncodedSamples += 80;
}
// update VAD decision vector
if (_hasInternalDTX && !vadDecision && _dtxEnabled) {
for (WebRtc_Word16 n = 0; n < MAX_FRAME_SIZE_10MSEC; n++) {
_vadLabel[n] = vadDecision;
}
}
// done encoding, return number of encoded bytes
return *bitStreamLenByte;
}
WebRtc_Word16
ACMG729::DisableDTX()
{
if(!_dtxEnabled)
{
// DTX already dissabled, do nothing
return 0;
}
else if(_encoderExist)
{
// Re-init the G.729 decoder to turn off DTX
if(WebRtcG729_EncoderInit(_encoderInstPtr, 0) < 0)
{
return -1;
}
_dtxEnabled = false;
return 0;
}
else
{
// encoder doesn't exists, therefore disabling is harmless
return 0;
}
}
WebRtc_Word32
ACMG729::ReplaceInternalDTXSafe(
const bool replaceInternalDTX)
{
// This function is used to dissable the G.729 built in DTX and use an
// external instead.
if(replaceInternalDTX == _hasInternalDTX)
{
// Make sure we keep the DTX/VAD setting if possible
bool oldEnableDTX = _dtxEnabled;
bool oldEnableVAD = _vadEnabled;
ACMVADMode oldMode = _vadMode;
if (replaceInternalDTX)
{
// Disable internal DTX before enabling external DTX
DisableDTX();
}
else
{
// Disable external DTX before enabling internal
ACMGenericCodec::DisableDTX();
}
_hasInternalDTX = !replaceInternalDTX;
WebRtc_Word16 status = SetVADSafe(oldEnableDTX, oldEnableVAD, oldMode);
// Check if VAD status has changed from inactive to active, or if error was
// reported
if (status == 1) {
_vadEnabled = true;
return status;
} else if (status < 0) {
_hasInternalDTX = replaceInternalDTX;
return -1;
}
}
WebRtc_Word16 ACMG729::EnableDTX() {
if (_dtxEnabled) {
// DTX already enabled, do nothing
return 0;
}
WebRtc_Word32
ACMG729::IsInternalDTXReplacedSafe(
bool* internalDTXReplaced)
{
// Get status of wether DTX is replaced or not
*internalDTXReplaced = !_hasInternalDTX;
} else if (_encoderExist) {
// Re-init the G.729 encoder to turn on DTX
if (WebRtcG729_EncoderInit(_encoderInstPtr, 1) < 0) {
return -1;
}
_dtxEnabled = true;
return 0;
} else {
return -1;
}
}
WebRtc_Word16
ACMG729::DecodeSafe(
WebRtc_UWord8* /* bitStream */,
WebRtc_Word16 /* bitStreamLenByte */,
WebRtc_Word16* /* audio */,
WebRtc_Word16* /* audioSamples */,
WebRtc_Word8* /* speechType */)
{
// This function is not used. G.729 decoder is called from inside NetEQ
WebRtc_Word16 ACMG729::DisableDTX() {
if (!_dtxEnabled) {
// DTX already dissabled, do nothing
return 0;
}
WebRtc_Word16
ACMG729::InternalInitEncoder(
WebRtcACMCodecParams* codecParams)
{
// Init G.729 encoder
return WebRtcG729_EncoderInit(_encoderInstPtr,
((codecParams->enableDTX)? 1:0));
}
WebRtc_Word16
ACMG729::InternalInitDecoder(
WebRtcACMCodecParams* /* codecParams */)
{
// Init G.729 decoder
return WebRtcG729_DecoderInit(_decoderInstPtr);
}
WebRtc_Word32
ACMG729::CodecDef(
WebRtcNetEQ_CodecDef& codecDef,
const CodecInst& codecInst)
{
if (!_decoderInitialized)
{
// Todo:
// log error
return -1;
} else if (_encoderExist) {
// Re-init the G.729 decoder to turn off DTX
if (WebRtcG729_EncoderInit(_encoderInstPtr, 0) < 0) {
return -1;
}
// Fill up the structure by calling
// "SET_CODEC_PAR" & "SET_G729_FUNCTION."
// Then call NetEQ to add the codec to it's
// database.
SET_CODEC_PAR((codecDef), kDecoderG729, codecInst.pltype,
_decoderInstPtr, 8000);
SET_G729_FUNCTIONS((codecDef));
_dtxEnabled = false;
return 0;
} else {
// encoder doesn't exists, therefore disabling is harmless
return 0;
}
}
WebRtc_Word32 ACMG729::ReplaceInternalDTXSafe(const bool replaceInternalDTX) {
// This function is used to disable the G.729 built in DTX and use an
// external instead.
ACMGenericCodec*
ACMG729::CreateInstance(void)
{
// Function not used
return NULL;
}
WebRtc_Word16
ACMG729::InternalCreateEncoder()
{
// Create encoder memory
return WebRtcG729_CreateEnc(&_encoderInstPtr);
}
void
ACMG729::DestructEncoderSafe()
{
// Free encoder memory
_encoderExist = false;
_encoderInitialized = false;
if(_encoderInstPtr != NULL)
{
WebRtcG729_FreeEnc(_encoderInstPtr);
_encoderInstPtr = NULL;
if (replaceInternalDTX == _hasInternalDTX) {
// Make sure we keep the DTX/VAD setting if possible
bool oldEnableDTX = _dtxEnabled;
bool oldEnableVAD = _vadEnabled;
ACMVADMode oldMode = _vadMode;
if (replaceInternalDTX) {
// Disable internal DTX before enabling external DTX
DisableDTX();
} else {
// Disable external DTX before enabling internal
ACMGenericCodec::DisableDTX();
}
}
WebRtc_Word16
ACMG729::InternalCreateDecoder()
{
// Create decoder memory
return WebRtcG729_CreateDec(&_decoderInstPtr);
}
void
ACMG729::DestructDecoderSafe()
{
// Free decoder memory
_decoderExist = false;
_decoderInitialized = false;
if(_decoderInstPtr != NULL)
{
WebRtcG729_FreeDec(_decoderInstPtr);
_decoderInstPtr = NULL;
_hasInternalDTX = !replaceInternalDTX;
WebRtc_Word16 status = SetVADSafe(oldEnableDTX, oldEnableVAD, oldMode);
// Check if VAD status has changed from inactive to active, or if error was
// reported
if (status == 1) {
_vadEnabled = true;
return status;
} else if (status < 0) {
_hasInternalDTX = replaceInternalDTX;
return -1;
}
}
return 0;
}
WebRtc_Word32 ACMG729::IsInternalDTXReplacedSafe(bool* internalDTXReplaced) {
// Get status of wether DTX is replaced or not
*internalDTXReplaced = !_hasInternalDTX;
return 0;
}
void
ACMG729::InternalDestructEncoderInst(
void* ptrInst)
{
if(ptrInst != NULL)
{
WebRtcG729_FreeEnc((G729_encinst_t_*)ptrInst);
}
return;
WebRtc_Word16 ACMG729::DecodeSafe(WebRtc_UWord8* /* bitStream */,
WebRtc_Word16 /* bitStreamLenByte */,
WebRtc_Word16* /* audio */,
WebRtc_Word16* /* audioSamples */,
WebRtc_Word8* /* speechType */) {
// This function is not used. G.729 decoder is called from inside NetEQ
return 0;
}
WebRtc_Word16 ACMG729::InternalInitEncoder(WebRtcACMCodecParams* codecParams) {
// Init G.729 encoder
return WebRtcG729_EncoderInit(_encoderInstPtr,
((codecParams->enableDTX) ? 1 : 0));
}
WebRtc_Word16 ACMG729::InternalInitDecoder(
WebRtcACMCodecParams* /* codecParams */) {
// Init G.729 decoder
return WebRtcG729_DecoderInit(_decoderInstPtr);
}
WebRtc_Word32 ACMG729::CodecDef(WebRtcNetEQ_CodecDef& codecDef,
const CodecInst& codecInst) {
if (!_decoderInitialized) {
// Todo:
// log error
return -1;
}
// Fill up the structure by calling
// "SET_CODEC_PAR" & "SET_G729_FUNCTION."
// Then call NetEQ to add the codec to it's
// database.
SET_CODEC_PAR((codecDef), kDecoderG729, codecInst.pltype, _decoderInstPtr,
8000);
SET_G729_FUNCTIONS((codecDef));
return 0;
}
ACMGenericCodec* ACMG729::CreateInstance(void) {
// Function not used
return NULL;
}
WebRtc_Word16 ACMG729::InternalCreateEncoder() {
// Create encoder memory
return WebRtcG729_CreateEnc(&_encoderInstPtr);
}
void ACMG729::DestructEncoderSafe() {
// Free encoder memory
_encoderExist = false;
_encoderInitialized = false;
if (_encoderInstPtr != NULL) {
WebRtcG729_FreeEnc(_encoderInstPtr);
_encoderInstPtr = NULL;
}
}
WebRtc_Word16 ACMG729::InternalCreateDecoder() {
// Create decoder memory
return WebRtcG729_CreateDec(&_decoderInstPtr);
}
void ACMG729::DestructDecoderSafe() {
// Free decoder memory
_decoderExist = false;
_decoderInitialized = false;
if (_decoderInstPtr != NULL) {
WebRtcG729_FreeDec(_decoderInstPtr);
_decoderInstPtr = NULL;
}
}
void ACMG729::InternalDestructEncoderInst(void* ptrInst) {
if (ptrInst != NULL) {
WebRtcG729_FreeEnc((G729_encinst_t_*) ptrInst);
}
return;
}
#endif
} // namespace webrtc
} // namespace webrtc

View File

@ -19,62 +19,53 @@ struct G729_decinst_t_;
namespace webrtc {
class ACMG729 : public ACMGenericCodec
{
public:
ACMG729(WebRtc_Word16 codecID);
~ACMG729();
// for FEC
ACMGenericCodec* CreateInstance(void);
class ACMG729 : public ACMGenericCodec {
public:
ACMG729(WebRtc_Word16 codecID);
~ACMG729();
// for FEC
ACMGenericCodec* CreateInstance(void);
WebRtc_Word16 InternalEncode(
WebRtc_UWord8* bitstream,
WebRtc_Word16* bitStreamLenByte);
WebRtc_Word16 InternalEncode(WebRtc_UWord8* bitstream,
WebRtc_Word16* bitStreamLenByte);
WebRtc_Word16 InternalInitEncoder(
WebRtcACMCodecParams *codecParams);
WebRtc_Word16 InternalInitEncoder(WebRtcACMCodecParams *codecParams);
WebRtc_Word16 InternalInitDecoder(
WebRtcACMCodecParams *codecParams);
WebRtc_Word16 InternalInitDecoder(WebRtcACMCodecParams *codecParams);
protected:
WebRtc_Word16 DecodeSafe(
WebRtc_UWord8* bitStream,
WebRtc_Word16 bitStreamLenByte,
WebRtc_Word16* audio,
WebRtc_Word16* audioSamples,
WebRtc_Word8* speechType);
protected:
WebRtc_Word16 DecodeSafe(WebRtc_UWord8* bitStream,
WebRtc_Word16 bitStreamLenByte,
WebRtc_Word16* audio,
WebRtc_Word16* audioSamples,
WebRtc_Word8* speechType);
WebRtc_Word32 CodecDef(
WebRtcNetEQ_CodecDef& codecDef,
const CodecInst& codecInst);
WebRtc_Word32 CodecDef(WebRtcNetEQ_CodecDef& codecDef,
const CodecInst& codecInst);
void DestructEncoderSafe();
void DestructEncoderSafe();
void DestructDecoderSafe();
void DestructDecoderSafe();
WebRtc_Word16 InternalCreateEncoder();
WebRtc_Word16 InternalCreateEncoder();
WebRtc_Word16 InternalCreateDecoder();
WebRtc_Word16 InternalCreateDecoder();
void InternalDestructEncoderInst(
void* ptrInst);
void InternalDestructEncoderInst(void* ptrInst);
WebRtc_Word16 EnableDTX();
WebRtc_Word16 EnableDTX();
WebRtc_Word16 DisableDTX();
WebRtc_Word16 DisableDTX();
WebRtc_Word32 ReplaceInternalDTXSafe(
const bool replaceInternalDTX);
WebRtc_Word32 ReplaceInternalDTXSafe(const bool replaceInternalDTX);
WebRtc_Word32 IsInternalDTXReplacedSafe(
bool* internalDTXReplaced);
WebRtc_Word32 IsInternalDTXReplacedSafe(bool* internalDTXReplaced);
G729_encinst_t_* _encoderInstPtr;
G729_decinst_t_* _decoderInstPtr;
G729_encinst_t_* _encoderInstPtr;
G729_decinst_t_* _decoderInstPtr;
};
} // namespace webrtc
} // namespace webrtc
#endif // WEBRTC_MODULES_AUDIO_CODING_MAIN_SOURCE_ACM_G729_H_

View File

@ -16,24 +16,9 @@
#include "webrtc_neteq_help_macros.h"
#ifdef WEBRTC_CODEC_G729_1
// NOTE! G.729.1 is not included in the open-source package. The following
// interface file is needed:
//
// /modules/audio_coding/codecs/g7291/main/interface/g7291_interface.h
//
// The API in the header file should match the one below.
//
// int16_t WebRtcG7291_Create(G729_1_inst_t_** inst);
// int16_t WebRtcG7291_Free(G729_1_inst_t_* inst);
// int16_t WebRtcG7291_Encode(G729_1_inst_t_* encInst, int16_t* input,
// int16_t* output, int16_t myRate,
// int16_t nrFrames);
// int16_t WebRtcG7291_EncoderInit(G729_1_inst_t_* encInst, int16_t myRate,
// int16_t flag8kHz, int16_t flagG729mode);
// int16_t WebRtcG7291_Decode(G729_1_inst_t_* decInst);
// int16_t WebRtcG7291_DecodeBwe(G729_1_inst_t_* decInst, int16_t* input);
// int16_t WebRtcG7291_DecodePlc(G729_1_inst_t_* decInst);
// int16_t WebRtcG7291_DecoderInit(G729_1_inst_t_* decInst);
// NOTE! G.729.1 is not included in the open-source package. Modify this file
// or your codec API to match the function calls and names of used G.729.1 API
// file.
#include "g7291_interface.h"
#endif
@ -41,7 +26,7 @@ namespace webrtc {
#ifndef WEBRTC_CODEC_G729_1
ACMG729_1::ACMG729_1( WebRtc_Word16 /* codecID */)
ACMG729_1::ACMG729_1(WebRtc_Word16 /* codecID */)
: _encoderInstPtr(NULL),
_decoderInstPtr(NULL),
_myRate(32000),
@ -50,105 +35,63 @@ ACMG729_1::ACMG729_1( WebRtc_Word16 /* codecID */)
return;
}
ACMG729_1::~ACMG729_1()
{
return;
ACMG729_1::~ACMG729_1() {
return;
}
WebRtc_Word16
ACMG729_1::InternalEncode(
WebRtc_UWord8* /* bitStream */,
WebRtc_Word16* /* bitStreamLenByte */)
{
return -1;
WebRtc_Word16 ACMG729_1::InternalEncode(WebRtc_UWord8* /* bitStream */,
WebRtc_Word16* /* bitStreamLenByte */) {
return -1;
}
WebRtc_Word16
ACMG729_1::DecodeSafe(
WebRtc_UWord8* /* bitStream */,
WebRtc_Word16 /* bitStreamLenByte */,
WebRtc_Word16* /* audio */,
WebRtc_Word16* /* audioSamples */,
WebRtc_Word8* /* speechType */)
{
return -1;
WebRtc_Word16 ACMG729_1::DecodeSafe(WebRtc_UWord8* /* bitStream */,
WebRtc_Word16 /* bitStreamLenByte */,
WebRtc_Word16* /* audio */,
WebRtc_Word16* /* audioSamples */,
WebRtc_Word8* /* speechType */) {
return -1;
}
WebRtc_Word16
ACMG729_1::InternalInitEncoder(
WebRtcACMCodecParams* /* codecParams */)
{
return -1;
WebRtc_Word16 ACMG729_1::InternalInitEncoder(
WebRtcACMCodecParams* /* codecParams */) {
return -1;
}
WebRtc_Word16
ACMG729_1::InternalInitDecoder(
WebRtcACMCodecParams* /* codecParams */)
{
return -1;
WebRtc_Word16 ACMG729_1::InternalInitDecoder(
WebRtcACMCodecParams* /* codecParams */) {
return -1;
}
WebRtc_Word32
ACMG729_1::CodecDef(
WebRtcNetEQ_CodecDef& /* codecDef */,
const CodecInst& /* codecInst */)
{
return -1;
WebRtc_Word32 ACMG729_1::CodecDef(WebRtcNetEQ_CodecDef& /* codecDef */,
const CodecInst& /* codecInst */) {
return -1;
}
ACMGenericCodec*
ACMG729_1::CreateInstance(void)
{
return NULL;
ACMGenericCodec* ACMG729_1::CreateInstance(void) {
return NULL;
}
WebRtc_Word16
ACMG729_1::InternalCreateEncoder()
{
return -1;
WebRtc_Word16 ACMG729_1::InternalCreateEncoder() {
return -1;
}
void
ACMG729_1::DestructEncoderSafe()
{
return;
void ACMG729_1::DestructEncoderSafe() {
return;
}
WebRtc_Word16
ACMG729_1::InternalCreateDecoder()
{
return -1;
WebRtc_Word16 ACMG729_1::InternalCreateDecoder() {
return -1;
}
void
ACMG729_1::DestructDecoderSafe()
{
return;
void ACMG729_1::DestructDecoderSafe() {
return;
}
void
ACMG729_1::InternalDestructEncoderInst(
void* /* ptrInst */)
{
return;
void ACMG729_1::InternalDestructEncoderInst(void* /* ptrInst */) {
return;
}
WebRtc_Word16
ACMG729_1::SetBitRateSafe(
const WebRtc_Word32 /*rate*/ )
{
WebRtc_Word16 ACMG729_1::SetBitRateSafe(const WebRtc_Word32 /*rate*/) {
return -1;
}
@ -168,304 +111,233 @@ ACMG729_1::ACMG729_1(WebRtc_Word16 codecID)
return;
}
ACMG729_1::~ACMG729_1()
{
if(_encoderInstPtr != NULL)
{
WebRtcG7291_Free(_encoderInstPtr);
_encoderInstPtr = NULL;
}
if(_decoderInstPtr != NULL)
{
WebRtcG7291_Free(_decoderInstPtr);
_decoderInstPtr = NULL;
}
return;
ACMG729_1::~ACMG729_1() {
if (_encoderInstPtr != NULL) {
WebRtcG7291_Free(_encoderInstPtr);
_encoderInstPtr = NULL;
}
if (_decoderInstPtr != NULL) {
WebRtcG7291_Free(_decoderInstPtr);
_decoderInstPtr = NULL;
}
return;
}
WebRtc_Word16 ACMG729_1::InternalEncode(WebRtc_UWord8* bitStream,
WebRtc_Word16* bitStreamLenByte) {
WebRtc_Word16
ACMG729_1::InternalEncode(
WebRtc_UWord8* bitStream,
WebRtc_Word16* bitStreamLenByte)
{
// Initialize before entering the loop
WebRtc_Word16 noEncodedSamples = 0;
*bitStreamLenByte = 0;
// Initialize before entering the loop
WebRtc_Word16 noEncodedSamples = 0;
*bitStreamLenByte = 0;
WebRtc_Word16 byteLengthFrame = 0;
// Derive number of 20ms frames per encoded packet.
// Derive number of 20ms frames per encoded packet.
// [1,2,3] <=> [20,40,60]ms <=> [320,640,960] samples
WebRtc_Word16 n20msFrames = (_frameLenSmpl / 320);
// Byte length for the frame. +1 is for rate information.
byteLengthFrame = _myRate/(8*50) * n20msFrames + (1 - _flagG729mode);
WebRtc_Word16 n20msFrames = (_frameLenSmpl / 320);
// Byte length for the frame. +1 is for rate information.
byteLengthFrame = _myRate / (8 * 50) * n20msFrames + (1 - _flagG729mode);
// The following might be revised if we have G729.1 Annex C (support for DTX);
do
{
*bitStreamLenByte = WebRtcG7291_Encode(_encoderInstPtr, &_inAudio[_inAudioIxRead],
(WebRtc_Word16*)bitStream, _myRate, n20msFrames);
// The following might be revised if we have G729.1 Annex C (support for DTX);
do {
*bitStreamLenByte = WebRtcG7291_Encode(_encoderInstPtr,
&_inAudio[_inAudioIxRead],
(WebRtc_Word16*) bitStream, _myRate,
n20msFrames);
// increment the read index this tell the caller that how far
// we have gone forward in reading the audio buffer
// increment the read index this tell the caller that how far
// we have gone forward in reading the audio buffer
_inAudioIxRead += 160;
// sanity check
if(*bitStreamLenByte < 0)
{
// sanity check
if (*bitStreamLenByte < 0) {
// error has happened
WEBRTC_TRACE(webrtc::kTraceError, webrtc::kTraceAudioCoding, _uniqueID,
"InternalEncode: Encode error for G729_1");
*bitStreamLenByte = 0;
return -1;
}
noEncodedSamples += 160;
} while(*bitStreamLenByte == 0);
// This criteria will change if we have Annex C.
if(*bitStreamLenByte != byteLengthFrame)
{
WEBRTC_TRACE(webrtc::kTraceError, webrtc::kTraceAudioCoding, _uniqueID,
"InternalEncode: Encode error for G729_1");
*bitStreamLenByte = 0;
return -1;
}
if(noEncodedSamples != _frameLenSmpl)
{
*bitStreamLenByte = 0;
return -1;
}
return *bitStreamLenByte;
}
WebRtc_Word16
ACMG729_1::DecodeSafe(
WebRtc_UWord8* /* bitStream */,
WebRtc_Word16 /* bitStreamLenByte */,
WebRtc_Word16* /* audio */,
WebRtc_Word16* /* audioSamples */,
WebRtc_Word8* /* speechType */)
{
return 0;
}
WebRtc_Word16
ACMG729_1::InternalInitEncoder(
WebRtcACMCodecParams* codecParams)
{
//set the bit rate and initialize
_myRate = codecParams->codecInstant.rate;
return SetBitRateSafe( (WebRtc_UWord32)_myRate);
}
WebRtc_Word16
ACMG729_1::InternalInitDecoder(
WebRtcACMCodecParams* /* codecParams */)
{
if (WebRtcG7291_DecoderInit(_decoderInstPtr) < 0)
{
WEBRTC_TRACE(webrtc::kTraceError, webrtc::kTraceAudioCoding, _uniqueID,
"InternalInitDecoder: init decoder failed for G729_1");
return -1;
}
return 0;
}
WebRtc_Word32
ACMG729_1::CodecDef(
WebRtcNetEQ_CodecDef& codecDef,
const CodecInst& codecInst)
{
if (!_decoderInitialized)
{
WEBRTC_TRACE(webrtc::kTraceError, webrtc::kTraceAudioCoding, _uniqueID,
"CodeDef: Decoder uninitialized for G729_1");
"InternalEncode: Encode error for G729_1");
*bitStreamLenByte = 0;
return -1;
}
// Fill up the structure by calling
// "SET_CODEC_PAR" & "SET_G729_FUNCTION."
// Then call NetEQ to add the codec to it's
// database.
SET_CODEC_PAR((codecDef), kDecoderG729_1, codecInst.pltype,
_decoderInstPtr, 16000);
SET_G729_1_FUNCTIONS((codecDef));
return 0;
}
noEncodedSamples += 160;
} while (*bitStreamLenByte == 0);
ACMGenericCodec*
ACMG729_1::CreateInstance(void)
{
return NULL;
}
WebRtc_Word16
ACMG729_1::InternalCreateEncoder()
{
if (WebRtcG7291_Create(&_encoderInstPtr) < 0)
{
// This criteria will change if we have Annex C.
if (*bitStreamLenByte != byteLengthFrame) {
WEBRTC_TRACE(webrtc::kTraceError, webrtc::kTraceAudioCoding, _uniqueID,
"InternalCreateEncoder: create encoder failed for G729_1");
"InternalEncode: Encode error for G729_1");
*bitStreamLenByte = 0;
return -1;
}
if (noEncodedSamples != _frameLenSmpl) {
*bitStreamLenByte = 0;
return -1;
}
return *bitStreamLenByte;
}
WebRtc_Word16 ACMG729_1::DecodeSafe(WebRtc_UWord8* /* bitStream */,
WebRtc_Word16 /* bitStreamLenByte */,
WebRtc_Word16* /* audio */,
WebRtc_Word16* /* audioSamples */,
WebRtc_Word8* /* speechType */) {
return 0;
}
WebRtc_Word16 ACMG729_1::InternalInitEncoder(
WebRtcACMCodecParams* codecParams) {
//set the bit rate and initialize
_myRate = codecParams->codecInstant.rate;
return SetBitRateSafe((WebRtc_UWord32) _myRate);
}
WebRtc_Word16 ACMG729_1::InternalInitDecoder(
WebRtcACMCodecParams* /* codecParams */) {
if (WebRtcG7291_DecoderInit(_decoderInstPtr) < 0) {
WEBRTC_TRACE(webrtc::kTraceError, webrtc::kTraceAudioCoding, _uniqueID,
"InternalInitDecoder: init decoder failed for G729_1");
return -1;
}
return 0;
}
WebRtc_Word32 ACMG729_1::CodecDef(WebRtcNetEQ_CodecDef& codecDef,
const CodecInst& codecInst) {
if (!_decoderInitialized) {
WEBRTC_TRACE(webrtc::kTraceError, webrtc::kTraceAudioCoding, _uniqueID,
"CodeDef: Decoder uninitialized for G729_1");
return -1;
}
void
ACMG729_1::DestructEncoderSafe()
{
_encoderExist = false;
_encoderInitialized = false;
if(_encoderInstPtr != NULL)
{
WebRtcG7291_Free(_encoderInstPtr);
_encoderInstPtr = NULL;
}
// Fill up the structure by calling
// "SET_CODEC_PAR" & "SET_G729_FUNCTION."
// Then call NetEQ to add the codec to it's
// database.
SET_CODEC_PAR((codecDef), kDecoderG729_1, codecInst.pltype, _decoderInstPtr,
16000);
SET_G729_1_FUNCTIONS((codecDef));
return 0;
}
ACMGenericCodec* ACMG729_1::CreateInstance(void) {
return NULL;
}
WebRtc_Word16
ACMG729_1::InternalCreateDecoder()
{
if (WebRtcG7291_Create(&_decoderInstPtr) < 0)
{
WebRtc_Word16 ACMG729_1::InternalCreateEncoder() {
if (WebRtcG7291_Create(&_encoderInstPtr) < 0) {
WEBRTC_TRACE(webrtc::kTraceError, webrtc::kTraceAudioCoding, _uniqueID,
"InternalCreateEncoder: create encoder failed for G729_1");
return -1;
}
return 0;
}
void ACMG729_1::DestructEncoderSafe() {
_encoderExist = false;
_encoderInitialized = false;
if (_encoderInstPtr != NULL) {
WebRtcG7291_Free(_encoderInstPtr);
_encoderInstPtr = NULL;
}
}
WebRtc_Word16 ACMG729_1::InternalCreateDecoder() {
if (WebRtcG7291_Create(&_decoderInstPtr) < 0) {
WEBRTC_TRACE(webrtc::kTraceError, webrtc::kTraceAudioCoding, _uniqueID,
"InternalCreateDecoder: create decoder failed for G729_1");
return -1;
}
return 0;
}
void ACMG729_1::DestructDecoderSafe() {
_decoderExist = false;
_decoderInitialized = false;
if (_decoderInstPtr != NULL) {
WebRtcG7291_Free(_decoderInstPtr);
_decoderInstPtr = NULL;
}
}
void ACMG729_1::InternalDestructEncoderInst(void* ptrInst) {
if (ptrInst != NULL) {
//WebRtcG7291_Free((G729_1_inst_t*)ptrInst);
}
return;
}
WebRtc_Word16 ACMG729_1::SetBitRateSafe(const WebRtc_Word32 rate) {
//allowed rates: { 8000, 12000, 14000, 16000, 18000, 20000,
// 22000, 24000, 26000, 28000, 30000, 32000};
// TODO(tlegrand): This check exists in one other place two. Should be
// possible to reuse code.
switch (rate) {
case 8000: {
_myRate = 8000;
break;
}
case 12000: {
_myRate = 12000;
break;
}
case 14000: {
_myRate = 14000;
break;
}
case 16000: {
_myRate = 16000;
break;
}
case 18000: {
_myRate = 18000;
break;
}
case 20000: {
_myRate = 20000;
break;
}
case 22000: {
_myRate = 22000;
break;
}
case 24000: {
_myRate = 24000;
break;
}
case 26000: {
_myRate = 26000;
break;
}
case 28000: {
_myRate = 28000;
break;
}
case 30000: {
_myRate = 30000;
break;
}
case 32000: {
_myRate = 32000;
break;
}
default: {
WEBRTC_TRACE(webrtc::kTraceError, webrtc::kTraceAudioCoding, _uniqueID,
"InternalCreateDecoder: create decoder failed for G729_1");
return -1;
}
return 0;
"SetBitRateSafe: Invalid rate G729_1");
return -1;
}
}
// Re-init with new rate
if (WebRtcG7291_EncoderInit(_encoderInstPtr, _myRate, _flag8kHz,
_flagG729mode) >= 0) {
_encoderParams.codecInstant.rate = _myRate;
return 0;
} else {
return -1;
}
}
void
ACMG729_1::DestructDecoderSafe()
{
_decoderExist = false;
_decoderInitialized = false;
if(_decoderInstPtr != NULL)
{
WebRtcG7291_Free(_decoderInstPtr);
_decoderInstPtr = NULL;
}
}
void
ACMG729_1::InternalDestructEncoderInst(
void* ptrInst)
{
if(ptrInst != NULL)
{
//WebRtcG7291_Free((G729_1_inst_t*)ptrInst);
}
return;
}
WebRtc_Word16
ACMG729_1::SetBitRateSafe(
const WebRtc_Word32 rate)
{
//allowed rates: { 8000, 12000, 14000, 16000, 18000, 20000,
// 22000, 24000, 26000, 28000, 30000, 32000};
// TODO(tlegrand): This check exists in one other place two. Should be
// possible to reuse code.
switch(rate)
{
case 8000:
{
_myRate = 8000;
break;
}
case 12000:
{
_myRate = 12000;
break;
}
case 14000:
{
_myRate = 14000;
break;
}
case 16000:
{
_myRate = 16000;
break;
}
case 18000:
{
_myRate = 18000;
break;
}
case 20000:
{
_myRate = 20000;
break;
}
case 22000:
{
_myRate = 22000;
break;
}
case 24000:
{
_myRate = 24000;
break;
}
case 26000:
{
_myRate = 26000;
break;
}
case 28000:
{
_myRate = 28000;
break;
}
case 30000:
{
_myRate = 30000;
break;
}
case 32000:
{
_myRate = 32000;
break;
}
default:
{
WEBRTC_TRACE(webrtc::kTraceError, webrtc::kTraceAudioCoding, _uniqueID,
"SetBitRateSafe: Invalid rate G729_1");
return -1;
}
}
// Re-init with new rate
if (WebRtcG7291_EncoderInit(_encoderInstPtr, _myRate, _flag8kHz, _flagG729mode) >= 0)
{
_encoderParams.codecInstant.rate = _myRate;
return 0;
}
else
{
return -1;
}
}
#endif
} // namespace webrtc
} // namespace webrtc

View File

@ -19,59 +19,50 @@ struct G729_1_inst_t_;
namespace webrtc {
class ACMG729_1: public ACMGenericCodec
{
public:
ACMG729_1(WebRtc_Word16 codecID);
~ACMG729_1();
// for FEC
ACMGenericCodec* CreateInstance(void);
class ACMG729_1 : public ACMGenericCodec {
public:
ACMG729_1(WebRtc_Word16 codecID);
~ACMG729_1();
// for FEC
ACMGenericCodec* CreateInstance(void);
WebRtc_Word16 InternalEncode(
WebRtc_UWord8* bitstream,
WebRtc_Word16* bitStreamLenByte);
WebRtc_Word16 InternalEncode(WebRtc_UWord8* bitstream,
WebRtc_Word16* bitStreamLenByte);
WebRtc_Word16 InternalInitEncoder(
WebRtcACMCodecParams *codecParams);
WebRtc_Word16 InternalInitEncoder(WebRtcACMCodecParams *codecParams);
WebRtc_Word16 InternalInitDecoder(
WebRtcACMCodecParams *codecParams);
WebRtc_Word16 InternalInitDecoder(WebRtcACMCodecParams *codecParams);
protected:
WebRtc_Word16 DecodeSafe(
WebRtc_UWord8* bitStream,
WebRtc_Word16 bitStreamLenByte,
WebRtc_Word16* audio,
WebRtc_Word16* audioSamples,
WebRtc_Word8* speechType);
protected:
WebRtc_Word16 DecodeSafe(WebRtc_UWord8* bitStream,
WebRtc_Word16 bitStreamLenByte,
WebRtc_Word16* audio,
WebRtc_Word16* audioSamples,
WebRtc_Word8* speechType);
WebRtc_Word32 CodecDef(
WebRtcNetEQ_CodecDef& codecDef,
const CodecInst& codecInst);
WebRtc_Word32 CodecDef(WebRtcNetEQ_CodecDef& codecDef,
const CodecInst& codecInst);
void DestructEncoderSafe();
void DestructEncoderSafe();
void DestructDecoderSafe();
void DestructDecoderSafe();
WebRtc_Word16 InternalCreateEncoder();
WebRtc_Word16 InternalCreateEncoder();
WebRtc_Word16 InternalCreateDecoder();
WebRtc_Word16 InternalCreateDecoder();
void InternalDestructEncoderInst(
void* ptrInst);
void InternalDestructEncoderInst(void* ptrInst);
WebRtc_Word16 SetBitRateSafe(
const WebRtc_Word32 rate);
WebRtc_Word16 SetBitRateSafe(const WebRtc_Word32 rate);
G729_1_inst_t_* _encoderInstPtr;
G729_1_inst_t_* _decoderInstPtr;
WebRtc_UWord16 _myRate;
WebRtc_Word16 _flag8kHz;
WebRtc_Word16 _flagG729mode;
G729_1_inst_t_* _encoderInstPtr;
G729_1_inst_t_* _decoderInstPtr;
WebRtc_UWord16 _myRate;
WebRtc_Word16 _flag8kHz;
WebRtc_Word16 _flagG729mode;
};
} // namespace webrtc
} // namespace webrtc
#endif // WEBRTC_MODULES_AUDIO_CODING_MAIN_SOURCE_ACM_G729_1_H_

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@ -16,25 +16,10 @@
#include "webrtc_neteq_help_macros.h"
#ifdef WEBRTC_CODEC_GSMFR
// NOTE! GSM-FR is not included in the open-source package. The following
// interface file is needed:
//
// /modules/audio_coding/codecs/gsmfr/main/interface/gsmfr_interface.h
//
// The API in the header file should match the one below.
//
// int16_t WebRtcGSMFR_CreateEnc(GSMFR_encinst_t_** inst);
// int16_t WebRtcGSMFR_CreateDec(GSMFR_decinst_t_** inst);
// int16_t WebRtcGSMFR_FreeEnc(GSMFR_encinst_t_* inst);
// int16_t WebRtcGSMFR_FreeDec(GSMFR_decinst_t_* inst);
// int16_t WebRtcGSMFR_Encode(GSMFR_encinst_t_* encInst, int16_t* input,
// int16_t len, int16_t* output);
// int16_t WebRtcGSMFR_EncoderInit(GSMFR_encinst_t_* encInst, int16_t mode);
// int16_t WebRtcGSMFR_Decode(GSMFR_decinst_t_* decInst);
// int16_t WebRtcGSMFR_DecodeBwe(GSMFR_decinst_t_* decInst, int16_t* input);
// int16_t WebRtcGSMFR_DecodePlc(GSMFR_decinst_t_* decInst);
// int16_t WebRtcGSMFR_DecoderInit(GSMFR_decinst_t_* decInst);
#include "gsmfr_interface.h"
// NOTE! GSM-FR is not included in the open-source package. Modify this file
// or your codec API to match the function calls and names of used GSM-FR API
// file.
#include "gsmfr_interface.h"
#endif
namespace webrtc {
@ -47,340 +32,228 @@ ACMGSMFR::ACMGSMFR(WebRtc_Word16 /* codecID */)
return;
}
ACMGSMFR::~ACMGSMFR()
{
return;
ACMGSMFR::~ACMGSMFR() {
return;
}
WebRtc_Word16
ACMGSMFR::InternalEncode(
WebRtc_UWord8* /* bitStream */,
WebRtc_Word16* /* bitStreamLenByte */)
{
return -1;
WebRtc_Word16 ACMGSMFR::InternalEncode(WebRtc_UWord8* /* bitStream */,
WebRtc_Word16* /* bitStreamLenByte */) {
return -1;
}
WebRtc_Word16
ACMGSMFR::DecodeSafe(
WebRtc_UWord8* /* bitStream */,
WebRtc_Word16 /* bitStreamLenByte */,
WebRtc_Word16* /* audio */,
WebRtc_Word16* /* audioSamples */,
WebRtc_Word8* /* speechType */)
{
return -1;
WebRtc_Word16 ACMGSMFR::DecodeSafe(WebRtc_UWord8* /* bitStream */,
WebRtc_Word16 /* bitStreamLenByte */,
WebRtc_Word16* /* audio */,
WebRtc_Word16* /* audioSamples */,
WebRtc_Word8* /* speechType */) {
return -1;
}
WebRtc_Word16
ACMGSMFR::EnableDTX()
{
return -1;
WebRtc_Word16 ACMGSMFR::EnableDTX() {
return -1;
}
WebRtc_Word16
ACMGSMFR::DisableDTX()
{
return -1;
WebRtc_Word16 ACMGSMFR::DisableDTX() {
return -1;
}
WebRtc_Word16
ACMGSMFR::InternalInitEncoder(
WebRtcACMCodecParams* /* codecParams */)
{
return -1;
WebRtc_Word16 ACMGSMFR::InternalInitEncoder(
WebRtcACMCodecParams* /* codecParams */) {
return -1;
}
WebRtc_Word16
ACMGSMFR::InternalInitDecoder(
WebRtcACMCodecParams* /* codecParams */)
{
return -1;
WebRtc_Word16 ACMGSMFR::InternalInitDecoder(
WebRtcACMCodecParams* /* codecParams */) {
return -1;
}
WebRtc_Word32
ACMGSMFR::CodecDef(
WebRtcNetEQ_CodecDef& /* codecDef */,
const CodecInst& /* codecInst */)
{
return -1;
WebRtc_Word32 ACMGSMFR::CodecDef(WebRtcNetEQ_CodecDef& /* codecDef */,
const CodecInst& /* codecInst */) {
return -1;
}
ACMGenericCodec*
ACMGSMFR::CreateInstance(void)
{
return NULL;
ACMGenericCodec* ACMGSMFR::CreateInstance(void) {
return NULL;
}
WebRtc_Word16
ACMGSMFR::InternalCreateEncoder()
{
return -1;
WebRtc_Word16 ACMGSMFR::InternalCreateEncoder() {
return -1;
}
void
ACMGSMFR::DestructEncoderSafe()
{
return;
void ACMGSMFR::DestructEncoderSafe() {
return;
}
WebRtc_Word16
ACMGSMFR::InternalCreateDecoder()
{
return -1;
WebRtc_Word16 ACMGSMFR::InternalCreateDecoder() {
return -1;
}
void
ACMGSMFR::DestructDecoderSafe()
{
return;
void ACMGSMFR::DestructDecoderSafe() {
return;
}
void
ACMGSMFR::InternalDestructEncoderInst(
void* /* ptrInst */)
{
return;
void ACMGSMFR::InternalDestructEncoderInst(void* /* ptrInst */) {
return;
}
#else //===================== Actual Implementation =======================
ACMGSMFR::ACMGSMFR(
WebRtc_Word16 codecID):
_encoderInstPtr(NULL),
_decoderInstPtr(NULL)
{
_codecID = codecID;
_hasInternalDTX = true;
return;
ACMGSMFR::ACMGSMFR(WebRtc_Word16 codecID)
: _encoderInstPtr(NULL),
_decoderInstPtr(NULL) {
_codecID = codecID;
_hasInternalDTX = true;
return;
}
ACMGSMFR::~ACMGSMFR()
{
if(_encoderInstPtr != NULL)
{
WebRtcGSMFR_FreeEnc(_encoderInstPtr);
_encoderInstPtr = NULL;
}
if(_decoderInstPtr != NULL)
{
WebRtcGSMFR_FreeDec(_decoderInstPtr);
_decoderInstPtr = NULL;
}
return;
ACMGSMFR::~ACMGSMFR() {
if (_encoderInstPtr != NULL) {
WebRtcGSMFR_FreeEnc(_encoderInstPtr);
_encoderInstPtr = NULL;
}
if (_decoderInstPtr != NULL) {
WebRtcGSMFR_FreeDec(_decoderInstPtr);
_decoderInstPtr = NULL;
}
return;
}
WebRtc_Word16
ACMGSMFR::InternalEncode(
WebRtc_UWord8* bitStream,
WebRtc_Word16* bitStreamLenByte)
{
*bitStreamLenByte = WebRtcGSMFR_Encode(_encoderInstPtr,
&_inAudio[_inAudioIxRead], _frameLenSmpl, (WebRtc_Word16*)bitStream);
// increment the read index this tell the caller that how far
// we have gone forward in reading the audio buffer
_inAudioIxRead += _frameLenSmpl;
return *bitStreamLenByte;
WebRtc_Word16 ACMGSMFR::InternalEncode(WebRtc_UWord8* bitStream,
WebRtc_Word16* bitStreamLenByte) {
*bitStreamLenByte = WebRtcGSMFR_Encode(_encoderInstPtr,
&_inAudio[_inAudioIxRead],
_frameLenSmpl,
(WebRtc_Word16*) bitStream);
// increment the read index this tell the caller that how far
// we have gone forward in reading the audio buffer
_inAudioIxRead += _frameLenSmpl;
return *bitStreamLenByte;
}
WebRtc_Word16 ACMGSMFR::DecodeSafe(WebRtc_UWord8* /* bitStream */,
WebRtc_Word16 /* bitStreamLenByte */,
WebRtc_Word16* /* audio */,
WebRtc_Word16* /* audioSamples */,
WebRtc_Word8* /* speechType */) {
return 0;
}
WebRtc_Word16
ACMGSMFR::DecodeSafe(
WebRtc_UWord8* /* bitStream */,
WebRtc_Word16 /* bitStreamLenByte */,
WebRtc_Word16* /* audio */,
WebRtc_Word16* /* audioSamples */,
WebRtc_Word8* /* speechType */)
{
WebRtc_Word16 ACMGSMFR::EnableDTX() {
if (_dtxEnabled) {
return 0;
}
WebRtc_Word16
ACMGSMFR::EnableDTX()
{
if(_dtxEnabled)
{
return 0;
}
else if(_encoderExist)
{
if(WebRtcGSMFR_EncoderInit(_encoderInstPtr, 1) < 0)
{
WEBRTC_TRACE(webrtc::kTraceError, webrtc::kTraceAudioCoding, _uniqueID,
"EnableDTX: cannot init encoder for GSMFR");
return -1;
}
_dtxEnabled = true;
return 0;
}
else
{
return -1;
}
}
WebRtc_Word16
ACMGSMFR::DisableDTX()
{
if(!_dtxEnabled)
{
return 0;
}
else if(_encoderExist)
{
if(WebRtcGSMFR_EncoderInit(_encoderInstPtr, 0) < 0)
{
} else if (_encoderExist) {
if (WebRtcGSMFR_EncoderInit(_encoderInstPtr, 1) < 0) {
WEBRTC_TRACE(webrtc::kTraceError, webrtc::kTraceAudioCoding, _uniqueID,
"DisableDTX: cannot init encoder for GSMFR");
return -1;
}
_dtxEnabled = false;
return 0;
"EnableDTX: cannot init encoder for GSMFR");
return -1;
}
else
{
// encoder doesn't exists, therefore disabling is harmless
return 0;
}
}
WebRtc_Word16
ACMGSMFR::InternalInitEncoder(
WebRtcACMCodecParams* codecParams)
{
if (WebRtcGSMFR_EncoderInit(_encoderInstPtr, ((codecParams->enableDTX)? 1:0)) < 0)
{
WEBRTC_TRACE(webrtc::kTraceError, webrtc::kTraceAudioCoding, _uniqueID,
"InternalInitEncoder: cannot init encoder for GSMFR");
}
return 0;
}
WebRtc_Word16
ACMGSMFR::InternalInitDecoder(
WebRtcACMCodecParams* /* codecParams */)
{
if (WebRtcGSMFR_DecoderInit(_decoderInstPtr) < 0)
{
WEBRTC_TRACE(webrtc::kTraceError, webrtc::kTraceAudioCoding, _uniqueID,
"InternalInitDecoder: cannot init decoder for GSMFR");
return -1;
}
return 0;
}
WebRtc_Word32
ACMGSMFR::CodecDef(
WebRtcNetEQ_CodecDef& codecDef,
const CodecInst& codecInst)
{
if (!_decoderInitialized)
{
WEBRTC_TRACE(webrtc::kTraceError, webrtc::kTraceAudioCoding, _uniqueID,
"CodecDef: decoder is not initialized for GSMFR");
return -1;
}
// Fill up the structure by calling
// "SET_CODEC_PAR" & "SET_GSMFR_FUNCTION."
// Then call NetEQ to add the codec to it's
// database.
SET_CODEC_PAR((codecDef), kDecoderGSMFR, codecInst.pltype,
_decoderInstPtr, 8000);
SET_GSMFR_FUNCTIONS((codecDef));
_dtxEnabled = true;
return 0;
}
ACMGenericCodec*
ACMGSMFR::CreateInstance(void)
{
return NULL;
}
WebRtc_Word16
ACMGSMFR::InternalCreateEncoder()
{
if (WebRtcGSMFR_CreateEnc(&_encoderInstPtr) < 0)
{
WEBRTC_TRACE(webrtc::kTraceError, webrtc::kTraceAudioCoding, _uniqueID,
"InternalCreateEncoder: cannot create instance for GSMFR encoder");
} else {
return -1;
}
return 0;
}
void
ACMGSMFR::DestructEncoderSafe()
{
if(_encoderInstPtr != NULL)
{
WebRtcGSMFR_FreeEnc(_encoderInstPtr);
_encoderInstPtr = NULL;
WebRtc_Word16 ACMGSMFR::DisableDTX() {
if (!_dtxEnabled) {
return 0;
} else if (_encoderExist) {
if (WebRtcGSMFR_EncoderInit(_encoderInstPtr, 0) < 0) {
WEBRTC_TRACE(webrtc::kTraceError, webrtc::kTraceAudioCoding, _uniqueID,
"DisableDTX: cannot init encoder for GSMFR");
return -1;
}
_encoderExist = false;
_encoderInitialized = false;
_dtxEnabled = false;
return 0;
} else {
// encoder doesn't exists, therefore disabling is harmless
return 0;
}
}
WebRtc_Word16
ACMGSMFR::InternalCreateDecoder()
{
if (WebRtcGSMFR_CreateDec(&_decoderInstPtr) < 0)
{
WebRtc_Word16 ACMGSMFR::InternalInitEncoder(WebRtcACMCodecParams* codecParams) {
if (WebRtcGSMFR_EncoderInit(_encoderInstPtr,
((codecParams->enableDTX) ? 1 : 0)) < 0) {
WEBRTC_TRACE(webrtc::kTraceError, webrtc::kTraceAudioCoding, _uniqueID,
"InternalCreateDecoder: cannot create instance for GSMFR decoder");
"InternalInitEncoder: cannot init encoder for GSMFR");
}
return 0;
}
WebRtc_Word16 ACMGSMFR::InternalInitDecoder(
WebRtcACMCodecParams* /* codecParams */) {
if (WebRtcGSMFR_DecoderInit(_decoderInstPtr) < 0) {
WEBRTC_TRACE(webrtc::kTraceError, webrtc::kTraceAudioCoding, _uniqueID,
"InternalInitDecoder: cannot init decoder for GSMFR");
return -1;
}
return 0;
}
void
ACMGSMFR::DestructDecoderSafe()
{
if(_decoderInstPtr != NULL)
{
WebRtcGSMFR_FreeDec(_decoderInstPtr);
_decoderInstPtr = NULL;
}
_decoderExist = false;
_decoderInitialized = false;
WebRtc_Word32 ACMGSMFR::CodecDef(WebRtcNetEQ_CodecDef& codecDef,
const CodecInst& codecInst) {
if (!_decoderInitialized) {
WEBRTC_TRACE(webrtc::kTraceError, webrtc::kTraceAudioCoding, _uniqueID,
"CodecDef: decoder is not initialized for GSMFR");
return -1;
}
// Fill up the structure by calling
// "SET_CODEC_PAR" & "SET_GSMFR_FUNCTION."
// Then call NetEQ to add the codec to it's
// database.
SET_CODEC_PAR((codecDef), kDecoderGSMFR, codecInst.pltype, _decoderInstPtr,
8000);
SET_GSMFR_FUNCTIONS((codecDef));
return 0;
}
ACMGenericCodec* ACMGSMFR::CreateInstance(void) {
return NULL;
}
void
ACMGSMFR::InternalDestructEncoderInst(
void* ptrInst)
{
if(ptrInst != NULL)
{
WebRtcGSMFR_FreeEnc((GSMFR_encinst_t_*)ptrInst);
}
return;
WebRtc_Word16 ACMGSMFR::InternalCreateEncoder() {
if (WebRtcGSMFR_CreateEnc(&_encoderInstPtr) < 0) {
WEBRTC_TRACE(webrtc::kTraceError, webrtc::kTraceAudioCoding, _uniqueID,
"InternalCreateEncoder: cannot create instance for GSMFR encoder");
return -1;
}
return 0;
}
void ACMGSMFR::DestructEncoderSafe() {
if (_encoderInstPtr != NULL) {
WebRtcGSMFR_FreeEnc(_encoderInstPtr);
_encoderInstPtr = NULL;
}
_encoderExist = false;
_encoderInitialized = false;
}
WebRtc_Word16 ACMGSMFR::InternalCreateDecoder() {
if (WebRtcGSMFR_CreateDec(&_decoderInstPtr) < 0) {
WEBRTC_TRACE(webrtc::kTraceError, webrtc::kTraceAudioCoding, _uniqueID,
"InternalCreateDecoder: cannot create instance for GSMFR decoder");
return -1;
}
return 0;
}
void ACMGSMFR::DestructDecoderSafe() {
if (_decoderInstPtr != NULL) {
WebRtcGSMFR_FreeDec(_decoderInstPtr);
_decoderInstPtr = NULL;
}
_decoderExist = false;
_decoderInitialized = false;
}
void ACMGSMFR::InternalDestructEncoderInst(void* ptrInst) {
if (ptrInst != NULL) {
WebRtcGSMFR_FreeEnc((GSMFR_encinst_t_*) ptrInst);
}
return;
}
#endif
} // namespace webrtc
} // namespace webrtc

View File

@ -19,55 +19,48 @@ struct GSMFR_decinst_t_;
namespace webrtc {
class ACMGSMFR : public ACMGenericCodec
{
public:
ACMGSMFR(WebRtc_Word16 codecID);
~ACMGSMFR();
// for FEC
ACMGenericCodec* CreateInstance(void);
class ACMGSMFR : public ACMGenericCodec {
public:
ACMGSMFR(WebRtc_Word16 codecID);
~ACMGSMFR();
// for FEC
ACMGenericCodec* CreateInstance(void);
WebRtc_Word16 InternalEncode(
WebRtc_UWord8* bitstream,
WebRtc_Word16* bitStreamLenByte);
WebRtc_Word16 InternalEncode(WebRtc_UWord8* bitstream,
WebRtc_Word16* bitStreamLenByte);
WebRtc_Word16 InternalInitEncoder(
WebRtcACMCodecParams *codecParams);
WebRtc_Word16 InternalInitEncoder(WebRtcACMCodecParams *codecParams);
WebRtc_Word16 InternalInitDecoder(
WebRtcACMCodecParams *codecParams);
WebRtc_Word16 InternalInitDecoder(WebRtcACMCodecParams *codecParams);
protected:
WebRtc_Word16 DecodeSafe(
WebRtc_UWord8* bitStream,
WebRtc_Word16 bitStreamLenByte,
WebRtc_Word16* audio,
WebRtc_Word16* audioSamples,
WebRtc_Word8* speechType);
protected:
WebRtc_Word16 DecodeSafe(WebRtc_UWord8* bitStream,
WebRtc_Word16 bitStreamLenByte,
WebRtc_Word16* audio,
WebRtc_Word16* audioSamples,
WebRtc_Word8* speechType);
WebRtc_Word32 CodecDef(
WebRtcNetEQ_CodecDef& codecDef,
const CodecInst& codecInst);
WebRtc_Word32 CodecDef(WebRtcNetEQ_CodecDef& codecDef,
const CodecInst& codecInst);
void DestructEncoderSafe();
void DestructEncoderSafe();
void DestructDecoderSafe();
void DestructDecoderSafe();
WebRtc_Word16 InternalCreateEncoder();
WebRtc_Word16 InternalCreateEncoder();
WebRtc_Word16 InternalCreateDecoder();
WebRtc_Word16 InternalCreateDecoder();
void InternalDestructEncoderInst(
void* ptrInst);
void InternalDestructEncoderInst(void* ptrInst);
WebRtc_Word16 EnableDTX();
WebRtc_Word16 EnableDTX();
WebRtc_Word16 DisableDTX();
WebRtc_Word16 DisableDTX();
GSMFR_encinst_t_* _encoderInstPtr;
GSMFR_decinst_t_* _decoderInstPtr;
GSMFR_encinst_t_* _encoderInstPtr;
GSMFR_decinst_t_* _decoderInstPtr;
};
} // namespace webrtc
} // namespace webrtc
#endif // WEBRTC_MODULES_AUDIO_CODING_MAIN_SOURCE_ACM_GSMFR_H_

View File

@ -16,11 +16,10 @@
#include "webrtc_neteq_help_macros.h"
#ifdef WEBRTC_CODEC_ILBC
#include "ilbc.h"
#include "ilbc.h"
#endif
namespace webrtc
{
namespace webrtc {
#ifndef WEBRTC_CODEC_ILBC
@ -30,333 +29,224 @@ ACMILBC::ACMILBC(WebRtc_Word16 /* codecID */)
return;
}
ACMILBC::~ACMILBC()
{
return;
ACMILBC::~ACMILBC() {
return;
}
WebRtc_Word16 ACMILBC::InternalEncode(WebRtc_UWord8* /* bitStream */,
WebRtc_Word16* /* bitStreamLenByte */) {
return -1;
}
WebRtc_Word16
ACMILBC::InternalEncode(
WebRtc_UWord8* /* bitStream */,
WebRtc_Word16* /* bitStreamLenByte */)
{
WebRtc_Word16 ACMILBC::DecodeSafe(WebRtc_UWord8* /* bitStream */,
WebRtc_Word16 /* bitStreamLenByte */,
WebRtc_Word16* /* audio */,
WebRtc_Word16* /* audioSamples */,
WebRtc_Word8* /* speechType */) {
return -1;
}
WebRtc_Word16 ACMILBC::InternalInitEncoder(
WebRtcACMCodecParams* /* codecParams */) {
return -1;
}
WebRtc_Word16 ACMILBC::InternalInitDecoder(
WebRtcACMCodecParams* /* codecParams */) {
return -1;
}
WebRtc_Word32 ACMILBC::CodecDef(WebRtcNetEQ_CodecDef& /* codecDef */,
const CodecInst& /* codecInst */) {
return -1;
}
ACMGenericCodec* ACMILBC::CreateInstance(void) {
return NULL;
}
WebRtc_Word16 ACMILBC::InternalCreateEncoder() {
return -1;
}
void ACMILBC::DestructEncoderSafe() {
return;
}
WebRtc_Word16 ACMILBC::InternalCreateDecoder() {
return -1;
}
void ACMILBC::DestructDecoderSafe() {
return;
}
void ACMILBC::InternalDestructEncoderInst(void* /* ptrInst */) {
return;
}
WebRtc_Word16 ACMILBC::SetBitRateSafe(const WebRtc_Word32 /* rate */) {
return -1;
}
#else //===================== Actual Implementation =======================
ACMILBC::ACMILBC(WebRtc_Word16 codecID)
: _encoderInstPtr(NULL),
_decoderInstPtr(NULL) {
_codecID = codecID;
return;
}
ACMILBC::~ACMILBC() {
if (_encoderInstPtr != NULL) {
WebRtcIlbcfix_EncoderFree(_encoderInstPtr);
_encoderInstPtr = NULL;
}
if (_decoderInstPtr != NULL) {
WebRtcIlbcfix_DecoderFree(_decoderInstPtr);
_decoderInstPtr = NULL;
}
return;
}
WebRtc_Word16 ACMILBC::InternalEncode(WebRtc_UWord8* bitStream,
WebRtc_Word16* bitStreamLenByte) {
*bitStreamLenByte = WebRtcIlbcfix_Encode(_encoderInstPtr,
&_inAudio[_inAudioIxRead],
_frameLenSmpl,
(WebRtc_Word16*) bitStream);
if (*bitStreamLenByte < 0) {
WEBRTC_TRACE(webrtc::kTraceError, webrtc::kTraceAudioCoding, _uniqueID,
"InternalEncode: error in encode for ILBC");
return -1;
}
// increment the read index this tell the caller that how far
// we have gone forward in reading the audio buffer
_inAudioIxRead += _frameLenSmpl;
return *bitStreamLenByte;
}
WebRtc_Word16 ACMILBC::DecodeSafe(WebRtc_UWord8* /* bitStream */,
WebRtc_Word16 /* bitStreamLenByte */,
WebRtc_Word16* /* audio */,
WebRtc_Word16* /* audioSamples */,
WebRtc_Word8* /* speechType */) {
return 0;
}
WebRtc_Word16
ACMILBC::DecodeSafe(
WebRtc_UWord8* /* bitStream */,
WebRtc_Word16 /* bitStreamLenByte */,
WebRtc_Word16* /* audio */,
WebRtc_Word16* /* audioSamples */,
WebRtc_Word8* /* speechType */)
{
WebRtc_Word16 ACMILBC::InternalInitEncoder(WebRtcACMCodecParams* codecParams) {
// initialize with a correct processing block length
if ((160 == (codecParams->codecInstant).pacsize) ||
(320 == (codecParams->codecInstant).pacsize)) {
// processing block of 20ms
return WebRtcIlbcfix_EncoderInit(_encoderInstPtr, 20);
} else if ((240 == (codecParams->codecInstant).pacsize) ||
(480 == (codecParams->codecInstant).pacsize)) {
// processing block of 30ms
return WebRtcIlbcfix_EncoderInit(_encoderInstPtr, 30);
} else {
WEBRTC_TRACE(webrtc::kTraceError, webrtc::kTraceAudioCoding, _uniqueID,
"InternalInitEncoder: invalid processing block");
return -1;
}
}
WebRtc_Word16
ACMILBC::InternalInitEncoder(
WebRtcACMCodecParams* /* codecParams */)
{
WebRtc_Word16 ACMILBC::InternalInitDecoder(WebRtcACMCodecParams* codecParams) {
// initialize with a correct processing block length
if ((160 == (codecParams->codecInstant).pacsize) ||
(320 == (codecParams->codecInstant).pacsize)) {
// processing block of 20ms
return WebRtcIlbcfix_DecoderInit(_decoderInstPtr, 20);
} else if ((240 == (codecParams->codecInstant).pacsize) ||
(480 == (codecParams->codecInstant).pacsize)) {
// processing block of 30ms
return WebRtcIlbcfix_DecoderInit(_decoderInstPtr, 30);
} else {
WEBRTC_TRACE(webrtc::kTraceError, webrtc::kTraceAudioCoding, _uniqueID,
"InternalInitDecoder: invalid processing block");
return -1;
}
}
WebRtc_Word16
ACMILBC::InternalInitDecoder(
WebRtcACMCodecParams* /* codecParams */)
{
WebRtc_Word32 ACMILBC::CodecDef(WebRtcNetEQ_CodecDef& codecDef,
const CodecInst& codecInst) {
if (!_decoderInitialized) {
WEBRTC_TRACE(webrtc::kTraceError, webrtc::kTraceAudioCoding, _uniqueID,
"CodeDef: decoder not initialized for ILBC");
return -1;
}
// Fill up the structure by calling
// "SET_CODEC_PAR" & "SET_ILBC_FUNCTION."
// Then return the structure back to NetEQ to add the codec to it's
// database.
SET_CODEC_PAR((codecDef), kDecoderILBC, codecInst.pltype, _decoderInstPtr,
8000);
SET_ILBC_FUNCTIONS((codecDef));
return 0;
}
ACMGenericCodec* ACMILBC::CreateInstance(void) {
return NULL;
}
WebRtc_Word32
ACMILBC::CodecDef(
WebRtcNetEQ_CodecDef& /* codecDef */,
const CodecInst& /* codecInst */)
{
WebRtc_Word16 ACMILBC::InternalCreateEncoder() {
if (WebRtcIlbcfix_EncoderCreate(&_encoderInstPtr) < 0) {
WEBRTC_TRACE(webrtc::kTraceError, webrtc::kTraceAudioCoding, _uniqueID,
"InternalCreateEncoder: cannot create instance for ILBC encoder");
return -1;
}
return 0;
}
ACMGenericCodec*
ACMILBC::CreateInstance(void)
{
return NULL;
void ACMILBC::DestructEncoderSafe() {
_encoderInitialized = false;
_encoderExist = false;
if (_encoderInstPtr != NULL) {
WebRtcIlbcfix_EncoderFree(_encoderInstPtr);
_encoderInstPtr = NULL;
}
}
WebRtc_Word16
ACMILBC::InternalCreateEncoder()
{
WebRtc_Word16 ACMILBC::InternalCreateDecoder() {
if (WebRtcIlbcfix_DecoderCreate(&_decoderInstPtr) < 0) {
WEBRTC_TRACE(webrtc::kTraceError, webrtc::kTraceAudioCoding, _uniqueID,
"InternalCreateDecoder: cannot create instance for ILBC decoder");
return -1;
}
return 0;
}
void
ACMILBC::DestructEncoderSafe()
{
return;
void ACMILBC::DestructDecoderSafe() {
_decoderInitialized = false;
_decoderExist = false;
if (_decoderInstPtr != NULL) {
WebRtcIlbcfix_DecoderFree(_decoderInstPtr);
_decoderInstPtr = NULL;
}
}
void ACMILBC::InternalDestructEncoderInst(void* ptrInst) {
if (ptrInst != NULL) {
WebRtcIlbcfix_EncoderFree((iLBC_encinst_t_*) ptrInst);
}
return;
}
WebRtc_Word16
ACMILBC::InternalCreateDecoder()
{
WebRtc_Word16 ACMILBC::SetBitRateSafe(const WebRtc_Word32 rate) {
// Check that rate is valid. No need to store the value
if (rate == 13300) {
WebRtcIlbcfix_EncoderInit(_encoderInstPtr, 30);
} else if (rate == 15200) {
WebRtcIlbcfix_EncoderInit(_encoderInstPtr, 20);
} else {
return -1;
}
}
_encoderParams.codecInstant.rate = rate;
void
ACMILBC::DestructDecoderSafe()
{
return;
}
void
ACMILBC::InternalDestructEncoderInst(
void* /* ptrInst */)
{
return;
}
WebRtc_Word16
ACMILBC::SetBitRateSafe(const WebRtc_Word32 /* rate */)
{
return -1;
}
#else //===================== Actual Implementation =======================
ACMILBC::ACMILBC(
WebRtc_Word16 codecID):
_encoderInstPtr(NULL),
_decoderInstPtr(NULL)
{
_codecID = codecID;
return;
}
ACMILBC::~ACMILBC()
{
if(_encoderInstPtr != NULL)
{
WebRtcIlbcfix_EncoderFree(_encoderInstPtr);
_encoderInstPtr = NULL;
}
if(_decoderInstPtr != NULL)
{
WebRtcIlbcfix_DecoderFree(_decoderInstPtr);
_decoderInstPtr = NULL;
}
return;
}
WebRtc_Word16
ACMILBC::InternalEncode(
WebRtc_UWord8* bitStream,
WebRtc_Word16* bitStreamLenByte)
{
*bitStreamLenByte = WebRtcIlbcfix_Encode(_encoderInstPtr,
&_inAudio[_inAudioIxRead], _frameLenSmpl, (WebRtc_Word16*)bitStream);
if (*bitStreamLenByte < 0)
{
WEBRTC_TRACE(webrtc::kTraceError, webrtc::kTraceAudioCoding, _uniqueID,
"InternalEncode: error in encode for ILBC");
return -1;
}
// increment the read index this tell the caller that how far
// we have gone forward in reading the audio buffer
_inAudioIxRead += _frameLenSmpl;
return *bitStreamLenByte;
}
WebRtc_Word16
ACMILBC::DecodeSafe(
WebRtc_UWord8* /* bitStream */,
WebRtc_Word16 /* bitStreamLenByte */,
WebRtc_Word16* /* audio */,
WebRtc_Word16* /* audioSamples */,
WebRtc_Word8* /* speechType */)
{
return 0;
}
WebRtc_Word16
ACMILBC::InternalInitEncoder(
WebRtcACMCodecParams* codecParams)
{
// initialize with a correct processing block length
if((160 == (codecParams->codecInstant).pacsize) ||
(320 == (codecParams->codecInstant).pacsize))
{
// processing block of 20ms
return WebRtcIlbcfix_EncoderInit(_encoderInstPtr, 20);
}
else if((240 == (codecParams->codecInstant).pacsize) ||
(480 == (codecParams->codecInstant).pacsize))
{
// processing block of 30ms
return WebRtcIlbcfix_EncoderInit(_encoderInstPtr, 30);
}
else
{
WEBRTC_TRACE(webrtc::kTraceError, webrtc::kTraceAudioCoding, _uniqueID,
"InternalInitEncoder: invalid processing block");
return -1;
}
}
WebRtc_Word16
ACMILBC::InternalInitDecoder(
WebRtcACMCodecParams* codecParams)
{
// initialize with a correct processing block length
if((160 == (codecParams->codecInstant).pacsize) ||
(320 == (codecParams->codecInstant).pacsize))
{
// processing block of 20ms
return WebRtcIlbcfix_DecoderInit(_decoderInstPtr, 20);
}
else if((240 == (codecParams->codecInstant).pacsize) ||
(480 == (codecParams->codecInstant).pacsize))
{
// processing block of 30ms
return WebRtcIlbcfix_DecoderInit(_decoderInstPtr, 30);
}
else
{
WEBRTC_TRACE(webrtc::kTraceError, webrtc::kTraceAudioCoding, _uniqueID,
"InternalInitDecoder: invalid processing block");
return -1;
}
}
WebRtc_Word32
ACMILBC::CodecDef(
WebRtcNetEQ_CodecDef& codecDef,
const CodecInst& codecInst)
{
if (!_decoderInitialized)
{
WEBRTC_TRACE(webrtc::kTraceError, webrtc::kTraceAudioCoding, _uniqueID,
"CodeDef: decoder not initialized for ILBC");
return -1;
}
// Fill up the structure by calling
// "SET_CODEC_PAR" & "SET_ILBC_FUNCTION."
// Then return the structure back to NetEQ to add the codec to it's
// database.
SET_CODEC_PAR((codecDef), kDecoderILBC, codecInst.pltype,
_decoderInstPtr, 8000);
SET_ILBC_FUNCTIONS((codecDef));
return 0;
}
ACMGenericCodec*
ACMILBC::CreateInstance(void)
{
return NULL;
}
WebRtc_Word16
ACMILBC::InternalCreateEncoder()
{
if (WebRtcIlbcfix_EncoderCreate(&_encoderInstPtr) < 0)
{
WEBRTC_TRACE(webrtc::kTraceError, webrtc::kTraceAudioCoding, _uniqueID,
"InternalCreateEncoder: cannot create instance for ILBC encoder");
return -1;
}
return 0;
}
void
ACMILBC::DestructEncoderSafe()
{
_encoderInitialized = false;
_encoderExist = false;
if(_encoderInstPtr != NULL)
{
WebRtcIlbcfix_EncoderFree(_encoderInstPtr);
_encoderInstPtr = NULL;
}
}
WebRtc_Word16
ACMILBC::InternalCreateDecoder()
{
if (WebRtcIlbcfix_DecoderCreate(&_decoderInstPtr) < 0)
{
WEBRTC_TRACE(webrtc::kTraceError, webrtc::kTraceAudioCoding, _uniqueID,
"InternalCreateDecoder: cannot create instance for ILBC decoder");
return -1;
}
return 0;
}
void
ACMILBC::DestructDecoderSafe()
{
_decoderInitialized = false;
_decoderExist = false;
if(_decoderInstPtr != NULL)
{
WebRtcIlbcfix_DecoderFree(_decoderInstPtr);
_decoderInstPtr = NULL;
}
}
void
ACMILBC::InternalDestructEncoderInst(
void* ptrInst)
{
if(ptrInst != NULL)
{
WebRtcIlbcfix_EncoderFree((iLBC_encinst_t_*)ptrInst);
}
return;
}
WebRtc_Word16
ACMILBC::SetBitRateSafe(const WebRtc_Word32 rate)
{
// Check that rate is valid. No need to store the value
if (rate == 13300)
{
WebRtcIlbcfix_EncoderInit(_encoderInstPtr, 30);
}
else if (rate == 15200)
{
WebRtcIlbcfix_EncoderInit(_encoderInstPtr, 20);
}
else
{
return -1;
}
_encoderParams.codecInstant.rate = rate;
return 0;
return 0;
}
#endif
} // namespace webrtc
} // namespace webrtc

View File

@ -17,58 +17,48 @@
struct iLBC_encinst_t_;
struct iLBC_decinst_t_;
namespace webrtc
{
namespace webrtc {
class ACMILBC : public ACMGenericCodec
{
public:
ACMILBC(WebRtc_Word16 codecID);
~ACMILBC();
// for FEC
ACMGenericCodec* CreateInstance(void);
class ACMILBC : public ACMGenericCodec {
public:
ACMILBC(WebRtc_Word16 codecID);
~ACMILBC();
// for FEC
ACMGenericCodec* CreateInstance(void);
WebRtc_Word16 InternalEncode(
WebRtc_UWord8* bitstream,
WebRtc_Word16* bitStreamLenByte);
WebRtc_Word16 InternalEncode(WebRtc_UWord8* bitstream,
WebRtc_Word16* bitStreamLenByte);
WebRtc_Word16 InternalInitEncoder(
WebRtcACMCodecParams *codecParams);
WebRtc_Word16 InternalInitEncoder(WebRtcACMCodecParams *codecParams);
WebRtc_Word16 InternalInitDecoder(
WebRtcACMCodecParams *codecParams);
WebRtc_Word16 InternalInitDecoder(WebRtcACMCodecParams *codecParams);
protected:
WebRtc_Word16 DecodeSafe(
WebRtc_UWord8* bitStream,
WebRtc_Word16 bitStreamLenByte,
WebRtc_Word16* audio,
WebRtc_Word16* audioSamples,
WebRtc_Word8* speechType);
protected:
WebRtc_Word16 DecodeSafe(WebRtc_UWord8* bitStream,
WebRtc_Word16 bitStreamLenByte,
WebRtc_Word16* audio,
WebRtc_Word16* audioSamples,
WebRtc_Word8* speechType);
WebRtc_Word32 CodecDef(
WebRtcNetEQ_CodecDef& codecDef,
const CodecInst& codecInst);
WebRtc_Word32 CodecDef(WebRtcNetEQ_CodecDef& codecDef,
const CodecInst& codecInst);
WebRtc_Word16 SetBitRateSafe(const WebRtc_Word32 rate);
WebRtc_Word16 SetBitRateSafe(
const WebRtc_Word32 rate);
void DestructEncoderSafe();
void DestructEncoderSafe();
void DestructDecoderSafe();
void DestructDecoderSafe();
WebRtc_Word16 InternalCreateEncoder();
WebRtc_Word16 InternalCreateEncoder();
WebRtc_Word16 InternalCreateDecoder();
WebRtc_Word16 InternalCreateDecoder();
void InternalDestructEncoderInst(void* ptrInst);
void InternalDestructEncoderInst(
void* ptrInst);
iLBC_encinst_t_* _encoderInstPtr;
iLBC_decinst_t_* _decoderInstPtr;
iLBC_encinst_t_* _encoderInstPtr;
iLBC_decinst_t_* _decoderInstPtr;
};
} // namespace webrtc
} // namespace webrtc
#endif // WEBRTC_MODULES_AUDIO_CODING_MAIN_SOURCE_ACM_ILBC_H_

File diff suppressed because it is too large Load Diff

View File

@ -13,137 +13,112 @@
#include "acm_generic_codec.h"
namespace webrtc
{
namespace webrtc {
struct ACMISACInst;
enum iSACCodingMode {ADAPTIVE, CHANNEL_INDEPENDENT};
class ACMISAC : public ACMGenericCodec
{
public:
ACMISAC(WebRtc_Word16 codecID);
~ACMISAC();
// for FEC
ACMGenericCodec* CreateInstance(void);
WebRtc_Word16 InternalEncode(
WebRtc_UWord8* bitstream,
WebRtc_Word16* bitStreamLenByte);
WebRtc_Word16 InternalInitEncoder(
WebRtcACMCodecParams *codecParams);
WebRtc_Word16 InternalInitDecoder(
WebRtcACMCodecParams *codecParams);
WebRtc_Word16 DeliverCachedIsacData(
WebRtc_UWord8* bitStream,
WebRtc_Word16* bitStreamLenByte,
WebRtc_UWord32* timestamp,
WebRtcACMEncodingType* encodingType,
const WebRtc_UWord16 isacRate,
const WebRtc_UWord8 isacBWestimate);
WebRtc_Word16 DeliverCachedData(
WebRtc_UWord8* /* bitStream */,
WebRtc_Word16* /* bitStreamLenByte */,
WebRtc_UWord32* /* timestamp */,
WebRtcACMEncodingType* /* encodingType */)
{
return -1;
}
WebRtc_Word16 UpdateDecoderSampFreq(
WebRtc_Word16 codecId);
WebRtc_Word16 UpdateEncoderSampFreq(
WebRtc_UWord16 sampFreqHz);
WebRtc_Word16 EncoderSampFreq(
WebRtc_UWord16& sampFreqHz);
WebRtc_Word32 ConfigISACBandwidthEstimator(
const WebRtc_UWord8 initFrameSizeMsec,
const WebRtc_UWord16 initRateBitPerSec,
const bool enforceFrameSize);
WebRtc_Word32 SetISACMaxPayloadSize(
const WebRtc_UWord16 maxPayloadLenBytes);
WebRtc_Word32 SetISACMaxRate(
const WebRtc_UWord32 maxRateBitPerSec);
WebRtc_Word16 REDPayloadISAC(
const WebRtc_Word32 isacRate,
const WebRtc_Word16 isacBwEstimate,
WebRtc_UWord8* payload,
WebRtc_Word16* payloadLenBytes);
protected:
WebRtc_Word16 DecodeSafe(
WebRtc_UWord8* bitStream,
WebRtc_Word16 bitStreamLenByte,
WebRtc_Word16* audio,
WebRtc_Word16* audioSamples,
WebRtc_Word8* speechType);
WebRtc_Word32 CodecDef(
WebRtcNetEQ_CodecDef& codecDef,
const CodecInst& codecInst);
void DestructEncoderSafe();
void DestructDecoderSafe();
WebRtc_Word16 SetBitRateSafe(
const WebRtc_Word32 bitRate);
WebRtc_Word32 GetEstimatedBandwidthSafe();
WebRtc_Word32 SetEstimatedBandwidthSafe(WebRtc_Word32 estimatedBandwidth);
WebRtc_Word32 GetRedPayloadSafe(
WebRtc_UWord8* redPayload,
WebRtc_Word16* payloadBytes);
WebRtc_Word16 InternalCreateEncoder();
WebRtc_Word16 InternalCreateDecoder();
void InternalDestructEncoderInst(
void* ptrInst);
WebRtc_Word16 Transcode(
WebRtc_UWord8* bitStream,
WebRtc_Word16* bitStreamLenByte,
WebRtc_Word16 qBWE,
WebRtc_Word32 rate,
bool isRED);
void CurrentRate(WebRtc_Word32& rateBitPerSec);
void UpdateFrameLen();
bool DecoderParamsSafe(
WebRtcACMCodecParams *decParams,
const WebRtc_UWord8 payloadType);
void SaveDecoderParamSafe(
const WebRtcACMCodecParams* codecParams);
ACMISACInst* _codecInstPtr;
bool _isEncInitialized;
iSACCodingMode _isacCodingMode;
bool _enforceFrameSize;
WebRtc_Word32 _isacCurrentBN;
WebRtc_UWord16 _samplesIn10MsAudio;
WebRtcACMCodecParams _decoderParams32kHz;
enum iSACCodingMode {
ADAPTIVE,
CHANNEL_INDEPENDENT
};
} //namespace
class ACMISAC : public ACMGenericCodec {
public:
ACMISAC(WebRtc_Word16 codecID);
~ACMISAC();
// for FEC
ACMGenericCodec* CreateInstance(void);
WebRtc_Word16 InternalEncode(WebRtc_UWord8* bitstream,
WebRtc_Word16* bitStreamLenByte);
WebRtc_Word16 InternalInitEncoder(WebRtcACMCodecParams *codecParams);
WebRtc_Word16 InternalInitDecoder(WebRtcACMCodecParams *codecParams);
WebRtc_Word16 DeliverCachedIsacData(WebRtc_UWord8* bitStream,
WebRtc_Word16* bitStreamLenByte,
WebRtc_UWord32* timestamp,
WebRtcACMEncodingType* encodingType,
const WebRtc_UWord16 isacRate,
const WebRtc_UWord8 isacBWestimate);
WebRtc_Word16 DeliverCachedData(WebRtc_UWord8* /* bitStream */,
WebRtc_Word16* /* bitStreamLenByte */,
WebRtc_UWord32* /* timestamp */,
WebRtcACMEncodingType* /* encodingType */) {
return -1;
}
WebRtc_Word16 UpdateDecoderSampFreq(WebRtc_Word16 codecId);
WebRtc_Word16 UpdateEncoderSampFreq(WebRtc_UWord16 sampFreqHz);
WebRtc_Word16 EncoderSampFreq(WebRtc_UWord16& sampFreqHz);
WebRtc_Word32 ConfigISACBandwidthEstimator(
const WebRtc_UWord8 initFrameSizeMsec,
const WebRtc_UWord16 initRateBitPerSec, const bool enforceFrameSize);
WebRtc_Word32 SetISACMaxPayloadSize(const WebRtc_UWord16 maxPayloadLenBytes);
WebRtc_Word32 SetISACMaxRate(const WebRtc_UWord32 maxRateBitPerSec);
WebRtc_Word16 REDPayloadISAC(const WebRtc_Word32 isacRate,
const WebRtc_Word16 isacBwEstimate,
WebRtc_UWord8* payload,
WebRtc_Word16* payloadLenBytes);
protected:
WebRtc_Word16 DecodeSafe(WebRtc_UWord8* bitStream,
WebRtc_Word16 bitStreamLenByte, WebRtc_Word16* audio,
WebRtc_Word16* audioSamples,
WebRtc_Word8* speechType);
WebRtc_Word32 CodecDef(WebRtcNetEQ_CodecDef& codecDef,
const CodecInst& codecInst);
void DestructEncoderSafe();
void DestructDecoderSafe();
WebRtc_Word16 SetBitRateSafe(const WebRtc_Word32 bitRate);
WebRtc_Word32 GetEstimatedBandwidthSafe();
WebRtc_Word32 SetEstimatedBandwidthSafe(WebRtc_Word32 estimatedBandwidth);
WebRtc_Word32 GetRedPayloadSafe(WebRtc_UWord8* redPayload,
WebRtc_Word16* payloadBytes);
WebRtc_Word16 InternalCreateEncoder();
WebRtc_Word16 InternalCreateDecoder();
void InternalDestructEncoderInst(void* ptrInst);
WebRtc_Word16 Transcode(WebRtc_UWord8* bitStream,
WebRtc_Word16* bitStreamLenByte, WebRtc_Word16 qBWE,
WebRtc_Word32 rate, bool isRED);
void CurrentRate(WebRtc_Word32& rateBitPerSec);
void UpdateFrameLen();
bool DecoderParamsSafe(WebRtcACMCodecParams *decParams,
const WebRtc_UWord8 payloadType);
void SaveDecoderParamSafe(const WebRtcACMCodecParams* codecParams);
ACMISACInst* _codecInstPtr;
bool _isEncInitialized;
iSACCodingMode _isacCodingMode;
bool _enforceFrameSize;
WebRtc_Word32 _isacCurrentBN;
WebRtc_UWord16 _samplesIn10MsAudio;
WebRtcACMCodecParams _decoderParams32kHz;
};
} // namespace
#endif // WEBRTC_MODULES_AUDIO_CODING_MAIN_SOURCE_ACM_ISAC_H_

View File

@ -13,62 +13,61 @@
#include "engine_configurations.h"
namespace webrtc
{
namespace webrtc {
#ifdef WEBRTC_CODEC_ISAC
# define ACM_ISAC_CREATE WebRtcIsac_Create
# define ACM_ISAC_FREE WebRtcIsac_Free
# define ACM_ISAC_ENCODERINIT WebRtcIsac_EncoderInit
# define ACM_ISAC_ENCODE WebRtcIsac_Encode
# define ACM_ISAC_DECODERINIT WebRtcIsac_DecoderInit
# define ACM_ISAC_DECODE_BWE WebRtcIsac_UpdateBwEstimate
# define ACM_ISAC_DECODE_B WebRtcIsac_Decode
# define ACM_ISAC_DECODEPLC WebRtcIsac_DecodePlc
# define ACM_ISAC_CONTROL WebRtcIsac_Control
# define ACM_ISAC_CONTROL_BWE WebRtcIsac_ControlBwe
# define ACM_ISAC_GETFRAMELEN WebRtcIsac_ReadFrameLen
# define ACM_ISAC_GETERRORCODE WebRtcIsac_GetErrorCode
# define ACM_ISAC_GETSENDBITRATE WebRtcIsac_GetUplinkBw
# define ACM_ISAC_SETMAXPAYLOADSIZE WebRtcIsac_SetMaxPayloadSize
# define ACM_ISAC_SETMAXRATE WebRtcIsac_SetMaxRate
# define ACM_ISAC_GETNEWBITSTREAM WebRtcIsac_GetNewBitStream
# define ACM_ISAC_GETSENDBWE WebRtcIsac_GetDownLinkBwIndex
# define ACM_ISAC_SETBWE WebRtcIsac_UpdateUplinkBw
# define ACM_ISAC_GETBWE WebRtcIsac_ReadBwIndex
# define ACM_ISAC_GETNEWFRAMELEN WebRtcIsac_GetNewFrameLen
# define ACM_ISAC_STRUCT ISACStruct
# define ACM_ISAC_GETENCSAMPRATE WebRtcIsac_EncSampRate
# define ACM_ISAC_GETDECSAMPRATE WebRtcIsac_DecSampRate
#define ACM_ISAC_CREATE WebRtcIsac_Create
#define ACM_ISAC_FREE WebRtcIsac_Free
#define ACM_ISAC_ENCODERINIT WebRtcIsac_EncoderInit
#define ACM_ISAC_ENCODE WebRtcIsac_Encode
#define ACM_ISAC_DECODERINIT WebRtcIsac_DecoderInit
#define ACM_ISAC_DECODE_BWE WebRtcIsac_UpdateBwEstimate
#define ACM_ISAC_DECODE_B WebRtcIsac_Decode
#define ACM_ISAC_DECODEPLC WebRtcIsac_DecodePlc
#define ACM_ISAC_CONTROL WebRtcIsac_Control
#define ACM_ISAC_CONTROL_BWE WebRtcIsac_ControlBwe
#define ACM_ISAC_GETFRAMELEN WebRtcIsac_ReadFrameLen
#define ACM_ISAC_GETERRORCODE WebRtcIsac_GetErrorCode
#define ACM_ISAC_GETSENDBITRATE WebRtcIsac_GetUplinkBw
#define ACM_ISAC_SETMAXPAYLOADSIZE WebRtcIsac_SetMaxPayloadSize
#define ACM_ISAC_SETMAXRATE WebRtcIsac_SetMaxRate
#define ACM_ISAC_GETNEWBITSTREAM WebRtcIsac_GetNewBitStream
#define ACM_ISAC_GETSENDBWE WebRtcIsac_GetDownLinkBwIndex
#define ACM_ISAC_SETBWE WebRtcIsac_UpdateUplinkBw
#define ACM_ISAC_GETBWE WebRtcIsac_ReadBwIndex
#define ACM_ISAC_GETNEWFRAMELEN WebRtcIsac_GetNewFrameLen
#define ACM_ISAC_STRUCT ISACStruct
#define ACM_ISAC_GETENCSAMPRATE WebRtcIsac_EncSampRate
#define ACM_ISAC_GETDECSAMPRATE WebRtcIsac_DecSampRate
#endif
#ifdef WEBRTC_CODEC_ISACFX
# define ACM_ISAC_CREATE WebRtcIsacfix_Create
# define ACM_ISAC_FREE WebRtcIsacfix_Free
# define ACM_ISAC_ENCODERINIT WebRtcIsacfix_EncoderInit
# define ACM_ISAC_ENCODE WebRtcIsacfix_Encode
# define ACM_ISAC_DECODERINIT WebRtcIsacfix_DecoderInit
# define ACM_ISAC_DECODE_BWE WebRtcIsacfix_UpdateBwEstimate
# define ACM_ISAC_DECODE_B WebRtcIsacfix_Decode
# define ACM_ISAC_DECODEPLC WebRtcIsacfix_DecodePlc
# define ACM_ISAC_CONTROL ACMISACFixControl // local Impl
# define ACM_ISAC_CONTROL_BWE ACMISACFixControlBWE // local Impl
# define ACM_ISAC_GETFRAMELEN WebRtcIsacfix_ReadFrameLen
# define ACM_ISAC_GETERRORCODE WebRtcIsacfix_GetErrorCode
# define ACM_ISAC_GETSENDBITRATE ACMISACFixGetSendBitrate // local Impl
# define ACM_ISAC_SETMAXPAYLOADSIZE WebRtcIsacfix_SetMaxPayloadSize
# define ACM_ISAC_SETMAXRATE WebRtcIsacfix_SetMaxRate
# define ACM_ISAC_GETNEWBITSTREAM ACMISACFixGetNewBitstream // local Impl
# define ACM_ISAC_GETSENDBWE ACMISACFixGetSendBWE // local Impl
# define ACM_ISAC_SETBWE WebRtcIsacfix_UpdateUplinkBw
# define ACM_ISAC_GETBWE WebRtcIsacfix_ReadBwIndex
# define ACM_ISAC_GETNEWFRAMELEN WebRtcIsacfix_GetNewFrameLen
# define ACM_ISAC_STRUCT ISACFIX_MainStruct
# define ACM_ISAC_GETENCSAMPRATE ACMISACFixGetEncSampRate // local Impl
# define ACM_ISAC_GETDECSAMPRATE ACMISACFixGetDecSampRate // local Impl
#define ACM_ISAC_CREATE WebRtcIsacfix_Create
#define ACM_ISAC_FREE WebRtcIsacfix_Free
#define ACM_ISAC_ENCODERINIT WebRtcIsacfix_EncoderInit
#define ACM_ISAC_ENCODE WebRtcIsacfix_Encode
#define ACM_ISAC_DECODERINIT WebRtcIsacfix_DecoderInit
#define ACM_ISAC_DECODE_BWE WebRtcIsacfix_UpdateBwEstimate
#define ACM_ISAC_DECODE_B WebRtcIsacfix_Decode
#define ACM_ISAC_DECODEPLC WebRtcIsacfix_DecodePlc
#define ACM_ISAC_CONTROL ACMISACFixControl // local Impl
#define ACM_ISAC_CONTROL_BWE ACMISACFixControlBWE // local Impl
#define ACM_ISAC_GETFRAMELEN WebRtcIsacfix_ReadFrameLen
#define ACM_ISAC_GETERRORCODE WebRtcIsacfix_GetErrorCode
#define ACM_ISAC_GETSENDBITRATE ACMISACFixGetSendBitrate // local Impl
#define ACM_ISAC_SETMAXPAYLOADSIZE WebRtcIsacfix_SetMaxPayloadSize
#define ACM_ISAC_SETMAXRATE WebRtcIsacfix_SetMaxRate
#define ACM_ISAC_GETNEWBITSTREAM ACMISACFixGetNewBitstream // local Impl
#define ACM_ISAC_GETSENDBWE ACMISACFixGetSendBWE // local Impl
#define ACM_ISAC_SETBWE WebRtcIsacfix_UpdateUplinkBw
#define ACM_ISAC_GETBWE WebRtcIsacfix_ReadBwIndex
#define ACM_ISAC_GETNEWFRAMELEN WebRtcIsacfix_GetNewFrameLen
#define ACM_ISAC_STRUCT ISACFIX_MainStruct
#define ACM_ISAC_GETENCSAMPRATE ACMISACFixGetEncSampRate // local Impl
#define ACM_ISAC_GETDECSAMPRATE ACMISACFixGetDecSampRate // local Impl
#endif
} //namespace
} //namespace
#endif // WEBRTC_MODULES_AUDIO_CODING_MAIN_SOURCE_ACM_ISAC_MACROS_H_

File diff suppressed because it is too large Load Diff

View File

@ -29,341 +29,317 @@ enum ACMSpeechType;
#define MAX_NUM_SLAVE_NETEQ 1
class ACMNetEQ
{
public:
// Constructor of the class
ACMNetEQ();
class ACMNetEQ {
public:
// Constructor of the class
ACMNetEQ();
// Destructor of the class.
~ACMNetEQ();
// Destructor of the class.
~ACMNetEQ();
//
// Init()
// Allocates memory for NetEQ and VAD and initializes them.
//
// Return value : 0 if ok.
// -1 if NetEQ or VAD returned an error or
// if out of memory.
//
WebRtc_Word32 Init();
//
// Init()
// Allocates memory for NetEQ and VAD and initializes them.
//
// Return value : 0 if ok.
// -1 if NetEQ or VAD returned an error or
// if out of memory.
//
WebRtc_Word32 Init();
//
// RecIn()
// Gives the payload to NetEQ.
//
// Input:
// - incomingPayload : Incoming audio payload.
// - payloadLength : Length of incoming audio payload.
// - rtpInfo : RTP header for the incoming payload containing
// information about payload type, sequence number,
// timestamp, ssrc and marker bit.
//
// Return value : 0 if ok.
// <0 if NetEQ returned an error.
//
WebRtc_Word32 RecIn(
const WebRtc_UWord8* incomingPayload,
const WebRtc_Word32 payloadLength,
const WebRtcRTPHeader& rtpInfo);
//
// RecIn()
// Gives the payload to NetEQ.
//
// Input:
// - incomingPayload : Incoming audio payload.
// - payloadLength : Length of incoming audio payload.
// - rtpInfo : RTP header for the incoming payload containing
// information about payload type, sequence number,
// timestamp, ssrc and marker bit.
//
// Return value : 0 if ok.
// <0 if NetEQ returned an error.
//
WebRtc_Word32 RecIn(const WebRtc_UWord8* incomingPayload,
const WebRtc_Word32 payloadLength,
const WebRtcRTPHeader& rtpInfo);
//
// RecOut()
// Asks NetEQ for 10 ms of decoded audio.
//
// Input:
// -audioFrame : an audio frame were output data and
// associated parameters are written to.
//
// Return value : 0 if ok.
// -1 if NetEQ returned an error.
//
WebRtc_Word32 RecOut(
AudioFrame& audioFrame);
//
// RecOut()
// Asks NetEQ for 10 ms of decoded audio.
//
// Input:
// -audioFrame : an audio frame were output data and
// associated parameters are written to.
//
// Return value : 0 if ok.
// -1 if NetEQ returned an error.
//
WebRtc_Word32 RecOut(AudioFrame& audioFrame);
//
// AddCodec()
// Adds a new codec to the NetEQ codec database.
//
// Input:
// - codecDef : The codec to be added.
// - toMaster : true if the codec has to be added to Master
// NetEq, otherwise will be added to the Slave
// NetEQ.
//
// Return value : 0 if ok.
// <0 if NetEQ returned an error.
//
WebRtc_Word32 AddCodec(
WebRtcNetEQ_CodecDef *codecDef,
bool toMaster = true);
//
// AddCodec()
// Adds a new codec to the NetEQ codec database.
//
// Input:
// - codecDef : The codec to be added.
// - toMaster : true if the codec has to be added to Master
// NetEq, otherwise will be added to the Slave
// NetEQ.
//
// Return value : 0 if ok.
// <0 if NetEQ returned an error.
//
WebRtc_Word32 AddCodec(WebRtcNetEQ_CodecDef *codecDef, bool toMaster = true);
//
// AllocatePacketBuffer()
// Allocates the NetEQ packet buffer.
//
// Input:
// - usedCodecs : An array of the codecs to be used by NetEQ.
// - noOfCodecs : Number of codecs in usedCodecs.
//
// Return value : 0 if ok.
// <0 if NetEQ returned an error.
//
WebRtc_Word32 AllocatePacketBuffer(
const WebRtcNetEQDecoder* usedCodecs,
WebRtc_Word16 noOfCodecs);
//
// AllocatePacketBuffer()
// Allocates the NetEQ packet buffer.
//
// Input:
// - usedCodecs : An array of the codecs to be used by NetEQ.
// - noOfCodecs : Number of codecs in usedCodecs.
//
// Return value : 0 if ok.
// <0 if NetEQ returned an error.
//
WebRtc_Word32 AllocatePacketBuffer(const WebRtcNetEQDecoder* usedCodecs,
WebRtc_Word16 noOfCodecs);
//
// SetExtraDelay()
// Sets an delayInMS milliseconds extra delay in NetEQ.
//
// Input:
// - delayInMS : Extra delay in milliseconds.
//
// Return value : 0 if ok.
// <0 if NetEQ returned an error.
//
WebRtc_Word32 SetExtraDelay(
const WebRtc_Word32 delayInMS);
//
// SetExtraDelay()
// Sets an delayInMS milliseconds extra delay in NetEQ.
//
// Input:
// - delayInMS : Extra delay in milliseconds.
//
// Return value : 0 if ok.
// <0 if NetEQ returned an error.
//
WebRtc_Word32 SetExtraDelay(const WebRtc_Word32 delayInMS);
//
// SetAVTPlayout()
// Enable/disable playout of AVT payloads.
//
// Input:
// - enable : Enable if true, disable if false.
//
// Return value : 0 if ok.
// <0 if NetEQ returned an error.
//
WebRtc_Word32 SetAVTPlayout(
const bool enable);
//
// SetAVTPlayout()
// Enable/disable playout of AVT payloads.
//
// Input:
// - enable : Enable if true, disable if false.
//
// Return value : 0 if ok.
// <0 if NetEQ returned an error.
//
WebRtc_Word32 SetAVTPlayout(const bool enable);
//
// AVTPlayout()
// Get the current AVT playout state.
//
// Return value : True if AVT playout is enabled.
// False if AVT playout is disabled.
//
bool AVTPlayout() const;
//
// AVTPlayout()
// Get the current AVT playout state.
//
// Return value : True if AVT playout is enabled.
// False if AVT playout is disabled.
//
bool AVTPlayout() const;
//
// CurrentSampFreqHz()
// Get the current sampling frequency in Hz.
//
// Return value : Sampling frequency in Hz.
//
WebRtc_Word32 CurrentSampFreqHz() const;
//
// CurrentSampFreqHz()
// Get the current sampling frequency in Hz.
//
// Return value : Sampling frequency in Hz.
//
WebRtc_Word32 CurrentSampFreqHz() const;
//
// SetPlayoutMode()
// Sets the playout mode to voice or fax.
//
// Input:
// - mode : The playout mode to be used, voice,
// fax, or streaming.
//
// Return value : 0 if ok.
// <0 if NetEQ returned an error.
//
WebRtc_Word32 SetPlayoutMode(
const AudioPlayoutMode mode);
//
// SetPlayoutMode()
// Sets the playout mode to voice or fax.
//
// Input:
// - mode : The playout mode to be used, voice,
// fax, or streaming.
//
// Return value : 0 if ok.
// <0 if NetEQ returned an error.
//
WebRtc_Word32 SetPlayoutMode(const AudioPlayoutMode mode);
//
// PlayoutMode()
// Get the current playout mode.
//
// Return value : The current playout mode.
//
AudioPlayoutMode PlayoutMode() const;
//
// PlayoutMode()
// Get the current playout mode.
//
// Return value : The current playout mode.
//
AudioPlayoutMode PlayoutMode() const;
//
// NetworkStatistics()
// Get the current network statistics from NetEQ.
//
// Output:
// - statistics : The current network statistics.
//
// Return value : 0 if ok.
// <0 if NetEQ returned an error.
//
WebRtc_Word32 NetworkStatistics(
ACMNetworkStatistics* statistics) const;
//
// NetworkStatistics()
// Get the current network statistics from NetEQ.
//
// Output:
// - statistics : The current network statistics.
//
// Return value : 0 if ok.
// <0 if NetEQ returned an error.
//
WebRtc_Word32 NetworkStatistics(ACMNetworkStatistics* statistics) const;
//
// VADMode()
// Get the current VAD Mode.
//
// Return value : The current VAD mode.
//
ACMVADMode VADMode() const;
//
// VADMode()
// Get the current VAD Mode.
//
// Return value : The current VAD mode.
//
ACMVADMode VADMode() const;
//
// SetVADMode()
// Set the VAD mode.
//
// Input:
// - mode : The new VAD mode.
//
// Return value : 0 if ok.
// -1 if an error occurred.
//
WebRtc_Word16 SetVADMode(
const ACMVADMode mode);
//
// SetVADMode()
// Set the VAD mode.
//
// Input:
// - mode : The new VAD mode.
//
// Return value : 0 if ok.
// -1 if an error occurred.
//
WebRtc_Word16 SetVADMode(const ACMVADMode mode);
//
// DecodeLock()
// Get the decode lock used to protect decoder instances while decoding.
//
// Return value : Pointer to the decode lock.
//
RWLockWrapper* DecodeLock() const
{
return _decodeLock;
}
//
// DecodeLock()
// Get the decode lock used to protect decoder instances while decoding.
//
// Return value : Pointer to the decode lock.
//
RWLockWrapper* DecodeLock() const {
return _decodeLock;
}
//
// FlushBuffers()
// Flushes the NetEQ packet and speech buffers.
//
// Return value : 0 if ok.
// -1 if NetEQ returned an error.
//
WebRtc_Word32 FlushBuffers();
//
// FlushBuffers()
// Flushes the NetEQ packet and speech buffers.
//
// Return value : 0 if ok.
// -1 if NetEQ returned an error.
//
WebRtc_Word32 FlushBuffers();
//
// RemoveCodec()
// Removes a codec from the NetEQ codec database.
//
// Input:
// - codecIdx : Codec to be removed.
//
// Return value : 0 if ok.
// -1 if an error occurred.
//
WebRtc_Word16 RemoveCodec(
WebRtcNetEQDecoder codecIdx,
bool isStereo = false);
//
// RemoveCodec()
// Removes a codec from the NetEQ codec database.
//
// Input:
// - codecIdx : Codec to be removed.
//
// Return value : 0 if ok.
// -1 if an error occurred.
//
WebRtc_Word16 RemoveCodec(WebRtcNetEQDecoder codecIdx, bool isStereo = false);
//
// SetBackgroundNoiseMode()
// Set the mode of the background noise.
//
// Input:
// - mode : an enumerator specifying the mode of the
// background noise.
//
// Return value : 0 if succeeded,
// -1 if failed to set the mode.
//
WebRtc_Word16 SetBackgroundNoiseMode(const ACMBackgroundNoiseMode mode);
//
// SetBackgroundNoiseMode()
// Set the mode of the background noise.
//
// Input:
// - mode : an enumerator specifying the mode of the
// background noise.
//
// Return value : 0 if succeeded,
// -1 if failed to set the mode.
//
WebRtc_Word16 SetBackgroundNoiseMode(
const ACMBackgroundNoiseMode mode);
//
// BackgroundNoiseMode()
// return the mode of the background noise.
//
// Return value : The mode of background noise.
//
WebRtc_Word16 BackgroundNoiseMode(ACMBackgroundNoiseMode& mode);
//
// BackgroundNoiseMode()
// return the mode of the background noise.
//
// Return value : The mode of background noise.
//
WebRtc_Word16 BackgroundNoiseMode(
ACMBackgroundNoiseMode& mode);
void SetUniqueId(WebRtc_Word32 id);
void SetUniqueId(
WebRtc_Word32 id);
WebRtc_Word32 PlayoutTimestamp(WebRtc_UWord32& timestamp);
WebRtc_Word32 PlayoutTimestamp(
WebRtc_UWord32& timestamp);
void SetReceivedStereo(bool receivedStereo);
void SetReceivedStereo(
bool receivedStereo);
WebRtc_UWord8 NumSlaves();
WebRtc_UWord8 NumSlaves();
enum JB {
masterJB = 0,
slaveJB = 1
};
enum JB {masterJB = 0, slaveJB = 1};
// Delete all slaves.
void RemoveSlaves();
// Delete all slaves.
void RemoveSlaves();
WebRtc_Word16 AddSlave(const WebRtcNetEQDecoder* usedCodecs,
WebRtc_Word16 noOfCodecs);
WebRtc_Word16 AddSlave(
const WebRtcNetEQDecoder* usedCodecs,
WebRtc_Word16 noOfCodecs);
private:
//
// RTPPack()
// Creates a Word16 RTP packet out of the payload data in Word16 and
// a WebRtcRTPHeader.
//
// Input:
// - payload : Payload to be packetized.
// - payloadLengthW8 : Length of the payload in bytes.
// - rtpInfo : RTP header struct.
//
// Output:
// - rtpPacket : The RTP packet.
//
static void RTPPack(WebRtc_Word16* rtpPacket, const WebRtc_Word8* payload,
const WebRtc_Word32 payloadLengthW8,
const WebRtcRTPHeader& rtpInfo);
private:
//
// RTPPack()
// Creates a Word16 RTP packet out of the payload data in Word16 and
// a WebRtcRTPHeader.
//
// Input:
// - payload : Payload to be packetized.
// - payloadLengthW8 : Length of the payload in bytes.
// - rtpInfo : RTP header struct.
//
// Output:
// - rtpPacket : The RTP packet.
//
static void RTPPack(
WebRtc_Word16* rtpPacket,
const WebRtc_Word8* payload,
const WebRtc_Word32 payloadLengthW8,
const WebRtcRTPHeader& rtpInfo);
void LogError(const char* neteqFuncName, const WebRtc_Word16 idx) const;
void LogError(
const char* neteqFuncName,
const WebRtc_Word16 idx) const;
WebRtc_Word16 InitByIdxSafe(const WebRtc_Word16 idx);
WebRtc_Word16 InitByIdxSafe(
const WebRtc_Word16 idx);
// EnableVAD()
// Enable VAD.
//
// Return value : 0 if ok.
// -1 if an error occurred.
//
WebRtc_Word16 EnableVAD();
// EnableVAD()
// Enable VAD.
//
// Return value : 0 if ok.
// -1 if an error occurred.
//
WebRtc_Word16 EnableVAD();
WebRtc_Word16 EnableVADByIdxSafe(const WebRtc_Word16 idx);
WebRtc_Word16 EnableVADByIdxSafe(
const WebRtc_Word16 idx);
WebRtc_Word16 AllocatePacketBufferByIdxSafe(
const WebRtcNetEQDecoder* usedCodecs,
WebRtc_Word16 noOfCodecs,
const WebRtc_Word16 idx);
WebRtc_Word16 AllocatePacketBufferByIdxSafe(
const WebRtcNetEQDecoder* usedCodecs,
WebRtc_Word16 noOfCodecs,
const WebRtc_Word16 idx);
// Delete the NetEQ corresponding to |index|.
void RemoveNetEQSafe(int index);
// Delete the NetEQ corresponding to |index|.
void RemoveNetEQSafe(int index);
void RemoveSlavesSafe();
void RemoveSlavesSafe();
void* _inst[MAX_NUM_SLAVE_NETEQ + 1];
void* _instMem[MAX_NUM_SLAVE_NETEQ + 1];
void* _inst[MAX_NUM_SLAVE_NETEQ + 1];
void* _instMem[MAX_NUM_SLAVE_NETEQ + 1];
WebRtc_Word16* _netEqPacketBuffer[MAX_NUM_SLAVE_NETEQ + 1];
WebRtc_Word16* _netEqPacketBuffer[MAX_NUM_SLAVE_NETEQ + 1];
WebRtc_Word32 _id;
float _currentSampFreqKHz;
bool _avtPlayout;
AudioPlayoutMode _playoutMode;
CriticalSectionWrapper* _netEqCritSect;
WebRtc_Word32 _id;
float _currentSampFreqKHz;
bool _avtPlayout;
AudioPlayoutMode _playoutMode;
CriticalSectionWrapper* _netEqCritSect;
WebRtcVadInst* _ptrVADInst[MAX_NUM_SLAVE_NETEQ + 1];
WebRtcVadInst* _ptrVADInst[MAX_NUM_SLAVE_NETEQ + 1];
bool _vadStatus;
ACMVADMode _vadMode;
RWLockWrapper* _decodeLock;
bool _isInitialized[MAX_NUM_SLAVE_NETEQ + 1];
WebRtc_UWord8 _numSlaves;
bool _receivedStereo;
void* _masterSlaveInfo;
AudioFrame::VADActivity _previousAudioActivity;
WebRtc_Word32 _extraDelay;
bool _vadStatus;
ACMVADMode _vadMode;
RWLockWrapper* _decodeLock;
bool _isInitialized[MAX_NUM_SLAVE_NETEQ + 1];
WebRtc_UWord8 _numSlaves;
bool _receivedStereo;
void* _masterSlaveInfo;
AudioFrame::VADActivity _previousAudioActivity;
WebRtc_Word32 _extraDelay;
CriticalSectionWrapper* _callbackCritSect;
CriticalSectionWrapper* _callbackCritSect;
};
} //namespace webrtc
} //namespace webrtc
#endif // WEBRTC_MODULES_AUDIO_CODING_MAIN_SOURCE_ACM_NETEQ_H_

View File

@ -18,7 +18,7 @@
#include "webrtc_neteq_help_macros.h"
#ifdef WEBRTC_CODEC_PCM16
#include "pcm16b.h"
#include "pcm16b.h"
#endif
namespace webrtc {
@ -90,7 +90,6 @@ void ACMPCM16B::SplitStereoPacket(uint8_t* /*payload*/,
}
#else //===================== Actual Implementation =======================
ACMPCM16B::ACMPCM16B(WebRtc_Word16 codecID) {
_codecID = codecID;
_samplingFreqHz = ACMCodecDB::CodecFreq(_codecID);
@ -103,8 +102,8 @@ ACMPCM16B::~ACMPCM16B() {
WebRtc_Word16 ACMPCM16B::InternalEncode(WebRtc_UWord8* bitStream,
WebRtc_Word16* bitStreamLenByte) {
*bitStreamLenByte = WebRtcPcm16b_Encode(&_inAudio[_inAudioIxRead],
_frameLenSmpl * _noChannels,
bitStream);
_frameLenSmpl * _noChannels,
bitStream);
// Increment the read index to tell the caller that how far
// we have gone forward in reading the audio buffer.
_inAudioIxRead += _frameLenSmpl * _noChannels;
@ -144,13 +143,13 @@ WebRtc_Word32 ACMPCM16B::CodecDef(WebRtcNetEQ_CodecDef& codecDef,
}
case 16000: {
SET_CODEC_PAR(codecDef, kDecoderPCM16Bwb, codecInst.pltype, NULL,
16000);
16000);
SET_PCM16B_WB_FUNCTIONS(codecDef);
break;
}
case 32000: {
SET_CODEC_PAR(codecDef, kDecoderPCM16Bswb32kHz, codecInst.pltype,
NULL, 32000);
NULL, 32000);
SET_PCM16B_SWB32_FUNCTIONS(codecDef);
break;
}
@ -162,19 +161,19 @@ WebRtc_Word32 ACMPCM16B::CodecDef(WebRtcNetEQ_CodecDef& codecDef,
switch(_samplingFreqHz) {
case 8000: {
SET_CODEC_PAR(codecDef, kDecoderPCM16B_2ch, codecInst.pltype, NULL,
8000);
8000);
SET_PCM16B_FUNCTIONS(codecDef);
break;
}
case 16000: {
SET_CODEC_PAR(codecDef, kDecoderPCM16Bwb_2ch, codecInst.pltype,
NULL, 16000);
NULL, 16000);
SET_PCM16B_WB_FUNCTIONS(codecDef);
break;
}
case 32000: {
SET_CODEC_PAR(codecDef, kDecoderPCM16Bswb32kHz_2ch, codecInst.pltype,
NULL, 32000);
NULL, 32000);
SET_PCM16B_SWB32_FUNCTIONS(codecDef);
break;
}
@ -244,4 +243,4 @@ void ACMPCM16B::SplitStereoPacket(uint8_t* payload, int32_t* payload_length) {
}
#endif
} // namespace webrtc
} // namespace webrtc

View File

@ -13,55 +13,47 @@
#include "acm_generic_codec.h"
namespace webrtc
{
namespace webrtc {
class ACMPCM16B : public ACMGenericCodec
{
public:
ACMPCM16B(WebRtc_Word16 codecID);
~ACMPCM16B();
// for FEC
ACMGenericCodec* CreateInstance(void);
class ACMPCM16B : public ACMGenericCodec {
public:
ACMPCM16B(WebRtc_Word16 codecID);
~ACMPCM16B();
// for FEC
ACMGenericCodec* CreateInstance(void);
WebRtc_Word16 InternalEncode(
WebRtc_UWord8* bitstream,
WebRtc_Word16* bitStreamLenByte);
WebRtc_Word16 InternalEncode(WebRtc_UWord8* bitstream,
WebRtc_Word16* bitStreamLenByte);
WebRtc_Word16 InternalInitEncoder(
WebRtcACMCodecParams *codecParams);
WebRtc_Word16 InternalInitEncoder(WebRtcACMCodecParams *codecParams);
WebRtc_Word16 InternalInitDecoder(
WebRtcACMCodecParams *codecParams);
WebRtc_Word16 InternalInitDecoder(WebRtcACMCodecParams *codecParams);
protected:
WebRtc_Word16 DecodeSafe(
WebRtc_UWord8* bitStream,
WebRtc_Word16 bitStreamLenByte,
WebRtc_Word16* audio,
WebRtc_Word16* audioSamples,
WebRtc_Word8* speechType);
protected:
WebRtc_Word16 DecodeSafe(WebRtc_UWord8* bitStream,
WebRtc_Word16 bitStreamLenByte,
WebRtc_Word16* audio,
WebRtc_Word16* audioSamples,
WebRtc_Word8* speechType);
WebRtc_Word32 CodecDef(
WebRtcNetEQ_CodecDef& codecDef,
const CodecInst& codecInst);
WebRtc_Word32 CodecDef(WebRtcNetEQ_CodecDef& codecDef,
const CodecInst& codecInst);
void DestructEncoderSafe();
void DestructEncoderSafe();
void DestructDecoderSafe();
void DestructDecoderSafe();
WebRtc_Word16 InternalCreateEncoder();
WebRtc_Word16 InternalCreateEncoder();
WebRtc_Word16 InternalCreateDecoder();
WebRtc_Word16 InternalCreateDecoder();
void InternalDestructEncoderInst(
void* ptrInst);
void InternalDestructEncoderInst(void* ptrInst);
void SplitStereoPacket(uint8_t* payload, int32_t* payload_length);
void SplitStereoPacket(uint8_t* payload, int32_t* payload_length);
WebRtc_Word32 _samplingFreqHz;
WebRtc_Word32 _samplingFreqHz;
};
} // namespace webrtc
} // namespace webrtc
#endif // WEBRTC_MODULES_AUDIO_CODING_MAIN_SOURCE_ACM_PCM16B_H_

View File

@ -120,11 +120,11 @@ void ACMPCMA::SplitStereoPacket(uint8_t* payload, int32_t* payload_length) {
// end of the bytestream vector. After looping the data is reordered to:
// l1 l2 l3 l4 ... l(N-1) lN r1 r2 r3 r4 ... r(N-1) r(N),
// where N is the total number of samples.
for (int i = 0; i < *payload_length / 2; i ++) {
for (int i = 0; i < *payload_length / 2; i++) {
right_byte = payload[i + 1];
memmove(&payload[i + 1], &payload[i + 2], *payload_length - i - 2);
payload[*payload_length - 1] = right_byte;
}
}
} // namespace webrtc
} // namespace webrtc

View File

@ -13,53 +13,45 @@
#include "acm_generic_codec.h"
namespace webrtc
{
namespace webrtc {
class ACMPCMA : public ACMGenericCodec
{
public:
ACMPCMA(WebRtc_Word16 codecID);
~ACMPCMA();
// for FEC
ACMGenericCodec* CreateInstance(void);
class ACMPCMA : public ACMGenericCodec {
public:
ACMPCMA(WebRtc_Word16 codecID);
~ACMPCMA();
// for FEC
ACMGenericCodec* CreateInstance(void);
WebRtc_Word16 InternalEncode(
WebRtc_UWord8* bitstream,
WebRtc_Word16* bitStreamLenByte);
WebRtc_Word16 InternalEncode(WebRtc_UWord8* bitstream,
WebRtc_Word16* bitStreamLenByte);
WebRtc_Word16 InternalInitEncoder(
WebRtcACMCodecParams *codecParams);
WebRtc_Word16 InternalInitEncoder(WebRtcACMCodecParams *codecParams);
WebRtc_Word16 InternalInitDecoder(
WebRtcACMCodecParams *codecParams);
WebRtc_Word16 InternalInitDecoder(WebRtcACMCodecParams *codecParams);
protected:
WebRtc_Word16 DecodeSafe(
WebRtc_UWord8* bitStream,
WebRtc_Word16 bitStreamLenByte,
WebRtc_Word16* audio,
WebRtc_Word16* audioSamples,
WebRtc_Word8* speechType);
protected:
WebRtc_Word16 DecodeSafe(WebRtc_UWord8* bitStream,
WebRtc_Word16 bitStreamLenByte,
WebRtc_Word16* audio,
WebRtc_Word16* audioSamples,
WebRtc_Word8* speechType);
WebRtc_Word32 CodecDef(
WebRtcNetEQ_CodecDef& codecDef,
const CodecInst& codecInst);
WebRtc_Word32 CodecDef(WebRtcNetEQ_CodecDef& codecDef,
const CodecInst& codecInst);
void DestructEncoderSafe();
void DestructEncoderSafe();
void DestructDecoderSafe();
void DestructDecoderSafe();
WebRtc_Word16 InternalCreateEncoder();
WebRtc_Word16 InternalCreateEncoder();
WebRtc_Word16 InternalCreateDecoder();
WebRtc_Word16 InternalCreateDecoder();
void InternalDestructEncoderInst(
void* ptrInst);
void InternalDestructEncoderInst(void* ptrInst);
void SplitStereoPacket(uint8_t* payload, int32_t* payload_length);
void SplitStereoPacket(uint8_t* payload, int32_t* payload_length);
};
} // namespace webrtc
} // namespace webrtc
#endif // WEBRTC_MODULES_AUDIO_CODING_MAIN_SOURCE_ACM_PCMA_H_

View File

@ -56,8 +56,8 @@ WebRtc_Word16 ACMPCMU::InternalInitEncoder(
WebRtc_Word16 ACMPCMU::InternalInitDecoder(
WebRtcACMCodecParams* /* codecParams */) {
// This codec does not need initialization, PCM has no instance.
return 0;
// This codec does not need initialization, PCM has no instance.
return 0;
}
WebRtc_Word32 ACMPCMU::CodecDef(WebRtcNetEQ_CodecDef& codecDef,
@ -122,11 +122,11 @@ void ACMPCMU::SplitStereoPacket(uint8_t* payload, int32_t* payload_length) {
// end of the bytestream vector. After looping the data is reordered to:
// l1 l2 l3 l4 ... l(N-1) lN r1 r2 r3 r4 ... r(N-1) r(N),
// where N is the total number of samples.
for (int i = 0; i < *payload_length / 2; i ++) {
for (int i = 0; i < *payload_length / 2; i++) {
right_byte = payload[i + 1];
memmove(&payload[i + 1], &payload[i + 2], *payload_length - i - 2);
payload[*payload_length - 1] = right_byte;
}
}
} // namespace webrtc
} // namespace webrtc

View File

@ -13,53 +13,45 @@
#include "acm_generic_codec.h"
namespace webrtc
{
namespace webrtc {
class ACMPCMU : public ACMGenericCodec
{
public:
ACMPCMU(WebRtc_Word16 codecID);
~ACMPCMU();
// for FEC
ACMGenericCodec* CreateInstance(void);
class ACMPCMU : public ACMGenericCodec {
public:
ACMPCMU(WebRtc_Word16 codecID);
~ACMPCMU();
// for FEC
ACMGenericCodec* CreateInstance(void);
WebRtc_Word16 InternalEncode(
WebRtc_UWord8* bitstream,
WebRtc_Word16* bitStreamLenByte);
WebRtc_Word16 InternalEncode(WebRtc_UWord8* bitstream,
WebRtc_Word16* bitStreamLenByte);
WebRtc_Word16 InternalInitEncoder(
WebRtcACMCodecParams *codecParams);
WebRtc_Word16 InternalInitEncoder(WebRtcACMCodecParams *codecParams);
WebRtc_Word16 InternalInitDecoder(
WebRtcACMCodecParams *codecParams);
WebRtc_Word16 InternalInitDecoder(WebRtcACMCodecParams *codecParams);
protected:
WebRtc_Word16 DecodeSafe(
WebRtc_UWord8* bitStream,
WebRtc_Word16 bitStreamLenByte,
WebRtc_Word16* audio,
WebRtc_Word16* audioSamples,
WebRtc_Word8* speechType);
protected:
WebRtc_Word16 DecodeSafe(WebRtc_UWord8* bitStream,
WebRtc_Word16 bitStreamLenByte,
WebRtc_Word16* audio,
WebRtc_Word16* audioSamples,
WebRtc_Word8* speechType);
WebRtc_Word32 CodecDef(
WebRtcNetEQ_CodecDef& codecDef,
const CodecInst& codecInst);
WebRtc_Word32 CodecDef(WebRtcNetEQ_CodecDef& codecDef,
const CodecInst& codecInst);
void DestructEncoderSafe();
void DestructEncoderSafe();
void DestructDecoderSafe();
void DestructDecoderSafe();
WebRtc_Word16 InternalCreateEncoder();
WebRtc_Word16 InternalCreateEncoder();
WebRtc_Word16 InternalCreateDecoder();
WebRtc_Word16 InternalCreateDecoder();
void InternalDestructEncoderInst(
void* ptrInst);
void InternalDestructEncoderInst(void* ptrInst);
void SplitStereoPacket(uint8_t* payload, int32_t* payload_length);
void SplitStereoPacket(uint8_t* payload, int32_t* payload_length);
};
} // namespace webrtc
} // namespace webrtc
#endif // WEBRTC_MODULES_AUDIO_CODING_MAIN_SOURCE_ACM_PCMU_H_

View File

@ -15,129 +15,89 @@
#include "webrtc_neteq.h"
#include "webrtc_neteq_help_macros.h"
namespace webrtc
{
namespace webrtc {
ACMRED::ACMRED(WebRtc_Word16 codecID)
{
_codecID = codecID;
ACMRED::ACMRED(WebRtc_Word16 codecID) {
_codecID = codecID;
}
ACMRED::~ACMRED()
{
return;
ACMRED::~ACMRED() {
return;
}
WebRtc_Word16
ACMRED::InternalEncode(
WebRtc_UWord8* /* bitStream */,
WebRtc_Word16* /* bitStreamLenByte */)
{
// RED is never used as an encoder
// RED has no instance
return 0;
WebRtc_Word16 ACMRED::InternalEncode(WebRtc_UWord8* /* bitStream */,
WebRtc_Word16* /* bitStreamLenByte */) {
// RED is never used as an encoder
// RED has no instance
return 0;
}
WebRtc_Word16
ACMRED::DecodeSafe(
WebRtc_UWord8* /* bitStream */,
WebRtc_Word16 /* bitStreamLenByte */,
WebRtc_Word16* /* audio */,
WebRtc_Word16* /* audioSamples */,
WebRtc_Word8* /* speechType */)
{
return 0;
WebRtc_Word16 ACMRED::DecodeSafe(WebRtc_UWord8* /* bitStream */,
WebRtc_Word16 /* bitStreamLenByte */,
WebRtc_Word16* /* audio */,
WebRtc_Word16* /* audioSamples */,
WebRtc_Word8* /* speechType */) {
return 0;
}
WebRtc_Word16
ACMRED::InternalInitEncoder(
WebRtcACMCodecParams* /* codecParams */)
{
// This codec does not need initialization,
// RED has no instance
return 0;
WebRtc_Word16 ACMRED::InternalInitEncoder(
WebRtcACMCodecParams* /* codecParams */) {
// This codec does not need initialization,
// RED has no instance
return 0;
}
WebRtc_Word16
ACMRED::InternalInitDecoder(
WebRtcACMCodecParams* /* codecParams */)
{
// This codec does not need initialization,
// RED has no instance
return 0;
WebRtc_Word16 ACMRED::InternalInitDecoder(
WebRtcACMCodecParams* /* codecParams */) {
// This codec does not need initialization,
// RED has no instance
return 0;
}
WebRtc_Word32 ACMRED::CodecDef(WebRtcNetEQ_CodecDef& codecDef,
const CodecInst& codecInst) {
if (!_decoderInitialized) {
// Todo:
// log error
return -1;
}
WebRtc_Word32
ACMRED::CodecDef(
WebRtcNetEQ_CodecDef& codecDef,
const CodecInst& codecInst)
{
if (!_decoderInitialized)
{
// Todo:
// log error
return -1;
}
// Fill up the structure by calling
// "SET_CODEC_PAR" & "SET_PCMU_FUNCTION."
// Then call NetEQ to add the codec to it's
// database.
SET_CODEC_PAR((codecDef), kDecoderRED, codecInst.pltype, NULL, 8000);
SET_RED_FUNCTIONS((codecDef));
return 0;
// Fill up the structure by calling
// "SET_CODEC_PAR" & "SET_PCMU_FUNCTION."
// Then call NetEQ to add the codec to it's
// database.
SET_CODEC_PAR((codecDef), kDecoderRED, codecInst.pltype, NULL, 8000);
SET_RED_FUNCTIONS((codecDef));
return 0;
}
ACMGenericCodec*
ACMRED::CreateInstance(void)
{
return NULL;
ACMGenericCodec* ACMRED::CreateInstance(void) {
return NULL;
}
WebRtc_Word16
ACMRED::InternalCreateEncoder()
{
// RED has no instance
return 0;
WebRtc_Word16 ACMRED::InternalCreateEncoder() {
// RED has no instance
return 0;
}
WebRtc_Word16
ACMRED::InternalCreateDecoder()
{
// RED has no instance
return 0;
WebRtc_Word16 ACMRED::InternalCreateDecoder() {
// RED has no instance
return 0;
}
void
ACMRED::InternalDestructEncoderInst(
void* /* ptrInst */)
{
// RED has no instance
return;
void ACMRED::InternalDestructEncoderInst(void* /* ptrInst */) {
// RED has no instance
return;
}
void
ACMRED::DestructEncoderSafe()
{
// RED has no instance
return;
void ACMRED::DestructEncoderSafe() {
// RED has no instance
return;
}
void ACMRED::DestructDecoderSafe()
{
// RED has no instance
return;
void ACMRED::DestructDecoderSafe() {
// RED has no instance
return;
}
} // namespace webrtc
} // namespace webrtc

View File

@ -13,51 +13,43 @@
#include "acm_generic_codec.h"
namespace webrtc
{
namespace webrtc {
class ACMRED : public ACMGenericCodec
{
public:
ACMRED(WebRtc_Word16 codecID);
~ACMRED();
// for FEC
ACMGenericCodec* CreateInstance(void);
class ACMRED : public ACMGenericCodec {
public:
ACMRED(WebRtc_Word16 codecID);
~ACMRED();
// for FEC
ACMGenericCodec* CreateInstance(void);
WebRtc_Word16 InternalEncode(
WebRtc_UWord8* bitstream,
WebRtc_Word16* bitStreamLenByte);
WebRtc_Word16 InternalEncode(WebRtc_UWord8* bitstream,
WebRtc_Word16* bitStreamLenByte);
WebRtc_Word16 InternalInitEncoder(
WebRtcACMCodecParams *codecParams);
WebRtc_Word16 InternalInitEncoder(WebRtcACMCodecParams *codecParams);
WebRtc_Word16 InternalInitDecoder(
WebRtcACMCodecParams *codecParams);
WebRtc_Word16 InternalInitDecoder(WebRtcACMCodecParams *codecParams);
protected:
WebRtc_Word16 DecodeSafe(
WebRtc_UWord8* bitStream,
WebRtc_Word16 bitStreamLenByte,
WebRtc_Word16* audio,
WebRtc_Word16* audioSamples,
WebRtc_Word8* speechType);
protected:
WebRtc_Word16 DecodeSafe(WebRtc_UWord8* bitStream,
WebRtc_Word16 bitStreamLenByte,
WebRtc_Word16* audio,
WebRtc_Word16* audioSamples,
WebRtc_Word8* speechType);
WebRtc_Word32 CodecDef(
WebRtcNetEQ_CodecDef& codecDef,
const CodecInst& codecInst);
WebRtc_Word32 CodecDef(WebRtcNetEQ_CodecDef& codecDef,
const CodecInst& codecInst);
void DestructEncoderSafe();
void DestructEncoderSafe();
void DestructDecoderSafe();
void DestructDecoderSafe();
WebRtc_Word16 InternalCreateEncoder();
WebRtc_Word16 InternalCreateEncoder();
WebRtc_Word16 InternalCreateDecoder();
WebRtc_Word16 InternalCreateDecoder();
void InternalDestructEncoderInst(
void* ptrInst);
void InternalDestructEncoderInst(void* ptrInst);
};
} // namespace webrtc
} // namespace webrtc
#endif // WEBRTC_MODULES_AUDIO_CODING_MAIN_SOURCE_ACM_RED_H_

View File

@ -17,35 +17,9 @@
#include "webrtc_neteq_help_macros.h"
#ifdef WEBRTC_CODEC_SPEEX
// NOTE! Speex is not included in the open-source package. The following
// interface file is needed:
//
// /modules/audio_coding/codecs/speex/main/interface/speex_interface.h
//
// The API in the header file should match the one below.
//
// int16_t WebRtcSpeex_CreateEnc(SPEEX_encinst_t **SPEEXenc_inst,
// int32_t fs);
// int16_t WebRtcSpeex_FreeEnc(SPEEX_encinst_t *SPEEXenc_inst);
// int16_t WebRtcSpeex_CreateDec(SPEEX_decinst_t **SPEEXdec_inst,
// int32_t fs,
// int16_t enh_enabled);
// int16_t WebRtcSpeex_FreeDec(SPEEX_decinst_t *SPEEXdec_inst);
// int16_t WebRtcSpeex_Encode(SPEEX_encinst_t *SPEEXenc_inst,
// int16_t *speechIn,
// int32_t rate);
// int16_t WebRtcSpeex_EncoderInit(SPEEX_encinst_t *SPEEXenc_inst,
// int16_t vbr, int16_t complexity,
// int16_t vad_enable);
// int16_t WebRtcSpeex_GetBitstream(SPEEX_encinst_t *SPEEXenc_inst,
// int16_t *encoded);
// int16_t WebRtcSpeex_DecodePlc(SPEEX_decinst_t *SPEEXdec_inst,
// int16_t *decoded, int16_t noOfLostFrames);
// int16_t WebRtcSpeex_Decode(SPEEX_decinst_t *SPEEXdec_inst,
// int16_t *encoded, int16_t len,
// int16_t *decoded, int16_t *speechType);
// int16_t WebRtcSpeex_DecoderInit(SPEEX_decinst_t *SPEEXdec_inst);
#include "speex_interface.h"
// NOTE! Speex is not included in the open-source package. Modify this file or
// your codec API to match the function calls and names of used Speex API file.
#include "speex_interface.h"
#endif
namespace webrtc {
@ -62,561 +36,431 @@ ACMSPEEX::ACMSPEEX(WebRtc_Word16 /* codecID */)
return;
}
ACMSPEEX::~ACMSPEEX()
{
return;
ACMSPEEX::~ACMSPEEX() {
return;
}
WebRtc_Word16
ACMSPEEX::InternalEncode(
WebRtc_UWord8* /* bitStream */,
WebRtc_Word16* /* bitStreamLenByte */)
{
return -1;
WebRtc_Word16 ACMSPEEX::InternalEncode(WebRtc_UWord8* /* bitStream */,
WebRtc_Word16* /* bitStreamLenByte */) {
return -1;
}
WebRtc_Word16
ACMSPEEX::DecodeSafe(
WebRtc_UWord8* /* bitStream */,
WebRtc_Word16 /* bitStreamLenByte */,
WebRtc_Word16* /* audio */,
WebRtc_Word16* /* audioSamples */,
WebRtc_Word8* /* speechType */)
{
return -1;
WebRtc_Word16 ACMSPEEX::DecodeSafe(WebRtc_UWord8* /* bitStream */,
WebRtc_Word16 /* bitStreamLenByte */,
WebRtc_Word16* /* audio */,
WebRtc_Word16* /* audioSamples */,
WebRtc_Word8* /* speechType */) {
return -1;
}
WebRtc_Word16
ACMSPEEX::EnableDTX()
{
return -1;
WebRtc_Word16 ACMSPEEX::EnableDTX() {
return -1;
}
WebRtc_Word16
ACMSPEEX::DisableDTX()
{
return -1;
WebRtc_Word16 ACMSPEEX::DisableDTX() {
return -1;
}
WebRtc_Word16
ACMSPEEX::InternalInitEncoder(
WebRtcACMCodecParams* /* codecParams */)
{
return -1;
WebRtc_Word16 ACMSPEEX::InternalInitEncoder(
WebRtcACMCodecParams* /* codecParams */) {
return -1;
}
WebRtc_Word16
ACMSPEEX::InternalInitDecoder(
WebRtcACMCodecParams* /* codecParams */)
{
return -1;
WebRtc_Word16 ACMSPEEX::InternalInitDecoder(
WebRtcACMCodecParams* /* codecParams */) {
return -1;
}
WebRtc_Word32
ACMSPEEX::CodecDef(
WebRtcNetEQ_CodecDef& /* codecDef */,
const CodecInst& /* codecInst */)
{
return -1;
WebRtc_Word32 ACMSPEEX::CodecDef(WebRtcNetEQ_CodecDef& /* codecDef */,
const CodecInst& /* codecInst */) {
return -1;
}
ACMGenericCodec*
ACMSPEEX::CreateInstance(void)
{
return NULL;
ACMGenericCodec* ACMSPEEX::CreateInstance(void) {
return NULL;
}
WebRtc_Word16
ACMSPEEX::InternalCreateEncoder()
{
return -1;
WebRtc_Word16 ACMSPEEX::InternalCreateEncoder() {
return -1;
}
void
ACMSPEEX::DestructEncoderSafe()
{
return;
void ACMSPEEX::DestructEncoderSafe() {
return;
}
WebRtc_Word16
ACMSPEEX::InternalCreateDecoder()
{
return -1;
WebRtc_Word16 ACMSPEEX::InternalCreateDecoder() {
return -1;
}
void
ACMSPEEX::DestructDecoderSafe()
{
return;
void ACMSPEEX::DestructDecoderSafe() {
return;
}
WebRtc_Word16
ACMSPEEX::SetBitRateSafe(
const WebRtc_Word32 /* rate */)
{
return -1;
WebRtc_Word16 ACMSPEEX::SetBitRateSafe(const WebRtc_Word32 /* rate */) {
return -1;
}
void
ACMSPEEX::InternalDestructEncoderInst(
void* /* ptrInst */)
{
return;
void ACMSPEEX::InternalDestructEncoderInst(void* /* ptrInst */) {
return;
}
#ifdef UNUSEDSPEEX
WebRtc_Word16
ACMSPEEX::EnableVBR()
{
return -1;
WebRtc_Word16 ACMSPEEX::EnableVBR() {
return -1;
}
WebRtc_Word16
ACMSPEEX::DisableVBR()
{
return -1;
WebRtc_Word16 ACMSPEEX::DisableVBR() {
return -1;
}
WebRtc_Word16
ACMSPEEX::SetComplMode(
WebRtc_Word16 mode)
{
return -1;
WebRtc_Word16 ACMSPEEX::SetComplMode(WebRtc_Word16 mode) {
return -1;
}
#endif
#else //===================== Actual Implementation =======================
#else //===================== Actual Implementation =======================
ACMSPEEX::ACMSPEEX(WebRtc_Word16 codecID):
_encoderInstPtr(NULL),
_decoderInstPtr(NULL)
{
_codecID = codecID;
ACMSPEEX::ACMSPEEX(WebRtc_Word16 codecID)
: _encoderInstPtr(NULL),
_decoderInstPtr(NULL) {
_codecID = codecID;
// Set sampling frequency, frame size and rate Speex
if(_codecID == ACMCodecDB::kSPEEX8)
{
_samplingFrequency = 8000;
_samplesIn20MsAudio = 160;
_encodingRate = 11000;
}
else if(_codecID == ACMCodecDB::kSPEEX16)
{
_samplingFrequency = 16000;
_samplesIn20MsAudio = 320;
_encodingRate = 22000;
}
else
{
WEBRTC_TRACE(webrtc::kTraceError, webrtc::kTraceAudioCoding, _uniqueID,
"Wrong codec id for Speex.");
// Set sampling frequency, frame size and rate Speex
if (_codecID == ACMCodecDB::kSPEEX8) {
_samplingFrequency = 8000;
_samplesIn20MsAudio = 160;
_encodingRate = 11000;
} else if (_codecID == ACMCodecDB::kSPEEX16) {
_samplingFrequency = 16000;
_samplesIn20MsAudio = 320;
_encodingRate = 22000;
} else {
WEBRTC_TRACE(webrtc::kTraceError, webrtc::kTraceAudioCoding, _uniqueID,
"Wrong codec id for Speex.");
_samplingFrequency = -1;
_samplesIn20MsAudio = -1;
_encodingRate = -1;
_samplingFrequency = -1;
_samplesIn20MsAudio = -1;
_encodingRate = -1;
}
_hasInternalDTX = true;
_dtxEnabled = false;
_vbrEnabled = false;
_complMode = 3; // default complexity value
return;
}
ACMSPEEX::~ACMSPEEX() {
if (_encoderInstPtr != NULL) {
WebRtcSpeex_FreeEnc(_encoderInstPtr);
_encoderInstPtr = NULL;
}
if (_decoderInstPtr != NULL) {
WebRtcSpeex_FreeDec(_decoderInstPtr);
_decoderInstPtr = NULL;
}
return;
}
WebRtc_Word16 ACMSPEEX::InternalEncode(WebRtc_UWord8* bitStream,
WebRtc_Word16* bitStreamLenByte) {
WebRtc_Word16 status;
WebRtc_Word16 numEncodedSamples = 0;
WebRtc_Word16 n = 0;
while (numEncodedSamples < _frameLenSmpl) {
status = WebRtcSpeex_Encode(_encoderInstPtr, &_inAudio[_inAudioIxRead],
_encodingRate);
// increment the read index this tell the caller that how far
// we have gone forward in reading the audio buffer
_inAudioIxRead += _samplesIn20MsAudio;
numEncodedSamples += _samplesIn20MsAudio;
if (status < 0) {
WEBRTC_TRACE(webrtc::kTraceError, webrtc::kTraceAudioCoding, _uniqueID,
"Error in Speex encoder");
return status;
}
_hasInternalDTX = true;
// Update VAD, if internal DTX is used
if (_hasInternalDTX && _dtxEnabled) {
_vadLabel[n++] = status;
_vadLabel[n++] = status;
}
if (status == 0) {
// This frame is detected as inactive. We need send whatever
// encoded so far.
*bitStreamLenByte = WebRtcSpeex_GetBitstream(_encoderInstPtr,
(WebRtc_Word16*) bitStream);
return *bitStreamLenByte;
}
}
*bitStreamLenByte = WebRtcSpeex_GetBitstream(_encoderInstPtr,
(WebRtc_Word16*) bitStream);
return *bitStreamLenByte;
}
WebRtc_Word16 ACMSPEEX::DecodeSafe(WebRtc_UWord8* /* bitStream */,
WebRtc_Word16 /* bitStreamLenByte */,
WebRtc_Word16* /* audio */,
WebRtc_Word16* /* audioSamples */,
WebRtc_Word8* /* speechType */) {
return 0;
}
WebRtc_Word16 ACMSPEEX::EnableDTX() {
if (_dtxEnabled) {
return 0;
} else if (_encoderExist) { // check if encoder exist
// enable DTX
if (WebRtcSpeex_EncoderInit(_encoderInstPtr, (_vbrEnabled ? 1 : 0),
_complMode, 1) < 0) {
WEBRTC_TRACE(webrtc::kTraceError, webrtc::kTraceAudioCoding, _uniqueID,
"Cannot enable DTX for Speex");
return -1;
}
_dtxEnabled = true;
return 0;
} else {
return -1;
}
return 0;
}
WebRtc_Word16 ACMSPEEX::DisableDTX() {
if (!_dtxEnabled) {
return 0;
} else if (_encoderExist) { // check if encoder exist
// disable DTX
if (WebRtcSpeex_EncoderInit(_encoderInstPtr, (_vbrEnabled ? 1 : 0),
_complMode, 0) < 0) {
WEBRTC_TRACE(webrtc::kTraceError, webrtc::kTraceAudioCoding, _uniqueID,
"Cannot disable DTX for Speex");
return -1;
}
_dtxEnabled = false;
_vbrEnabled = false;
_complMode = 3; // default complexity value
return;
}
ACMSPEEX::~ACMSPEEX()
{
if(_encoderInstPtr != NULL)
{
WebRtcSpeex_FreeEnc(_encoderInstPtr);
_encoderInstPtr = NULL;
}
if(_decoderInstPtr != NULL)
{
WebRtcSpeex_FreeDec(_decoderInstPtr);
_decoderInstPtr = NULL;
}
return;
}
WebRtc_Word16
ACMSPEEX::InternalEncode(
WebRtc_UWord8* bitStream,
WebRtc_Word16* bitStreamLenByte)
{
WebRtc_Word16 status;
WebRtc_Word16 numEncodedSamples = 0;
WebRtc_Word16 n = 0;
while( numEncodedSamples < _frameLenSmpl)
{
status = WebRtcSpeex_Encode(_encoderInstPtr, &_inAudio[_inAudioIxRead],
_encodingRate);
// increment the read index this tell the caller that how far
// we have gone forward in reading the audio buffer
_inAudioIxRead += _samplesIn20MsAudio;
numEncodedSamples += _samplesIn20MsAudio;
if(status < 0)
{
WEBRTC_TRACE(webrtc::kTraceError, webrtc::kTraceAudioCoding, _uniqueID,
"Error in Speex encoder");
return status;
}
// Update VAD, if internal DTX is used
if(_hasInternalDTX && _dtxEnabled)
{
_vadLabel[n++] = status;
_vadLabel[n++] = status;
}
if(status == 0)
{
// This frame is detected as inactive. We need send whatever
// encoded so far.
*bitStreamLenByte = WebRtcSpeex_GetBitstream(_encoderInstPtr,
(WebRtc_Word16*)bitStream);
return *bitStreamLenByte;
}
}
*bitStreamLenByte = WebRtcSpeex_GetBitstream(_encoderInstPtr,
(WebRtc_Word16*)bitStream);
return *bitStreamLenByte;
}
WebRtc_Word16
ACMSPEEX::DecodeSafe(
WebRtc_UWord8* /* bitStream */,
WebRtc_Word16 /* bitStreamLenByte */,
WebRtc_Word16* /* audio */,
WebRtc_Word16* /* audioSamples */,
WebRtc_Word8* /* speechType */)
{
return 0;
}
WebRtc_Word16
ACMSPEEX::EnableDTX()
{
if(_dtxEnabled)
{
return 0;
}
else if(_encoderExist) // check if encoder exist
{
// enable DTX
if(WebRtcSpeex_EncoderInit(_encoderInstPtr, (_vbrEnabled ? 1:0), _complMode, 1) < 0)
{
WEBRTC_TRACE(webrtc::kTraceError, webrtc::kTraceAudioCoding, _uniqueID,
"Cannot enable DTX for Speex");
return -1;
}
_dtxEnabled = true;
return 0;
}
else
{
return -1;
}
} else {
// encoder doesn't exists, therefore disabling is harmless
return 0;
}
return 0;
}
WebRtc_Word16
ACMSPEEX::DisableDTX()
{
if(!_dtxEnabled)
{
return 0;
}
else if(_encoderExist) // check if encoder exist
{
// disable DTX
if(WebRtcSpeex_EncoderInit(_encoderInstPtr, (_vbrEnabled ? 1:0), _complMode, 0) < 0)
{
WEBRTC_TRACE(webrtc::kTraceError, webrtc::kTraceAudioCoding, _uniqueID,
"Cannot disable DTX for Speex");
return -1;
}
_dtxEnabled = false;
return 0;
}
else
{
// encoder doesn't exists, therefore disabling is harmless
return 0;
}
WebRtc_Word16 ACMSPEEX::InternalInitEncoder(WebRtcACMCodecParams* codecParams) {
// sanity check
if (_encoderInstPtr == NULL) {
WEBRTC_TRACE(webrtc::kTraceError, webrtc::kTraceAudioCoding, _uniqueID,
"Cannot initialize Speex encoder, instance does not exist");
return -1;
}
WebRtc_Word16 status = SetBitRateSafe((codecParams->codecInstant).rate);
status +=
(WebRtcSpeex_EncoderInit(_encoderInstPtr, _vbrEnabled, _complMode,
((codecParams->enableDTX) ? 1 : 0)) < 0) ?
-1 : 0;
if (status >= 0) {
return 0;
} else {
WEBRTC_TRACE(webrtc::kTraceError, webrtc::kTraceAudioCoding, _uniqueID,
"Error in initialization of Speex encoder");
return -1;
}
}
WebRtc_Word16
ACMSPEEX::InternalInitEncoder(
WebRtcACMCodecParams* codecParams)
{
// sanity check
if (_encoderInstPtr == NULL)
{
WEBRTC_TRACE(webrtc::kTraceError, webrtc::kTraceAudioCoding, _uniqueID,
"Cannot initialize Speex encoder, instance does not exist");
return -1;
}
WebRtc_Word16 ACMSPEEX::InternalInitDecoder(
WebRtcACMCodecParams* /* codecParams */) {
WebRtc_Word16 status;
WebRtc_Word16 status = SetBitRateSafe((codecParams->codecInstant).rate);
status += (WebRtcSpeex_EncoderInit(_encoderInstPtr, _vbrEnabled, _complMode, ((codecParams->enableDTX)? 1:0)) < 0)? -1:0;
// sanity check
if (_decoderInstPtr == NULL) {
WEBRTC_TRACE(webrtc::kTraceError, webrtc::kTraceAudioCoding, _uniqueID,
"Cannot initialize Speex decoder, instance does not exist");
return -1;
}
status = ((WebRtcSpeex_DecoderInit(_decoderInstPtr) < 0) ? -1 : 0);
if (status >= 0) {
return 0;
} else {
WEBRTC_TRACE(webrtc::kTraceError, webrtc::kTraceAudioCoding, _uniqueID,
"Error in initialization of Speex encoder");
return -1;
}
}
WebRtc_Word16
ACMSPEEX::InternalInitDecoder(
WebRtcACMCodecParams* /* codecParams */)
{
WebRtc_Word16 status;
// sanity check
if (_decoderInstPtr == NULL)
{
WEBRTC_TRACE(webrtc::kTraceError, webrtc::kTraceAudioCoding, _uniqueID,
"Cannot initialize Speex decoder, instance does not exist");
return -1;
}
status = ((WebRtcSpeex_DecoderInit(_decoderInstPtr) < 0)? -1:0);
if (status >= 0) {
return 0;
} else {
WEBRTC_TRACE(webrtc::kTraceError, webrtc::kTraceAudioCoding, _uniqueID,
"Error in initialization of Speex decoder");
return -1;
}
}
WebRtc_Word32
ACMSPEEX::CodecDef(
WebRtcNetEQ_CodecDef& codecDef,
const CodecInst& codecInst)
{
if (!_decoderInitialized)
{
WEBRTC_TRACE(webrtc::kTraceError, webrtc::kTraceAudioCoding, _uniqueID,
"Error, Speex decoder is not initialized");
return -1;
}
// Fill up the structure by calling
// "SET_CODEC_PAR" & "SET_SPEEX_FUNCTION."
// Then call NetEQ to add the codec to its
// database.
switch(_samplingFrequency)
{
case 8000:
{
SET_CODEC_PAR((codecDef), kDecoderSPEEX_8, codecInst.pltype,
_decoderInstPtr, 8000);
break;
}
case 16000:
{
SET_CODEC_PAR((codecDef), kDecoderSPEEX_16, codecInst.pltype,
_decoderInstPtr, 16000);
break;
}
default:
{
WEBRTC_TRACE(webrtc::kTraceError, webrtc::kTraceAudioCoding, _uniqueID,
"Unsupported sampling frequency for Speex");
return -1;
}
}
SET_SPEEX_FUNCTIONS((codecDef));
if (status >= 0) {
return 0;
} else {
WEBRTC_TRACE(webrtc::kTraceError, webrtc::kTraceAudioCoding, _uniqueID,
"Error in initialization of Speex decoder");
return -1;
}
}
ACMGenericCodec*
ACMSPEEX::CreateInstance(void)
{
return NULL;
}
WebRtc_Word32 ACMSPEEX::CodecDef(WebRtcNetEQ_CodecDef& codecDef,
const CodecInst& codecInst) {
if (!_decoderInitialized) {
WEBRTC_TRACE(webrtc::kTraceError, webrtc::kTraceAudioCoding, _uniqueID,
"Error, Speex decoder is not initialized");
return -1;
}
WebRtc_Word16
ACMSPEEX::InternalCreateEncoder()
{
return WebRtcSpeex_CreateEnc(&_encoderInstPtr, _samplingFrequency);
}
// Fill up the structure by calling
// "SET_CODEC_PAR" & "SET_SPEEX_FUNCTION."
// Then call NetEQ to add the codec to its
// database.
void
ACMSPEEX::DestructEncoderSafe()
{
if(_encoderInstPtr != NULL)
{
WebRtcSpeex_FreeEnc(_encoderInstPtr);
_encoderInstPtr = NULL;
switch (_samplingFrequency) {
case 8000: {
SET_CODEC_PAR((codecDef), kDecoderSPEEX_8, codecInst.pltype,
_decoderInstPtr, 8000);
break;
}
// there is no encoder set the following
_encoderExist = false;
_encoderInitialized = false;
_encodingRate = 0;
}
WebRtc_Word16
ACMSPEEX::InternalCreateDecoder()
{
return WebRtcSpeex_CreateDec(&_decoderInstPtr, _samplingFrequency, 1);
}
void
ACMSPEEX::DestructDecoderSafe()
{
if(_decoderInstPtr != NULL)
{
WebRtcSpeex_FreeDec(_decoderInstPtr);
_decoderInstPtr = NULL;
case 16000: {
SET_CODEC_PAR((codecDef), kDecoderSPEEX_16, codecInst.pltype,
_decoderInstPtr, 16000);
break;
}
// there is no encoder instance set the followings
_decoderExist = false;
_decoderInitialized = false;
default: {
WEBRTC_TRACE(webrtc::kTraceError, webrtc::kTraceAudioCoding, _uniqueID,
"Unsupported sampling frequency for Speex");
return -1;
}
}
SET_SPEEX_FUNCTIONS((codecDef));
return 0;
}
WebRtc_Word16
ACMSPEEX::SetBitRateSafe(
const WebRtc_Word32 rate)
{
// Check if changed rate
if (rate == _encodingRate) {
return 0;
} else if (rate > 2000) {
_encodingRate = rate;
_encoderParams.codecInstant.rate = rate;
} else {
WEBRTC_TRACE(webrtc::kTraceError, webrtc::kTraceAudioCoding, _uniqueID,
"Unsupported encoding rate for Speex");
ACMGenericCodec* ACMSPEEX::CreateInstance(void) {
return NULL;
}
return -1;
}
WebRtc_Word16 ACMSPEEX::InternalCreateEncoder() {
return WebRtcSpeex_CreateEnc(&_encoderInstPtr, _samplingFrequency);
}
void ACMSPEEX::DestructEncoderSafe() {
if (_encoderInstPtr != NULL) {
WebRtcSpeex_FreeEnc(_encoderInstPtr);
_encoderInstPtr = NULL;
}
// there is no encoder set the following
_encoderExist = false;
_encoderInitialized = false;
_encodingRate = 0;
}
WebRtc_Word16 ACMSPEEX::InternalCreateDecoder() {
return WebRtcSpeex_CreateDec(&_decoderInstPtr, _samplingFrequency, 1);
}
void ACMSPEEX::DestructDecoderSafe() {
if (_decoderInstPtr != NULL) {
WebRtcSpeex_FreeDec(_decoderInstPtr);
_decoderInstPtr = NULL;
}
// there is no encoder instance set the followings
_decoderExist = false;
_decoderInitialized = false;
}
WebRtc_Word16 ACMSPEEX::SetBitRateSafe(const WebRtc_Word32 rate) {
// Check if changed rate
if (rate == _encodingRate) {
return 0;
} else if (rate > 2000) {
_encodingRate = rate;
_encoderParams.codecInstant.rate = rate;
} else {
WEBRTC_TRACE(webrtc::kTraceError, webrtc::kTraceAudioCoding, _uniqueID,
"Unsupported encoding rate for Speex");
return -1;
}
return 0;
}
void
ACMSPEEX::InternalDestructEncoderInst(
void* ptrInst)
{
if(ptrInst != NULL)
{
WebRtcSpeex_FreeEnc((SPEEX_encinst_t_*)ptrInst);
}
return;
void ACMSPEEX::InternalDestructEncoderInst(void* ptrInst) {
if (ptrInst != NULL) {
WebRtcSpeex_FreeEnc((SPEEX_encinst_t_*) ptrInst);
}
return;
}
#ifdef UNUSEDSPEEX
// This API is currently not in use. If requested to be able to enable/disable VBR
// an ACM API need to be added.
WebRtc_Word16
ACMSPEEX::EnableVBR()
{
if(_vbrEnabled)
{
return 0;
}
else if(_encoderExist) // check if encoder exist
{
// enable Variable Bit Rate (VBR)
if(WebRtcSpeex_EncoderInit(_encoderInstPtr, 1, _complMode, (_dtxEnabled? 1:0)) < 0)
{
WEBRTC_TRACE(webrtc::kTraceError, webrtc::kTraceAudioCoding, _uniqueID,
"Cannot enable VBR mode for Speex");
WebRtc_Word16 ACMSPEEX::EnableVBR() {
if (_vbrEnabled) {
return 0;
} else if (_encoderExist) // check if encoder exist
{
// enable Variable Bit Rate (VBR)
if (WebRtcSpeex_EncoderInit(_encoderInstPtr, 1, _complMode,
(_dtxEnabled ? 1 : 0)) < 0) {
WEBRTC_TRACE(webrtc::kTraceError, webrtc::kTraceAudioCoding, _uniqueID,
"Cannot enable VBR mode for Speex");
return -1;
}
_vbrEnabled = true;
return 0;
}
else
{
return -1;
return -1;
}
_vbrEnabled = true;
return 0;
} else {
return -1;
}
}
// This API is currently not in use. If requested to be able to enable/disable
// VBR an ACM API need to be added.
WebRtc_Word16 ACMSPEEX::DisableVBR() {
if (!_vbrEnabled) {
return 0;
} else if (_encoderExist) { // check if encoder exist
// disable DTX
if (WebRtcSpeex_EncoderInit(_encoderInstPtr, 0, _complMode,
(_dtxEnabled ? 1 : 0)) < 0) {
WEBRTC_TRACE(webrtc::kTraceError, webrtc::kTraceAudioCoding, _uniqueID,
"Cannot disable DTX for Speex");
// This API is currently not in use. If requested to be able to enable/disable VBR
// an ACM API need to be added.
WebRtc_Word16
ACMSPEEX::DisableVBR()
{
if(!_vbrEnabled)
{
return 0;
}
else if(_encoderExist) // check if encoder exist
{
// disable DTX
if(WebRtcSpeex_EncoderInit(_encoderInstPtr, 0, _complMode, (_dtxEnabled? 1:0)) < 0)
{
WEBRTC_TRACE(webrtc::kTraceError, webrtc::kTraceAudioCoding, _uniqueID,
"Cannot disable DTX for Speex");
return -1;
}
_vbrEnabled = false;
return 0;
}
else
{
// encoder doesn't exists, therefore disabling is harmless
return 0;
return -1;
}
_vbrEnabled = false;
return 0;
} else {
// encoder doesn't exists, therefore disabling is harmless
return 0;
}
}
// This API is currently not in use. If requested to be able to set complexity
// an ACM API need to be added.
WebRtc_Word16
ACMSPEEX::SetComplMode(
WebRtc_Word16 mode)
{
// Check if new mode
if(mode == _complMode)
{
return 0;
}
else if(_encoderExist) // check if encoder exist
{
// Set new mode
if(WebRtcSpeex_EncoderInit(_encoderInstPtr, 0, mode, (_dtxEnabled? 1:0)) < 0)
{
WEBRTC_TRACE(webrtc::kTraceError, webrtc::kTraceAudioCoding, _uniqueID,
"Error in complexity mode for Speex");
return -1;
}
_complMode = mode;
return 0;
}
else
{
// encoder doesn't exists, therefore disabling is harmless
return 0;
WebRtc_Word16 ACMSPEEX::SetComplMode(WebRtc_Word16 mode) {
// Check if new mode
if (mode == _complMode) {
return 0;
} else if (_encoderExist) { // check if encoder exist
// Set new mode
if (WebRtcSpeex_EncoderInit(_encoderInstPtr, 0, mode, (_dtxEnabled ? 1 : 0))
< 0) {
WEBRTC_TRACE(webrtc::kTraceError, webrtc::kTraceAudioCoding, _uniqueID,
"Error in complexity mode for Speex");
return -1;
}
_complMode = mode;
return 0;
} else {
// encoder doesn't exists, therefore disabling is harmless
return 0;
}
}
#endif
#endif
} // namespace webrtc
} // namespace webrtc

View File

@ -19,72 +19,63 @@ struct SPEEX_decinst_t_;
namespace webrtc {
class ACMSPEEX : public ACMGenericCodec
{
public:
ACMSPEEX(WebRtc_Word16 codecID);
~ACMSPEEX();
// for FEC
ACMGenericCodec* CreateInstance(void);
class ACMSPEEX : public ACMGenericCodec {
public:
ACMSPEEX(WebRtc_Word16 codecID);
~ACMSPEEX();
// for FEC
ACMGenericCodec* CreateInstance(void);
WebRtc_Word16 InternalEncode(
WebRtc_UWord8* bitstream,
WebRtc_Word16* bitStreamLenByte);
WebRtc_Word16 InternalEncode(WebRtc_UWord8* bitstream,
WebRtc_Word16* bitStreamLenByte);
WebRtc_Word16 InternalInitEncoder(
WebRtcACMCodecParams *codecParams);
WebRtc_Word16 InternalInitEncoder(WebRtcACMCodecParams *codecParams);
WebRtc_Word16 InternalInitDecoder(
WebRtcACMCodecParams *codecParams);
WebRtc_Word16 InternalInitDecoder(WebRtcACMCodecParams *codecParams);
protected:
WebRtc_Word16 DecodeSafe(
WebRtc_UWord8* bitStream,
WebRtc_Word16 bitStreamLenByte,
WebRtc_Word16* audio,
WebRtc_Word16* audioSamples,
WebRtc_Word8* speechType);
protected:
WebRtc_Word16 DecodeSafe(WebRtc_UWord8* bitStream,
WebRtc_Word16 bitStreamLenByte,
WebRtc_Word16* audio,
WebRtc_Word16* audioSamples,
WebRtc_Word8* speechType);
WebRtc_Word32 CodecDef(
WebRtcNetEQ_CodecDef& codecDef,
const CodecInst& codecInst);
WebRtc_Word32 CodecDef(WebRtcNetEQ_CodecDef& codecDef,
const CodecInst& codecInst);
void DestructEncoderSafe();
void DestructEncoderSafe();
void DestructDecoderSafe();
void DestructDecoderSafe();
WebRtc_Word16 InternalCreateEncoder();
WebRtc_Word16 InternalCreateEncoder();
WebRtc_Word16 InternalCreateDecoder();
WebRtc_Word16 InternalCreateDecoder();
void InternalDestructEncoderInst(
void* ptrInst);
void InternalDestructEncoderInst(void* ptrInst);
WebRtc_Word16 SetBitRateSafe(
const WebRtc_Word32 rate);
WebRtc_Word16 SetBitRateSafe(const WebRtc_Word32 rate);
WebRtc_Word16 EnableDTX();
WebRtc_Word16 EnableDTX();
WebRtc_Word16 DisableDTX();
WebRtc_Word16 DisableDTX();
#ifdef UNUSEDSPEEX
WebRtc_Word16 EnableVBR();
WebRtc_Word16 EnableVBR();
WebRtc_Word16 DisableVBR();
WebRtc_Word16 DisableVBR();
WebRtc_Word16 SetComplMode(
WebRtc_Word16 mode);
WebRtc_Word16 SetComplMode(WebRtc_Word16 mode);
#endif
SPEEX_encinst_t_* _encoderInstPtr;
SPEEX_decinst_t_* _decoderInstPtr;
WebRtc_Word16 _complMode;
bool _vbrEnabled;
WebRtc_Word32 _encodingRate;
WebRtc_Word16 _samplingFrequency;
WebRtc_UWord16 _samplesIn20MsAudio;
SPEEX_encinst_t_* _encoderInstPtr;
SPEEX_decinst_t_* _decoderInstPtr;
WebRtc_Word16 _complMode;
bool _vbrEnabled;
WebRtc_Word32 _encodingRate;
WebRtc_Word16 _samplingFrequency;
WebRtc_UWord16 _samplesIn20MsAudio;
};
} // namespace webrtc
} // namespace webrtc
#endif // WEBRTC_MODULES_AUDIO_CODING_MAIN_SOURCE_ACM_SPEEX_H_

View File

@ -8,51 +8,38 @@
* be found in the AUTHORS file in the root of the source tree.
*/
#include "acm_dtmf_detection.h"
#include "audio_coding_module.h"
#include "audio_coding_module_impl.h"
#include "trace.h"
namespace webrtc
{
namespace webrtc {
// Create module
AudioCodingModule*
AudioCodingModule::Create(
const WebRtc_Word32 id)
{
return new AudioCodingModuleImpl(id);
AudioCodingModule* AudioCodingModule::Create(const WebRtc_Word32 id) {
return new AudioCodingModuleImpl(id);
}
// Destroy module
void
AudioCodingModule::Destroy(
AudioCodingModule* module)
{
delete static_cast<AudioCodingModuleImpl*> (module);
void AudioCodingModule::Destroy(AudioCodingModule* module) {
delete static_cast<AudioCodingModuleImpl*>(module);
}
// Get number of supported codecs
WebRtc_UWord8 AudioCodingModule::NumberOfCodecs()
{
return static_cast<WebRtc_UWord8>(ACMCodecDB::kNumCodecs);
WebRtc_UWord8 AudioCodingModule::NumberOfCodecs() {
return static_cast<WebRtc_UWord8>(ACMCodecDB::kNumCodecs);
}
// Get supported codec param with id
WebRtc_Word32
AudioCodingModule::Codec(
const WebRtc_UWord8 listId,
CodecInst& codec)
{
// Get the codec settings for the codec with the given list ID
return ACMCodecDB::Codec(listId, &codec);
WebRtc_Word32 AudioCodingModule::Codec(const WebRtc_UWord8 listId,
CodecInst& codec) {
// Get the codec settings for the codec with the given list ID
return ACMCodecDB::Codec(listId, &codec);
}
// Get supported codec Param with name, frequency and number of channels.
WebRtc_Word32 AudioCodingModule::Codec(const char* payload_name,
CodecInst& codec,
int sampling_freq_hz,
CodecInst& codec, int sampling_freq_hz,
int channels) {
int codec_id;
@ -62,10 +49,10 @@ WebRtc_Word32 AudioCodingModule::Codec(const char* payload_name,
// We couldn't find a matching codec, set the parameterss to unacceptable
// values and return.
codec.plname[0] = '\0';
codec.pltype = -1;
codec.pacsize = 0;
codec.rate = 0;
codec.plfreq = 0;
codec.pltype = -1;
codec.pacsize = 0;
codec.rate = 0;
codec.plfreq = 0;
return -1;
}
@ -77,30 +64,23 @@ WebRtc_Word32 AudioCodingModule::Codec(const char* payload_name,
// Get supported codec Index with name, frequency and number of channels.
WebRtc_Word32 AudioCodingModule::Codec(const char* payload_name,
int sampling_freq_hz,
int channels) {
int sampling_freq_hz, int channels) {
return ACMCodecDB::CodecId(payload_name, sampling_freq_hz, channels);
}
// Checks the validity of the parameters of the given codec
bool
AudioCodingModule::IsCodecValid(
const CodecInst& codec)
{
int mirrorID;
char errMsg[500];
bool AudioCodingModule::IsCodecValid(const CodecInst& codec) {
int mirrorID;
char errMsg[500];
int codecNumber = ACMCodecDB::CodecNumber(&codec, &mirrorID, errMsg, 500);
int codecNumber = ACMCodecDB::CodecNumber(&codec, &mirrorID, errMsg, 500);
if(codecNumber < 0)
{
WEBRTC_TRACE(webrtc::kTraceError, webrtc::kTraceAudioCoding, -1, errMsg);
return false;
}
else
{
return true;
}
if (codecNumber < 0) {
WEBRTC_TRACE(webrtc::kTraceError, webrtc::kTraceAudioCoding, -1, errMsg);
return false;
} else {
return true;
}
}
} // namespace webrtc
} // namespace webrtc