OLD | NEW |
1 /* | 1 /* |
2 * Copyright (c) 2014 The WebRTC project authors. All Rights Reserved. | 2 * Copyright (c) 2014 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 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
55 } | 55 } |
56 | 56 |
57 bool AimdRateControl::ValidEstimate() const { | 57 bool AimdRateControl::ValidEstimate() const { |
58 return bitrate_is_initialized_; | 58 return bitrate_is_initialized_; |
59 } | 59 } |
60 | 60 |
61 int64_t AimdRateControl::GetFeedbackInterval() const { | 61 int64_t AimdRateControl::GetFeedbackInterval() const { |
62 // Estimate how often we can send RTCP if we allocate up to 5% of bandwidth | 62 // Estimate how often we can send RTCP if we allocate up to 5% of bandwidth |
63 // to feedback. | 63 // to feedback. |
64 static const int kRtcpSize = 80; | 64 static const int kRtcpSize = 80; |
65 int64_t interval = static_cast<int64_t>( | 65 const int64_t interval = static_cast<int64_t>( |
66 kRtcpSize * 8.0 * 1000.0 / (0.05 * current_bitrate_bps_) + 0.5); | 66 kRtcpSize * 8.0 * 1000.0 / (0.05 * current_bitrate_bps_) + 0.5); |
67 const int64_t kMinFeedbackIntervalMs = 200; | 67 const int64_t kMinFeedbackIntervalMs = 200; |
68 return std::min(std::max(interval, kMinFeedbackIntervalMs), | 68 return rtc::SafeClamp(interval, kMinFeedbackIntervalMs, |
69 kMaxFeedbackIntervalMs); | 69 kMaxFeedbackIntervalMs); |
70 } | 70 } |
71 | 71 |
72 bool AimdRateControl::TimeToReduceFurther(int64_t time_now, | 72 bool AimdRateControl::TimeToReduceFurther(int64_t time_now, |
73 uint32_t incoming_bitrate_bps) const { | 73 uint32_t incoming_bitrate_bps) const { |
74 const int64_t bitrate_reduction_interval = | 74 const int64_t bitrate_reduction_interval = |
75 std::max<int64_t>(std::min<int64_t>(rtt_, 200), 10); | 75 std::max<int64_t>(std::min<int64_t>(rtt_, 200), 10); |
76 if (time_now - time_last_bitrate_change_ >= bitrate_reduction_interval) { | 76 if (time_now - time_last_bitrate_change_ >= bitrate_reduction_interval) { |
77 return true; | 77 return true; |
78 } | 78 } |
79 if (ValidEstimate()) { | 79 if (ValidEstimate()) { |
(...skipping 230 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
310 default: | 310 default: |
311 assert(false); | 311 assert(false); |
312 } | 312 } |
313 } | 313 } |
314 | 314 |
315 void AimdRateControl::ChangeRegion(RateControlRegion region) { | 315 void AimdRateControl::ChangeRegion(RateControlRegion region) { |
316 rate_control_region_ = region; | 316 rate_control_region_ = region; |
317 } | 317 } |
318 | 318 |
319 } // namespace webrtc | 319 } // namespace webrtc |
OLD | NEW |