| 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 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 61 } | 61 } |
| 62 | 62 |
| 63 BitrateAllocator::~BitrateAllocator() { | 63 BitrateAllocator::~BitrateAllocator() { |
| 64 RTC_HISTOGRAM_COUNTS_100("WebRTC.Call.NumberOfPauseEvents", | 64 RTC_HISTOGRAM_COUNTS_100("WebRTC.Call.NumberOfPauseEvents", |
| 65 num_pause_events_); | 65 num_pause_events_); |
| 66 } | 66 } |
| 67 | 67 |
| 68 void BitrateAllocator::OnNetworkChanged(uint32_t target_bitrate_bps, | 68 void BitrateAllocator::OnNetworkChanged(uint32_t target_bitrate_bps, |
| 69 uint8_t fraction_loss, | 69 uint8_t fraction_loss, |
| 70 int64_t rtt, | 70 int64_t rtt, |
| 71 int64_t probing_interval_ms) { | 71 int64_t bwe_period_ms) { |
| 72 RTC_DCHECK_CALLED_SEQUENTIALLY(&sequenced_checker_); | 72 RTC_DCHECK_CALLED_SEQUENTIALLY(&sequenced_checker_); |
| 73 last_bitrate_bps_ = target_bitrate_bps; | 73 last_bitrate_bps_ = target_bitrate_bps; |
| 74 last_non_zero_bitrate_bps_ = | 74 last_non_zero_bitrate_bps_ = |
| 75 target_bitrate_bps > 0 ? target_bitrate_bps : last_non_zero_bitrate_bps_; | 75 target_bitrate_bps > 0 ? target_bitrate_bps : last_non_zero_bitrate_bps_; |
| 76 last_fraction_loss_ = fraction_loss; | 76 last_fraction_loss_ = fraction_loss; |
| 77 last_rtt_ = rtt; | 77 last_rtt_ = rtt; |
| 78 last_probing_interval_ms_ = probing_interval_ms; | 78 last_bwe_period_ms_ = bwe_period_ms; |
| 79 | 79 |
| 80 // Periodically log the incoming BWE. | 80 // Periodically log the incoming BWE. |
| 81 int64_t now = clock_->TimeInMilliseconds(); | 81 int64_t now = clock_->TimeInMilliseconds(); |
| 82 if (now > last_bwe_log_time_ + kBweLogIntervalMs) { | 82 if (now > last_bwe_log_time_ + kBweLogIntervalMs) { |
| 83 LOG(LS_INFO) << "Current BWE " << target_bitrate_bps; | 83 LOG(LS_INFO) << "Current BWE " << target_bitrate_bps; |
| 84 last_bwe_log_time_ = now; | 84 last_bwe_log_time_ = now; |
| 85 } | 85 } |
| 86 | 86 |
| 87 ObserverAllocation allocation = AllocateBitrates(target_bitrate_bps); | 87 ObserverAllocation allocation = AllocateBitrates(target_bitrate_bps); |
| 88 | 88 |
| 89 for (auto& config : bitrate_observer_configs_) { | 89 for (auto& config : bitrate_observer_configs_) { |
| 90 uint32_t allocated_bitrate = allocation[config.observer]; | 90 uint32_t allocated_bitrate = allocation[config.observer]; |
| 91 uint32_t protection_bitrate = config.observer->OnBitrateUpdated( | 91 uint32_t protection_bitrate = config.observer->OnBitrateUpdated( |
| 92 allocated_bitrate, last_fraction_loss_, last_rtt_, | 92 allocated_bitrate, last_fraction_loss_, last_rtt_, |
| 93 last_probing_interval_ms_); | 93 last_bwe_period_ms_); |
| 94 | 94 |
| 95 if (allocated_bitrate == 0 && config.allocated_bitrate_bps > 0) { | 95 if (allocated_bitrate == 0 && config.allocated_bitrate_bps > 0) { |
| 96 if (target_bitrate_bps > 0) | 96 if (target_bitrate_bps > 0) |
| 97 ++num_pause_events_; | 97 ++num_pause_events_; |
| 98 // The protection bitrate is an estimate based on the ratio between media | 98 // The protection bitrate is an estimate based on the ratio between media |
| 99 // and protection used before this observer was muted. | 99 // and protection used before this observer was muted. |
| 100 uint32_t predicted_protection_bps = | 100 uint32_t predicted_protection_bps = |
| 101 (1.0 - config.media_ratio) * config.min_bitrate_bps; | 101 (1.0 - config.media_ratio) * config.min_bitrate_bps; |
| 102 LOG(LS_INFO) << "Pausing observer " << config.observer | 102 LOG(LS_INFO) << "Pausing observer " << config.observer |
| 103 << " with configured min bitrate " << config.min_bitrate_bps | 103 << " with configured min bitrate " << config.min_bitrate_bps |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 141 } | 141 } |
| 142 | 142 |
| 143 ObserverAllocation allocation; | 143 ObserverAllocation allocation; |
| 144 if (last_bitrate_bps_ > 0) { | 144 if (last_bitrate_bps_ > 0) { |
| 145 // Calculate a new allocation and update all observers. | 145 // Calculate a new allocation and update all observers. |
| 146 allocation = AllocateBitrates(last_bitrate_bps_); | 146 allocation = AllocateBitrates(last_bitrate_bps_); |
| 147 for (auto& config : bitrate_observer_configs_) { | 147 for (auto& config : bitrate_observer_configs_) { |
| 148 uint32_t allocated_bitrate = allocation[config.observer]; | 148 uint32_t allocated_bitrate = allocation[config.observer]; |
| 149 uint32_t protection_bitrate = config.observer->OnBitrateUpdated( | 149 uint32_t protection_bitrate = config.observer->OnBitrateUpdated( |
| 150 allocated_bitrate, last_fraction_loss_, last_rtt_, | 150 allocated_bitrate, last_fraction_loss_, last_rtt_, |
| 151 last_probing_interval_ms_); | 151 last_bwe_period_ms_); |
| 152 config.allocated_bitrate_bps = allocated_bitrate; | 152 config.allocated_bitrate_bps = allocated_bitrate; |
| 153 if (allocated_bitrate > 0) | 153 if (allocated_bitrate > 0) |
| 154 config.media_ratio = MediaRatio(allocated_bitrate, protection_bitrate); | 154 config.media_ratio = MediaRatio(allocated_bitrate, protection_bitrate); |
| 155 } | 155 } |
| 156 } else { | 156 } else { |
| 157 // Currently, an encoder is not allowed to produce frames. | 157 // Currently, an encoder is not allowed to produce frames. |
| 158 // But we still have to return the initial config bitrate + let the | 158 // But we still have to return the initial config bitrate + let the |
| 159 // observer know that it can not produce frames. | 159 // observer know that it can not produce frames. |
| 160 allocation = AllocateBitrates(last_non_zero_bitrate_bps_); | 160 allocation = AllocateBitrates(last_non_zero_bitrate_bps_); |
| 161 observer->OnBitrateUpdated(0, last_fraction_loss_, last_rtt_, | 161 observer->OnBitrateUpdated(0, last_fraction_loss_, last_rtt_, |
| 162 last_probing_interval_ms_); | 162 last_bwe_period_ms_); |
| 163 } | 163 } |
| 164 UpdateAllocationLimits(); | 164 UpdateAllocationLimits(); |
| 165 } | 165 } |
| 166 | 166 |
| 167 void BitrateAllocator::UpdateAllocationLimits() { | 167 void BitrateAllocator::UpdateAllocationLimits() { |
| 168 RTC_DCHECK_CALLED_SEQUENTIALLY(&sequenced_checker_); | 168 RTC_DCHECK_CALLED_SEQUENTIALLY(&sequenced_checker_); |
| 169 uint32_t total_requested_padding_bitrate = 0; | 169 uint32_t total_requested_padding_bitrate = 0; |
| 170 uint32_t total_requested_min_bitrate = 0; | 170 uint32_t total_requested_min_bitrate = 0; |
| 171 | 171 |
| 172 for (const auto& config : bitrate_observer_configs_) { | 172 for (const auto& config : bitrate_observer_configs_) { |
| (...skipping 258 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 431 static_cast<uint32_t>(bitrate_observer_configs_.size()); | 431 static_cast<uint32_t>(bitrate_observer_configs_.size()); |
| 432 for (const auto& observer_config : bitrate_observer_configs_) { | 432 for (const auto& observer_config : bitrate_observer_configs_) { |
| 433 if (observer_config.min_bitrate_bps + extra_bitrate_per_observer < | 433 if (observer_config.min_bitrate_bps + extra_bitrate_per_observer < |
| 434 MinBitrateWithHysteresis(observer_config)) { | 434 MinBitrateWithHysteresis(observer_config)) { |
| 435 return false; | 435 return false; |
| 436 } | 436 } |
| 437 } | 437 } |
| 438 return true; | 438 return true; |
| 439 } | 439 } |
| 440 } // namespace webrtc | 440 } // namespace webrtc |
| OLD | NEW |