From 81fd2bfbbabb227d2bcfd7f74bb525effa42a337 Mon Sep 17 00:00:00 2001 From: "tina.legrand@webrtc.org" Date: Mon, 29 Aug 2011 11:18:44 +0000 Subject: [PATCH] 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 --- .../audio_coding/main/source/acm_cng.cc | 17 +- .../main/source/acm_codec_database.cc | 1357 +++++++---------- .../main/source/acm_codec_database.h | 363 +++-- .../main/source/acm_generic_codec.cc | 21 +- .../audio_coding/main/source/acm_isac.cc | 13 +- .../main/source/audio_coding_module.cc | 34 +- .../main/source/audio_coding_module_impl.cc | 145 +- .../main/source/audio_coding_module_impl.h | 10 +- 8 files changed, 874 insertions(+), 1086 deletions(-) diff --git a/src/modules/audio_coding/main/source/acm_cng.cc b/src/modules/audio_coding/main/source/acm_cng.cc index 20bbdf4598..606fb8a23d 100644 --- a/src/modules/audio_coding/main/source/acm_cng.cc +++ b/src/modules/audio_coding/main/source/acm_cng.cc @@ -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; } diff --git a/src/modules/audio_coding/main/source/acm_codec_database.cc b/src/modules/audio_coding/main/source/acm_codec_database.cc index 2945eebe6f..cc552e43ad 100644 --- a/src/modules/audio_coding/main/source/acm_codec_database.cc +++ b/src/modules/audio_coding/main/source/acm_codec_database.cc @@ -8,14 +8,21 @@ * be found in the AUTHORS file in the root of the source tree. */ +/* + * This file generates databases with information about all supported audio + * codecs. + */ + +// TODO(tlegrand): Change constant input pointers in all functions to constant +// references, where appripriate. +#include "acm_codec_database.h" + #include -#include "acm_codec_database.h" #include "acm_common_defs.h" #include "trace.h" -// Includes needed to get version info -// and to create the codecs +// Includes needed to get version info and to create the codecs. #include "acm_pcma.h" #include "acm_pcmu.h" #include "g711_interface.h" @@ -51,900 +58,564 @@ #include "g722_interface.h" #endif -namespace webrtc -{ +namespace webrtc { -#define TEMPORARY_BUFFER_SIZE 500 - -bool ACMCodecDB::_isInitiated = false; -WebRtc_Word16 ACMCodecDB::_noOfCodecs = 0; -WebRtc_Word16 ACMCodecDB::_noNetEqDecoders = 0; -WebRtc_Word16 ACMCodecDB::_noPayloads = 0; - -WebRtc_Word16 ACMCodecDB::isac = -1; -WebRtc_Word16 ACMCodecDB::isacswb = -1; -WebRtc_Word16 ACMCodecDB::pcm16b = -1; -WebRtc_Word16 ACMCodecDB::pcm16bwb = -1; -WebRtc_Word16 ACMCodecDB::pcm16bswb32 = -1; -WebRtc_Word16 ACMCodecDB::pcm16bswb48 = -1; -WebRtc_Word16 ACMCodecDB::pcmu = -1; -WebRtc_Word16 ACMCodecDB::pcma = -1; -WebRtc_Word16 ACMCodecDB::ilbc = -1; -WebRtc_Word16 ACMCodecDB::gsmAMR = -1; -WebRtc_Word16 ACMCodecDB::gsmAMRWB = -1; -WebRtc_Word16 ACMCodecDB::g722 = -1; -WebRtc_Word16 ACMCodecDB::g722_1_32 = -1; -WebRtc_Word16 ACMCodecDB::g722_1_24 = -1; -WebRtc_Word16 ACMCodecDB::g722_1_16 = -1; -WebRtc_Word16 ACMCodecDB::g722_1C_48 = -1; -WebRtc_Word16 ACMCodecDB::g722_1C_32 = -1; -WebRtc_Word16 ACMCodecDB::g722_1C_24 = -1; -WebRtc_Word16 ACMCodecDB::g729 = -1; -WebRtc_Word16 ACMCodecDB::gsmfr = -1; -WebRtc_Word16 ACMCodecDB::speex8 = -1; -WebRtc_Word16 ACMCodecDB::speex16 = -1; -WebRtc_Word16 ACMCodecDB::cnNB = -1; -WebRtc_Word16 ACMCodecDB::cnWB = -1; -WebRtc_Word16 ACMCodecDB::cnSWB = -1; -WebRtc_Word16 ACMCodecDB::avt = -1; -WebRtc_Word16 ACMCodecDB::red = -1; - -WebRtc_UWord8 ACMCodecDB::_nrOfAllowedPacSizes[MAX_NR_OF_CODECS]; -WebRtc_UWord16 ACMCodecDB::_allowedPacSizesSmpl[MAX_NR_OF_CODECS][MAX_NR_OF_PACSIZES]; -CodecInst ACMCodecDB::_mycodecs[MAX_NR_OF_CODECS]; -enum WebRtcNetEQDecoder ACMCodecDB::_netEqDecoders[MAX_NR_OF_CODECS]; -WebRtc_Word8 ACMCodecDB::_versions[VERSION_SIZE]; -WebRtc_UWord16 ACMCodecDB::_basicCodingBlockSmpl[MAX_NR_OF_CODECS]; -WebRtc_UWord16 ACMCodecDB::_channelSupport[MAX_NR_OF_CODECS]; -WebRtc_UWord32 ACMCodecDB::_versionStringSize = 0; - -// We dynamically allocate some of the dynamic payload types to the defined codecs -// Note! There are a limited number of payload types. If more codecs are defined -// they will receive reserved fixed payload types (values 65-95). -static int kDynamicPayloadtypes[MAX_NR_OF_CODECS] = { - 105, 107, 108, 109, 110, 111, 112, 113, 114, 115, 116, 117, 118, 119, - 120, 121, 122, 123, 124, 125, 126, 95, 94, 93, 92, 91, 90, 89, - 88, 87, 86, 85, 84, 83, 82, 81, 80, 79, 78, 77, 76, 75, - 74, 73, 72, 71, 70, 69, 68, 67, 66, 65 +// We dynamically allocate some of the dynamic payload types to the defined +// codecs. Note! There are a limited number of payload types. If more codecs +// are defined they will receive reserved fixed payload types (values 67-95). +const int kDynamicPayloadtypes[ACMCodecDB::kMaxNumCodecs] = { + 105, 107, 108, 109, 110, 111, 112, 113, 114, 115, 116, 117, 118, 119, + 120, 121, 122, 123, 124, 125, 126, 95, 94, 93, 92, 91, 90, 89, + 88, 87, 86, 85, 84, 83, 82, 81, 80, 79, 78, 77, 76, 75, + 74, 73, 72, 71, 70, 69, 68, 67 }; -WebRtc_Word16 -ACMCodecDB::Codec( - WebRtc_Word16 listnr, - CodecInst* codec_inst) -{ - // Error check to se that listnr is between 0 and (_noOfCodecs - 1) - if ((listnr < 0) || (listnr >= _noOfCodecs)) - { - return -1; - } +// Creates database with all supported codec at compile time. +// Each entry needs the following parameters in the given order: +// payload type, name, sampling frequency, packet size in samples, +// default channel support, and default rate. +static int count_database = 0; +const CodecInst ACMCodecDB::database_[] = { +#if (defined(WEBRTC_CODEC_ISAC) || defined(WEBRTC_CODEC_ISACFX)) + {103, "ISAC", 16000, ISACWB_PAC_SIZE, 1, ISACWB_DEFAULT_RATE}, +# if (defined(WEBRTC_CODEC_ISAC)) + {104, "ISAC", 32000, ISACSWB_PAC_SIZE, 1, ISACSWB_DEFAULT_RATE}, +# endif +#endif +#ifdef WEBRTC_CODEC_PCM16 + {kDynamicPayloadtypes[count_database++], "L16", 8000, 80, 1, 128000}, + {kDynamicPayloadtypes[count_database++], "L16", 16000, 160, 1, 256000}, + {kDynamicPayloadtypes[count_database++], "L16", 32000, 320, 1, 512000}, +#endif + // G.711, PCM mu-law and A-law. + {0, "PCMU", 8000, 160, 1, 64000}, + {8, "PCMA", 8000, 160, 1, 64000}, +#ifdef WEBRTC_CODEC_ILBC + {102, "ILBC", 8000, 240, 1, 13300}, +#endif +#ifdef WEBRTC_CODEC_G722 + {9, "G722", 16000, 320, 1, 64000}, +#endif + // Comfort noise for three different sampling frequencies. + {13, "CN", 8000, 240, 1, 0}, + {98, "CN", 16000, 480, 1, 0}, + {99, "CN", 32000, 960, 1, 0}, +#ifdef WEBRTC_CODEC_AVT + {106, "telephone-event", 8000, 240, 1, 0}, +#endif +#ifdef WEBRTC_CODEC_RED + {127, "red", 8000, 0, 1, 0}, +#endif + // To prevent compile errors due to trailing commas. + {-1, "Null", -1, -1, -1, -1} +}; - memcpy(codec_inst,&_mycodecs[listnr],sizeof(CodecInst)); - return 0; +// Create database with all codec settings at compile time. +// Each entry needs the following parameters in the given order: +// Number of allowed packet sizes, a vector with the allowed packet sizes, +// Basic block samples, max number of channels that are supported. +const ACMCodecDB::CodecSettings ACMCodecDB::codec_settings_[] = { +#if (defined(WEBRTC_CODEC_ISAC) || defined(WEBRTC_CODEC_ISACFX)) + {2, {ISACWB_PAC_SIZE, ISACWB_PAC_SIZE*2}, 0, 1}, +# if (defined(WEBRTC_CODEC_ISAC)) + {1, {ISACSWB_PAC_SIZE}, 0, 1}, +# endif +#endif +#ifdef WEBRTC_CODEC_PCM16 + {4, {80, 160, 240, 320}, 0, 2}, + {4, {160, 320, 480, 640}, 0, 2}, + {2, {320, 640}, 0, 2}, +#endif + // G.711, PCM mu-law and A-law. + {6, {80, 160, 240, 320, 400, 480}, 0, 2}, + {6, {80, 160, 240, 320, 400, 480}, 0, 2}, +#ifdef WEBRTC_CODEC_ILBC + {4, {160, 240, 320, 480}, 0, 1}, +#endif +#ifdef WEBRTC_CODEC_G722 + {6, {160, 320, 480, 640, 800, 960}, 0, 2}, +#endif + // Comfort noise for three different sampling frequencies. + {1, {240}, 240, 1}, + {1, {480}, 480, 1}, + {1, {960}, 960, 1}, +#ifdef WEBRTC_CODEC_AVT + {1, {240}, 240, 1}, +#endif +#ifdef WEBRTC_CODEC_RED + {1, {0}, 0, 1}, +#endif + // To prevent compile errors due to trailing commas. + {-1, {-1}, -1, -1} +}; + +// Create a database of all NetEQ decoders at compile time. +WebRtcNetEQDecoder ACMCodecDB::neteq_decoders_[] = { +#if (defined(WEBRTC_CODEC_ISAC) || defined(WEBRTC_CODEC_ISACFX)) + kDecoderISAC, +# if (defined(WEBRTC_CODEC_ISAC)) + kDecoderISACswb, +# endif +#endif +#ifdef WEBRTC_CODEC_PCM16 + kDecoderPCM16B, + kDecoderPCM16Bwb, + kDecoderPCM16Bswb32kHz, +#endif + kDecoderPCMu, + kDecoderPCMa, +#ifdef WEBRTC_CODEC_ILBC + kDecoderILBC, +#endif +#ifdef WEBRTC_CODEC_AMR + kDecoderAMR, +#endif +#ifdef WEBRTC_CODEC_AMRWB + kDecoderAMRWB, +#endif +#ifdef WEBRTC_CODEC_G722 + kDecoderG722, +#endif +#ifdef WEBRTC_CODEC_G722_1 + kDecoderG722_1_32, + kDecoderG722_1_24, + kDecoderG722_1_16, +#endif +#ifdef WEBRTC_CODEC_G722_1C + kDecoderG722_1C_48, + kDecoderG722_1C_32, + kDecoderG722_1C_24, +#endif +#ifdef WEBRTC_CODEC_G729 + kDecoderG729, +#endif +#ifdef WEBRTC_CODEC_GSMFR + kDecoderGSMFR, +#endif +#ifdef WEBRTC_CODEC_SPEEX + kDecoderSPEEX_8, + kDecoderSPEEX_16, +#endif + kDecoderCNG, + kDecoderCNG, + kDecoderCNG, +#ifdef WEBRTC_CODEC_AVT + kDecoderAVT, +#endif +#ifdef WEBRTC_CODEC_RED + kDecoderRED, +#endif + kDecoderReservedEnd +}; + +// Get codec information from database. +// TODO(tlegrand): replace memcpy with a pointer to the data base memory. +int ACMCodecDB::Codec(int codec_id, CodecInst* codec_inst) { + // Error check to see that codec_id is not out of bounds. + if ((codec_id < 0) || (codec_id >= kNumCodecs)) { + return -1; + } + + // Copy database information for the codec to the output. + memcpy(codec_inst, &database_[codec_id], sizeof(CodecInst)); + + return 0; } +// Enumerator for error codes when asking for codec database id. +enum { + kInvalidCodec = -10, + kInvalidFrequency = -20, + kInvalidPayloadtype = -30, + kInvalidPacketSize = -40, + kInvalidRate = -50 +}; -WebRtc_Word16 -ACMCodecDB::CodecNumber( - const CodecInst* codecInst, - WebRtc_Word16& mirrorID, - WebRtc_Word8* errMessage, - WebRtc_Word16 maxErrMsgLenByte) -{ - WebRtc_Word16 codecID = ACMCodecDB::CodecNumber(codecInst, mirrorID); - if((codecID < 0) && (errMessage != NULL)) - { - WebRtc_Word8 myErrMsg[1000]; - if (codecID == -10) - { - // Codec not supported - sprintf(myErrMsg, - "Call to ACMCodecDB::CodecNumber failed, plname=%s is \ -not a valid codec", codecInst->plname); - } - else if (codecID == -20) - { - // Sampling frequency doesn't match codec - sprintf(myErrMsg, - "Call to ACMCodecDB::CodecNumber failed, plfreq=%d is \ -not a valid frequency for the codec %s", codecInst->plfreq, codecInst->plname); - } - else if (codecID == -30) - { - // Wrong payload type for Comfort Noise - sprintf(myErrMsg, - "Call to ACMCodecDB::CodecNumber failed, payload \ -number %d is out of range for %s", codecInst->pltype, codecInst->plname); - } - else if (codecID == -40) - { - // Wrong payload type for RED - sprintf(myErrMsg, - "Call to ACMCodecDB::CodecNumber failed, payload \ -number %d is out of range for %s", codecInst->pltype, codecInst->plname); - } - else if (codecID == -50) - { - // Packet size is out of range for the codec - sprintf(myErrMsg, - "Call to ACMCodecDB::CodecNumber failed, Packet \ -size is out of range for %s", codecInst->plname); - } - else if (codecID == -60) - { - // Not a valid rate for the codec - sprintf(myErrMsg, - "Call to ACMCodecDB::CodecNumber failed, rate=%d \ -is not a valid rate for %s", codecInst->rate, codecInst->plname); - } - else - { - // Other error - sprintf(myErrMsg, - "invalid codec parameters to be registered, \ -ACMCodecDB::CodecNumber failed"); - } - strncpy(errMessage, myErrMsg, maxErrMsgLenByte - 1); - // make sure that the massage is null-terminated. - errMessage[maxErrMsgLenByte - 1] = '\0'; +// Gets the codec id number from the database. If there is some mismatch in +// the codec settings, an error message will be recorded in the error string. +// NOTE! Only the first mismatch found will be recorded in the error string. +int ACMCodecDB::CodecNumber(const CodecInst* codec_inst, int* mirror_id, + char* err_message, int max_message_len_byte) { + int codec_id = ACMCodecDB::CodecNumber(codec_inst, mirror_id); + + // Write error message if ACMCodecDB::CodecNumber() returned error. + if ((codec_id < 0) && (err_message != NULL)) { + char my_err_msg[1000]; + + if (codec_id == kInvalidCodec) { + sprintf(my_err_msg, "Call to ACMCodecDB::CodecNumber failed, plname=%s " + "is not a valid codec", codec_inst->plname); + } else if (codec_id == kInvalidFrequency) { + sprintf(my_err_msg, "Call to ACMCodecDB::CodecNumber failed, plfreq=%d " + "is not a valid frequency for the codec %s", codec_inst->plfreq, + codec_inst->plname); + } else if (codec_id == kInvalidPayloadtype) { + sprintf(my_err_msg, "Call to ACMCodecDB::CodecNumber failed, payload " + "number %d is out of range for %s", codec_inst->pltype, + codec_inst->plname); + } else if (codec_id == kInvalidPacketSize) { + sprintf(my_err_msg, "Call to ACMCodecDB::CodecNumber failed, Packet " + "size is out of range for %s", codec_inst->plname); + } else if (codec_id == kInvalidRate) { + sprintf(my_err_msg, "Call to ACMCodecDB::CodecNumber failed, rate=%d " + "is not a valid rate for %s", codec_inst->rate, + codec_inst->plname); + } else { + // Other error + sprintf(my_err_msg, "invalid codec parameters to be registered, " + "ACMCodecDB::CodecNumber failed"); } - return codecID; + + strncpy(err_message, my_err_msg, max_message_len_byte - 1); + // make sure that the message is null-terminated. + err_message[max_message_len_byte - 1] = '\0'; + } + + return codec_id; } +// Gets the codec id number from the database. If there is some mismatch in +// the codec settings, the function will return an error code. +// NOTE! The first mismatch found will generate the return value. +int ACMCodecDB::CodecNumber(const CodecInst* codec_inst, int* mirror_id) { + int codec_number = -1; + bool name_match = false; -WebRtc_Word16 -ACMCodecDB::CodecNumber( - const CodecInst* codec_inst, - WebRtc_Word16& mirrorID) -{ - WebRtc_Word16 codecNumber = -1; - WebRtc_Word16 nameMatch = 0; + // Looks for a matching payload name and frequency in the codec list. + // Need to check both since some codecs have several codec entries with + // different frequencies (like iSAC). + for (int i = 0; i < kNumCodecs; i++) { + if (STR_CASE_CMP(database_[i].plname, codec_inst->plname) == 0) { + // We have found a matching codec name in the list. + name_match = true; - // Find a matching payload name and frequency in the codec list - // Need to check both since some codecs have several codec entries with - // Different frequencies (like iSAC) - for(WebRtc_Word16 i = 0; i < _noOfCodecs; i++) - { - if(STR_CASE_CMP(_mycodecs[i].plname, codec_inst->plname) == 0) - { - //We have found a matching codec name in the list - nameMatch = 1; + // Checks if frequency match. + if (codec_inst->plfreq == database_[i].plfreq) { + codec_number = i; + break; + } + } + } - // Check if frequncy match - if (codec_inst->plfreq == _mycodecs[i].plfreq) - { - codecNumber = i; - break; - } + // Checks if the error is in the name or in the frequency. + if (codec_number == -1) { + if (!name_match) { + return kInvalidCodec; + } else { + return kInvalidFrequency; + } + } + + // Checks the validity of payload type + if (!ValidPayloadType(codec_inst->pltype)) { + return kInvalidPayloadtype; + } + + // Comfort Noise is special case, packet-size & rate is not checked. + if (STR_CASE_CMP(database_[codec_number].plname, "CN") == 0) { + *mirror_id = codec_number; + return codec_number; + } + + // RED is special case, packet-size & rate is not checked. + if (STR_CASE_CMP(database_[codec_number].plname, "red") == 0) { + *mirror_id = codec_number; + return codec_number; + } + + // Checks the validity of packet size. + if (codec_settings_[codec_number].num_packet_sizes > 0) { + bool packet_size_ok = false; + int i; + int packet_size_samples; + for (i = 0; i < codec_settings_[codec_number].num_packet_sizes; i++) { + packet_size_samples = + codec_settings_[codec_number].packet_sizes_samples[i]; + if (codec_inst->pacsize == packet_size_samples) { + packet_size_ok = true; + break; + } + } + + if (!packet_size_ok) { + return kInvalidPacketSize; + } + } + + if (codec_inst->pacsize < 1) { + return kInvalidPacketSize; + } + + + // Check the validity of rate. Codecs with multiple rates have their own + // function for this. + *mirror_id = codec_number; + if (STR_CASE_CMP("isac", codec_inst->plname) == 0) { + if (IsISACRateValid(codec_inst->rate)) { + // Set mirrorID to iSAC WB which is only created once to be used both for + // iSAC WB and SWB, because they need to share struct. + *mirror_id = kISAC; + return codec_number; + } else { + return kInvalidRate; + } + } else if (STR_CASE_CMP("ilbc", codec_inst->plname) == 0) { + return IsILBCRateValid(codec_inst->rate, codec_inst->pacsize) + ? codec_number : kInvalidRate; + } + + return IsRateValid(codec_number, codec_inst->rate) ? + codec_number : kInvalidRate; +} + +// Gets codec id number, and mirror id, from database for the receiver. +int ACMCodecDB::ReceiverCodecNumber(const CodecInst* codec_inst, + int* mirror_id) { + int codec_number = -1; + + // Looks for a matching payload name and frequency in the codec list. + // Need to check both since some codecs have several codec entries with + // different frequencies (like iSAC). + for (int i = 0; i < kNumCodecs; i++) { + if (STR_CASE_CMP(database_[i].plname, codec_inst->plname) == 0) { + // We have found a matching codec name in the list. + + // Check if frequency match. + if (codec_inst->plfreq == database_[i].plfreq) { + codec_number = i; + *mirror_id = codec_number; + + // Check if codec is iSAC, set mirrorID to iSAC WB which is only + // created once to be used both for iSAC WB and SWB, because they need + // to share struct. + if (STR_CASE_CMP(codec_inst->plname, "ISAC") == 0) { + *mirror_id = kISAC; } - } - if(codecNumber == -1) - { - if (!nameMatch) { - // Codec name doesn't match any codec in the list - return -10; - } else { - // Error in payload frequency, doesn't match codec - return -20; - } + break; + } } + } - // Check the validity of payload type - if(ValidPayloadType(codec_inst->pltype) < 0) - { - // Payload type out of range - return -40; - } - - // Comfort Noise is special case, packet-size & rate is not checked - if(STR_CASE_CMP(_mycodecs[codecNumber].plname, "CN") == 0) - { - mirrorID = codecNumber; - return codecNumber; - } - - // RED is special case, packet-size & rate is not checked - if(STR_CASE_CMP(_mycodecs[codecNumber].plname, "red") == 0) - { - mirrorID = codecNumber; - return codecNumber; - } - - // Check the validity of packet size - if(_nrOfAllowedPacSizes[codecNumber] > 0) - { - // Check that the new packet size is in the valid range. - bool pacSizeOK = false; - for(WebRtc_Word32 i=0;i< _nrOfAllowedPacSizes[codecNumber];i++) - { - if(codec_inst->pacsize == _allowedPacSizesSmpl[codecNumber][i]) - { - pacSizeOK = true; - break; - } - } - if(!pacSizeOK) - { - // Packet size is out of range - return -50; - } - } - if( codec_inst->pacsize < 1) - { - // Packet size is out of range - return -50; - } - - mirrorID = codecNumber; - - // Check the validity of rate - if(STR_CASE_CMP("isac", codec_inst->plname) == 0) - { - if(IsISACRateValid(codec_inst->rate)) - { - // Set mirrorID to iSAC WB which is only created - // once to be used both for iSAC WB and SWB, because - // they need to share struct - mirrorID = ACMCodecDB::isac; - return codecNumber; - } - else - { - // Not a valid rate - return -60; - } - } - else if(STR_CASE_CMP("ilbc", codec_inst->plname) == 0) - { - return IsILBCRateValid(codec_inst->rate, codec_inst->pacsize) ? codecNumber : -60; - } - - return IsRateValid(codecNumber, codec_inst->rate) ? codecNumber : -60; + return codec_number; } +// Returns the codec sampling frequency for codec with id = "codec_id" in +// database. +int ACMCodecDB::CodecFreq(int codec_id) { + // Error check to see that codec_id is not out of bounds. + if (codec_id < 0 || codec_id >= kNumCodecs) { + return -1; + } -WebRtc_Word16 -ACMCodecDB::ReceiverCodecNumber( - const CodecInst& codecInst, - WebRtc_Word16& mirrorID) -{ - WebRtc_Word16 codecNumber = -1; - WebRtc_Word16 nameMatch = 0; - - // Find a matching payload name and frequency in the codec list - // Need to check both since some codecs have several codec entries with - // Different frequencies (like iSAC) - for(WebRtc_Word16 i = 0; i < _noOfCodecs; i++) - { - if(STR_CASE_CMP(_mycodecs[i].plname, codecInst.plname) == 0) - { - //We have found a matching codec name in the list - nameMatch = 1; - - // Check if frequency match - if (codecInst.plfreq == _mycodecs[i].plfreq) - { - codecNumber = i; - mirrorID = codecNumber; - - // Check if codec is iSAC, set mirrorID to iSAC WB - // which is only created once to be used both for - // iSAC WB and SWB, because they need to share struct - if(STR_CASE_CMP(codecInst.plname, "ISAC") == 0) - { - mirrorID = ACMCodecDB::isac; - } - break; - } - } - } - - if(codecNumber == -1) - { - return codecNumber; - } - - return codecNumber; + return database_[codec_id].plfreq; } +// Returns the codec's basic coding block size in samples. +int ACMCodecDB::BasicCodingBlock(int codec_id) { + // Error check to see that codec_id is not out of bounds. + if (codec_id < 0 || codec_id >= kNumCodecs) { + return -1; + } -// Return number of codecs in the database -WebRtc_Word16 -ACMCodecDB::NoOfCodecs() -{ - return _noOfCodecs; + return codec_settings_[codec_id].basic_block_samples; } - -// Return number of NetEQ decoders in the database. -// Note that the number is huigher than _moOfCodecs because some payload names -// are treated as different decoders in NetEQ, like iSAC wb and swb. -WebRtc_Word16 -ACMCodecDB::NoNetEqDecoders() -{ - return _noNetEqDecoders; +// Returns the NetEQ decoder database. +WebRtcNetEQDecoder* ACMCodecDB::NetEQDecoders() { + return neteq_decoders_; } +// All version numbers for the codecs in the database are listed in text. +// TODO(tlegrand): change to use std::string. +int ACMCodecDB::CodecsVersion(char* version, size_t* remaining_buffer_bytes, + size_t* position) { + const size_t kTemporaryBufferSize = 500; + const size_t kVersionBufferSize = 1000; + char versions_buffer[kVersionBufferSize]; + char version_num_buf[kTemporaryBufferSize]; + size_t len = *position; + size_t remaining_size = kVersionBufferSize; -// Return the codec sampling frequency for code number "listnr" in database -WebRtc_Word32 -ACMCodecDB::CodecFreq(WebRtc_Word16 listnr) -{ - // Error check to se that listnr is between 0 and (_noOfCodecs - 1) - if ( listnr < 0 || listnr >= _noOfCodecs) - return -1; + versions_buffer[0] = '\0'; - return _mycodecs[listnr].plfreq; +#if (defined(WEBRTC_CODEC_ISAC) || defined(WEBRTC_CODEC_ISACFX)) + remaining_size = kVersionBufferSize - strlen(versions_buffer); + ACM_ISAC_VERSION(version_num_buf); + strncat(versions_buffer, "ISAC\t\t", remaining_size); + remaining_size = kVersionBufferSize - strlen(versions_buffer); + strncat(versions_buffer, version_num_buf, remaining_size); + remaining_size = kVersionBufferSize - strlen(versions_buffer); + strncat(versions_buffer, "\n", remaining_size); +#endif +#ifdef WEBRTC_CODEC_PCM16 + remaining_size = kVersionBufferSize - strlen(versions_buffer); + strncat(versions_buffer, "L16\t\t1.0.0\n", remaining_size); +#endif + remaining_size = kVersionBufferSize - strlen(versions_buffer); + WebRtcG711_Version(version_num_buf, kTemporaryBufferSize); + strncat(versions_buffer, "G.711\t\t", remaining_size); + remaining_size = kVersionBufferSize - strlen(versions_buffer); + strncat(versions_buffer, version_num_buf, remaining_size); + remaining_size = kVersionBufferSize - strlen(versions_buffer); + strncat(versions_buffer, "\n", remaining_size); +#ifdef WEBRTC_CODEC_ILBC + remaining_size = kVersionBufferSize - strlen(versions_buffer); + WebRtcIlbcfix_version(version_num_buf); + strncat(versions_buffer, "ILBC\t\t", remaining_size); + remaining_size = kVersionBufferSize - strlen(versions_buffer); + strncat(versions_buffer, version_num_buf, remaining_size); + remaining_size = kVersionBufferSize - strlen(versions_buffer); + strncat(versions_buffer, "\n", remaining_size); +#endif +#ifdef WEBRTC_CODEC_G722 + remaining_size = kVersionBufferSize - strlen(versions_buffer); + WebRtcG722_Version(version_num_buf, kTemporaryBufferSize); + strncat(versions_buffer, "G.722\t\t", remaining_size); + remaining_size = kVersionBufferSize - strlen(versions_buffer); + strncat(versions_buffer, version_num_buf, remaining_size); +#endif + remaining_size = kVersionBufferSize - strlen(versions_buffer); + WebRtcCng_Version(version_num_buf); + strncat(versions_buffer, "CNG\t\t", remaining_size); + remaining_size = kVersionBufferSize - strlen(versions_buffer); + strncat(versions_buffer, version_num_buf, remaining_size); +#ifdef WEBRTC_CODEC_AVT + remaining_size = kVersionBufferSize - strlen(versions_buffer); + strncat(versions_buffer, "Tone Generation\t1.0.0\n", remaining_size); +#endif + strncpy(&version[len], versions_buffer, *remaining_buffer_bytes); + *position = strlen(version); + *remaining_buffer_bytes -= (*position - len); + if (*remaining_buffer_bytes < strlen(versions_buffer)) { + return -1; + } + + return 0; } -// Return the codecs basic coding block size in samples -WebRtc_Word16 -ACMCodecDB::BasicCodingBlock( - WebRtc_Word16 listNr) -{ - // Error check to se that listnr is between 0 and (_noOfCodecs - 1) - if ( listNr < 0 || listNr >= _noOfCodecs) - return -1; - - return _basicCodingBlockSmpl[listNr]; -} - -// Return the NetEQ decoder database -enum WebRtcNetEQDecoder* -ACMCodecDB::NetEqDecoders() -{ - return _netEqDecoders; -} - -// All version numbers for the codecs in the data base are listed in text. -WebRtc_Word16 -ACMCodecDB::CodecsVersion( - WebRtc_Word8* version, - WebRtc_UWord32& remainingBufferInBytes, - WebRtc_UWord32& position) -{ - WebRtc_UWord32 len = position; - strncpy(&version[len], _versions, remainingBufferInBytes); - position = (WebRtc_UWord32)strlen(version); - remainingBufferInBytes -= (position - len); - if(remainingBufferInBytes < _versionStringSize) - { - return -1; - } - return 0; -} - -// Get mirror id. The Id is used for codecs sharing struct for settings that +// Gets mirror id. The Id is used for codecs sharing struct for settings that // need different payload types. -WebRtc_Word16 -ACMCodecDB::MirrorID( - const WebRtc_Word16 codecID) -{ - if(STR_CASE_CMP(_mycodecs[codecID].plname, "isac") == 0) - { - return ACMCodecDB::isac; - } - else - { - return codecID; - } +int ACMCodecDB::MirrorID(int codec_id) { + if (STR_CASE_CMP(database_[codec_id].plname, "isac") == 0) { + return kISAC; + } else { + return codec_id; + } } - - -ACMGenericCodec* -ACMCodecDB::CreateCodecInstance( - const CodecInst* codecInst) -{ - // All we have support for right now - if(!STR_CASE_CMP(codecInst->plname, "ISAC")) - { +// Creates memory/instance for storing codec state. +ACMGenericCodec* ACMCodecDB::CreateCodecInstance(const CodecInst* codec_inst) { + // All we have support for right now. + if (!STR_CASE_CMP(codec_inst->plname, "ISAC")) { #if (defined(WEBRTC_CODEC_ISAC) || defined(WEBRTC_CODEC_ISACFX)) - return new ACMISAC(isac); + return new ACMISAC(kISAC); #endif - } - else if(!STR_CASE_CMP(codecInst->plname, "PCMU")) - { - return new ACMPCMU(pcmu); - } - else if(!STR_CASE_CMP(codecInst->plname, "PCMA")) - { - return new ACMPCMA(pcma); - } - else if(!STR_CASE_CMP(codecInst->plname, "ILBC")) - { + } else if (!STR_CASE_CMP(codec_inst->plname, "PCMU")) { + return new ACMPCMU(kPCMU); + } else if (!STR_CASE_CMP(codec_inst->plname, "PCMA")) { + return new ACMPCMA(kPCMA); + } else if (!STR_CASE_CMP(codec_inst->plname, "ILBC")) { #ifdef WEBRTC_CODEC_ILBC - return new ACMILBC(ilbc); + return new ACMILBC(kILBC); #endif - } - else if(!STR_CASE_CMP(codecInst->plname, "G722")) - { + } else if (!STR_CASE_CMP(codec_inst->plname, "G722")) { #ifdef WEBRTC_CODEC_G722 - return new ACMG722(g722); + return new ACMG722(kG722); #endif + } else if (!STR_CASE_CMP(codec_inst->plname, "CN")) { + // For CN we need to check sampling frequency to know what codec to create. + int codec_id; + switch (codec_inst->plfreq) { + case 8000: { + codec_id = kCNNB; + break; + } + case 16000: { + codec_id = kCNWB; + break; + } + case 32000: { + codec_id = kCNSWB; + break; + } + default: { + return NULL; + } } - else if(!STR_CASE_CMP(codecInst->plname, "CN")) - { - // We need to check sampling frequency - // know what codec to create. - WebRtc_Word16 codecID; - switch(codecInst->plfreq) - { - case 8000: - { - codecID = ACMCodecDB::cnNB; - break; - } - case 16000: - { - codecID = ACMCodecDB::cnWB; - break; - } - case 32000: - { - codecID = ACMCodecDB::cnSWB; - break; - } - default: - return NULL; - } - return new ACMCNG(codecID); - } - else if(!STR_CASE_CMP(codecInst->plname, "L16")) - { + return new ACMCNG(codec_id); + } else if (!STR_CASE_CMP(codec_inst->plname, "L16")) { #ifdef WEBRTC_CODEC_PCM16 - // For this codec we need to check sampling frequency - // to know what codec to create. - WebRtc_Word16 codecID; - switch(codecInst->plfreq) - { - case 8000: - { - codecID = ACMCodecDB::pcm16b; - break; - } - case 16000: - { - codecID = ACMCodecDB::pcm16bwb; - break; - } - case 32000: - { - codecID = ACMCodecDB::pcm16bswb32; - break; - } - default: - return NULL; - } - return new ACMPCM16B(codecID); -#endif + // For L16 we need to check sampling frequency to know what codec to create. + int codec_id; + switch (codec_inst->plfreq) { + case 8000: { + codec_id = kPCM16B; + break; + } + case 16000: { + codec_id =kPCM16Bwb; + break; + } + case 32000: { + codec_id = kPCM16Bswb32kHz; + break; + } + default: { + return NULL; + } } - else if(!STR_CASE_CMP(codecInst->plname, "telephone-event")) - { + return new ACMPCM16B(codec_id); +#endif + } else if (!STR_CASE_CMP(codec_inst->plname, "telephone-event")) { #ifdef WEBRTC_CODEC_AVT - return new ACMDTMFPlayout(avt); + return new ACMDTMFPlayout(kAVT); #endif - } - else if(!STR_CASE_CMP(codecInst->plname, "red")) - { + } else if (!STR_CASE_CMP(codec_inst->plname, "red")) { #ifdef WEBRTC_CODEC_RED - return new ACMRED(red); + return new ACMRED(kRED); #endif - } - return NULL; + } + return NULL; } - -//Here we build the complete database "_mycodecs" of our codecs -void -ACMCodecDB::initACMCodecDB() -{ - if(_isInitiated) - { - return; - } - else - { - _isInitiated = true; - } - WebRtc_Word8 versionNrBuff[TEMPORARY_BUFFER_SIZE]; - WebRtc_Word32 remainingSize = VERSION_SIZE; - - _versions[0] = '\0'; - - // Init the stereo settings vector - for (int i=0; i= 10000))) - { - return true; - } - else - { - return false; - } -#endif + } } -// Check if the bitrate is valid for iLBC -bool -ACMCodecDB::IsILBCRateValid( -#ifndef WEBRTC_CODEC_ILBC - const WebRtc_Word32 /* rate */, - const WebRtc_Word16 /* frameSizeSamples */) -{ +// Checks if the bitrate is valid for iSAC. +bool ACMCodecDB::IsISACRateValid(int rate) { + if ((rate == -1) || ((rate <= 56000) && (rate >= 10000))) { + return true; + } else { return false; -#else - const WebRtc_Word32 rate, - const WebRtc_Word16 frameSizeSamples) -{ - if(((frameSizeSamples == 240) || (frameSizeSamples == 480)) && - (rate == 13300)) - { - return true; - } - else if(((frameSizeSamples == 160) || (frameSizeSamples == 320)) && - (rate == 15200)) - { - return true; - } - else - { - return false; - } -#endif + } } -// Check if the payload type is valid -WebRtc_Word16 -ACMCodecDB::ValidPayloadType( - const int payloadType) -{ - if((payloadType < 0) || (payloadType > 127)) - { - return -1; - } - return 0; +// Checks if the bitrate is valid for iLBC. +bool ACMCodecDB::IsILBCRateValid(int rate, int frame_size_samples) { + if (((frame_size_samples == 240) || (frame_size_samples == 480)) && + (rate == 13300)) { + return true; + } else if (((frame_size_samples == 160) || (frame_size_samples == 320)) && + (rate == 15200)) { + return true; + } else { + return false; + } } -} // namespace webrtc +// Checks if the payload type is in the valid range. +bool ACMCodecDB::ValidPayloadType(int payload_type) { + if ((payload_type < 0) || (payload_type > 127)) { + return false; + } + return true; +} + +} // namespace webrtc diff --git a/src/modules/audio_coding/main/source/acm_codec_database.h b/src/modules/audio_coding/main/source/acm_codec_database.h index c83e84b162..d5716a12aa 100644 --- a/src/modules/audio_coding/main/source/acm_codec_database.h +++ b/src/modules/audio_coding/main/source/acm_codec_database.h @@ -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_ diff --git a/src/modules/audio_coding/main/source/acm_generic_codec.cc b/src/modules/audio_coding/main/source/acm_generic_codec.cc index 68d9885a5d..7920421b09 100644 --- a/src/modules/audio_coding/main/source/acm_generic_codec.cc +++ b/src/modules/audio_coding/main/source/acm_generic_codec.cc @@ -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; diff --git a/src/modules/audio_coding/main/source/acm_isac.cc b/src/modules/audio_coding/main/source/acm_isac.cc index d5ec8914c3..37ebe0915c 100644 --- a/src/modules/audio_coding/main/source/acm_isac.cc +++ b/src/modules/audio_coding/main/source/acm_isac.cc @@ -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); } diff --git a/src/modules/audio_coding/main/source/audio_coding_module.cc b/src/modules/audio_coding/main/source/audio_coding_module.cc index 97c5af9a9a..45e7761e97 100644 --- a/src/modules/audio_coding/main/source/audio_coding_module.cc +++ b/src/modules/audio_coding/main/source/audio_coding_module.cc @@ -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(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) + ¤t_remaining_bytes, ¤t_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(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) { diff --git a/src/modules/audio_coding/main/source/audio_coding_module_impl.cc b/src/modules/audio_coding/main/source/audio_coding_module_impl.cc index 79fff303ed..b861e92b12 100644 --- a/src/modules/audio_coding/main/source/audio_coding_module_impl.cc +++ b/src/modules/audio_coding/main/source/audio_coding_module_impl.cc @@ -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]) diff --git a/src/modules/audio_coding/main/source/audio_coding_module_impl.h b/src/modules/audio_coding/main/source/audio_coding_module_impl.h index e39c1157ac..c3f2c39283 100644 --- a/src/modules/audio_coding/main/source/audio_coding_module_impl.h +++ b/src/modules/audio_coding/main/source/audio_coding_module_impl.h @@ -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