Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1088)

Side by Side Diff: webrtc/modules/congestion_controller/congestion_controller.cc

Issue 2146013002: Reland of actor NACK bitrate allocation (Closed) Base URL: https://chromium.googlesource.com/external/webrtc.git@master
Patch Set: Created 4 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 112 matching lines...) Expand 10 before | Expand all | Expand 10 after
157 RemoteBitrateObserver* remote_bitrate_observer, 160 RemoteBitrateObserver* remote_bitrate_observer,
158 RtcEventLog* event_log) 161 RtcEventLog* event_log)
159 : clock_(clock), 162 : clock_(clock),
160 observer_(observer), 163 observer_(observer),
161 packet_router_(new PacketRouter()), 164 packet_router_(new PacketRouter()),
162 pacer_(new PacedSender(clock_, packet_router_.get())), 165 pacer_(new PacedSender(clock_, packet_router_.get())),
163 remote_bitrate_estimator_( 166 remote_bitrate_estimator_(
164 new WrappingBitrateEstimator(remote_bitrate_observer, clock_)), 167 new WrappingBitrateEstimator(remote_bitrate_observer, clock_)),
165 bitrate_controller_( 168 bitrate_controller_(
166 BitrateController::CreateBitrateController(clock_, event_log)), 169 BitrateController::CreateBitrateController(clock_, event_log)),
170 retransmission_rate_limiter_(
171 new RateLimiter(clock, kMaxRetransmitWindowSizeMs)),
167 remote_estimator_proxy_(clock_, packet_router_.get()), 172 remote_estimator_proxy_(clock_, packet_router_.get()),
168 transport_feedback_adapter_(bitrate_controller_.get(), clock_), 173 transport_feedback_adapter_(bitrate_controller_.get(), clock_),
169 min_bitrate_bps_(RemoteBitrateEstimator::kDefaultMinBitrateBps), 174 min_bitrate_bps_(RemoteBitrateEstimator::kDefaultMinBitrateBps),
170 last_reported_bitrate_bps_(0), 175 last_reported_bitrate_bps_(0),
171 last_reported_fraction_loss_(0), 176 last_reported_fraction_loss_(0),
172 last_reported_rtt_(0), 177 last_reported_rtt_(0),
173 network_state_(kNetworkUp) { 178 network_state_(kNetworkUp) {
174 Init(); 179 Init();
175 } 180 }
176 181
177 CongestionController::CongestionController( 182 CongestionController::CongestionController(
178 Clock* clock, 183 Clock* clock,
179 Observer* observer, 184 Observer* observer,
180 RemoteBitrateObserver* remote_bitrate_observer, 185 RemoteBitrateObserver* remote_bitrate_observer,
181 RtcEventLog* event_log, 186 RtcEventLog* event_log,
182 std::unique_ptr<PacketRouter> packet_router, 187 std::unique_ptr<PacketRouter> packet_router,
183 std::unique_ptr<PacedSender> pacer) 188 std::unique_ptr<PacedSender> pacer)
184 : clock_(clock), 189 : clock_(clock),
185 observer_(observer), 190 observer_(observer),
186 packet_router_(std::move(packet_router)), 191 packet_router_(std::move(packet_router)),
187 pacer_(std::move(pacer)), 192 pacer_(std::move(pacer)),
188 remote_bitrate_estimator_( 193 remote_bitrate_estimator_(
189 new WrappingBitrateEstimator(remote_bitrate_observer, clock_)), 194 new WrappingBitrateEstimator(remote_bitrate_observer, clock_)),
190 // Constructed last as this object calls the provided callback on 195 // Constructed last as this object calls the provided callback on
191 // construction. 196 // construction.
192 bitrate_controller_( 197 bitrate_controller_(
193 BitrateController::CreateBitrateController(clock_, event_log)), 198 BitrateController::CreateBitrateController(clock_, event_log)),
199 retransmission_rate_limiter_(
200 new RateLimiter(clock, kMaxRetransmitWindowSizeMs)),
194 remote_estimator_proxy_(clock_, packet_router_.get()), 201 remote_estimator_proxy_(clock_, packet_router_.get()),
195 transport_feedback_adapter_(bitrate_controller_.get(), clock_), 202 transport_feedback_adapter_(bitrate_controller_.get(), clock_),
196 min_bitrate_bps_(RemoteBitrateEstimator::kDefaultMinBitrateBps), 203 min_bitrate_bps_(RemoteBitrateEstimator::kDefaultMinBitrateBps),
197 last_reported_bitrate_bps_(0), 204 last_reported_bitrate_bps_(0),
198 last_reported_fraction_loss_(0), 205 last_reported_fraction_loss_(0),
199 last_reported_rtt_(0), 206 last_reported_rtt_(0),
200 network_state_(kNetworkUp) { 207 network_state_(kNetworkUp) {
201 Init(); 208 Init();
202 } 209 }
203 210
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after
259 } else { 266 } else {
260 return remote_bitrate_estimator_.get(); 267 return remote_bitrate_estimator_.get();
261 } 268 }
262 } 269 }
263 270
264 TransportFeedbackObserver* 271 TransportFeedbackObserver*
265 CongestionController::GetTransportFeedbackObserver() { 272 CongestionController::GetTransportFeedbackObserver() {
266 return &transport_feedback_adapter_; 273 return &transport_feedback_adapter_;
267 } 274 }
268 275
276 RateLimiter* CongestionController::GetRetransmissionRateLimiter() {
277 return retransmission_rate_limiter_.get();
278 }
279
269 void CongestionController::SetAllocatedSendBitrateLimits( 280 void CongestionController::SetAllocatedSendBitrateLimits(
270 int min_send_bitrate_bps, 281 int min_send_bitrate_bps,
271 int max_padding_bitrate_bps) { 282 int max_padding_bitrate_bps) {
272 pacer_->SetSendBitrateLimits(min_send_bitrate_bps, max_padding_bitrate_bps); 283 pacer_->SetSendBitrateLimits(min_send_bitrate_bps, max_padding_bitrate_bps);
273 } 284 }
274 285
275 int64_t CongestionController::GetPacerQueuingDelayMs() const { 286 int64_t CongestionController::GetPacerQueuingDelayMs() const {
276 return pacer_->QueueInMs(); 287 return pacer_->QueueInMs();
277 } 288 }
278 289
(...skipping 13 matching lines...) Expand all
292 } 303 }
293 304
294 void CongestionController::OnSentPacket(const rtc::SentPacket& sent_packet) { 305 void CongestionController::OnSentPacket(const rtc::SentPacket& sent_packet) {
295 transport_feedback_adapter_.OnSentPacket(sent_packet.packet_id, 306 transport_feedback_adapter_.OnSentPacket(sent_packet.packet_id,
296 sent_packet.send_time_ms); 307 sent_packet.send_time_ms);
297 } 308 }
298 309
299 void CongestionController::OnRttUpdate(int64_t avg_rtt_ms, int64_t max_rtt_ms) { 310 void CongestionController::OnRttUpdate(int64_t avg_rtt_ms, int64_t max_rtt_ms) {
300 remote_bitrate_estimator_->OnRttUpdate(avg_rtt_ms, max_rtt_ms); 311 remote_bitrate_estimator_->OnRttUpdate(avg_rtt_ms, max_rtt_ms);
301 transport_feedback_adapter_.OnRttUpdate(avg_rtt_ms, max_rtt_ms); 312 transport_feedback_adapter_.OnRttUpdate(avg_rtt_ms, max_rtt_ms);
313
314 int64_t nack_window_size_ms = max_rtt_ms;
315 if (nack_window_size_ms > kMaxRetransmitWindowSizeMs) {
316 nack_window_size_ms = kMaxRetransmitWindowSizeMs;
317 } else if (nack_window_size_ms < kMinRetransmitWindowSizeMs) {
318 nack_window_size_ms = kMinRetransmitWindowSizeMs;
319 }
320 retransmission_rate_limiter_->SetWindowSize(nack_window_size_ms);
302 } 321 }
303 322
304 int64_t CongestionController::TimeUntilNextProcess() { 323 int64_t CongestionController::TimeUntilNextProcess() {
305 return std::min(bitrate_controller_->TimeUntilNextProcess(), 324 return std::min(bitrate_controller_->TimeUntilNextProcess(),
306 remote_bitrate_estimator_->TimeUntilNextProcess()); 325 remote_bitrate_estimator_->TimeUntilNextProcess());
307 } 326 }
308 327
309 void CongestionController::Process() { 328 void CongestionController::Process() {
310 bitrate_controller_->Process(); 329 bitrate_controller_->Process();
311 remote_bitrate_estimator_->Process(); 330 remote_bitrate_estimator_->Process();
312 MaybeTriggerOnNetworkChanged(); 331 MaybeTriggerOnNetworkChanged();
313 } 332 }
314 333
315 void CongestionController::MaybeTriggerOnNetworkChanged() { 334 void CongestionController::MaybeTriggerOnNetworkChanged() {
316 // TODO(perkj): |observer_| can be nullptr if the ctor that accepts a 335 // TODO(perkj): |observer_| can be nullptr if the ctor that accepts a
317 // BitrateObserver is used. Remove this check once the ctor is removed. 336 // BitrateObserver is used. Remove this check once the ctor is removed.
318 if (!observer_) 337 if (!observer_)
319 return; 338 return;
320 339
321 uint32_t bitrate_bps; 340 uint32_t bitrate_bps;
322 uint8_t fraction_loss; 341 uint8_t fraction_loss;
323 int64_t rtt; 342 int64_t rtt;
324 bool estimate_changed = bitrate_controller_->GetNetworkParameters( 343 bool estimate_changed = bitrate_controller_->GetNetworkParameters(
325 &bitrate_bps, &fraction_loss, &rtt); 344 &bitrate_bps, &fraction_loss, &rtt);
326 if (estimate_changed) 345 if (estimate_changed) {
327 pacer_->SetEstimatedBitrate(bitrate_bps); 346 pacer_->SetEstimatedBitrate(bitrate_bps);
347 retransmission_rate_limiter_->SetMaxRate(bitrate_bps);
348 }
328 349
329 bitrate_bps = IsNetworkDown() || IsSendQueueFull() ? 0 : bitrate_bps; 350 bitrate_bps = IsNetworkDown() || IsSendQueueFull() ? 0 : bitrate_bps;
330 351
331 if (HasNetworkParametersToReportChanged(bitrate_bps, fraction_loss, rtt)) { 352 if (HasNetworkParametersToReportChanged(bitrate_bps, fraction_loss, rtt)) {
332 observer_->OnNetworkChanged(bitrate_bps, fraction_loss, rtt); 353 observer_->OnNetworkChanged(bitrate_bps, fraction_loss, rtt);
333 } 354 }
334 } 355 }
335 356
336 bool CongestionController::HasNetworkParametersToReportChanged( 357 bool CongestionController::HasNetworkParametersToReportChanged(
337 uint32_t bitrate_bps, 358 uint32_t bitrate_bps,
(...skipping 17 matching lines...) Expand all
355 bool CongestionController::IsSendQueueFull() const { 376 bool CongestionController::IsSendQueueFull() const {
356 return pacer_->ExpectedQueueTimeMs() > PacedSender::kMaxQueueLengthMs; 377 return pacer_->ExpectedQueueTimeMs() > PacedSender::kMaxQueueLengthMs;
357 } 378 }
358 379
359 bool CongestionController::IsNetworkDown() const { 380 bool CongestionController::IsNetworkDown() const {
360 rtc::CritScope cs(&critsect_); 381 rtc::CritScope cs(&critsect_);
361 return network_state_ == kNetworkDown; 382 return network_state_ == kNetworkDown;
362 } 383 }
363 384
364 } // namespace webrtc 385 } // namespace webrtc
OLDNEW
« no previous file with comments | « webrtc/common_types.h ('k') | webrtc/modules/congestion_controller/include/congestion_controller.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698