| 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_(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), |
| 59 total_requested_min_bitrate_(0) { |
| 58 sequenced_checker_.Detach(); | 60 sequenced_checker_.Detach(); |
| 59 } | 61 } |
| 60 | 62 |
| 61 BitrateAllocator::~BitrateAllocator() { | 63 BitrateAllocator::~BitrateAllocator() { |
| 62 RTC_HISTOGRAM_COUNTS_100("WebRTC.Call.NumberOfPauseEvents", | 64 RTC_HISTOGRAM_COUNTS_100("WebRTC.Call.NumberOfPauseEvents", |
| 63 num_pause_events_); | 65 num_pause_events_); |
| 64 } | 66 } |
| 65 | 67 |
| 66 void BitrateAllocator::OnNetworkChanged(uint32_t target_bitrate_bps, | 68 void BitrateAllocator::OnNetworkChanged(uint32_t target_bitrate_bps, |
| 67 uint8_t fraction_loss, | 69 uint8_t fraction_loss, |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 108 << ", configured min bitrate " << config.min_bitrate_bps | 110 << ", configured min bitrate " << config.min_bitrate_bps |
| 109 << ", current allocation " << allocated_bitrate | 111 << ", current allocation " << allocated_bitrate |
| 110 << " and protection bitrate " << protection_bitrate; | 112 << " and protection bitrate " << protection_bitrate; |
| 111 } | 113 } |
| 112 | 114 |
| 113 // Only update the media ratio if the observer got an allocation. | 115 // Only update the media ratio if the observer got an allocation. |
| 114 if (allocated_bitrate > 0) | 116 if (allocated_bitrate > 0) |
| 115 config.media_ratio = MediaRatio(allocated_bitrate, protection_bitrate); | 117 config.media_ratio = MediaRatio(allocated_bitrate, protection_bitrate); |
| 116 config.allocated_bitrate_bps = allocated_bitrate; | 118 config.allocated_bitrate_bps = allocated_bitrate; |
| 117 } | 119 } |
| 120 UpdateAllocationLimits(); |
| 118 } | 121 } |
| 119 | 122 |
| 120 void BitrateAllocator::AddObserver(BitrateAllocatorObserver* observer, | 123 void BitrateAllocator::AddObserver(BitrateAllocatorObserver* observer, |
| 121 uint32_t min_bitrate_bps, | 124 uint32_t min_bitrate_bps, |
| 122 uint32_t max_bitrate_bps, | 125 uint32_t max_bitrate_bps, |
| 123 uint32_t pad_up_bitrate_bps, | 126 uint32_t pad_up_bitrate_bps, |
| 124 bool enforce_min_bitrate) { | 127 bool enforce_min_bitrate) { |
| 125 RTC_DCHECK_CALLED_SEQUENTIALLY(&sequenced_checker_); | 128 RTC_DCHECK_CALLED_SEQUENTIALLY(&sequenced_checker_); |
| 126 auto it = FindObserverConfig(observer); | 129 auto it = FindObserverConfig(observer); |
| 127 | 130 |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 160 } | 163 } |
| 161 UpdateAllocationLimits(); | 164 UpdateAllocationLimits(); |
| 162 } | 165 } |
| 163 | 166 |
| 164 void BitrateAllocator::UpdateAllocationLimits() { | 167 void BitrateAllocator::UpdateAllocationLimits() { |
| 165 RTC_DCHECK_CALLED_SEQUENTIALLY(&sequenced_checker_); | 168 RTC_DCHECK_CALLED_SEQUENTIALLY(&sequenced_checker_); |
| 166 uint32_t total_requested_padding_bitrate = 0; | 169 uint32_t total_requested_padding_bitrate = 0; |
| 167 uint32_t total_requested_min_bitrate = 0; | 170 uint32_t total_requested_min_bitrate = 0; |
| 168 | 171 |
| 169 for (const auto& config : bitrate_observer_configs_) { | 172 for (const auto& config : bitrate_observer_configs_) { |
| 173 uint32_t stream_padding = config.pad_up_bitrate_bps; |
| 170 if (config.enforce_min_bitrate) { | 174 if (config.enforce_min_bitrate) { |
| 171 total_requested_min_bitrate += config.min_bitrate_bps; | 175 total_requested_min_bitrate += config.min_bitrate_bps; |
| 176 } else if (config.allocated_bitrate_bps == 0) { |
| 177 stream_padding = |
| 178 std::max(MinBitrateWithHysteresis(config), stream_padding); |
| 172 } | 179 } |
| 173 total_requested_padding_bitrate += config.pad_up_bitrate_bps; | 180 total_requested_padding_bitrate += stream_padding; |
| 174 } | 181 } |
| 175 | 182 |
| 183 if (total_requested_padding_bitrate == total_requested_padding_bitrate_ && |
| 184 total_requested_min_bitrate == total_requested_min_bitrate_) { |
| 185 return; |
| 186 } |
| 187 |
| 188 total_requested_min_bitrate_ = total_requested_min_bitrate; |
| 189 total_requested_padding_bitrate_ = total_requested_padding_bitrate; |
| 190 |
| 176 LOG(LS_INFO) << "UpdateAllocationLimits : total_requested_min_bitrate: " | 191 LOG(LS_INFO) << "UpdateAllocationLimits : total_requested_min_bitrate: " |
| 177 << total_requested_min_bitrate | 192 << total_requested_min_bitrate |
| 178 << "bps, total_requested_padding_bitrate: " | 193 << "bps, total_requested_padding_bitrate: " |
| 179 << total_requested_padding_bitrate << "bps"; | 194 << total_requested_padding_bitrate << "bps"; |
| 180 limit_observer_->OnAllocationLimitsChanged(total_requested_min_bitrate, | 195 limit_observer_->OnAllocationLimitsChanged(total_requested_min_bitrate, |
| 181 total_requested_padding_bitrate); | 196 total_requested_padding_bitrate); |
| 182 } | 197 } |
| 183 | 198 |
| 184 void BitrateAllocator::RemoveObserver(BitrateAllocatorObserver* observer) { | 199 void BitrateAllocator::RemoveObserver(BitrateAllocatorObserver* observer) { |
| 185 RTC_DCHECK_CALLED_SEQUENTIALLY(&sequenced_checker_); | 200 RTC_DCHECK_CALLED_SEQUENTIALLY(&sequenced_checker_); |
| (...skipping 223 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 409 uint32_t sum_min_bitrates) { | 424 uint32_t sum_min_bitrates) { |
| 410 RTC_DCHECK_CALLED_SEQUENTIALLY(&sequenced_checker_); | 425 RTC_DCHECK_CALLED_SEQUENTIALLY(&sequenced_checker_); |
| 411 if (bitrate < sum_min_bitrates) | 426 if (bitrate < sum_min_bitrates) |
| 412 return false; | 427 return false; |
| 413 | 428 |
| 414 uint32_t extra_bitrate_per_observer = | 429 uint32_t extra_bitrate_per_observer = |
| 415 (bitrate - sum_min_bitrates) / | 430 (bitrate - sum_min_bitrates) / |
| 416 static_cast<uint32_t>(bitrate_observer_configs_.size()); | 431 static_cast<uint32_t>(bitrate_observer_configs_.size()); |
| 417 for (const auto& observer_config : bitrate_observer_configs_) { | 432 for (const auto& observer_config : bitrate_observer_configs_) { |
| 418 if (observer_config.min_bitrate_bps + extra_bitrate_per_observer < | 433 if (observer_config.min_bitrate_bps + extra_bitrate_per_observer < |
| 419 MinBitrateWithHysteresis(observer_config)) | 434 MinBitrateWithHysteresis(observer_config)) { |
| 420 return false; | 435 return false; |
| 436 } |
| 421 } | 437 } |
| 422 return true; | 438 return true; |
| 423 } | 439 } |
| 424 } // namespace webrtc | 440 } // namespace webrtc |
| OLD | NEW |