diff --git a/webrtc/media/engine/webrtcvoiceengine.cc b/webrtc/media/engine/webrtcvoiceengine.cc index df93ac28f4..b9a725b0a0 100644 --- a/webrtc/media/engine/webrtcvoiceengine.cc +++ b/webrtc/media/engine/webrtcvoiceengine.cc @@ -1226,6 +1226,8 @@ class WebRtcVoiceMediaChannel::WebRtcAudioSendStream : voe_audio_transport_(voe_audio_transport), call_(call), config_(send_transport), + send_side_bwe_with_overhead_(webrtc::field_trial::FindFullName( + "WebRTC-SendSideBwe-WithOverhead") == "Enabled"), max_send_bitrate_bps_(max_send_bitrate_bps), rtp_parameters_(CreateRtpParametersWithOneEncoding()) { RTC_DCHECK_GE(ch, 0); @@ -1458,8 +1460,7 @@ class WebRtcVoiceMediaChannel::WebRtcAudioSendStream config_.max_bitrate_bps = kOpusBitrateFbBps; // TODO(mflodman): Keep testing this and set proper values. // Note: This is an early experiment currently only supported by Opus. - if (webrtc::field_trial::FindFullName( - "WebRTC-SendSideBwe-WithOverhead") == "Enabled") { + if (send_side_bwe_with_overhead_) { auto packet_sizes_ms = WebRtcVoiceCodecs::GetPacketSizesMs( config_.send_codec_spec.codec_inst); if (!packet_sizes_ms.empty()) { @@ -1500,6 +1501,7 @@ class WebRtcVoiceMediaChannel::WebRtcAudioSendStream webrtc::AudioTransport* const voe_audio_transport_ = nullptr; webrtc::Call* call_ = nullptr; webrtc::AudioSendStream::Config config_; + const bool send_side_bwe_with_overhead_; // The stream is owned by WebRtcAudioSendStream and may be reallocated if // configuration changes. webrtc::AudioSendStream* stream_ = nullptr; diff --git a/webrtc/modules/audio_coding/codecs/opus/audio_encoder_opus.cc b/webrtc/modules/audio_coding/codecs/opus/audio_encoder_opus.cc index 8e0254fe25..bd0afc6fa8 100644 --- a/webrtc/modules/audio_coding/codecs/opus/audio_encoder_opus.cc +++ b/webrtc/modules/audio_coding/codecs/opus/audio_encoder_opus.cc @@ -174,7 +174,9 @@ AudioEncoderOpus::AudioEncoderOpus( const Config& config, AudioNetworkAdaptorCreator&& audio_network_adaptor_creator, std::unique_ptr bitrate_smoother) - : packet_loss_rate_(0.0), + : send_side_bwe_with_overhead_(webrtc::field_trial::FindFullName( + "WebRTC-SendSideBwe-WithOverhead") == "Enabled"), + packet_loss_rate_(0.0), inst_(nullptr), packet_loss_fraction_smoother_(new PacketLossFractionSmoother( config.clock)), @@ -314,8 +316,7 @@ void AudioEncoderOpus::OnReceivedUplinkBandwidth( bitrate_smoother_->AddSample(target_audio_bitrate_bps); ApplyAudioNetworkAdaptor(); - } else if (webrtc::field_trial::FindFullName( - "WebRTC-SendSideBwe-WithOverhead") == "Enabled") { + } else if (send_side_bwe_with_overhead_) { if (!overhead_bytes_per_packet_) { LOG(LS_INFO) << "AudioEncoderOpus: Overhead unknown, target audio bitrate " diff --git a/webrtc/modules/audio_coding/codecs/opus/audio_encoder_opus.h b/webrtc/modules/audio_coding/codecs/opus/audio_encoder_opus.h index 051a60765a..3d0483b9ca 100644 --- a/webrtc/modules/audio_coding/codecs/opus/audio_encoder_opus.h +++ b/webrtc/modules/audio_coding/codecs/opus/audio_encoder_opus.h @@ -161,6 +161,7 @@ class AudioEncoderOpus final : public AudioEncoder { void MaybeUpdateUplinkBandwidth(); Config config_; + const bool send_side_bwe_with_overhead_; float packet_loss_rate_; std::vector input_buffer_; OpusEncInst* inst_; diff --git a/webrtc/modules/congestion_controller/transport_feedback_adapter.cc b/webrtc/modules/congestion_controller/transport_feedback_adapter.cc index b9440ac959..87fab26c8a 100644 --- a/webrtc/modules/congestion_controller/transport_feedback_adapter.cc +++ b/webrtc/modules/congestion_controller/transport_feedback_adapter.cc @@ -43,7 +43,9 @@ class PacketInfoComparator { TransportFeedbackAdapter::TransportFeedbackAdapter( Clock* clock, BitrateController* bitrate_controller) - : transport_overhead_bytes_per_packet_(0), + : send_side_bwe_with_overhead_(webrtc::field_trial::FindFullName( + "WebRTC-SendSideBwe-WithOverhead") == "Enabled"), + transport_overhead_bytes_per_packet_(0), send_time_history_(clock, kSendTimeHistoryWindowMs), clock_(clock), current_offset_ms_(kNoTimestamp), @@ -61,8 +63,7 @@ void TransportFeedbackAdapter::AddPacket(uint16_t sequence_number, size_t length, int probe_cluster_id) { rtc::CritScope cs(&lock_); - if (webrtc::field_trial::FindFullName("WebRTC-SendSideBwe-WithOverhead") == - "Enabled") { + if (send_side_bwe_with_overhead_) { length += transport_overhead_bytes_per_packet_; } send_time_history_.AddAndRemoveOld(sequence_number, length, probe_cluster_id); diff --git a/webrtc/modules/congestion_controller/transport_feedback_adapter.h b/webrtc/modules/congestion_controller/transport_feedback_adapter.h index 5ff48aaf97..632f125aa6 100644 --- a/webrtc/modules/congestion_controller/transport_feedback_adapter.h +++ b/webrtc/modules/congestion_controller/transport_feedback_adapter.h @@ -58,6 +58,7 @@ class TransportFeedbackAdapter : public TransportFeedbackObserver, std::vector GetPacketFeedbackVector( const rtcp::TransportFeedback& feedback); + const bool send_side_bwe_with_overhead_; rtc::CriticalSection lock_; rtc::CriticalSection bwe_lock_; int transport_overhead_bytes_per_packet_ GUARDED_BY(&lock_); diff --git a/webrtc/video/video_send_stream.cc b/webrtc/video/video_send_stream.cc index 9189b98e5a..bb67114ad0 100644 --- a/webrtc/video/video_send_stream.cc +++ b/webrtc/video/video_send_stream.cc @@ -292,9 +292,6 @@ int CalculateMaxPadBitrateBps(std::vector streams, uint32_t CalculateOverheadRateBps(int packets_per_second, size_t overhead_bytes_per_packet, uint32_t max_overhead_bps) { - if (webrtc::field_trial::FindFullName("WebRTC-SendSideBwe-WithOverhead") != - "Enabled") - return 0; uint32_t overhead_bps = static_cast(8 * overhead_bytes_per_packet * packets_per_second); return std::min(overhead_bps, max_overhead_bps); @@ -398,6 +395,8 @@ class VideoSendStreamImpl : public webrtc::BitrateAllocatorObserver, void SignalEncoderTimedOut(); void SignalEncoderActive(); + const bool send_side_bwe_with_overhead_; + SendStatisticsProxy* const stats_proxy_; const VideoSendStream::Config* const config_; std::map suspended_ssrcs_; @@ -758,7 +757,9 @@ VideoSendStreamImpl::VideoSendStreamImpl( const VideoSendStream::Config* config, int initial_encoder_max_bitrate, std::map suspended_ssrcs) - : stats_proxy_(stats_proxy), + : send_side_bwe_with_overhead_(webrtc::field_trial::FindFullName( + "WebRTC-SendSideBwe-WithOverhead") == "Enabled"), + stats_proxy_(stats_proxy), config_(config), suspended_ssrcs_(std::move(suspended_ssrcs)), module_process_thread_(nullptr), @@ -1226,14 +1227,15 @@ uint32_t VideoSendStreamImpl::OnBitrateUpdated(uint32_t bitrate_bps, // Substract overhead from bitrate. rtc::CritScope lock(&overhead_bytes_per_packet_crit_); - uint32_t payload_bitrate_bps = - bitrate_bps - - CalculateOverheadRateBps( - CalculatePacketRate(bitrate_bps, - config_->rtp.max_packet_size + - transport_overhead_bytes_per_packet_), - overhead_bytes_per_packet_ + transport_overhead_bytes_per_packet_, - bitrate_bps); + uint32_t payload_bitrate_bps = bitrate_bps; + if (send_side_bwe_with_overhead_) { + payload_bitrate_bps -= CalculateOverheadRateBps( + CalculatePacketRate(bitrate_bps, + config_->rtp.max_packet_size + + transport_overhead_bytes_per_packet_), + overhead_bytes_per_packet_ + transport_overhead_bytes_per_packet_, + bitrate_bps); + } // Get the encoder target rate. It is the estimated network rate - // protection overhead. @@ -1241,13 +1243,17 @@ uint32_t VideoSendStreamImpl::OnBitrateUpdated(uint32_t bitrate_bps, payload_bitrate_bps, stats_proxy_->GetSendFrameRate(), fraction_loss, rtt); - uint32_t encoder_overhead_rate_bps = CalculateOverheadRateBps( - CalculatePacketRate(encoder_target_rate_bps_, - config_->rtp.max_packet_size + - transport_overhead_bytes_per_packet_ - - overhead_bytes_per_packet_), - overhead_bytes_per_packet_ + transport_overhead_bytes_per_packet_, - bitrate_bps - encoder_target_rate_bps_); + uint32_t encoder_overhead_rate_bps = + send_side_bwe_with_overhead_ + ? CalculateOverheadRateBps( + CalculatePacketRate(encoder_target_rate_bps_, + config_->rtp.max_packet_size + + transport_overhead_bytes_per_packet_ - + overhead_bytes_per_packet_), + overhead_bytes_per_packet_ + + transport_overhead_bytes_per_packet_, + bitrate_bps - encoder_target_rate_bps_) + : 0; // When the field trial "WebRTC-SendSideBwe-WithOverhead" is enabled // protection_bitrate includes overhead.