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 | // Mono |
| 89 | {9, "G722", 16000, 320, 1, 64000}, |
| 90 | // Stereo |
| 91 | {119, "G722", 16000, 320, 2, 64000}, |
turaj@webrtc.org | 7959e16 | 2013-09-12 18:30:26 +0000 | [diff] [blame] | 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 |
turaj@webrtc.org | 7959e16 | 2013-09-12 18:30:26 +0000 | [diff] [blame] | 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}, |
turaj@webrtc.org | 532f3dc | 2013-09-19 00:12:23 +0000 | [diff] [blame] | 101 | #ifdef ENABLE_48000_HZ |
turaj@webrtc.org | 7959e16 | 2013-09-12 18:30:26 +0000 | [diff] [blame] | 102 | {100, "CN", 48000, 1440, 1, 0}, |
turaj@webrtc.org | 532f3dc | 2013-09-19 00:12:23 +0000 | [diff] [blame] | 103 | #endif |
turaj@webrtc.org | 7959e16 | 2013-09-12 18:30:26 +0000 | [diff] [blame] | 104 | {106, "telephone-event", 8000, 240, 1, 0}, |
solenberg | 2779bab | 2016-11-17 04:45:19 -0800 | [diff] [blame] | 105 | {114, "telephone-event", 16000, 240, 1, 0}, |
| 106 | {115, "telephone-event", 32000, 240, 1, 0}, |
| 107 | {116, "telephone-event", 48000, 240, 1, 0}, |
turaj@webrtc.org | 7959e16 | 2013-09-12 18:30:26 +0000 | [diff] [blame] | 108 | #ifdef WEBRTC_CODEC_RED |
| 109 | {127, "red", 8000, 0, 1, 0}, |
| 110 | #endif |
| 111 | // To prevent compile errors due to trailing commas. |
pkasting | 25702cb | 2016-01-08 13:50:27 -0800 | [diff] [blame] | 112 | {-1, "Null", -1, -1, 0, -1} |
turaj@webrtc.org | 7959e16 | 2013-09-12 18:30:26 +0000 | [diff] [blame] | 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)) |
kwiberg | 65cb70d | 2017-03-03 06:16:28 -0800 | [diff] [blame] | 121 | {2, {480, 960}, 0, 1}, |
turaj@webrtc.org | 7959e16 | 2013-09-12 18:30:26 +0000 | [diff] [blame] | 122 | # if (defined(WEBRTC_CODEC_ISAC)) |
kwiberg | 65cb70d | 2017-03-03 06:16:28 -0800 | [diff] [blame] | 123 | {1, {960}, 0, 1}, |
turaj@webrtc.org | 7959e16 | 2013-09-12 18:30:26 +0000 | [diff] [blame] | 124 | # endif |
| 125 | #endif |
turaj@webrtc.org | 7959e16 | 2013-09-12 18:30:26 +0000 | [diff] [blame] | 126 | // Mono |
kwiberg | ec249d4 | 2015-09-24 04:32:03 -0700 | [diff] [blame] | 127 | {4, {80, 160, 240, 320}, 0, 2}, |
| 128 | {4, {160, 320, 480, 640}, 0, 2}, |
| 129 | {2, {320, 640}, 0, 2}, |
turaj@webrtc.org | 7959e16 | 2013-09-12 18:30:26 +0000 | [diff] [blame] | 130 | // Stereo |
kwiberg | ec249d4 | 2015-09-24 04:32:03 -0700 | [diff] [blame] | 131 | {4, {80, 160, 240, 320}, 0, 2}, |
| 132 | {4, {160, 320, 480, 640}, 0, 2}, |
turaj@webrtc.org | 7959e16 | 2013-09-12 18:30:26 +0000 | [diff] [blame] | 133 | {2, {320, 640}, 0, 2}, |
turaj@webrtc.org | 7959e16 | 2013-09-12 18:30:26 +0000 | [diff] [blame] | 134 | // G.711, PCM mu-law and A-law. |
| 135 | // Mono |
kwiberg | ec249d4 | 2015-09-24 04:32:03 -0700 | [diff] [blame] | 136 | {6, {80, 160, 240, 320, 400, 480}, 0, 2}, |
| 137 | {6, {80, 160, 240, 320, 400, 480}, 0, 2}, |
turaj@webrtc.org | 7959e16 | 2013-09-12 18:30:26 +0000 | [diff] [blame] | 138 | // Stereo |
kwiberg | ec249d4 | 2015-09-24 04:32:03 -0700 | [diff] [blame] | 139 | {6, {80, 160, 240, 320, 400, 480}, 0, 2}, |
| 140 | {6, {80, 160, 240, 320, 400, 480}, 0, 2}, |
turaj@webrtc.org | 7959e16 | 2013-09-12 18:30:26 +0000 | [diff] [blame] | 141 | #ifdef WEBRTC_CODEC_ILBC |
kwiberg | ec249d4 | 2015-09-24 04:32:03 -0700 | [diff] [blame] | 142 | {4, {160, 240, 320, 480}, 0, 1}, |
turaj@webrtc.org | 7959e16 | 2013-09-12 18:30:26 +0000 | [diff] [blame] | 143 | #endif |
turaj@webrtc.org | 7959e16 | 2013-09-12 18:30:26 +0000 | [diff] [blame] | 144 | // Mono |
kwiberg | ec249d4 | 2015-09-24 04:32:03 -0700 | [diff] [blame] | 145 | {6, {160, 320, 480, 640, 800, 960}, 0, 2}, |
turaj@webrtc.org | 7959e16 | 2013-09-12 18:30:26 +0000 | [diff] [blame] | 146 | // Stereo |
kwiberg | ec249d4 | 2015-09-24 04:32:03 -0700 | [diff] [blame] | 147 | {6, {160, 320, 480, 640, 800, 960}, 0, 2}, |
turaj@webrtc.org | 7959e16 | 2013-09-12 18:30:26 +0000 | [diff] [blame] | 148 | #ifdef WEBRTC_CODEC_OPUS |
| 149 | // Opus supports frames shorter than 10ms, |
| 150 | // but it doesn't help us to use them. |
| 151 | // Mono and stereo. |
minyue | 2e03c66 | 2017-02-01 17:31:11 -0800 | [diff] [blame] | 152 | #if WEBRTC_OPUS_SUPPORT_120MS_PTIME |
| 153 | {5, {480, 960, 1920, 2880, 5760}, 0, 2}, |
| 154 | #else |
kwiberg | ec249d4 | 2015-09-24 04:32:03 -0700 | [diff] [blame] | 155 | {4, {480, 960, 1920, 2880}, 0, 2}, |
turaj@webrtc.org | 7959e16 | 2013-09-12 18:30:26 +0000 | [diff] [blame] | 156 | #endif |
minyue | 2e03c66 | 2017-02-01 17:31:11 -0800 | [diff] [blame] | 157 | #endif |
turaj@webrtc.org | 7959e16 | 2013-09-12 18:30:26 +0000 | [diff] [blame] | 158 | // Comfort noise for three different sampling frequencies. |
kwiberg | ec249d4 | 2015-09-24 04:32:03 -0700 | [diff] [blame] | 159 | {1, {240}, 240, 1}, |
| 160 | {1, {480}, 480, 1}, |
| 161 | {1, {960}, 960, 1}, |
solenberg | 2779bab | 2016-11-17 04:45:19 -0800 | [diff] [blame] | 162 | // 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] | 163 | #ifdef ENABLE_48000_HZ |
kwiberg | ec249d4 | 2015-09-24 04:32:03 -0700 | [diff] [blame] | 164 | {1, {1440}, 1440, 1}, |
turaj@webrtc.org | 532f3dc | 2013-09-19 00:12:23 +0000 | [diff] [blame] | 165 | #endif |
kwiberg | ec249d4 | 2015-09-24 04:32:03 -0700 | [diff] [blame] | 166 | {1, {240}, 240, 1}, |
solenberg | 2779bab | 2016-11-17 04:45:19 -0800 | [diff] [blame] | 167 | {1, {240}, 240, 1}, |
| 168 | {1, {240}, 240, 1}, |
| 169 | {1, {240}, 240, 1}, |
turaj@webrtc.org | 7959e16 | 2013-09-12 18:30:26 +0000 | [diff] [blame] | 170 | #ifdef WEBRTC_CODEC_RED |
kwiberg | ec249d4 | 2015-09-24 04:32:03 -0700 | [diff] [blame] | 171 | {1, {0}, 0, 1}, |
turaj@webrtc.org | 7959e16 | 2013-09-12 18:30:26 +0000 | [diff] [blame] | 172 | #endif |
| 173 | // To prevent compile errors due to trailing commas. |
pkasting | 25702cb | 2016-01-08 13:50:27 -0800 | [diff] [blame] | 174 | {-1, {-1}, -1, 0} |
turaj@webrtc.org | 7959e16 | 2013-09-12 18:30:26 +0000 | [diff] [blame] | 175 | }; |
| 176 | |
| 177 | // Create a database of all NetEQ decoders at compile time. |
| 178 | const NetEqDecoder ACMCodecDB::neteq_decoders_[] = { |
| 179 | #if (defined(WEBRTC_CODEC_ISAC) || defined(WEBRTC_CODEC_ISACFX)) |
kwiberg | ee1879c | 2015-10-29 06:20:28 -0700 | [diff] [blame] | 180 | NetEqDecoder::kDecoderISAC, |
turaj@webrtc.org | 7959e16 | 2013-09-12 18:30:26 +0000 | [diff] [blame] | 181 | # if (defined(WEBRTC_CODEC_ISAC)) |
kwiberg | ee1879c | 2015-10-29 06:20:28 -0700 | [diff] [blame] | 182 | NetEqDecoder::kDecoderISACswb, |
turaj@webrtc.org | 7959e16 | 2013-09-12 18:30:26 +0000 | [diff] [blame] | 183 | # endif |
| 184 | #endif |
turaj@webrtc.org | 7959e16 | 2013-09-12 18:30:26 +0000 | [diff] [blame] | 185 | // Mono |
kwiberg | ee1879c | 2015-10-29 06:20:28 -0700 | [diff] [blame] | 186 | NetEqDecoder::kDecoderPCM16B, NetEqDecoder::kDecoderPCM16Bwb, |
| 187 | NetEqDecoder::kDecoderPCM16Bswb32kHz, |
turaj@webrtc.org | 7959e16 | 2013-09-12 18:30:26 +0000 | [diff] [blame] | 188 | // Stereo |
kwiberg | ee1879c | 2015-10-29 06:20:28 -0700 | [diff] [blame] | 189 | NetEqDecoder::kDecoderPCM16B_2ch, NetEqDecoder::kDecoderPCM16Bwb_2ch, |
| 190 | NetEqDecoder::kDecoderPCM16Bswb32kHz_2ch, |
turaj@webrtc.org | 7959e16 | 2013-09-12 18:30:26 +0000 | [diff] [blame] | 191 | // G.711, PCM mu-las and A-law. |
| 192 | // Mono |
kwiberg | ee1879c | 2015-10-29 06:20:28 -0700 | [diff] [blame] | 193 | NetEqDecoder::kDecoderPCMu, NetEqDecoder::kDecoderPCMa, |
turaj@webrtc.org | 7959e16 | 2013-09-12 18:30:26 +0000 | [diff] [blame] | 194 | // Stereo |
kwiberg | ee1879c | 2015-10-29 06:20:28 -0700 | [diff] [blame] | 195 | NetEqDecoder::kDecoderPCMu_2ch, NetEqDecoder::kDecoderPCMa_2ch, |
turaj@webrtc.org | 7959e16 | 2013-09-12 18:30:26 +0000 | [diff] [blame] | 196 | #ifdef WEBRTC_CODEC_ILBC |
kwiberg | ee1879c | 2015-10-29 06:20:28 -0700 | [diff] [blame] | 197 | NetEqDecoder::kDecoderILBC, |
turaj@webrtc.org | 7959e16 | 2013-09-12 18:30:26 +0000 | [diff] [blame] | 198 | #endif |
turaj@webrtc.org | 7959e16 | 2013-09-12 18:30:26 +0000 | [diff] [blame] | 199 | // Mono |
kwiberg | ee1879c | 2015-10-29 06:20:28 -0700 | [diff] [blame] | 200 | NetEqDecoder::kDecoderG722, |
turaj@webrtc.org | 7959e16 | 2013-09-12 18:30:26 +0000 | [diff] [blame] | 201 | // Stereo |
kwiberg | ee1879c | 2015-10-29 06:20:28 -0700 | [diff] [blame] | 202 | NetEqDecoder::kDecoderG722_2ch, |
turaj@webrtc.org | 7959e16 | 2013-09-12 18:30:26 +0000 | [diff] [blame] | 203 | #ifdef WEBRTC_CODEC_OPUS |
| 204 | // Mono and stereo. |
kwiberg | ee1879c | 2015-10-29 06:20:28 -0700 | [diff] [blame] | 205 | NetEqDecoder::kDecoderOpus, |
turaj@webrtc.org | 7959e16 | 2013-09-12 18:30:26 +0000 | [diff] [blame] | 206 | #endif |
turaj@webrtc.org | 7959e16 | 2013-09-12 18:30:26 +0000 | [diff] [blame] | 207 | // Comfort noise for three different sampling frequencies. |
kwiberg | ee1879c | 2015-10-29 06:20:28 -0700 | [diff] [blame] | 208 | NetEqDecoder::kDecoderCNGnb, NetEqDecoder::kDecoderCNGwb, |
| 209 | NetEqDecoder::kDecoderCNGswb32kHz, |
turaj@webrtc.org | 532f3dc | 2013-09-19 00:12:23 +0000 | [diff] [blame] | 210 | #ifdef ENABLE_48000_HZ |
kwiberg | ee1879c | 2015-10-29 06:20:28 -0700 | [diff] [blame] | 211 | NetEqDecoder::kDecoderCNGswb48kHz, |
turaj@webrtc.org | 532f3dc | 2013-09-19 00:12:23 +0000 | [diff] [blame] | 212 | #endif |
kwiberg | ee1879c | 2015-10-29 06:20:28 -0700 | [diff] [blame] | 213 | NetEqDecoder::kDecoderAVT, |
solenberg | 2779bab | 2016-11-17 04:45:19 -0800 | [diff] [blame] | 214 | NetEqDecoder::kDecoderAVT16kHz, |
| 215 | NetEqDecoder::kDecoderAVT32kHz, |
| 216 | NetEqDecoder::kDecoderAVT48kHz, |
turaj@webrtc.org | 7959e16 | 2013-09-12 18:30:26 +0000 | [diff] [blame] | 217 | #ifdef WEBRTC_CODEC_RED |
kwiberg | ee1879c | 2015-10-29 06:20:28 -0700 | [diff] [blame] | 218 | NetEqDecoder::kDecoderRED, |
turaj@webrtc.org | 7959e16 | 2013-09-12 18:30:26 +0000 | [diff] [blame] | 219 | #endif |
| 220 | }; |
| 221 | |
turaj@webrtc.org | 7959e16 | 2013-09-12 18:30:26 +0000 | [diff] [blame] | 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. |
Henrik Lundin | 93ef1d8 | 2015-04-13 09:31:16 +0200 | [diff] [blame] | 233 | int ACMCodecDB::CodecNumber(const CodecInst& codec_inst) { |
turaj@webrtc.org | 7959e16 | 2013-09-12 18:30:26 +0000 | [diff] [blame] | 234 | // Look for a matching codec in the database. |
| 235 | int codec_id = CodecId(codec_inst); |
| 236 | |
| 237 | // Checks if we found a matching codec. |
| 238 | if (codec_id == -1) { |
| 239 | return kInvalidCodec; |
| 240 | } |
| 241 | |
| 242 | // Checks the validity of payload type |
kwiberg | 93a2feb | 2015-11-05 07:39:37 -0800 | [diff] [blame] | 243 | if (!RentACodec::IsPayloadTypeValid(codec_inst.pltype)) { |
turaj@webrtc.org | 7959e16 | 2013-09-12 18:30:26 +0000 | [diff] [blame] | 244 | return kInvalidPayloadtype; |
| 245 | } |
| 246 | |
| 247 | // Comfort Noise is special case, packet-size & rate is not checked. |
| 248 | if (STR_CASE_CMP(database_[codec_id].plname, "CN") == 0) { |
turaj@webrtc.org | 7959e16 | 2013-09-12 18:30:26 +0000 | [diff] [blame] | 249 | return codec_id; |
| 250 | } |
| 251 | |
| 252 | // RED is special case, packet-size & rate is not checked. |
| 253 | if (STR_CASE_CMP(database_[codec_id].plname, "red") == 0) { |
turaj@webrtc.org | 7959e16 | 2013-09-12 18:30:26 +0000 | [diff] [blame] | 254 | return codec_id; |
| 255 | } |
| 256 | |
| 257 | // Checks the validity of packet size. |
| 258 | if (codec_settings_[codec_id].num_packet_sizes > 0) { |
| 259 | bool packet_size_ok = false; |
| 260 | int i; |
| 261 | int packet_size_samples; |
| 262 | for (i = 0; i < codec_settings_[codec_id].num_packet_sizes; i++) { |
| 263 | packet_size_samples = |
| 264 | codec_settings_[codec_id].packet_sizes_samples[i]; |
| 265 | if (codec_inst.pacsize == packet_size_samples) { |
| 266 | packet_size_ok = true; |
| 267 | break; |
| 268 | } |
| 269 | } |
| 270 | |
| 271 | if (!packet_size_ok) { |
| 272 | return kInvalidPacketSize; |
| 273 | } |
| 274 | } |
| 275 | |
| 276 | if (codec_inst.pacsize < 1) { |
| 277 | return kInvalidPacketSize; |
| 278 | } |
| 279 | |
| 280 | // Check the validity of rate. Codecs with multiple rates have their own |
| 281 | // function for this. |
turaj@webrtc.org | 7959e16 | 2013-09-12 18:30:26 +0000 | [diff] [blame] | 282 | if (STR_CASE_CMP("isac", codec_inst.plname) == 0) { |
Henrik Lundin | 93ef1d8 | 2015-04-13 09:31:16 +0200 | [diff] [blame] | 283 | return IsISACRateValid(codec_inst.rate) ? codec_id : kInvalidRate; |
turaj@webrtc.org | 7959e16 | 2013-09-12 18:30:26 +0000 | [diff] [blame] | 284 | } else if (STR_CASE_CMP("ilbc", codec_inst.plname) == 0) { |
| 285 | return IsILBCRateValid(codec_inst.rate, codec_inst.pacsize) |
| 286 | ? codec_id : kInvalidRate; |
turaj@webrtc.org | 7959e16 | 2013-09-12 18:30:26 +0000 | [diff] [blame] | 287 | } else if (STR_CASE_CMP("opus", codec_inst.plname) == 0) { |
| 288 | return IsOpusRateValid(codec_inst.rate) |
| 289 | ? codec_id : kInvalidRate; |
turaj@webrtc.org | 7959e16 | 2013-09-12 18:30:26 +0000 | [diff] [blame] | 290 | } |
| 291 | |
kwiberg | 4b938e5 | 2015-11-03 12:38:27 -0800 | [diff] [blame] | 292 | return database_[codec_id].rate == codec_inst.rate ? codec_id : kInvalidRate; |
turaj@webrtc.org | 7959e16 | 2013-09-12 18:30:26 +0000 | [diff] [blame] | 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 | int ACMCodecDB::CodecId(const CodecInst& codec_inst) { |
| 301 | return (CodecId(codec_inst.plname, codec_inst.plfreq, |
| 302 | codec_inst.channels)); |
| 303 | } |
| 304 | |
Peter Kasting | 6955870 | 2016-01-12 16:26:35 -0800 | [diff] [blame] | 305 | int ACMCodecDB::CodecId(const char* payload_name, |
| 306 | int frequency, |
| 307 | size_t channels) { |
kwiberg | fce4a94 | 2015-10-27 11:40:24 -0700 | [diff] [blame] | 308 | for (const CodecInst& ci : RentACodec::Database()) { |
turaj@webrtc.org | 7959e16 | 2013-09-12 18:30:26 +0000 | [diff] [blame] | 309 | bool name_match = false; |
| 310 | bool frequency_match = false; |
| 311 | 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. |
kwiberg | fce4a94 | 2015-10-27 11:40:24 -0700 | [diff] [blame] | 316 | name_match = (STR_CASE_CMP(ci.plname, payload_name) == 0); |
| 317 | frequency_match = (frequency == ci.plfreq) || (frequency == -1); |
turaj@webrtc.org | 7959e16 | 2013-09-12 18:30:26 +0000 | [diff] [blame] | 318 | // The number of channels must match for all codecs but Opus. |
| 319 | if (STR_CASE_CMP(payload_name, "opus") != 0) { |
kwiberg | fce4a94 | 2015-10-27 11:40:24 -0700 | [diff] [blame] | 320 | channels_match = (channels == ci.channels); |
turaj@webrtc.org | 7959e16 | 2013-09-12 18:30:26 +0000 | [diff] [blame] | 321 | } else { |
| 322 | // For opus we just check that number of channels is valid. |
| 323 | channels_match = (channels == 1 || channels == 2); |
| 324 | } |
| 325 | |
| 326 | if (name_match && frequency_match && channels_match) { |
| 327 | // We have found a matching codec in the list. |
kwiberg | fce4a94 | 2015-10-27 11:40:24 -0700 | [diff] [blame] | 328 | return &ci - RentACodec::Database().data(); |
turaj@webrtc.org | 7959e16 | 2013-09-12 18:30:26 +0000 | [diff] [blame] | 329 | } |
| 330 | } |
| 331 | |
| 332 | // We didn't find a matching codec. |
| 333 | return -1; |
| 334 | } |
Henrik Lundin | 93ef1d8 | 2015-04-13 09:31:16 +0200 | [diff] [blame] | 335 | // Gets codec id number from database for the receiver. |
| 336 | int ACMCodecDB::ReceiverCodecNumber(const CodecInst& codec_inst) { |
turaj@webrtc.org | 7959e16 | 2013-09-12 18:30:26 +0000 | [diff] [blame] | 337 | // Look for a matching codec in the database. |
Henrik Lundin | 93ef1d8 | 2015-04-13 09:31:16 +0200 | [diff] [blame] | 338 | return CodecId(codec_inst); |
turaj@webrtc.org | 7959e16 | 2013-09-12 18:30:26 +0000 | [diff] [blame] | 339 | } |
| 340 | |
turaj@webrtc.org | 6d5d248 | 2013-10-06 04:47:28 +0000 | [diff] [blame] | 341 | } // namespace acm2 |
| 342 | |
turaj@webrtc.org | 7959e16 | 2013-09-12 18:30:26 +0000 | [diff] [blame] | 343 | } // namespace webrtc |