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