Ensure that the start bitrate can be set multiple times.

If the start bitrate is set twice, it will be set to the sum of the start
bitrates of the currently registered bitrate observers, or left unchanged
if the current estimate actually is greater than the sum.

BUG=3503
R=henrik.lundin@webrtc.org, pbos@webrtc.org

Review URL: https://webrtc-codereview.appspot.com/15839004

git-svn-id: http://webrtc.googlecode.com/svn/trunk@6491 4adac7df-926f-26a2-2b94-8c16560cd09d
diff --git a/webrtc/modules/bitrate_controller/bitrate_controller_impl.cc b/webrtc/modules/bitrate_controller/bitrate_controller_impl.cc
index 48f59b8..cff5dd1 100644
--- a/webrtc/modules/bitrate_controller/bitrate_controller_impl.cc
+++ b/webrtc/modules/bitrate_controller/bitrate_controller_impl.cc
@@ -139,6 +139,21 @@
     it->second->start_bitrate_ = start_bitrate;
     it->second->min_bitrate_ = min_bitrate;
     it->second->max_bitrate_ = max_bitrate;
+    // Set the send-side bandwidth to the max of the sum of start bitrates and
+    // the current estimate, so that if the user wants to immediately use more
+    // bandwidth, that can be enforced.
+    uint32_t sum_start_bitrate = 0;
+    BitrateObserverConfList::iterator it;
+    for (it = bitrate_observers_.begin(); it != bitrate_observers_.end();
+         ++it) {
+      sum_start_bitrate += it->second->start_bitrate_;
+    }
+    uint32_t current_estimate;
+    uint8_t loss;
+    uint32_t rtt;
+    bandwidth_estimation_.CurrentEstimate(&current_estimate, &loss, &rtt);
+    bandwidth_estimation_.SetSendBitrate(std::max(sum_start_bitrate,
+                                                  current_estimate));
   } else {
     // Add new settings.
     bitrate_observers_.push_back(BitrateObserverConfiguration(observer,
@@ -159,12 +174,10 @@
 }
 
 void BitrateControllerImpl::UpdateMinMaxBitrate() {
-  uint32_t sum_start_bitrate = 0;
   uint32_t sum_min_bitrate = 0;
   uint32_t sum_max_bitrate = 0;
   BitrateObserverConfList::iterator it;
   for (it = bitrate_observers_.begin(); it != bitrate_observers_.end(); ++it) {
-    sum_start_bitrate += it->second->start_bitrate_;
     sum_min_bitrate += it->second->min_bitrate_;
     sum_max_bitrate += it->second->max_bitrate_;
   }