Break out allocation from BitrateController into a BitrateAllocator.

This also refactors some of the padding and allocation code in ViEEncoder, and
makes ChannelGroup a simple forwarder from BitrateController to
BitrateAllocator.

This CL is part of a bigger picture, see https://review.webrtc.org/35319004/ for
details.

BUG=4323
R=mflodman@webrtc.org, pbos@webrtc.org, sprang@webrtc.org

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

Cr-Commit-Position: refs/heads/master@{#8595}
git-svn-id: http://webrtc.googlecode.com/svn/trunk@8595 4adac7df-926f-26a2-2b94-8c16560cd09d
diff --git a/webrtc/modules/bitrate_controller/include/bitrate_controller.h b/webrtc/modules/bitrate_controller/include/bitrate_controller.h
index aea822b..c12dbeb 100644
--- a/webrtc/modules/bitrate_controller/include/bitrate_controller.h
+++ b/webrtc/modules/bitrate_controller/include/bitrate_controller.h
@@ -15,67 +15,50 @@
 #ifndef WEBRTC_MODULES_BITRATE_CONTROLLER_INCLUDE_BITRATE_CONTROLLER_H_
 #define WEBRTC_MODULES_BITRATE_CONTROLLER_INCLUDE_BITRATE_CONTROLLER_H_
 
+#include <map>
+
 #include "webrtc/modules/interface/module.h"
 #include "webrtc/modules/rtp_rtcp/interface/rtp_rtcp_defines.h"
 
 namespace webrtc {
 
+class CriticalSectionWrapper;
+
 class BitrateObserver {
- /*
-  * Observer class for the encoders, each encoder should implement this class
-  * to get the target bitrate. It also get the fraction loss and rtt to
-  * optimize its settings for this type of network. |target_bitrate| is the
-  * target media/payload bitrate excluding packet headers, measured in bits
-  * per second.
-  */
+  // Observer class for bitrate changes announced due to change in bandwidth
+  // estimate or due to bitrate allocation changes. Fraction loss and rtt is
+  // also part of this callback to allow the obsevrer to optimize its settings
+  // for different types of network environments. The bitrate does not include
+  // packet headers and is measured in bits per second.
  public:
-  virtual void OnNetworkChanged(uint32_t target_bitrate,
+  virtual void OnNetworkChanged(uint32_t bitrate_bps,
                                 uint8_t fraction_loss,  // 0 - 255.
-                                int64_t rtt) = 0;
+                                int64_t rtt_ms) = 0;
 
   virtual ~BitrateObserver() {}
 };
 
 class BitrateController : public Module {
-/*
- * This class collects feedback from all streams sent to a peer (via
- * RTCPBandwidthObservers). It does one  aggregated send side bandwidth
- * estimation and divide the available bitrate between all its registered
- * BitrateObservers.
- */
+  // This class collects feedback from all streams sent to a peer (via
+  // RTCPBandwidthObservers). It does one  aggregated send side bandwidth
+  // estimation and divide the available bitrate between all its registered
+  // BitrateObservers.
  public:
-  // The argument |enforce_min_bitrate| controls the behavior when the available
-  // bitrate is lower than the minimum bitrate, or the sum of minimum bitrates.
-  // When true, the bitrate will never be set lower than the minimum bitrate(s).
-  // When false, the bitrate observers will be allocated rates up to their
-  // respective minimum bitrate, satisfying one observer after the other.
+  static const int kDefaultStartBitrateKbps = 300;
+
   static BitrateController* CreateBitrateController(Clock* clock,
-                                                    bool enforce_min_bitrate);
+                                                    BitrateObserver* observer);
   virtual ~BitrateController() {}
 
   virtual RtcpBandwidthObserver* CreateRtcpBandwidthObserver() = 0;
 
+  virtual void SetStartBitrate(int start_bitrate_bps) = 0;
+  virtual void SetMinMaxBitrate(int min_bitrate_bps, int max_bitrate_bps) = 0;
+
   // Gets the available payload bandwidth in bits per second. Note that
   // this bandwidth excludes packet headers.
   virtual bool AvailableBandwidth(uint32_t* bandwidth) const = 0;
 
-  /*
-  *  Set the start and max send bitrate used by the bandwidth management.
-  *
-  *  observer, updates bitrates if already in use.
-  *  min_bitrate_kbit = 0 equals no min bitrate.
-  *  max_bitrate_kit = 0 equals no max bitrate.
-  */
-  virtual void SetBitrateObserver(BitrateObserver* observer,
-                                  uint32_t start_bitrate,
-                                  uint32_t min_bitrate,
-                                  uint32_t max_bitrate) = 0;
-
-  virtual void RemoveBitrateObserver(BitrateObserver* observer) = 0;
-
-  // Changes the mode that was set in the constructor.
-  virtual void EnforceMinBitrate(bool enforce_min_bitrate) = 0;
-
   virtual void SetReservedBitrate(uint32_t reserved_bitrate_bps) = 0;
 
   virtual void SetBitrateSent(uint32_t bitrate_sent_bps) = 0;