Add probing to recover faster from large bitrate drops. A single probe at 85% of the original bitrate is sent when transitioning from underusing back to normal state. The actual sending of the probes is disabled by default, and enabled by the field trial string WebRTC-BweRapidRecoveryExperiment/Enabled/. Existing code that did probing after large drops in ALR have been restructured so that it also delays the probe until we are no longer overusing.

BUG=webrtc:8015

Review-Url: https://codereview.webrtc.org/2986563002
Cr-Commit-Position: refs/heads/master@{#19187}
diff --git a/webrtc/modules/congestion_controller/probe_controller_unittest.cc b/webrtc/modules/congestion_controller/probe_controller_unittest.cc
index 9fc0f55..e0a040f 100644
--- a/webrtc/modules/congestion_controller/probe_controller_unittest.cc
+++ b/webrtc/modules/congestion_controller/probe_controller_unittest.cc
@@ -33,6 +33,8 @@
 constexpr int kExponentialProbingTimeoutMs = 5000;
 
 constexpr int kAlrProbeInterval = 5000;
+constexpr int kAlrEndedTimeoutMs = 3000;
+constexpr int kBitrateDropTimeoutMs = 5000;
 
 }  // namespace
 
@@ -120,22 +122,71 @@
   probe_controller_->SetEstimatedBitrate(1800);
 }
 
-TEST_F(ProbeControllerTest, ProbeAfterEstimateDropInAlr) {
+TEST_F(ProbeControllerTest, RequestProbeInAlr) {
   EXPECT_CALL(pacer_, CreateProbeCluster(_)).Times(2);
   probe_controller_->SetBitrates(kMinBitrateBps, kStartBitrateBps,
                                  kMaxBitrateBps);
   probe_controller_->SetEstimatedBitrate(500);
   testing::Mock::VerifyAndClearExpectations(&pacer_);
-
-  // When bandwidth estimate drops the controller should send a probe at the
-  // previous bitrate.
-  EXPECT_CALL(pacer_, CreateProbeCluster(500)).Times(1);
+  EXPECT_CALL(pacer_, CreateProbeCluster(0.85 * 500)).Times(1);
   EXPECT_CALL(pacer_, GetApplicationLimitedRegionStartTime())
       .WillRepeatedly(
           Return(rtc::Optional<int64_t>(clock_.TimeInMilliseconds())));
   clock_.AdvanceTimeMilliseconds(kAlrProbeInterval + 1);
   probe_controller_->Process();
-  probe_controller_->SetEstimatedBitrate(50);
+  probe_controller_->SetEstimatedBitrate(250);
+  probe_controller_->RequestProbe();
+}
+
+TEST_F(ProbeControllerTest, RequestProbeWhenAlrEndedRecently) {
+  EXPECT_CALL(pacer_, CreateProbeCluster(_)).Times(2);
+  probe_controller_->SetBitrates(kMinBitrateBps, kStartBitrateBps,
+                                 kMaxBitrateBps);
+  probe_controller_->SetEstimatedBitrate(500);
+  testing::Mock::VerifyAndClearExpectations(&pacer_);
+  EXPECT_CALL(pacer_, CreateProbeCluster(0.85 * 500)).Times(1);
+  EXPECT_CALL(pacer_, GetApplicationLimitedRegionStartTime())
+      .WillRepeatedly(Return(rtc::Optional<int64_t>()));
+  clock_.AdvanceTimeMilliseconds(kAlrProbeInterval + 1);
+  probe_controller_->Process();
+  probe_controller_->SetEstimatedBitrate(250);
+  probe_controller_->SetAlrEndedTimeMs(clock_.TimeInMilliseconds());
+  clock_.AdvanceTimeMilliseconds(kAlrEndedTimeoutMs - 1);
+  probe_controller_->RequestProbe();
+}
+
+TEST_F(ProbeControllerTest, RequestProbeWhenAlrNotEndedRecently) {
+  EXPECT_CALL(pacer_, CreateProbeCluster(_)).Times(2);
+  probe_controller_->SetBitrates(kMinBitrateBps, kStartBitrateBps,
+                                 kMaxBitrateBps);
+  probe_controller_->SetEstimatedBitrate(500);
+  testing::Mock::VerifyAndClearExpectations(&pacer_);
+  EXPECT_CALL(pacer_, CreateProbeCluster(_)).Times(0);
+  EXPECT_CALL(pacer_, GetApplicationLimitedRegionStartTime())
+      .WillRepeatedly(Return(rtc::Optional<int64_t>()));
+  clock_.AdvanceTimeMilliseconds(kAlrProbeInterval + 1);
+  probe_controller_->Process();
+  probe_controller_->SetEstimatedBitrate(250);
+  probe_controller_->SetAlrEndedTimeMs(clock_.TimeInMilliseconds());
+  clock_.AdvanceTimeMilliseconds(kAlrEndedTimeoutMs + 1);
+  probe_controller_->RequestProbe();
+}
+
+TEST_F(ProbeControllerTest, RequestProbeWhenBweDropNotRecent) {
+  EXPECT_CALL(pacer_, CreateProbeCluster(_)).Times(2);
+  probe_controller_->SetBitrates(kMinBitrateBps, kStartBitrateBps,
+                                 kMaxBitrateBps);
+  probe_controller_->SetEstimatedBitrate(500);
+  testing::Mock::VerifyAndClearExpectations(&pacer_);
+  EXPECT_CALL(pacer_, CreateProbeCluster(_)).Times(0);
+  EXPECT_CALL(pacer_, GetApplicationLimitedRegionStartTime())
+      .WillRepeatedly(
+          Return(rtc::Optional<int64_t>(clock_.TimeInMilliseconds())));
+  clock_.AdvanceTimeMilliseconds(kAlrProbeInterval + 1);
+  probe_controller_->Process();
+  probe_controller_->SetEstimatedBitrate(250);
+  clock_.AdvanceTimeMilliseconds(kBitrateDropTimeoutMs + 1);
+  probe_controller_->RequestProbe();
 }
 
 TEST_F(ProbeControllerTest, PeriodicProbing) {