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