| OLD | NEW |
| 1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "net/quic/congestion_control/inter_arrival_sender.h" | 5 #include "net/quic/congestion_control/inter_arrival_sender.h" |
| 6 | 6 |
| 7 namespace net { | 7 namespace net { |
| 8 | 8 |
| 9 namespace { | 9 namespace { |
| 10 const int64 kProbeBitrateKBytesPerSecond = 1200; // 9.6 Mbit/s | 10 const int64 kProbeBitrateKBytesPerSecond = 1200; // 9.6 Mbit/s |
| 11 const float kPacketLossBitrateReduction = 0.7f; | 11 const float kPacketLossBitrateReduction = 0.7f; |
| 12 const float kUncertainSafetyMargin = 0.7f; | 12 const float kUncertainSafetyMargin = 0.7f; |
| 13 const float kMaxBitrateReduction = 0.9f; | 13 const float kMaxBitrateReduction = 0.9f; |
| 14 const float kMinBitrateReduction = 0.05f; | 14 const float kMinBitrateReduction = 0.05f; |
| 15 const uint64 kMinBitrateKbit = 10; | 15 const uint64 kMinBitrateKbit = 10; |
| 16 const int kInitialRttMs = 60; // At a typical RTT 60 ms. | 16 const int kInitialRttMs = 60; // At a typical RTT 60 ms. |
| 17 const float kAlpha = 0.125f; |
| 18 const float kOneMinusAlpha = 1 - kAlpha; |
| 17 | 19 |
| 18 static const int kBitrateSmoothingPeriodMs = 1000; | 20 static const int kBitrateSmoothingPeriodMs = 1000; |
| 19 static const int kMinBitrateSmoothingPeriodMs = 500; | 21 static const int kMinBitrateSmoothingPeriodMs = 500; |
| 20 | 22 |
| 21 } // namespace | 23 } // namespace |
| 22 | 24 |
| 23 InterArrivalSender::InterArrivalSender(const QuicClock* clock) | 25 InterArrivalSender::InterArrivalSender(const QuicClock* clock) |
| 24 : probing_(true), | 26 : probing_(true), |
| 25 current_bandwidth_(QuicBandwidth::Zero()), | 27 current_bandwidth_(QuicBandwidth::Zero()), |
| 26 smoothed_rtt_(QuicTime::Delta::Zero()), | 28 smoothed_rtt_(QuicTime::Delta::Zero()), |
| (...skipping 166 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 193 << available_channel_estimate.ToKBitsPerSecond() << " Kbits/s " | 195 << available_channel_estimate.ToKBitsPerSecond() << " Kbits/s " |
| 194 << " channel estimate:" | 196 << " channel estimate:" |
| 195 << channel_estimate.ToKBitsPerSecond() << " Kbits/s "; | 197 << channel_estimate.ToKBitsPerSecond() << " Kbits/s "; |
| 196 return false; | 198 return false; |
| 197 } | 199 } |
| 198 | 200 |
| 199 void InterArrivalSender::OnIncomingAck( | 201 void InterArrivalSender::OnIncomingAck( |
| 200 QuicPacketSequenceNumber /*acked_sequence_number*/, | 202 QuicPacketSequenceNumber /*acked_sequence_number*/, |
| 201 QuicByteCount acked_bytes, | 203 QuicByteCount acked_bytes, |
| 202 QuicTime::Delta rtt) { | 204 QuicTime::Delta rtt) { |
| 203 DCHECK(!rtt.IsZero()); | 205 // RTT can't be negative. |
| 204 DCHECK(!rtt.IsInfinite()); | 206 DCHECK_LE(0, rtt.ToMicroseconds()); |
| 207 |
| 208 if (probing_) { |
| 209 probe_->OnAcknowledgedPacket(acked_bytes); |
| 210 } |
| 211 |
| 212 if (rtt.IsInfinite()) { |
| 213 return; |
| 214 } |
| 215 |
| 205 if (smoothed_rtt_.IsZero()) { | 216 if (smoothed_rtt_.IsZero()) { |
| 206 smoothed_rtt_ = rtt; | 217 smoothed_rtt_ = rtt; |
| 207 } else { | 218 } else { |
| 208 smoothed_rtt_ = QuicTime::Delta::FromMicroseconds( | 219 smoothed_rtt_ = QuicTime::Delta::FromMicroseconds( |
| 209 (smoothed_rtt_.ToMicroseconds() * 3 + rtt.ToMicroseconds()) / 4); | 220 kOneMinusAlpha * smoothed_rtt_.ToMicroseconds() + |
| 221 kAlpha * rtt.ToMicroseconds()); |
| 210 } | 222 } |
| 211 state_machine_->set_rtt(SmoothedRtt()); | 223 state_machine_->set_rtt(smoothed_rtt_); |
| 212 if (probing_) { | |
| 213 probe_->OnAcknowledgedPacket(acked_bytes); | |
| 214 } | |
| 215 } | 224 } |
| 216 | 225 |
| 217 void InterArrivalSender::OnIncomingLoss(QuicTime ack_receive_time) { | 226 void InterArrivalSender::OnIncomingLoss(QuicTime ack_receive_time) { |
| 218 // Packet loss was reported. | 227 // Packet loss was reported. |
| 219 if (!probing_) { | 228 if (!probing_) { |
| 220 if (!state_machine_->PacketLossEvent()) { | 229 if (!state_machine_->PacketLossEvent()) { |
| 221 // Less than one RTT since last PacketLossEvent. | 230 // Less than one RTT since last PacketLossEvent. |
| 222 return; | 231 return; |
| 223 } | 232 } |
| 224 // Calculate new pace rate. | 233 // Calculate new pace rate. |
| (...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 298 return current_bandwidth_; | 307 return current_bandwidth_; |
| 299 } | 308 } |
| 300 | 309 |
| 301 QuicTime::Delta InterArrivalSender::SmoothedRtt() { | 310 QuicTime::Delta InterArrivalSender::SmoothedRtt() { |
| 302 if (smoothed_rtt_.IsZero()) { | 311 if (smoothed_rtt_.IsZero()) { |
| 303 return QuicTime::Delta::FromMilliseconds(kInitialRttMs); | 312 return QuicTime::Delta::FromMilliseconds(kInitialRttMs); |
| 304 } | 313 } |
| 305 return smoothed_rtt_; | 314 return smoothed_rtt_; |
| 306 } | 315 } |
| 307 | 316 |
| 317 QuicTime::Delta InterArrivalSender::RetransmissionDelay() { |
| 318 // TODO(pwestin): Calculate and return retransmission delay. |
| 319 // Use 2 * the smoothed RTT for now. |
| 320 return smoothed_rtt_.Add(smoothed_rtt_); |
| 321 } |
| 322 |
| 308 void InterArrivalSender::EstimateNewBandwidth(QuicTime feedback_receive_time, | 323 void InterArrivalSender::EstimateNewBandwidth(QuicTime feedback_receive_time, |
| 309 QuicBandwidth sent_bandwidth) { | 324 QuicBandwidth sent_bandwidth) { |
| 310 QuicBandwidth new_bandwidth = bitrate_ramp_up_->GetNewBitrate(sent_bandwidth); | 325 QuicBandwidth new_bandwidth = bitrate_ramp_up_->GetNewBitrate(sent_bandwidth); |
| 311 if (current_bandwidth_ == new_bandwidth) { | 326 if (current_bandwidth_ == new_bandwidth) { |
| 312 return; | 327 return; |
| 313 } | 328 } |
| 314 current_bandwidth_ = new_bandwidth; | 329 current_bandwidth_ = new_bandwidth; |
| 315 state_machine_->IncreaseBitrateDecision(); | 330 state_machine_->IncreaseBitrateDecision(); |
| 316 | 331 |
| 317 QuicBandwidth channel_estimate = QuicBandwidth::Zero(); | 332 QuicBandwidth channel_estimate = QuicBandwidth::Zero(); |
| (...skipping 162 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 480 bitrate_ramp_up_->Reset(new_rate, current_bandwidth_, channel_estimate); | 495 bitrate_ramp_up_->Reset(new_rate, current_bandwidth_, channel_estimate); |
| 481 if (new_rate != current_bandwidth_) { | 496 if (new_rate != current_bandwidth_) { |
| 482 current_bandwidth_ = new_rate; | 497 current_bandwidth_ = new_rate; |
| 483 paced_sender_->UpdateBandwidthEstimate(feedback_receive_time, | 498 paced_sender_->UpdateBandwidthEstimate(feedback_receive_time, |
| 484 current_bandwidth_); | 499 current_bandwidth_); |
| 485 state_machine_->DecreaseBitrateDecision(); | 500 state_machine_->DecreaseBitrateDecision(); |
| 486 } | 501 } |
| 487 } | 502 } |
| 488 | 503 |
| 489 } // namespace net | 504 } // namespace net |
| OLD | NEW |