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 |
11 #include "webrtc/modules/bitrate_controller/send_side_bandwidth_estimation.h" | 11 #include "webrtc/modules/bitrate_controller/send_side_bandwidth_estimation.h" |
12 | 12 |
13 #include <cmath> | 13 #include <cmath> |
14 | 14 |
15 #include "webrtc/base/checks.h" | 15 #include "webrtc/base/checks.h" |
16 #include "webrtc/call/rtc_event_log.h" | |
16 #include "webrtc/system_wrappers/interface/field_trial.h" | 17 #include "webrtc/system_wrappers/interface/field_trial.h" |
17 #include "webrtc/system_wrappers/interface/logging.h" | 18 #include "webrtc/system_wrappers/interface/logging.h" |
18 #include "webrtc/system_wrappers/interface/metrics.h" | 19 #include "webrtc/system_wrappers/interface/metrics.h" |
19 | 20 |
20 namespace webrtc { | 21 namespace webrtc { |
21 namespace { | 22 namespace { |
22 const int64_t kBweIncreaseIntervalMs = 1000; | 23 const int64_t kBweIncreaseIntervalMs = 1000; |
23 const int64_t kBweDecreaseIntervalMs = 300; | 24 const int64_t kBweDecreaseIntervalMs = 300; |
24 const int64_t kStartPhaseMs = 2000; | 25 const int64_t kStartPhaseMs = 2000; |
25 const int64_t kBweConverganceTimeMs = 20000; | 26 const int64_t kBweConverganceTimeMs = 20000; |
(...skipping 25 matching lines...) Expand all Loading... | |
51 last_low_bitrate_log_ms_(-1), | 52 last_low_bitrate_log_ms_(-1), |
52 time_last_receiver_block_ms_(0), | 53 time_last_receiver_block_ms_(0), |
53 last_fraction_loss_(0), | 54 last_fraction_loss_(0), |
54 last_round_trip_time_ms_(0), | 55 last_round_trip_time_ms_(0), |
55 bwe_incoming_(0), | 56 bwe_incoming_(0), |
56 time_last_decrease_ms_(0), | 57 time_last_decrease_ms_(0), |
57 first_report_time_ms_(-1), | 58 first_report_time_ms_(-1), |
58 initially_lost_packets_(0), | 59 initially_lost_packets_(0), |
59 bitrate_at_2_seconds_kbps_(0), | 60 bitrate_at_2_seconds_kbps_(0), |
60 uma_update_state_(kNoUpdate), | 61 uma_update_state_(kNoUpdate), |
61 rampup_uma_stats_updated_(kNumUmaRampupMetrics, false) { | 62 rampup_uma_stats_updated_(kNumUmaRampupMetrics, false), |
62 } | 63 event_log_(nullptr) { |
64 } | |
63 | 65 |
64 SendSideBandwidthEstimation::~SendSideBandwidthEstimation() {} | 66 SendSideBandwidthEstimation::~SendSideBandwidthEstimation() {} |
65 | 67 |
66 void SendSideBandwidthEstimation::SetSendBitrate(int bitrate) { | 68 void SendSideBandwidthEstimation::SetSendBitrate(int bitrate) { |
67 RTC_DCHECK_GT(bitrate, 0); | 69 RTC_DCHECK_GT(bitrate, 0); |
68 bitrate_ = bitrate; | 70 bitrate_ = bitrate; |
69 | 71 |
70 // Clear last sent bitrate history so the new value can be used directly | 72 // Clear last sent bitrate history so the new value can be used directly |
71 // and not capped. | 73 // and not capped. |
72 min_bitrate_history_.clear(); | 74 min_bitrate_history_.clear(); |
(...skipping 125 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
198 // If instead one would do: bitrate_ *= 1.08^(delta time), it would | 200 // If instead one would do: bitrate_ *= 1.08^(delta time), it would |
199 // take over one second since the lower packet loss to achieve 108kbps. | 201 // take over one second since the lower packet loss to achieve 108kbps. |
200 bitrate_ = static_cast<uint32_t>( | 202 bitrate_ = static_cast<uint32_t>( |
201 min_bitrate_history_.front().second * 1.08 + 0.5); | 203 min_bitrate_history_.front().second * 1.08 + 0.5); |
202 | 204 |
203 // Add 1 kbps extra, just to make sure that we do not get stuck | 205 // Add 1 kbps extra, just to make sure that we do not get stuck |
204 // (gives a little extra increase at low rates, negligible at higher | 206 // (gives a little extra increase at low rates, negligible at higher |
205 // rates). | 207 // rates). |
206 bitrate_ += 1000; | 208 bitrate_ += 1000; |
207 | 209 |
210 if (event_log_) { | |
211 event_log_->LogBwePacketLossEvent(bitrate_, last_fraction_loss_, | |
stefan-webrtc
2015/10/19 08:43:22
Would there be a point in differentiating between
terelius
2015/10/26 17:40:18
Since we have log the fraction lost, we are able t
stefan-webrtc
2015/10/28 16:03:18
True, sgtm
| |
212 accumulate_expected_packets_); | |
213 } | |
208 } else if (last_fraction_loss_ <= 26) { | 214 } else if (last_fraction_loss_ <= 26) { |
209 // Loss between 2% - 10%: Do nothing. | 215 // Loss between 2% - 10%: Do nothing. |
210 | 216 |
211 } else { | 217 } else { |
212 // Loss > 10%: Limit the rate decreases to once a kBweDecreaseIntervalMs + | 218 // Loss > 10%: Limit the rate decreases to once a kBweDecreaseIntervalMs + |
213 // rtt. | 219 // rtt. |
214 if ((now_ms - time_last_decrease_ms_) >= | 220 if ((now_ms - time_last_decrease_ms_) >= |
215 (kBweDecreaseIntervalMs + last_round_trip_time_ms_)) { | 221 (kBweDecreaseIntervalMs + last_round_trip_time_ms_)) { |
216 time_last_decrease_ms_ = now_ms; | 222 time_last_decrease_ms_ = now_ms; |
217 | 223 |
218 // Reduce rate: | 224 // Reduce rate: |
219 // newRate = rate * (1 - 0.5*lossRate); | 225 // newRate = rate * (1 - 0.5*lossRate); |
220 // where packetLoss = 256*lossRate; | 226 // where packetLoss = 256*lossRate; |
221 bitrate_ = static_cast<uint32_t>( | 227 bitrate_ = static_cast<uint32_t>( |
222 (bitrate_ * static_cast<double>(512 - last_fraction_loss_)) / | 228 (bitrate_ * static_cast<double>(512 - last_fraction_loss_)) / |
223 512.0); | 229 512.0); |
224 } | 230 } |
231 if (event_log_) { | |
232 event_log_->LogBwePacketLossEvent(bitrate_, last_fraction_loss_, | |
233 accumulate_expected_packets_); | |
234 } | |
225 } | 235 } |
226 } | 236 } |
227 bitrate_ = CapBitrateToThresholds(now_ms, bitrate_); | 237 bitrate_ = CapBitrateToThresholds(now_ms, bitrate_); |
228 } | 238 } |
229 | 239 |
230 bool SendSideBandwidthEstimation::IsInStartPhase(int64_t now_ms) const { | 240 bool SendSideBandwidthEstimation::IsInStartPhase(int64_t now_ms) const { |
231 return first_report_time_ms_ == -1 || | 241 return first_report_time_ms_ == -1 || |
232 now_ms - first_report_time_ms_ < kStartPhaseMs; | 242 now_ms - first_report_time_ms_ < kStartPhaseMs; |
233 } | 243 } |
234 | 244 |
(...skipping 30 matching lines...) Expand all Loading... | |
265 now_ms - last_low_bitrate_log_ms_ > kLowBitrateLogPeriodMs) { | 275 now_ms - last_low_bitrate_log_ms_ > kLowBitrateLogPeriodMs) { |
266 LOG(LS_WARNING) << "Estimated available bandwidth " << bitrate / 1000 | 276 LOG(LS_WARNING) << "Estimated available bandwidth " << bitrate / 1000 |
267 << " kbps is below configured min bitrate " | 277 << " kbps is below configured min bitrate " |
268 << min_bitrate_configured_ / 1000 << " kbps."; | 278 << min_bitrate_configured_ / 1000 << " kbps."; |
269 last_low_bitrate_log_ms_ = now_ms; | 279 last_low_bitrate_log_ms_ = now_ms; |
270 } | 280 } |
271 bitrate = min_bitrate_configured_; | 281 bitrate = min_bitrate_configured_; |
272 } | 282 } |
273 return bitrate; | 283 return bitrate; |
274 } | 284 } |
285 | |
286 void SendSideBandwidthEstimation::SetEventLog(RtcEventLog* event_log) { | |
287 event_log_ = event_log; | |
288 } | |
289 | |
275 } // namespace webrtc | 290 } // namespace webrtc |
OLD | NEW |