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