New ACM codec database, created at compile time.

Review URL: http://webrtc-codereview.appspot.com/127002

git-svn-id: http://webrtc.googlecode.com/svn/trunk@480 4adac7df-926f-26a2-2b94-8c16560cd09d
This commit is contained in:
tina.legrand@webrtc.org 2011-08-29 11:18:44 +00:00
parent af931bdb39
commit 81fd2bfbba
8 changed files with 874 additions and 1086 deletions

View File

@ -25,22 +25,7 @@ ACMCNG::ACMCNG(WebRtc_Word16 codecID)
_encoderInstPtr = NULL;
_decoderInstPtr = NULL;
_codecID = codecID;
if(_codecID == ACMCodecDB::cnNB)
{
_sampFreqHz = 8000;
}
else if(_codecID == ACMCodecDB::cnWB)
{
_sampFreqHz = 16000;
}
else if(_codecID == ACMCodecDB::cnSWB)
{
_sampFreqHz = 32000;
}
else
{
_sampFreqHz = -1;
}
_sampFreqHz = ACMCodecDB::CodecFreq(_codecID);
return;
}

File diff suppressed because it is too large Load Diff

View File

@ -8,131 +8,284 @@
* be found in the AUTHORS file in the root of the source tree.
*/
#ifndef ACM_CODEC_DATABASE_H
#define ACM_CODEC_DATABASE_H
/*
* This file generates databases with information about all supported audio
* codecs.
*/
#ifndef WEBRTC_MODULES_AUDIO_CODING_MAIN_SOURCE_ACM_CODEC_DATABASE_H_
#define WEBRTC_MODULES_AUDIO_CODING_MAIN_SOURCE_ACM_CODEC_DATABASE_H_
#include "acm_generic_codec.h"
#include "common_types.h"
#include "typedefs.h"
#include "webrtc_neteq.h"
namespace webrtc
{
namespace webrtc {
// These might need to be increased if adding a new codec to
// the database
#define MAX_NR_OF_CODECS 52
#define MAX_NR_OF_PACSIZES 6
#define VERSION_SIZE 1000
// TODO(tlegrand): replace class ACMCodecDB with a namespace.
class ACMCodecDB {
public:
// Enum with array indexes for the supported codecs. NOTE! The order MUST
// be the same as when creating the database in acm_codec_database.cc.
enum {
kNone = -1
#if (defined(WEBRTC_CODEC_ISAC) || defined(WEBRTC_CODEC_ISACFX))
, kISAC
# if (defined(WEBRTC_CODEC_ISAC))
, kISACSWB
# endif
#endif
#ifdef WEBRTC_CODEC_PCM16
, kPCM16B
, kPCM16Bwb
, kPCM16Bswb32kHz
#endif
, kPCMU
, kPCMA
#ifdef WEBRTC_CODEC_ILBC
, kILBC
#endif
#ifdef WEBRTC_CODEC_AMR
, kGSMAMR
#endif
#ifdef WEBRTC_CODEC_AMRWB
, kGSMAMRWB
#endif
#ifdef WEBRTC_CODEC_G722
, kG722
#endif
#ifdef WEBRTC_CODEC_G722_1
, kG722_1_32
, kG722_1_24
, kG722_1_16
#endif
#ifdef WEBRTC_CODEC_G722_1C
, kG722_1C_48
, kG722_1C_32
, kG722_1C_24
#endif
#ifdef WEBRTC_CODEC_G729
, kG729
#endif
#ifdef WEBRTC_CODEC_GSMFR
, kGSMFR
#endif
#ifdef WEBRTC_CODEC_SPEEX
, kSPEEX8
, kSPEEX16
#endif
, kCNNB
, kCNWB
, kCNSWB
#ifdef WEBRTC_CODEC_AVT
, kAVT
#endif
#ifdef WEBRTC_CODEC_RED
, kRED
#endif
, kNumCodecs
};
class ACMCodecDB
{
public:
static WebRtc_Word16 Codec(
WebRtc_Word16 listnr,
CodecInst* codec_inst);
// Set unsupported codecs to -1
#ifndef WEBRTC_CODEC_ISAC
enum {kISACSWB = -1};
# ifndef WEBRTC_CODEC_ISACFX
enum {kISAC = -1};
# endif
#endif
#ifndef WEBRTC_CODEC_PCM16
enum {kPCM16B = -1};
enum {kPCM16Bwb = -1};
enum {kPCM16Bswb32kHz = -1};
#endif
// 48 kHz not supported, always set to -1.
enum {kPCM16Bswb48kHz = -1};
#ifndef WEBRTC_CODEC_ILBC
enum {kILBC = -1};
#endif
#ifndef WEBRTC_CODEC_AMR
enum {kGSMAMR = -1};
#endif
#ifndef WEBRTC_CODEC_AMRWB
enum {kGSMAMRWB = -1};
#endif
#ifndef WEBRTC_CODEC_G722
enum {kG722 = -1};
#endif
#ifndef WEBRTC_CODEC_G722_1
enum {kG722_1_32 = -1};
enum {kG722_1_24 = -1};
enum {kG722_1_16 = -1};
#endif
#ifndef WEBRTC_CODEC_G722_1C
enum {kG722_1C_48 = -1};
enum {kG722_1C_32 = -1};
enum {kG722_1C_24 = -1};
#endif
#ifndef WEBRTC_CODEC_G729
enum {kG729 = -1};
#endif
#ifndef WEBRTC_CODEC_GSMFR
enum {kGSMFR = -1};
#endif
#ifndef WEBRTC_CODEC_SPEEX
enum {kSPEEX8 = -1};
enum {kSPEEX16 = -1};
#endif
#ifndef WEBRTC_CODEC_AVT
enum {kAVT = -1};
#endif
#ifndef WEBRTC_CODEC_RED
enum {kRED = -1};
#endif
static WebRtc_Word16 CodecNumber(
const CodecInst* codec_inst,
WebRtc_Word16& mirrorID,
WebRtc_Word8* errMessage,
WebRtc_Word16 maxErrMsgLenByte);
// kMaxNumCodecs - Maximum number of codecs that can be activated in one
// build.
// kMaxNumPacketSize - Maximum number of allowed packet sizes for one codec.
// These might need to be increased if adding a new codec to the database
static const int kMaxNumCodecs = 50;
static const int kMaxNumPacketSize = 6;
static WebRtc_Word16 CodecNumber(
const CodecInst* codec_inst,
WebRtc_Word16& mirrorID);
// Codec specific settings
//
// num_packet_sizes - number of allowed packet sizes.
// packet_sizes_samples - list of the allowed packet sizes.
// basic_block_samples - assigned a value different from 0 if the codec
// requires to be fed with a specific number of samples
// that can be different from packet size.
// channel_support - number of channels supported to encode;
// 1 = mono, 2 = stereo, etc.
struct CodecSettings {
int num_packet_sizes;
int packet_sizes_samples[kMaxNumPacketSize];
int basic_block_samples;
int channel_support;
};
static WebRtc_Word16 ReceiverCodecNumber(
const CodecInst& codecInst,
WebRtc_Word16& mirrorID);
// Gets codec information from database at the position in database given by
// [codec_id].
// Input:
// [codec_id] - number that specifies at what position in the database to
// get the information.
// Output:
// [codec_inst] - filled with information about the codec.
// Return:
// 0 if successful, otherwise -1.
static int Codec(int codec_id, CodecInst* codec_inst);
static WebRtc_Word16 NoOfCodecs();
static WebRtc_Word16 NoNetEqDecoders();
static WebRtc_Word32 CodecFreq(
WebRtc_Word16 listnr);
// Returns codec id and mirror id from database, given the information
// received in the input [codec_inst]. Mirror id is a number that tells
// where to find the codec's memory (instance). The number is either the
// same as codec id (most common), or a number pointing at a different
// entry in the database, if the codec has several entries with different
// payload types. This is used for codecs that must share one struct even if
// the payload type differs.
// One example is the codec iSAC which has the same struct for both 16 and
// 32 khz, but they have different entries in the database. Let's say the
// function is called with iSAC 32kHz. The function will return 1 as that is
// the entry in the data base, and [mirror_id] = 0, as that is the entry for
// iSAC 16 kHz, which holds the shared memory.
// Input:
// [codec_inst] - Information about the codec for which we require the
// database id.
// Output:
// [mirror_id] - mirror id, which most often is the same as the return
// value, see above.
// [err_message] - if present, in the event of a mismatch found between the
// input and the database, a descriptive error message is
// written here.
// [err_message] - if present, the length of error message is returned here.
// Return:
// codec id if successful, otherwise < 0.
static int CodecNumber(const CodecInst* codec_inst, int* mirror_id,
char* err_message, int max_message_len_byte);
static int CodecNumber(const CodecInst* codec_inst, int* mirror_id);
static int ReceiverCodecNumber(const CodecInst* codec_inst, int* mirror_id);
static WebRtc_Word16 BasicCodingBlock(
WebRtc_Word16 listnr);
// Returns the codec sampling frequency for codec with id = "codec_id" in
// database.
// TODO(tlegrand): Check if function is needed, or if we can change
// to access database directly.
// Input:
// [codec_id] - number that specifies at what position in the database to
// get the information.
// Return:
// codec sampling frequency if successful, otherwise -1.
static int CodecFreq(int codec_id);
static enum WebRtcNetEQDecoder* NetEqDecoders();
// Return the codec's basic coding block size in samples.
// TODO(tlegrand): Check if function is needed, or if we can change
// to access database directly.
// Input:
// [codec_id] - number that specifies at what position in the database to
// get the information.
// Return:
// codec basic block size if successful, otherwise -1.
static int BasicCodingBlock(int codec_id);
static WebRtc_Word16 CodecsVersion(
WebRtc_Word8* version,
WebRtc_UWord32& remainingBufferInBytes,
WebRtc_UWord32& position);
// Returns the NetEQ decoder database.
static WebRtcNetEQDecoder* NetEQDecoders();
static WebRtc_Word16 MirrorID(
const WebRtc_Word16 codecID);
// All version numbers for the codecs in the database are listed in text.
// Input/Output:
// [version] - pointer to a char vector with minimum size 1000 bytes.
// Audio coding module's and all component's versions is
// written here.
// [remaining_buffer_bytes] - remaining space in buffer.
// [position] - current position to write at in buffer.
// Return:
// -1 if version information doesn't fit, 0 on success.
static int CodecsVersion(char* version, size_t* remaining_buffer_bytes,
size_t* position);
static ACMGenericCodec* CreateCodecInstance(
const CodecInst* codecInst);
// Returns mirror id, which is a number that tells where to find the codec's
// memory (instance). It is either the same as codec id (most common), or a
// number pointing at a different entry in the database, if the codec have
// several entries with different payload types. This is used for codecs that
// must share struct even if the payload type differs.
// TODO(tlegrand): Check if function is needed, or if we can change
// to access database directly.
// Input:
// [codec_id] - number that specifies codec's position in the database.
// Return:
// Mirror id on success, otherwise -1.
static int MirrorID(int codec_id);
static void initACMCodecDB();
// Create memory/instance for storing codec state.
// Input:
// [codec_inst] - information about codec. Only name of codec, "plname", is
// used in this function.
static ACMGenericCodec* CreateCodecInstance(const CodecInst* codec_inst);
static bool IsRateValid(
const WebRtc_Word16 listNr,
const WebRtc_Word32 rate);
// Checks if the bitrate is valid for the codec.
// Input:
// [codec_id] - number that specifies codec's position in the database.
// [rate] - bitrate to check.
// [frame_size_samples] - (used for iLBC) specifies which frame size to go
// with the rate.
static bool IsRateValid(int codec_id, int rate);
static bool IsISACRateValid(int rate);
static bool IsILBCRateValid(int rate, int frame_size_samples);
static bool IsISACRateValid(
const WebRtc_Word32 rate);
// Check if the payload type is valid, meaning that it is in the valid range
// of 0 to 127.
// Input:
// [payload_type] - payload type.
static bool ValidPayloadType(int payload_type);
static bool IsILBCRateValid(
const WebRtc_Word32 rate,
const WebRtc_Word16 frameSizeSamples);
static WebRtc_Word16 ValidPayloadType(
const int payloadType);
static WebRtc_Word16
pcm16b,
pcm16bwb,
pcm16bswb32,
pcm16bswb48,
pcmu,
pcma,
ilbc,
gsmAMR,
gsmAMRWB,
g722,
g722_1_32,
g722_1_24,
g722_1_16,
g722_1C_48,
g722_1C_32,
g722_1C_24,
g729,
isac,
isacswb,
gsmfr,
speex8,
speex16,
cnNB,
cnWB,
cnSWB,
avt,
red;
static WebRtc_Word16 _noOfCodecs;
static WebRtc_Word16 _noNetEqDecoders;
static WebRtc_Word16 _noPayloads;
// Information about the supported codecs
static CodecInst _mycodecs[MAX_NR_OF_CODECS];
static enum WebRtcNetEQDecoder _netEqDecoders[MAX_NR_OF_CODECS];
static WebRtc_UWord16 _allowedPacSizesSmpl[MAX_NR_OF_CODECS][MAX_NR_OF_PACSIZES];
static WebRtc_UWord8 _nrOfAllowedPacSizes[MAX_NR_OF_CODECS];
static WebRtc_UWord16 _basicCodingBlockSmpl[MAX_NR_OF_CODECS];
static WebRtc_UWord16 _channelSupport[MAX_NR_OF_CODECS];
private:
static bool _isInitiated;
static WebRtc_Word8 _versions[VERSION_SIZE];
static WebRtc_UWord32 _versionStringSize;
// Databases with information about the supported codecs
// database_ - stored information about all codecs: payload type, name,
// sampling frequency, packet size in samples, default channel
// support, and default rate.
// codec_settings_ - stored codec settings: number of allowed packet sizes,
// a vector with the allowed packet sizes, basic block
// samples, and max number of channels that are supported.
// neteq_decoders_ - list of supported decoders in NetEQ.
static const CodecInst database_[kMaxNumCodecs];
static const CodecSettings codec_settings_[kMaxNumCodecs];
static WebRtcNetEQDecoder neteq_decoders_[kMaxNumCodecs];
};
} // namespace webrtc
} // namespace webrtc
#endif //ACM_CODEC_DATABASE_H
#endif // WEBRTC_MODULES_AUDIO_CODING_MAIN_SOURCE_ACM_CODEC_DATABASE_H_

View File

@ -229,9 +229,9 @@ ACMGenericCodec::EncodeSafe(
}
// Not all codecs accept the whole frame to be pushed into
// encoder at once. "myBasicCodingBlockSmpl" is
// encoder at once.
const WebRtc_Word16 myBasicCodingBlockSmpl =
ACMCodecDB::_basicCodingBlockSmpl[_codecID];
ACMCodecDB::BasicCodingBlock(_codecID);
if((myBasicCodingBlockSmpl < 0) ||
(!_encoderInitialized) ||
(!_encoderExist))
@ -607,9 +607,9 @@ ACMGenericCodec::InitEncoderSafe(
bool forceInitialization)
{
// Check if we got a valid set of parameters
WebRtc_Word16 mirrorID;
WebRtc_Word16 codecNumber =
ACMCodecDB::CodecNumber(&(codecParams->codecInstant), mirrorID);
int mirrorID;
int codecNumber =
ACMCodecDB::CodecNumber(&(codecParams->codecInstant), &mirrorID);
if(codecNumber < 0)
{
@ -718,10 +718,10 @@ ACMGenericCodec::InitDecoderSafe(
WebRtcACMCodecParams* codecParams,
bool forceInitialization)
{
WebRtc_Word16 mirrorID;
int mirrorID;
// Check if we got a valid set of parameters
WebRtc_Word16 codecNumber =
ACMCodecDB::ReceiverCodecNumber(codecParams->codecInstant, mirrorID);
int codecNumber =
ACMCodecDB::ReceiverCodecNumber(&codecParams->codecInstant, &mirrorID);
if(codecNumber < 0)
{
@ -1308,7 +1308,6 @@ ACMGenericCodec::ProcessFrameVADDTX(
WebRtc_Word16 samplesIn10Msec = (WebRtc_Word16)(freqHz / 100);
WebRtc_Word32 frameLenMsec = (((WebRtc_Word32)_frameLenSmpl * 1000) / freqHz);
WebRtc_Word16 status;
WebRtc_Word16 vadFlag = 0;
// Vector for storing maximum 30 ms of mono audio at 32 kHz
WebRtc_Word16 audio[960];
@ -1345,10 +1344,6 @@ ACMGenericCodec::ProcessFrameVADDTX(
// Call VAD
status = WebRtcVad_Process(_ptrVADInst, (WebRtc_Word16)freqHz,
audio, noSamplesToProcess[i]);
if (status)
{
vadFlag = 1;
}
_vadLabel[i] = status;

View File

@ -248,11 +248,6 @@ ACMISAC::UnregisterFromNetEqSafe(
return -1;
}
bool
ACMISAC::IsValidDefaultEncoder()
{
return false;
}
WebRtc_Word16
ACMISAC::UpdateDecoderSampFreq(
@ -634,11 +629,11 @@ ACMISAC::InternalInitDecoder(
// set decoder sampling frequency.
if(codecParams->codecInstant.plfreq == 32000)
{
UpdateDecoderSampFreq(ACMCodecDB::isacswb);
UpdateDecoderSampFreq(ACMCodecDB::kISACSWB);
}
else
{
UpdateDecoderSampFreq(ACMCodecDB::isac);
UpdateDecoderSampFreq(ACMCodecDB::kISAC);
}
// in a one-way communication we may never register send-codec.
@ -1023,11 +1018,11 @@ ACMISAC::UpdateDecoderSampFreq(
#ifdef WEBRTC_CODEC_ISAC
WebRtc_Word16 codecId)
{
if(ACMCodecDB::isac == codecId)
if(ACMCodecDB::kISAC == codecId)
{
return WebRtcIsac_SetDecSampRate(_codecInstPtr->inst, kIsacWideband);
}
else if(ACMCodecDB::isacswb == codecId)
else if(ACMCodecDB::kISACSWB == codecId)
{
return WebRtcIsac_SetDecSampRate(_codecInstPtr->inst, kIsacSuperWideband);
}

View File

@ -42,21 +42,30 @@ AudioCodingModule::GetVersion(
{
WebRtc_Word32 len = position;
strncpy(&version[position], "AudioCodingModule 1.3.0\n", remainingBufferInBytes);
position = (WebRtc_UWord32)strlen(version);
position = static_cast<WebRtc_UWord32>(strlen(version));
remainingBufferInBytes -= (position - len);
// Get NetEQ version.
if(ACMNetEQ::GetVersion(version,
remainingBufferInBytes, position) < 0)
{
return -1;
}
ACMCodecDB::initACMCodecDB();
// Set position and size before calling ACMCodecDB::CodecsVersion
// to get versions of all codecs.
size_t current_position = position;
size_t current_remaining_bytes = remainingBufferInBytes;
if(ACMCodecDB::CodecsVersion(version,
remainingBufferInBytes, position) < 0)
&current_remaining_bytes, &current_position) < 0)
{
return -1;
}
// Update position and size of version vector.
remainingBufferInBytes = current_remaining_bytes;
position = current_position;
return 0;
}
@ -65,8 +74,7 @@ WebRtc_UWord8 AudioCodingModule::NumberOfCodecs()
{
WEBRTC_TRACE(webrtc::kTraceModuleCall, webrtc::kTraceAudioCoding, -1,
"NumberOfCodecs()");
ACMCodecDB::initACMCodecDB();
return (WebRtc_UWord8)ACMCodecDB::NoOfCodecs();
return static_cast<WebRtc_UWord8>(ACMCodecDB::kNumCodecs);
}
// Get supported codec param with id
@ -77,7 +85,6 @@ AudioCodingModule::Codec(
{
WEBRTC_TRACE(webrtc::kTraceModuleCall, webrtc::kTraceAudioCoding, -1,
"Codec(const WebRtc_UWord8 listId, CodecInst& codec)");
ACMCodecDB::initACMCodecDB();
// Get the codec settings for the codec with the given list ID
return ACMCodecDB::Codec(listId, &codec);
@ -92,11 +99,9 @@ AudioCodingModule::Codec(
{
WEBRTC_TRACE(webrtc::kTraceModuleCall, webrtc::kTraceAudioCoding, -1,
"Codec(const WebRtc_Word8* payloadName, CodecInst& codec)");
ACMCodecDB::initACMCodecDB();
// Search through codec list for a matching name
for(WebRtc_Word16 codecCntr = 0; codecCntr < ACMCodecDB::NoOfCodecs();
codecCntr++)
for(int codecCntr = 0; codecCntr < ACMCodecDB::kNumCodecs; codecCntr++)
{
// Store codec settings for codec number "codeCntr" in the output struct
ACMCodecDB::Codec(codecCntr, &codec);
@ -130,12 +135,10 @@ AudioCodingModule::Codec(
{
WEBRTC_TRACE(webrtc::kTraceModuleCall, webrtc::kTraceAudioCoding, -1,
"Codec(const WebRtc_Word8* payloadName)");
ACMCodecDB::initACMCodecDB();
CodecInst codec;
// Search through codec list for a matching name
for(WebRtc_Word16 codecCntr = 0; codecCntr < ACMCodecDB::NoOfCodecs();
codecCntr++)
for(int codecCntr = 0; codecCntr < ACMCodecDB::kNumCodecs; codecCntr++)
{
// Temporally store codec settings for codec number "codeCntr" in "codec"
ACMCodecDB::Codec(codecCntr, &codec);
@ -160,13 +163,12 @@ bool
AudioCodingModule::IsCodecValid(
const CodecInst& codec)
{
WebRtc_Word16 mirrorID;
WebRtc_Word8 errMsg[500];
int mirrorID;
char errMsg[500];
WEBRTC_TRACE(webrtc::kTraceModuleCall, webrtc::kTraceAudioCoding, -1,
"IsCodecValid(const CodecInst& codec)");
ACMCodecDB::initACMCodecDB();
WebRtc_Word16 codecNumber = ACMCodecDB::CodecNumber(&codec, mirrorID, errMsg, 500);
int codecNumber = ACMCodecDB::CodecNumber(&codec, &mirrorID, errMsg, 500);
if(codecNumber < 0)
{

View File

@ -76,8 +76,8 @@ AudioCodingModuleImpl::AudioCodingModuleImpl(
_lastInTimestamp = 0xD87F3F9F;
// nullify the codec name
strncpy(_sendCodecInst.plname, "noCodecRegistered", 31);
ACMCodecDB::initACMCodecDB();
for (WebRtc_Word16 i = 0; i < MAX_NR_OF_CODECS; i++)
for (int i = 0; i < ACMCodecDB::kMaxNumCodecs; i++)
{
_codecs[i] = NULL;
_registeredPlTypes[i] = -1;
@ -99,24 +99,24 @@ AudioCodingModuleImpl::AudioCodingModuleImpl(
// Register the default payload type for RED and for
// CNG for the three frequencies 8, 16 and 32 kHz
for (int i = (ACMCodecDB::_noOfCodecs - 1); i>=0; i--)
for (int i = (ACMCodecDB::kNumCodecs - 1); i>=0; i--)
{
if((STR_CASE_CMP(ACMCodecDB::_mycodecs[i].plname, "red") == 0))
if((STR_CASE_CMP(ACMCodecDB::database_[i].plname, "red") == 0))
{
_redPayloadType = ACMCodecDB::_mycodecs[i].pltype;
}
else if ((STR_CASE_CMP(ACMCodecDB::_mycodecs[i].plname, "CN") == 0))
_redPayloadType = ACMCodecDB::database_[i].pltype;
}
else if ((STR_CASE_CMP(ACMCodecDB::database_[i].plname, "CN") == 0))
{
if (ACMCodecDB::_mycodecs[i].plfreq == 8000)
if (ACMCodecDB::database_[i].plfreq == 8000)
{
memcpy(&_cngNB, &ACMCodecDB::_mycodecs[i], sizeof(_cngNB));
}
else if (ACMCodecDB::_mycodecs[i].plfreq == 16000)
memcpy(&_cngNB, &ACMCodecDB::database_[i], sizeof(_cngNB));
}
else if (ACMCodecDB::database_[i].plfreq == 16000)
{
memcpy(&_cngWB, &ACMCodecDB::_mycodecs[i], sizeof(_cngWB));
} else if (ACMCodecDB::_mycodecs[i].plfreq == 32000)
memcpy(&_cngWB, &ACMCodecDB::database_[i], sizeof(_cngWB));
} else if (ACMCodecDB::database_[i].plfreq == 32000)
{
memcpy(&_cngSWB, &ACMCodecDB::_mycodecs[i], sizeof(_cngSWB));
memcpy(&_cngSWB, &ACMCodecDB::database_[i], sizeof(_cngSWB));
}
}
}
@ -163,7 +163,7 @@ AudioCodingModuleImpl::~AudioCodingModuleImpl()
CriticalSectionScoped lock(*_acmCritSect);
_currentSendCodecIdx = -1;
for (WebRtc_Word16 i=0; i < MAX_NR_OF_CODECS; i++)
for (int i=0; i < ACMCodecDB::kMaxNumCodecs; i++)
{
if (_codecs[i] != NULL)
{
@ -276,7 +276,7 @@ AudioCodingModuleImpl::ChangeUniqueId(
_outgoingPL = fopen(fileName, "wb");
#endif
for (WebRtc_Word16 i = 0; i < MAX_NR_OF_CODECS; i++)
for (int i = 0; i < ACMCodecDB::kMaxNumCodecs; i++)
{
if(_codecs[i] != NULL)
{
@ -569,7 +569,7 @@ AudioCodingModuleImpl::InitializeSender()
_sendCodecInst.plname[0] = '\0';
for(WebRtc_Word16 codecCntr = 0; codecCntr < MAX_NR_OF_CODECS; codecCntr++)
for(int codecCntr = 0; codecCntr < ACMCodecDB::kMaxNumCodecs; codecCntr++)
{
if(_codecs[codecCntr] != NULL)
{
@ -664,9 +664,10 @@ mono codecs are supported, i.e. channels=1.", sendCodec.channels);
return -1;
}
WebRtc_Word8 errMsg[500];
WebRtc_Word16 mirrorId;
WebRtc_Word16 codecID = ACMCodecDB::CodecNumber(&sendCodec, mirrorId, errMsg, 500);
char errMsg[500];
int mirrorId;
int codecID = ACMCodecDB::CodecNumber(&sendCodec, &mirrorId, errMsg,
sizeof(errMsg));
CriticalSectionScoped lock(*_acmCritSect);
// Check for reported errors from function CodecNumber()
@ -695,7 +696,7 @@ mono codecs are supported, i.e. channels=1.", sendCodec.channels);
if(!STR_CASE_CMP(sendCodec.plname, "red"))
{
// Check if the payload-type is valid
if(ACMCodecDB::ValidPayloadType(sendCodec.pltype) < 0)
if(!ACMCodecDB::ValidPayloadType(sendCodec.pltype))
{
WEBRTC_TRACE(webrtc::kTraceError, webrtc::kTraceAudioCoding, _id,
"Invalid payload-type %d for %s.",
@ -742,7 +743,7 @@ mono codecs are supported, i.e. channels=1.", sendCodec.channels);
}
// Check if the payload-type is valid
if(ACMCodecDB::ValidPayloadType(sendCodec.pltype) < 0)
if(!ACMCodecDB::ValidPayloadType(sendCodec.pltype))
{
WEBRTC_TRACE(webrtc::kTraceError, webrtc::kTraceAudioCoding, _id,
"Invalid payload-type %d for %s.",
@ -751,7 +752,7 @@ mono codecs are supported, i.e. channels=1.", sendCodec.channels);
}
// Check if codec supports the number of channels
if(ACMCodecDB::_channelSupport[codecID] < sendCodec.channels)
if(ACMCodecDB::codec_settings_[codecID].channel_support < sendCodec.channels)
{
WEBRTC_TRACE(webrtc::kTraceError, webrtc::kTraceAudioCoding, _id,
"%d number of channels not supportedn for %s.",
@ -769,9 +770,9 @@ mono codecs are supported, i.e. channels=1.", sendCodec.channels);
bool oldCodecFamily;
if(_sendCodecRegistered)
{
WebRtc_Word16 sendCodecMirrorID;
WebRtc_Word16 sendCodecID =
ACMCodecDB::CodecNumber(&_sendCodecInst, sendCodecMirrorID);
int sendCodecMirrorID;
int sendCodecID =
ACMCodecDB::CodecNumber(&_sendCodecInst, &sendCodecMirrorID);
assert(sendCodecID >= 0);
oldCodecFamily = (sendCodecID == codecID) || (mirrorId == sendCodecMirrorID);
}
@ -879,7 +880,7 @@ with the previously registered codec");
// At this point check if the given payload type is valid.
// Record it later when the sampling frequency is changed
// successfully.
if(ACMCodecDB::ValidPayloadType(sendCodec.pltype) < 0)
if(!ACMCodecDB::ValidPayloadType(sendCodec.pltype))
{
WEBRTC_TRACE(webrtc::kTraceError, webrtc::kTraceAudioCoding, _id,
"Out of range payload type");
@ -1355,15 +1356,13 @@ AudioCodingModuleImpl::InitializeReceiverSafe()
{
WEBRTC_TRACE(webrtc::kTraceModuleCall, webrtc::kTraceAudioCoding, _id,
"InitializeReceiver()");
WebRtc_Word16 noCodecs = ACMCodecDB::NoOfCodecs();
int i = 0;
// If the receiver is already initialized then we
// also like to destruct decoders if any exist. After a call
// to this function, we should have a clean start-up.
if(_receiverInitialized)
{
for(WebRtc_Word16 codecCntr = 0; codecCntr < noCodecs; codecCntr++)
for(int codecCntr = 0; codecCntr < ACMCodecDB::kNumCodecs; codecCntr++)
{
if(UnregisterReceiveCodecSafe(codecCntr) < 0)
{
@ -1376,36 +1375,36 @@ AudioCodingModuleImpl::InitializeReceiverSafe()
if (_netEq.Init() != 0)
{
WEBRTC_TRACE(webrtc::kTraceError, webrtc::kTraceAudioCoding, _id,
"InitializeReceiver() failed, Could not initialize NetEq");
"InitializeReceiver() failed, Could not initialize NetEQ");
return -1;
}
_netEq.SetUniqueId(_id);
if (_netEq.AllocatePacketBuffer(ACMCodecDB::NetEqDecoders(),
ACMCodecDB::NoNetEqDecoders()) != 0)
if (_netEq.AllocatePacketBuffer(ACMCodecDB::NetEQDecoders(),
ACMCodecDB::kNumCodecs) != 0)
{
WEBRTC_TRACE(webrtc::kTraceError, webrtc::kTraceAudioCoding, _id,
"NetEq cannot allocatePacket Buffer");
"NetEQ cannot allocatePacket Buffer");
return -1;
}
// Register RED and CN
int regInNeteq = 0;
for (i = (ACMCodecDB::_noOfCodecs - 1); i>-1; i--) {
if((STR_CASE_CMP(ACMCodecDB::_mycodecs[i].plname, "red") == 0)) {
for (int i = (ACMCodecDB::kNumCodecs - 1); i>-1; i--) {
if((STR_CASE_CMP(ACMCodecDB::database_[i].plname, "red") == 0)) {
regInNeteq = 1;
} else if ((STR_CASE_CMP(ACMCodecDB::_mycodecs[i].plname, "CN") == 0)) {
} else if ((STR_CASE_CMP(ACMCodecDB::database_[i].plname, "CN") == 0)) {
regInNeteq = 1;
}
if (regInNeteq == 1) {
if(RegisterRecCodecMSSafe(ACMCodecDB::_mycodecs[i], i, i,
if(RegisterRecCodecMSSafe(ACMCodecDB::database_[i], i, i,
ACMNetEQ::masterJB) < 0)
{
WEBRTC_TRACE(webrtc::kTraceError, webrtc::kTraceAudioCoding, _id,
"Cannot register master codec.");
return -1;
}
_registeredPlTypes[i] = ACMCodecDB::_mycodecs[i].pltype;
_registeredPlTypes[i] = ACMCodecDB::database_[i].pltype;
regInNeteq = 0;
}
}
@ -1422,7 +1421,7 @@ AudioCodingModuleImpl::ResetDecoder()
"ResetDecoder()");
CriticalSectionScoped lock(*_acmCritSect);
for(WebRtc_Word16 codecCntr = 0; codecCntr < MAX_NR_OF_CODECS; codecCntr++)
for(int codecCntr = 0; codecCntr < ACMCodecDB::kMaxNumCodecs; codecCntr++)
{
if((_codecs[codecCntr] != NULL) && (_registeredPlTypes[codecCntr] != -1))
{
@ -1487,17 +1486,17 @@ AudioCodingModuleImpl::RegisterReceiveCodec(
return -1;
}
WebRtc_Word16 mirrorId;
WebRtc_Word16 codecId = ACMCodecDB::ReceiverCodecNumber(receiveCodec, mirrorId);
int mirrorId;
int codecId = ACMCodecDB::ReceiverCodecNumber(&receiveCodec, &mirrorId);
if(codecId < 0 || codecId >= ACMCodecDB::NoOfCodecs())
if(codecId < 0 || codecId >= ACMCodecDB::kNumCodecs)
{
WEBRTC_TRACE(webrtc::kTraceError, webrtc::kTraceAudioCoding, _id,
"Wrong codec params to be registered as receive codec");
return -1;
}
// Check if the payload-type is valid.
if(ACMCodecDB::ValidPayloadType(receiveCodec.pltype) < 0)
if(!ACMCodecDB::ValidPayloadType(receiveCodec.pltype))
{
WEBRTC_TRACE(webrtc::kTraceError, webrtc::kTraceAudioCoding, _id,
"Invalid payload-type %d for %s.",
@ -1540,11 +1539,11 @@ AudioCodingModuleImpl::RegisterReceiveCodec(
{
if(_netEq.NumSlaves() < 1)
{
if(_netEq.AddSlave(ACMCodecDB::NetEqDecoders(),
ACMCodecDB::NoNetEqDecoders()) < 0)
if(_netEq.AddSlave(ACMCodecDB::NetEQDecoders(),
ACMCodecDB::kNumCodecs) < 0)
{
WEBRTC_TRACE(webrtc::kTraceError, webrtc::kTraceAudioCoding, _id,
"Cannot Add Slave jitter buffer to NetEq.");
"Cannot Add Slave jitter buffer to NetEQ.");
return -1;
}
}
@ -1660,12 +1659,12 @@ AudioCodingModuleImpl::RegisterRecCodecMSSafe(
!= 0)
{
WEBRTC_TRACE(webrtc::kTraceError, webrtc::kTraceAudioCoding, _id,
"Receive codec could not be registered in NetEq");
"Receive codec could not be registered in NetEQ");
return -1;
}
// Guaranty that the same payload-type that is
// registered in NetEq is stored in the codec.
// registered in NetEQ is stored in the codec.
codecArray[codecId]->SaveDecoderParam(&codecParams);
}
@ -1681,11 +1680,10 @@ AudioCodingModuleImpl::ReceiveCodec(
{
WEBRTC_TRACE(webrtc::kTraceModuleCall, webrtc::kTraceAudioCoding, _id,
"ReceiveCodec()");
WebRtc_Word16 decCntr;
WebRtcACMCodecParams decoderParam;
CriticalSectionScoped lock(*_acmCritSect);
for(decCntr = 0; decCntr < MAX_NR_OF_CODECS; decCntr++)
for(int decCntr = 0; decCntr < ACMCodecDB::kMaxNumCodecs; decCntr++)
{
if(_codecs[decCntr] != NULL)
{
@ -1768,8 +1766,7 @@ AudioCodingModuleImpl::IncomingPacket(
// I cannot use the function that BV has written, i.e.
// "DecoderParamByPlType()" as for iSAC there is one instance and
// multiple payloads.
int i;
for(i = 0; i < MAX_NR_OF_CODECS; i++)
for(int i = 0; i < ACMCodecDB::kMaxNumCodecs; i++)
{
if(_registeredPlTypes[i] == myPayloadType)
{
@ -1869,8 +1866,7 @@ AudioCodingModuleImpl::DecoderEstimatedBandwidth() const
int plTypSWB;
// Get iSAC settings
for(WebRtc_Word16 codecCntr = 0; codecCntr < ACMCodecDB::NoOfCodecs();
codecCntr++)
for(int codecCntr = 0; codecCntr < ACMCodecDB::kNumCodecs; codecCntr++)
{
// Store codec settings for codec number "codeCntr" in the output struct
ACMCodecDB::Codec(codecCntr, &codecInst);
@ -2016,11 +2012,11 @@ AudioCodingModuleImpl::PlayoutData10Ms(
{
// we are in 8 kHz so the master channel needs only 80 samples
WebRtc_Word16 masterChannel[80];
for(WebRtc_Word16 n = 0; n < 80; n++)
for(int n = 0; n < 80; n++)
{
masterChannel[n] = audioFrame._payloadData[n<<1];
}
_dtmfDetector->Detect(audioFrame._payloadData,
_dtmfDetector->Detect(masterChannel,
audioFrame._payloadDataLengthInSamples,
audioFrame._frequencyInHz, toneDetected, tone);
}
@ -2037,12 +2033,11 @@ AudioCodingModuleImpl::PlayoutData10Ms(
else
{
WebRtc_Word16 masterChannel[WEBRTC_10MS_PCM_AUDIO];
WebRtc_Word16 n;
for(n = 0; n < audioFrameTmp._payloadDataLengthInSamples; n++)
for(int n = 0; n < audioFrameTmp._payloadDataLengthInSamples; n++)
{
masterChannel[n] = audioFrameTmp._payloadData[n<<1];
}
_dtmfDetector->Detect(audioFrameTmp._payloadData,
_dtmfDetector->Detect(masterChannel,
audioFrameTmp._payloadDataLengthInSamples, recvFreq,
toneDetected, tone);
}
@ -2338,7 +2333,7 @@ AudioCodingModuleImpl::DecoderParamByPlType(
WebRtcACMCodecParams& codecParams) const
{
CriticalSectionScoped lock(*_acmCritSect);
for(WebRtc_Word16 codecCntr = 0; codecCntr < MAX_NR_OF_CODECS; codecCntr++)
for(WebRtc_Word16 codecCntr = 0; codecCntr < ACMCodecDB::kMaxNumCodecs; codecCntr++)
{
if(_codecs[codecCntr] != NULL)
{
@ -2371,7 +2366,7 @@ AudioCodingModuleImpl::DecoderListIDByPlName(
{
WebRtcACMCodecParams codecParams;
CriticalSectionScoped lock(*_acmCritSect);
for(WebRtc_Word16 codecCntr = 0; codecCntr < MAX_NR_OF_CODECS; codecCntr++)
for(WebRtc_Word16 codecCntr = 0; codecCntr < ACMCodecDB::kMaxNumCodecs; codecCntr++)
{
if((_codecs[codecCntr] != NULL))
{
@ -2559,17 +2554,16 @@ bool
AudioCodingModuleImpl::HaveValidEncoder(
const WebRtc_Word8* callerName) const
{
WebRtc_Word16 numCodecs = ACMCodecDB::NoOfCodecs();
if((!_sendCodecRegistered) ||
(_currentSendCodecIdx < 0) ||
(_currentSendCodecIdx >= numCodecs))
(_currentSendCodecIdx >= ACMCodecDB::kNumCodecs))
{
WEBRTC_TRACE(webrtc::kTraceError, webrtc::kTraceAudioCoding, _id,
"%s failed: No send codec is registered.", callerName);
return false;
}
if((_currentSendCodecIdx < 0) ||
(_currentSendCodecIdx >= numCodecs))
(_currentSendCodecIdx >= ACMCodecDB::kNumCodecs))
{
WEBRTC_TRACE(webrtc::kTraceError, webrtc::kTraceAudioCoding, _id,
"%s failed: Send codec index out of range.", callerName);
@ -2594,7 +2588,7 @@ AudioCodingModuleImpl::UnregisterReceiveCodec(
WebRtc_Word16 codecID;
// Search through the list of registered payload types
for (codecID = 0; codecID < MAX_NR_OF_CODECS; codecID++)
for (codecID = 0; codecID < ACMCodecDB::kMaxNumCodecs; codecID++)
{
if (_registeredPlTypes[codecID] == payloadType)
{
@ -2603,17 +2597,10 @@ AudioCodingModuleImpl::UnregisterReceiveCodec(
}
}
if(codecID >= ACMCodecDB::NoOfCodecs())
if(codecID >= ACMCodecDB::kNumCodecs)
{
// payload type was not registered. No need to unregister
return 0;
}
else if(codecID < 0)
{
WEBRTC_TRACE(webrtc::kTraceError, webrtc::kTraceAudioCoding, _id,
"UnregisterReceiveCodec() failed: the given codec, %s, is not supported",
payloadType);
return -1;
}
// Unregister the codec with the given payload type
@ -2624,32 +2611,32 @@ WebRtc_Word32
AudioCodingModuleImpl::UnregisterReceiveCodecSafe(
const WebRtc_Word16 codecID)
{
WebRtcNetEQDecoder *neteqDecoder = ACMCodecDB::NetEqDecoders();
WebRtcNetEQDecoder *neteqDecoder = ACMCodecDB::NetEQDecoders();
WebRtc_Word16 mirrorID = ACMCodecDB::MirrorID(codecID);
if(_codecs[codecID] != NULL)
{
if(_registeredPlTypes[codecID] != -1)
{
// before deleting the decoder instance unregister
// from NetEq.
// from NetEQ.
if(_netEq.RemoveCodec(neteqDecoder[codecID], _stereoReceive[codecID]) < 0)
{
CodecInst codecInst;
ACMCodecDB::Codec(codecID, &codecInst);
WEBRTC_TRACE(webrtc::kTraceError, webrtc::kTraceAudioCoding, _id,
"Unregistering %s-%d from NetEq failed.",
"Unregistering %s-%d from NetEQ failed.",
codecInst.plname, codecInst.plfreq);
return -1;
}
// CN is a special case for NetEQ, all three sampling frequencies are
// deletad if one is deleted
if(STR_CASE_CMP(ACMCodecDB::_mycodecs[codecID].plname, "CN") == 0)
if(STR_CASE_CMP(ACMCodecDB::database_[codecID].plname, "CN") == 0)
{
// Search codecs nearby in the database to unregister all CN.
for (int i=-2; i<3; i++)
{
if (STR_CASE_CMP(ACMCodecDB::_mycodecs[codecID+i].plname, "CN") == 0)
if (STR_CASE_CMP(ACMCodecDB::database_[codecID+i].plname, "CN") == 0)
{
_codecs[codecID+i]->DestructDecoder();
if(_stereoReceive[codecID+i])

View File

@ -339,10 +339,10 @@ private:
bool _vadEnabled;
bool _dtxEnabled;
ACMVADMode _vadMode;
ACMGenericCodec* _codecs[MAX_NR_OF_CODECS];
ACMGenericCodec* _slaveCodecs[MAX_NR_OF_CODECS];
WebRtc_Word16 _mirrorCodecIdx[MAX_NR_OF_CODECS];
bool _stereoReceive[MAX_NR_OF_CODECS];
ACMGenericCodec* _codecs[ACMCodecDB::kMaxNumCodecs];
ACMGenericCodec* _slaveCodecs[ACMCodecDB::kMaxNumCodecs];
WebRtc_Word16 _mirrorCodecIdx[ACMCodecDB::kMaxNumCodecs];
bool _stereoReceive[ACMCodecDB::kMaxNumCodecs];
bool _stereoSend;
WebRtc_Word32 _currentSendCodecIdx;
bool _sendCodecRegistered;
@ -370,7 +370,7 @@ private:
// This keeps track of payload types associated with _codecs[].
// We define it as signed variable and initialize with -1 to indicate
// unused elements.
WebRtc_Word16 _registeredPlTypes[MAX_NR_OF_CODECS];
WebRtc_Word16 _registeredPlTypes[ACMCodecDB::kMaxNumCodecs];
// Used when payloads are pushed into ACM without any RTP info
// One example is when pre-encoded bit-stream is pushed from