OLD | NEW |
---|---|
1 /* | 1 /* |
2 * Copyright (c) 2012 The WebRTC project authors. All Rights Reserved. | 2 * Copyright (c) 2012 The WebRTC project authors. All Rights Reserved. |
3 * | 3 * |
4 * Use of this source code is governed by a BSD-style license | 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 | 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 | 6 * tree. An additional intellectual property rights grant can be found |
7 * in the file PATENTS. All contributing project authors may | 7 * in the file PATENTS. All contributing project authors may |
8 * be found in the AUTHORS file in the root of the source tree. | 8 * be found in the AUTHORS file in the root of the source tree. |
9 */ | 9 */ |
10 | 10 |
11 /* | 11 /* |
12 * This file generates databases with information about all supported audio | 12 * This file generates databases with information about all supported audio |
13 * codecs. | 13 * codecs. |
14 */ | 14 */ |
15 | 15 |
16 // TODO(tlegrand): Change constant input pointers in all functions to constant | 16 // TODO(tlegrand): Change constant input pointers in all functions to constant |
17 // references, where appropriate. | 17 // references, where appropriate. |
18 #include "webrtc/modules/audio_coding/main/acm2/acm_codec_database.h" | 18 #include "webrtc/modules/audio_coding/main/acm2/acm_codec_database.h" |
19 | 19 |
20 #include <assert.h> | 20 #include <assert.h> |
21 | 21 |
22 #include "webrtc/base/checks.h" | 22 #include "webrtc/base/checks.h" |
23 #include "webrtc/modules/audio_coding/main/acm2/acm_common_defs.h" | 23 #include "webrtc/modules/audio_coding/main/acm2/acm_common_defs.h" |
24 #include "webrtc/system_wrappers/interface/trace.h" | 24 #include "webrtc/system_wrappers/interface/trace.h" |
25 | 25 |
26 namespace webrtc { | 26 namespace webrtc { |
27 | 27 |
28 namespace acm2 { | 28 namespace acm2 { |
29 | 29 |
30 namespace { | |
31 | |
32 // Checks if the bitrate is valid for the codec. | |
33 bool IsRateValid(int codec_id, int rate) { | |
34 return ACMCodecDB::database_[codec_id].rate == rate; | |
35 } | |
36 | |
37 // Checks if the bitrate is valid for iSAC. | |
38 bool IsISACRateValid(int rate) { | |
39 return (rate == -1) || ((rate <= 56000) && (rate >= 10000)); | |
40 } | |
41 | |
42 // Checks if the bitrate is valid for iLBC. | |
43 bool IsILBCRateValid(int rate, int frame_size_samples) { | |
44 if (((frame_size_samples == 240) || (frame_size_samples == 480)) && | |
45 (rate == 13300)) { | |
46 return true; | |
47 } else if (((frame_size_samples == 160) || (frame_size_samples == 320)) && | |
48 (rate == 15200)) { | |
49 return true; | |
50 } else { | |
51 return false; | |
52 } | |
53 } | |
54 | |
55 // Checks if the bitrate is valid for Opus. | |
56 bool IsOpusRateValid(int rate) { | |
57 return (rate >= 6000) && (rate <= 510000); | |
58 } | |
59 | |
60 } // namespace | |
61 | |
30 // Not yet used payload-types. | 62 // Not yet used payload-types. |
31 // 83, 82, 81, 80, 79, 78, 77, 76, 75, 74, 73, 72, 71, 70, 69, 68, | 63 // 83, 82, 81, 80, 79, 78, 77, 76, 75, 74, 73, 72, 71, 70, 69, 68, |
32 // 67, 66, 65 | 64 // 67, 66, 65 |
33 | 65 |
34 const CodecInst ACMCodecDB::database_[] = { | 66 const CodecInst ACMCodecDB::database_[] = { |
35 #if (defined(WEBRTC_CODEC_ISAC) || defined(WEBRTC_CODEC_ISACFX)) | 67 #if (defined(WEBRTC_CODEC_ISAC) || defined(WEBRTC_CODEC_ISACFX)) |
36 {103, "ISAC", 16000, kIsacPacSize480, 1, kIsacWbDefaultRate}, | 68 {103, "ISAC", 16000, kIsacPacSize480, 1, kIsacWbDefaultRate}, |
37 # if (defined(WEBRTC_CODEC_ISAC)) | 69 # if (defined(WEBRTC_CODEC_ISAC)) |
38 {104, "ISAC", 32000, kIsacPacSize960, 1, kIsacSwbDefaultRate}, | 70 {104, "ISAC", 32000, kIsacPacSize960, 1, kIsacSwbDefaultRate}, |
39 {105, "ISAC", 48000, kIsacPacSize1440, 1, kIsacSwbDefaultRate}, | 71 {105, "ISAC", 48000, kIsacPacSize1440, 1, kIsacSwbDefaultRate}, |
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
82 // To prevent compile errors due to trailing commas. | 114 // To prevent compile errors due to trailing commas. |
83 {-1, "Null", -1, -1, -1, -1} | 115 {-1, "Null", -1, -1, -1, -1} |
84 }; | 116 }; |
85 | 117 |
86 // Create database with all codec settings at compile time. | 118 // Create database with all codec settings at compile time. |
87 // Each entry needs the following parameters in the given order: | 119 // Each entry needs the following parameters in the given order: |
88 // Number of allowed packet sizes, a vector with the allowed packet sizes, | 120 // Number of allowed packet sizes, a vector with the allowed packet sizes, |
89 // Basic block samples, max number of channels that are supported. | 121 // Basic block samples, max number of channels that are supported. |
90 const ACMCodecDB::CodecSettings ACMCodecDB::codec_settings_[] = { | 122 const ACMCodecDB::CodecSettings ACMCodecDB::codec_settings_[] = { |
91 #if (defined(WEBRTC_CODEC_ISAC) || defined(WEBRTC_CODEC_ISACFX)) | 123 #if (defined(WEBRTC_CODEC_ISAC) || defined(WEBRTC_CODEC_ISACFX)) |
92 {2, {kIsacPacSize480, kIsacPacSize960}, 0, 1, true}, | 124 {2, {kIsacPacSize480, kIsacPacSize960}, 0, 1}, |
93 # if (defined(WEBRTC_CODEC_ISAC)) | 125 # if (defined(WEBRTC_CODEC_ISAC)) |
94 {1, {kIsacPacSize960}, 0, 1, true}, | 126 {1, {kIsacPacSize960}, 0, 1}, |
95 {1, {kIsacPacSize1440}, 0, 1, true}, | 127 {1, {kIsacPacSize1440}, 0, 1}, |
96 # endif | 128 # endif |
97 #endif | 129 #endif |
98 // Mono | 130 // Mono |
99 {4, {80, 160, 240, 320}, 0, 2, false}, | 131 {4, {80, 160, 240, 320}, 0, 2}, |
100 {4, {160, 320, 480, 640}, 0, 2, false}, | 132 {4, {160, 320, 480, 640}, 0, 2}, |
101 {2, {320, 640}, 0, 2, false}, | 133 {2, {320, 640}, 0, 2}, |
102 // Stereo | 134 // Stereo |
103 {4, {80, 160, 240, 320}, 0, 2, false}, | 135 {4, {80, 160, 240, 320}, 0, 2}, |
104 {4, {160, 320, 480, 640}, 0, 2, false}, | 136 {4, {160, 320, 480, 640}, 0, 2}, |
105 {2, {320, 640}, 0, 2}, | 137 {2, {320, 640}, 0, 2}, |
106 // G.711, PCM mu-law and A-law. | 138 // G.711, PCM mu-law and A-law. |
107 // Mono | 139 // Mono |
108 {6, {80, 160, 240, 320, 400, 480}, 0, 2, false}, | 140 {6, {80, 160, 240, 320, 400, 480}, 0, 2}, |
109 {6, {80, 160, 240, 320, 400, 480}, 0, 2, false}, | 141 {6, {80, 160, 240, 320, 400, 480}, 0, 2}, |
110 // Stereo | 142 // Stereo |
111 {6, {80, 160, 240, 320, 400, 480}, 0, 2, false}, | 143 {6, {80, 160, 240, 320, 400, 480}, 0, 2}, |
112 {6, {80, 160, 240, 320, 400, 480}, 0, 2, false}, | 144 {6, {80, 160, 240, 320, 400, 480}, 0, 2}, |
113 #ifdef WEBRTC_CODEC_ILBC | 145 #ifdef WEBRTC_CODEC_ILBC |
114 {4, {160, 240, 320, 480}, 0, 1, false}, | 146 {4, {160, 240, 320, 480}, 0, 1}, |
115 #endif | 147 #endif |
116 #ifdef WEBRTC_CODEC_G722 | 148 #ifdef WEBRTC_CODEC_G722 |
117 // Mono | 149 // Mono |
118 {6, {160, 320, 480, 640, 800, 960}, 0, 2, false}, | 150 {6, {160, 320, 480, 640, 800, 960}, 0, 2}, |
119 // Stereo | 151 // Stereo |
120 {6, {160, 320, 480, 640, 800, 960}, 0, 2, false}, | 152 {6, {160, 320, 480, 640, 800, 960}, 0, 2}, |
121 #endif | 153 #endif |
122 #ifdef WEBRTC_CODEC_OPUS | 154 #ifdef WEBRTC_CODEC_OPUS |
123 // Opus supports frames shorter than 10ms, | 155 // Opus supports frames shorter than 10ms, |
124 // but it doesn't help us to use them. | 156 // but it doesn't help us to use them. |
125 // Mono and stereo. | 157 // Mono and stereo. |
126 {4, {480, 960, 1920, 2880}, 0, 2, false}, | 158 {4, {480, 960, 1920, 2880}, 0, 2}, |
127 #endif | 159 #endif |
128 // Comfort noise for three different sampling frequencies. | 160 // Comfort noise for three different sampling frequencies. |
129 {1, {240}, 240, 1, false}, | 161 {1, {240}, 240, 1}, |
130 {1, {480}, 480, 1, false}, | 162 {1, {480}, 480, 1}, |
131 {1, {960}, 960, 1, false}, | 163 {1, {960}, 960, 1}, |
132 #ifdef ENABLE_48000_HZ | 164 #ifdef ENABLE_48000_HZ |
133 {1, {1440}, 1440, 1, false}, | 165 {1, {1440}, 1440, 1}, |
134 #endif | 166 #endif |
135 {1, {240}, 240, 1, false}, | 167 {1, {240}, 240, 1}, |
136 #ifdef WEBRTC_CODEC_RED | 168 #ifdef WEBRTC_CODEC_RED |
137 {1, {0}, 0, 1, false}, | 169 {1, {0}, 0, 1}, |
138 #endif | 170 #endif |
139 // To prevent compile errors due to trailing commas. | 171 // To prevent compile errors due to trailing commas. |
140 {-1, {-1}, -1, -1, false} | 172 {-1, {-1}, -1, -1} |
141 }; | 173 }; |
142 | 174 |
143 // Create a database of all NetEQ decoders at compile time. | 175 // Create a database of all NetEQ decoders at compile time. |
144 const NetEqDecoder ACMCodecDB::neteq_decoders_[] = { | 176 const NetEqDecoder ACMCodecDB::neteq_decoders_[] = { |
145 #if (defined(WEBRTC_CODEC_ISAC) || defined(WEBRTC_CODEC_ISACFX)) | 177 #if (defined(WEBRTC_CODEC_ISAC) || defined(WEBRTC_CODEC_ISACFX)) |
146 kDecoderISAC, | 178 kDecoderISAC, |
147 # if (defined(WEBRTC_CODEC_ISAC)) | 179 # if (defined(WEBRTC_CODEC_ISAC)) |
148 kDecoderISACswb, | 180 kDecoderISACswb, |
149 kDecoderISACfb, | 181 kDecoderISACfb, |
150 # endif | 182 # endif |
(...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
262 return kInvalidPacketSize; | 294 return kInvalidPacketSize; |
263 } | 295 } |
264 | 296 |
265 // Check the validity of rate. Codecs with multiple rates have their own | 297 // Check the validity of rate. Codecs with multiple rates have their own |
266 // function for this. | 298 // function for this. |
267 if (STR_CASE_CMP("isac", codec_inst.plname) == 0) { | 299 if (STR_CASE_CMP("isac", codec_inst.plname) == 0) { |
268 return IsISACRateValid(codec_inst.rate) ? codec_id : kInvalidRate; | 300 return IsISACRateValid(codec_inst.rate) ? codec_id : kInvalidRate; |
269 } else if (STR_CASE_CMP("ilbc", codec_inst.plname) == 0) { | 301 } else if (STR_CASE_CMP("ilbc", codec_inst.plname) == 0) { |
270 return IsILBCRateValid(codec_inst.rate, codec_inst.pacsize) | 302 return IsILBCRateValid(codec_inst.rate, codec_inst.pacsize) |
271 ? codec_id : kInvalidRate; | 303 ? codec_id : kInvalidRate; |
272 } else if (STR_CASE_CMP("amr", codec_inst.plname) == 0) { | |
273 return IsAMRRateValid(codec_inst.rate) | |
274 ? codec_id : kInvalidRate; | |
275 } else if (STR_CASE_CMP("amr-wb", codec_inst.plname) == 0) { | |
276 return IsAMRwbRateValid(codec_inst.rate) | |
277 ? codec_id : kInvalidRate; | |
278 } else if (STR_CASE_CMP("g7291", codec_inst.plname) == 0) { | |
279 return IsG7291RateValid(codec_inst.rate) | |
280 ? codec_id : kInvalidRate; | |
281 } else if (STR_CASE_CMP("opus", codec_inst.plname) == 0) { | 304 } else if (STR_CASE_CMP("opus", codec_inst.plname) == 0) { |
282 return IsOpusRateValid(codec_inst.rate) | 305 return IsOpusRateValid(codec_inst.rate) |
283 ? codec_id : kInvalidRate; | 306 ? codec_id : kInvalidRate; |
284 } else if (STR_CASE_CMP("speex", codec_inst.plname) == 0) { | |
285 return IsSpeexRateValid(codec_inst.rate) | |
286 ? codec_id : kInvalidRate; | |
287 } | 307 } |
288 | 308 |
289 return IsRateValid(codec_id, codec_inst.rate) ? | 309 return IsRateValid(codec_id, codec_inst.rate) ? |
290 codec_id : kInvalidRate; | 310 codec_id : kInvalidRate; |
291 } | 311 } |
292 | 312 |
293 // Looks for a matching payload name, frequency, and channels in the | 313 // Looks for a matching payload name, frequency, and channels in the |
294 // codec list. Need to check all three since some codecs have several codec | 314 // codec list. Need to check all three since some codecs have several codec |
295 // entries with different frequencies and/or channels. | 315 // entries with different frequencies and/or channels. |
296 // Does not check other codec settings, such as payload type and packet size. | 316 // Does not check other codec settings, such as payload type and packet size. |
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
338 // database. | 358 // database. |
339 int ACMCodecDB::CodecFreq(int codec_id) { | 359 int ACMCodecDB::CodecFreq(int codec_id) { |
340 // Error check to see that codec_id is not out of bounds. | 360 // Error check to see that codec_id is not out of bounds. |
341 if (codec_id < 0 || codec_id >= kNumCodecs) { | 361 if (codec_id < 0 || codec_id >= kNumCodecs) { |
342 return -1; | 362 return -1; |
343 } | 363 } |
344 | 364 |
345 return database_[codec_id].plfreq; | 365 return database_[codec_id].plfreq; |
346 } | 366 } |
347 | 367 |
348 // Returns the codec's basic coding block size in samples. | |
349 int ACMCodecDB::BasicCodingBlock(int codec_id) { | |
350 // Error check to see that codec_id is not out of bounds. | |
351 if (codec_id < 0 || codec_id >= kNumCodecs) { | |
352 return -1; | |
353 } | |
354 | |
355 return codec_settings_[codec_id].basic_block_samples; | |
356 } | |
357 | |
358 // Returns the NetEQ decoder database. | |
359 const NetEqDecoder* ACMCodecDB::NetEQDecoders() { | |
hlundin-webrtc
2015/09/23 14:42:07
So, the getter is not used, but the underlying arr
| |
360 return neteq_decoders_; | |
361 } | |
362 | |
363 // Checks if the bitrate is valid for the codec. | |
364 bool ACMCodecDB::IsRateValid(int codec_id, int rate) { | |
365 return database_[codec_id].rate == rate; | |
366 } | |
367 | |
368 // Checks if the bitrate is valid for iSAC. | |
369 bool ACMCodecDB::IsISACRateValid(int rate) { | |
370 return (rate == -1) || ((rate <= 56000) && (rate >= 10000)); | |
371 } | |
372 | |
373 // Checks if the bitrate is valid for iLBC. | |
374 bool ACMCodecDB::IsILBCRateValid(int rate, int frame_size_samples) { | |
375 if (((frame_size_samples == 240) || (frame_size_samples == 480)) && | |
376 (rate == 13300)) { | |
377 return true; | |
378 } else if (((frame_size_samples == 160) || (frame_size_samples == 320)) && | |
379 (rate == 15200)) { | |
380 return true; | |
381 } else { | |
382 return false; | |
383 } | |
384 } | |
385 | |
386 // Check if the bitrate is valid for the GSM-AMR. | |
387 bool ACMCodecDB::IsAMRRateValid(int rate) { | |
388 switch (rate) { | |
389 case 4750: | |
390 case 5150: | |
391 case 5900: | |
392 case 6700: | |
393 case 7400: | |
394 case 7950: | |
395 case 10200: | |
396 case 12200: { | |
397 return true; | |
398 } | |
399 default: { | |
400 return false; | |
401 } | |
402 } | |
403 } | |
404 | |
405 // Check if the bitrate is valid for GSM-AMR-WB. | |
406 bool ACMCodecDB::IsAMRwbRateValid(int rate) { | |
407 switch (rate) { | |
408 case 7000: | |
409 case 9000: | |
410 case 12000: | |
411 case 14000: | |
412 case 16000: | |
413 case 18000: | |
414 case 20000: | |
415 case 23000: | |
416 case 24000: { | |
417 return true; | |
418 } | |
419 default: { | |
420 return false; | |
421 } | |
422 } | |
423 } | |
424 | |
425 // Check if the bitrate is valid for G.729.1. | |
426 bool ACMCodecDB::IsG7291RateValid(int rate) { | |
427 switch (rate) { | |
428 case 8000: | |
429 case 12000: | |
430 case 14000: | |
431 case 16000: | |
432 case 18000: | |
433 case 20000: | |
434 case 22000: | |
435 case 24000: | |
436 case 26000: | |
437 case 28000: | |
438 case 30000: | |
439 case 32000: { | |
440 return true; | |
441 } | |
442 default: { | |
443 return false; | |
444 } | |
445 } | |
446 } | |
447 | |
448 // Checks if the bitrate is valid for Speex. | |
449 bool ACMCodecDB::IsSpeexRateValid(int rate) { | |
450 return rate > 2000; | |
451 } | |
452 | |
453 // Checks if the bitrate is valid for Opus. | |
454 bool ACMCodecDB::IsOpusRateValid(int rate) { | |
455 return (rate >= 6000) && (rate <= 510000); | |
456 } | |
457 | |
458 // Checks if the payload type is in the valid range. | 368 // Checks if the payload type is in the valid range. |
459 bool ACMCodecDB::ValidPayloadType(int payload_type) { | 369 bool ACMCodecDB::ValidPayloadType(int payload_type) { |
460 return (payload_type >= 0) && (payload_type <= 127); | 370 return (payload_type >= 0) && (payload_type <= 127); |
461 } | 371 } |
462 | 372 |
463 bool ACMCodecDB::OwnsDecoder(int codec_id) { | |
464 assert(codec_id >= 0 && codec_id < ACMCodecDB::kNumCodecs); | |
465 return ACMCodecDB::codec_settings_[codec_id].owns_decoder; | |
466 } | |
467 | |
468 } // namespace acm2 | 373 } // namespace acm2 |
469 | 374 |
470 } // namespace webrtc | 375 } // namespace webrtc |
OLD | NEW |