OLD | NEW |
1 /* | 1 /* |
2 * Copyright (c) 2014 The WebRTC project authors. All Rights Reserved. | 2 * Copyright (c) 2014 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 19 matching lines...) Expand all Loading... |
30 avg_max_bitrate_kbps_(-1.0f), | 30 avg_max_bitrate_kbps_(-1.0f), |
31 var_max_bitrate_kbps_(0.4f), | 31 var_max_bitrate_kbps_(0.4f), |
32 rate_control_state_(kRcHold), | 32 rate_control_state_(kRcHold), |
33 came_from_state_(kRcDecrease), | 33 came_from_state_(kRcDecrease), |
34 rate_control_region_(kRcMaxUnknown), | 34 rate_control_region_(kRcMaxUnknown), |
35 time_last_bitrate_change_(-1), | 35 time_last_bitrate_change_(-1), |
36 current_input_(kBwNormal, 0, 1.0), | 36 current_input_(kBwNormal, 0, 1.0), |
37 updated_(false), | 37 updated_(false), |
38 time_first_incoming_estimate_(-1), | 38 time_first_incoming_estimate_(-1), |
39 bitrate_is_initialized_(false), | 39 bitrate_is_initialized_(false), |
40 beta_(0.9f), | 40 beta_(0.85f), |
41 rtt_(kDefaultRttMs), | 41 rtt_(kDefaultRttMs), |
42 time_of_last_log_(-1) {} | 42 time_of_last_log_(-1) { |
| 43 } |
43 | 44 |
44 RateControlType AimdRateControl::GetControlType() const { | 45 RateControlType AimdRateControl::GetControlType() const { |
45 return kAimdControl; | 46 return kAimdControl; |
46 } | 47 } |
47 | 48 |
48 uint32_t AimdRateControl::GetMinBitrate() const { | 49 uint32_t AimdRateControl::GetMinBitrate() const { |
49 return min_configured_bitrate_bps_; | 50 return min_configured_bitrate_bps_; |
50 } | 51 } |
51 | 52 |
52 bool AimdRateControl::ValidEstimate() const { | 53 bool AimdRateControl::ValidEstimate() const { |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
91 if (now_ms - time_of_last_log_ > kLogIntervalMs) { | 92 if (now_ms - time_of_last_log_ > kLogIntervalMs) { |
92 time_of_last_log_ = now_ms; | 93 time_of_last_log_ = now_ms; |
93 } | 94 } |
94 return current_bitrate_bps_; | 95 return current_bitrate_bps_; |
95 } | 96 } |
96 | 97 |
97 void AimdRateControl::SetRtt(int64_t rtt) { | 98 void AimdRateControl::SetRtt(int64_t rtt) { |
98 rtt_ = rtt; | 99 rtt_ = rtt; |
99 } | 100 } |
100 | 101 |
101 RateControlRegion AimdRateControl::Update(const RateControlInput* input, | 102 void AimdRateControl::Update(const RateControlInput* input, int64_t now_ms) { |
102 int64_t now_ms) { | |
103 assert(input); | 103 assert(input); |
104 | 104 |
105 // Set the initial bit rate value to what we're receiving the first half | 105 // Set the initial bit rate value to what we're receiving the first half |
106 // second. | 106 // second. |
107 if (!bitrate_is_initialized_) { | 107 if (!bitrate_is_initialized_) { |
108 if (time_first_incoming_estimate_ < 0) { | 108 if (time_first_incoming_estimate_ < 0) { |
109 if (input->_incomingBitRate > 0) { | 109 if (input->_incomingBitRate > 0) { |
110 time_first_incoming_estimate_ = now_ms; | 110 time_first_incoming_estimate_ = now_ms; |
111 } | 111 } |
112 } else if (now_ms - time_first_incoming_estimate_ > 500 && | 112 } else if (now_ms - time_first_incoming_estimate_ > 500 && |
113 input->_incomingBitRate > 0) { | 113 input->_incomingBitRate > 0) { |
114 current_bitrate_bps_ = input->_incomingBitRate; | 114 current_bitrate_bps_ = input->_incomingBitRate; |
115 bitrate_is_initialized_ = true; | 115 bitrate_is_initialized_ = true; |
116 } | 116 } |
117 } | 117 } |
118 | 118 |
119 if (updated_ && current_input_._bwState == kBwOverusing) { | 119 if (updated_ && current_input_._bwState == kBwOverusing) { |
120 // Only update delay factor and incoming bit rate. We always want to react | 120 // Only update delay factor and incoming bit rate. We always want to react |
121 // on an over-use. | 121 // on an over-use. |
122 current_input_._noiseVar = input->_noiseVar; | 122 current_input_._noiseVar = input->_noiseVar; |
123 current_input_._incomingBitRate = input->_incomingBitRate; | 123 current_input_._incomingBitRate = input->_incomingBitRate; |
124 } else { | 124 } else { |
125 updated_ = true; | 125 updated_ = true; |
126 current_input_ = *input; | 126 current_input_ = *input; |
127 } | 127 } |
128 return rate_control_region_; | |
129 } | 128 } |
130 | 129 |
131 void AimdRateControl::SetEstimate(int bitrate_bps, int64_t now_ms) { | 130 void AimdRateControl::SetEstimate(int bitrate_bps, int64_t now_ms) { |
132 updated_ = true; | 131 updated_ = true; |
133 bitrate_is_initialized_ = true; | 132 bitrate_is_initialized_ = true; |
134 current_bitrate_bps_ = ChangeBitrate(bitrate_bps, bitrate_bps, now_ms); | 133 current_bitrate_bps_ = ChangeBitrate(bitrate_bps, bitrate_bps, now_ms); |
135 } | 134 } |
136 | 135 |
137 uint32_t AimdRateControl::ChangeBitrate(uint32_t current_bitrate_bps, | 136 uint32_t AimdRateControl::ChangeBitrate(uint32_t current_bitrate_bps, |
138 uint32_t incoming_bitrate_bps, | 137 uint32_t incoming_bitrate_bps, |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
171 uint32_t additive_increase_bps = AdditiveRateIncrease( | 170 uint32_t additive_increase_bps = AdditiveRateIncrease( |
172 now_ms, time_last_bitrate_change_, response_time); | 171 now_ms, time_last_bitrate_change_, response_time); |
173 current_bitrate_bps += additive_increase_bps; | 172 current_bitrate_bps += additive_increase_bps; |
174 | 173 |
175 } else { | 174 } else { |
176 uint32_t multiplicative_increase_bps = MultiplicativeRateIncrease( | 175 uint32_t multiplicative_increase_bps = MultiplicativeRateIncrease( |
177 now_ms, time_last_bitrate_change_, current_bitrate_bps); | 176 now_ms, time_last_bitrate_change_, current_bitrate_bps); |
178 current_bitrate_bps += multiplicative_increase_bps; | 177 current_bitrate_bps += multiplicative_increase_bps; |
179 } | 178 } |
180 | 179 |
181 if (max_hold_rate_bps_ > 0 && | |
182 beta_ * max_hold_rate_bps_ > current_bitrate_bps) { | |
183 current_bitrate_bps = static_cast<uint32_t>(beta_ * max_hold_rate_bps_); | |
184 avg_max_bitrate_kbps_ = beta_ * max_hold_rate_bps_ / 1000.0f; | |
185 ChangeRegion(kRcNearMax); | |
186 fast_recovery_after_hold = true; | |
187 } | |
188 max_hold_rate_bps_ = 0; | |
189 time_last_bitrate_change_ = now_ms; | 180 time_last_bitrate_change_ = now_ms; |
190 break; | 181 break; |
191 } | 182 } |
192 case kRcDecrease: { | 183 case kRcDecrease: { |
193 if (incoming_bitrate_bps < min_configured_bitrate_bps_) { | 184 if (incoming_bitrate_bps < min_configured_bitrate_bps_) { |
194 current_bitrate_bps = min_configured_bitrate_bps_; | 185 current_bitrate_bps = min_configured_bitrate_bps_; |
195 } else { | 186 } else { |
196 // Set bit rate to something slightly lower than max | 187 // Set bit rate to something slightly lower than max |
197 // to get rid of any self-induced delay. | 188 // to get rid of any self-induced delay. |
198 current_bitrate_bps = static_cast<uint32_t>(beta_ * | 189 current_bitrate_bps = static_cast<uint32_t>(beta_ * |
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
245 uint32_t multiplicative_increase_bps = std::max( | 236 uint32_t multiplicative_increase_bps = std::max( |
246 current_bitrate_bps * (alpha - 1.0), 1000.0); | 237 current_bitrate_bps * (alpha - 1.0), 1000.0); |
247 return multiplicative_increase_bps; | 238 return multiplicative_increase_bps; |
248 } | 239 } |
249 | 240 |
250 uint32_t AimdRateControl::AdditiveRateIncrease( | 241 uint32_t AimdRateControl::AdditiveRateIncrease( |
251 int64_t now_ms, int64_t last_ms, int64_t response_time_ms) const { | 242 int64_t now_ms, int64_t last_ms, int64_t response_time_ms) const { |
252 assert(response_time_ms > 0); | 243 assert(response_time_ms > 0); |
253 double beta = 0.0; | 244 double beta = 0.0; |
254 if (last_ms > 0) { | 245 if (last_ms > 0) { |
255 beta = std::min((now_ms - last_ms) / | 246 beta = 0.5 * |
256 static_cast<double>(response_time_ms), 1.0); | 247 std::min((now_ms - last_ms) / static_cast<double>(response_time_ms), |
| 248 1.0); |
257 } | 249 } |
258 double bits_per_frame = static_cast<double>(current_bitrate_bps_) / 30.0; | 250 double bits_per_frame = static_cast<double>(current_bitrate_bps_) / 30.0; |
259 double packets_per_frame = std::ceil(bits_per_frame / (8.0 * 1200.0)); | 251 double packets_per_frame = std::ceil(bits_per_frame / (8.0 * 1200.0)); |
260 double avg_packet_size_bits = bits_per_frame / packets_per_frame; | 252 double avg_packet_size_bits = bits_per_frame / packets_per_frame; |
261 uint32_t additive_increase_bps = std::max( | 253 uint32_t additive_increase_bps = std::max( |
262 1000.0, beta * avg_packet_size_bits); | 254 1000.0, beta * avg_packet_size_bits); |
263 return additive_increase_bps; | 255 return additive_increase_bps; |
264 } | 256 } |
265 | 257 |
266 void AimdRateControl::UpdateMaxBitRateEstimate(float incoming_bitrate_kbps) { | 258 void AimdRateControl::UpdateMaxBitRateEstimate(float incoming_bitrate_kbps) { |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
304 case kBwUnderusing: | 296 case kBwUnderusing: |
305 ChangeState(kRcHold); | 297 ChangeState(kRcHold); |
306 break; | 298 break; |
307 default: | 299 default: |
308 assert(false); | 300 assert(false); |
309 } | 301 } |
310 } | 302 } |
311 | 303 |
312 void AimdRateControl::ChangeRegion(RateControlRegion region) { | 304 void AimdRateControl::ChangeRegion(RateControlRegion region) { |
313 rate_control_region_ = region; | 305 rate_control_region_ = region; |
314 switch (rate_control_region_) { | |
315 case kRcAboveMax: | |
316 case kRcMaxUnknown: | |
317 beta_ = 0.9f; | |
318 break; | |
319 case kRcNearMax: | |
320 beta_ = 0.95f; | |
321 break; | |
322 default: | |
323 assert(false); | |
324 } | |
325 } | 306 } |
326 | 307 |
327 void AimdRateControl::ChangeState(RateControlState new_state) { | 308 void AimdRateControl::ChangeState(RateControlState new_state) { |
328 came_from_state_ = rate_control_state_; | 309 came_from_state_ = rate_control_state_; |
329 rate_control_state_ = new_state; | 310 rate_control_state_ = new_state; |
330 } | 311 } |
331 } // namespace webrtc | 312 } // namespace webrtc |
OLD | NEW |