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/modules/congestion_controller/probe_bitrate_estimator.h" | 11 #include "webrtc/modules/congestion_controller/probe_bitrate_estimator.h" |
12 | 12 |
13 #include <vector> | 13 #include <vector> |
14 #include <utility> | 14 #include <utility> |
15 | 15 |
16 #include "testing/gmock/include/gmock/gmock.h" | 16 #include "testing/gmock/include/gmock/gmock.h" |
17 #include "testing/gtest/include/gtest/gtest.h" | 17 #include "testing/gtest/include/gtest/gtest.h" |
18 #include "webrtc/modules/remote_bitrate_estimator/aimd_rate_control.h" | 18 #include "webrtc/modules/remote_bitrate_estimator/aimd_rate_control.h" |
19 | 19 |
20 namespace webrtc { | 20 namespace webrtc { |
21 | 21 |
22 class TestProbeBitrateEstimator : public ::testing::Test { | 22 class TestProbeBitrateEstimator : public ::testing::Test { |
23 public: | 23 public: |
24 TestProbeBitrateEstimator() : probe_bitrate_estimator_() {} | 24 TestProbeBitrateEstimator() : probe_bitrate_estimator_() {} |
25 | 25 |
26 void AddPacketFeedback(int probe_cluster_id, | 26 void AddPacketFeedback(int probe_cluster_id, |
27 size_t size, | 27 size_t size_bytes, |
28 int64_t send_time_ms, | 28 int64_t send_time_ms, |
29 int64_t arrival_time_ms) { | 29 int64_t arrival_time_ms) { |
30 PacketInfo info(arrival_time_ms, send_time_ms, 0, size, probe_cluster_id); | 30 PacketInfo info(arrival_time_ms, send_time_ms, 0, size_bytes, |
| 31 probe_cluster_id); |
31 ProbingResult res = probe_bitrate_estimator_.PacketFeedback(info); | 32 ProbingResult res = probe_bitrate_estimator_.PacketFeedback(info); |
32 if (res.bps != ProbingResult::kNoEstimate) | 33 if (res.valid()) |
33 results_.emplace_back(res.bps, res.timestamp); | 34 results_.emplace_back(res.bps, res.timestamp); |
34 } | 35 } |
35 | 36 |
36 void CheckResult(size_t index, int bps, int max_diff, int64_t timestamp) { | 37 void CheckResult(size_t index, int bps, int max_diff, int64_t timestamp) { |
37 ASSERT_GT(results_.size(), index); | 38 ASSERT_GT(results_.size(), index); |
38 EXPECT_NEAR(results_[index].first, bps, max_diff); | 39 EXPECT_NEAR(results_[index].first, bps, max_diff); |
39 EXPECT_EQ(results_[index].second, timestamp); | 40 EXPECT_EQ(results_[index].second, timestamp); |
40 } | 41 } |
41 | 42 |
42 protected: | 43 protected: |
43 std::vector<std::pair<int, int64_t>> results_; | 44 std::vector<std::pair<int, int64_t>> results_; |
44 ProbeBitrateEstimator probe_bitrate_estimator_; | 45 ProbeBitrateEstimator probe_bitrate_estimator_; |
45 }; | 46 }; |
46 | 47 |
47 TEST_F(TestProbeBitrateEstimator, OneCluster) { | 48 TEST_F(TestProbeBitrateEstimator, OneCluster) { |
48 AddPacketFeedback(0, 1000, 0, 10); | 49 AddPacketFeedback(0, 1000, 0, 10); |
49 AddPacketFeedback(0, 1000, 10, 20); | 50 AddPacketFeedback(0, 1000, 10, 20); |
50 AddPacketFeedback(0, 1000, 20, 30); | 51 AddPacketFeedback(0, 1000, 20, 30); |
51 AddPacketFeedback(0, 1000, 40, 50); | 52 AddPacketFeedback(0, 1000, 30, 40); |
52 | 53 |
53 CheckResult(0, 100000, 10, 50); | 54 CheckResult(0, 800000, 10, 40); |
54 } | 55 } |
55 | 56 |
56 TEST_F(TestProbeBitrateEstimator, FastReceive) { | 57 TEST_F(TestProbeBitrateEstimator, FastReceive) { |
57 AddPacketFeedback(0, 1000, 0, 15); | 58 AddPacketFeedback(0, 1000, 0, 15); |
58 AddPacketFeedback(0, 1000, 10, 30); | 59 AddPacketFeedback(0, 1000, 10, 30); |
59 AddPacketFeedback(0, 1000, 20, 40); | 60 AddPacketFeedback(0, 1000, 20, 35); |
60 AddPacketFeedback(0, 1000, 40, 50); | 61 AddPacketFeedback(0, 1000, 30, 40); |
61 | 62 |
62 CheckResult(0, 100000, 10, 50); | 63 CheckResult(0, 800000, 10, 40); |
63 } | 64 } |
64 | 65 |
65 TEST_F(TestProbeBitrateEstimator, TooFastReceive) { | 66 TEST_F(TestProbeBitrateEstimator, TooFastReceive) { |
66 AddPacketFeedback(0, 1000, 0, 19); | 67 AddPacketFeedback(0, 1000, 0, 19); |
67 AddPacketFeedback(0, 1000, 10, 30); | 68 AddPacketFeedback(0, 1000, 10, 30); |
68 AddPacketFeedback(0, 1000, 20, 40); | 69 AddPacketFeedback(0, 1000, 20, 40); |
69 AddPacketFeedback(0, 1000, 40, 50); | 70 AddPacketFeedback(0, 1000, 40, 50); |
70 | 71 |
71 EXPECT_TRUE(results_.empty()); | 72 EXPECT_TRUE(results_.empty()); |
72 } | 73 } |
73 | 74 |
74 TEST_F(TestProbeBitrateEstimator, SlowReceive) { | 75 TEST_F(TestProbeBitrateEstimator, SlowReceive) { |
75 AddPacketFeedback(0, 1000, 0, 10); | 76 AddPacketFeedback(0, 1000, 0, 10); |
76 AddPacketFeedback(0, 1000, 10, 40); | 77 AddPacketFeedback(0, 1000, 10, 40); |
77 AddPacketFeedback(0, 1000, 20, 70); | 78 AddPacketFeedback(0, 1000, 20, 70); |
78 AddPacketFeedback(0, 1000, 40, 110); | 79 AddPacketFeedback(0, 1000, 30, 85); |
79 | 80 |
80 CheckResult(0, 40000, 10, 110); | 81 CheckResult(0, 320000, 10, 85); |
81 } | 82 } |
82 | 83 |
83 TEST_F(TestProbeBitrateEstimator, BurstReceive) { | 84 TEST_F(TestProbeBitrateEstimator, BurstReceive) { |
84 AddPacketFeedback(0, 1000, 0, 50); | 85 AddPacketFeedback(0, 1000, 0, 50); |
85 AddPacketFeedback(0, 1000, 10, 50); | 86 AddPacketFeedback(0, 1000, 10, 50); |
86 AddPacketFeedback(0, 1000, 20, 50); | 87 AddPacketFeedback(0, 1000, 20, 50); |
87 AddPacketFeedback(0, 1000, 40, 50); | 88 AddPacketFeedback(0, 1000, 40, 50); |
88 | 89 |
89 EXPECT_TRUE(results_.empty()); | 90 EXPECT_TRUE(results_.empty()); |
90 } | 91 } |
91 | 92 |
92 TEST_F(TestProbeBitrateEstimator, MultipleClusters) { | 93 TEST_F(TestProbeBitrateEstimator, MultipleClusters) { |
93 AddPacketFeedback(0, 1000, 0, 10); | 94 AddPacketFeedback(0, 1000, 0, 10); |
94 AddPacketFeedback(0, 1000, 10, 20); | 95 AddPacketFeedback(0, 1000, 10, 20); |
95 AddPacketFeedback(0, 1000, 20, 30); | 96 AddPacketFeedback(0, 1000, 20, 30); |
96 AddPacketFeedback(0, 1000, 40, 60); | 97 AddPacketFeedback(0, 1000, 40, 60); |
97 AddPacketFeedback(0, 1000, 50, 60); | 98 AddPacketFeedback(0, 1000, 50, 60); |
98 | 99 |
99 CheckResult(0, 80000, 10, 60); | 100 CheckResult(0, 480000, 10, 60); |
100 CheckResult(1, 100000, 10, 60); | 101 CheckResult(1, 640000, 10, 60); |
101 | 102 |
102 AddPacketFeedback(1, 1000, 60, 70); | 103 AddPacketFeedback(1, 1000, 60, 70); |
103 AddPacketFeedback(1, 1000, 65, 77); | 104 AddPacketFeedback(1, 1000, 65, 77); |
104 AddPacketFeedback(1, 1000, 70, 84); | 105 AddPacketFeedback(1, 1000, 70, 84); |
105 AddPacketFeedback(1, 1000, 75, 90); | 106 AddPacketFeedback(1, 1000, 75, 90); |
106 | 107 |
107 CheckResult(2, 200000, 10, 90); | 108 CheckResult(2, 1200000, 10, 90); |
108 } | 109 } |
109 | 110 |
110 TEST_F(TestProbeBitrateEstimator, OldProbe) { | 111 TEST_F(TestProbeBitrateEstimator, OldProbe) { |
111 AddPacketFeedback(0, 1000, 0, 10); | 112 AddPacketFeedback(0, 1000, 0, 10); |
112 AddPacketFeedback(0, 1000, 10, 20); | 113 AddPacketFeedback(0, 1000, 10, 20); |
113 AddPacketFeedback(0, 1000, 20, 30); | 114 AddPacketFeedback(0, 1000, 20, 30); |
114 | 115 |
115 AddPacketFeedback(1, 1000, 60, 70); | 116 AddPacketFeedback(1, 1000, 60, 70); |
116 AddPacketFeedback(1, 1000, 65, 77); | 117 AddPacketFeedback(1, 1000, 65, 77); |
117 AddPacketFeedback(1, 1000, 70, 84); | 118 AddPacketFeedback(1, 1000, 70, 84); |
118 AddPacketFeedback(1, 1000, 75, 90); | 119 AddPacketFeedback(1, 1000, 75, 90); |
119 | 120 |
120 CheckResult(0, 200000, 10, 90); | 121 CheckResult(0, 1200000, 10, 90); |
121 | 122 |
122 AddPacketFeedback(0, 1000, 40, 60); | 123 AddPacketFeedback(0, 1000, 40, 60); |
123 | 124 |
124 EXPECT_EQ(1ul, results_.size()); | 125 EXPECT_EQ(1ul, results_.size()); |
125 } | 126 } |
126 | 127 |
127 } // namespace webrtc | 128 } // namespace webrtc |
OLD | NEW |