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/engine_configurations.h" | 14 #include "webrtc/engine_configurations.h" |
15 #include "webrtc/modules/audio_coding/main/acm2/acm_codec_database.h" | 15 #include "webrtc/modules/audio_coding/main/acm2/acm_codec_database.h" |
16 #include "webrtc/system_wrappers/interface/trace.h" | 16 #include "webrtc/system_wrappers/interface/trace.h" |
17 | 17 |
18 namespace webrtc { | 18 namespace webrtc { |
19 namespace acm2 { | 19 namespace acm2 { |
20 | 20 |
21 namespace { | 21 namespace { |
22 bool IsCodecRED(const CodecInst& codec) { | 22 bool IsCodecRED(const CodecInst& codec) { |
23 return (STR_CASE_CMP(codec.plname, "RED") == 0); | 23 return (STR_CASE_CMP(codec.plname, "RED") == 0); |
24 } | 24 } |
25 | 25 |
26 bool IsCodecRED(int index) { | |
27 return (IsCodecRED(ACMCodecDB::database_[index])); | |
28 } | |
29 | |
30 bool IsCodecCN(const CodecInst& codec) { | 26 bool IsCodecCN(const CodecInst& codec) { |
31 return (STR_CASE_CMP(codec.plname, "CN") == 0); | 27 return (STR_CASE_CMP(codec.plname, "CN") == 0); |
32 } | 28 } |
33 | 29 |
34 bool IsCodecCN(int index) { | |
35 return (IsCodecCN(ACMCodecDB::database_[index])); | |
36 } | |
37 | |
38 // Check if the given codec is a valid to be registered as send codec. | 30 // 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) { | 31 int IsValidSendCodec(const CodecInst& send_codec, bool is_primary_encoder) { |
40 int dummy_id = 0; | 32 int dummy_id = 0; |
41 if ((send_codec.channels != 1) && (send_codec.channels != 2)) { | 33 if ((send_codec.channels != 1) && (send_codec.channels != 2)) { |
42 WEBRTC_TRACE(webrtc::kTraceError, webrtc::kTraceAudioCoding, dummy_id, | 34 WEBRTC_TRACE(webrtc::kTraceError, webrtc::kTraceAudioCoding, dummy_id, |
43 "Wrong number of channels (%d, only mono and stereo are " | 35 "Wrong number of channels (%d, only mono and stereo are " |
44 "supported) for %s encoder", | 36 "supported) for %s encoder", |
45 send_codec.channels, | 37 send_codec.channels, |
46 is_primary_encoder ? "primary" : "secondary"); | 38 is_primary_encoder ? "primary" : "secondary"); |
47 return -1; | 39 return -1; |
(...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
157 red_nb_pltype_(255), | 149 red_nb_pltype_(255), |
158 stereo_send_(false), | 150 stereo_send_(false), |
159 dtx_enabled_(false), | 151 dtx_enabled_(false), |
160 vad_mode_(VADNormal), | 152 vad_mode_(VADNormal), |
161 send_codec_inst_(kEmptyCodecInst), | 153 send_codec_inst_(kEmptyCodecInst), |
162 red_enabled_(false), | 154 red_enabled_(false), |
163 codec_fec_enabled_(false), | 155 codec_fec_enabled_(false), |
164 encoder_is_opus_(false) { | 156 encoder_is_opus_(false) { |
165 // Register the default payload type for RED and for CNG at sampling rates of | 157 // Register the default payload type for RED and for CNG at sampling rates of |
166 // 8, 16, 32 and 48 kHz. | 158 // 8, 16, 32 and 48 kHz. |
167 for (int i = (ACMCodecDB::kNumCodecs - 1); i >= 0; i--) { | 159 for (const CodecInst& ci : RentACodec::Database()) { |
168 if (IsCodecRED(i) && ACMCodecDB::database_[i].plfreq == 8000) { | 160 if (IsCodecRED(ci) && ci.plfreq == 8000) { |
169 red_nb_pltype_ = static_cast<uint8_t>(ACMCodecDB::database_[i].pltype); | 161 red_nb_pltype_ = static_cast<uint8_t>(ci.pltype); |
170 } else if (IsCodecCN(i)) { | 162 } else if (IsCodecCN(ci)) { |
171 if (ACMCodecDB::database_[i].plfreq == 8000) { | 163 if (ci.plfreq == 8000) { |
172 cng_nb_pltype_ = static_cast<uint8_t>(ACMCodecDB::database_[i].pltype); | 164 cng_nb_pltype_ = static_cast<uint8_t>(ci.pltype); |
173 } else if (ACMCodecDB::database_[i].plfreq == 16000) { | 165 } else if (ci.plfreq == 16000) { |
174 cng_wb_pltype_ = static_cast<uint8_t>(ACMCodecDB::database_[i].pltype); | 166 cng_wb_pltype_ = static_cast<uint8_t>(ci.pltype); |
175 } else if (ACMCodecDB::database_[i].plfreq == 32000) { | 167 } else if (ci.plfreq == 32000) { |
176 cng_swb_pltype_ = static_cast<uint8_t>(ACMCodecDB::database_[i].pltype); | 168 cng_swb_pltype_ = static_cast<uint8_t>(ci.pltype); |
177 } else if (ACMCodecDB::database_[i].plfreq == 48000) { | 169 } else if (ci.plfreq == 48000) { |
178 cng_fb_pltype_ = static_cast<uint8_t>(ACMCodecDB::database_[i].pltype); | 170 cng_fb_pltype_ = static_cast<uint8_t>(ci.pltype); |
179 } | 171 } |
180 } | 172 } |
181 } | 173 } |
182 thread_checker_.DetachFromThread(); | 174 thread_checker_.DetachFromThread(); |
183 } | 175 } |
184 | 176 |
185 CodecManager::~CodecManager() = default; | 177 CodecManager::~CodecManager() = default; |
186 | 178 |
187 int CodecManager::RegisterEncoder(const CodecInst& send_codec) { | 179 int CodecManager::RegisterEncoder(const CodecInst& send_codec) { |
188 RTC_DCHECK(thread_checker_.CalledOnValidThread()); | 180 RTC_DCHECK(thread_checker_.CalledOnValidThread()); |
(...skipping 275 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
464 case 48000: | 456 case 48000: |
465 return -1; | 457 return -1; |
466 default: | 458 default: |
467 FATAL() << sample_rate_hz << " Hz is not supported"; | 459 FATAL() << sample_rate_hz << " Hz is not supported"; |
468 return -1; | 460 return -1; |
469 } | 461 } |
470 } | 462 } |
471 | 463 |
472 } // namespace acm2 | 464 } // namespace acm2 |
473 } // namespace webrtc | 465 } // namespace webrtc |
OLD | NEW |