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