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 335 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
541 if (config.uplink_packet_loss_fraction) | 542 if (config.uplink_packet_loss_fraction) |
542 SetProjectedPacketLossRate(*config.uplink_packet_loss_fraction); | 543 SetProjectedPacketLossRate(*config.uplink_packet_loss_fraction); |
543 if (config.enable_dtx) | 544 if (config.enable_dtx) |
544 SetDtx(*config.enable_dtx); | 545 SetDtx(*config.enable_dtx); |
545 if (config.num_channels) | 546 if (config.num_channels) |
546 SetNumChannelsToEncode(*config.num_channels); | 547 SetNumChannelsToEncode(*config.num_channels); |
547 } | 548 } |
548 | 549 |
549 std::unique_ptr<AudioNetworkAdaptor> | 550 std::unique_ptr<AudioNetworkAdaptor> |
550 AudioEncoderOpus::DefaultAudioNetworkAdaptorCreator( | 551 AudioEncoderOpus::DefaultAudioNetworkAdaptorCreator( |
551 const std::string& config_string, | 552 const ProtoString& config_string, |
552 RtcEventLog* event_log, | 553 RtcEventLog* event_log, |
553 const Clock* clock) const { | 554 const Clock* clock) const { |
554 AudioNetworkAdaptorImpl::Config config; | 555 AudioNetworkAdaptorImpl::Config config; |
555 config.clock = clock; | 556 config.clock = clock; |
556 config.event_log = event_log; | 557 config.event_log = event_log; |
557 return std::unique_ptr<AudioNetworkAdaptor>(new AudioNetworkAdaptorImpl( | 558 return std::unique_ptr<AudioNetworkAdaptor>(new AudioNetworkAdaptorImpl( |
558 config, | 559 config, |
559 ControllerManagerImpl::Create( | 560 ControllerManagerImpl::Create( |
560 config_string, NumChannels(), supported_frame_lengths_ms(), | 561 config_string, NumChannels(), supported_frame_lengths_ms(), |
561 kMinBitrateBps, num_channels_to_encode_, next_frame_length_ms_, | 562 kMinBitrateBps, num_channels_to_encode_, next_frame_length_ms_, |
562 GetTargetBitrate(), config_.fec_enabled, GetDtx(), clock))); | 563 GetTargetBitrate(), config_.fec_enabled, GetDtx(), clock))); |
563 } | 564 } |
564 | 565 |
565 void AudioEncoderOpus::MaybeUpdateUplinkBandwidth() { | 566 void AudioEncoderOpus::MaybeUpdateUplinkBandwidth() { |
566 if (audio_network_adaptor_) { | 567 if (audio_network_adaptor_) { |
567 int64_t now_ms = rtc::TimeMillis(); | 568 int64_t now_ms = rtc::TimeMillis(); |
568 if (!bitrate_smoother_last_update_time_ || | 569 if (!bitrate_smoother_last_update_time_ || |
569 now_ms - *bitrate_smoother_last_update_time_ >= | 570 now_ms - *bitrate_smoother_last_update_time_ >= |
570 config_.uplink_bandwidth_update_interval_ms) { | 571 config_.uplink_bandwidth_update_interval_ms) { |
571 rtc::Optional<float> smoothed_bitrate = bitrate_smoother_->GetAverage(); | 572 rtc::Optional<float> smoothed_bitrate = bitrate_smoother_->GetAverage(); |
572 if (smoothed_bitrate) | 573 if (smoothed_bitrate) |
573 audio_network_adaptor_->SetUplinkBandwidth(*smoothed_bitrate); | 574 audio_network_adaptor_->SetUplinkBandwidth(*smoothed_bitrate); |
574 bitrate_smoother_last_update_time_ = rtc::Optional<int64_t>(now_ms); | 575 bitrate_smoother_last_update_time_ = rtc::Optional<int64_t>(now_ms); |
575 } | 576 } |
576 } | 577 } |
577 } | 578 } |
578 | 579 |
579 } // namespace webrtc | 580 } // namespace webrtc |
OLD | NEW |