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/rate_limiter.h" |
21 #include "webrtc/base/socket.h" | 21 #include "webrtc/base/socket.h" |
22 #include "webrtc/base/thread_annotations.h" | 22 #include "webrtc/base/thread_annotations.h" |
23 #include "webrtc/modules/bitrate_controller/include/bitrate_controller.h" | 23 #include "webrtc/modules/bitrate_controller/include/bitrate_controller.h" |
24 #include "webrtc/modules/congestion_controller/probe_controller.h" | 24 #include "webrtc/modules/congestion_controller/probe_controller.h" |
25 #include "webrtc/modules/remote_bitrate_estimator/include/send_time_history.h" | 25 #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" | 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/system_wrappers/include/field_trial.h" | |
30 #include "webrtc/video/payload_router.h" | 31 #include "webrtc/video/payload_router.h" |
31 | 32 |
32 namespace webrtc { | 33 namespace webrtc { |
33 namespace { | 34 namespace { |
34 | 35 |
35 static const uint32_t kTimeOffsetSwitchThreshold = 30; | 36 static const uint32_t kTimeOffsetSwitchThreshold = 30; |
36 static const int64_t kRetransmitWindowSizeMs = 500; | 37 static const int64_t kRetransmitWindowSizeMs = 500; |
37 | 38 |
38 // 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. |
39 static void ClampBitrates(int* bitrate_bps, | 40 static void ClampBitrates(int* bitrate_bps, |
40 int* min_bitrate_bps, | 41 int* min_bitrate_bps, |
41 int* max_bitrate_bps) { | 42 int* max_bitrate_bps) { |
42 // 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, |
43 // 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. |
44 // The congestion controller should allow a min bitrate of 0. | 45 // The congestion controller should allow a min bitrate of 0. |
45 const int kMinBitrateBps = 10000; | 46 if (*min_bitrate_bps < CongestionController::GetMinBitrateBps()) |
46 if (*min_bitrate_bps < kMinBitrateBps) | 47 *min_bitrate_bps = CongestionController::GetMinBitrateBps(); |
47 *min_bitrate_bps = kMinBitrateBps; | |
48 if (*max_bitrate_bps > 0) | 48 if (*max_bitrate_bps > 0) |
49 *max_bitrate_bps = std::max(*min_bitrate_bps, *max_bitrate_bps); | 49 *max_bitrate_bps = std::max(*min_bitrate_bps, *max_bitrate_bps); |
50 if (*bitrate_bps > 0) | 50 if (*bitrate_bps > 0) |
51 *bitrate_bps = std::max(*min_bitrate_bps, *bitrate_bps); | 51 *bitrate_bps = std::max(*min_bitrate_bps, *bitrate_bps); |
52 } | 52 } |
53 | 53 |
54 class WrappingBitrateEstimator : public RemoteBitrateEstimator { | 54 class WrappingBitrateEstimator : public RemoteBitrateEstimator { |
55 public: | 55 public: |
56 WrappingBitrateEstimator(RemoteBitrateObserver* observer, Clock* clock) | 56 WrappingBitrateEstimator(RemoteBitrateObserver* observer, Clock* clock) |
57 : observer_(observer), | 57 : observer_(observer), |
58 clock_(clock), | 58 clock_(clock), |
59 crit_sect_(CriticalSectionWrapper::CreateCriticalSection()), | 59 crit_sect_(CriticalSectionWrapper::CreateCriticalSection()), |
60 rbe_(new RemoteBitrateEstimatorSingleStream(observer_, clock_)), | 60 rbe_(new RemoteBitrateEstimatorSingleStream(observer_, clock_)), |
61 using_absolute_send_time_(false), | 61 using_absolute_send_time_(false), |
62 packets_since_absolute_send_time_(0), | 62 packets_since_absolute_send_time_(0), |
63 min_bitrate_bps_(RemoteBitrateEstimator::kDefaultMinBitrateBps) {} | 63 min_bitrate_bps_(CongestionController::GetMinBitrateBps()) {} |
64 | 64 |
65 virtual ~WrappingBitrateEstimator() {} | 65 virtual ~WrappingBitrateEstimator() {} |
66 | 66 |
67 void IncomingPacket(int64_t arrival_time_ms, | 67 void IncomingPacket(int64_t arrival_time_ms, |
68 size_t payload_size, | 68 size_t payload_size, |
69 const RTPHeader& header) override { | 69 const RTPHeader& header) override { |
70 CriticalSectionScoped cs(crit_sect_.get()); | 70 CriticalSectionScoped cs(crit_sect_.get()); |
71 PickEstimatorFromHeader(header); | 71 PickEstimatorFromHeader(header); |
72 rbe_->IncomingPacket(arrival_time_ms, payload_size, header); | 72 rbe_->IncomingPacket(arrival_time_ms, payload_size, header); |
73 } | 73 } |
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
146 std::unique_ptr<RemoteBitrateEstimator> rbe_; | 146 std::unique_ptr<RemoteBitrateEstimator> rbe_; |
147 bool using_absolute_send_time_; | 147 bool using_absolute_send_time_; |
148 uint32_t packets_since_absolute_send_time_; | 148 uint32_t packets_since_absolute_send_time_; |
149 int min_bitrate_bps_; | 149 int min_bitrate_bps_; |
150 | 150 |
151 RTC_DISALLOW_IMPLICIT_CONSTRUCTORS(WrappingBitrateEstimator); | 151 RTC_DISALLOW_IMPLICIT_CONSTRUCTORS(WrappingBitrateEstimator); |
152 }; | 152 }; |
153 | 153 |
154 } // namespace | 154 } // namespace |
155 | 155 |
156 | |
157 int CongestionController::GetMinBitrateBps() { | |
158 constexpr int kAudioMinBitrateBps = 5000; | |
159 constexpr int kMinBitrateBps = 10000; | |
160 if (webrtc::field_trial::FindFullName("WebRTC-Audio-SendSideBwe") == | |
161 "Enabled") | |
stefan-webrtc
2016/11/01 09:09:15
{} since it's a multi-line if
michaelt
2016/11/01 09:21:55
Done.
| |
162 return kAudioMinBitrateBps; | |
163 return kMinBitrateBps; | |
164 } | |
165 | |
156 CongestionController::CongestionController( | 166 CongestionController::CongestionController( |
157 Clock* clock, | 167 Clock* clock, |
158 Observer* observer, | 168 Observer* observer, |
159 RemoteBitrateObserver* remote_bitrate_observer, | 169 RemoteBitrateObserver* remote_bitrate_observer, |
160 RtcEventLog* event_log) | 170 RtcEventLog* event_log) |
161 : clock_(clock), | 171 : clock_(clock), |
162 observer_(observer), | 172 observer_(observer), |
163 packet_router_(new PacketRouter()), | 173 packet_router_(new PacketRouter()), |
164 pacer_(new PacedSender(clock_, packet_router_.get())), | 174 pacer_(new PacedSender(clock_, packet_router_.get())), |
165 remote_bitrate_estimator_( | 175 remote_bitrate_estimator_( |
166 new WrappingBitrateEstimator(remote_bitrate_observer, clock_)), | 176 new WrappingBitrateEstimator(remote_bitrate_observer, clock_)), |
167 bitrate_controller_( | 177 bitrate_controller_( |
168 BitrateController::CreateBitrateController(clock_, event_log)), | 178 BitrateController::CreateBitrateController(clock_, event_log)), |
169 probe_controller_(new ProbeController(pacer_.get(), clock_)), | 179 probe_controller_(new ProbeController(pacer_.get(), clock_)), |
170 retransmission_rate_limiter_( | 180 retransmission_rate_limiter_( |
171 new RateLimiter(clock, kRetransmitWindowSizeMs)), | 181 new RateLimiter(clock, kRetransmitWindowSizeMs)), |
172 remote_estimator_proxy_(clock_, packet_router_.get()), | 182 remote_estimator_proxy_(clock_, packet_router_.get()), |
173 transport_feedback_adapter_(clock_, bitrate_controller_.get()), | 183 transport_feedback_adapter_(clock_, bitrate_controller_.get()), |
174 min_bitrate_bps_(RemoteBitrateEstimator::kDefaultMinBitrateBps), | 184 min_bitrate_bps_(GetMinBitrateBps()), |
175 max_bitrate_bps_(0), | 185 max_bitrate_bps_(0), |
176 last_reported_bitrate_bps_(0), | 186 last_reported_bitrate_bps_(0), |
177 last_reported_fraction_loss_(0), | 187 last_reported_fraction_loss_(0), |
178 last_reported_rtt_(0), | 188 last_reported_rtt_(0), |
179 network_state_(kNetworkUp) { | 189 network_state_(kNetworkUp) { |
180 Init(); | 190 Init(); |
181 } | 191 } |
182 | 192 |
183 CongestionController::CongestionController( | 193 CongestionController::CongestionController( |
184 Clock* clock, | 194 Clock* clock, |
(...skipping 10 matching lines...) Expand all Loading... | |
195 new WrappingBitrateEstimator(remote_bitrate_observer, clock_)), | 205 new WrappingBitrateEstimator(remote_bitrate_observer, clock_)), |
196 // Constructed last as this object calls the provided callback on | 206 // Constructed last as this object calls the provided callback on |
197 // construction. | 207 // construction. |
198 bitrate_controller_( | 208 bitrate_controller_( |
199 BitrateController::CreateBitrateController(clock_, event_log)), | 209 BitrateController::CreateBitrateController(clock_, event_log)), |
200 probe_controller_(new ProbeController(pacer_.get(), clock_)), | 210 probe_controller_(new ProbeController(pacer_.get(), clock_)), |
201 retransmission_rate_limiter_( | 211 retransmission_rate_limiter_( |
202 new RateLimiter(clock, kRetransmitWindowSizeMs)), | 212 new RateLimiter(clock, kRetransmitWindowSizeMs)), |
203 remote_estimator_proxy_(clock_, packet_router_.get()), | 213 remote_estimator_proxy_(clock_, packet_router_.get()), |
204 transport_feedback_adapter_(clock_, bitrate_controller_.get()), | 214 transport_feedback_adapter_(clock_, bitrate_controller_.get()), |
205 min_bitrate_bps_(RemoteBitrateEstimator::kDefaultMinBitrateBps), | 215 min_bitrate_bps_(GetMinBitrateBps()), |
206 max_bitrate_bps_(0), | 216 max_bitrate_bps_(0), |
207 last_reported_bitrate_bps_(0), | 217 last_reported_bitrate_bps_(0), |
208 last_reported_fraction_loss_(0), | 218 last_reported_fraction_loss_(0), |
209 last_reported_rtt_(0), | 219 last_reported_rtt_(0), |
210 network_state_(kNetworkUp) { | 220 network_state_(kNetworkUp) { |
211 Init(); | 221 Init(); |
212 } | 222 } |
213 | 223 |
214 CongestionController::~CongestionController() {} | 224 CongestionController::~CongestionController() {} |
215 | 225 |
(...skipping 156 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
372 bool CongestionController::IsSendQueueFull() const { | 382 bool CongestionController::IsSendQueueFull() const { |
373 return pacer_->ExpectedQueueTimeMs() > PacedSender::kMaxQueueLengthMs; | 383 return pacer_->ExpectedQueueTimeMs() > PacedSender::kMaxQueueLengthMs; |
374 } | 384 } |
375 | 385 |
376 bool CongestionController::IsNetworkDown() const { | 386 bool CongestionController::IsNetworkDown() const { |
377 rtc::CritScope cs(&critsect_); | 387 rtc::CritScope cs(&critsect_); |
378 return network_state_ == kNetworkDown; | 388 return network_state_ == kNetworkDown; |
379 } | 389 } |
380 | 390 |
381 } // namespace webrtc | 391 } // namespace webrtc |
OLD | NEW |