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