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 |
(...skipping 15 matching lines...) Expand all Loading... |
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_abs_s
end_time.h" |
27 #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/utility/include/process_thread.h" | 28 #include "webrtc/modules/utility/include/process_thread.h" |
29 #include "webrtc/system_wrappers/include/critical_section_wrapper.h" | 29 #include "webrtc/system_wrappers/include/critical_section_wrapper.h" |
30 #include "webrtc/video/payload_router.h" | 30 #include "webrtc/video/payload_router.h" |
31 | 31 |
32 namespace webrtc { | 32 namespace webrtc { |
33 namespace { | 33 namespace { |
34 | 34 |
35 static const uint32_t kTimeOffsetSwitchThreshold = 30; | 35 static const uint32_t kTimeOffsetSwitchThreshold = 30; |
36 static const int64_t kMinRetransmitWindowSizeMs = 30; | 36 static const int64_t kRetransmitWindowSizeMs = 500; |
37 static const int64_t kMaxRetransmitWindowSizeMs = 1000; | |
38 | 37 |
39 // Makes sure that the bitrate and the min, max values are in valid range. | 38 // Makes sure that the bitrate and the min, max values are in valid range. |
40 static void ClampBitrates(int* bitrate_bps, | 39 static void ClampBitrates(int* bitrate_bps, |
41 int* min_bitrate_bps, | 40 int* min_bitrate_bps, |
42 int* max_bitrate_bps) { | 41 int* max_bitrate_bps) { |
43 // TODO(holmer): We should make sure the default bitrates are set to 10 kbps, | 42 // 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. | 43 // 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. | 44 // The congestion controller should allow a min bitrate of 0. |
46 const int kMinBitrateBps = 10000; | 45 const int kMinBitrateBps = 10000; |
47 if (*min_bitrate_bps < kMinBitrateBps) | 46 if (*min_bitrate_bps < kMinBitrateBps) |
(...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
161 RtcEventLog* event_log) | 160 RtcEventLog* event_log) |
162 : clock_(clock), | 161 : clock_(clock), |
163 observer_(observer), | 162 observer_(observer), |
164 packet_router_(new PacketRouter()), | 163 packet_router_(new PacketRouter()), |
165 pacer_(new PacedSender(clock_, packet_router_.get())), | 164 pacer_(new PacedSender(clock_, packet_router_.get())), |
166 remote_bitrate_estimator_( | 165 remote_bitrate_estimator_( |
167 new WrappingBitrateEstimator(remote_bitrate_observer, clock_)), | 166 new WrappingBitrateEstimator(remote_bitrate_observer, clock_)), |
168 bitrate_controller_( | 167 bitrate_controller_( |
169 BitrateController::CreateBitrateController(clock_, event_log)), | 168 BitrateController::CreateBitrateController(clock_, event_log)), |
170 retransmission_rate_limiter_( | 169 retransmission_rate_limiter_( |
171 new RateLimiter(clock, kMaxRetransmitWindowSizeMs)), | 170 new RateLimiter(clock, kRetransmitWindowSizeMs)), |
172 remote_estimator_proxy_(clock_, packet_router_.get()), | 171 remote_estimator_proxy_(clock_, packet_router_.get()), |
173 transport_feedback_adapter_(bitrate_controller_.get(), clock_), | 172 transport_feedback_adapter_(bitrate_controller_.get(), clock_), |
174 min_bitrate_bps_(RemoteBitrateEstimator::kDefaultMinBitrateBps), | 173 min_bitrate_bps_(RemoteBitrateEstimator::kDefaultMinBitrateBps), |
175 last_reported_bitrate_bps_(0), | 174 last_reported_bitrate_bps_(0), |
176 last_reported_fraction_loss_(0), | 175 last_reported_fraction_loss_(0), |
177 last_reported_rtt_(0), | 176 last_reported_rtt_(0), |
178 network_state_(kNetworkUp) { | 177 network_state_(kNetworkUp) { |
179 Init(); | 178 Init(); |
180 } | 179 } |
181 | 180 |
182 CongestionController::CongestionController( | 181 CongestionController::CongestionController( |
183 Clock* clock, | 182 Clock* clock, |
184 Observer* observer, | 183 Observer* observer, |
185 RemoteBitrateObserver* remote_bitrate_observer, | 184 RemoteBitrateObserver* remote_bitrate_observer, |
186 RtcEventLog* event_log, | 185 RtcEventLog* event_log, |
187 std::unique_ptr<PacketRouter> packet_router, | 186 std::unique_ptr<PacketRouter> packet_router, |
188 std::unique_ptr<PacedSender> pacer) | 187 std::unique_ptr<PacedSender> pacer) |
189 : clock_(clock), | 188 : clock_(clock), |
190 observer_(observer), | 189 observer_(observer), |
191 packet_router_(std::move(packet_router)), | 190 packet_router_(std::move(packet_router)), |
192 pacer_(std::move(pacer)), | 191 pacer_(std::move(pacer)), |
193 remote_bitrate_estimator_( | 192 remote_bitrate_estimator_( |
194 new WrappingBitrateEstimator(remote_bitrate_observer, clock_)), | 193 new WrappingBitrateEstimator(remote_bitrate_observer, clock_)), |
195 // Constructed last as this object calls the provided callback on | 194 // Constructed last as this object calls the provided callback on |
196 // construction. | 195 // construction. |
197 bitrate_controller_( | 196 bitrate_controller_( |
198 BitrateController::CreateBitrateController(clock_, event_log)), | 197 BitrateController::CreateBitrateController(clock_, event_log)), |
199 retransmission_rate_limiter_( | 198 retransmission_rate_limiter_( |
200 new RateLimiter(clock, kMaxRetransmitWindowSizeMs)), | 199 new RateLimiter(clock, kRetransmitWindowSizeMs)), |
201 remote_estimator_proxy_(clock_, packet_router_.get()), | 200 remote_estimator_proxy_(clock_, packet_router_.get()), |
202 transport_feedback_adapter_(bitrate_controller_.get(), clock_), | 201 transport_feedback_adapter_(bitrate_controller_.get(), clock_), |
203 min_bitrate_bps_(RemoteBitrateEstimator::kDefaultMinBitrateBps), | 202 min_bitrate_bps_(RemoteBitrateEstimator::kDefaultMinBitrateBps), |
204 last_reported_bitrate_bps_(0), | 203 last_reported_bitrate_bps_(0), |
205 last_reported_fraction_loss_(0), | 204 last_reported_fraction_loss_(0), |
206 last_reported_rtt_(0), | 205 last_reported_rtt_(0), |
207 network_state_(kNetworkUp) { | 206 network_state_(kNetworkUp) { |
208 Init(); | 207 Init(); |
209 } | 208 } |
210 | 209 |
(...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
303 } | 302 } |
304 | 303 |
305 void CongestionController::OnSentPacket(const rtc::SentPacket& sent_packet) { | 304 void CongestionController::OnSentPacket(const rtc::SentPacket& sent_packet) { |
306 transport_feedback_adapter_.OnSentPacket(sent_packet.packet_id, | 305 transport_feedback_adapter_.OnSentPacket(sent_packet.packet_id, |
307 sent_packet.send_time_ms); | 306 sent_packet.send_time_ms); |
308 } | 307 } |
309 | 308 |
310 void CongestionController::OnRttUpdate(int64_t avg_rtt_ms, int64_t max_rtt_ms) { | 309 void CongestionController::OnRttUpdate(int64_t avg_rtt_ms, int64_t max_rtt_ms) { |
311 remote_bitrate_estimator_->OnRttUpdate(avg_rtt_ms, max_rtt_ms); | 310 remote_bitrate_estimator_->OnRttUpdate(avg_rtt_ms, max_rtt_ms); |
312 transport_feedback_adapter_.OnRttUpdate(avg_rtt_ms, max_rtt_ms); | 311 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 } | 312 } |
322 | 313 |
323 int64_t CongestionController::TimeUntilNextProcess() { | 314 int64_t CongestionController::TimeUntilNextProcess() { |
324 return std::min(bitrate_controller_->TimeUntilNextProcess(), | 315 return std::min(bitrate_controller_->TimeUntilNextProcess(), |
325 remote_bitrate_estimator_->TimeUntilNextProcess()); | 316 remote_bitrate_estimator_->TimeUntilNextProcess()); |
326 } | 317 } |
327 | 318 |
328 void CongestionController::Process() { | 319 void CongestionController::Process() { |
329 bitrate_controller_->Process(); | 320 bitrate_controller_->Process(); |
330 remote_bitrate_estimator_->Process(); | 321 remote_bitrate_estimator_->Process(); |
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
376 bool CongestionController::IsSendQueueFull() const { | 367 bool CongestionController::IsSendQueueFull() const { |
377 return pacer_->ExpectedQueueTimeMs() > PacedSender::kMaxQueueLengthMs; | 368 return pacer_->ExpectedQueueTimeMs() > PacedSender::kMaxQueueLengthMs; |
378 } | 369 } |
379 | 370 |
380 bool CongestionController::IsNetworkDown() const { | 371 bool CongestionController::IsNetworkDown() const { |
381 rtc::CritScope cs(&critsect_); | 372 rtc::CritScope cs(&critsect_); |
382 return network_state_ == kNetworkDown; | 373 return network_state_ == kNetworkDown; |
383 } | 374 } |
384 | 375 |
385 } // namespace webrtc | 376 } // namespace webrtc |
OLD | NEW |