OLD | NEW |
1 /* | 1 /* |
2 * Copyright (c) 2012 The WebRTC project authors. All Rights Reserved. | 2 * Copyright (c) 2012 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 26 matching lines...) Expand all Loading... |
37 | 37 |
38 const UmaRampUpMetric kUmaRampupMetrics[] = { | 38 const UmaRampUpMetric kUmaRampupMetrics[] = { |
39 {"WebRTC.BWE.RampUpTimeTo500kbpsInMs", 500}, | 39 {"WebRTC.BWE.RampUpTimeTo500kbpsInMs", 500}, |
40 {"WebRTC.BWE.RampUpTimeTo1000kbpsInMs", 1000}, | 40 {"WebRTC.BWE.RampUpTimeTo1000kbpsInMs", 1000}, |
41 {"WebRTC.BWE.RampUpTimeTo2000kbpsInMs", 2000}}; | 41 {"WebRTC.BWE.RampUpTimeTo2000kbpsInMs", 2000}}; |
42 const size_t kNumUmaRampupMetrics = | 42 const size_t kNumUmaRampupMetrics = |
43 sizeof(kUmaRampupMetrics) / sizeof(kUmaRampupMetrics[0]); | 43 sizeof(kUmaRampupMetrics) / sizeof(kUmaRampupMetrics[0]); |
44 | 44 |
45 } // namespace | 45 } // namespace |
46 | 46 |
47 SendSideBandwidthEstimation::SendSideBandwidthEstimation(RtcEventLog* event_log) | 47 SendSideBandwidthEstimation::SendSideBandwidthEstimation() |
48 : lost_packets_since_last_loss_update_Q8_(0), | 48 : lost_packets_since_last_loss_update_Q8_(0), |
49 expected_packets_since_last_loss_update_(0), | 49 expected_packets_since_last_loss_update_(0), |
50 bitrate_(0), | 50 bitrate_(0), |
51 min_bitrate_configured_(kDefaultMinBitrateBps), | 51 min_bitrate_configured_(kDefaultMinBitrateBps), |
52 max_bitrate_configured_(kDefaultMaxBitrateBps), | 52 max_bitrate_configured_(kDefaultMaxBitrateBps), |
53 last_low_bitrate_log_ms_(-1), | 53 last_low_bitrate_log_ms_(-1), |
54 has_decreased_since_last_fraction_loss_(false), | 54 has_decreased_since_last_fraction_loss_(false), |
55 time_last_receiver_block_ms_(-1), | 55 time_last_receiver_block_ms_(-1), |
56 last_fraction_loss_(0), | 56 last_fraction_loss_(0), |
57 last_round_trip_time_ms_(0), | 57 last_round_trip_time_ms_(0), |
58 bwe_incoming_(0), | 58 bwe_incoming_(0), |
59 delay_based_bitrate_bps_(0), | 59 delay_based_bitrate_bps_(0), |
60 time_last_decrease_ms_(0), | 60 time_last_decrease_ms_(0), |
61 first_report_time_ms_(-1), | 61 first_report_time_ms_(-1), |
62 initially_lost_packets_(0), | 62 initially_lost_packets_(0), |
63 bitrate_at_2_seconds_kbps_(0), | 63 bitrate_at_2_seconds_kbps_(0), |
64 uma_update_state_(kNoUpdate), | 64 uma_update_state_(kNoUpdate), |
65 rampup_uma_stats_updated_(kNumUmaRampupMetrics, false), | 65 rampup_uma_stats_updated_(kNumUmaRampupMetrics, false), |
66 event_log_(event_log) { | 66 event_log_(nullptr) {} |
67 RTC_DCHECK(event_log); | |
68 } | |
69 | 67 |
70 SendSideBandwidthEstimation::~SendSideBandwidthEstimation() {} | 68 SendSideBandwidthEstimation::~SendSideBandwidthEstimation() {} |
71 | 69 |
72 void SendSideBandwidthEstimation::SetBitrates(int send_bitrate, | 70 void SendSideBandwidthEstimation::SetBitrates(int send_bitrate, |
73 int min_bitrate, | 71 int min_bitrate, |
74 int max_bitrate) { | 72 int max_bitrate) { |
75 if (send_bitrate > 0) | 73 if (send_bitrate > 0) |
76 SetSendBitrate(send_bitrate); | 74 SetSendBitrate(send_bitrate); |
77 SetMinMaxBitrate(min_bitrate, max_bitrate); | 75 SetMinMaxBitrate(min_bitrate, max_bitrate); |
78 } | 76 } |
(...skipping 143 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
222 // If instead one would do: bitrate_ *= 1.08^(delta time), it would | 220 // If instead one would do: bitrate_ *= 1.08^(delta time), it would |
223 // take over one second since the lower packet loss to achieve 108kbps. | 221 // take over one second since the lower packet loss to achieve 108kbps. |
224 bitrate_ = static_cast<uint32_t>( | 222 bitrate_ = static_cast<uint32_t>( |
225 min_bitrate_history_.front().second * 1.08 + 0.5); | 223 min_bitrate_history_.front().second * 1.08 + 0.5); |
226 | 224 |
227 // Add 1 kbps extra, just to make sure that we do not get stuck | 225 // Add 1 kbps extra, just to make sure that we do not get stuck |
228 // (gives a little extra increase at low rates, negligible at higher | 226 // (gives a little extra increase at low rates, negligible at higher |
229 // rates). | 227 // rates). |
230 bitrate_ += 1000; | 228 bitrate_ += 1000; |
231 | 229 |
232 event_log_->LogBwePacketLossEvent( | 230 if (event_log_) { |
233 bitrate_, last_fraction_loss_, | 231 event_log_->LogBwePacketLossEvent( |
234 expected_packets_since_last_loss_update_); | 232 bitrate_, last_fraction_loss_, |
| 233 expected_packets_since_last_loss_update_); |
| 234 } |
235 } else if (last_fraction_loss_ <= 26) { | 235 } else if (last_fraction_loss_ <= 26) { |
236 // Loss between 2% - 10%: Do nothing. | 236 // Loss between 2% - 10%: Do nothing. |
237 } else { | 237 } else { |
238 // Loss > 10%: Limit the rate decreases to once a kBweDecreaseIntervalMs + | 238 // Loss > 10%: Limit the rate decreases to once a kBweDecreaseIntervalMs + |
239 // rtt. | 239 // rtt. |
240 if (!has_decreased_since_last_fraction_loss_ && | 240 if (!has_decreased_since_last_fraction_loss_ && |
241 (now_ms - time_last_decrease_ms_) >= | 241 (now_ms - time_last_decrease_ms_) >= |
242 (kBweDecreaseIntervalMs + last_round_trip_time_ms_)) { | 242 (kBweDecreaseIntervalMs + last_round_trip_time_ms_)) { |
243 time_last_decrease_ms_ = now_ms; | 243 time_last_decrease_ms_ = now_ms; |
244 | 244 |
245 // Reduce rate: | 245 // Reduce rate: |
246 // newRate = rate * (1 - 0.5*lossRate); | 246 // newRate = rate * (1 - 0.5*lossRate); |
247 // where packetLoss = 256*lossRate; | 247 // where packetLoss = 256*lossRate; |
248 bitrate_ = static_cast<uint32_t>( | 248 bitrate_ = static_cast<uint32_t>( |
249 (bitrate_ * static_cast<double>(512 - last_fraction_loss_)) / | 249 (bitrate_ * static_cast<double>(512 - last_fraction_loss_)) / |
250 512.0); | 250 512.0); |
251 has_decreased_since_last_fraction_loss_ = true; | 251 has_decreased_since_last_fraction_loss_ = true; |
252 } | 252 } |
253 event_log_->LogBwePacketLossEvent( | 253 if (event_log_) { |
254 bitrate_, last_fraction_loss_, | 254 event_log_->LogBwePacketLossEvent( |
255 expected_packets_since_last_loss_update_); | 255 bitrate_, last_fraction_loss_, |
| 256 expected_packets_since_last_loss_update_); |
| 257 } |
256 } | 258 } |
257 } | 259 } |
258 bitrate_ = CapBitrateToThresholds(now_ms, bitrate_); | 260 bitrate_ = CapBitrateToThresholds(now_ms, bitrate_); |
259 } | 261 } |
260 | 262 |
261 bool SendSideBandwidthEstimation::IsInStartPhase(int64_t now_ms) const { | 263 bool SendSideBandwidthEstimation::IsInStartPhase(int64_t now_ms) const { |
262 return first_report_time_ms_ == -1 || | 264 return first_report_time_ms_ == -1 || |
263 now_ms - first_report_time_ms_ < kStartPhaseMs; | 265 now_ms - first_report_time_ms_ < kStartPhaseMs; |
264 } | 266 } |
265 | 267 |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
299 now_ms - last_low_bitrate_log_ms_ > kLowBitrateLogPeriodMs) { | 301 now_ms - last_low_bitrate_log_ms_ > kLowBitrateLogPeriodMs) { |
300 LOG(LS_WARNING) << "Estimated available bandwidth " << bitrate / 1000 | 302 LOG(LS_WARNING) << "Estimated available bandwidth " << bitrate / 1000 |
301 << " kbps is below configured min bitrate " | 303 << " kbps is below configured min bitrate " |
302 << min_bitrate_configured_ / 1000 << " kbps."; | 304 << min_bitrate_configured_ / 1000 << " kbps."; |
303 last_low_bitrate_log_ms_ = now_ms; | 305 last_low_bitrate_log_ms_ = now_ms; |
304 } | 306 } |
305 bitrate = min_bitrate_configured_; | 307 bitrate = min_bitrate_configured_; |
306 } | 308 } |
307 return bitrate; | 309 return bitrate; |
308 } | 310 } |
| 311 |
| 312 void SendSideBandwidthEstimation::SetEventLog(RtcEventLog* event_log) { |
| 313 event_log_ = event_log; |
| 314 } |
| 315 |
309 } // namespace webrtc | 316 } // namespace webrtc |
OLD | NEW |