Chromium Code Reviews| 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 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 49 : limit_observer_(limit_observer), | 49 : limit_observer_(limit_observer), |
| 50 bitrate_observer_configs_(), | 50 bitrate_observer_configs_(), |
| 51 last_bitrate_bps_(0), | 51 last_bitrate_bps_(0), |
| 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 total_requested_padding_bitrate_(0), | 58 total_requested_padding_bitrate_(0), |
| 59 total_requested_min_bitrate_(0) { | 59 total_requested_min_bitrate_(0), |
| 60 bitrate_allocation_strategy_(nullptr) { | |
| 60 sequenced_checker_.Detach(); | 61 sequenced_checker_.Detach(); |
| 61 } | 62 } |
| 62 | 63 |
| 63 BitrateAllocator::~BitrateAllocator() { | 64 BitrateAllocator::~BitrateAllocator() { |
| 64 RTC_HISTOGRAM_COUNTS_100("WebRTC.Call.NumberOfPauseEvents", | 65 RTC_HISTOGRAM_COUNTS_100("WebRTC.Call.NumberOfPauseEvents", |
| 65 num_pause_events_); | 66 num_pause_events_); |
| 66 } | 67 } |
| 67 | 68 |
| 68 void BitrateAllocator::OnNetworkChanged(uint32_t target_bitrate_bps, | 69 void BitrateAllocator::OnNetworkChanged(uint32_t target_bitrate_bps, |
| 69 uint8_t fraction_loss, | 70 uint8_t fraction_loss, |
| (...skipping 122 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 192 LOG(LS_INFO) << "UpdateAllocationLimits : total_requested_min_bitrate: " | 193 LOG(LS_INFO) << "UpdateAllocationLimits : total_requested_min_bitrate: " |
| 193 << total_requested_min_bitrate | 194 << total_requested_min_bitrate |
| 194 << "bps, total_requested_padding_bitrate: " | 195 << "bps, total_requested_padding_bitrate: " |
| 195 << total_requested_padding_bitrate << "bps"; | 196 << total_requested_padding_bitrate << "bps"; |
| 196 limit_observer_->OnAllocationLimitsChanged(total_requested_min_bitrate, | 197 limit_observer_->OnAllocationLimitsChanged(total_requested_min_bitrate, |
| 197 total_requested_padding_bitrate); | 198 total_requested_padding_bitrate); |
| 198 } | 199 } |
| 199 | 200 |
| 200 void BitrateAllocator::RemoveObserver(BitrateAllocatorObserver* observer) { | 201 void BitrateAllocator::RemoveObserver(BitrateAllocatorObserver* observer) { |
| 201 RTC_DCHECK_CALLED_SEQUENTIALLY(&sequenced_checker_); | 202 RTC_DCHECK_CALLED_SEQUENTIALLY(&sequenced_checker_); |
| 203 | |
| 202 auto it = FindObserverConfig(observer); | 204 auto it = FindObserverConfig(observer); |
| 203 if (it != bitrate_observer_configs_.end()) { | 205 if (it != bitrate_observer_configs_.end()) { |
| 204 bitrate_observer_configs_.erase(it); | 206 bitrate_observer_configs_.erase(it); |
| 205 } | 207 } |
| 206 | 208 |
| 207 UpdateAllocationLimits(); | 209 UpdateAllocationLimits(); |
| 208 } | 210 } |
| 209 | 211 |
| 210 int BitrateAllocator::GetStartBitrate(BitrateAllocatorObserver* observer) { | 212 int BitrateAllocator::GetStartBitrate(BitrateAllocatorObserver* observer) { |
| 211 RTC_DCHECK_CALLED_SEQUENTIALLY(&sequenced_checker_); | 213 RTC_DCHECK_CALLED_SEQUENTIALLY(&sequenced_checker_); |
| 212 const auto& it = FindObserverConfig(observer); | 214 const auto& it = FindObserverConfig(observer); |
| 213 if (it == bitrate_observer_configs_.end()) { | 215 if (it == bitrate_observer_configs_.end()) { |
| 214 // This observer hasn't been added yet, just give it its fair share. | 216 // This observer hasn't been added yet, just give it its fair share. |
| 215 return last_non_zero_bitrate_bps_ / | 217 return last_non_zero_bitrate_bps_ / |
| 216 static_cast<int>((bitrate_observer_configs_.size() + 1)); | 218 static_cast<int>((bitrate_observer_configs_.size() + 1)); |
| 217 } else if (it->allocated_bitrate_bps == -1) { | 219 } else if (it->allocated_bitrate_bps == -1) { |
| 218 // This observer hasn't received an allocation yet, so do the same. | 220 // This observer hasn't received an allocation yet, so do the same. |
| 219 return last_non_zero_bitrate_bps_ / | 221 return last_non_zero_bitrate_bps_ / |
| 220 static_cast<int>(bitrate_observer_configs_.size()); | 222 static_cast<int>(bitrate_observer_configs_.size()); |
| 221 } else { | 223 } else { |
| 222 // This observer already has an allocation. | 224 // This observer already has an allocation. |
| 223 return it->allocated_bitrate_bps; | 225 return it->allocated_bitrate_bps; |
| 224 } | 226 } |
| 225 } | 227 } |
| 226 | 228 |
| 229 void BitrateAllocator::SetBitrateAllocationStrategy( | |
| 230 rtc::BitrateAllocationStrategy* bitrate_allocation_strategy) { | |
| 231 RTC_DCHECK_CALLED_SEQUENTIALLY(&sequenced_checker_); | |
| 232 bitrate_allocation_strategy_ = bitrate_allocation_strategy; | |
| 233 } | |
| 234 | |
| 227 BitrateAllocator::ObserverConfigs::iterator | 235 BitrateAllocator::ObserverConfigs::iterator |
| 228 BitrateAllocator::FindObserverConfig(const BitrateAllocatorObserver* observer) { | 236 BitrateAllocator::FindObserverConfig(const BitrateAllocatorObserver* observer) { |
| 229 RTC_DCHECK_CALLED_SEQUENTIALLY(&sequenced_checker_); | 237 RTC_DCHECK_CALLED_SEQUENTIALLY(&sequenced_checker_); |
| 230 for (auto it = bitrate_observer_configs_.begin(); | 238 for (auto it = bitrate_observer_configs_.begin(); |
| 231 it != bitrate_observer_configs_.end(); ++it) { | 239 it != bitrate_observer_configs_.end(); ++it) { |
| 232 if (it->observer == observer) | 240 if (it->observer == observer) |
| 233 return it; | 241 return it; |
| 234 } | 242 } |
| 235 return bitrate_observer_configs_.end(); | 243 return bitrate_observer_configs_.end(); |
| 236 } | 244 } |
| 237 | 245 |
| 238 BitrateAllocator::ObserverAllocation BitrateAllocator::AllocateBitrates( | 246 BitrateAllocator::ObserverAllocation BitrateAllocator::AllocateBitrates( |
| 239 uint32_t bitrate) { | 247 uint32_t bitrate) { |
| 240 RTC_DCHECK_CALLED_SEQUENTIALLY(&sequenced_checker_); | 248 RTC_DCHECK_CALLED_SEQUENTIALLY(&sequenced_checker_); |
| 241 if (bitrate_observer_configs_.empty()) | 249 if (bitrate_observer_configs_.empty()) |
| 242 return ObserverAllocation(); | 250 return ObserverAllocation(); |
| 243 | 251 |
| 252 if (bitrate_allocation_strategy_ != nullptr) { | |
| 253 std::vector<const rtc::BitrateAllocationStrategy::TrackConfig*> | |
| 254 track_configs(bitrate_observer_configs_.size()); | |
| 255 for (auto it = bitrate_observer_configs_.begin(); | |
| 256 it != bitrate_observer_configs_.end(); ++it) { | |
| 257 track_configs[it - bitrate_observer_configs_.begin()] = &*it; | |
| 258 } | |
|
Taylor Brandstetter
2017/09/15 01:24:41
nit: I think a foreach style loop would still be m
alexnarest
2017/09/15 08:29:39
Done.
| |
| 259 std::vector<uint32_t> track_allocations = | |
| 260 bitrate_allocation_strategy_->AllocateBitrates(bitrate, track_configs); | |
| 261 // The strategy should return allocation for all tracks. | |
| 262 RTC_CHECK(track_allocations.size() == bitrate_observer_configs_.size()); | |
| 263 ObserverAllocation allocation; | |
| 264 auto track_allocations_it = track_allocations.begin(); | |
| 265 for (const auto& observer_config : bitrate_observer_configs_) { | |
| 266 allocation[observer_config.observer] = *track_allocations_it++; | |
| 267 } | |
| 268 return allocation; | |
| 269 } | |
| 270 | |
| 244 if (bitrate == 0) | 271 if (bitrate == 0) |
| 245 return ZeroRateAllocation(); | 272 return ZeroRateAllocation(); |
| 246 | 273 |
| 247 uint32_t sum_min_bitrates = 0; | 274 uint32_t sum_min_bitrates = 0; |
| 248 uint32_t sum_max_bitrates = 0; | 275 uint32_t sum_max_bitrates = 0; |
| 249 for (const auto& observer_config : bitrate_observer_configs_) { | 276 for (const auto& observer_config : bitrate_observer_configs_) { |
| 250 sum_min_bitrates += observer_config.min_bitrate_bps; | 277 sum_min_bitrates += observer_config.min_bitrate_bps; |
| 251 sum_max_bitrates += observer_config.max_bitrate_bps; | 278 sum_max_bitrates += observer_config.max_bitrate_bps; |
| 252 } | 279 } |
| 253 | 280 |
| (...skipping 178 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 432 static_cast<uint32_t>(bitrate_observer_configs_.size()); | 459 static_cast<uint32_t>(bitrate_observer_configs_.size()); |
| 433 for (const auto& observer_config : bitrate_observer_configs_) { | 460 for (const auto& observer_config : bitrate_observer_configs_) { |
| 434 if (observer_config.min_bitrate_bps + extra_bitrate_per_observer < | 461 if (observer_config.min_bitrate_bps + extra_bitrate_per_observer < |
| 435 MinBitrateWithHysteresis(observer_config)) { | 462 MinBitrateWithHysteresis(observer_config)) { |
| 436 return false; | 463 return false; |
| 437 } | 464 } |
| 438 } | 465 } |
| 439 return true; | 466 return true; |
| 440 } | 467 } |
| 441 } // namespace webrtc | 468 } // namespace webrtc |
| OLD | NEW |