OLD | NEW |
1 /* | 1 /* |
2 * Copyright (c) 2014 The WebRTC project authors. All Rights Reserved. | 2 * Copyright (c) 2014 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/codecs/opus/audio_encoder_opus.h" | 11 #include "webrtc/modules/audio_coding/codecs/opus/audio_encoder_opus.h" |
12 | 12 |
13 #include <algorithm> | 13 #include <algorithm> |
14 #include <iterator> | 14 #include <iterator> |
15 | 15 |
16 #include "webrtc/base/checks.h" | 16 #include "webrtc/base/checks.h" |
17 #include "webrtc/base/logging.h" | 17 #include "webrtc/base/logging.h" |
18 #include "webrtc/base/numerics/exp_filter.h" | 18 #include "webrtc/base/numerics/exp_filter.h" |
19 #include "webrtc/base/protobuf_utils.h" | |
20 #include "webrtc/base/safe_conversions.h" | 19 #include "webrtc/base/safe_conversions.h" |
21 #include "webrtc/base/timeutils.h" | 20 #include "webrtc/base/timeutils.h" |
22 #include "webrtc/common_types.h" | 21 #include "webrtc/common_types.h" |
23 #include "webrtc/modules/audio_coding/audio_network_adaptor/audio_network_adapto
r_impl.h" | 22 #include "webrtc/modules/audio_coding/audio_network_adaptor/audio_network_adapto
r_impl.h" |
24 #include "webrtc/modules/audio_coding/audio_network_adaptor/controller_manager.h
" | 23 #include "webrtc/modules/audio_coding/audio_network_adaptor/controller_manager.h
" |
25 #include "webrtc/modules/audio_coding/codecs/opus/opus_interface.h" | 24 #include "webrtc/modules/audio_coding/codecs/opus/opus_interface.h" |
26 #include "webrtc/system_wrappers/include/field_trial.h" | 25 #include "webrtc/system_wrappers/include/field_trial.h" |
27 | 26 |
28 namespace webrtc { | 27 namespace webrtc { |
29 | 28 |
(...skipping 156 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
186 std::unique_ptr<SmoothingFilter> bitrate_smoother) | 185 std::unique_ptr<SmoothingFilter> bitrate_smoother) |
187 : send_side_bwe_with_overhead_(webrtc::field_trial::IsEnabled( | 186 : send_side_bwe_with_overhead_(webrtc::field_trial::IsEnabled( |
188 "WebRTC-SendSideBwe-WithOverhead")), | 187 "WebRTC-SendSideBwe-WithOverhead")), |
189 packet_loss_rate_(0.0), | 188 packet_loss_rate_(0.0), |
190 inst_(nullptr), | 189 inst_(nullptr), |
191 packet_loss_fraction_smoother_(new PacketLossFractionSmoother( | 190 packet_loss_fraction_smoother_(new PacketLossFractionSmoother( |
192 config.clock)), | 191 config.clock)), |
193 audio_network_adaptor_creator_( | 192 audio_network_adaptor_creator_( |
194 audio_network_adaptor_creator | 193 audio_network_adaptor_creator |
195 ? std::move(audio_network_adaptor_creator) | 194 ? std::move(audio_network_adaptor_creator) |
196 : [this](const ProtoString& config_string, | 195 : [this](const std::string& config_string, |
197 RtcEventLog* event_log, | 196 RtcEventLog* event_log, |
198 const Clock* clock) { | 197 const Clock* clock) { |
199 return DefaultAudioNetworkAdaptorCreator(config_string, | 198 return DefaultAudioNetworkAdaptorCreator(config_string, |
200 event_log, clock); | 199 event_log, clock); |
201 }), | 200 }), |
202 bitrate_smoother_(bitrate_smoother | 201 bitrate_smoother_(bitrate_smoother |
203 ? std::move(bitrate_smoother) : std::unique_ptr<SmoothingFilter>( | 202 ? std::move(bitrate_smoother) : std::unique_ptr<SmoothingFilter>( |
204 // We choose 5sec as initial time constant due to empirical data. | 203 // We choose 5sec as initial time constant due to empirical data. |
205 new SmoothingFilterImpl(5000, config.clock))) { | 204 new SmoothingFilterImpl(5000, config.clock))) { |
206 RTC_CHECK(RecreateEncoderInstance(config)); | 205 RTC_CHECK(RecreateEncoderInstance(config)); |
(...skipping 335 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
542 if (config.uplink_packet_loss_fraction) | 541 if (config.uplink_packet_loss_fraction) |
543 SetProjectedPacketLossRate(*config.uplink_packet_loss_fraction); | 542 SetProjectedPacketLossRate(*config.uplink_packet_loss_fraction); |
544 if (config.enable_dtx) | 543 if (config.enable_dtx) |
545 SetDtx(*config.enable_dtx); | 544 SetDtx(*config.enable_dtx); |
546 if (config.num_channels) | 545 if (config.num_channels) |
547 SetNumChannelsToEncode(*config.num_channels); | 546 SetNumChannelsToEncode(*config.num_channels); |
548 } | 547 } |
549 | 548 |
550 std::unique_ptr<AudioNetworkAdaptor> | 549 std::unique_ptr<AudioNetworkAdaptor> |
551 AudioEncoderOpus::DefaultAudioNetworkAdaptorCreator( | 550 AudioEncoderOpus::DefaultAudioNetworkAdaptorCreator( |
552 const ProtoString& config_string, | 551 const std::string& config_string, |
553 RtcEventLog* event_log, | 552 RtcEventLog* event_log, |
554 const Clock* clock) const { | 553 const Clock* clock) const { |
555 AudioNetworkAdaptorImpl::Config config; | 554 AudioNetworkAdaptorImpl::Config config; |
556 config.clock = clock; | 555 config.clock = clock; |
557 config.event_log = event_log; | 556 config.event_log = event_log; |
558 return std::unique_ptr<AudioNetworkAdaptor>(new AudioNetworkAdaptorImpl( | 557 return std::unique_ptr<AudioNetworkAdaptor>(new AudioNetworkAdaptorImpl( |
559 config, | 558 config, |
560 ControllerManagerImpl::Create( | 559 ControllerManagerImpl::Create( |
561 config_string, NumChannels(), supported_frame_lengths_ms(), | 560 config_string, NumChannels(), supported_frame_lengths_ms(), |
562 kMinBitrateBps, num_channels_to_encode_, next_frame_length_ms_, | 561 kMinBitrateBps, num_channels_to_encode_, next_frame_length_ms_, |
563 GetTargetBitrate(), config_.fec_enabled, GetDtx(), clock))); | 562 GetTargetBitrate(), config_.fec_enabled, GetDtx(), clock))); |
564 } | 563 } |
565 | 564 |
566 void AudioEncoderOpus::MaybeUpdateUplinkBandwidth() { | 565 void AudioEncoderOpus::MaybeUpdateUplinkBandwidth() { |
567 if (audio_network_adaptor_) { | 566 if (audio_network_adaptor_) { |
568 int64_t now_ms = rtc::TimeMillis(); | 567 int64_t now_ms = rtc::TimeMillis(); |
569 if (!bitrate_smoother_last_update_time_ || | 568 if (!bitrate_smoother_last_update_time_ || |
570 now_ms - *bitrate_smoother_last_update_time_ >= | 569 now_ms - *bitrate_smoother_last_update_time_ >= |
571 config_.uplink_bandwidth_update_interval_ms) { | 570 config_.uplink_bandwidth_update_interval_ms) { |
572 rtc::Optional<float> smoothed_bitrate = bitrate_smoother_->GetAverage(); | 571 rtc::Optional<float> smoothed_bitrate = bitrate_smoother_->GetAverage(); |
573 if (smoothed_bitrate) | 572 if (smoothed_bitrate) |
574 audio_network_adaptor_->SetUplinkBandwidth(*smoothed_bitrate); | 573 audio_network_adaptor_->SetUplinkBandwidth(*smoothed_bitrate); |
575 bitrate_smoother_last_update_time_ = rtc::Optional<int64_t>(now_ms); | 574 bitrate_smoother_last_update_time_ = rtc::Optional<int64_t>(now_ms); |
576 } | 575 } |
577 } | 576 } |
578 } | 577 } |
579 | 578 |
580 } // namespace webrtc | 579 } // namespace webrtc |
OLD | NEW |