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_owner.h" | 11 #include "webrtc/modules/audio_coding/main/acm2/codec_owner.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/codecs/cng/include/audio_encoder_cng.h" | 15 #include "webrtc/modules/audio_coding/codecs/cng/include/audio_encoder_cng.h" |
16 #include "webrtc/modules/audio_coding/codecs/g711/include/audio_encoder_pcm.h" | 16 #include "webrtc/modules/audio_coding/codecs/g711/include/audio_encoder_pcm.h" |
17 #include "webrtc/modules/audio_coding/codecs/g722/include/audio_encoder_g722.h" | 17 #include "webrtc/modules/audio_coding/codecs/g722/include/audio_encoder_g722.h" |
18 #include "webrtc/modules/audio_coding/codecs/ilbc/interface/audio_encoder_ilbc.h
" | 18 #include "webrtc/modules/audio_coding/codecs/ilbc/interface/audio_encoder_ilbc.h
" |
19 #include "webrtc/modules/audio_coding/codecs/isac/fix/interface/audio_encoder_is
acfix.h" | 19 #include "webrtc/modules/audio_coding/codecs/isac/fix/interface/audio_encoder_is
acfix.h" |
20 #include "webrtc/modules/audio_coding/codecs/isac/main/interface/audio_encoder_i
sac.h" | 20 #include "webrtc/modules/audio_coding/codecs/isac/main/interface/audio_encoder_i
sac.h" |
21 #include "webrtc/modules/audio_coding/codecs/opus/interface/audio_encoder_opus.h
" | 21 #include "webrtc/modules/audio_coding/codecs/opus/interface/audio_encoder_opus.h
" |
22 #include "webrtc/modules/audio_coding/codecs/pcm16b/include/audio_encoder_pcm16b
.h" | 22 #include "webrtc/modules/audio_coding/codecs/pcm16b/include/audio_encoder_pcm16b
.h" |
23 #include "webrtc/modules/audio_coding/codecs/red/audio_encoder_copy_red.h" | 23 #include "webrtc/modules/audio_coding/codecs/red/audio_encoder_copy_red.h" |
24 #include "webrtc/modules/audio_coding/main/acm2/acm_common_defs.h" | 24 #include "webrtc/modules/audio_coding/main/acm2/delayed_logger.h" |
25 #include "webrtc/system_wrappers/interface/metrics.h" | |
26 | 25 |
27 namespace webrtc { | 26 namespace webrtc { |
28 namespace acm2 { | 27 namespace acm2 { |
29 | 28 |
30 namespace { | 29 namespace { |
31 bool IsIsac(const CodecInst& codec) { | 30 bool IsIsac(const CodecInst& codec) { |
32 return | 31 return |
33 #if (defined(WEBRTC_CODEC_ISAC) || defined(WEBRTC_CODEC_ISACFX)) | 32 #if (defined(WEBRTC_CODEC_ISAC) || defined(WEBRTC_CODEC_ISACFX)) |
34 !STR_CASE_CMP(codec.plname, "isac") || | 33 !STR_CASE_CMP(codec.plname, "isac") || |
35 #endif | 34 #endif |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
70 | 69 |
71 bool IsG722(const CodecInst& codec) { | 70 bool IsG722(const CodecInst& codec) { |
72 return | 71 return |
73 #ifdef WEBRTC_CODEC_G722 | 72 #ifdef WEBRTC_CODEC_G722 |
74 !STR_CASE_CMP(codec.plname, "g722") || | 73 !STR_CASE_CMP(codec.plname, "g722") || |
75 #endif | 74 #endif |
76 false; | 75 false; |
77 } | 76 } |
78 } // namespace | 77 } // namespace |
79 | 78 |
80 CodecOwner::CodecOwner() | 79 CodecOwner::CodecOwner(DelayedLogger* bitrate_logger) |
81 : isac_is_encoder_(false), external_speech_encoder_(nullptr) { | 80 : isac_is_encoder_(false), |
| 81 external_speech_encoder_(nullptr), |
| 82 bitrate_logger_(bitrate_logger) { |
82 } | 83 } |
83 | 84 |
84 CodecOwner::~CodecOwner() = default; | 85 CodecOwner::~CodecOwner() = default; |
85 | 86 |
86 namespace { | 87 namespace { |
87 AudioEncoderDecoderMutableIsac* CreateIsacCodec(const CodecInst& speech_inst) { | 88 AudioEncoderDecoderMutableIsac* CreateIsacCodec(const CodecInst& speech_inst) { |
88 #if defined(WEBRTC_CODEC_ISACFX) | 89 #if defined(WEBRTC_CODEC_ISACFX) |
89 return new AudioEncoderDecoderMutableIsacFix(speech_inst); | 90 return new AudioEncoderDecoderMutableIsacFix(speech_inst); |
90 #elif defined(WEBRTC_CODEC_ISAC) | 91 #elif defined(WEBRTC_CODEC_ISAC) |
91 return new AudioEncoderDecoderMutableIsacFloat(speech_inst); | 92 return new AudioEncoderDecoderMutableIsacFloat(speech_inst); |
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
175 } // namespace | 176 } // namespace |
176 | 177 |
177 void CodecOwner::SetEncoders(const CodecInst& speech_inst, | 178 void CodecOwner::SetEncoders(const CodecInst& speech_inst, |
178 int cng_payload_type, | 179 int cng_payload_type, |
179 ACMVADMode vad_mode, | 180 ACMVADMode vad_mode, |
180 int red_payload_type) { | 181 int red_payload_type) { |
181 CreateSpeechEncoder(speech_inst, &speech_encoder_, &isac_codec_, | 182 CreateSpeechEncoder(speech_inst, &speech_encoder_, &isac_codec_, |
182 &isac_is_encoder_); | 183 &isac_is_encoder_); |
183 external_speech_encoder_ = nullptr; | 184 external_speech_encoder_ = nullptr; |
184 ChangeCngAndRed(cng_payload_type, vad_mode, red_payload_type); | 185 ChangeCngAndRed(cng_payload_type, vad_mode, red_payload_type); |
185 RTC_HISTOGRAM_COUNTS_100(HISTOGRAM_NAME_AUDIO_TARGET_BITRATE_IN_KBPS, | 186 if (bitrate_logger_) { |
186 SpeechEncoder()->GetTargetBitrate() / 1000); | 187 bitrate_logger_->SetValue(SpeechEncoder()->GetTargetBitrate() / 1000); |
| 188 } |
187 } | 189 } |
188 | 190 |
189 void CodecOwner::SetEncoders(AudioEncoderMutable* external_speech_encoder, | 191 void CodecOwner::SetEncoders(AudioEncoderMutable* external_speech_encoder, |
190 int cng_payload_type, | 192 int cng_payload_type, |
191 ACMVADMode vad_mode, | 193 ACMVADMode vad_mode, |
192 int red_payload_type) { | 194 int red_payload_type) { |
193 external_speech_encoder_ = external_speech_encoder; | 195 external_speech_encoder_ = external_speech_encoder; |
194 speech_encoder_.reset(); | 196 speech_encoder_.reset(); |
195 isac_is_encoder_ = false; | 197 isac_is_encoder_ = false; |
196 ChangeCngAndRed(cng_payload_type, vad_mode, red_payload_type); | 198 ChangeCngAndRed(cng_payload_type, vad_mode, red_payload_type); |
197 RTC_HISTOGRAM_COUNTS_100(HISTOGRAM_NAME_AUDIO_TARGET_BITRATE_IN_KBPS, | 199 if (bitrate_logger_) { |
198 SpeechEncoder()->GetTargetBitrate() / 1000); | 200 bitrate_logger_->SetValue(SpeechEncoder()->GetTargetBitrate() / 1000); |
| 201 } |
199 } | 202 } |
200 | 203 |
201 void CodecOwner::ChangeCngAndRed(int cng_payload_type, | 204 void CodecOwner::ChangeCngAndRed(int cng_payload_type, |
202 ACMVADMode vad_mode, | 205 ACMVADMode vad_mode, |
203 int red_payload_type) { | 206 int red_payload_type) { |
204 AudioEncoderMutable* speech_encoder = SpeechEncoder(); | 207 AudioEncoderMutable* speech_encoder = SpeechEncoder(); |
205 if (cng_payload_type != -1 || red_payload_type != -1) { | 208 if (cng_payload_type != -1 || red_payload_type != -1) { |
206 // The RED and CNG encoders need to be in sync with the speech encoder, so | 209 // The RED and CNG encoders need to be in sync with the speech encoder, so |
207 // reset the latter to ensure its buffer is empty. | 210 // reset the latter to ensure its buffer is empty. |
208 speech_encoder->Reset(); | 211 speech_encoder->Reset(); |
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
255 DCHECK_LE(num_true, 1); | 258 DCHECK_LE(num_true, 1); |
256 if (external_speech_encoder_) | 259 if (external_speech_encoder_) |
257 return external_speech_encoder_; | 260 return external_speech_encoder_; |
258 if (speech_encoder_) | 261 if (speech_encoder_) |
259 return speech_encoder_.get(); | 262 return speech_encoder_.get(); |
260 return isac_is_encoder_ ? isac_codec_.get() : nullptr; | 263 return isac_is_encoder_ ? isac_codec_.get() : nullptr; |
261 } | 264 } |
262 | 265 |
263 } // namespace acm2 | 266 } // namespace acm2 |
264 } // namespace webrtc | 267 } // namespace webrtc |
OLD | NEW |