diff --git a/webrtc/call/congestion_controller.cc b/webrtc/call/congestion_controller.cc index 52704154bb..27185c162d 100644 --- a/webrtc/call/congestion_controller.cc +++ b/webrtc/call/congestion_controller.cc @@ -282,16 +282,22 @@ void CongestionController::SignalNetworkState(NetworkState state) { void CongestionController::OnNetworkChanged(uint32_t target_bitrate_bps, uint8_t fraction_loss, int64_t rtt) { - bitrate_allocator_->OnNetworkChanged(target_bitrate_bps, fraction_loss, rtt); + uint32_t allocated_bitrate_bps = bitrate_allocator_->OnNetworkChanged( + target_bitrate_bps, fraction_loss, rtt); int pad_up_to_bitrate_bps = 0; { rtc::CritScope lock(&encoder_crit_); for (const auto& encoder : encoders_) pad_up_to_bitrate_bps += encoder->GetPaddingNeededBps(); } + // Allocated bitrate might be higher than bitrate estimate if enforcing min + // bitrate, or lower if estimate is higher than the sum of max bitrates, so + // set the pacer bitrate to the maximum of the two. + uint32_t pacer_bitrate_bps = + std::max(target_bitrate_bps, allocated_bitrate_bps); pacer_->UpdateBitrate( - target_bitrate_bps / 1000, - PacedSender::kDefaultPaceMultiplier * target_bitrate_bps / 1000, + pacer_bitrate_bps / 1000, + PacedSender::kDefaultPaceMultiplier * pacer_bitrate_bps / 1000, pad_up_to_bitrate_bps / 1000); } diff --git a/webrtc/modules/bitrate_controller/bitrate_allocator.cc b/webrtc/modules/bitrate_controller/bitrate_allocator.cc index 0aec528cde..dc421bb69d 100644 --- a/webrtc/modules/bitrate_controller/bitrate_allocator.cc +++ b/webrtc/modules/bitrate_controller/bitrate_allocator.cc @@ -26,23 +26,26 @@ const int kDefaultBitrateBps = 300000; BitrateAllocator::BitrateAllocator() : crit_sect_(CriticalSectionWrapper::CreateCriticalSection()), bitrate_observers_(), + bitrate_observers_modified_(false), enforce_min_bitrate_(true), last_bitrate_bps_(kDefaultBitrateBps), last_fraction_loss_(0), - last_rtt_(0) { -} + last_rtt_(0) {} - -void BitrateAllocator::OnNetworkChanged(uint32_t bitrate, - uint8_t fraction_loss, - int64_t rtt) { +uint32_t BitrateAllocator::OnNetworkChanged(uint32_t bitrate, + uint8_t fraction_loss, + int64_t rtt) { CriticalSectionScoped lock(crit_sect_.get()); last_bitrate_bps_ = bitrate; last_fraction_loss_ = fraction_loss; last_rtt_ = rtt; + uint32_t allocated_bitrate_bps = 0; ObserverBitrateMap allocation = AllocateBitrates(); - for (const auto& kv : allocation) + for (const auto& kv : allocation) { kv.first->OnNetworkChanged(kv.second, last_fraction_loss_, last_rtt_); + allocated_bitrate_bps += kv.second; + } + return allocated_bitrate_bps; } BitrateAllocator::ObserverBitrateMap BitrateAllocator::AllocateBitrates() { diff --git a/webrtc/modules/bitrate_controller/include/bitrate_allocator.h b/webrtc/modules/bitrate_controller/include/bitrate_allocator.h index 34b9ed5328..4ee27f36d3 100644 --- a/webrtc/modules/bitrate_controller/include/bitrate_allocator.h +++ b/webrtc/modules/bitrate_controller/include/bitrate_allocator.h @@ -31,9 +31,12 @@ class BitrateAllocator { public: BitrateAllocator(); - void OnNetworkChanged(uint32_t target_bitrate, - uint8_t fraction_loss, - int64_t rtt); + // Allocate target_bitrate across the registered BitrateObservers. + // Returns actual bitrate allocated (might be higher than target_bitrate if + // for instance EnforceMinBitrate() is enabled. + uint32_t OnNetworkChanged(uint32_t target_bitrate, + uint8_t fraction_loss, + int64_t rtt); // Set the start and max send bitrate used by the bandwidth management. //