Reinstate killswitch for WebRTC-Bwe-ReceiverLimitCapsOnly.

Bug: webrtc:12306
Change-Id: Idd643c3152252732562553f207d0a6335773e98a
Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/221043
Reviewed-by: Åsa Persson <asapersson@webrtc.org>
Commit-Queue: Christoffer Rodbro <crodbro@webrtc.org>
Cr-Commit-Position: refs/heads/master@{#34211}
diff --git a/modules/congestion_controller/goog_cc/goog_cc_network_control_unittest.cc b/modules/congestion_controller/goog_cc/goog_cc_network_control_unittest.cc
index 37089bc..484b568 100644
--- a/modules/congestion_controller/goog_cc/goog_cc_network_control_unittest.cc
+++ b/modules/congestion_controller/goog_cc/goog_cc_network_control_unittest.cc
@@ -124,6 +124,35 @@
   truth->PrintRow();
   EXPECT_NEAR(client->target_rate().kbps(), 90, 25);
 }
+
+DataRate RunRembDipScenario(std::string test_name) {
+  Scenario s(test_name);
+  NetworkSimulationConfig net_conf;
+  net_conf.bandwidth = DataRate::KilobitsPerSec(2000);
+  net_conf.delay = TimeDelta::Millis(50);
+  auto* client = s.CreateClient("send", [&](CallClientConfig* c) {
+    c->transport.rates.start_rate = DataRate::KilobitsPerSec(1000);
+  });
+  auto send_net = {s.CreateSimulationNode(net_conf)};
+  auto ret_net = {s.CreateSimulationNode(net_conf)};
+  auto* route = s.CreateRoutes(
+      client, send_net, s.CreateClient("return", CallClientConfig()), ret_net);
+  s.CreateVideoStream(route->forward(), VideoStreamConfig());
+
+  s.RunFor(TimeDelta::Seconds(10));
+  EXPECT_GT(client->send_bandwidth().kbps(), 1500);
+
+  DataRate RembLimit = DataRate::KilobitsPerSec(250);
+  client->SetRemoteBitrate(RembLimit);
+  s.RunFor(TimeDelta::Seconds(1));
+  EXPECT_EQ(client->send_bandwidth(), RembLimit);
+
+  DataRate RembLimitLifted = DataRate::KilobitsPerSec(10000);
+  client->SetRemoteBitrate(RembLimitLifted);
+  s.RunFor(TimeDelta::Seconds(10));
+
+  return client->send_bandwidth();
+}
 }  // namespace
 
 class GoogCcNetworkControllerTest : public ::testing::Test {
@@ -851,31 +880,16 @@
 }
 
 TEST(GoogCcScenario, RampupOnRembCapLifted) {
-  Scenario s("googcc_unit/rampup_ramb_cap_lifted");
-  NetworkSimulationConfig net_conf;
-  net_conf.bandwidth = DataRate::KilobitsPerSec(2000);
-  net_conf.delay = TimeDelta::Millis(50);
-  auto* client = s.CreateClient("send", [&](CallClientConfig* c) {
-    c->transport.rates.start_rate = DataRate::KilobitsPerSec(1000);
-  });
-  auto send_net = {s.CreateSimulationNode(net_conf)};
-  auto ret_net = {s.CreateSimulationNode(net_conf)};
-  auto* route = s.CreateRoutes(
-      client, send_net, s.CreateClient("return", CallClientConfig()), ret_net);
-  s.CreateVideoStream(route->forward(), VideoStreamConfig());
+  DataRate final_estimate =
+      RunRembDipScenario("googcc_unit/rampup_ramb_cap_lifted");
+  EXPECT_GT(final_estimate.kbps(), 1500);
+}
 
-  s.RunFor(TimeDelta::Seconds(10));
-  EXPECT_GT(client->send_bandwidth().kbps(), 1500);
-
-  DataRate RembLimit = DataRate::KilobitsPerSec(250);
-  client->SetRemoteBitrate(RembLimit);
-  s.RunFor(TimeDelta::Seconds(1));
-  EXPECT_EQ(client->send_bandwidth(), RembLimit);
-
-  DataRate RembLimitLifted = DataRate::KilobitsPerSec(10000);
-  client->SetRemoteBitrate(RembLimitLifted);
-  s.RunFor(TimeDelta::Seconds(10));
-  EXPECT_GT(client->send_bandwidth().kbps(), 1500);
+TEST(GoogCcScenario, SlowRampupOnRembCapLiftedWithKillSwitch) {
+  ScopedFieldTrials trial("WebRTC-Bwe-ReceiverLimitCapsOnly/Disabled/");
+  DataRate final_estimate =
+      RunRembDipScenario("googcc_unit/slow_rampup_remb_cap_lifted_killswitch");
+  EXPECT_LT(final_estimate.kbps(), 1000);
 }
 
 }  // namespace test
diff --git a/modules/congestion_controller/goog_cc/send_side_bandwidth_estimation.cc b/modules/congestion_controller/goog_cc/send_side_bandwidth_estimation.cc
index 143e7e4..a4ee99d 100644
--- a/modules/congestion_controller/goog_cc/send_side_bandwidth_estimation.cc
+++ b/modules/congestion_controller/goog_cc/send_side_bandwidth_estimation.cc
@@ -226,7 +226,8 @@
       low_loss_threshold_(kDefaultLowLossThreshold),
       high_loss_threshold_(kDefaultHighLossThreshold),
       bitrate_threshold_(kDefaultBitrateThreshold),
-      loss_based_bandwidth_estimation_(key_value_config) {
+      loss_based_bandwidth_estimation_(key_value_config),
+      disable_receiver_limit_caps_only_("Disabled") {
   RTC_DCHECK(event_log);
   if (BweLossExperimentIsEnabled()) {
     uint32_t bitrate_threshold_kbps;
@@ -239,6 +240,8 @@
       bitrate_threshold_ = DataRate::KilobitsPerSec(bitrate_threshold_kbps);
     }
   }
+  ParseFieldTrial({&disable_receiver_limit_caps_only_},
+                  key_value_config->Lookup("WebRTC-Bwe-ReceiverLimitCapsOnly"));
 }
 
 SendSideBandwidthEstimation::~SendSideBandwidthEstimation() {}
@@ -307,7 +310,9 @@
 }
 
 DataRate SendSideBandwidthEstimation::target_rate() const {
-  DataRate target = std::min(current_target_, receiver_limit_);
+  DataRate target = current_target_;
+  if (!disable_receiver_limit_caps_only_)
+    target = std::min(target, receiver_limit_);
   return std::max(min_bitrate_configured_, target);
 }
 
@@ -579,7 +584,10 @@
 }
 
 DataRate SendSideBandwidthEstimation::GetUpperLimit() const {
-  return std::min(delay_based_limit_, max_bitrate_configured_);
+  DataRate upper_limit = delay_based_limit_;
+  if (disable_receiver_limit_caps_only_)
+    upper_limit = std::min(upper_limit, receiver_limit_);
+  return std::min(upper_limit, max_bitrate_configured_);
 }
 
 void SendSideBandwidthEstimation::MaybeLogLowBitrateWarning(DataRate bitrate,
diff --git a/modules/congestion_controller/goog_cc/send_side_bandwidth_estimation.h b/modules/congestion_controller/goog_cc/send_side_bandwidth_estimation.h
index 05bf10d..8c1e1d0 100644
--- a/modules/congestion_controller/goog_cc/send_side_bandwidth_estimation.h
+++ b/modules/congestion_controller/goog_cc/send_side_bandwidth_estimation.h
@@ -190,6 +190,7 @@
   float high_loss_threshold_;
   DataRate bitrate_threshold_;
   LossBasedBandwidthEstimation loss_based_bandwidth_estimation_;
+  FieldTrialFlag disable_receiver_limit_caps_only_;
 };
 }  // namespace webrtc
 #endif  // MODULES_CONGESTION_CONTROLLER_GOOG_CC_SEND_SIDE_BANDWIDTH_ESTIMATION_H_