This cl:
1. It moves calculation of the needed padding to VideoSendStream instead of ViEEncoder and only does it once per send Stream instead of every time the network estimate changes.
2. The maximum amount of padding sent was prior to this cl calculated and updated based on network estimate changes. However, it can only change based on encoder configuration changes and if send streams are added or removed. This cl change the VideoSendStream/VieEncoder to notify the BitrateAllocator of changes to the needed padding bitrate and for BitrateAllocator to notify Call of these changes.
3. Fixed an issue in the SendPacer where it could send a padding packet before sending a real packet. This caused the test EndToEndTest.RestartingSendStreamPreservesRtpStatesWithRtx to fail with these refactorings since the pacer suddenly could send a padding packet before the encoder had produced its first frame.
BUG=webrtc:5687
Review-Url: https://codereview.webrtc.org/1993113003
Cr-Commit-Position: refs/heads/master@{#13149}
diff --git a/webrtc/call/call.cc b/webrtc/call/call.cc
index ea01d91..93b638a 100644
--- a/webrtc/call/call.cc
+++ b/webrtc/call/call.cc
@@ -55,7 +55,8 @@
class Call : public webrtc::Call,
public PacketReceiver,
- public CongestionController::Observer {
+ public CongestionController::Observer,
+ public BitrateAllocator::LimitObserver {
public:
explicit Call(const Call::Config& config);
virtual ~Call();
@@ -102,6 +103,10 @@
void OnNetworkChanged(uint32_t bitrate_bps, uint8_t fraction_loss,
int64_t rtt_ms) override;
+ // Implements BitrateAllocator::LimitObserver.
+ void OnAllocationLimitsChanged(uint32_t min_send_bitrate_bps,
+ uint32_t max_padding_bitrate_bps) override;
+
private:
DeliveryStatus DeliverRtcp(MediaType media_type, const uint8_t* packet,
size_t length);
@@ -174,6 +179,7 @@
rtc::CriticalSection bitrate_crit_;
int64_t estimated_send_bitrate_sum_kbits_ GUARDED_BY(&bitrate_crit_);
int64_t pacer_bitrate_sum_kbits_ GUARDED_BY(&bitrate_crit_);
+ uint32_t min_allocated_send_bitrate_bps_ GUARDED_BY(&bitrate_crit_);
int64_t num_bitrate_updates_ GUARDED_BY(&bitrate_crit_);
std::map<std::string, rtc::NetworkRoute> network_routes_;
@@ -198,7 +204,7 @@
module_process_thread_(ProcessThread::Create("ModuleProcessThread")),
pacer_thread_(ProcessThread::Create("PacerThread")),
call_stats_(new CallStats(clock_)),
- bitrate_allocator_(new BitrateAllocator()),
+ bitrate_allocator_(new BitrateAllocator(this)),
config_(config),
audio_network_state_(kNetworkUp),
video_network_state_(kNetworkUp),
@@ -212,6 +218,7 @@
first_packet_sent_ms_(-1),
estimated_send_bitrate_sum_kbits_(0),
pacer_bitrate_sum_kbits_(0),
+ min_allocated_send_bitrate_bps_(0),
num_bitrate_updates_(0),
remb_(clock_),
congestion_controller_(new CongestionController(clock_, this, &remb_)),
@@ -677,38 +684,29 @@
void Call::OnNetworkChanged(uint32_t target_bitrate_bps, uint8_t fraction_loss,
int64_t rtt_ms) {
- uint32_t allocated_bitrate_bps = bitrate_allocator_->OnNetworkChanged(
- target_bitrate_bps, fraction_loss, rtt_ms);
+ bitrate_allocator_->OnNetworkChanged(target_bitrate_bps, fraction_loss,
+ rtt_ms);
- int pad_up_to_bitrate_bps = 0;
- {
- ReadLockScoped read_lock(*send_crit_);
- // No need to update as long as we're not sending.
- if (video_send_streams_.empty())
- return;
-
- for (VideoSendStream* stream : video_send_streams_)
- pad_up_to_bitrate_bps += stream->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);
{
rtc::CritScope lock(&bitrate_crit_);
// We only update these stats if we have send streams, and assume that
// OnNetworkChanged is called roughly with a fixed frequency.
estimated_send_bitrate_sum_kbits_ += target_bitrate_bps / 1000;
+ // Pacer bitrate might be higher than bitrate estimate if enforcing min
+ // bitrate.
+ uint32_t pacer_bitrate_bps =
+ std::max(target_bitrate_bps, min_allocated_send_bitrate_bps_);
pacer_bitrate_sum_kbits_ += pacer_bitrate_bps / 1000;
++num_bitrate_updates_;
}
+}
- // Make sure to not ask for more padding than the current BWE allows for.
- pad_up_to_bitrate_bps = std::min(static_cast<uint32_t>(pad_up_to_bitrate_bps),
- target_bitrate_bps);
- congestion_controller_->SetAllocatedSendBitrate(allocated_bitrate_bps,
- pad_up_to_bitrate_bps);
+void Call::OnAllocationLimitsChanged(uint32_t min_send_bitrate_bps,
+ uint32_t max_padding_bitrate_bps) {
+ congestion_controller_->SetAllocatedSendBitrateLimits(
+ min_send_bitrate_bps, max_padding_bitrate_bps);
+ rtc::CritScope lock(&bitrate_crit_);
+ min_allocated_send_bitrate_bps_ = min_send_bitrate_bps;
}
void Call::ConfigureSync(const std::string& sync_group) {