| 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" |
| 25 #include "webrtc/system_wrappers/interface/metrics.h" |
| 24 | 26 |
| 25 namespace webrtc { | 27 namespace webrtc { |
| 26 namespace acm2 { | 28 namespace acm2 { |
| 27 | 29 |
| 28 namespace { | 30 namespace { |
| 29 bool IsIsac(const CodecInst& codec) { | 31 bool IsIsac(const CodecInst& codec) { |
| 30 return | 32 return |
| 31 #if (defined(WEBRTC_CODEC_ISAC) || defined(WEBRTC_CODEC_ISACFX)) | 33 #if (defined(WEBRTC_CODEC_ISAC) || defined(WEBRTC_CODEC_ISACFX)) |
| 32 !STR_CASE_CMP(codec.plname, "isac") || | 34 !STR_CASE_CMP(codec.plname, "isac") || |
| 33 #endif | 35 #endif |
| (...skipping 139 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 173 } // namespace | 175 } // namespace |
| 174 | 176 |
| 175 void CodecOwner::SetEncoders(const CodecInst& speech_inst, | 177 void CodecOwner::SetEncoders(const CodecInst& speech_inst, |
| 176 int cng_payload_type, | 178 int cng_payload_type, |
| 177 ACMVADMode vad_mode, | 179 ACMVADMode vad_mode, |
| 178 int red_payload_type) { | 180 int red_payload_type) { |
| 179 CreateSpeechEncoder(speech_inst, &speech_encoder_, &isac_codec_, | 181 CreateSpeechEncoder(speech_inst, &speech_encoder_, &isac_codec_, |
| 180 &isac_is_encoder_); | 182 &isac_is_encoder_); |
| 181 external_speech_encoder_ = nullptr; | 183 external_speech_encoder_ = nullptr; |
| 182 ChangeCngAndRed(cng_payload_type, vad_mode, red_payload_type); | 184 ChangeCngAndRed(cng_payload_type, vad_mode, red_payload_type); |
| 185 RTC_HISTOGRAM_COUNTS_100(HISTOGRAM_NAME_AUDIO_TARGET_BITRATE_IN_KBPS, |
| 186 SpeechEncoder()->GetTargetBitrate() / 1000); |
| 183 } | 187 } |
| 184 | 188 |
| 185 void CodecOwner::SetEncoders(AudioEncoderMutable* external_speech_encoder, | 189 void CodecOwner::SetEncoders(AudioEncoderMutable* external_speech_encoder, |
| 186 int cng_payload_type, | 190 int cng_payload_type, |
| 187 ACMVADMode vad_mode, | 191 ACMVADMode vad_mode, |
| 188 int red_payload_type) { | 192 int red_payload_type) { |
| 189 external_speech_encoder_ = external_speech_encoder; | 193 external_speech_encoder_ = external_speech_encoder; |
| 190 speech_encoder_.reset(); | 194 speech_encoder_.reset(); |
| 191 isac_is_encoder_ = false; | 195 isac_is_encoder_ = false; |
| 192 ChangeCngAndRed(cng_payload_type, vad_mode, red_payload_type); | 196 ChangeCngAndRed(cng_payload_type, vad_mode, red_payload_type); |
| 197 RTC_HISTOGRAM_COUNTS_100(HISTOGRAM_NAME_AUDIO_TARGET_BITRATE_IN_KBPS, |
| 198 SpeechEncoder()->GetTargetBitrate() / 1000); |
| 193 } | 199 } |
| 194 | 200 |
| 195 void CodecOwner::ChangeCngAndRed(int cng_payload_type, | 201 void CodecOwner::ChangeCngAndRed(int cng_payload_type, |
| 196 ACMVADMode vad_mode, | 202 ACMVADMode vad_mode, |
| 197 int red_payload_type) { | 203 int red_payload_type) { |
| 198 AudioEncoderMutable* speech_encoder = SpeechEncoder(); | 204 AudioEncoderMutable* speech_encoder = SpeechEncoder(); |
| 199 if (cng_payload_type != -1 || red_payload_type != -1) { | 205 if (cng_payload_type != -1 || red_payload_type != -1) { |
| 200 // The RED and CNG encoders need to be in sync with the speech encoder, so | 206 // The RED and CNG encoders need to be in sync with the speech encoder, so |
| 201 // reset the latter to ensure its buffer is empty. | 207 // reset the latter to ensure its buffer is empty. |
| 202 speech_encoder->Reset(); | 208 speech_encoder->Reset(); |
| (...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 249 DCHECK_LE(num_true, 1); | 255 DCHECK_LE(num_true, 1); |
| 250 if (external_speech_encoder_) | 256 if (external_speech_encoder_) |
| 251 return external_speech_encoder_; | 257 return external_speech_encoder_; |
| 252 if (speech_encoder_) | 258 if (speech_encoder_) |
| 253 return speech_encoder_.get(); | 259 return speech_encoder_.get(); |
| 254 return isac_is_encoder_ ? isac_codec_.get() : nullptr; | 260 return isac_is_encoder_ ? isac_codec_.get() : nullptr; |
| 255 } | 261 } |
| 256 | 262 |
| 257 } // namespace acm2 | 263 } // namespace acm2 |
| 258 } // namespace webrtc | 264 } // namespace webrtc |
| OLD | NEW |