| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright (c) 2015 The WebRTC project authors. All Rights Reserved. | 2 * Copyright (c) 2015 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 #include "webrtc/modules/audio_coding/main/acm2/codec_manager.h" | 11 #include "webrtc/modules/audio_coding/main/acm2/codec_manager.h" |
| 12 | 12 |
| 13 #include "webrtc/base/checks.h" | 13 #include "webrtc/base/checks.h" |
| 14 #include "webrtc/base/format_macros.h" |
| 14 #include "webrtc/engine_configurations.h" | 15 #include "webrtc/engine_configurations.h" |
| 15 #include "webrtc/modules/audio_coding/main/acm2/acm_codec_database.h" | 16 #include "webrtc/modules/audio_coding/main/acm2/acm_codec_database.h" |
| 16 #include "webrtc/system_wrappers/interface/trace.h" | 17 #include "webrtc/system_wrappers/interface/trace.h" |
| 17 | 18 |
| 18 namespace webrtc { | 19 namespace webrtc { |
| 19 namespace acm2 { | 20 namespace acm2 { |
| 20 | 21 |
| 21 namespace { | 22 namespace { |
| 22 bool IsCodecRED(const CodecInst& codec) { | 23 bool IsCodecRED(const CodecInst& codec) { |
| 23 return (STR_CASE_CMP(codec.plname, "RED") == 0); | 24 return (STR_CASE_CMP(codec.plname, "RED") == 0); |
| 24 } | 25 } |
| 25 | 26 |
| 26 bool IsCodecRED(int index) { | 27 bool IsCodecRED(int index) { |
| 27 return (IsCodecRED(ACMCodecDB::database_[index])); | 28 return (IsCodecRED(ACMCodecDB::database_[index])); |
| 28 } | 29 } |
| 29 | 30 |
| 30 bool IsCodecCN(const CodecInst& codec) { | 31 bool IsCodecCN(const CodecInst& codec) { |
| 31 return (STR_CASE_CMP(codec.plname, "CN") == 0); | 32 return (STR_CASE_CMP(codec.plname, "CN") == 0); |
| 32 } | 33 } |
| 33 | 34 |
| 34 bool IsCodecCN(int index) { | 35 bool IsCodecCN(int index) { |
| 35 return (IsCodecCN(ACMCodecDB::database_[index])); | 36 return (IsCodecCN(ACMCodecDB::database_[index])); |
| 36 } | 37 } |
| 37 | 38 |
| 38 // Check if the given codec is a valid to be registered as send codec. | 39 // Check if the given codec is a valid to be registered as send codec. |
| 39 int IsValidSendCodec(const CodecInst& send_codec, bool is_primary_encoder) { | 40 int IsValidSendCodec(const CodecInst& send_codec, bool is_primary_encoder) { |
| 40 int dummy_id = 0; | 41 int dummy_id = 0; |
| 41 if ((send_codec.channels != 1) && (send_codec.channels != 2)) { | 42 if ((send_codec.channels != 1) && (send_codec.channels != 2)) { |
| 42 WEBRTC_TRACE(webrtc::kTraceError, webrtc::kTraceAudioCoding, dummy_id, | 43 WEBRTC_TRACE(webrtc::kTraceError, webrtc::kTraceAudioCoding, dummy_id, |
| 43 "Wrong number of channels (%d, only mono and stereo are " | 44 "Wrong number of channels (%" PRIuS ", only mono and stereo " |
| 44 "supported) for %s encoder", | 45 "are supported) for %s encoder", |
| 45 send_codec.channels, | 46 send_codec.channels, |
| 46 is_primary_encoder ? "primary" : "secondary"); | 47 is_primary_encoder ? "primary" : "secondary"); |
| 47 return -1; | 48 return -1; |
| 48 } | 49 } |
| 49 | 50 |
| 50 int codec_id = ACMCodecDB::CodecNumber(send_codec); | 51 int codec_id = ACMCodecDB::CodecNumber(send_codec); |
| 51 if (codec_id < 0) { | 52 if (codec_id < 0) { |
| 52 WEBRTC_TRACE(webrtc::kTraceError, webrtc::kTraceAudioCoding, dummy_id, | 53 WEBRTC_TRACE(webrtc::kTraceError, webrtc::kTraceAudioCoding, dummy_id, |
| 53 "Invalid codec setting for the send codec."); | 54 "Invalid codec setting for the send codec."); |
| 54 return -1; | 55 return -1; |
| (...skipping 12 matching lines...) Expand all Loading... |
| 67 // Telephone-event cannot be a send codec. | 68 // Telephone-event cannot be a send codec. |
| 68 if (!STR_CASE_CMP(send_codec.plname, "telephone-event")) { | 69 if (!STR_CASE_CMP(send_codec.plname, "telephone-event")) { |
| 69 WEBRTC_TRACE(webrtc::kTraceError, webrtc::kTraceAudioCoding, dummy_id, | 70 WEBRTC_TRACE(webrtc::kTraceError, webrtc::kTraceAudioCoding, dummy_id, |
| 70 "telephone-event cannot be a send codec"); | 71 "telephone-event cannot be a send codec"); |
| 71 return -1; | 72 return -1; |
| 72 } | 73 } |
| 73 | 74 |
| 74 if (ACMCodecDB::codec_settings_[codec_id].channel_support < | 75 if (ACMCodecDB::codec_settings_[codec_id].channel_support < |
| 75 send_codec.channels) { | 76 send_codec.channels) { |
| 76 WEBRTC_TRACE(webrtc::kTraceError, webrtc::kTraceAudioCoding, dummy_id, | 77 WEBRTC_TRACE(webrtc::kTraceError, webrtc::kTraceAudioCoding, dummy_id, |
| 77 "%d number of channels not supportedn for %s.", | 78 "%" PRIuS " number of channels not supportedn for %s.", |
| 78 send_codec.channels, send_codec.plname); | 79 send_codec.channels, send_codec.plname); |
| 79 return -1; | 80 return -1; |
| 80 } | 81 } |
| 81 | 82 |
| 82 if (!is_primary_encoder) { | 83 if (!is_primary_encoder) { |
| 83 // If registering the secondary encoder, then RED and CN are not valid | 84 // If registering the secondary encoder, then RED and CN are not valid |
| 84 // choices as encoder. | 85 // choices as encoder. |
| 85 if (IsCodecRED(send_codec)) { | 86 if (IsCodecRED(send_codec)) { |
| 86 WEBRTC_TRACE(webrtc::kTraceError, webrtc::kTraceAudioCoding, dummy_id, | 87 WEBRTC_TRACE(webrtc::kTraceError, webrtc::kTraceAudioCoding, dummy_id, |
| 87 "RED cannot be secondary codec"); | 88 "RED cannot be secondary codec"); |
| (...skipping 377 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 465 case 48000: | 466 case 48000: |
| 466 return -1; | 467 return -1; |
| 467 default: | 468 default: |
| 468 FATAL() << sample_rate_hz << " Hz is not supported"; | 469 FATAL() << sample_rate_hz << " Hz is not supported"; |
| 469 return -1; | 470 return -1; |
| 470 } | 471 } |
| 471 } | 472 } |
| 472 | 473 |
| 473 } // namespace acm2 | 474 } // namespace acm2 |
| 474 } // namespace webrtc | 475 } // namespace webrtc |
| OLD | NEW |