Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(238)

Side by Side Diff: webrtc/video/stats_counter_unittest.cc

Issue 2235223002: Add ability to handle data from multiple streams in RateAccCounter. (Closed) Base URL: https://chromium.googlesource.com/external/webrtc.git@master
Patch Set: Created 4 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« webrtc/video/stats_counter.cc ('K') | « webrtc/video/stats_counter.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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/video/stats_counter.h" 11 #include "webrtc/video/stats_counter.h"
12 12
13 #include "testing/gtest/include/gtest/gtest.h" 13 #include "testing/gtest/include/gtest/gtest.h"
14 14
15 #include "webrtc/system_wrappers/include/clock.h" 15 #include "webrtc/system_wrappers/include/clock.h"
16 16
17 namespace webrtc { 17 namespace webrtc {
18 namespace { 18 namespace {
19 const int kProcessIntervalMs = 2000; 19 const int kProcessIntervalMs = 2000;
20 const int kSsrc = 123456;
20 21
21 class StatsCounterObserverImpl : public StatsCounterObserver { 22 class StatsCounterObserverImpl : public StatsCounterObserver {
22 public: 23 public:
23 StatsCounterObserverImpl() : num_calls_(0), last_sample_(-1) {} 24 StatsCounterObserverImpl() : num_calls_(0), last_sample_(-1) {}
24 void OnMetricUpdated(int sample) override { 25 void OnMetricUpdated(int sample) override {
25 ++num_calls_; 26 ++num_calls_;
26 last_sample_ = sample; 27 last_sample_ = sample;
27 } 28 }
28 int num_calls_; 29 int num_calls_;
29 int last_sample_; 30 int last_sample_;
30 }; 31 };
31 } // namespace 32 } // namespace
32 33
33 class StatsCounterTest : public ::testing::Test { 34 class StatsCounterTest : public ::testing::Test {
34 protected: 35 protected:
35 StatsCounterTest() 36 StatsCounterTest()
36 : clock_(1234) {} 37 : clock_(1234) {}
37 38
38 void AddSampleAndAdvance(int sample, int interval_ms, AvgCounter* counter) { 39 void AddSampleAndAdvance(int sample, int interval_ms, AvgCounter* counter) {
39 counter->Add(sample); 40 counter->Add(sample);
40 clock_.AdvanceTimeMilliseconds(interval_ms); 41 clock_.AdvanceTimeMilliseconds(interval_ms);
41 } 42 }
42 43
43 void SetSampleAndAdvance(int sample, 44 void SetSampleAndAdvance(int sample,
44 int interval_ms, 45 int interval_ms,
45 RateAccCounter* counter) { 46 RateAccCounter* counter) {
46 counter->Set(sample); 47 counter->Set(sample, kSsrc);
47 clock_.AdvanceTimeMilliseconds(interval_ms); 48 clock_.AdvanceTimeMilliseconds(interval_ms);
48 } 49 }
49 50
50 void VerifyStatsIsNotSet(const AggregatedStats& stats) { 51 void VerifyStatsIsNotSet(const AggregatedStats& stats) {
51 EXPECT_EQ(0, stats.num_samples); 52 EXPECT_EQ(0, stats.num_samples);
52 EXPECT_EQ(-1, stats.min); 53 EXPECT_EQ(-1, stats.min);
53 EXPECT_EQ(-1, stats.max); 54 EXPECT_EQ(-1, stats.max);
54 EXPECT_EQ(-1, stats.average); 55 EXPECT_EQ(-1, stats.average);
55 } 56 }
56 57
(...skipping 126 matching lines...) Expand 10 before | Expand all | Expand 10 after
183 // Aggregated stats. 184 // Aggregated stats.
184 AggregatedStats stats = counter.GetStats(); 185 AggregatedStats stats = counter.GetStats();
185 EXPECT_EQ(1, stats.num_samples); 186 EXPECT_EQ(1, stats.num_samples);
186 EXPECT_EQ(279, stats.min); 187 EXPECT_EQ(279, stats.min);
187 EXPECT_EQ(279, stats.max); 188 EXPECT_EQ(279, stats.max);
188 } 189 }
189 190
190 TEST_F(StatsCounterTest, TestMetric_RateAccCounter) { 191 TEST_F(StatsCounterTest, TestMetric_RateAccCounter) {
191 StatsCounterObserverImpl* observer = new StatsCounterObserverImpl(); 192 StatsCounterObserverImpl* observer = new StatsCounterObserverImpl();
192 RateAccCounter counter(&clock_, observer, true); 193 RateAccCounter counter(&clock_, observer, true);
193 counter.Set(175); 194 counter.Set(175, kSsrc);
194 counter.Set(188); 195 counter.Set(188, kSsrc);
195 clock_.AdvanceTimeMilliseconds(kProcessIntervalMs); 196 clock_.AdvanceTimeMilliseconds(kProcessIntervalMs);
196 // Trigger process (sample included in next interval). 197 // Trigger process (sample included in next interval).
197 counter.Set(192); 198 counter.Set(192, kSsrc);
198 // Rate per interval: (188 - 0) / 2 sec = 94 samples/sec 199 // Rate per interval: (188 - 0) / 2 sec = 94 samples/sec
199 EXPECT_EQ(1, observer->num_calls_); 200 EXPECT_EQ(1, observer->num_calls_);
200 EXPECT_EQ(94, observer->last_sample_); 201 EXPECT_EQ(94, observer->last_sample_);
201 // Aggregated stats. 202 // Aggregated stats.
202 AggregatedStats stats = counter.GetStats(); 203 AggregatedStats stats = counter.GetStats();
203 EXPECT_EQ(1, stats.num_samples); 204 EXPECT_EQ(1, stats.num_samples);
204 EXPECT_EQ(94, stats.min); 205 EXPECT_EQ(94, stats.min);
205 EXPECT_EQ(94, stats.max); 206 EXPECT_EQ(94, stats.max);
206 } 207 }
207 208
209 TEST_F(StatsCounterTest, TestMetric_RateAccCounterWithMultipleSsrcs) {
210 StatsCounterObserverImpl* observer = new StatsCounterObserverImpl();
211 RateAccCounter counter(&clock_, observer, true);
212 counter.Set(175, kSsrc);
213 counter.Set(188, kSsrc);
214 counter.Set(100, kSsrc + 1);
215 clock_.AdvanceTimeMilliseconds(kProcessIntervalMs);
216 // Trigger process (sample included in next interval).
217 counter.Set(150, kSsrc + 1);
218 // Rate per interval: ((188 - 0) + (100 - 0)) / 2 sec = 144 samples/sec
219 EXPECT_EQ(1, observer->num_calls_);
220 EXPECT_EQ(144, observer->last_sample_);
221 clock_.AdvanceTimeMilliseconds(kProcessIntervalMs);
222 // Trigger process (sample included in next interval).
223 counter.Set(198, kSsrc);
224 // Rate per interval: (0 + (150 - 100)) / 2 sec = 25 samples/sec
225 EXPECT_EQ(2, observer->num_calls_);
226 EXPECT_EQ(25, observer->last_sample_);
227 clock_.AdvanceTimeMilliseconds(kProcessIntervalMs);
228 // Trigger process (sample included in next interval).
229 counter.Set(200, kSsrc);
230 // Rate per interval: ((198 - 188) + (0)) / 2 sec = 5 samples/sec
231 EXPECT_EQ(3, observer->num_calls_);
232 EXPECT_EQ(5, observer->last_sample_);
233 // Aggregated stats.
234 AggregatedStats stats = counter.GetStats();
235 EXPECT_EQ(3, stats.num_samples);
236 EXPECT_EQ(5, stats.min);
237 EXPECT_EQ(144, stats.max);
238 }
239
208 TEST_F(StatsCounterTest, TestGetStats_MultipleIntervals) { 240 TEST_F(StatsCounterTest, TestGetStats_MultipleIntervals) {
209 AvgCounter counter(&clock_, nullptr); 241 AvgCounter counter(&clock_, nullptr);
210 const int kSample1 = 1; 242 const int kSample1 = 1;
211 const int kSample2 = 5; 243 const int kSample2 = 5;
212 const int kSample3 = 8; 244 const int kSample3 = 8;
213 const int kSample4 = 11; 245 const int kSample4 = 11;
214 const int kSample5 = 50; 246 const int kSample5 = 50;
215 AddSampleAndAdvance(kSample1, kProcessIntervalMs, &counter); 247 AddSampleAndAdvance(kSample1, kProcessIntervalMs, &counter);
216 AddSampleAndAdvance(kSample2, kProcessIntervalMs, &counter); 248 AddSampleAndAdvance(kSample2, kProcessIntervalMs, &counter);
217 AddSampleAndAdvance(kSample3, kProcessIntervalMs, &counter); 249 AddSampleAndAdvance(kSample3, kProcessIntervalMs, &counter);
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
252 const int kSample1 = 200; // 200 / 2 sec 284 const int kSample1 = 200; // 200 / 2 sec
253 const int kSample2 = 100; // -100 / 2 sec - negative ignored 285 const int kSample2 = 100; // -100 / 2 sec - negative ignored
254 const int kSample3 = 700; // 600 / 2 sec 286 const int kSample3 = 700; // 600 / 2 sec
255 RateAccCounter counter(&clock_, observer, true); 287 RateAccCounter counter(&clock_, observer, true);
256 SetSampleAndAdvance(kSample1, kProcessIntervalMs, &counter); 288 SetSampleAndAdvance(kSample1, kProcessIntervalMs, &counter);
257 SetSampleAndAdvance(kSample2, kProcessIntervalMs, &counter); 289 SetSampleAndAdvance(kSample2, kProcessIntervalMs, &counter);
258 SetSampleAndAdvance(kSample3, kProcessIntervalMs, &counter); 290 SetSampleAndAdvance(kSample3, kProcessIntervalMs, &counter);
259 EXPECT_EQ(1, observer->num_calls_); 291 EXPECT_EQ(1, observer->num_calls_);
260 EXPECT_EQ(100, observer->last_sample_); 292 EXPECT_EQ(100, observer->last_sample_);
261 // Trigger process (sample included in next interval). 293 // Trigger process (sample included in next interval).
262 counter.Set(2000); 294 counter.Set(2000, kSsrc);
263 EXPECT_EQ(2, observer->num_calls_); 295 EXPECT_EQ(2, observer->num_calls_);
264 EXPECT_EQ(300, observer->last_sample_); 296 EXPECT_EQ(300, observer->last_sample_);
265 // Aggregated stats. 297 // Aggregated stats.
266 AggregatedStats stats = counter.GetStats(); 298 AggregatedStats stats = counter.GetStats();
267 EXPECT_EQ(2, stats.num_samples); 299 EXPECT_EQ(2, stats.num_samples);
268 EXPECT_EQ(100, stats.min); 300 EXPECT_EQ(100, stats.min);
269 EXPECT_EQ(300, stats.max); 301 EXPECT_EQ(300, stats.max);
270 EXPECT_EQ(200, stats.average); 302 EXPECT_EQ(200, stats.average);
271 } 303 }
272 304
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after
338 EXPECT_EQ(3, observer->num_calls_); 370 EXPECT_EQ(3, observer->num_calls_);
339 EXPECT_EQ(10, observer->last_sample_); 371 EXPECT_EQ(10, observer->last_sample_);
340 // Aggregated stats. 372 // Aggregated stats.
341 AggregatedStats stats = counter.GetStats(); 373 AggregatedStats stats = counter.GetStats();
342 EXPECT_EQ(3, stats.num_samples); 374 EXPECT_EQ(3, stats.num_samples);
343 EXPECT_EQ(0, stats.min); 375 EXPECT_EQ(0, stats.min);
344 EXPECT_EQ(25, stats.max); 376 EXPECT_EQ(25, stats.max);
345 } 377 }
346 378
347 } // namespace webrtc 379 } // namespace webrtc
OLDNEW
« webrtc/video/stats_counter.cc ('K') | « webrtc/video/stats_counter.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698