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

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

Issue 2131913003: Revert of Refactor 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"
21 #include "webrtc/base/socket.h" 20 #include "webrtc/base/socket.h"
22 #include "webrtc/base/thread_annotations.h" 21 #include "webrtc/base/thread_annotations.h"
23 #include "webrtc/modules/bitrate_controller/include/bitrate_controller.h" 22 #include "webrtc/modules/bitrate_controller/include/bitrate_controller.h"
24 #include "webrtc/modules/congestion_controller/delay_based_bwe.h" 23 #include "webrtc/modules/congestion_controller/delay_based_bwe.h"
25 #include "webrtc/modules/remote_bitrate_estimator/include/send_time_history.h" 24 #include "webrtc/modules/remote_bitrate_estimator/include/send_time_history.h"
26 #include "webrtc/modules/remote_bitrate_estimator/remote_bitrate_estimator_abs_s end_time.h" 25 #include "webrtc/modules/remote_bitrate_estimator/remote_bitrate_estimator_abs_s end_time.h"
27 #include "webrtc/modules/remote_bitrate_estimator/remote_bitrate_estimator_singl e_stream.h" 26 #include "webrtc/modules/remote_bitrate_estimator/remote_bitrate_estimator_singl e_stream.h"
28 #include "webrtc/modules/utility/include/process_thread.h" 27 #include "webrtc/modules/utility/include/process_thread.h"
29 #include "webrtc/system_wrappers/include/critical_section_wrapper.h" 28 #include "webrtc/system_wrappers/include/critical_section_wrapper.h"
30 #include "webrtc/video/payload_router.h" 29 #include "webrtc/video/payload_router.h"
31 30
32 namespace webrtc { 31 namespace webrtc {
33 namespace { 32 namespace {
34 33
35 static const uint32_t kTimeOffsetSwitchThreshold = 30; 34 static const uint32_t kTimeOffsetSwitchThreshold = 30;
36 static const int64_t kMinRetransmitWindowSizeMs = 30;
37 static const int64_t kMaxRetransmitWindowSizeMs = 1000;
38 35
39 // Makes sure that the bitrate and the min, max values are in valid range. 36 // Makes sure that the bitrate and the min, max values are in valid range.
40 static void ClampBitrates(int* bitrate_bps, 37 static void ClampBitrates(int* bitrate_bps,
41 int* min_bitrate_bps, 38 int* min_bitrate_bps,
42 int* max_bitrate_bps) { 39 int* max_bitrate_bps) {
43 // TODO(holmer): We should make sure the default bitrates are set to 10 kbps, 40 // TODO(holmer): We should make sure the default bitrates are set to 10 kbps,
44 // and that we don't try to set the min bitrate to 0 from any applications. 41 // and that we don't try to set the min bitrate to 0 from any applications.
45 // The congestion controller should allow a min bitrate of 0. 42 // The congestion controller should allow a min bitrate of 0.
46 const int kMinBitrateBps = 10000; 43 const int kMinBitrateBps = 10000;
47 if (*min_bitrate_bps < kMinBitrateBps) 44 if (*min_bitrate_bps < kMinBitrateBps)
(...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after
160 RemoteBitrateObserver* remote_bitrate_observer, 157 RemoteBitrateObserver* remote_bitrate_observer,
161 RtcEventLog* event_log) 158 RtcEventLog* event_log)
162 : clock_(clock), 159 : clock_(clock),
163 observer_(observer), 160 observer_(observer),
164 packet_router_(new PacketRouter()), 161 packet_router_(new PacketRouter()),
165 pacer_(new PacedSender(clock_, packet_router_.get())), 162 pacer_(new PacedSender(clock_, packet_router_.get())),
166 remote_bitrate_estimator_( 163 remote_bitrate_estimator_(
167 new WrappingBitrateEstimator(remote_bitrate_observer, clock_)), 164 new WrappingBitrateEstimator(remote_bitrate_observer, clock_)),
168 bitrate_controller_( 165 bitrate_controller_(
169 BitrateController::CreateBitrateController(clock_, event_log)), 166 BitrateController::CreateBitrateController(clock_, event_log)),
170 retransmission_rate_limiter_(
171 new RateLimiter(clock, kMaxRetransmitWindowSizeMs)),
172 remote_estimator_proxy_(clock_, packet_router_.get()), 167 remote_estimator_proxy_(clock_, packet_router_.get()),
173 transport_feedback_adapter_(bitrate_controller_.get(), clock_), 168 transport_feedback_adapter_(bitrate_controller_.get(), clock_),
174 min_bitrate_bps_(RemoteBitrateEstimator::kDefaultMinBitrateBps), 169 min_bitrate_bps_(RemoteBitrateEstimator::kDefaultMinBitrateBps),
175 last_reported_bitrate_bps_(0), 170 last_reported_bitrate_bps_(0),
176 last_reported_fraction_loss_(0), 171 last_reported_fraction_loss_(0),
177 last_reported_rtt_(0), 172 last_reported_rtt_(0),
178 network_state_(kNetworkUp) { 173 network_state_(kNetworkUp) {
179 Init(); 174 Init();
180 } 175 }
181 176
182 CongestionController::CongestionController( 177 CongestionController::CongestionController(
183 Clock* clock, 178 Clock* clock,
184 Observer* observer, 179 Observer* observer,
185 RemoteBitrateObserver* remote_bitrate_observer, 180 RemoteBitrateObserver* remote_bitrate_observer,
186 RtcEventLog* event_log, 181 RtcEventLog* event_log,
187 std::unique_ptr<PacketRouter> packet_router, 182 std::unique_ptr<PacketRouter> packet_router,
188 std::unique_ptr<PacedSender> pacer) 183 std::unique_ptr<PacedSender> pacer)
189 : clock_(clock), 184 : clock_(clock),
190 observer_(observer), 185 observer_(observer),
191 packet_router_(std::move(packet_router)), 186 packet_router_(std::move(packet_router)),
192 pacer_(std::move(pacer)), 187 pacer_(std::move(pacer)),
193 remote_bitrate_estimator_( 188 remote_bitrate_estimator_(
194 new WrappingBitrateEstimator(remote_bitrate_observer, clock_)), 189 new WrappingBitrateEstimator(remote_bitrate_observer, clock_)),
195 // Constructed last as this object calls the provided callback on 190 // Constructed last as this object calls the provided callback on
196 // construction. 191 // construction.
197 bitrate_controller_( 192 bitrate_controller_(
198 BitrateController::CreateBitrateController(clock_, event_log)), 193 BitrateController::CreateBitrateController(clock_, event_log)),
199 retransmission_rate_limiter_(
200 new RateLimiter(clock, kMaxRetransmitWindowSizeMs)),
201 remote_estimator_proxy_(clock_, packet_router_.get()), 194 remote_estimator_proxy_(clock_, packet_router_.get()),
202 transport_feedback_adapter_(bitrate_controller_.get(), clock_), 195 transport_feedback_adapter_(bitrate_controller_.get(), clock_),
203 min_bitrate_bps_(RemoteBitrateEstimator::kDefaultMinBitrateBps), 196 min_bitrate_bps_(RemoteBitrateEstimator::kDefaultMinBitrateBps),
204 last_reported_bitrate_bps_(0), 197 last_reported_bitrate_bps_(0),
205 last_reported_fraction_loss_(0), 198 last_reported_fraction_loss_(0),
206 last_reported_rtt_(0), 199 last_reported_rtt_(0),
207 network_state_(kNetworkUp) { 200 network_state_(kNetworkUp) {
208 Init(); 201 Init();
209 } 202 }
210 203
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after
266 } else { 259 } else {
267 return remote_bitrate_estimator_.get(); 260 return remote_bitrate_estimator_.get();
268 } 261 }
269 } 262 }
270 263
271 TransportFeedbackObserver* 264 TransportFeedbackObserver*
272 CongestionController::GetTransportFeedbackObserver() { 265 CongestionController::GetTransportFeedbackObserver() {
273 return &transport_feedback_adapter_; 266 return &transport_feedback_adapter_;
274 } 267 }
275 268
276 RateLimiter* CongestionController::GetRetransmissionRateLimiter() {
277 return retransmission_rate_limiter_.get();
278 }
279
280 void CongestionController::SetAllocatedSendBitrateLimits( 269 void CongestionController::SetAllocatedSendBitrateLimits(
281 int min_send_bitrate_bps, 270 int min_send_bitrate_bps,
282 int max_padding_bitrate_bps) { 271 int max_padding_bitrate_bps) {
283 pacer_->SetSendBitrateLimits(min_send_bitrate_bps, max_padding_bitrate_bps); 272 pacer_->SetSendBitrateLimits(min_send_bitrate_bps, max_padding_bitrate_bps);
284 } 273 }
285 274
286 int64_t CongestionController::GetPacerQueuingDelayMs() const { 275 int64_t CongestionController::GetPacerQueuingDelayMs() const {
287 return pacer_->QueueInMs(); 276 return pacer_->QueueInMs();
288 } 277 }
289 278
(...skipping 13 matching lines...) Expand all
303 } 292 }
304 293
305 void CongestionController::OnSentPacket(const rtc::SentPacket& sent_packet) { 294 void CongestionController::OnSentPacket(const rtc::SentPacket& sent_packet) {
306 transport_feedback_adapter_.OnSentPacket(sent_packet.packet_id, 295 transport_feedback_adapter_.OnSentPacket(sent_packet.packet_id,
307 sent_packet.send_time_ms); 296 sent_packet.send_time_ms);
308 } 297 }
309 298
310 void CongestionController::OnRttUpdate(int64_t avg_rtt_ms, int64_t max_rtt_ms) { 299 void CongestionController::OnRttUpdate(int64_t avg_rtt_ms, int64_t max_rtt_ms) {
311 remote_bitrate_estimator_->OnRttUpdate(avg_rtt_ms, max_rtt_ms); 300 remote_bitrate_estimator_->OnRttUpdate(avg_rtt_ms, max_rtt_ms);
312 transport_feedback_adapter_.OnRttUpdate(avg_rtt_ms, max_rtt_ms); 301 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);
321 } 302 }
322 303
323 int64_t CongestionController::TimeUntilNextProcess() { 304 int64_t CongestionController::TimeUntilNextProcess() {
324 return std::min(bitrate_controller_->TimeUntilNextProcess(), 305 return std::min(bitrate_controller_->TimeUntilNextProcess(),
325 remote_bitrate_estimator_->TimeUntilNextProcess()); 306 remote_bitrate_estimator_->TimeUntilNextProcess());
326 } 307 }
327 308
328 void CongestionController::Process() { 309 void CongestionController::Process() {
329 bitrate_controller_->Process(); 310 bitrate_controller_->Process();
330 remote_bitrate_estimator_->Process(); 311 remote_bitrate_estimator_->Process();
331 MaybeTriggerOnNetworkChanged(); 312 MaybeTriggerOnNetworkChanged();
332 } 313 }
333 314
334 void CongestionController::MaybeTriggerOnNetworkChanged() { 315 void CongestionController::MaybeTriggerOnNetworkChanged() {
335 // TODO(perkj): |observer_| can be nullptr if the ctor that accepts a 316 // TODO(perkj): |observer_| can be nullptr if the ctor that accepts a
336 // BitrateObserver is used. Remove this check once the ctor is removed. 317 // BitrateObserver is used. Remove this check once the ctor is removed.
337 if (!observer_) 318 if (!observer_)
338 return; 319 return;
339 320
340 uint32_t bitrate_bps; 321 uint32_t bitrate_bps;
341 uint8_t fraction_loss; 322 uint8_t fraction_loss;
342 int64_t rtt; 323 int64_t rtt;
343 bool estimate_changed = bitrate_controller_->GetNetworkParameters( 324 bool estimate_changed = bitrate_controller_->GetNetworkParameters(
344 &bitrate_bps, &fraction_loss, &rtt); 325 &bitrate_bps, &fraction_loss, &rtt);
345 if (estimate_changed) { 326 if (estimate_changed)
346 pacer_->SetEstimatedBitrate(bitrate_bps); 327 pacer_->SetEstimatedBitrate(bitrate_bps);
347 retransmission_rate_limiter_->SetMaxRate(bitrate_bps);
348 }
349 328
350 bitrate_bps = IsNetworkDown() || IsSendQueueFull() ? 0 : bitrate_bps; 329 bitrate_bps = IsNetworkDown() || IsSendQueueFull() ? 0 : bitrate_bps;
351 330
352 if (HasNetworkParametersToReportChanged(bitrate_bps, fraction_loss, rtt)) { 331 if (HasNetworkParametersToReportChanged(bitrate_bps, fraction_loss, rtt)) {
353 observer_->OnNetworkChanged(bitrate_bps, fraction_loss, rtt); 332 observer_->OnNetworkChanged(bitrate_bps, fraction_loss, rtt);
354 } 333 }
355 } 334 }
356 335
357 bool CongestionController::HasNetworkParametersToReportChanged( 336 bool CongestionController::HasNetworkParametersToReportChanged(
358 uint32_t bitrate_bps, 337 uint32_t bitrate_bps,
(...skipping 17 matching lines...) Expand all
376 bool CongestionController::IsSendQueueFull() const { 355 bool CongestionController::IsSendQueueFull() const {
377 return pacer_->ExpectedQueueTimeMs() > PacedSender::kMaxQueueLengthMs; 356 return pacer_->ExpectedQueueTimeMs() > PacedSender::kMaxQueueLengthMs;
378 } 357 }
379 358
380 bool CongestionController::IsNetworkDown() const { 359 bool CongestionController::IsNetworkDown() const {
381 rtc::CritScope cs(&critsect_); 360 rtc::CritScope cs(&critsect_);
382 return network_state_ == kNetworkDown; 361 return network_state_ == kNetworkDown;
383 } 362 }
384 363
385 } // namespace webrtc 364 } // 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