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 147 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 217 } else if (it->allocated_bitrate_bps == -1) { | 218 } else if (it->allocated_bitrate_bps == -1) { |
| 218 // This observer hasn't received an allocation yet, so do the same. | 219 // This observer hasn't received an allocation yet, so do the same. |
| 219 return last_non_zero_bitrate_bps_ / | 220 return last_non_zero_bitrate_bps_ / |
| 220 static_cast<int>(bitrate_observer_configs_.size()); | 221 static_cast<int>(bitrate_observer_configs_.size()); |
| 221 } else { | 222 } else { |
| 222 // This observer already has an allocation. | 223 // This observer already has an allocation. |
| 223 return it->allocated_bitrate_bps; | 224 return it->allocated_bitrate_bps; |
| 224 } | 225 } |
| 225 } | 226 } |
| 226 | 227 |
| 228 void BitrateAllocator::SetBitrateAllocationStrategy( | |
| 229 rtc::BitrateAllocationStrategy* bitrate_allocation_strategy) { | |
| 230 RTC_DCHECK_CALLED_SEQUENTIALLY(&sequenced_checker_); | |
| 231 bitrate_allocation_strategy_ = bitrate_allocation_strategy; | |
| 232 } | |
| 233 | |
| 227 BitrateAllocator::ObserverConfigs::iterator | 234 BitrateAllocator::ObserverConfigs::iterator |
| 228 BitrateAllocator::FindObserverConfig(const BitrateAllocatorObserver* observer) { | 235 BitrateAllocator::FindObserverConfig(const BitrateAllocatorObserver* observer) { |
| 229 RTC_DCHECK_CALLED_SEQUENTIALLY(&sequenced_checker_); | 236 RTC_DCHECK_CALLED_SEQUENTIALLY(&sequenced_checker_); |
| 230 for (auto it = bitrate_observer_configs_.begin(); | 237 for (auto it = bitrate_observer_configs_.begin(); |
| 231 it != bitrate_observer_configs_.end(); ++it) { | 238 it != bitrate_observer_configs_.end(); ++it) { |
| 232 if (it->observer == observer) | 239 if (it->observer == observer) |
| 233 return it; | 240 return it; |
| 234 } | 241 } |
| 235 return bitrate_observer_configs_.end(); | 242 return bitrate_observer_configs_.end(); |
| 236 } | 243 } |
| 237 | 244 |
| 245 BitrateAllocator::ObserverConfigs::iterator | |
| 246 BitrateAllocator::FindObserverConfig(const std::string track_id) { | |
| 247 RTC_DCHECK_CALLED_SEQUENTIALLY(&sequenced_checker_); | |
| 248 for (auto it = bitrate_observer_configs_.begin(); | |
| 249 it != bitrate_observer_configs_.end(); ++it) { | |
| 250 if (it->track_id == track_id) | |
| 251 return it; | |
| 252 } | |
| 253 return bitrate_observer_configs_.end(); | |
| 254 } | |
| 255 | |
| 238 BitrateAllocator::ObserverAllocation BitrateAllocator::AllocateBitrates( | 256 BitrateAllocator::ObserverAllocation BitrateAllocator::AllocateBitrates( |
| 239 uint32_t bitrate) { | 257 uint32_t bitrate) { |
| 240 RTC_DCHECK_CALLED_SEQUENTIALLY(&sequenced_checker_); | 258 RTC_DCHECK_CALLED_SEQUENTIALLY(&sequenced_checker_); |
| 241 if (bitrate_observer_configs_.empty()) | 259 if (bitrate_observer_configs_.empty()) |
| 242 return ObserverAllocation(); | 260 return ObserverAllocation(); |
| 243 | 261 |
| 262 if (bitrate_allocation_strategy_ != nullptr) { | |
| 263 rtc::BitrateAllocationStrategy::TrackConfigs track_configs; | |
| 264 for (auto& observer_config : bitrate_observer_configs_) { | |
| 265 // The strategy will not be able to handle track without ID specifically | |
| 266 // but it will be able to handle it in some general way. For example a | |
| 267 // strategy giving priotiry to audio streams will consider a stream | |
| 268 // without an ID as a non-audio streams and will allocate bitrate for it | |
| 269 // after required minimum allocated for audio. | |
| 270 if (observer_config.track_id.size() == 0) { | |
| 271 observer_config.track_id = | |
| 272 (std::stringstream() | |
|
nisse-webrtc
2017/08/22 15:23:33
Converting a pointer to a string and using it as i
alexnarest
2017/08/31 18:40:26
Track ID should not be empty because strategies do
| |
| 273 << static_cast<const void*>(observer_config.observer)) | |
| 274 .str(); | |
| 275 } | |
| 276 track_configs[observer_config.track_id] = | |
|
nisse-webrtc
2017/08/22 15:23:33
Could we rearrange the code to eliminate this copy
alexnarest
2017/08/31 18:40:26
Done.
| |
| 277 rtc::BitrateAllocationStrategy::TrackConfig( | |
| 278 observer_config.min_bitrate_bps, observer_config.max_bitrate_bps, | |
| 279 observer_config.enforce_min_bitrate, observer_config.track_id); | |
| 280 } | |
| 281 rtc::BitrateAllocationStrategy::TrackAllocations track_allocations = | |
| 282 bitrate_allocation_strategy_->AllocateBitrates(bitrate, track_configs); | |
| 283 ObserverAllocation allocation; | |
| 284 for (const auto& observer_config : bitrate_observer_configs_) { | |
| 285 // The strategy should return allocation for all tracks. | |
| 286 // In release builds still may be better to use zero allocation | |
| 287 // rathen than crash | |
| 288 RTC_DCHECK(track_allocations.find(observer_config.track_id) != | |
| 289 track_allocations.end()); | |
| 290 allocation[observer_config.observer] = | |
| 291 track_allocations[observer_config.track_id]; | |
| 292 } | |
| 293 return allocation; | |
| 294 } | |
| 295 | |
| 244 if (bitrate == 0) | 296 if (bitrate == 0) |
| 245 return ZeroRateAllocation(); | 297 return ZeroRateAllocation(); |
| 246 | 298 |
| 247 uint32_t sum_min_bitrates = 0; | 299 uint32_t sum_min_bitrates = 0; |
| 248 uint32_t sum_max_bitrates = 0; | 300 uint32_t sum_max_bitrates = 0; |
| 249 for (const auto& observer_config : bitrate_observer_configs_) { | 301 for (const auto& observer_config : bitrate_observer_configs_) { |
| 250 sum_min_bitrates += observer_config.min_bitrate_bps; | 302 sum_min_bitrates += observer_config.min_bitrate_bps; |
| 251 sum_max_bitrates += observer_config.max_bitrate_bps; | 303 sum_max_bitrates += observer_config.max_bitrate_bps; |
| 252 } | 304 } |
| 253 | 305 |
| (...skipping 178 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 432 static_cast<uint32_t>(bitrate_observer_configs_.size()); | 484 static_cast<uint32_t>(bitrate_observer_configs_.size()); |
| 433 for (const auto& observer_config : bitrate_observer_configs_) { | 485 for (const auto& observer_config : bitrate_observer_configs_) { |
| 434 if (observer_config.min_bitrate_bps + extra_bitrate_per_observer < | 486 if (observer_config.min_bitrate_bps + extra_bitrate_per_observer < |
| 435 MinBitrateWithHysteresis(observer_config)) { | 487 MinBitrateWithHysteresis(observer_config)) { |
| 436 return false; | 488 return false; |
| 437 } | 489 } |
| 438 } | 490 } |
| 439 return true; | 491 return true; |
| 440 } | 492 } |
| 441 } // namespace webrtc | 493 } // namespace webrtc |
| OLD | NEW |