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 | 47 |
48 BitrateAllocator::BitrateAllocator(LimitObserver* limit_observer) | 48 BitrateAllocator::BitrateAllocator(LimitObserver* limit_observer) |
49 : limit_observer_(limit_observer), | 49 : limit_observer_(limit_observer), |
50 bitrate_observer_configs_(), | 50 bitrate_observer_configs_(), |
51 last_bitrate_bps_(kDefaultBitrateBps), | 51 last_bitrate_bps_(kDefaultBitrateBps), |
52 last_non_zero_bitrate_bps_(kDefaultBitrateBps), | 52 last_non_zero_bitrate_bps_(kDefaultBitrateBps), |
53 last_fraction_loss_(0), | 53 last_fraction_loss_(0), |
54 last_rtt_(0), | 54 last_rtt_(0), |
55 num_pause_events_(0), | 55 num_pause_events_(0), |
56 clock_(Clock::GetRealTimeClock()), | 56 clock_(Clock::GetRealTimeClock()), |
57 last_bwe_log_time_(0) {} | 57 last_bwe_log_time_(0) { |
| 58 sequenced_checker_.Detach(); |
| 59 } |
58 | 60 |
59 BitrateAllocator::~BitrateAllocator() { | 61 BitrateAllocator::~BitrateAllocator() { |
60 RTC_LOGGED_HISTOGRAM_COUNTS_100("WebRTC.Call.NumberOfPauseEvents", | 62 RTC_LOGGED_HISTOGRAM_COUNTS_100("WebRTC.Call.NumberOfPauseEvents", |
61 num_pause_events_); | 63 num_pause_events_); |
62 } | 64 } |
63 | 65 |
64 void BitrateAllocator::OnNetworkChanged(uint32_t target_bitrate_bps, | 66 void BitrateAllocator::OnNetworkChanged(uint32_t target_bitrate_bps, |
65 uint8_t fraction_loss, | 67 uint8_t fraction_loss, |
66 int64_t rtt) { | 68 int64_t rtt) { |
67 rtc::CritScope lock(&crit_sect_); | 69 RTC_DCHECK_CALLED_SEQUENTIALLY(&sequenced_checker_); |
68 last_bitrate_bps_ = target_bitrate_bps; | 70 last_bitrate_bps_ = target_bitrate_bps; |
69 last_non_zero_bitrate_bps_ = | 71 last_non_zero_bitrate_bps_ = |
70 target_bitrate_bps > 0 ? target_bitrate_bps : last_non_zero_bitrate_bps_; | 72 target_bitrate_bps > 0 ? target_bitrate_bps : last_non_zero_bitrate_bps_; |
71 last_fraction_loss_ = fraction_loss; | 73 last_fraction_loss_ = fraction_loss; |
72 last_rtt_ = rtt; | 74 last_rtt_ = rtt; |
73 | 75 |
74 // Periodically log the incoming BWE. | 76 // Periodically log the incoming BWE. |
75 int64_t now = clock_->TimeInMilliseconds(); | 77 int64_t now = clock_->TimeInMilliseconds(); |
76 if (now > last_bwe_log_time_ + kBweLogIntervalMs) { | 78 if (now > last_bwe_log_time_ + kBweLogIntervalMs) { |
77 LOG(LS_INFO) << "Current BWE " << target_bitrate_bps; | 79 LOG(LS_INFO) << "Current BWE " << target_bitrate_bps; |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
110 config.media_ratio = MediaRatio(allocated_bitrate, protection_bitrate); | 112 config.media_ratio = MediaRatio(allocated_bitrate, protection_bitrate); |
111 config.allocated_bitrate_bps = allocated_bitrate; | 113 config.allocated_bitrate_bps = allocated_bitrate; |
112 } | 114 } |
113 } | 115 } |
114 | 116 |
115 void BitrateAllocator::AddObserver(BitrateAllocatorObserver* observer, | 117 void BitrateAllocator::AddObserver(BitrateAllocatorObserver* observer, |
116 uint32_t min_bitrate_bps, | 118 uint32_t min_bitrate_bps, |
117 uint32_t max_bitrate_bps, | 119 uint32_t max_bitrate_bps, |
118 uint32_t pad_up_bitrate_bps, | 120 uint32_t pad_up_bitrate_bps, |
119 bool enforce_min_bitrate) { | 121 bool enforce_min_bitrate) { |
120 rtc::CritScope lock(&crit_sect_); | 122 RTC_DCHECK_CALLED_SEQUENTIALLY(&sequenced_checker_); |
121 auto it = FindObserverConfig(observer); | 123 auto it = FindObserverConfig(observer); |
122 | 124 |
123 // Update settings if the observer already exists, create a new one otherwise. | 125 // Update settings if the observer already exists, create a new one otherwise. |
124 if (it != bitrate_observer_configs_.end()) { | 126 if (it != bitrate_observer_configs_.end()) { |
125 it->min_bitrate_bps = min_bitrate_bps; | 127 it->min_bitrate_bps = min_bitrate_bps; |
126 it->max_bitrate_bps = max_bitrate_bps; | 128 it->max_bitrate_bps = max_bitrate_bps; |
127 it->pad_up_bitrate_bps = pad_up_bitrate_bps; | 129 it->pad_up_bitrate_bps = pad_up_bitrate_bps; |
128 it->enforce_min_bitrate = enforce_min_bitrate; | 130 it->enforce_min_bitrate = enforce_min_bitrate; |
129 } else { | 131 } else { |
130 bitrate_observer_configs_.push_back( | 132 bitrate_observer_configs_.push_back( |
(...skipping 17 matching lines...) Expand all Loading... |
148 // Currently, an encoder is not allowed to produce frames. | 150 // Currently, an encoder is not allowed to produce frames. |
149 // But we still have to return the initial config bitrate + let the | 151 // But we still have to return the initial config bitrate + let the |
150 // observer know that it can not produce frames. | 152 // observer know that it can not produce frames. |
151 allocation = AllocateBitrates(last_non_zero_bitrate_bps_); | 153 allocation = AllocateBitrates(last_non_zero_bitrate_bps_); |
152 observer->OnBitrateUpdated(0, last_fraction_loss_, last_rtt_); | 154 observer->OnBitrateUpdated(0, last_fraction_loss_, last_rtt_); |
153 } | 155 } |
154 UpdateAllocationLimits(); | 156 UpdateAllocationLimits(); |
155 } | 157 } |
156 | 158 |
157 void BitrateAllocator::UpdateAllocationLimits() { | 159 void BitrateAllocator::UpdateAllocationLimits() { |
| 160 RTC_DCHECK_CALLED_SEQUENTIALLY(&sequenced_checker_); |
158 uint32_t total_requested_padding_bitrate = 0; | 161 uint32_t total_requested_padding_bitrate = 0; |
159 uint32_t total_requested_min_bitrate = 0; | 162 uint32_t total_requested_min_bitrate = 0; |
160 | 163 |
161 { | 164 for (const auto& config : bitrate_observer_configs_) { |
162 rtc::CritScope lock(&crit_sect_); | 165 if (config.enforce_min_bitrate) { |
163 for (const auto& config : bitrate_observer_configs_) { | 166 total_requested_min_bitrate += config.min_bitrate_bps; |
164 if (config.enforce_min_bitrate) { | |
165 total_requested_min_bitrate += config.min_bitrate_bps; | |
166 } | |
167 total_requested_padding_bitrate += config.pad_up_bitrate_bps; | |
168 } | 167 } |
| 168 total_requested_padding_bitrate += config.pad_up_bitrate_bps; |
169 } | 169 } |
170 | 170 |
171 LOG(LS_INFO) << "UpdateAllocationLimits : total_requested_min_bitrate: " | 171 LOG(LS_INFO) << "UpdateAllocationLimits : total_requested_min_bitrate: " |
172 << total_requested_min_bitrate | 172 << total_requested_min_bitrate |
173 << "bps, total_requested_padding_bitrate: " | 173 << "bps, total_requested_padding_bitrate: " |
174 << total_requested_padding_bitrate << "bps"; | 174 << total_requested_padding_bitrate << "bps"; |
175 limit_observer_->OnAllocationLimitsChanged(total_requested_min_bitrate, | 175 limit_observer_->OnAllocationLimitsChanged(total_requested_min_bitrate, |
176 total_requested_padding_bitrate); | 176 total_requested_padding_bitrate); |
177 } | 177 } |
178 | 178 |
179 void BitrateAllocator::RemoveObserver(BitrateAllocatorObserver* observer) { | 179 void BitrateAllocator::RemoveObserver(BitrateAllocatorObserver* observer) { |
180 { | 180 RTC_DCHECK_CALLED_SEQUENTIALLY(&sequenced_checker_); |
181 rtc::CritScope lock(&crit_sect_); | 181 auto it = FindObserverConfig(observer); |
182 auto it = FindObserverConfig(observer); | 182 if (it != bitrate_observer_configs_.end()) { |
183 if (it != bitrate_observer_configs_.end()) { | 183 bitrate_observer_configs_.erase(it); |
184 bitrate_observer_configs_.erase(it); | |
185 } | |
186 } | 184 } |
| 185 |
187 UpdateAllocationLimits(); | 186 UpdateAllocationLimits(); |
188 } | 187 } |
189 | 188 |
190 int BitrateAllocator::GetStartBitrate(BitrateAllocatorObserver* observer) { | 189 int BitrateAllocator::GetStartBitrate(BitrateAllocatorObserver* observer) { |
191 rtc::CritScope lock(&crit_sect_); | 190 RTC_DCHECK_CALLED_SEQUENTIALLY(&sequenced_checker_); |
192 const auto& it = FindObserverConfig(observer); | 191 const auto& it = FindObserverConfig(observer); |
193 if (it == bitrate_observer_configs_.end()) { | 192 if (it == bitrate_observer_configs_.end()) { |
194 // This observer hasn't been added yet, just give it its fair share. | 193 // This observer hasn't been added yet, just give it its fair share. |
195 return last_non_zero_bitrate_bps_ / | 194 return last_non_zero_bitrate_bps_ / |
196 static_cast<int>((bitrate_observer_configs_.size() + 1)); | 195 static_cast<int>((bitrate_observer_configs_.size() + 1)); |
197 } else if (it->allocated_bitrate_bps == -1) { | 196 } else if (it->allocated_bitrate_bps == -1) { |
198 // This observer hasn't received an allocation yet, so do the same. | 197 // This observer hasn't received an allocation yet, so do the same. |
199 return last_non_zero_bitrate_bps_ / | 198 return last_non_zero_bitrate_bps_ / |
200 static_cast<int>(bitrate_observer_configs_.size()); | 199 static_cast<int>(bitrate_observer_configs_.size()); |
201 } else { | 200 } else { |
202 // This observer already has an allocation. | 201 // This observer already has an allocation. |
203 return it->allocated_bitrate_bps; | 202 return it->allocated_bitrate_bps; |
204 } | 203 } |
205 } | 204 } |
206 | 205 |
207 BitrateAllocator::ObserverConfigs::iterator | 206 BitrateAllocator::ObserverConfigs::iterator |
208 BitrateAllocator::FindObserverConfig( | 207 BitrateAllocator::FindObserverConfig(const BitrateAllocatorObserver* observer) { |
209 const BitrateAllocatorObserver* observer) { | 208 RTC_DCHECK_CALLED_SEQUENTIALLY(&sequenced_checker_); |
210 for (auto it = bitrate_observer_configs_.begin(); | 209 for (auto it = bitrate_observer_configs_.begin(); |
211 it != bitrate_observer_configs_.end(); ++it) { | 210 it != bitrate_observer_configs_.end(); ++it) { |
212 if (it->observer == observer) | 211 if (it->observer == observer) |
213 return it; | 212 return it; |
214 } | 213 } |
215 return bitrate_observer_configs_.end(); | 214 return bitrate_observer_configs_.end(); |
216 } | 215 } |
217 | 216 |
218 BitrateAllocator::ObserverAllocation BitrateAllocator::AllocateBitrates( | 217 BitrateAllocator::ObserverAllocation BitrateAllocator::AllocateBitrates( |
219 uint32_t bitrate) { | 218 uint32_t bitrate) { |
| 219 RTC_DCHECK_CALLED_SEQUENTIALLY(&sequenced_checker_); |
220 if (bitrate_observer_configs_.empty()) | 220 if (bitrate_observer_configs_.empty()) |
221 return ObserverAllocation(); | 221 return ObserverAllocation(); |
222 | 222 |
223 if (bitrate == 0) | 223 if (bitrate == 0) |
224 return ZeroRateAllocation(); | 224 return ZeroRateAllocation(); |
225 | 225 |
226 uint32_t sum_min_bitrates = 0; | 226 uint32_t sum_min_bitrates = 0; |
227 uint32_t sum_max_bitrates = 0; | 227 uint32_t sum_max_bitrates = 0; |
228 for (const auto& observer_config : bitrate_observer_configs_) { | 228 for (const auto& observer_config : bitrate_observer_configs_) { |
229 sum_min_bitrates += observer_config.min_bitrate_bps; | 229 sum_min_bitrates += observer_config.min_bitrate_bps; |
230 sum_max_bitrates += observer_config.max_bitrate_bps; | 230 sum_max_bitrates += observer_config.max_bitrate_bps; |
231 } | 231 } |
232 | 232 |
233 // Not enough for all observers to get an allocation, allocate according to: | 233 // Not enough for all observers to get an allocation, allocate according to: |
234 // enforced min bitrate -> allocated bitrate previous round -> restart paused | 234 // enforced min bitrate -> allocated bitrate previous round -> restart paused |
235 // streams. | 235 // streams. |
236 if (!EnoughBitrateForAllObservers(bitrate, sum_min_bitrates)) | 236 if (!EnoughBitrateForAllObservers(bitrate, sum_min_bitrates)) |
237 return LowRateAllocation(bitrate); | 237 return LowRateAllocation(bitrate); |
238 | 238 |
239 // All observers will get their min bitrate plus an even share of the rest. | 239 // All observers will get their min bitrate plus an even share of the rest. |
240 if (bitrate <= sum_max_bitrates) | 240 if (bitrate <= sum_max_bitrates) |
241 return NormalRateAllocation(bitrate, sum_min_bitrates); | 241 return NormalRateAllocation(bitrate, sum_min_bitrates); |
242 | 242 |
243 // All observers will get up to kTransmissionMaxBitrateMultiplier x max. | 243 // All observers will get up to kTransmissionMaxBitrateMultiplier x max. |
244 return MaxRateAllocation(bitrate, sum_max_bitrates); | 244 return MaxRateAllocation(bitrate, sum_max_bitrates); |
245 } | 245 } |
246 | 246 |
247 BitrateAllocator::ObserverAllocation BitrateAllocator::ZeroRateAllocation() { | 247 BitrateAllocator::ObserverAllocation BitrateAllocator::ZeroRateAllocation() { |
| 248 RTC_DCHECK_CALLED_SEQUENTIALLY(&sequenced_checker_); |
248 ObserverAllocation allocation; | 249 ObserverAllocation allocation; |
249 for (const auto& observer_config : bitrate_observer_configs_) | 250 for (const auto& observer_config : bitrate_observer_configs_) |
250 allocation[observer_config.observer] = 0; | 251 allocation[observer_config.observer] = 0; |
251 return allocation; | 252 return allocation; |
252 } | 253 } |
253 | 254 |
254 BitrateAllocator::ObserverAllocation BitrateAllocator::LowRateAllocation( | 255 BitrateAllocator::ObserverAllocation BitrateAllocator::LowRateAllocation( |
255 uint32_t bitrate) { | 256 uint32_t bitrate) { |
| 257 RTC_DCHECK_CALLED_SEQUENTIALLY(&sequenced_checker_); |
256 ObserverAllocation allocation; | 258 ObserverAllocation allocation; |
257 | |
258 // Start by allocating bitrate to observers enforcing a min bitrate, hence | 259 // Start by allocating bitrate to observers enforcing a min bitrate, hence |
259 // remaining_bitrate might turn negative. | 260 // remaining_bitrate might turn negative. |
260 int64_t remaining_bitrate = bitrate; | 261 int64_t remaining_bitrate = bitrate; |
261 for (const auto& observer_config : bitrate_observer_configs_) { | 262 for (const auto& observer_config : bitrate_observer_configs_) { |
262 int32_t allocated_bitrate = 0; | 263 int32_t allocated_bitrate = 0; |
263 if (observer_config.enforce_min_bitrate) | 264 if (observer_config.enforce_min_bitrate) |
264 allocated_bitrate = observer_config.min_bitrate_bps; | 265 allocated_bitrate = observer_config.min_bitrate_bps; |
265 | 266 |
266 allocation[observer_config.observer] = allocated_bitrate; | 267 allocation[observer_config.observer] = allocated_bitrate; |
267 remaining_bitrate -= allocated_bitrate; | 268 remaining_bitrate -= allocated_bitrate; |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
301 if (remaining_bitrate > 0) | 302 if (remaining_bitrate > 0) |
302 DistributeBitrateEvenly(remaining_bitrate, false, 1, &allocation); | 303 DistributeBitrateEvenly(remaining_bitrate, false, 1, &allocation); |
303 | 304 |
304 RTC_DCHECK_EQ(allocation.size(), bitrate_observer_configs_.size()); | 305 RTC_DCHECK_EQ(allocation.size(), bitrate_observer_configs_.size()); |
305 return allocation; | 306 return allocation; |
306 } | 307 } |
307 | 308 |
308 BitrateAllocator::ObserverAllocation BitrateAllocator::NormalRateAllocation( | 309 BitrateAllocator::ObserverAllocation BitrateAllocator::NormalRateAllocation( |
309 uint32_t bitrate, | 310 uint32_t bitrate, |
310 uint32_t sum_min_bitrates) { | 311 uint32_t sum_min_bitrates) { |
311 | 312 RTC_DCHECK_CALLED_SEQUENTIALLY(&sequenced_checker_); |
312 ObserverAllocation allocation; | 313 ObserverAllocation allocation; |
313 for (const auto& observer_config : bitrate_observer_configs_) | 314 for (const auto& observer_config : bitrate_observer_configs_) |
314 allocation[observer_config.observer] = observer_config.min_bitrate_bps; | 315 allocation[observer_config.observer] = observer_config.min_bitrate_bps; |
315 | 316 |
316 bitrate -= sum_min_bitrates; | 317 bitrate -= sum_min_bitrates; |
317 if (bitrate > 0) | 318 if (bitrate > 0) |
318 DistributeBitrateEvenly(bitrate, true, 1, &allocation); | 319 DistributeBitrateEvenly(bitrate, true, 1, &allocation); |
319 | 320 |
320 return allocation; | 321 return allocation; |
321 } | 322 } |
322 | 323 |
323 BitrateAllocator::ObserverAllocation BitrateAllocator::MaxRateAllocation( | 324 BitrateAllocator::ObserverAllocation BitrateAllocator::MaxRateAllocation( |
324 uint32_t bitrate, uint32_t sum_max_bitrates) { | 325 uint32_t bitrate, |
| 326 uint32_t sum_max_bitrates) { |
| 327 RTC_DCHECK_CALLED_SEQUENTIALLY(&sequenced_checker_); |
325 ObserverAllocation allocation; | 328 ObserverAllocation allocation; |
326 | 329 |
327 for (const auto& observer_config : bitrate_observer_configs_) { | 330 for (const auto& observer_config : bitrate_observer_configs_) { |
328 allocation[observer_config.observer] = observer_config.max_bitrate_bps; | 331 allocation[observer_config.observer] = observer_config.max_bitrate_bps; |
329 bitrate -= observer_config.max_bitrate_bps; | 332 bitrate -= observer_config.max_bitrate_bps; |
330 } | 333 } |
331 DistributeBitrateEvenly(bitrate, true, kTransmissionMaxBitrateMultiplier, | 334 DistributeBitrateEvenly(bitrate, true, kTransmissionMaxBitrateMultiplier, |
332 &allocation); | 335 &allocation); |
333 return allocation; | 336 return allocation; |
334 } | 337 } |
335 | 338 |
336 uint32_t BitrateAllocator::LastAllocatedBitrate( | 339 uint32_t BitrateAllocator::LastAllocatedBitrate( |
337 const ObserverConfig& observer_config) { | 340 const ObserverConfig& observer_config) { |
338 | |
339 // Return the configured minimum bitrate for newly added observers, to avoid | 341 // Return the configured minimum bitrate for newly added observers, to avoid |
340 // requiring an extra high bitrate for the observer to get an allocated | 342 // requiring an extra high bitrate for the observer to get an allocated |
341 // bitrate. | 343 // bitrate. |
342 return observer_config.allocated_bitrate_bps == -1 ? | 344 return observer_config.allocated_bitrate_bps == -1 |
343 observer_config.min_bitrate_bps : observer_config.allocated_bitrate_bps; | 345 ? observer_config.min_bitrate_bps |
| 346 : observer_config.allocated_bitrate_bps; |
344 } | 347 } |
345 | 348 |
346 uint32_t BitrateAllocator::MinBitrateWithHysteresis( | 349 uint32_t BitrateAllocator::MinBitrateWithHysteresis( |
347 const ObserverConfig& observer_config) { | 350 const ObserverConfig& observer_config) { |
348 uint32_t min_bitrate = observer_config.min_bitrate_bps; | 351 uint32_t min_bitrate = observer_config.min_bitrate_bps; |
349 if (LastAllocatedBitrate(observer_config) == 0) { | 352 if (LastAllocatedBitrate(observer_config) == 0) { |
350 min_bitrate += std::max(static_cast<uint32_t>(kToggleFactor * min_bitrate), | 353 min_bitrate += std::max(static_cast<uint32_t>(kToggleFactor * min_bitrate), |
351 kMinToggleBitrateBps); | 354 kMinToggleBitrateBps); |
352 } | 355 } |
353 // Account for protection bitrate used by this observer in the previous | 356 // Account for protection bitrate used by this observer in the previous |
354 // allocation. | 357 // allocation. |
355 // Note: the ratio will only be updated when the stream is active, meaning a | 358 // Note: the ratio will only be updated when the stream is active, meaning a |
356 // paused stream won't get any ratio updates. This might lead to waiting a bit | 359 // paused stream won't get any ratio updates. This might lead to waiting a bit |
357 // longer than necessary if the network condition improves, but this is to | 360 // longer than necessary if the network condition improves, but this is to |
358 // avoid too much toggling. | 361 // avoid too much toggling. |
359 if (observer_config.media_ratio > 0.0 && observer_config.media_ratio < 1.0) | 362 if (observer_config.media_ratio > 0.0 && observer_config.media_ratio < 1.0) |
360 min_bitrate += min_bitrate * (1.0 - observer_config.media_ratio); | 363 min_bitrate += min_bitrate * (1.0 - observer_config.media_ratio); |
361 | 364 |
362 return min_bitrate; | 365 return min_bitrate; |
363 } | 366 } |
364 | 367 |
365 void BitrateAllocator::DistributeBitrateEvenly(uint32_t bitrate, | 368 void BitrateAllocator::DistributeBitrateEvenly(uint32_t bitrate, |
366 bool include_zero_allocations, | 369 bool include_zero_allocations, |
367 int max_multiplier, | 370 int max_multiplier, |
368 ObserverAllocation* allocation) { | 371 ObserverAllocation* allocation) { |
| 372 RTC_DCHECK_CALLED_SEQUENTIALLY(&sequenced_checker_); |
369 RTC_DCHECK_EQ(allocation->size(), bitrate_observer_configs_.size()); | 373 RTC_DCHECK_EQ(allocation->size(), bitrate_observer_configs_.size()); |
370 | 374 |
371 ObserverSortingMap list_max_bitrates; | 375 ObserverSortingMap list_max_bitrates; |
372 for (const auto& observer_config : bitrate_observer_configs_) { | 376 for (const auto& observer_config : bitrate_observer_configs_) { |
373 if (include_zero_allocations || | 377 if (include_zero_allocations || |
374 allocation->at(observer_config.observer) != 0) { | 378 allocation->at(observer_config.observer) != 0) { |
375 list_max_bitrates.insert(std::pair<uint32_t, const ObserverConfig*>( | 379 list_max_bitrates.insert(std::pair<uint32_t, const ObserverConfig*>( |
376 observer_config.max_bitrate_bps, &observer_config)); | 380 observer_config.max_bitrate_bps, &observer_config)); |
377 } | 381 } |
378 } | 382 } |
(...skipping 12 matching lines...) Expand all Loading... |
391 total_allocation = max_multiplier * it->first; | 395 total_allocation = max_multiplier * it->first; |
392 } | 396 } |
393 // Finally, update the allocation for this observer. | 397 // Finally, update the allocation for this observer. |
394 allocation->at(it->second->observer) = total_allocation; | 398 allocation->at(it->second->observer) = total_allocation; |
395 it = list_max_bitrates.erase(it); | 399 it = list_max_bitrates.erase(it); |
396 } | 400 } |
397 } | 401 } |
398 | 402 |
399 bool BitrateAllocator::EnoughBitrateForAllObservers(uint32_t bitrate, | 403 bool BitrateAllocator::EnoughBitrateForAllObservers(uint32_t bitrate, |
400 uint32_t sum_min_bitrates) { | 404 uint32_t sum_min_bitrates) { |
| 405 RTC_DCHECK_CALLED_SEQUENTIALLY(&sequenced_checker_); |
401 if (bitrate < sum_min_bitrates) | 406 if (bitrate < sum_min_bitrates) |
402 return false; | 407 return false; |
403 | 408 |
404 uint32_t extra_bitrate_per_observer = (bitrate - sum_min_bitrates) / | 409 uint32_t extra_bitrate_per_observer = |
| 410 (bitrate - sum_min_bitrates) / |
405 static_cast<uint32_t>(bitrate_observer_configs_.size()); | 411 static_cast<uint32_t>(bitrate_observer_configs_.size()); |
406 for (const auto& observer_config : bitrate_observer_configs_) { | 412 for (const auto& observer_config : bitrate_observer_configs_) { |
407 if (observer_config.min_bitrate_bps + extra_bitrate_per_observer < | 413 if (observer_config.min_bitrate_bps + extra_bitrate_per_observer < |
408 MinBitrateWithHysteresis(observer_config)) | 414 MinBitrateWithHysteresis(observer_config)) |
409 return false; | 415 return false; |
410 } | 416 } |
411 return true; | 417 return true; |
412 } | 418 } |
413 } // namespace webrtc | 419 } // namespace webrtc |
OLD | NEW |