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; _encoderInstPtr = NULL;
_decoderInstPtr = NULL; _decoderInstPtr = NULL;
_codecID = codecID; _codecID = codecID;
if(_codecID == ACMCodecDB::cnNB) _sampFreqHz = ACMCodecDB::CodecFreq(_codecID);
{
_sampFreqHz = 8000;
}
else if(_codecID == ACMCodecDB::cnWB)
{
_sampFreqHz = 16000;
}
else if(_codecID == ACMCodecDB::cnSWB)
{
_sampFreqHz = 32000;
}
else
{
_sampFreqHz = -1;
}
return; 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. * 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 "acm_generic_codec.h"
#include "common_types.h" #include "common_types.h"
#include "typedefs.h"
#include "webrtc_neteq.h" #include "webrtc_neteq.h"
namespace webrtc namespace webrtc {
{
// These might need to be increased if adding a new codec to // TODO(tlegrand): replace class ACMCodecDB with a namespace.
// the database class ACMCodecDB {
#define MAX_NR_OF_CODECS 52 public:
#define MAX_NR_OF_PACSIZES 6 // Enum with array indexes for the supported codecs. NOTE! The order MUST
#define VERSION_SIZE 1000 // 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 // Set unsupported codecs to -1
{ #ifndef WEBRTC_CODEC_ISAC
public: enum {kISACSWB = -1};
static WebRtc_Word16 Codec( # ifndef WEBRTC_CODEC_ISACFX
WebRtc_Word16 listnr, enum {kISAC = -1};
CodecInst* codec_inst); # 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
// kMaxNumCodecs - Maximum number of codecs that can be activated in one
static WebRtc_Word16 CodecNumber( // build.
const CodecInst* codec_inst, // kMaxNumPacketSize - Maximum number of allowed packet sizes for one codec.
WebRtc_Word16& mirrorID, // These might need to be increased if adding a new codec to the database
WebRtc_Word8* errMessage, static const int kMaxNumCodecs = 50;
WebRtc_Word16 maxErrMsgLenByte); static const int kMaxNumPacketSize = 6;
static WebRtc_Word16 CodecNumber( // Codec specific settings
const CodecInst* codec_inst, //
WebRtc_Word16& mirrorID); // 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( // Gets codec information from database at the position in database given by
const CodecInst& codecInst, // [codec_id].
WebRtc_Word16& mirrorID); // 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(); // Returns codec id and mirror id from database, given the information
// received in the input [codec_inst]. Mirror id is a number that tells
static WebRtc_Word16 NoNetEqDecoders(); // 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
static WebRtc_Word32 CodecFreq( // entry in the database, if the codec has several entries with different
WebRtc_Word16 listnr); // 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( // Returns the codec sampling frequency for codec with id = "codec_id" in
WebRtc_Word16 listnr); // 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( // Returns the NetEQ decoder database.
WebRtc_Word8* version, static WebRtcNetEQDecoder* NetEQDecoders();
WebRtc_UWord32& remainingBufferInBytes,
WebRtc_UWord32& position);
static WebRtc_Word16 MirrorID( // All version numbers for the codecs in the database are listed in text.
const WebRtc_Word16 codecID); // 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( // Returns mirror id, which is a number that tells where to find the codec's
const CodecInst* codecInst); // 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( // Checks if the bitrate is valid for the codec.
const WebRtc_Word16 listNr, // Input:
const WebRtc_Word32 rate); // [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( // Check if the payload type is valid, meaning that it is in the valid range
const WebRtc_Word32 rate); // of 0 to 127.
// Input:
// [payload_type] - payload type.
static bool ValidPayloadType(int payload_type);
static bool IsILBCRateValid( // Databases with information about the supported codecs
const WebRtc_Word32 rate, // database_ - stored information about all codecs: payload type, name,
const WebRtc_Word16 frameSizeSamples); // sampling frequency, packet size in samples, default channel
// support, and default rate.
static WebRtc_Word16 ValidPayloadType( // codec_settings_ - stored codec settings: number of allowed packet sizes,
const int payloadType); // a vector with the allowed packet sizes, basic block
// samples, and max number of channels that are supported.
static WebRtc_Word16 // neteq_decoders_ - list of supported decoders in NetEQ.
pcm16b, static const CodecInst database_[kMaxNumCodecs];
pcm16bwb, static const CodecSettings codec_settings_[kMaxNumCodecs];
pcm16bswb32, static WebRtcNetEQDecoder neteq_decoders_[kMaxNumCodecs];
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;
}; };
} // 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 // Not all codecs accept the whole frame to be pushed into
// encoder at once. "myBasicCodingBlockSmpl" is // encoder at once.
const WebRtc_Word16 myBasicCodingBlockSmpl = const WebRtc_Word16 myBasicCodingBlockSmpl =
ACMCodecDB::_basicCodingBlockSmpl[_codecID]; ACMCodecDB::BasicCodingBlock(_codecID);
if((myBasicCodingBlockSmpl < 0) || if((myBasicCodingBlockSmpl < 0) ||
(!_encoderInitialized) || (!_encoderInitialized) ||
(!_encoderExist)) (!_encoderExist))
@ -607,9 +607,9 @@ ACMGenericCodec::InitEncoderSafe(
bool forceInitialization) bool forceInitialization)
{ {
// Check if we got a valid set of parameters // Check if we got a valid set of parameters
WebRtc_Word16 mirrorID; int mirrorID;
WebRtc_Word16 codecNumber = int codecNumber =
ACMCodecDB::CodecNumber(&(codecParams->codecInstant), mirrorID); ACMCodecDB::CodecNumber(&(codecParams->codecInstant), &mirrorID);
if(codecNumber < 0) if(codecNumber < 0)
{ {
@ -718,10 +718,10 @@ ACMGenericCodec::InitDecoderSafe(
WebRtcACMCodecParams* codecParams, WebRtcACMCodecParams* codecParams,
bool forceInitialization) bool forceInitialization)
{ {
WebRtc_Word16 mirrorID; int mirrorID;
// Check if we got a valid set of parameters // Check if we got a valid set of parameters
WebRtc_Word16 codecNumber = int codecNumber =
ACMCodecDB::ReceiverCodecNumber(codecParams->codecInstant, mirrorID); ACMCodecDB::ReceiverCodecNumber(&codecParams->codecInstant, &mirrorID);
if(codecNumber < 0) if(codecNumber < 0)
{ {
@ -1308,7 +1308,6 @@ ACMGenericCodec::ProcessFrameVADDTX(
WebRtc_Word16 samplesIn10Msec = (WebRtc_Word16)(freqHz / 100); WebRtc_Word16 samplesIn10Msec = (WebRtc_Word16)(freqHz / 100);
WebRtc_Word32 frameLenMsec = (((WebRtc_Word32)_frameLenSmpl * 1000) / freqHz); WebRtc_Word32 frameLenMsec = (((WebRtc_Word32)_frameLenSmpl * 1000) / freqHz);
WebRtc_Word16 status; WebRtc_Word16 status;
WebRtc_Word16 vadFlag = 0;
// Vector for storing maximum 30 ms of mono audio at 32 kHz // Vector for storing maximum 30 ms of mono audio at 32 kHz
WebRtc_Word16 audio[960]; WebRtc_Word16 audio[960];
@ -1345,10 +1344,6 @@ ACMGenericCodec::ProcessFrameVADDTX(
// Call VAD // Call VAD
status = WebRtcVad_Process(_ptrVADInst, (WebRtc_Word16)freqHz, status = WebRtcVad_Process(_ptrVADInst, (WebRtc_Word16)freqHz,
audio, noSamplesToProcess[i]); audio, noSamplesToProcess[i]);
if (status)
{
vadFlag = 1;
}
_vadLabel[i] = status; _vadLabel[i] = status;

View File

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

View File

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

View File

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

View File

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