Declares BitrateAllocator methods const.

Bug: webrtc:9883
Change-Id: I79e4f8d233281975c4073a381c7568469390b817
Reviewed-on: https://webrtc-review.googlesource.com/c/107725
Reviewed-by: Niels Moller <nisse@webrtc.org>
Commit-Queue: Sebastian Jansson <srte@webrtc.org>
Cr-Commit-Position: refs/heads/master@{#25343}
diff --git a/call/bitrate_allocator.cc b/call/bitrate_allocator.cc
index acb19ae..fc2618b 100644
--- a/call/bitrate_allocator.cc
+++ b/call/bitrate_allocator.cc
@@ -248,7 +248,8 @@
   UpdateAllocationLimits();
 }
 
-int BitrateAllocator::GetStartBitrate(BitrateAllocatorObserver* observer) {
+int BitrateAllocator::GetStartBitrate(
+    BitrateAllocatorObserver* observer) const {
   RTC_DCHECK_CALLED_SEQUENTIALLY(&sequenced_checker_);
   const auto& it = FindObserverConfig(observer);
   if (it == bitrate_observer_configs_.end()) {
@@ -272,6 +273,17 @@
   bitrate_allocation_strategy_ = std::move(bitrate_allocation_strategy);
 }
 
+BitrateAllocator::ObserverConfigs::const_iterator
+BitrateAllocator::FindObserverConfig(
+    const BitrateAllocatorObserver* observer) const {
+  for (auto it = bitrate_observer_configs_.begin();
+       it != bitrate_observer_configs_.end(); ++it) {
+    if (it->observer == observer)
+      return it;
+  }
+  return bitrate_observer_configs_.end();
+}
+
 BitrateAllocator::ObserverConfigs::iterator
 BitrateAllocator::FindObserverConfig(const BitrateAllocatorObserver* observer) {
   for (auto it = bitrate_observer_configs_.begin();
@@ -283,7 +295,7 @@
 }
 
 BitrateAllocator::ObserverAllocation BitrateAllocator::AllocateBitrates(
-    uint32_t bitrate) {
+    uint32_t bitrate) const {
   if (bitrate_observer_configs_.empty())
     return ObserverAllocation();
 
@@ -331,7 +343,8 @@
   return MaxRateAllocation(bitrate, sum_max_bitrates);
 }
 
-BitrateAllocator::ObserverAllocation BitrateAllocator::ZeroRateAllocation() {
+BitrateAllocator::ObserverAllocation BitrateAllocator::ZeroRateAllocation()
+    const {
   ObserverAllocation allocation;
   for (const auto& observer_config : bitrate_observer_configs_)
     allocation[observer_config.observer] = 0;
@@ -339,7 +352,7 @@
 }
 
 BitrateAllocator::ObserverAllocation BitrateAllocator::LowRateAllocation(
-    uint32_t bitrate) {
+    uint32_t bitrate) const {
   ObserverAllocation allocation;
   // Start by allocating bitrate to observers enforcing a min bitrate, hence
   // remaining_bitrate might turn negative.
@@ -400,7 +413,7 @@
 // min_bitrate_bps values, until one of the observers hits its max_bitrate_bps.
 BitrateAllocator::ObserverAllocation BitrateAllocator::NormalRateAllocation(
     uint32_t bitrate,
-    uint32_t sum_min_bitrates) {
+    uint32_t sum_min_bitrates) const {
   ObserverAllocation allocation;
   ObserverAllocation observers_capacities;
   for (const auto& observer_config : bitrate_observer_configs_) {
@@ -420,7 +433,7 @@
 
 BitrateAllocator::ObserverAllocation BitrateAllocator::MaxRateAllocation(
     uint32_t bitrate,
-    uint32_t sum_max_bitrates) {
+    uint32_t sum_max_bitrates) const {
   ObserverAllocation allocation;
 
   for (const auto& observer_config : bitrate_observer_configs_) {
@@ -457,10 +470,11 @@
   return min_bitrate;
 }
 
-void BitrateAllocator::DistributeBitrateEvenly(uint32_t bitrate,
-                                               bool include_zero_allocations,
-                                               int max_multiplier,
-                                               ObserverAllocation* allocation) {
+void BitrateAllocator::DistributeBitrateEvenly(
+    uint32_t bitrate,
+    bool include_zero_allocations,
+    int max_multiplier,
+    ObserverAllocation* allocation) const {
   RTC_DCHECK_EQ(allocation->size(), bitrate_observer_configs_.size());
 
   ObserverSortingMap list_max_bitrates;
@@ -491,8 +505,9 @@
   }
 }
 
-bool BitrateAllocator::EnoughBitrateForAllObservers(uint32_t bitrate,
-                                                    uint32_t sum_min_bitrates) {
+bool BitrateAllocator::EnoughBitrateForAllObservers(
+    uint32_t bitrate,
+    uint32_t sum_min_bitrates) const {
   if (bitrate < sum_min_bitrates)
     return false;
 
@@ -511,7 +526,7 @@
 void BitrateAllocator::DistributeBitrateRelatively(
     uint32_t remaining_bitrate,
     const ObserverAllocation& observers_capacities,
-    ObserverAllocation* allocation) {
+    ObserverAllocation* allocation) const {
   RTC_DCHECK_EQ(allocation->size(), bitrate_observer_configs_.size());
   RTC_DCHECK_EQ(observers_capacities.size(), bitrate_observer_configs_.size());
 
diff --git a/call/bitrate_allocator.h b/call/bitrate_allocator.h
index 47df7e0..8d00086 100644
--- a/call/bitrate_allocator.h
+++ b/call/bitrate_allocator.h
@@ -73,7 +73,7 @@
   virtual void AddObserver(BitrateAllocatorObserver* observer,
                            MediaStreamAllocationConfig config) = 0;
   virtual void RemoveObserver(BitrateAllocatorObserver* observer) = 0;
-  virtual int GetStartBitrate(BitrateAllocatorObserver* observer) = 0;
+  virtual int GetStartBitrate(BitrateAllocatorObserver* observer) const = 0;
 
  protected:
   virtual ~BitrateAllocatorInterface() = default;
@@ -120,7 +120,7 @@
 
   // Returns initial bitrate allocated for |observer|. If |observer| is not in
   // the list of added observers, a best guess is returned.
-  int GetStartBitrate(BitrateAllocatorObserver* observer) override;
+  int GetStartBitrate(BitrateAllocatorObserver* observer) const override;
 
   // Sets external allocation strategy. If strategy is not set default WebRTC
   // allocation mechanism will be used. The strategy may be changed during call.
@@ -171,31 +171,34 @@
   void UpdateAllocationLimits() RTC_RUN_ON(&sequenced_checker_);
 
   typedef std::vector<ObserverConfig> ObserverConfigs;
+  ObserverConfigs::const_iterator FindObserverConfig(
+      const BitrateAllocatorObserver* observer) const
+      RTC_RUN_ON(&sequenced_checker_);
   ObserverConfigs::iterator FindObserverConfig(
       const BitrateAllocatorObserver* observer) RTC_RUN_ON(&sequenced_checker_);
 
   typedef std::multimap<uint32_t, const ObserverConfig*> ObserverSortingMap;
   typedef std::map<BitrateAllocatorObserver*, int> ObserverAllocation;
 
-  ObserverAllocation AllocateBitrates(uint32_t bitrate)
+  ObserverAllocation AllocateBitrates(uint32_t bitrate) const
       RTC_RUN_ON(&sequenced_checker_);
 
   // Allocates zero bitrate to all observers.
-  ObserverAllocation ZeroRateAllocation() RTC_RUN_ON(&sequenced_checker_);
+  ObserverAllocation ZeroRateAllocation() const RTC_RUN_ON(&sequenced_checker_);
   // Allocates bitrate to observers when there isn't enough to allocate the
   // minimum to all observers.
-  ObserverAllocation LowRateAllocation(uint32_t bitrate)
+  ObserverAllocation LowRateAllocation(uint32_t bitrate) const
       RTC_RUN_ON(&sequenced_checker_);
   // Allocates bitrate to all observers when the available bandwidth is enough
   // to allocate the minimum to all observers but not enough to allocate the
   // max bitrate of each observer.
   ObserverAllocation NormalRateAllocation(uint32_t bitrate,
-                                          uint32_t sum_min_bitrates)
+                                          uint32_t sum_min_bitrates) const
       RTC_RUN_ON(&sequenced_checker_);
   // Allocates bitrate to observers when there is enough available bandwidth
   // for all observers to be allocated their max bitrate.
   ObserverAllocation MaxRateAllocation(uint32_t bitrate,
-                                       uint32_t sum_max_bitrates)
+                                       uint32_t sum_max_bitrates) const
       RTC_RUN_ON(&sequenced_checker_);
 
   // Splits |bitrate| evenly to observers already in |allocation|.
@@ -205,9 +208,10 @@
   void DistributeBitrateEvenly(uint32_t bitrate,
                                bool include_zero_allocations,
                                int max_multiplier,
-                               ObserverAllocation* allocation)
+                               ObserverAllocation* allocation) const
       RTC_RUN_ON(&sequenced_checker_);
-  bool EnoughBitrateForAllObservers(uint32_t bitrate, uint32_t sum_min_bitrates)
+  bool EnoughBitrateForAllObservers(uint32_t bitrate,
+                                    uint32_t sum_min_bitrates) const
       RTC_RUN_ON(&sequenced_checker_);
 
   // From the available |bitrate|, each observer will be allocated a
@@ -219,7 +223,7 @@
   void DistributeBitrateRelatively(
       uint32_t bitrate,
       const ObserverAllocation& observers_capacities,
-      ObserverAllocation* allocation) RTC_RUN_ON(&sequenced_checker_);
+      ObserverAllocation* allocation) const RTC_RUN_ON(&sequenced_checker_);
 
   // Allow packets to be transmitted in up to 2 times max video bitrate if the
   // bandwidth estimate allows it.
diff --git a/call/test/mock_bitrate_allocator.h b/call/test/mock_bitrate_allocator.h
index 714c025..f00ed79 100644
--- a/call/test/mock_bitrate_allocator.h
+++ b/call/test/mock_bitrate_allocator.h
@@ -21,7 +21,7 @@
   MOCK_METHOD2(AddObserver,
                void(BitrateAllocatorObserver*, MediaStreamAllocationConfig));
   MOCK_METHOD1(RemoveObserver, void(BitrateAllocatorObserver*));
-  MOCK_METHOD1(GetStartBitrate, int(BitrateAllocatorObserver*));
+  MOCK_CONST_METHOD1(GetStartBitrate, int(BitrateAllocatorObserver*));
 };
 }  // namespace webrtc
 #endif  // CALL_TEST_MOCK_BITRATE_ALLOCATOR_H_