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 "testing/gmock/include/gmock/gmock.h" | 11 #include "testing/gmock/include/gmock/gmock.h" |
12 #include "testing/gtest/include/gtest/gtest.h" | 12 #include "testing/gtest/include/gtest/gtest.h" |
13 | 13 |
14 #include "webrtc/base/scoped_ptr.h" | 14 #include "webrtc/base/scoped_ptr.h" |
15 #include "webrtc/modules/rtp_rtcp/interface/rtp_rtcp_defines.h" | 15 #include "webrtc/modules/rtp_rtcp/interface/rtp_rtcp_defines.h" |
16 #include "webrtc/system_wrappers/interface/tick_util.h" | 16 #include "webrtc/system_wrappers/interface/tick_util.h" |
17 #include "webrtc/video_engine/call_stats.h" | 17 #include "webrtc/video_engine/call_stats.h" |
18 | 18 |
19 using ::testing::_; | 19 using ::testing::_; |
20 using ::testing::AnyNumber; | 20 using ::testing::AnyNumber; |
21 using ::testing::Return; | 21 using ::testing::Return; |
22 | 22 |
23 namespace webrtc { | 23 namespace webrtc { |
24 | 24 |
25 class MockStatsObserver : public CallStatsObserver { | 25 class MockStatsObserver : public CallStatsObserver { |
26 public: | 26 public: |
27 MockStatsObserver() {} | 27 MockStatsObserver() {} |
28 virtual ~MockStatsObserver() {} | 28 virtual ~MockStatsObserver() {} |
29 | 29 |
30 MOCK_METHOD1(OnRttUpdate, void(int64_t)); | 30 MOCK_METHOD2(OnRttUpdate, void(int64_t, int64_t)); |
31 }; | 31 }; |
32 | 32 |
33 class CallStatsTest : public ::testing::Test { | 33 class CallStatsTest : public ::testing::Test { |
34 protected: | 34 protected: |
35 virtual void SetUp() { | 35 virtual void SetUp() { |
36 TickTime::UseFakeClock(12345); | 36 TickTime::UseFakeClock(12345); |
37 call_stats_.reset(new CallStats()); | 37 call_stats_.reset(new CallStats()); |
38 } | 38 } |
39 rtc::scoped_ptr<CallStats> call_stats_; | 39 rtc::scoped_ptr<CallStats> call_stats_; |
40 }; | 40 }; |
41 | 41 |
42 TEST_F(CallStatsTest, AddAndTriggerCallback) { | 42 TEST_F(CallStatsTest, AddAndTriggerCallback) { |
43 MockStatsObserver stats_observer; | 43 MockStatsObserver stats_observer; |
44 RtcpRttStats* rtcp_rtt_stats = call_stats_->rtcp_rtt_stats(); | 44 RtcpRttStats* rtcp_rtt_stats = call_stats_->rtcp_rtt_stats(); |
45 call_stats_->RegisterStatsObserver(&stats_observer); | 45 call_stats_->RegisterStatsObserver(&stats_observer); |
46 TickTime::AdvanceFakeClock(1000); | 46 TickTime::AdvanceFakeClock(1000); |
47 EXPECT_EQ(0, rtcp_rtt_stats->LastProcessedRtt()); | 47 EXPECT_EQ(0, rtcp_rtt_stats->LastProcessedRtt()); |
48 | 48 |
49 const int64_t kRtt = 25; | 49 const int64_t kRtt = 25; |
50 rtcp_rtt_stats->OnRttUpdate(kRtt); | 50 rtcp_rtt_stats->OnRttUpdate(kRtt); |
51 EXPECT_CALL(stats_observer, OnRttUpdate(kRtt)) | 51 EXPECT_CALL(stats_observer, OnRttUpdate(kRtt, kRtt)).Times(1); |
52 .Times(1); | |
53 call_stats_->Process(); | 52 call_stats_->Process(); |
54 EXPECT_EQ(kRtt, rtcp_rtt_stats->LastProcessedRtt()); | 53 EXPECT_EQ(kRtt, rtcp_rtt_stats->LastProcessedRtt()); |
55 | 54 |
56 const int64_t kRttTimeOutMs = 1500 + 10; | 55 const int64_t kRttTimeOutMs = 1500 + 10; |
57 TickTime::AdvanceFakeClock(kRttTimeOutMs); | 56 TickTime::AdvanceFakeClock(kRttTimeOutMs); |
58 EXPECT_CALL(stats_observer, OnRttUpdate(_)) | 57 EXPECT_CALL(stats_observer, OnRttUpdate(_, _)).Times(0); |
59 .Times(0); | |
60 call_stats_->Process(); | 58 call_stats_->Process(); |
61 EXPECT_EQ(0, rtcp_rtt_stats->LastProcessedRtt()); | 59 EXPECT_EQ(0, rtcp_rtt_stats->LastProcessedRtt()); |
62 | 60 |
63 call_stats_->DeregisterStatsObserver(&stats_observer); | 61 call_stats_->DeregisterStatsObserver(&stats_observer); |
64 } | 62 } |
65 | 63 |
66 TEST_F(CallStatsTest, ProcessTime) { | 64 TEST_F(CallStatsTest, ProcessTime) { |
67 MockStatsObserver stats_observer; | 65 MockStatsObserver stats_observer; |
68 call_stats_->RegisterStatsObserver(&stats_observer); | 66 call_stats_->RegisterStatsObserver(&stats_observer); |
69 RtcpRttStats* rtcp_rtt_stats = call_stats_->rtcp_rtt_stats(); | 67 RtcpRttStats* rtcp_rtt_stats = call_stats_->rtcp_rtt_stats(); |
70 rtcp_rtt_stats->OnRttUpdate(100); | 68 rtcp_rtt_stats->OnRttUpdate(100); |
71 | 69 |
72 // Time isn't updated yet. | 70 // Time isn't updated yet. |
73 EXPECT_CALL(stats_observer, OnRttUpdate(_)) | 71 EXPECT_CALL(stats_observer, OnRttUpdate(_, _)).Times(0); |
74 .Times(0); | |
75 call_stats_->Process(); | 72 call_stats_->Process(); |
76 | 73 |
77 // Advance clock and verify we get an update. | 74 // Advance clock and verify we get an update. |
78 TickTime::AdvanceFakeClock(1000); | 75 TickTime::AdvanceFakeClock(1000); |
79 EXPECT_CALL(stats_observer, OnRttUpdate(_)) | 76 EXPECT_CALL(stats_observer, OnRttUpdate(_, _)).Times(1); |
80 .Times(1); | |
81 call_stats_->Process(); | 77 call_stats_->Process(); |
82 | 78 |
83 // Advance clock just too little to get an update. | 79 // Advance clock just too little to get an update. |
84 TickTime::AdvanceFakeClock(999); | 80 TickTime::AdvanceFakeClock(999); |
85 rtcp_rtt_stats->OnRttUpdate(100); | 81 rtcp_rtt_stats->OnRttUpdate(100); |
86 EXPECT_CALL(stats_observer, OnRttUpdate(_)) | 82 EXPECT_CALL(stats_observer, OnRttUpdate(_, _)).Times(0); |
87 .Times(0); | |
88 call_stats_->Process(); | 83 call_stats_->Process(); |
89 | 84 |
90 // Advance enough to trigger a new update. | 85 // Advance enough to trigger a new update. |
91 TickTime::AdvanceFakeClock(1); | 86 TickTime::AdvanceFakeClock(1); |
92 EXPECT_CALL(stats_observer, OnRttUpdate(_)) | 87 EXPECT_CALL(stats_observer, OnRttUpdate(_, _)).Times(1); |
93 .Times(1); | |
94 call_stats_->Process(); | 88 call_stats_->Process(); |
95 | 89 |
96 call_stats_->DeregisterStatsObserver(&stats_observer); | 90 call_stats_->DeregisterStatsObserver(&stats_observer); |
97 } | 91 } |
98 | 92 |
99 // Verify all observers get correct estimates and observers can be added and | 93 // Verify all observers get correct estimates and observers can be added and |
100 // removed. | 94 // removed. |
101 TEST_F(CallStatsTest, MultipleObservers) { | 95 TEST_F(CallStatsTest, MultipleObservers) { |
102 MockStatsObserver stats_observer_1; | 96 MockStatsObserver stats_observer_1; |
103 call_stats_->RegisterStatsObserver(&stats_observer_1); | 97 call_stats_->RegisterStatsObserver(&stats_observer_1); |
104 // Add the second observer twice, there should still be only one report to the | 98 // Add the second observer twice, there should still be only one report to the |
105 // observer. | 99 // observer. |
106 MockStatsObserver stats_observer_2; | 100 MockStatsObserver stats_observer_2; |
107 call_stats_->RegisterStatsObserver(&stats_observer_2); | 101 call_stats_->RegisterStatsObserver(&stats_observer_2); |
108 call_stats_->RegisterStatsObserver(&stats_observer_2); | 102 call_stats_->RegisterStatsObserver(&stats_observer_2); |
109 | 103 |
110 RtcpRttStats* rtcp_rtt_stats = call_stats_->rtcp_rtt_stats(); | 104 RtcpRttStats* rtcp_rtt_stats = call_stats_->rtcp_rtt_stats(); |
111 const int64_t kRtt = 100; | 105 const int64_t kRtt = 100; |
112 rtcp_rtt_stats->OnRttUpdate(kRtt); | 106 rtcp_rtt_stats->OnRttUpdate(kRtt); |
113 | 107 |
114 // Verify both observers are updated. | 108 // Verify both observers are updated. |
115 TickTime::AdvanceFakeClock(1000); | 109 TickTime::AdvanceFakeClock(1000); |
116 EXPECT_CALL(stats_observer_1, OnRttUpdate(kRtt)) | 110 EXPECT_CALL(stats_observer_1, OnRttUpdate(kRtt, kRtt)).Times(1); |
117 .Times(1); | 111 EXPECT_CALL(stats_observer_2, OnRttUpdate(kRtt, kRtt)).Times(1); |
118 EXPECT_CALL(stats_observer_2, OnRttUpdate(kRtt)) | |
119 .Times(1); | |
120 call_stats_->Process(); | 112 call_stats_->Process(); |
121 | 113 |
122 // Deregister the second observer and verify update is only sent to the first | 114 // Deregister the second observer and verify update is only sent to the first |
123 // observer. | 115 // observer. |
124 call_stats_->DeregisterStatsObserver(&stats_observer_2); | 116 call_stats_->DeregisterStatsObserver(&stats_observer_2); |
125 rtcp_rtt_stats->OnRttUpdate(kRtt); | 117 rtcp_rtt_stats->OnRttUpdate(kRtt); |
126 TickTime::AdvanceFakeClock(1000); | 118 TickTime::AdvanceFakeClock(1000); |
127 EXPECT_CALL(stats_observer_1, OnRttUpdate(kRtt)) | 119 EXPECT_CALL(stats_observer_1, OnRttUpdate(kRtt, kRtt)).Times(1); |
128 .Times(1); | 120 EXPECT_CALL(stats_observer_2, OnRttUpdate(kRtt, kRtt)).Times(0); |
129 EXPECT_CALL(stats_observer_2, OnRttUpdate(kRtt)) | |
130 .Times(0); | |
131 call_stats_->Process(); | 121 call_stats_->Process(); |
132 | 122 |
133 // Deregister the first observer. | 123 // Deregister the first observer. |
134 call_stats_->DeregisterStatsObserver(&stats_observer_1); | 124 call_stats_->DeregisterStatsObserver(&stats_observer_1); |
135 rtcp_rtt_stats->OnRttUpdate(kRtt); | 125 rtcp_rtt_stats->OnRttUpdate(kRtt); |
136 TickTime::AdvanceFakeClock(1000); | 126 TickTime::AdvanceFakeClock(1000); |
137 EXPECT_CALL(stats_observer_1, OnRttUpdate(kRtt)) | 127 EXPECT_CALL(stats_observer_1, OnRttUpdate(kRtt, kRtt)).Times(0); |
138 .Times(0); | 128 EXPECT_CALL(stats_observer_2, OnRttUpdate(kRtt, kRtt)).Times(0); |
139 EXPECT_CALL(stats_observer_2, OnRttUpdate(kRtt)) | |
140 .Times(0); | |
141 call_stats_->Process(); | 129 call_stats_->Process(); |
142 } | 130 } |
143 | 131 |
144 // Verify increasing and decreasing rtt triggers callbacks with correct values. | 132 // Verify increasing and decreasing rtt triggers callbacks with correct values. |
145 TEST_F(CallStatsTest, ChangeRtt) { | 133 TEST_F(CallStatsTest, ChangeRtt) { |
146 MockStatsObserver stats_observer; | 134 MockStatsObserver stats_observer; |
147 call_stats_->RegisterStatsObserver(&stats_observer); | 135 call_stats_->RegisterStatsObserver(&stats_observer); |
148 RtcpRttStats* rtcp_rtt_stats = call_stats_->rtcp_rtt_stats(); | 136 RtcpRttStats* rtcp_rtt_stats = call_stats_->rtcp_rtt_stats(); |
149 | 137 |
150 // Advance clock to be ready for an update. | 138 // Advance clock to be ready for an update. |
151 TickTime::AdvanceFakeClock(1000); | 139 TickTime::AdvanceFakeClock(1000); |
152 | 140 |
153 // Set a first value and verify the callback is triggered. | 141 // Set a first value and verify the callback is triggered. |
154 const int64_t kFirstRtt = 100; | 142 const int64_t kFirstRtt = 100; |
155 rtcp_rtt_stats->OnRttUpdate(kFirstRtt); | 143 rtcp_rtt_stats->OnRttUpdate(kFirstRtt); |
156 EXPECT_CALL(stats_observer, OnRttUpdate(kFirstRtt)) | 144 EXPECT_CALL(stats_observer, OnRttUpdate(kFirstRtt, kFirstRtt)).Times(1); |
157 .Times(1); | |
158 call_stats_->Process(); | 145 call_stats_->Process(); |
159 | 146 |
160 // Increase rtt and verify the new value is reported. | 147 // Increase rtt and verify the new value is reported. |
161 TickTime::AdvanceFakeClock(1000); | 148 TickTime::AdvanceFakeClock(1000); |
162 const int64_t kHighRtt = kFirstRtt + 20; | 149 const int64_t kHighRtt = kFirstRtt + 20; |
| 150 const int64_t kAvgRtt1 = 103; |
163 rtcp_rtt_stats->OnRttUpdate(kHighRtt); | 151 rtcp_rtt_stats->OnRttUpdate(kHighRtt); |
164 EXPECT_CALL(stats_observer, OnRttUpdate(kHighRtt)) | 152 EXPECT_CALL(stats_observer, OnRttUpdate(kAvgRtt1, kHighRtt)).Times(1); |
165 .Times(1); | |
166 call_stats_->Process(); | 153 call_stats_->Process(); |
167 | 154 |
168 // Increase time enough for a new update, but not too much to make the | 155 // Increase time enough for a new update, but not too much to make the |
169 // rtt invalid. Report a lower rtt and verify the old/high value still is sent | 156 // rtt invalid. Report a lower rtt and verify the old/high value still is sent |
170 // in the callback. | 157 // in the callback. |
171 TickTime::AdvanceFakeClock(1000); | 158 TickTime::AdvanceFakeClock(1000); |
172 const int64_t kLowRtt = kFirstRtt - 20; | 159 const int64_t kLowRtt = kFirstRtt - 20; |
| 160 const int64_t kAvgRtt2 = 102; |
173 rtcp_rtt_stats->OnRttUpdate(kLowRtt); | 161 rtcp_rtt_stats->OnRttUpdate(kLowRtt); |
174 EXPECT_CALL(stats_observer, OnRttUpdate(kHighRtt)) | 162 EXPECT_CALL(stats_observer, OnRttUpdate(kAvgRtt2, kHighRtt)).Times(1); |
175 .Times(1); | |
176 call_stats_->Process(); | 163 call_stats_->Process(); |
177 | 164 |
178 // Advance time to make the high report invalid, the lower rtt should now be | 165 // Advance time to make the high report invalid, the lower rtt should now be |
179 // in the callback. | 166 // in the callback. |
180 TickTime::AdvanceFakeClock(1000); | 167 TickTime::AdvanceFakeClock(1000); |
181 EXPECT_CALL(stats_observer, OnRttUpdate(kLowRtt)) | 168 const int64_t kAvgRtt3 = 95; |
182 .Times(1); | 169 EXPECT_CALL(stats_observer, OnRttUpdate(kAvgRtt3, kLowRtt)).Times(1); |
183 call_stats_->Process(); | 170 call_stats_->Process(); |
184 | 171 |
185 call_stats_->DeregisterStatsObserver(&stats_observer); | 172 call_stats_->DeregisterStatsObserver(&stats_observer); |
186 } | 173 } |
187 | 174 |
188 TEST_F(CallStatsTest, LastProcessedRtt) { | 175 TEST_F(CallStatsTest, LastProcessedRtt) { |
189 MockStatsObserver stats_observer; | 176 MockStatsObserver stats_observer; |
190 call_stats_->RegisterStatsObserver(&stats_observer); | 177 call_stats_->RegisterStatsObserver(&stats_observer); |
191 RtcpRttStats* rtcp_rtt_stats = call_stats_->rtcp_rtt_stats(); | 178 RtcpRttStats* rtcp_rtt_stats = call_stats_->rtcp_rtt_stats(); |
192 TickTime::AdvanceFakeClock(1000); | 179 TickTime::AdvanceFakeClock(1000); |
193 | 180 |
194 // Set a first values and verify that LastProcessedRtt initially returns the | 181 // Set a first values and verify that LastProcessedRtt initially returns the |
195 // average rtt. | 182 // average rtt. |
196 const int64_t kRttLow = 10; | 183 const int64_t kRttLow = 10; |
197 const int64_t kRttHigh = 30; | 184 const int64_t kRttHigh = 30; |
198 const int64_t kAvgRtt = 20; | 185 const int64_t kAvgRtt = 20; |
199 rtcp_rtt_stats->OnRttUpdate(kRttLow); | 186 rtcp_rtt_stats->OnRttUpdate(kRttLow); |
200 rtcp_rtt_stats->OnRttUpdate(kRttHigh); | 187 rtcp_rtt_stats->OnRttUpdate(kRttHigh); |
201 EXPECT_CALL(stats_observer, OnRttUpdate(kRttHigh)) | 188 EXPECT_CALL(stats_observer, OnRttUpdate(kAvgRtt, kRttHigh)).Times(1); |
202 .Times(1); | |
203 call_stats_->Process(); | 189 call_stats_->Process(); |
204 EXPECT_EQ(kAvgRtt, rtcp_rtt_stats->LastProcessedRtt()); | 190 EXPECT_EQ(kAvgRtt, rtcp_rtt_stats->LastProcessedRtt()); |
205 | 191 |
206 // Update values and verify LastProcessedRtt. | 192 // Update values and verify LastProcessedRtt. |
207 TickTime::AdvanceFakeClock(1000); | 193 TickTime::AdvanceFakeClock(1000); |
208 rtcp_rtt_stats->OnRttUpdate(kRttLow); | 194 rtcp_rtt_stats->OnRttUpdate(kRttLow); |
209 rtcp_rtt_stats->OnRttUpdate(kRttHigh); | 195 rtcp_rtt_stats->OnRttUpdate(kRttHigh); |
210 EXPECT_CALL(stats_observer, OnRttUpdate(kRttHigh)) | 196 EXPECT_CALL(stats_observer, OnRttUpdate(kAvgRtt, kRttHigh)).Times(1); |
211 .Times(1); | |
212 call_stats_->Process(); | 197 call_stats_->Process(); |
213 EXPECT_EQ(kAvgRtt, rtcp_rtt_stats->LastProcessedRtt()); | 198 EXPECT_EQ(kAvgRtt, rtcp_rtt_stats->LastProcessedRtt()); |
214 | 199 |
215 call_stats_->DeregisterStatsObserver(&stats_observer); | 200 call_stats_->DeregisterStatsObserver(&stats_observer); |
216 } | 201 } |
217 | 202 |
218 } // namespace webrtc | 203 } // namespace webrtc |
OLD | NEW |