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_ == 0) | 57 if (last_bitrate_bps_ <= sum_min_bitrates) |
58 return ZeroRateAllocation(); | |
59 else if (last_bitrate_bps_ <= sum_min_bitrates) | |
60 return LowRateAllocation(last_bitrate_bps_); | 58 return LowRateAllocation(last_bitrate_bps_); |
61 else | 59 else |
62 return NormalRateAllocation(last_bitrate_bps_, sum_min_bitrates); | 60 return NormalRateAllocation(last_bitrate_bps_, sum_min_bitrates); |
63 } | 61 } |
64 | 62 |
65 int BitrateAllocator::AddObserver(BitrateAllocatorObserver* observer, | 63 int BitrateAllocator::AddObserver(BitrateAllocatorObserver* observer, |
66 uint32_t min_bitrate_bps, | 64 uint32_t min_bitrate_bps, |
67 uint32_t max_bitrate_bps) { | 65 uint32_t max_bitrate_bps) { |
68 rtc::CritScope lock(&crit_sect_); | 66 rtc::CritScope lock(&crit_sect_); |
69 | 67 |
(...skipping 29 matching lines...) Expand all Loading... |
99 void BitrateAllocator::RemoveObserver(BitrateAllocatorObserver* observer) { | 97 void BitrateAllocator::RemoveObserver(BitrateAllocatorObserver* observer) { |
100 rtc::CritScope lock(&crit_sect_); | 98 rtc::CritScope lock(&crit_sect_); |
101 BitrateObserverConfList::iterator it = | 99 BitrateObserverConfList::iterator it = |
102 FindObserverConfigurationPair(observer); | 100 FindObserverConfigurationPair(observer); |
103 if (it != bitrate_observers_.end()) { | 101 if (it != bitrate_observers_.end()) { |
104 bitrate_observers_.erase(it); | 102 bitrate_observers_.erase(it); |
105 bitrate_observers_modified_ = true; | 103 bitrate_observers_modified_ = true; |
106 } | 104 } |
107 } | 105 } |
108 | 106 |
| 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 |
109 BitrateAllocator::BitrateObserverConfList::iterator | 119 BitrateAllocator::BitrateObserverConfList::iterator |
110 BitrateAllocator::FindObserverConfigurationPair( | 120 BitrateAllocator::FindObserverConfigurationPair( |
111 const BitrateAllocatorObserver* observer) { | 121 const BitrateAllocatorObserver* observer) { |
112 for (auto it = bitrate_observers_.begin(); it != bitrate_observers_.end(); | 122 for (auto it = bitrate_observers_.begin(); it != bitrate_observers_.end(); |
113 ++it) { | 123 ++it) { |
114 if (it->first == observer) | 124 if (it->first == observer) |
115 return it; | 125 return it; |
116 } | 126 } |
117 return bitrate_observers_.end(); | 127 return bitrate_observers_.end(); |
118 } | 128 } |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
153 } else { | 163 } else { |
154 allocation[max_it->second.observer] = observer_allowance; | 164 allocation[max_it->second.observer] = observer_allowance; |
155 } | 165 } |
156 list_max_bitrates.erase(max_it); | 166 list_max_bitrates.erase(max_it); |
157 // Prepare next iteration. | 167 // Prepare next iteration. |
158 max_it = list_max_bitrates.begin(); | 168 max_it = list_max_bitrates.begin(); |
159 } | 169 } |
160 return allocation; | 170 return allocation; |
161 } | 171 } |
162 | 172 |
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 | |
171 BitrateAllocator::ObserverBitrateMap BitrateAllocator::LowRateAllocation( | 173 BitrateAllocator::ObserverBitrateMap BitrateAllocator::LowRateAllocation( |
172 uint32_t bitrate) { | 174 uint32_t bitrate) { |
173 ObserverBitrateMap allocation; | 175 ObserverBitrateMap allocation; |
174 if (enforce_min_bitrate_) { | 176 if (enforce_min_bitrate_) { |
175 // Min bitrate to all observers. | 177 // Min bitrate to all observers. |
176 for (const auto& observer : bitrate_observers_) | 178 for (const auto& observer : bitrate_observers_) |
177 allocation[observer.first] = observer.second.min_bitrate; | 179 allocation[observer.first] = observer.second.min_bitrate; |
178 } else { | 180 } else { |
179 // Allocate up to |min_bitrate| to one observer at a time, until | 181 // Allocate up to |min_bitrate| to one observer at a time, until |
180 // |bitrate| is depleted. | 182 // |bitrate| is depleted. |
181 uint32_t remainder = bitrate; | 183 uint32_t remainder = bitrate; |
182 for (const auto& observer : bitrate_observers_) { | 184 for (const auto& observer : bitrate_observers_) { |
183 uint32_t allocated_bitrate = | 185 uint32_t allocated_bitrate = |
184 std::min(remainder, observer.second.min_bitrate); | 186 std::min(remainder, observer.second.min_bitrate); |
185 allocation[observer.first] = allocated_bitrate; | 187 allocation[observer.first] = allocated_bitrate; |
186 remainder -= allocated_bitrate; | 188 remainder -= allocated_bitrate; |
187 } | 189 } |
188 } | 190 } |
189 return allocation; | 191 return allocation; |
190 } | 192 } |
191 } // namespace webrtc | 193 } // namespace webrtc |
OLD | NEW |