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