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/modules/audio_coding/main/acm2/acm_common_defs.h" | 16 #include "webrtc/modules/audio_coding/main/acm2/delayed_logger.h" |
17 #include "webrtc/system_wrappers/interface/metrics.h" | |
18 #include "webrtc/system_wrappers/interface/trace.h" | 17 #include "webrtc/system_wrappers/interface/trace.h" |
19 | 18 |
20 namespace webrtc { | 19 namespace webrtc { |
21 namespace acm2 { | 20 namespace acm2 { |
22 | 21 |
23 namespace { | 22 namespace { |
24 bool IsCodecRED(const CodecInst& codec) { | 23 bool IsCodecRED(const CodecInst& codec) { |
25 return (STR_CASE_CMP(codec.plname, "RED") == 0); | 24 return (STR_CASE_CMP(codec.plname, "RED") == 0); |
26 } | 25 } |
27 | 26 |
(...skipping 120 matching lines...) Loading... |
148 } | 147 } |
149 | 148 |
150 bool CodecSupported(const CodecInst& codec) { | 149 bool CodecSupported(const CodecInst& codec) { |
151 return IsOpus(codec) || IsPcmU(codec) || IsPcmA(codec) || IsPcm16B(codec) || | 150 return IsOpus(codec) || IsPcmU(codec) || IsPcmA(codec) || IsPcm16B(codec) || |
152 IsIlbc(codec) || IsG722(codec) || IsIsac(codec); | 151 IsIlbc(codec) || IsG722(codec) || IsIsac(codec); |
153 } | 152 } |
154 | 153 |
155 const CodecInst kEmptyCodecInst = {-1, "noCodecRegistered", 0, 0, 0, 0}; | 154 const CodecInst kEmptyCodecInst = {-1, "noCodecRegistered", 0, 0, 0, 0}; |
156 } // namespace | 155 } // namespace |
157 | 156 |
158 CodecManager::CodecManager() | 157 CodecManager::CodecManager(DelayedLogger* bitrate_logger) |
159 : cng_nb_pltype_(255), | 158 : cng_nb_pltype_(255), |
160 cng_wb_pltype_(255), | 159 cng_wb_pltype_(255), |
161 cng_swb_pltype_(255), | 160 cng_swb_pltype_(255), |
162 cng_fb_pltype_(255), | 161 cng_fb_pltype_(255), |
163 red_nb_pltype_(255), | 162 red_nb_pltype_(255), |
164 stereo_send_(false), | 163 stereo_send_(false), |
165 dtx_enabled_(false), | 164 dtx_enabled_(false), |
166 vad_mode_(VADNormal), | 165 vad_mode_(VADNormal), |
167 send_codec_inst_(kEmptyCodecInst), | 166 send_codec_inst_(kEmptyCodecInst), |
168 red_enabled_(false), | 167 red_enabled_(false), |
169 codec_fec_enabled_(false) { | 168 codec_fec_enabled_(false), |
| 169 codec_owner_(bitrate_logger), |
| 170 bitrate_logger_(bitrate_logger) { |
170 // Register the default payload type for RED and for CNG at sampling rates of | 171 // Register the default payload type for RED and for CNG at sampling rates of |
171 // 8, 16, 32 and 48 kHz. | 172 // 8, 16, 32 and 48 kHz. |
172 for (int i = (ACMCodecDB::kNumCodecs - 1); i >= 0; i--) { | 173 for (int i = (ACMCodecDB::kNumCodecs - 1); i >= 0; i--) { |
173 if (IsCodecRED(i) && ACMCodecDB::database_[i].plfreq == 8000) { | 174 if (IsCodecRED(i) && ACMCodecDB::database_[i].plfreq == 8000) { |
174 red_nb_pltype_ = static_cast<uint8_t>(ACMCodecDB::database_[i].pltype); | 175 red_nb_pltype_ = static_cast<uint8_t>(ACMCodecDB::database_[i].pltype); |
175 } else if (IsCodecCN(i)) { | 176 } else if (IsCodecCN(i)) { |
176 if (ACMCodecDB::database_[i].plfreq == 8000) { | 177 if (ACMCodecDB::database_[i].plfreq == 8000) { |
177 cng_nb_pltype_ = static_cast<uint8_t>(ACMCodecDB::database_[i].pltype); | 178 cng_nb_pltype_ = static_cast<uint8_t>(ACMCodecDB::database_[i].pltype); |
178 } else if (ACMCodecDB::database_[i].plfreq == 16000) { | 179 } else if (ACMCodecDB::database_[i].plfreq == 16000) { |
179 cng_wb_pltype_ = static_cast<uint8_t>(ACMCodecDB::database_[i].pltype); | 180 cng_wb_pltype_ = static_cast<uint8_t>(ACMCodecDB::database_[i].pltype); |
(...skipping 127 matching lines...) Loading... |
307 DCHECK(codec_owner_.Encoder()); | 308 DCHECK(codec_owner_.Encoder()); |
308 } | 309 } |
309 send_codec_inst_.plfreq = send_codec.plfreq; | 310 send_codec_inst_.plfreq = send_codec.plfreq; |
310 send_codec_inst_.pacsize = send_codec.pacsize; | 311 send_codec_inst_.pacsize = send_codec.pacsize; |
311 send_codec_inst_.channels = send_codec.channels; | 312 send_codec_inst_.channels = send_codec.channels; |
312 send_codec_inst_.pltype = send_codec.pltype; | 313 send_codec_inst_.pltype = send_codec.pltype; |
313 | 314 |
314 // Check if a change in Rate is required. | 315 // Check if a change in Rate is required. |
315 if (send_codec.rate != send_codec_inst_.rate) { | 316 if (send_codec.rate != send_codec_inst_.rate) { |
316 codec_owner_.SpeechEncoder()->SetTargetBitrate(send_codec.rate); | 317 codec_owner_.SpeechEncoder()->SetTargetBitrate(send_codec.rate); |
317 RTC_HISTOGRAM_COUNTS_100( | 318 if (bitrate_logger_) { |
318 HISTOGRAM_NAME_AUDIO_TARGET_BITRATE_IN_KBPS, | 319 bitrate_logger_->SetValue( |
319 codec_owner_.SpeechEncoder()->GetTargetBitrate() / 1000); | 320 codec_owner_.SpeechEncoder()->GetTargetBitrate() / 1000); |
| 321 } |
320 send_codec_inst_.rate = send_codec.rate; | 322 send_codec_inst_.rate = send_codec.rate; |
321 } | 323 } |
322 | 324 |
323 codec_fec_enabled_ = codec_fec_enabled_ && | 325 codec_fec_enabled_ = codec_fec_enabled_ && |
324 codec_owner_.SpeechEncoder()->SetFec(codec_fec_enabled_); | 326 codec_owner_.SpeechEncoder()->SetFec(codec_fec_enabled_); |
325 | 327 |
326 return 0; | 328 return 0; |
327 } | 329 } |
328 | 330 |
329 void CodecManager::RegisterEncoder( | 331 void CodecManager::RegisterEncoder( |
(...skipping 140 matching lines...) Loading... |
470 case 48000: | 472 case 48000: |
471 return -1; | 473 return -1; |
472 default: | 474 default: |
473 FATAL() << sample_rate_hz << " Hz is not supported"; | 475 FATAL() << sample_rate_hz << " Hz is not supported"; |
474 return -1; | 476 return -1; |
475 } | 477 } |
476 } | 478 } |
477 | 479 |
478 } // namespace acm2 | 480 } // namespace acm2 |
479 } // namespace webrtc | 481 } // namespace webrtc |
OLD | NEW |