diff --git a/modules/congestion_controller/goog_cc/acknowledged_bitrate_estimator.cc b/modules/congestion_controller/goog_cc/acknowledged_bitrate_estimator.cc index 0722b2218b..31a9dccc3b 100644 --- a/modules/congestion_controller/goog_cc/acknowledged_bitrate_estimator.cc +++ b/modules/congestion_controller/goog_cc/acknowledged_bitrate_estimator.cc @@ -15,6 +15,7 @@ #include "absl/memory/memory.h" #include "modules/rtp_rtcp/include/rtp_rtcp_defines.h" #include "rtc_base/numerics/safe_conversions.h" +#include "system_wrappers/include/field_trial.h" namespace webrtc { @@ -31,7 +32,9 @@ AcknowledgedBitrateEstimator::~AcknowledgedBitrateEstimator() {} AcknowledgedBitrateEstimator::AcknowledgedBitrateEstimator( std::unique_ptr bitrate_estimator) - : bitrate_estimator_(std::move(bitrate_estimator)) {} + : account_for_unacknowledged_traffic_( + field_trial::IsEnabled("WebRTC-Bwe-AccountForUnacked")), + bitrate_estimator_(std::move(bitrate_estimator)) {} void AcknowledgedBitrateEstimator::IncomingPacketFeedbackVector( const std::vector& packet_feedback_vector) { @@ -41,18 +44,25 @@ void AcknowledgedBitrateEstimator::IncomingPacketFeedbackVector( for (const auto& packet : packet_feedback_vector) { if (IsInSendTimeHistory(packet)) { MaybeExpectFastRateChange(packet.send_time_ms); - bitrate_estimator_->Update(packet.arrival_time_ms, - rtc::dchecked_cast(packet.payload_size)); + int acknowledged_estimate = rtc::dchecked_cast(packet.payload_size); + if (account_for_unacknowledged_traffic_) + acknowledged_estimate += packet.unacknowledged_data; + bitrate_estimator_->Update(packet.arrival_time_ms, acknowledged_estimate); } } } absl::optional AcknowledgedBitrateEstimator::bitrate_bps() const { auto estimated_bitrate = bitrate_estimator_->bitrate_bps(); - return estimated_bitrate - ? *estimated_bitrate + - allocated_bitrate_without_feedback_bps_.value_or(0) - : estimated_bitrate; + // If we account for unacknowledged traffic, we should not add the allocated + // bitrate for unallocated stream as we expect it to be included already. + if (account_for_unacknowledged_traffic_) { + return estimated_bitrate; + } else { + return estimated_bitrate + ? *estimated_bitrate + allocated_bitrate_without_feedback_bps_ + : estimated_bitrate; + } } void AcknowledgedBitrateEstimator::SetAlrEndedTimeMs( @@ -62,7 +72,7 @@ void AcknowledgedBitrateEstimator::SetAlrEndedTimeMs( void AcknowledgedBitrateEstimator::SetAllocatedBitrateWithoutFeedback( uint32_t bitrate_bps) { - allocated_bitrate_without_feedback_bps_.emplace(bitrate_bps); + allocated_bitrate_without_feedback_bps_ = bitrate_bps; } void AcknowledgedBitrateEstimator::MaybeExpectFastRateChange( diff --git a/modules/congestion_controller/goog_cc/acknowledged_bitrate_estimator.h b/modules/congestion_controller/goog_cc/acknowledged_bitrate_estimator.h index ccb9718b25..31e44102a4 100644 --- a/modules/congestion_controller/goog_cc/acknowledged_bitrate_estimator.h +++ b/modules/congestion_controller/goog_cc/acknowledged_bitrate_estimator.h @@ -37,9 +37,10 @@ class AcknowledgedBitrateEstimator { private: void MaybeExpectFastRateChange(int64_t packet_arrival_time_ms); + const bool account_for_unacknowledged_traffic_; absl::optional alr_ended_time_ms_; std::unique_ptr bitrate_estimator_; - absl::optional allocated_bitrate_without_feedback_bps_; + uint32_t allocated_bitrate_without_feedback_bps_ = 0; }; } // namespace webrtc diff --git a/modules/congestion_controller/goog_cc/goog_cc_network_control.cc b/modules/congestion_controller/goog_cc/goog_cc_network_control.cc index d8520ea9d2..efd78b4170 100644 --- a/modules/congestion_controller/goog_cc/goog_cc_network_control.cc +++ b/modules/congestion_controller/goog_cc/goog_cc_network_control.cc @@ -110,6 +110,7 @@ std::vector ReceivedPacketsFeedbackAsRtp( pf.payload_size = fb.sent_packet->size.bytes(); pf.pacing_info = fb.sent_packet->pacing_info; pf.send_time_ms = fb.sent_packet->send_time.ms(); + pf.unacknowledged_data = fb.sent_packet->prior_unacked_data.bytes(); } else { pf.send_time_ms = PacketFeedback::kNoSendTime; } diff --git a/test/scenario/scenario_unittest.cc b/test/scenario/scenario_unittest.cc index 305f8660cc..87647a4fdd 100644 --- a/test/scenario/scenario_unittest.cc +++ b/test/scenario/scenario_unittest.cc @@ -27,6 +27,10 @@ TEST(ScenarioTest, StartsAndStopsWithoutErrors) { s.CreateVideoStream(bob, {bob_net}, alice, {alice_net}, video_stream_config); AudioStreamConfig audio_stream_config; + audio_stream_config.encoder.min_rate = DataRate::kbps(6); + audio_stream_config.encoder.max_rate = DataRate::kbps(64); + audio_stream_config.encoder.allocate_bitrate = true; + audio_stream_config.stream.in_bandwidth_estimation = false; s.CreateAudioStream(alice, {alice_net}, bob, {bob_net}, audio_stream_config); s.CreateAudioStream(bob, {bob_net}, alice, {alice_net}, audio_stream_config);