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/congestion_controller/include/congestion_controller.h" | 11 #include "webrtc/modules/congestion_controller/include/congestion_controller.h" |
12 | 12 |
13 #include <algorithm> | 13 #include <algorithm> |
14 #include <memory> | 14 #include <memory> |
15 #include <vector> | 15 #include <vector> |
16 | 16 |
17 #include "webrtc/base/checks.h" | 17 #include "webrtc/base/checks.h" |
18 #include "webrtc/base/constructormagic.h" | 18 #include "webrtc/base/constructormagic.h" |
19 #include "webrtc/base/logging.h" | 19 #include "webrtc/base/logging.h" |
20 #include "webrtc/base/rate_limiter.h" | |
20 #include "webrtc/base/socket.h" | 21 #include "webrtc/base/socket.h" |
21 #include "webrtc/base/thread_annotations.h" | 22 #include "webrtc/base/thread_annotations.h" |
22 #include "webrtc/modules/bitrate_controller/include/bitrate_controller.h" | 23 #include "webrtc/modules/bitrate_controller/include/bitrate_controller.h" |
23 #include "webrtc/modules/congestion_controller/delay_based_bwe.h" | 24 #include "webrtc/modules/congestion_controller/delay_based_bwe.h" |
24 #include "webrtc/modules/remote_bitrate_estimator/include/send_time_history.h" | 25 #include "webrtc/modules/remote_bitrate_estimator/include/send_time_history.h" |
25 #include "webrtc/modules/remote_bitrate_estimator/remote_bitrate_estimator_abs_s end_time.h" | 26 #include "webrtc/modules/remote_bitrate_estimator/remote_bitrate_estimator_abs_s end_time.h" |
26 #include "webrtc/modules/remote_bitrate_estimator/remote_bitrate_estimator_singl e_stream.h" | 27 #include "webrtc/modules/remote_bitrate_estimator/remote_bitrate_estimator_singl e_stream.h" |
27 #include "webrtc/modules/utility/include/process_thread.h" | 28 #include "webrtc/modules/utility/include/process_thread.h" |
28 #include "webrtc/system_wrappers/include/critical_section_wrapper.h" | 29 #include "webrtc/system_wrappers/include/critical_section_wrapper.h" |
29 #include "webrtc/video/payload_router.h" | 30 #include "webrtc/video/payload_router.h" |
30 | 31 |
31 namespace webrtc { | 32 namespace webrtc { |
32 namespace { | 33 namespace { |
33 | 34 |
34 static const uint32_t kTimeOffsetSwitchThreshold = 30; | 35 static const uint32_t kTimeOffsetSwitchThreshold = 30; |
36 static const int64_t kMinRetransmitWindowSizeMs = 30; | |
37 static const int64_t kMaxRetransmitWindowSizeMs = 1000; | |
35 | 38 |
36 // Makes sure that the bitrate and the min, max values are in valid range. | 39 // Makes sure that the bitrate and the min, max values are in valid range. |
37 static void ClampBitrates(int* bitrate_bps, | 40 static void ClampBitrates(int* bitrate_bps, |
38 int* min_bitrate_bps, | 41 int* min_bitrate_bps, |
39 int* max_bitrate_bps) { | 42 int* max_bitrate_bps) { |
40 // TODO(holmer): We should make sure the default bitrates are set to 10 kbps, | 43 // TODO(holmer): We should make sure the default bitrates are set to 10 kbps, |
41 // and that we don't try to set the min bitrate to 0 from any applications. | 44 // and that we don't try to set the min bitrate to 0 from any applications. |
42 // The congestion controller should allow a min bitrate of 0. | 45 // The congestion controller should allow a min bitrate of 0. |
43 const int kMinBitrateBps = 10000; | 46 const int kMinBitrateBps = 10000; |
44 if (*min_bitrate_bps < kMinBitrateBps) | 47 if (*min_bitrate_bps < kMinBitrateBps) |
(...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
156 BitrateObserver* bitrate_observer, | 159 BitrateObserver* bitrate_observer, |
157 RemoteBitrateObserver* remote_bitrate_observer) | 160 RemoteBitrateObserver* remote_bitrate_observer) |
158 : clock_(clock), | 161 : clock_(clock), |
159 observer_(nullptr), | 162 observer_(nullptr), |
160 packet_router_(new PacketRouter()), | 163 packet_router_(new PacketRouter()), |
161 pacer_(new PacedSender(clock_, packet_router_.get())), | 164 pacer_(new PacedSender(clock_, packet_router_.get())), |
162 remote_bitrate_estimator_( | 165 remote_bitrate_estimator_( |
163 new WrappingBitrateEstimator(remote_bitrate_observer, clock_)), | 166 new WrappingBitrateEstimator(remote_bitrate_observer, clock_)), |
164 bitrate_controller_( | 167 bitrate_controller_( |
165 BitrateController::CreateBitrateController(clock_, bitrate_observer)), | 168 BitrateController::CreateBitrateController(clock_, bitrate_observer)), |
169 retransmission_rate_limiter_( | |
170 new RateLimiter(clock, kMaxRetransmitWindowSizeMs)), | |
166 remote_estimator_proxy_(clock_, packet_router_.get()), | 171 remote_estimator_proxy_(clock_, packet_router_.get()), |
167 transport_feedback_adapter_(bitrate_controller_.get(), clock_), | 172 transport_feedback_adapter_(bitrate_controller_.get(), clock_), |
168 min_bitrate_bps_(RemoteBitrateEstimator::kDefaultMinBitrateBps), | 173 min_bitrate_bps_(RemoteBitrateEstimator::kDefaultMinBitrateBps), |
169 last_reported_bitrate_bps_(0), | 174 last_reported_bitrate_bps_(0), |
170 last_reported_fraction_loss_(0), | 175 last_reported_fraction_loss_(0), |
171 last_reported_rtt_(0), | 176 last_reported_rtt_(0), |
172 network_state_(kNetworkUp) { | 177 network_state_(kNetworkUp) { |
173 Init(); | 178 Init(); |
174 } | 179 } |
175 | 180 |
176 CongestionController::CongestionController( | 181 CongestionController::CongestionController( |
177 Clock* clock, | 182 Clock* clock, |
178 Observer* observer, | 183 Observer* observer, |
179 RemoteBitrateObserver* remote_bitrate_observer) | 184 RemoteBitrateObserver* remote_bitrate_observer) |
180 : clock_(clock), | 185 : clock_(clock), |
181 observer_(observer), | 186 observer_(observer), |
182 packet_router_(new PacketRouter()), | 187 packet_router_(new PacketRouter()), |
183 pacer_(new PacedSender(clock_, packet_router_.get())), | 188 pacer_(new PacedSender(clock_, packet_router_.get())), |
184 remote_bitrate_estimator_( | 189 remote_bitrate_estimator_( |
185 new WrappingBitrateEstimator(remote_bitrate_observer, clock_)), | 190 new WrappingBitrateEstimator(remote_bitrate_observer, clock_)), |
186 bitrate_controller_(BitrateController::CreateBitrateController(clock_)), | 191 bitrate_controller_(BitrateController::CreateBitrateController(clock_)), |
192 retransmission_rate_limiter_( | |
193 new RateLimiter(clock, kMaxRetransmitWindowSizeMs)), | |
187 remote_estimator_proxy_(clock_, packet_router_.get()), | 194 remote_estimator_proxy_(clock_, packet_router_.get()), |
188 transport_feedback_adapter_(bitrate_controller_.get(), clock_), | 195 transport_feedback_adapter_(bitrate_controller_.get(), clock_), |
189 min_bitrate_bps_(RemoteBitrateEstimator::kDefaultMinBitrateBps), | 196 min_bitrate_bps_(RemoteBitrateEstimator::kDefaultMinBitrateBps), |
190 last_reported_bitrate_bps_(0), | 197 last_reported_bitrate_bps_(0), |
191 last_reported_fraction_loss_(0), | 198 last_reported_fraction_loss_(0), |
192 last_reported_rtt_(0), | 199 last_reported_rtt_(0), |
193 network_state_(kNetworkUp) { | 200 network_state_(kNetworkUp) { |
194 Init(); | 201 Init(); |
195 } | 202 } |
196 | 203 |
197 CongestionController::CongestionController( | 204 CongestionController::CongestionController( |
198 Clock* clock, | 205 Clock* clock, |
199 Observer* observer, | 206 Observer* observer, |
200 RemoteBitrateObserver* remote_bitrate_observer, | 207 RemoteBitrateObserver* remote_bitrate_observer, |
201 std::unique_ptr<PacketRouter> packet_router, | 208 std::unique_ptr<PacketRouter> packet_router, |
202 std::unique_ptr<PacedSender> pacer) | 209 std::unique_ptr<PacedSender> pacer) |
203 : clock_(clock), | 210 : clock_(clock), |
204 observer_(observer), | 211 observer_(observer), |
205 packet_router_(std::move(packet_router)), | 212 packet_router_(std::move(packet_router)), |
206 pacer_(std::move(pacer)), | 213 pacer_(std::move(pacer)), |
207 remote_bitrate_estimator_( | 214 remote_bitrate_estimator_( |
208 new WrappingBitrateEstimator(remote_bitrate_observer, clock_)), | 215 new WrappingBitrateEstimator(remote_bitrate_observer, clock_)), |
209 // Constructed last as this object calls the provided callback on | 216 // Constructed last as this object calls the provided callback on |
210 // construction. | 217 // construction. |
211 bitrate_controller_(BitrateController::CreateBitrateController(clock_)), | 218 bitrate_controller_(BitrateController::CreateBitrateController(clock_)), |
219 retransmission_rate_limiter_( | |
220 new RateLimiter(clock, kMaxRetransmitWindowSizeMs)), | |
212 remote_estimator_proxy_(clock_, packet_router_.get()), | 221 remote_estimator_proxy_(clock_, packet_router_.get()), |
213 transport_feedback_adapter_(bitrate_controller_.get(), clock_), | 222 transport_feedback_adapter_(bitrate_controller_.get(), clock_), |
214 min_bitrate_bps_(RemoteBitrateEstimator::kDefaultMinBitrateBps), | 223 min_bitrate_bps_(RemoteBitrateEstimator::kDefaultMinBitrateBps), |
215 last_reported_bitrate_bps_(0), | 224 last_reported_bitrate_bps_(0), |
216 last_reported_fraction_loss_(0), | 225 last_reported_fraction_loss_(0), |
217 last_reported_rtt_(0), | 226 last_reported_rtt_(0), |
218 network_state_(kNetworkUp) { | 227 network_state_(kNetworkUp) { |
219 Init(); | 228 Init(); |
220 } | 229 } |
221 | 230 |
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
277 } else { | 286 } else { |
278 return remote_bitrate_estimator_.get(); | 287 return remote_bitrate_estimator_.get(); |
279 } | 288 } |
280 } | 289 } |
281 | 290 |
282 TransportFeedbackObserver* | 291 TransportFeedbackObserver* |
283 CongestionController::GetTransportFeedbackObserver() { | 292 CongestionController::GetTransportFeedbackObserver() { |
284 return &transport_feedback_adapter_; | 293 return &transport_feedback_adapter_; |
285 } | 294 } |
286 | 295 |
296 RateLimiter* CongestionController::GetRetransmissionRateLimiter() { | |
297 return retransmission_rate_limiter_.get(); | |
298 } | |
299 | |
287 void CongestionController::SetAllocatedSendBitrateLimits( | 300 void CongestionController::SetAllocatedSendBitrateLimits( |
288 int min_send_bitrate_bps, | 301 int min_send_bitrate_bps, |
289 int max_padding_bitrate_bps) { | 302 int max_padding_bitrate_bps) { |
290 pacer_->SetSendBitrateLimits(min_send_bitrate_bps, max_padding_bitrate_bps); | 303 pacer_->SetSendBitrateLimits(min_send_bitrate_bps, max_padding_bitrate_bps); |
291 } | 304 } |
292 | 305 |
293 int64_t CongestionController::GetPacerQueuingDelayMs() const { | 306 int64_t CongestionController::GetPacerQueuingDelayMs() const { |
294 return pacer_->QueueInMs(); | 307 return pacer_->QueueInMs(); |
295 } | 308 } |
296 | 309 |
(...skipping 11 matching lines...) Expand all Loading... | |
308 } | 321 } |
309 | 322 |
310 void CongestionController::OnSentPacket(const rtc::SentPacket& sent_packet) { | 323 void CongestionController::OnSentPacket(const rtc::SentPacket& sent_packet) { |
311 transport_feedback_adapter_.OnSentPacket(sent_packet.packet_id, | 324 transport_feedback_adapter_.OnSentPacket(sent_packet.packet_id, |
312 sent_packet.send_time_ms); | 325 sent_packet.send_time_ms); |
313 } | 326 } |
314 | 327 |
315 void CongestionController::OnRttUpdate(int64_t avg_rtt_ms, int64_t max_rtt_ms) { | 328 void CongestionController::OnRttUpdate(int64_t avg_rtt_ms, int64_t max_rtt_ms) { |
316 remote_bitrate_estimator_->OnRttUpdate(avg_rtt_ms, max_rtt_ms); | 329 remote_bitrate_estimator_->OnRttUpdate(avg_rtt_ms, max_rtt_ms); |
317 transport_feedback_adapter_.OnRttUpdate(avg_rtt_ms, max_rtt_ms); | 330 transport_feedback_adapter_.OnRttUpdate(avg_rtt_ms, max_rtt_ms); |
331 | |
332 int64_t nack_window_size_ms = max_rtt_ms; | |
333 if (nack_window_size_ms > kMaxRetransmitWindowSizeMs) { | |
334 nack_window_size_ms = kMaxRetransmitWindowSizeMs; | |
335 } else if (nack_window_size_ms < kMinRetransmitWindowSizeMs) { | |
336 nack_window_size_ms = kMinRetransmitWindowSizeMs; | |
337 } | |
338 retransmission_rate_limiter_->SetWindowSize(nack_window_size_ms); | |
stefan-webrtc
2016/07/06 12:43:21
CongestionController doesn't know anything about r
sprang_webrtc
2016/07/06 14:13:07
Maybe not. It had all the needed data to do the jo
| |
318 } | 339 } |
319 | 340 |
320 int64_t CongestionController::TimeUntilNextProcess() { | 341 int64_t CongestionController::TimeUntilNextProcess() { |
321 return std::min(bitrate_controller_->TimeUntilNextProcess(), | 342 return std::min(bitrate_controller_->TimeUntilNextProcess(), |
322 remote_bitrate_estimator_->TimeUntilNextProcess()); | 343 remote_bitrate_estimator_->TimeUntilNextProcess()); |
323 } | 344 } |
324 | 345 |
325 void CongestionController::Process() { | 346 void CongestionController::Process() { |
326 bitrate_controller_->Process(); | 347 bitrate_controller_->Process(); |
327 remote_bitrate_estimator_->Process(); | 348 remote_bitrate_estimator_->Process(); |
328 MaybeTriggerOnNetworkChanged(); | 349 MaybeTriggerOnNetworkChanged(); |
329 } | 350 } |
330 | 351 |
331 void CongestionController::MaybeTriggerOnNetworkChanged() { | 352 void CongestionController::MaybeTriggerOnNetworkChanged() { |
332 // TODO(perkj): |observer_| can be nullptr if the ctor that accepts a | 353 // TODO(perkj): |observer_| can be nullptr if the ctor that accepts a |
333 // BitrateObserver is used. Remove this check once the ctor is removed. | 354 // BitrateObserver is used. Remove this check once the ctor is removed. |
334 if (!observer_) | 355 if (!observer_) |
335 return; | 356 return; |
336 | 357 |
337 uint32_t bitrate_bps; | 358 uint32_t bitrate_bps; |
338 uint8_t fraction_loss; | 359 uint8_t fraction_loss; |
339 int64_t rtt; | 360 int64_t rtt; |
340 bool estimate_changed = bitrate_controller_->GetNetworkParameters( | 361 bool estimate_changed = bitrate_controller_->GetNetworkParameters( |
341 &bitrate_bps, &fraction_loss, &rtt); | 362 &bitrate_bps, &fraction_loss, &rtt); |
342 if (estimate_changed) | 363 if (estimate_changed) { |
343 pacer_->SetEstimatedBitrate(bitrate_bps); | 364 pacer_->SetEstimatedBitrate(bitrate_bps); |
365 retransmission_rate_limiter_->SetMaxRate(bitrate_bps); | |
366 } | |
344 | 367 |
345 bitrate_bps = IsNetworkDown() || IsSendQueueFull() ? 0 : bitrate_bps; | 368 bitrate_bps = IsNetworkDown() || IsSendQueueFull() ? 0 : bitrate_bps; |
346 | 369 |
347 if (HasNetworkParametersToReportChanged(bitrate_bps, fraction_loss, rtt)) { | 370 if (HasNetworkParametersToReportChanged(bitrate_bps, fraction_loss, rtt)) { |
348 observer_->OnNetworkChanged(bitrate_bps, fraction_loss, rtt); | 371 observer_->OnNetworkChanged(bitrate_bps, fraction_loss, rtt); |
349 } | 372 } |
350 } | 373 } |
351 | 374 |
352 bool CongestionController::HasNetworkParametersToReportChanged( | 375 bool CongestionController::HasNetworkParametersToReportChanged( |
353 uint32_t bitrate_bps, | 376 uint32_t bitrate_bps, |
(...skipping 13 matching lines...) Expand all Loading... | |
367 bool CongestionController::IsSendQueueFull() const { | 390 bool CongestionController::IsSendQueueFull() const { |
368 return pacer_->ExpectedQueueTimeMs() > PacedSender::kMaxQueueLengthMs; | 391 return pacer_->ExpectedQueueTimeMs() > PacedSender::kMaxQueueLengthMs; |
369 } | 392 } |
370 | 393 |
371 bool CongestionController::IsNetworkDown() const { | 394 bool CongestionController::IsNetworkDown() const { |
372 rtc::CritScope cs(&critsect_); | 395 rtc::CritScope cs(&critsect_); |
373 return network_state_ == kNetworkDown; | 396 return network_state_ == kNetworkDown; |
374 } | 397 } |
375 | 398 |
376 } // namespace webrtc | 399 } // namespace webrtc |
OLD | NEW |