OLD | NEW |
---|---|
1 /* | 1 /* |
2 * Copyright (c) 2016 The WebRTC project authors. All Rights Reserved. | 2 * Copyright (c) 2016 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/test/gtest.h" | 11 #include "webrtc/test/gtest.h" |
12 #include "webrtc/base/random.h" | 12 #include "webrtc/base/random.h" |
13 #include "webrtc/modules/congestion_controller/trendline_estimator.h" | 13 #include "webrtc/modules/congestion_controller/trendline_estimator.h" |
14 | 14 |
15 namespace webrtc { | 15 namespace webrtc { |
16 | 16 |
17 namespace { | 17 namespace { |
18 constexpr size_t kWindowSize = 15; | 18 constexpr size_t kWindowSize = 20; |
19 constexpr double kSmoothing = 0.0; | 19 constexpr double kSmoothing = 0.0; |
20 constexpr double kGain = 1; | 20 constexpr double kGain = 1; |
21 constexpr int64_t kAvgTimeBetweenPackets = 10; | 21 constexpr int64_t kAvgTimeBetweenPackets = 10; |
22 constexpr size_t kPacketCount = 2 * kWindowSize + 1; | |
22 } // namespace | 23 } // namespace |
23 | 24 |
24 TEST(TrendlineEstimator, PerfectLineSlopeOneHalf) { | 25 void TestEstimator(double slope, double jitter_stddev, double tolerance) { |
25 TrendlineEstimator estimator(kWindowSize, kSmoothing, kGain); | 26 TrendlineEstimator estimator(kWindowSize, kSmoothing, kGain); |
26 Random rand(0x1234567); | 27 Random random(0x1234567); |
27 double now_ms = rand.Rand<double>() * 10000; | 28 int64_t send_times[kPacketCount]; |
28 for (size_t i = 1; i < 2 * kWindowSize; i++) { | 29 int64_t recv_times[kPacketCount]; |
29 double send_delta = rand.Rand<double>() * 2 * kAvgTimeBetweenPackets; | 30 int64_t send_start_time = random.Rand(1000000); |
30 double recv_delta = 2 * send_delta; | 31 int64_t recv_start_time = random.Rand(1000000); |
31 now_ms += recv_delta; | 32 for (size_t i = 0; i < kPacketCount; i++) { |
brandtr
2016/12/15 12:06:08
I think we often write ++i in for loops.
terelius
2016/12/15 13:11:08
Done. However, the style guide explicitly allows e
| |
32 estimator.Update(recv_delta, send_delta, now_ms); | 33 send_times[i] = send_start_time + i * kAvgTimeBetweenPackets; |
34 double latency = i * kAvgTimeBetweenPackets / (1 - slope); | |
35 double jitter = random.Gaussian(0, jitter_stddev); | |
36 recv_times[i] = recv_start_time + latency + jitter; | |
37 } | |
38 for (size_t i = 1; i < kPacketCount; i++) { | |
brandtr
2016/12/15 12:06:08
Here too.
terelius
2016/12/15 13:11:08
Done.
| |
39 double recv_delta = recv_times[i] - recv_times[i - 1]; | |
40 double send_delta = send_times[i] - send_times[i - 1]; | |
41 estimator.Update(recv_delta, send_delta, recv_times[i]); | |
33 if (i < kWindowSize) | 42 if (i < kWindowSize) |
34 EXPECT_NEAR(estimator.trendline_slope(), 0, 0.001); | 43 EXPECT_NEAR(estimator.trendline_slope(), 0, 0.001); |
35 else | 44 else |
36 EXPECT_NEAR(estimator.trendline_slope(), 0.5, 0.001); | 45 EXPECT_NEAR(estimator.trendline_slope(), slope, tolerance); |
37 } | 46 } |
38 } | 47 } |
39 | 48 |
49 TEST(TrendlineEstimator, PerfectLineSlopeOneHalf) { | |
50 TestEstimator(0.5, 0, 0.001); | |
51 } | |
52 | |
40 TEST(TrendlineEstimator, PerfectLineSlopeMinusOne) { | 53 TEST(TrendlineEstimator, PerfectLineSlopeMinusOne) { |
41 TrendlineEstimator estimator(kWindowSize, kSmoothing, kGain); | 54 TestEstimator(-1, 0, 0.001); |
42 Random rand(0x1234567); | |
43 double now_ms = rand.Rand<double>() * 10000; | |
44 for (size_t i = 1; i < 2 * kWindowSize; i++) { | |
45 double send_delta = rand.Rand<double>() * 2 * kAvgTimeBetweenPackets; | |
46 double recv_delta = 0.5 * send_delta; | |
47 now_ms += recv_delta; | |
48 estimator.Update(recv_delta, send_delta, now_ms); | |
49 if (i < kWindowSize) | |
50 EXPECT_NEAR(estimator.trendline_slope(), 0, 0.001); | |
51 else | |
52 EXPECT_NEAR(estimator.trendline_slope(), -1, 0.001); | |
53 } | |
54 } | 55 } |
55 | 56 |
56 TEST(TrendlineEstimator, PerfectLineSlopeZero) { | 57 TEST(TrendlineEstimator, PerfectLineSlopeZero) { |
57 TrendlineEstimator estimator(kWindowSize, kSmoothing, kGain); | 58 TestEstimator(0, 0, 0.001); |
58 Random rand(0x1234567); | |
59 double now_ms = rand.Rand<double>() * 10000; | |
60 for (size_t i = 1; i < 2 * kWindowSize; i++) { | |
61 double send_delta = rand.Rand<double>() * 2 * kAvgTimeBetweenPackets; | |
62 double recv_delta = send_delta; | |
63 now_ms += recv_delta; | |
64 estimator.Update(recv_delta, send_delta, now_ms); | |
65 EXPECT_NEAR(estimator.trendline_slope(), 0, 0.001); | |
66 } | |
67 } | 59 } |
68 | 60 |
69 TEST(TrendlineEstimator, JitteryLineSlopeOneHalf) { | 61 TEST(TrendlineEstimator, JitteryLineSlopeOneHalf) { |
70 TrendlineEstimator estimator(kWindowSize, kSmoothing, kGain); | 62 TestEstimator(0.5, kAvgTimeBetweenPackets / 3.0, 0.01); |
71 Random rand(0x1234567); | |
72 double now_ms = rand.Rand<double>() * 10000; | |
73 for (size_t i = 1; i < 2 * kWindowSize; i++) { | |
74 double send_delta = rand.Rand<double>() * 2 * kAvgTimeBetweenPackets; | |
75 double recv_delta = 2 * send_delta + rand.Gaussian(0, send_delta / 3); | |
76 now_ms += recv_delta; | |
77 estimator.Update(recv_delta, send_delta, now_ms); | |
78 if (i < kWindowSize) | |
79 EXPECT_NEAR(estimator.trendline_slope(), 0, 0.001); | |
80 else | |
81 EXPECT_NEAR(estimator.trendline_slope(), 0.5, 0.1); | |
82 } | |
83 } | 63 } |
84 | 64 |
85 TEST(TrendlineEstimator, JitteryLineSlopeMinusOne) { | 65 TEST(TrendlineEstimator, JitteryLineSlopeMinusOne) { |
86 TrendlineEstimator estimator(kWindowSize, kSmoothing, kGain); | 66 TestEstimator(-1, kAvgTimeBetweenPackets / 3.0, 0.075); |
87 Random rand(0x1234567); | |
88 double now_ms = rand.Rand<double>() * 10000; | |
89 for (size_t i = 1; i < 2 * kWindowSize; i++) { | |
90 double send_delta = rand.Rand<double>() * 2 * kAvgTimeBetweenPackets; | |
91 double recv_delta = 0.5 * send_delta + rand.Gaussian(0, send_delta / 25); | |
92 now_ms += recv_delta; | |
93 estimator.Update(recv_delta, send_delta, now_ms); | |
94 if (i < kWindowSize) | |
95 EXPECT_NEAR(estimator.trendline_slope(), 0, 0.001); | |
96 else | |
97 EXPECT_NEAR(estimator.trendline_slope(), -1, 0.1); | |
98 } | |
99 } | 67 } |
100 | 68 |
101 TEST(TrendlineEstimator, JitteryLineSlopeZero) { | 69 TEST(TrendlineEstimator, JitteryLineSlopeZero) { |
102 TrendlineEstimator estimator(kWindowSize, kSmoothing, kGain); | 70 TestEstimator(0, kAvgTimeBetweenPackets / 3.0, 0.02); |
103 Random rand(0x1234567); | |
104 double now_ms = rand.Rand<double>() * 10000; | |
105 for (size_t i = 1; i < 2 * kWindowSize; i++) { | |
106 double send_delta = rand.Rand<double>() * 2 * kAvgTimeBetweenPackets; | |
107 double recv_delta = send_delta + rand.Gaussian(0, send_delta / 8); | |
108 now_ms += recv_delta; | |
109 estimator.Update(recv_delta, send_delta, now_ms); | |
110 EXPECT_NEAR(estimator.trendline_slope(), 0, 0.1); | |
111 } | |
112 } | 71 } |
113 | 72 |
114 } // namespace webrtc | 73 } // namespace webrtc |
OLD | NEW |