| OLD | NEW | 
|---|
| 1 /* | 1 /* | 
| 2  *  Copyright (c) 2015 The WebRTC project authors. All Rights Reserved. | 2  *  Copyright (c) 2015 The WebRTC project authors. All Rights Reserved. | 
| 3  * | 3  * | 
| 4  *  Use of this source code is governed by a BSD-style license | 4  *  Use of this source code is governed by a BSD-style license | 
| 5  *  that can be found in the LICENSE file in the root of the source | 5  *  that can be found in the LICENSE file in the root of the source | 
| 6  *  tree. An additional intellectual property rights grant can be found | 6  *  tree. An additional intellectual property rights grant can be found | 
| 7  *  in the file PATENTS.  All contributing project authors may | 7  *  in the file PATENTS.  All contributing project authors may | 
| 8  *  be found in the AUTHORS file in the root of the source tree. | 8  *  be found in the AUTHORS file in the root of the source tree. | 
| 9  * | 9  * | 
| 10  */ | 10  */ | 
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 47   return allocated_bitrate_bps; | 47   return allocated_bitrate_bps; | 
| 48 } | 48 } | 
| 49 | 49 | 
| 50 BitrateAllocator::ObserverBitrateMap BitrateAllocator::AllocateBitrates() { | 50 BitrateAllocator::ObserverBitrateMap BitrateAllocator::AllocateBitrates() { | 
| 51   if (bitrate_observers_.empty()) | 51   if (bitrate_observers_.empty()) | 
| 52     return ObserverBitrateMap(); | 52     return ObserverBitrateMap(); | 
| 53 | 53 | 
| 54   uint32_t sum_min_bitrates = 0; | 54   uint32_t sum_min_bitrates = 0; | 
| 55   for (const auto& observer : bitrate_observers_) | 55   for (const auto& observer : bitrate_observers_) | 
| 56     sum_min_bitrates += observer.second.min_bitrate; | 56     sum_min_bitrates += observer.second.min_bitrate; | 
| 57   if (last_bitrate_bps_ <= sum_min_bitrates) | 57   if (last_bitrate_bps_ == 0) | 
|  | 58     return ZeroRateAllocation(); | 
|  | 59   else if (last_bitrate_bps_ <= sum_min_bitrates) | 
| 58     return LowRateAllocation(last_bitrate_bps_); | 60     return LowRateAllocation(last_bitrate_bps_); | 
| 59   else | 61   else | 
| 60     return NormalRateAllocation(last_bitrate_bps_, sum_min_bitrates); | 62     return NormalRateAllocation(last_bitrate_bps_, sum_min_bitrates); | 
| 61 } | 63 } | 
| 62 | 64 | 
| 63 int BitrateAllocator::AddObserver(BitrateAllocatorObserver* observer, | 65 int BitrateAllocator::AddObserver(BitrateAllocatorObserver* observer, | 
| 64                                   uint32_t min_bitrate_bps, | 66                                   uint32_t min_bitrate_bps, | 
| 65                                   uint32_t max_bitrate_bps) { | 67                                   uint32_t max_bitrate_bps) { | 
| 66   rtc::CritScope lock(&crit_sect_); | 68   rtc::CritScope lock(&crit_sect_); | 
| 67 | 69 | 
| (...skipping 29 matching lines...) Expand all  Loading... | 
| 97 void BitrateAllocator::RemoveObserver(BitrateAllocatorObserver* observer) { | 99 void BitrateAllocator::RemoveObserver(BitrateAllocatorObserver* observer) { | 
| 98   rtc::CritScope lock(&crit_sect_); | 100   rtc::CritScope lock(&crit_sect_); | 
| 99   BitrateObserverConfList::iterator it = | 101   BitrateObserverConfList::iterator it = | 
| 100       FindObserverConfigurationPair(observer); | 102       FindObserverConfigurationPair(observer); | 
| 101   if (it != bitrate_observers_.end()) { | 103   if (it != bitrate_observers_.end()) { | 
| 102     bitrate_observers_.erase(it); | 104     bitrate_observers_.erase(it); | 
| 103     bitrate_observers_modified_ = true; | 105     bitrate_observers_modified_ = true; | 
| 104   } | 106   } | 
| 105 } | 107 } | 
| 106 | 108 | 
| 107 void BitrateAllocator::GetMinMaxBitrateSumBps(int* min_bitrate_sum_bps, |  | 
| 108                                               int* max_bitrate_sum_bps) const { |  | 
| 109   *min_bitrate_sum_bps = 0; |  | 
| 110   *max_bitrate_sum_bps = 0; |  | 
| 111 |  | 
| 112   rtc::CritScope lock(&crit_sect_); |  | 
| 113   for (const auto& observer : bitrate_observers_) { |  | 
| 114     *min_bitrate_sum_bps += observer.second.min_bitrate; |  | 
| 115     *max_bitrate_sum_bps += observer.second.max_bitrate; |  | 
| 116   } |  | 
| 117 } |  | 
| 118 |  | 
| 119 BitrateAllocator::BitrateObserverConfList::iterator | 109 BitrateAllocator::BitrateObserverConfList::iterator | 
| 120 BitrateAllocator::FindObserverConfigurationPair( | 110 BitrateAllocator::FindObserverConfigurationPair( | 
| 121     const BitrateAllocatorObserver* observer) { | 111     const BitrateAllocatorObserver* observer) { | 
| 122   for (auto it = bitrate_observers_.begin(); it != bitrate_observers_.end(); | 112   for (auto it = bitrate_observers_.begin(); it != bitrate_observers_.end(); | 
| 123        ++it) { | 113        ++it) { | 
| 124     if (it->first == observer) | 114     if (it->first == observer) | 
| 125       return it; | 115       return it; | 
| 126   } | 116   } | 
| 127   return bitrate_observers_.end(); | 117   return bitrate_observers_.end(); | 
| 128 } | 118 } | 
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 163     } else { | 153     } else { | 
| 164       allocation[max_it->second.observer] = observer_allowance; | 154       allocation[max_it->second.observer] = observer_allowance; | 
| 165     } | 155     } | 
| 166     list_max_bitrates.erase(max_it); | 156     list_max_bitrates.erase(max_it); | 
| 167     // Prepare next iteration. | 157     // Prepare next iteration. | 
| 168     max_it = list_max_bitrates.begin(); | 158     max_it = list_max_bitrates.begin(); | 
| 169   } | 159   } | 
| 170   return allocation; | 160   return allocation; | 
| 171 } | 161 } | 
| 172 | 162 | 
|  | 163 BitrateAllocator::ObserverBitrateMap BitrateAllocator::ZeroRateAllocation() { | 
|  | 164   ObserverBitrateMap allocation; | 
|  | 165   // Zero bitrate to all observers. | 
|  | 166   for (const auto& observer : bitrate_observers_) | 
|  | 167     allocation[observer.first] = 0; | 
|  | 168   return allocation; | 
|  | 169 } | 
|  | 170 | 
| 173 BitrateAllocator::ObserverBitrateMap BitrateAllocator::LowRateAllocation( | 171 BitrateAllocator::ObserverBitrateMap BitrateAllocator::LowRateAllocation( | 
| 174     uint32_t bitrate) { | 172     uint32_t bitrate) { | 
| 175   ObserverBitrateMap allocation; | 173   ObserverBitrateMap allocation; | 
| 176   if (enforce_min_bitrate_) { | 174   if (enforce_min_bitrate_) { | 
| 177     // Min bitrate to all observers. | 175     // Min bitrate to all observers. | 
| 178     for (const auto& observer : bitrate_observers_) | 176     for (const auto& observer : bitrate_observers_) | 
| 179       allocation[observer.first] = observer.second.min_bitrate; | 177       allocation[observer.first] = observer.second.min_bitrate; | 
| 180   } else { | 178   } else { | 
| 181     // Allocate up to |min_bitrate| to one observer at a time, until | 179     // Allocate up to |min_bitrate| to one observer at a time, until | 
| 182     // |bitrate| is depleted. | 180     // |bitrate| is depleted. | 
| 183     uint32_t remainder = bitrate; | 181     uint32_t remainder = bitrate; | 
| 184     for (const auto& observer : bitrate_observers_) { | 182     for (const auto& observer : bitrate_observers_) { | 
| 185       uint32_t allocated_bitrate = | 183       uint32_t allocated_bitrate = | 
| 186           std::min(remainder, observer.second.min_bitrate); | 184           std::min(remainder, observer.second.min_bitrate); | 
| 187       allocation[observer.first] = allocated_bitrate; | 185       allocation[observer.first] = allocated_bitrate; | 
| 188       remainder -= allocated_bitrate; | 186       remainder -= allocated_bitrate; | 
| 189     } | 187     } | 
| 190   } | 188   } | 
| 191   return allocation; | 189   return allocation; | 
| 192 } | 190 } | 
| 193 }  // namespace webrtc | 191 }  // namespace webrtc | 
| OLD | NEW | 
|---|