Don't interrupt exponential probing when VideoStream bitrates are reconfigured.

Bug: chromium:834255, webrtc:8955
Change-Id: Iba316e940ddc2d0d5891e57c24b808c68e0bbcfe
Reviewed-on: https://webrtc-review.googlesource.com/70760
Reviewed-by: Erik Språng <sprang@webrtc.org>
Reviewed-by: Sebastian Jansson <srte@webrtc.org>
Commit-Queue: Philip Eliasson <philipel@webrtc.org>
Cr-Commit-Position: refs/heads/master@{#22943}
diff --git a/modules/congestion_controller/goog_cc/probe_controller.cc b/modules/congestion_controller/goog_cc/probe_controller.cc
index 66838d3..c05c094 100644
--- a/modules/congestion_controller/goog_cc/probe_controller.cc
+++ b/modules/congestion_controller/goog_cc/probe_controller.cc
@@ -137,7 +137,8 @@
     int64_t at_time_ms) {
   // TODO(philipel): Should |max_total_allocated_bitrate| be used as a limit for
   //                 ALR probing?
-  if (max_total_allocated_bitrate != max_total_allocated_bitrate_ &&
+  if (state_ == State::kProbingComplete &&
+      max_total_allocated_bitrate != max_total_allocated_bitrate_ &&
       estimated_bitrate_bps_ != 0 &&
       (max_bitrate_bps_ <= 0 || estimated_bitrate_bps_ < max_bitrate_bps_) &&
       estimated_bitrate_bps_ < max_total_allocated_bitrate) {
@@ -147,6 +148,12 @@
 
 void ProbeController::OnNetworkAvailability(NetworkAvailability msg) {
   network_available_ = msg.network_available;
+
+  if (!network_available_ && state_ == State::kWaitingForProbingResult) {
+    state_ = State::kProbingComplete;
+    min_bitrate_to_probe_further_bps_ = kExponentialProbingDisabled;
+  }
+
   if (network_available_ && state_ == State::kInit && start_bitrate_bps_ > 0)
     InitiateExponentialProbing(msg.at_time.ms());
 }
diff --git a/modules/congestion_controller/probe_controller.cc b/modules/congestion_controller/probe_controller.cc
index 6fbe01e..ea1f45c 100644
--- a/modules/congestion_controller/probe_controller.cc
+++ b/modules/congestion_controller/probe_controller.cc
@@ -130,7 +130,8 @@
   rtc::CritScope cs(&critsect_);
   // TODO(philipel): Should |max_total_allocated_bitrate| be used as a limit for
   //                 ALR probing?
-  if (max_total_allocated_bitrate != max_total_allocated_bitrate_ &&
+  if (state_ == State::kProbingComplete &&
+      max_total_allocated_bitrate != max_total_allocated_bitrate_ &&
       estimated_bitrate_bps_ != 0 &&
       (max_bitrate_bps_ <= 0 || estimated_bitrate_bps_ < max_bitrate_bps_) &&
       estimated_bitrate_bps_ < max_total_allocated_bitrate) {
@@ -143,6 +144,13 @@
 void ProbeController::OnNetworkStateChanged(NetworkState network_state) {
   rtc::CritScope cs(&critsect_);
   network_state_ = network_state;
+
+  if (network_state_ == kNetworkDown &&
+      state_ == State::kWaitingForProbingResult) {
+    state_ = State::kProbingComplete;
+    min_bitrate_to_probe_further_bps_ = kExponentialProbingDisabled;
+  }
+
   if (network_state_ == kNetworkUp && state_ == State::kInit)
     InitiateExponentialProbing();
 }
diff --git a/video/end_to_end_tests/probing_tests.cc b/video/end_to_end_tests/probing_tests.cc
index 777a346..e709505 100644
--- a/video/end_to_end_tests/probing_tests.cc
+++ b/video/end_to_end_tests/probing_tests.cc
@@ -216,6 +216,11 @@
       send_stream_ = send_stream;
     }
 
+    void OnRtpTransportControllerSendCreated(
+        RtpTransportControllerSend* transport_controller) override {
+      transport_controller_ = transport_controller;
+    }
+
     test::PacketTransport* CreateSendTransport(
         test::SingleThreadedTaskQueueForTesting* task_queue,
         Call* sender_call) override {
@@ -244,6 +249,12 @@
               config.link_capacity_kbps = 200;
               send_transport_->SetConfig(config);
 
+              // In order to speed up the test we can interrupt exponential
+              // probing by toggling the network availability. The alternative
+              // is to wait for it to time out (1000 ms).
+              transport_controller_->OnNetworkAvailability(false);
+              transport_controller_->OnNetworkAvailability(true);
+
               ++state_;
             }
             break;
@@ -279,6 +290,7 @@
     test::PacketTransport* send_transport_;
     VideoSendStream* send_stream_;
     VideoEncoderConfig* encoder_config_;
+    RtpTransportControllerSend* transport_controller_;
   };
 
   bool success = false;