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