Chromium Code Reviews| 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 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 42 | 42 |
| 43 } | 43 } |
| 44 | 44 |
| 45 SendSideBandwidthEstimation::SendSideBandwidthEstimation() | 45 SendSideBandwidthEstimation::SendSideBandwidthEstimation() |
| 46 : accumulate_lost_packets_Q8_(0), | 46 : accumulate_lost_packets_Q8_(0), |
| 47 accumulate_expected_packets_(0), | 47 accumulate_expected_packets_(0), |
| 48 bitrate_(0), | 48 bitrate_(0), |
| 49 min_bitrate_configured_(kDefaultMinBitrateBps), | 49 min_bitrate_configured_(kDefaultMinBitrateBps), |
| 50 max_bitrate_configured_(kDefaultMaxBitrateBps), | 50 max_bitrate_configured_(kDefaultMaxBitrateBps), |
| 51 last_low_bitrate_log_ms_(-1), | 51 last_low_bitrate_log_ms_(-1), |
| 52 time_last_receiver_block_ms_(0), | 52 has_decreased_since_last_fraction_loss_(false), |
| 53 time_last_receiver_block_ms_(-1), | |
| 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 | 63 |
| 64 SendSideBandwidthEstimation::~SendSideBandwidthEstimation() {} | 64 SendSideBandwidthEstimation::~SendSideBandwidthEstimation() {} |
| 65 | 65 |
| 66 void SendSideBandwidthEstimation::SetSendBitrate(int bitrate) { | 66 void SendSideBandwidthEstimation::SetSendBitrate(int bitrate) { |
| 67 RTC_DCHECK_GT(bitrate, 0); | 67 RTC_DCHECK_GT(bitrate, 0); |
| 68 bitrate_ = bitrate; | 68 bitrate_ = bitrate; |
| 69 | 69 |
| 70 // Clear last sent bitrate history so the new value can be used directly | 70 // Clear last sent bitrate history so the new value can be used directly |
| 71 // and not capped. | 71 // and not capped. |
| 72 min_bitrate_history_.clear(); | 72 min_bitrate_history_.clear(); |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 111 | 111 |
| 112 // Update RTT. | 112 // Update RTT. |
| 113 last_round_trip_time_ms_ = rtt; | 113 last_round_trip_time_ms_ = rtt; |
| 114 | 114 |
| 115 // Check sequence number diff and weight loss report | 115 // Check sequence number diff and weight loss report |
| 116 if (number_of_packets > 0) { | 116 if (number_of_packets > 0) { |
| 117 // Calculate number of lost packets. | 117 // Calculate number of lost packets. |
| 118 const int num_lost_packets_Q8 = fraction_loss * number_of_packets; | 118 const int num_lost_packets_Q8 = fraction_loss * number_of_packets; |
| 119 // Accumulate reports. | 119 // Accumulate reports. |
| 120 accumulate_lost_packets_Q8_ += num_lost_packets_Q8; | 120 accumulate_lost_packets_Q8_ += num_lost_packets_Q8; |
| 121 accumulate_expected_packets_ += number_of_packets; | 121 accumulate_expected_packets_ += number_of_packets; |
|
mflodman
2015/10/22 07:06:58
Old, but I'd like to change name on this variable,
pbos-webrtc
2015/10/22 13:16:06
Done.
mflodman
2015/10/22 14:34:34
Thanks!
| |
| 122 | 122 |
| 123 // Report loss if the total report is based on sufficiently many packets. | 123 // Report loss if the total report is based on sufficiently many packets. |
|
stefan-webrtc
2015/10/22 09:20:47
Maybe change this comment to explain the if-statem
pbos-webrtc
2015/10/22 13:16:05
Done.
| |
| 124 if (accumulate_expected_packets_ >= kLimitNumPackets) { | 124 if (accumulate_expected_packets_ < kLimitNumPackets) |
| 125 last_fraction_loss_ = | 125 return; |
| 126 accumulate_lost_packets_Q8_ / accumulate_expected_packets_; | |
| 127 | 126 |
| 128 // Reset accumulators. | 127 has_decreased_since_last_fraction_loss_ = false; |
| 129 accumulate_lost_packets_Q8_ = 0; | 128 last_fraction_loss_ = |
| 130 accumulate_expected_packets_ = 0; | 129 accumulate_lost_packets_Q8_ / accumulate_expected_packets_; |
| 131 } else { | 130 |
| 132 // Early return without updating estimate. | 131 // Reset accumulators. |
| 133 return; | 132 accumulate_lost_packets_Q8_ = 0; |
| 134 } | 133 accumulate_expected_packets_ = 0; |
| 135 } | 134 } |
| 136 time_last_receiver_block_ms_ = now_ms; | 135 time_last_receiver_block_ms_ = now_ms; |
| 137 UpdateEstimate(now_ms); | 136 UpdateEstimate(now_ms); |
| 138 UpdateUmaStats(now_ms, rtt, (fraction_loss * number_of_packets) >> 8); | 137 UpdateUmaStats(now_ms, rtt, (fraction_loss * number_of_packets) >> 8); |
| 139 } | 138 } |
| 140 | 139 |
| 141 void SendSideBandwidthEstimation::UpdateUmaStats(int64_t now_ms, | 140 void SendSideBandwidthEstimation::UpdateUmaStats(int64_t now_ms, |
| 142 int64_t rtt, | 141 int64_t rtt, |
| 143 int lost_packets) { | 142 int lost_packets) { |
| 144 int bitrate_kbps = static_cast<int>((bitrate_ + 500) / 1000); | 143 int bitrate_kbps = static_cast<int>((bitrate_ + 500) / 1000); |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 179 // packet loss reported, to allow startup bitrate probing. | 178 // packet loss reported, to allow startup bitrate probing. |
| 180 if (last_fraction_loss_ == 0 && IsInStartPhase(now_ms) && | 179 if (last_fraction_loss_ == 0 && IsInStartPhase(now_ms) && |
| 181 bwe_incoming_ > bitrate_) { | 180 bwe_incoming_ > bitrate_) { |
| 182 bitrate_ = CapBitrateToThresholds(now_ms, bwe_incoming_); | 181 bitrate_ = CapBitrateToThresholds(now_ms, bwe_incoming_); |
| 183 min_bitrate_history_.clear(); | 182 min_bitrate_history_.clear(); |
| 184 min_bitrate_history_.push_back(std::make_pair(now_ms, bitrate_)); | 183 min_bitrate_history_.push_back(std::make_pair(now_ms, bitrate_)); |
| 185 return; | 184 return; |
| 186 } | 185 } |
| 187 UpdateMinHistory(now_ms); | 186 UpdateMinHistory(now_ms); |
| 188 // Only start updating bitrate when receiving receiver blocks. | 187 // Only start updating bitrate when receiving receiver blocks. |
| 189 if (time_last_receiver_block_ms_ != 0) { | 188 if (time_last_receiver_block_ms_ != -1) { |
|
mflodman
2015/10/22 07:06:57
I'd like to discuss if we should check already her
stefan-webrtc
2015/10/22 09:20:47
Are you talking about whether we should check for
mflodman
2015/10/22 11:22:29
Yes. But also, what happens if we're in an increas
stefan-webrtc
2015/10/22 11:28:06
Yes, if we don't have REMB this isn't great. Overa
pbos-webrtc
2015/10/22 13:16:06
Sure, I put a TODO for now.
| |
| 190 if (last_fraction_loss_ <= 5) { | 189 if (last_fraction_loss_ <= 5) { |
| 191 // Loss < 2%: Increase rate by 8% of the min bitrate in the last | 190 // Loss < 2%: Increase rate by 8% of the min bitrate in the last |
| 192 // kBweIncreaseIntervalMs. | 191 // kBweIncreaseIntervalMs. |
| 193 // Note that by remembering the bitrate over the last second one can | 192 // Note that by remembering the bitrate over the last second one can |
| 194 // rampup up one second faster than if only allowed to start ramping | 193 // rampup up one second faster than if only allowed to start ramping |
| 195 // at 8% per second rate now. E.g.: | 194 // at 8% per second rate now. E.g.: |
| 196 // If sending a constant 100kbps it can rampup immediatly to 108kbps | 195 // If sending a constant 100kbps it can rampup immediatly to 108kbps |
| 197 // whenever a receiver report is received with lower packet loss. | 196 // whenever a receiver report is received with lower packet loss. |
| 198 // If instead one would do: bitrate_ *= 1.08^(delta time), it would | 197 // 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. | 198 // take over one second since the lower packet loss to achieve 108kbps. |
| 200 bitrate_ = static_cast<uint32_t>( | 199 bitrate_ = static_cast<uint32_t>( |
| 201 min_bitrate_history_.front().second * 1.08 + 0.5); | 200 min_bitrate_history_.front().second * 1.08 + 0.5); |
| 202 | 201 |
| 203 // Add 1 kbps extra, just to make sure that we do not get stuck | 202 // 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 | 203 // (gives a little extra increase at low rates, negligible at higher |
| 205 // rates). | 204 // rates). |
| 206 bitrate_ += 1000; | 205 bitrate_ += 1000; |
| 207 | 206 |
| 208 } else if (last_fraction_loss_ <= 26) { | 207 } else if (last_fraction_loss_ <= 26) { |
| 209 // Loss between 2% - 10%: Do nothing. | 208 // Loss between 2% - 10%: Do nothing. |
| 210 | |
| 211 } else { | 209 } else { |
| 212 // Loss > 10%: Limit the rate decreases to once a kBweDecreaseIntervalMs + | 210 // Loss > 10%: Limit the rate decreases to once a kBweDecreaseIntervalMs + |
| 213 // rtt. | 211 // rtt. |
| 214 if ((now_ms - time_last_decrease_ms_) >= | 212 if (!has_decreased_since_last_fraction_loss_ && |
|
mflodman
2015/10/22 07:06:57
You can use 'accumulate_expected_packets_' instead
pbos-webrtc
2015/10/22 13:16:05
Nope, accumulate_expected_packets_ gets reset ever
mflodman
2015/10/22 14:34:34
I was unclear in this comment, but we can avoid th
pbos-webrtc
2015/10/22 14:59:45
That sounds like it'd be a bit harder to understan
| |
| 215 (kBweDecreaseIntervalMs + last_round_trip_time_ms_)) { | 213 (now_ms - time_last_decrease_ms_) >= |
| 214 (kBweDecreaseIntervalMs + last_round_trip_time_ms_)) { | |
| 216 time_last_decrease_ms_ = now_ms; | 215 time_last_decrease_ms_ = now_ms; |
| 217 | 216 |
| 218 // Reduce rate: | 217 // Reduce rate: |
| 219 // newRate = rate * (1 - 0.5*lossRate); | 218 // newRate = rate * (1 - 0.5*lossRate); |
| 220 // where packetLoss = 256*lossRate; | 219 // where packetLoss = 256*lossRate; |
| 221 bitrate_ = static_cast<uint32_t>( | 220 bitrate_ = static_cast<uint32_t>( |
| 222 (bitrate_ * static_cast<double>(512 - last_fraction_loss_)) / | 221 (bitrate_ * static_cast<double>(512 - last_fraction_loss_)) / |
| 223 512.0); | 222 512.0); |
| 223 has_decreased_since_last_fraction_loss_ = true; | |
| 224 } | 224 } |
| 225 } | 225 } |
| 226 } | 226 } |
| 227 bitrate_ = CapBitrateToThresholds(now_ms, bitrate_); | 227 bitrate_ = CapBitrateToThresholds(now_ms, bitrate_); |
| 228 } | 228 } |
| 229 | 229 |
| 230 bool SendSideBandwidthEstimation::IsInStartPhase(int64_t now_ms) const { | 230 bool SendSideBandwidthEstimation::IsInStartPhase(int64_t now_ms) const { |
| 231 return first_report_time_ms_ == -1 || | 231 return first_report_time_ms_ == -1 || |
| 232 now_ms - first_report_time_ms_ < kStartPhaseMs; | 232 now_ms - first_report_time_ms_ < kStartPhaseMs; |
| 233 } | 233 } |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 266 LOG(LS_WARNING) << "Estimated available bandwidth " << bitrate / 1000 | 266 LOG(LS_WARNING) << "Estimated available bandwidth " << bitrate / 1000 |
| 267 << " kbps is below configured min bitrate " | 267 << " kbps is below configured min bitrate " |
| 268 << min_bitrate_configured_ / 1000 << " kbps."; | 268 << min_bitrate_configured_ / 1000 << " kbps."; |
| 269 last_low_bitrate_log_ms_ = now_ms; | 269 last_low_bitrate_log_ms_ = now_ms; |
| 270 } | 270 } |
| 271 bitrate = min_bitrate_configured_; | 271 bitrate = min_bitrate_configured_; |
| 272 } | 272 } |
| 273 return bitrate; | 273 return bitrate; |
| 274 } | 274 } |
| 275 } // namespace webrtc | 275 } // namespace webrtc |
| OLD | NEW |