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