OLD | NEW |
1 /* | 1 /* |
2 * Copyright (c) 2017 The WebRTC project authors. All Rights Reserved. | 2 * Copyright (c) 2017 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 | 11 |
12 #ifndef WEBRTC_MODULES_REMOTE_BITRATE_ESTIMATOR_TEST_ESTIMATORS_MIN_RTT_FILTER_H
_ | 12 #ifndef WEBRTC_MODULES_REMOTE_BITRATE_ESTIMATOR_TEST_ESTIMATORS_MIN_RTT_FILTER_H
_ |
13 #define WEBRTC_MODULES_REMOTE_BITRATE_ESTIMATOR_TEST_ESTIMATORS_MIN_RTT_FILTER_H
_ | 13 #define WEBRTC_MODULES_REMOTE_BITRATE_ESTIMATOR_TEST_ESTIMATORS_MIN_RTT_FILTER_H
_ |
14 | 14 |
15 #include <cstdint> | 15 #include <cstdint> |
16 #include <limits> | 16 #include <limits> |
| 17 #include <list> |
17 | 18 |
18 #include "webrtc/rtc_base/optional.h" | 19 #include "webrtc/rtc_base/optional.h" |
19 | 20 |
20 namespace webrtc { | 21 namespace webrtc { |
21 namespace testing { | 22 namespace testing { |
22 namespace bwe { | 23 namespace bwe { |
23 | 24 |
24 // Expiration time for min_rtt sample, which is set to 10 seconds according to | 25 // Average rtt for past |kRttFilterSize| packets should grow by |
25 // BBR design doc. | 26 // |kRttIncreaseThresholdForExpiry| in order to enter PROBE_RTT mode and expire. |
26 const int64_t kMinRttFilterSizeMs = 10000; | 27 // old min_rtt estimate. |
| 28 const float kRttIncreaseThresholdForExpiry = 2.3f; |
| 29 const size_t kRttFilterSize = 25; |
27 | 30 |
28 class MinRttFilter { | 31 class MinRttFilter { |
29 public: | 32 public: |
| 33 // This class implements a simple filter to ensure that PROBE_RTT is only |
| 34 // entered when RTTs start to increase, instead of fixed 10 second window as |
| 35 // in orginal BBR design doc, to avoid unnecessary freezes in stream. |
30 MinRttFilter() {} | 36 MinRttFilter() {} |
31 ~MinRttFilter() {} | 37 ~MinRttFilter() {} |
32 | 38 |
33 rtc::Optional<int64_t> min_rtt_ms() { return min_rtt_ms_; } | 39 rtc::Optional<int64_t> min_rtt_ms() { return min_rtt_ms_; } |
34 void AddRttSample(int64_t rtt_ms, int64_t now_ms) { | 40 void AddRttSample(int64_t rtt_ms, int64_t now_ms) { |
35 if (!min_rtt_ms_ || rtt_ms <= *min_rtt_ms_ || MinRttExpired(now_ms)) { | 41 if (!min_rtt_ms_ || rtt_ms <= *min_rtt_ms_ || MinRttExpired(now_ms)) { |
36 min_rtt_ms_.emplace(rtt_ms); | 42 min_rtt_ms_.emplace(rtt_ms); |
37 discovery_time_ms_ = now_ms; | |
38 } | 43 } |
| 44 rtt_samples_.push_back(rtt_ms); |
| 45 if (rtt_samples_.size() > kRttFilterSize) |
| 46 rtt_samples_.pop_front(); |
39 } | 47 } |
40 int64_t discovery_time() { return discovery_time_ms_; } | |
41 | 48 |
42 // Checks whether or not last discovered min_rtt value is older than x | 49 // Checks whether or not last RTT values for past |kRttFilterSize| packets |
43 // milliseconds. | 50 // started to increase, meaning we have to update min_rtt estimate. |
44 bool MinRttExpired(int64_t now_ms) { | 51 bool MinRttExpired(int64_t now_ms) { |
45 return now_ms - discovery_time_ms_ >= kMinRttFilterSizeMs; | 52 if (rtt_samples_.size() < kRttFilterSize || !min_rtt_ms_) |
| 53 return false; |
| 54 int64_t sum_of_rtts_ms = 0; |
| 55 for (int64_t i : rtt_samples_) |
| 56 sum_of_rtts_ms += i; |
| 57 if (sum_of_rtts_ms >= |
| 58 *min_rtt_ms_ * kRttIncreaseThresholdForExpiry * kRttFilterSize) { |
| 59 rtt_samples_.clear(); |
| 60 return true; |
| 61 } |
| 62 return false; |
46 } | 63 } |
47 | 64 |
48 private: | 65 private: |
49 rtc::Optional<int64_t> min_rtt_ms_; | 66 rtc::Optional<int64_t> min_rtt_ms_; |
50 int64_t discovery_time_ms_ = 0; | 67 std::list<int64_t> rtt_samples_; |
51 }; | 68 }; |
52 } // namespace bwe | 69 } // namespace bwe |
53 } // namespace testing | 70 } // namespace testing |
54 } // namespace webrtc | 71 } // namespace webrtc |
55 | 72 |
56 #endif // WEBRTC_MODULES_REMOTE_BITRATE_ESTIMATOR_TEST_ESTIMATORS_MIN_RTT_FILTE
R_H_ | 73 #endif // WEBRTC_MODULES_REMOTE_BITRATE_ESTIMATOR_TEST_ESTIMATORS_MIN_RTT_FILTE
R_H_ |
OLD | NEW |