LCOV - code coverage report
Current view: top level - media/webrtc/trunk/webrtc/modules/audio_coding/acm2 - acm_codec_database.cc (source / functions) Hit Total Coverage
Test: output.info Lines: 0 58 0.0 %
Date: 2017-07-14 16:53:18 Functions: 0 7 0.0 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : /*
       2             :  *  Copyright (c) 2012 The WebRTC project authors. All Rights Reserved.
       3             :  *
       4             :  *  Use of this source code is governed by a BSD-style license
       5             :  *  that can be found in the LICENSE file in the root of the source
       6             :  *  tree. An additional intellectual property rights grant can be found
       7             :  *  in the file PATENTS.  All contributing project authors may
       8             :  *  be found in the AUTHORS file in the root of the source tree.
       9             :  */
      10             : 
      11             : /*
      12             :  * This file generates databases with information about all supported audio
      13             :  * codecs.
      14             :  */
      15             : 
      16             : // TODO(tlegrand): Change constant input pointers in all functions to constant
      17             : // references, where appropriate.
      18             : #include "webrtc/modules/audio_coding/acm2/acm_codec_database.h"
      19             : 
      20             : #include <assert.h>
      21             : 
      22             : #include "webrtc/base/checks.h"
      23             : #include "webrtc/modules/audio_coding/acm2/acm_common_defs.h"
      24             : #include "webrtc/system_wrappers/include/trace.h"
      25             : 
      26             : namespace webrtc {
      27             : 
      28             : namespace acm2 {
      29             : 
      30             : namespace {
      31             : 
      32             : // Checks if the bitrate is valid for iSAC.
      33           0 : bool IsISACRateValid(int rate) {
      34           0 :   return (rate == -1) || ((rate <= 56000) && (rate >= 10000));
      35             : }
      36             : 
      37             : // Checks if the bitrate is valid for iLBC.
      38           0 : bool IsILBCRateValid(int rate, int frame_size_samples) {
      39           0 :   if (((frame_size_samples == 240) || (frame_size_samples == 480)) &&
      40             :       (rate == 13300)) {
      41           0 :     return true;
      42           0 :   } else if (((frame_size_samples == 160) || (frame_size_samples == 320)) &&
      43             :       (rate == 15200)) {
      44           0 :     return true;
      45             :   } else {
      46           0 :     return false;
      47             :   }
      48             : }
      49             : 
      50             : // Checks if the bitrate is valid for Opus.
      51           0 : bool IsOpusRateValid(int rate) {
      52           0 :   return (rate >= 6000) && (rate <= 510000);
      53             : }
      54             : 
      55             : }  // namespace
      56             : 
      57             : // Not yet used payload-types.
      58             : // 83,  82,  81, 80, 79,  78,  77,  76,  75,  74,  73,  72,  71,  70,  69, 68,
      59             : // 67, 66, 65
      60             : 
      61             : const CodecInst ACMCodecDB::database_[] = {
      62             : #if (defined(WEBRTC_CODEC_ISAC) || defined(WEBRTC_CODEC_ISACFX))
      63             :   {103, "ISAC", 16000, kIsacPacSize480, 1, kIsacWbDefaultRate},
      64             : # if (defined(WEBRTC_CODEC_ISAC))
      65             :   {104, "ISAC", 32000, kIsacPacSize960, 1, kIsacSwbDefaultRate},
      66             : # endif
      67             : #endif
      68             :   // Mono
      69             :   {107, "L16", 8000, 80, 1, 128000},
      70             :   {108, "L16", 16000, 160, 1, 256000},
      71             :   {109, "L16", 32000, 320, 1, 512000},
      72             :   // Stereo
      73             :   {111, "L16", 8000, 80, 2, 128000},
      74             :   {112, "L16", 16000, 160, 2, 256000},
      75             :   {113, "L16", 32000, 320, 2, 512000},
      76             :   // G.711, PCM mu-law and A-law.
      77             :   // Mono
      78             :   {0, "PCMU", 8000, 160, 1, 64000},
      79             :   {8, "PCMA", 8000, 160, 1, 64000},
      80             :   // Stereo
      81             :   {110, "PCMU", 8000, 160, 2, 64000},
      82             :   {118, "PCMA", 8000, 160, 2, 64000},
      83             : #ifdef WEBRTC_CODEC_ILBC
      84             :   {102, "ILBC", 8000, 240, 1, 13300},
      85             : #endif
      86             : #ifdef WEBRTC_CODEC_G722
      87             :   // Mono
      88             :   {9, "G722", 16000, 320, 1, 64000},
      89             :   // Stereo
      90             :   {119, "G722", 16000, 320, 2, 64000},
      91             : #endif
      92             : #ifdef WEBRTC_CODEC_OPUS
      93             :   // Opus internally supports 48, 24, 16, 12, 8 kHz.
      94             :   // Mono and stereo.
      95             :   {120, "opus", 48000, 960, 2, 64000},
      96             : #endif
      97             :   // Comfort noise for four different sampling frequencies.
      98             :   {13, "CN", 8000, 240, 1, 0},
      99             :   {98, "CN", 16000, 480, 1, 0},
     100             :   {99, "CN", 32000, 960, 1, 0},
     101             : #ifdef ENABLE_48000_HZ
     102             :   {100, "CN", 48000, 1440, 1, 0},
     103             : #endif
     104             :   {106, "telephone-event", 8000, 240, 1, 0},
     105             :   {114, "telephone-event", 16000, 240, 1, 0},
     106             :   {115, "telephone-event", 32000, 240, 1, 0},
     107             :   {116, "telephone-event", 48000, 240, 1, 0},
     108             : #ifdef WEBRTC_CODEC_RED
     109             :   {127, "red", 8000, 0, 1, 0},
     110             : #endif
     111             :   // To prevent compile errors due to trailing commas.
     112             :   {-1, "Null", -1, -1, 0, -1}
     113             : };
     114             : 
     115             : // Create database with all codec settings at compile time.
     116             : // Each entry needs the following parameters in the given order:
     117             : // Number of allowed packet sizes, a vector with the allowed packet sizes,
     118             : // Basic block samples, max number of channels that are supported.
     119             : const ACMCodecDB::CodecSettings ACMCodecDB::codec_settings_[] = {
     120             : #if (defined(WEBRTC_CODEC_ISAC) || defined(WEBRTC_CODEC_ISACFX))
     121             :     {2, {kIsacPacSize480, kIsacPacSize960}, 0, 1},
     122             : # if (defined(WEBRTC_CODEC_ISAC))
     123             :     {1, {kIsacPacSize960}, 0, 1},
     124             : # endif
     125             : #endif
     126             :     // Mono
     127             :     {4, {80, 160, 240, 320}, 0, 2},
     128             :     {4, {160, 320, 480, 640}, 0, 2},
     129             :     {2, {320, 640}, 0, 2},
     130             :     // Stereo
     131             :     {4, {80, 160, 240, 320}, 0, 2},
     132             :     {4, {160, 320, 480, 640}, 0, 2},
     133             :     {2, {320, 640}, 0, 2},
     134             :     // G.711, PCM mu-law and A-law.
     135             :     // Mono
     136             :     {6, {80, 160, 240, 320, 400, 480}, 0, 2},
     137             :     {6, {80, 160, 240, 320, 400, 480}, 0, 2},
     138             :     // Stereo
     139             :     {6, {80, 160, 240, 320, 400, 480}, 0, 2},
     140             :     {6, {80, 160, 240, 320, 400, 480}, 0, 2},
     141             : #ifdef WEBRTC_CODEC_ILBC
     142             :     {4, {160, 240, 320, 480}, 0, 1},
     143             : #endif
     144             : #ifdef WEBRTC_CODEC_G722
     145             :     // Mono
     146             :     {6, {160, 320, 480, 640, 800, 960}, 0, 2},
     147             :     // Stereo
     148             :     {6, {160, 320, 480, 640, 800, 960}, 0, 2},
     149             : #endif
     150             : #ifdef WEBRTC_CODEC_OPUS
     151             :     // Opus supports frames shorter than 10ms,
     152             :     // but it doesn't help us to use them.
     153             :     // Mono and stereo.
     154             :     {4, {480, 960, 1920, 2880}, 0, 2},
     155             : #endif
     156             :     // Comfort noise for three different sampling frequencies.
     157             :     {1, {240}, 240, 1},
     158             :     {1, {480}, 480, 1},
     159             :     {1, {960}, 960, 1},
     160             : // TODO(solenberg): What is this flag? It is never set in the build files.
     161             : #ifdef ENABLE_48000_HZ
     162             :     {1, {1440}, 1440, 1},
     163             : #endif
     164             :     {1, {240}, 240, 1},
     165             :     {1, {240}, 240, 1},
     166             :     {1, {240}, 240, 1},
     167             :     {1, {240}, 240, 1},
     168             : #ifdef WEBRTC_CODEC_RED
     169             :     {1, {0}, 0, 1},
     170             : #endif
     171             :     // To prevent compile errors due to trailing commas.
     172             :     {-1, {-1}, -1, 0}
     173             : };
     174             : 
     175             : // Create a database of all NetEQ decoders at compile time.
     176             : const NetEqDecoder ACMCodecDB::neteq_decoders_[] = {
     177             : #if (defined(WEBRTC_CODEC_ISAC) || defined(WEBRTC_CODEC_ISACFX))
     178             :     NetEqDecoder::kDecoderISAC,
     179             : # if (defined(WEBRTC_CODEC_ISAC))
     180             :     NetEqDecoder::kDecoderISACswb,
     181             : # endif
     182             : #endif
     183             :     // Mono
     184             :     NetEqDecoder::kDecoderPCM16B, NetEqDecoder::kDecoderPCM16Bwb,
     185             :     NetEqDecoder::kDecoderPCM16Bswb32kHz,
     186             :     // Stereo
     187             :     NetEqDecoder::kDecoderPCM16B_2ch, NetEqDecoder::kDecoderPCM16Bwb_2ch,
     188             :     NetEqDecoder::kDecoderPCM16Bswb32kHz_2ch,
     189             :     // G.711, PCM mu-las and A-law.
     190             :     // Mono
     191             :     NetEqDecoder::kDecoderPCMu, NetEqDecoder::kDecoderPCMa,
     192             :     // Stereo
     193             :     NetEqDecoder::kDecoderPCMu_2ch, NetEqDecoder::kDecoderPCMa_2ch,
     194             : #ifdef WEBRTC_CODEC_ILBC
     195             :     NetEqDecoder::kDecoderILBC,
     196             : #endif
     197             : #ifdef WEBRTC_CODEC_G722
     198             :     // Mono
     199             :     NetEqDecoder::kDecoderG722,
     200             :     // Stereo
     201             :     NetEqDecoder::kDecoderG722_2ch,
     202             : #endif
     203             : #ifdef WEBRTC_CODEC_OPUS
     204             :     // Mono and stereo.
     205             :     NetEqDecoder::kDecoderOpus,
     206             : #endif
     207             :     // Comfort noise for three different sampling frequencies.
     208             :     NetEqDecoder::kDecoderCNGnb, NetEqDecoder::kDecoderCNGwb,
     209             :     NetEqDecoder::kDecoderCNGswb32kHz,
     210             : #ifdef ENABLE_48000_HZ
     211             :     NetEqDecoder::kDecoderCNGswb48kHz,
     212             : #endif
     213             :     NetEqDecoder::kDecoderAVT,
     214             :     NetEqDecoder::kDecoderAVT16kHz,
     215             :     NetEqDecoder::kDecoderAVT32kHz,
     216             :     NetEqDecoder::kDecoderAVT48kHz,
     217             : #ifdef WEBRTC_CODEC_RED
     218             :     NetEqDecoder::kDecoderRED,
     219             : #endif
     220             : };
     221             : 
     222             : // Enumerator for error codes when asking for codec database id.
     223             : enum {
     224             :   kInvalidCodec = -10,
     225             :   kInvalidPayloadtype = -30,
     226             :   kInvalidPacketSize = -40,
     227             :   kInvalidRate = -50
     228             : };
     229             : 
     230             : // Gets the codec id number from the database. If there is some mismatch in
     231             : // the codec settings, the function will return an error code.
     232             : // NOTE! The first mismatch found will generate the return value.
     233           0 : int ACMCodecDB::CodecNumber(const CodecInst& codec_inst) {
     234             :   // Look for a matching codec in the database.
     235           0 :   int codec_id = CodecId(codec_inst);
     236             : 
     237             :   // Checks if we found a matching codec.
     238           0 :   if (codec_id == -1) {
     239           0 :     return kInvalidCodec;
     240             :   }
     241             : 
     242             :   // Checks the validity of payload type
     243           0 :   if (!RentACodec::IsPayloadTypeValid(codec_inst.pltype)) {
     244           0 :     return kInvalidPayloadtype;
     245             :   }
     246             : 
     247             :   // Comfort Noise is special case, packet-size & rate is not checked.
     248           0 :   if (STR_CASE_CMP(database_[codec_id].plname, "CN") == 0) {
     249           0 :     return codec_id;
     250             :   }
     251             : 
     252             :   // RED is special case, packet-size & rate is not checked.
     253           0 :   if (STR_CASE_CMP(database_[codec_id].plname, "red") == 0) {
     254           0 :     return codec_id;
     255             :   }
     256             : 
     257             :   // Checks the validity of packet size.
     258           0 :   if (codec_settings_[codec_id].num_packet_sizes > 0) {
     259           0 :     bool packet_size_ok = false;
     260             :     int i;
     261             :     int packet_size_samples;
     262           0 :     for (i = 0; i < codec_settings_[codec_id].num_packet_sizes; i++) {
     263           0 :       packet_size_samples =
     264             :           codec_settings_[codec_id].packet_sizes_samples[i];
     265           0 :       if (codec_inst.pacsize == packet_size_samples) {
     266           0 :         packet_size_ok = true;
     267           0 :         break;
     268             :       }
     269             :     }
     270             : 
     271           0 :     if (!packet_size_ok) {
     272           0 :       return kInvalidPacketSize;
     273             :     }
     274             :   }
     275             : 
     276           0 :   if (codec_inst.pacsize < 1) {
     277           0 :     return kInvalidPacketSize;
     278             :   }
     279             : 
     280             :   // Check the validity of rate. Codecs with multiple rates have their own
     281             :   // function for this.
     282           0 :   if (STR_CASE_CMP("isac", codec_inst.plname) == 0) {
     283           0 :     return IsISACRateValid(codec_inst.rate) ? codec_id : kInvalidRate;
     284           0 :   } else if (STR_CASE_CMP("ilbc", codec_inst.plname) == 0) {
     285           0 :     return IsILBCRateValid(codec_inst.rate, codec_inst.pacsize)
     286           0 :         ? codec_id : kInvalidRate;
     287           0 :   } else if (STR_CASE_CMP("opus", codec_inst.plname) == 0) {
     288           0 :     return IsOpusRateValid(codec_inst.rate)
     289           0 :         ? codec_id : kInvalidRate;
     290             :   }
     291             : 
     292           0 :   return database_[codec_id].rate == codec_inst.rate ? codec_id : kInvalidRate;
     293             : }
     294             : 
     295             : // Looks for a matching payload name, frequency, and channels in the
     296             : // codec list. Need to check all three since some codecs have several codec
     297             : // entries with different frequencies and/or channels.
     298             : // Does not check other codec settings, such as payload type and packet size.
     299             : // Returns the id of the codec, or -1 if no match is found.
     300           0 : int ACMCodecDB::CodecId(const CodecInst& codec_inst) {
     301           0 :   return (CodecId(codec_inst.plname, codec_inst.plfreq,
     302           0 :                   codec_inst.channels));
     303             : }
     304             : 
     305           0 : int ACMCodecDB::CodecId(const char* payload_name,
     306             :                         int frequency,
     307             :                         size_t channels) {
     308           0 :   for (const CodecInst& ci : RentACodec::Database()) {
     309           0 :     bool name_match = false;
     310           0 :     bool frequency_match = false;
     311           0 :     bool channels_match = false;
     312             : 
     313             :     // Payload name, sampling frequency and number of channels need to match.
     314             :     // NOTE! If |frequency| is -1, the frequency is not applicable, and is
     315             :     // always treated as true, like for RED.
     316           0 :     name_match = (STR_CASE_CMP(ci.plname, payload_name) == 0);
     317           0 :     frequency_match = (frequency == ci.plfreq) || (frequency == -1);
     318             :     // The number of channels must match for all codecs but Opus.
     319           0 :     if (STR_CASE_CMP(payload_name, "opus") != 0) {
     320           0 :       channels_match = (channels == ci.channels);
     321             :     } else {
     322             :       // For opus we just check that number of channels is valid.
     323           0 :       channels_match = (channels == 1 || channels == 2);
     324             :     }
     325             : 
     326           0 :     if (name_match && frequency_match && channels_match) {
     327             :       // We have found a matching codec in the list.
     328           0 :       return &ci - RentACodec::Database().data();
     329             :     }
     330             :   }
     331             : 
     332             :   // We didn't find a matching codec.
     333           0 :   return -1;
     334             : }
     335             : // Gets codec id number from database for the receiver.
     336           0 : int ACMCodecDB::ReceiverCodecNumber(const CodecInst& codec_inst) {
     337             :   // Look for a matching codec in the database.
     338           0 :   return CodecId(codec_inst);
     339             : }
     340             : 
     341             : }  // namespace acm2
     342             : 
     343             : }  // namespace webrtc

Generated by: LCOV version 1.13