| 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 #include <utility> | 15 #include <utility> |
| 16 | 16 |
| 17 #include "webrtc/base/arraysize.h" | 17 #include "webrtc/base/arraysize.h" |
| 18 #include "webrtc/base/checks.h" | 18 #include "webrtc/base/checks.h" |
| 19 #include "webrtc/base/logging.h" | 19 #include "webrtc/base/logging.h" |
| 20 #include "webrtc/base/numerics/exp_filter.h" | 20 #include "webrtc/base/numerics/exp_filter.h" |
| 21 #include "webrtc/base/protobuf_utils.h" |
| 21 #include "webrtc/base/safe_conversions.h" | 22 #include "webrtc/base/safe_conversions.h" |
| 22 #include "webrtc/base/string_to_number.h" | 23 #include "webrtc/base/string_to_number.h" |
| 23 #include "webrtc/base/timeutils.h" | 24 #include "webrtc/base/timeutils.h" |
| 24 #include "webrtc/common_types.h" | 25 #include "webrtc/common_types.h" |
| 25 #include "webrtc/modules/audio_coding/audio_network_adaptor/audio_network_adapto
r_impl.h" | 26 #include "webrtc/modules/audio_coding/audio_network_adaptor/audio_network_adapto
r_impl.h" |
| 26 #include "webrtc/modules/audio_coding/audio_network_adaptor/controller_manager.h
" | 27 #include "webrtc/modules/audio_coding/audio_network_adaptor/controller_manager.h
" |
| 27 #include "webrtc/modules/audio_coding/codecs/opus/opus_interface.h" | 28 #include "webrtc/modules/audio_coding/codecs/opus/opus_interface.h" |
| 28 #include "webrtc/system_wrappers/include/field_trial.h" | 29 #include "webrtc/system_wrappers/include/field_trial.h" |
| 29 | 30 |
| 30 namespace webrtc { | 31 namespace webrtc { |
| (...skipping 332 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 363 std::unique_ptr<SmoothingFilter> bitrate_smoother) | 364 std::unique_ptr<SmoothingFilter> bitrate_smoother) |
| 364 : send_side_bwe_with_overhead_(webrtc::field_trial::IsEnabled( | 365 : send_side_bwe_with_overhead_(webrtc::field_trial::IsEnabled( |
| 365 "WebRTC-SendSideBwe-WithOverhead")), | 366 "WebRTC-SendSideBwe-WithOverhead")), |
| 366 packet_loss_rate_(0.0), | 367 packet_loss_rate_(0.0), |
| 367 inst_(nullptr), | 368 inst_(nullptr), |
| 368 packet_loss_fraction_smoother_(new PacketLossFractionSmoother( | 369 packet_loss_fraction_smoother_(new PacketLossFractionSmoother( |
| 369 config.clock)), | 370 config.clock)), |
| 370 audio_network_adaptor_creator_( | 371 audio_network_adaptor_creator_( |
| 371 audio_network_adaptor_creator | 372 audio_network_adaptor_creator |
| 372 ? std::move(audio_network_adaptor_creator) | 373 ? std::move(audio_network_adaptor_creator) |
| 373 : [this](const std::string& config_string, | 374 : [this](const ProtoString& config_string, |
| 374 RtcEventLog* event_log, | 375 RtcEventLog* event_log, |
| 375 const Clock* clock) { | 376 const Clock* clock) { |
| 376 return DefaultAudioNetworkAdaptorCreator(config_string, | 377 return DefaultAudioNetworkAdaptorCreator(config_string, |
| 377 event_log, clock); | 378 event_log, clock); |
| 378 }), | 379 }), |
| 379 bitrate_smoother_(bitrate_smoother | 380 bitrate_smoother_(bitrate_smoother |
| 380 ? std::move(bitrate_smoother) : std::unique_ptr<SmoothingFilter>( | 381 ? std::move(bitrate_smoother) : std::unique_ptr<SmoothingFilter>( |
| 381 // We choose 5sec as initial time constant due to empirical data. | 382 // We choose 5sec as initial time constant due to empirical data. |
| 382 new SmoothingFilterImpl(5000, config.clock))) { | 383 new SmoothingFilterImpl(5000, config.clock))) { |
| 383 RTC_CHECK(RecreateEncoderInstance(config)); | 384 RTC_CHECK(RecreateEncoderInstance(config)); |
| (...skipping 330 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 714 if (config.uplink_packet_loss_fraction) | 715 if (config.uplink_packet_loss_fraction) |
| 715 SetProjectedPacketLossRate(*config.uplink_packet_loss_fraction); | 716 SetProjectedPacketLossRate(*config.uplink_packet_loss_fraction); |
| 716 if (config.enable_dtx) | 717 if (config.enable_dtx) |
| 717 SetDtx(*config.enable_dtx); | 718 SetDtx(*config.enable_dtx); |
| 718 if (config.num_channels) | 719 if (config.num_channels) |
| 719 SetNumChannelsToEncode(*config.num_channels); | 720 SetNumChannelsToEncode(*config.num_channels); |
| 720 } | 721 } |
| 721 | 722 |
| 722 std::unique_ptr<AudioNetworkAdaptor> | 723 std::unique_ptr<AudioNetworkAdaptor> |
| 723 AudioEncoderOpus::DefaultAudioNetworkAdaptorCreator( | 724 AudioEncoderOpus::DefaultAudioNetworkAdaptorCreator( |
| 724 const std::string& config_string, | 725 const ProtoString& config_string, |
| 725 RtcEventLog* event_log, | 726 RtcEventLog* event_log, |
| 726 const Clock* clock) const { | 727 const Clock* clock) const { |
| 727 AudioNetworkAdaptorImpl::Config config; | 728 AudioNetworkAdaptorImpl::Config config; |
| 728 config.clock = clock; | 729 config.clock = clock; |
| 729 config.event_log = event_log; | 730 config.event_log = event_log; |
| 730 return std::unique_ptr<AudioNetworkAdaptor>(new AudioNetworkAdaptorImpl( | 731 return std::unique_ptr<AudioNetworkAdaptor>(new AudioNetworkAdaptorImpl( |
| 731 config, | 732 config, |
| 732 ControllerManagerImpl::Create( | 733 ControllerManagerImpl::Create( |
| 733 config_string, NumChannels(), supported_frame_lengths_ms(), | 734 config_string, NumChannels(), supported_frame_lengths_ms(), |
| 734 kOpusMinBitrateBps, num_channels_to_encode_, next_frame_length_ms_, | 735 kOpusMinBitrateBps, num_channels_to_encode_, next_frame_length_ms_, |
| 735 GetTargetBitrate(), config_.fec_enabled, GetDtx(), clock))); | 736 GetTargetBitrate(), config_.fec_enabled, GetDtx(), clock))); |
| 736 } | 737 } |
| 737 | 738 |
| 738 void AudioEncoderOpus::MaybeUpdateUplinkBandwidth() { | 739 void AudioEncoderOpus::MaybeUpdateUplinkBandwidth() { |
| 739 if (audio_network_adaptor_) { | 740 if (audio_network_adaptor_) { |
| 740 int64_t now_ms = rtc::TimeMillis(); | 741 int64_t now_ms = rtc::TimeMillis(); |
| 741 if (!bitrate_smoother_last_update_time_ || | 742 if (!bitrate_smoother_last_update_time_ || |
| 742 now_ms - *bitrate_smoother_last_update_time_ >= | 743 now_ms - *bitrate_smoother_last_update_time_ >= |
| 743 config_.uplink_bandwidth_update_interval_ms) { | 744 config_.uplink_bandwidth_update_interval_ms) { |
| 744 rtc::Optional<float> smoothed_bitrate = bitrate_smoother_->GetAverage(); | 745 rtc::Optional<float> smoothed_bitrate = bitrate_smoother_->GetAverage(); |
| 745 if (smoothed_bitrate) | 746 if (smoothed_bitrate) |
| 746 audio_network_adaptor_->SetUplinkBandwidth(*smoothed_bitrate); | 747 audio_network_adaptor_->SetUplinkBandwidth(*smoothed_bitrate); |
| 747 bitrate_smoother_last_update_time_ = rtc::Optional<int64_t>(now_ms); | 748 bitrate_smoother_last_update_time_ = rtc::Optional<int64_t>(now_ms); |
| 748 } | 749 } |
| 749 } | 750 } |
| 750 } | 751 } |
| 751 | 752 |
| 752 } // namespace webrtc | 753 } // namespace webrtc |
| OLD | NEW |