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 <math.h> | 11 #include <math.h> |
12 #include <cmath> | 12 #include <cmath> |
13 #include <cstdlib> | 13 #include <cstdlib> |
14 | 14 |
15 #include "testing/gtest/include/gtest/gtest.h" | 15 #include "testing/gtest/include/gtest/gtest.h" |
16 | 16 |
17 #include "webrtc/base/scoped_ptr.h" | 17 #include "webrtc/base/scoped_ptr.h" |
18 #include "webrtc/common_types.h" | 18 #include "webrtc/common_types.h" |
19 #include "webrtc/modules/remote_bitrate_estimator/inter_arrival.h" | 19 #include "webrtc/modules/remote_bitrate_estimator/inter_arrival.h" |
20 #include "webrtc/modules/remote_bitrate_estimator/overuse_detector.h" | 20 #include "webrtc/modules/remote_bitrate_estimator/overuse_detector.h" |
21 #include "webrtc/modules/remote_bitrate_estimator/overuse_estimator.h" | 21 #include "webrtc/modules/remote_bitrate_estimator/overuse_estimator.h" |
| 22 #include "webrtc/modules/remote_bitrate_estimator/rate_statistics.h" |
22 #include "webrtc/test/testsupport/gtest_disable.h" | 23 #include "webrtc/test/testsupport/gtest_disable.h" |
23 | 24 |
24 namespace webrtc { | 25 namespace webrtc { |
25 namespace testing { | 26 namespace testing { |
26 | 27 |
27 const double kRtpTimestampToMs = 1.0 / 90.0; | 28 const double kRtpTimestampToMs = 1.0 / 90.0; |
28 | 29 |
29 class OveruseDetectorTest : public ::testing::Test { | 30 class OveruseDetectorTest : public ::testing::Test { |
30 protected: | 31 protected: |
31 void SetUp() { | 32 void SetUp() { |
32 srand(1234); | 33 srand(1234); |
33 now_ms_ = 0; | 34 now_ms_ = 0; |
34 receive_time_ms_ = 0; | 35 receive_time_ms_ = 0; |
35 rtp_timestamp_ = 10 * 90; | 36 rtp_timestamp_ = 10 * 90; |
36 overuse_detector_.reset(new OveruseDetector(options_)); | 37 overuse_detector_.reset(new OveruseDetector(options_)); |
37 overuse_estimator_.reset(new OveruseEstimator(options_)); | 38 overuse_estimator_.reset(new OveruseEstimator(options_)); |
38 inter_arrival_.reset(new InterArrival(5 * 90, kRtpTimestampToMs, true)); | 39 inter_arrival_.reset(new InterArrival(5 * 90, kRtpTimestampToMs, true)); |
| 40 incoming_bitrate_.reset(new RateStatistics(1000, 8000)); |
39 } | 41 } |
40 // Normal Distribution. | 42 // Normal Distribution. |
41 #define PI 3.14159265 | 43 #define PI 3.14159265 |
42 int GaussianRandom(int mean_ms, int standard_deviation_ms) { | 44 int GaussianRandom(int mean_ms, int standard_deviation_ms) { |
43 // Creating a Normal distribution variable from two independent uniform | 45 // Creating a Normal distribution variable from two independent uniform |
44 // variables based on the Box-Muller transform. | 46 // variables based on the Box-Muller transform. |
45 double uniform1 = (std::rand() + 1.0) / (RAND_MAX + 1.0); | 47 double uniform1 = (std::rand() + 1.0) / (RAND_MAX + 1.0); |
46 double uniform2 = (std::rand() + 1.0) / (RAND_MAX + 1.0); | 48 double uniform2 = (std::rand() + 1.0) / (RAND_MAX + 1.0); |
47 return static_cast<int>(mean_ms + standard_deviation_ms * | 49 return static_cast<int>(mean_ms + standard_deviation_ms * |
48 sqrt(-2 * log(uniform1)) * cos(2 * PI * uniform2)); | 50 sqrt(-2 * log(uniform1)) * cos(2 * PI * uniform2)); |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
86 } | 88 } |
87 } | 89 } |
88 return -1; | 90 return -1; |
89 } | 91 } |
90 | 92 |
91 void UpdateDetector(uint32_t rtp_timestamp, int64_t receive_time_ms, | 93 void UpdateDetector(uint32_t rtp_timestamp, int64_t receive_time_ms, |
92 size_t packet_size) { | 94 size_t packet_size) { |
93 uint32_t timestamp_delta; | 95 uint32_t timestamp_delta; |
94 int64_t time_delta; | 96 int64_t time_delta; |
95 int size_delta; | 97 int size_delta; |
| 98 incoming_bitrate_->Update(packet_size, receive_time_ms); |
96 if (inter_arrival_->ComputeDeltas(rtp_timestamp, | 99 if (inter_arrival_->ComputeDeltas(rtp_timestamp, |
97 receive_time_ms, | 100 receive_time_ms, |
98 packet_size, | 101 packet_size, |
99 ×tamp_delta, | 102 ×tamp_delta, |
100 &time_delta, | 103 &time_delta, |
101 &size_delta)) { | 104 &size_delta)) { |
102 double timestamp_delta_ms = timestamp_delta / 90.0; | 105 double timestamp_delta_ms = timestamp_delta / 90.0; |
103 overuse_estimator_->Update(time_delta, timestamp_delta_ms, size_delta, | 106 overuse_estimator_->Update(time_delta, timestamp_delta_ms, size_delta, |
104 overuse_detector_->State()); | 107 overuse_detector_->State()); |
105 overuse_detector_->Detect(overuse_estimator_->offset(), | 108 overuse_detector_->Detect( |
106 timestamp_delta_ms, | 109 overuse_estimator_->offset(), timestamp_delta_ms, |
107 overuse_estimator_->num_of_deltas(), 0); | 110 overuse_estimator_->num_of_deltas(), receive_time_ms, |
| 111 incoming_bitrate_->Rate(receive_time_ms)); |
108 } | 112 } |
109 } | 113 } |
110 | 114 |
111 int64_t now_ms_; | 115 int64_t now_ms_; |
112 int64_t receive_time_ms_; | 116 int64_t receive_time_ms_; |
113 uint32_t rtp_timestamp_; | 117 uint32_t rtp_timestamp_; |
114 OverUseDetectorOptions options_; | 118 OverUseDetectorOptions options_; |
115 rtc::scoped_ptr<OveruseDetector> overuse_detector_; | 119 rtc::scoped_ptr<OveruseDetector> overuse_detector_; |
116 rtc::scoped_ptr<OveruseEstimator> overuse_estimator_; | 120 rtc::scoped_ptr<OveruseEstimator> overuse_estimator_; |
117 rtc::scoped_ptr<InterArrival> inter_arrival_; | 121 rtc::scoped_ptr<InterArrival> inter_arrival_; |
| 122 rtc::scoped_ptr<RateStatistics> incoming_bitrate_; |
118 }; | 123 }; |
119 | 124 |
120 TEST_F(OveruseDetectorTest, GaussianRandom) { | 125 TEST_F(OveruseDetectorTest, GaussianRandom) { |
121 int buckets[100]; | 126 int buckets[100]; |
122 memset(buckets, 0, sizeof(buckets)); | 127 memset(buckets, 0, sizeof(buckets)); |
123 for (int i = 0; i < 100000; ++i) { | 128 for (int i = 0; i < 100000; ++i) { |
124 int index = GaussianRandom(49, 10); | 129 int index = GaussianRandom(49, 10); |
125 if (index >= 0 && index < 100) | 130 if (index >= 0 && index < 100) |
126 buckets[index]++; | 131 buckets[index]++; |
127 } | 132 } |
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
185 int packets_per_frame = 6; | 190 int packets_per_frame = 6; |
186 int frame_duration_ms = 33; | 191 int frame_duration_ms = 33; |
187 int drift_per_frame_ms = 1; | 192 int drift_per_frame_ms = 1; |
188 int sigma_ms = 0; // No variance. | 193 int sigma_ms = 0; // No variance. |
189 int unique_overuse = Run100000Samples(packets_per_frame, packet_size, | 194 int unique_overuse = Run100000Samples(packets_per_frame, packet_size, |
190 frame_duration_ms, sigma_ms); | 195 frame_duration_ms, sigma_ms); |
191 | 196 |
192 EXPECT_EQ(0, unique_overuse); | 197 EXPECT_EQ(0, unique_overuse); |
193 int frames_until_overuse = RunUntilOveruse(packets_per_frame, packet_size, | 198 int frames_until_overuse = RunUntilOveruse(packets_per_frame, packet_size, |
194 frame_duration_ms, sigma_ms, drift_per_frame_ms); | 199 frame_duration_ms, sigma_ms, drift_per_frame_ms); |
195 EXPECT_EQ(6, frames_until_overuse); | 200 EXPECT_EQ(11, frames_until_overuse); |
196 } | 201 } |
197 | 202 |
198 TEST_F(OveruseDetectorTest, SimpleOveruse100kbit10fps) { | 203 TEST_F(OveruseDetectorTest, SimpleOveruse100kbit10fps) { |
199 size_t packet_size = 1200; | 204 size_t packet_size = 1200; |
200 int packets_per_frame = 1; | 205 int packets_per_frame = 1; |
201 int frame_duration_ms = 100; | 206 int frame_duration_ms = 100; |
202 int drift_per_frame_ms = 1; | 207 int drift_per_frame_ms = 1; |
203 int sigma_ms = 0; // No variance. | 208 int sigma_ms = 0; // No variance. |
204 int unique_overuse = Run100000Samples(packets_per_frame, packet_size, | 209 int unique_overuse = Run100000Samples(packets_per_frame, packet_size, |
205 frame_duration_ms, sigma_ms); | 210 frame_duration_ms, sigma_ms); |
206 | 211 |
207 EXPECT_EQ(0, unique_overuse); | 212 EXPECT_EQ(0, unique_overuse); |
208 int frames_until_overuse = RunUntilOveruse(packets_per_frame, packet_size, | 213 int frames_until_overuse = RunUntilOveruse(packets_per_frame, packet_size, |
209 frame_duration_ms, sigma_ms, drift_per_frame_ms); | 214 frame_duration_ms, sigma_ms, drift_per_frame_ms); |
210 EXPECT_EQ(4, frames_until_overuse); | 215 EXPECT_EQ(11, frames_until_overuse); |
211 } | 216 } |
212 | 217 |
213 TEST_F(OveruseDetectorTest, DISABLED_OveruseWithHighVariance100Kbit10fps) { | 218 TEST_F(OveruseDetectorTest, DISABLED_OveruseWithHighVariance100Kbit10fps) { |
214 uint32_t frame_duration_ms = 100; | 219 uint32_t frame_duration_ms = 100; |
215 uint32_t drift_per_frame_ms = 10; | 220 uint32_t drift_per_frame_ms = 10; |
216 uint32_t rtp_timestamp = frame_duration_ms * 90; | 221 uint32_t rtp_timestamp = frame_duration_ms * 90; |
217 size_t packet_size = 1200; | 222 size_t packet_size = 1200; |
218 int offset = 10; | 223 int offset = 10; |
219 | 224 |
220 // Run 1000 samples to reach steady state. | 225 // Run 1000 samples to reach steady state. |
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
292 if (i % 2) { | 297 if (i % 2) { |
293 offset = rand() % 2; | 298 offset = rand() % 2; |
294 now_ms_ += frame_duration_ms - offset; | 299 now_ms_ += frame_duration_ms - offset; |
295 } else { | 300 } else { |
296 now_ms_ += frame_duration_ms + offset; | 301 now_ms_ += frame_duration_ms + offset; |
297 } | 302 } |
298 EXPECT_EQ(kBwNormal, overuse_detector_->State()); | 303 EXPECT_EQ(kBwNormal, overuse_detector_->State()); |
299 } | 304 } |
300 // Simulate a higher send pace, that is too high. | 305 // Simulate a higher send pace, that is too high. |
301 // Total build up of 30 ms. | 306 // Total build up of 30 ms. |
302 for (int j = 0; j < 5; ++j) { | 307 for (int j = 0; j < 4; ++j) { |
303 UpdateDetector(rtp_timestamp, now_ms_, packet_size); | 308 UpdateDetector(rtp_timestamp, now_ms_, packet_size); |
304 UpdateDetector(rtp_timestamp, now_ms_, packet_size); | 309 UpdateDetector(rtp_timestamp, now_ms_, packet_size); |
305 UpdateDetector(rtp_timestamp, now_ms_, packet_size); | 310 UpdateDetector(rtp_timestamp, now_ms_, packet_size); |
306 UpdateDetector(rtp_timestamp, now_ms_, packet_size); | 311 UpdateDetector(rtp_timestamp, now_ms_, packet_size); |
307 UpdateDetector(rtp_timestamp, now_ms_, packet_size); | 312 UpdateDetector(rtp_timestamp, now_ms_, packet_size); |
308 UpdateDetector(rtp_timestamp, now_ms_, packet_size); | 313 UpdateDetector(rtp_timestamp, now_ms_, packet_size); |
309 now_ms_ += frame_duration_ms + drift_per_frame_ms * 6; | 314 now_ms_ += frame_duration_ms + drift_per_frame_ms * 6; |
310 rtp_timestamp += frame_duration_ms * 90; | 315 rtp_timestamp += frame_duration_ms * 90; |
311 EXPECT_EQ(kBwNormal, overuse_detector_->State()); | 316 EXPECT_EQ(kBwNormal, overuse_detector_->State()); |
312 } | 317 } |
313 UpdateDetector(rtp_timestamp, now_ms_, packet_size); | 318 UpdateDetector(rtp_timestamp, now_ms_, packet_size); |
314 EXPECT_EQ(kBwOverusing, overuse_detector_->State()); | 319 EXPECT_EQ(kBwOverusing, overuse_detector_->State()); |
315 } | 320 } |
316 | 321 |
317 TEST_F(OveruseDetectorTest, | 322 TEST_F(OveruseDetectorTest, |
318 DISABLED_ON_ANDROID(LowGaussianVariance30Kbit3fps)) { | 323 DISABLED_ON_ANDROID(LowGaussianVariance30Kbit3fps)) { |
319 size_t packet_size = 1200; | 324 size_t packet_size = 1200; |
320 int packets_per_frame = 1; | 325 int packets_per_frame = 1; |
321 int frame_duration_ms = 333; | 326 int frame_duration_ms = 333; |
322 int drift_per_frame_ms = 1; | 327 int drift_per_frame_ms = 1; |
323 int sigma_ms = 3; | 328 int sigma_ms = 3; |
324 int unique_overuse = Run100000Samples(packets_per_frame, packet_size, | 329 int unique_overuse = Run100000Samples(packets_per_frame, packet_size, |
325 frame_duration_ms, sigma_ms); | 330 frame_duration_ms, sigma_ms); |
326 EXPECT_EQ(0, unique_overuse); | 331 EXPECT_EQ(0, unique_overuse); |
327 int frames_until_overuse = RunUntilOveruse(packets_per_frame, packet_size, | 332 int frames_until_overuse = RunUntilOveruse(packets_per_frame, packet_size, |
328 frame_duration_ms, sigma_ms, drift_per_frame_ms); | 333 frame_duration_ms, sigma_ms, drift_per_frame_ms); |
329 EXPECT_NEAR(29, frames_until_overuse, 5); | 334 EXPECT_NEAR(36, frames_until_overuse, 5); |
330 } | 335 } |
331 | 336 |
332 TEST_F(OveruseDetectorTest, LowGaussianVarianceFastDrift30Kbit3fps) { | 337 TEST_F(OveruseDetectorTest, LowGaussianVarianceFastDrift30Kbit3fps) { |
333 size_t packet_size = 1200; | 338 size_t packet_size = 1200; |
334 int packets_per_frame = 1; | 339 int packets_per_frame = 1; |
335 int frame_duration_ms = 333; | 340 int frame_duration_ms = 333; |
336 int drift_per_frame_ms = 100; | 341 int drift_per_frame_ms = 100; |
337 int sigma_ms = 3; | 342 int sigma_ms = 3; |
338 int unique_overuse = Run100000Samples(packets_per_frame, packet_size, | 343 int unique_overuse = Run100000Samples(packets_per_frame, packet_size, |
339 frame_duration_ms, sigma_ms); | 344 frame_duration_ms, sigma_ms); |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
376 size_t packet_size = 1200; | 381 size_t packet_size = 1200; |
377 int packets_per_frame = 2; | 382 int packets_per_frame = 2; |
378 int frame_duration_ms = 200; | 383 int frame_duration_ms = 200; |
379 int drift_per_frame_ms = 1; | 384 int drift_per_frame_ms = 1; |
380 int sigma_ms = 3; | 385 int sigma_ms = 3; |
381 int unique_overuse = Run100000Samples(packets_per_frame, packet_size, | 386 int unique_overuse = Run100000Samples(packets_per_frame, packet_size, |
382 frame_duration_ms, sigma_ms); | 387 frame_duration_ms, sigma_ms); |
383 EXPECT_EQ(0, unique_overuse); | 388 EXPECT_EQ(0, unique_overuse); |
384 int frames_until_overuse = RunUntilOveruse(packets_per_frame, packet_size, | 389 int frames_until_overuse = RunUntilOveruse(packets_per_frame, packet_size, |
385 frame_duration_ms, sigma_ms, drift_per_frame_ms); | 390 frame_duration_ms, sigma_ms, drift_per_frame_ms); |
386 EXPECT_NEAR(29, frames_until_overuse, 5); | 391 EXPECT_NEAR(36, frames_until_overuse, 5); |
387 } | 392 } |
388 | 393 |
389 TEST_F(OveruseDetectorTest, | 394 TEST_F(OveruseDetectorTest, |
390 DISABLED_ON_ANDROID(HighGaussianVariance100Kbit5fps)) { | 395 DISABLED_ON_ANDROID(HighGaussianVariance100Kbit5fps)) { |
391 size_t packet_size = 1200; | 396 size_t packet_size = 1200; |
392 int packets_per_frame = 2; | 397 int packets_per_frame = 2; |
393 int frame_duration_ms = 200; | 398 int frame_duration_ms = 200; |
394 int drift_per_frame_ms = 1; | 399 int drift_per_frame_ms = 1; |
395 int sigma_ms = 10; | 400 int sigma_ms = 10; |
396 int unique_overuse = Run100000Samples(packets_per_frame, packet_size, | 401 int unique_overuse = Run100000Samples(packets_per_frame, packet_size, |
397 frame_duration_ms, sigma_ms); | 402 frame_duration_ms, sigma_ms); |
398 EXPECT_EQ(0, unique_overuse); | 403 EXPECT_EQ(0, unique_overuse); |
399 int frames_until_overuse = RunUntilOveruse(packets_per_frame, packet_size, | 404 int frames_until_overuse = RunUntilOveruse(packets_per_frame, packet_size, |
400 frame_duration_ms, sigma_ms, drift_per_frame_ms); | 405 frame_duration_ms, sigma_ms, drift_per_frame_ms); |
401 EXPECT_NEAR(79, frames_until_overuse, 15); | 406 EXPECT_NEAR(109, frames_until_overuse, 15); |
402 } | 407 } |
403 | 408 |
404 TEST_F(OveruseDetectorTest, | 409 TEST_F(OveruseDetectorTest, |
405 DISABLED_ON_ANDROID(LowGaussianVariance100Kbit10fps)) { | 410 DISABLED_ON_ANDROID(LowGaussianVariance100Kbit10fps)) { |
406 size_t packet_size = 1200; | 411 size_t packet_size = 1200; |
407 int packets_per_frame = 1; | 412 int packets_per_frame = 1; |
408 int frame_duration_ms = 100; | 413 int frame_duration_ms = 100; |
409 int drift_per_frame_ms = 1; | 414 int drift_per_frame_ms = 1; |
410 int sigma_ms = 3; | 415 int sigma_ms = 3; |
411 int unique_overuse = Run100000Samples(packets_per_frame, packet_size, | 416 int unique_overuse = Run100000Samples(packets_per_frame, packet_size, |
412 frame_duration_ms, sigma_ms); | 417 frame_duration_ms, sigma_ms); |
413 EXPECT_EQ(0, unique_overuse); | 418 EXPECT_EQ(0, unique_overuse); |
414 int frames_until_overuse = RunUntilOveruse(packets_per_frame, packet_size, | 419 int frames_until_overuse = RunUntilOveruse(packets_per_frame, packet_size, |
415 frame_duration_ms, sigma_ms, drift_per_frame_ms); | 420 frame_duration_ms, sigma_ms, drift_per_frame_ms); |
416 EXPECT_NEAR(29, frames_until_overuse, 5); | 421 EXPECT_NEAR(36, frames_until_overuse, 5); |
417 } | 422 } |
418 | 423 |
419 TEST_F(OveruseDetectorTest, | 424 TEST_F(OveruseDetectorTest, |
420 DISABLED_ON_ANDROID(HighGaussianVariance100Kbit10fps)) { | 425 DISABLED_ON_ANDROID(HighGaussianVariance100Kbit10fps)) { |
421 size_t packet_size = 1200; | 426 size_t packet_size = 1200; |
422 int packets_per_frame = 1; | 427 int packets_per_frame = 1; |
423 int frame_duration_ms = 100; | 428 int frame_duration_ms = 100; |
424 int drift_per_frame_ms = 1; | 429 int drift_per_frame_ms = 1; |
425 int sigma_ms = 10; | 430 int sigma_ms = 10; |
426 int unique_overuse = Run100000Samples(packets_per_frame, packet_size, | 431 int unique_overuse = Run100000Samples(packets_per_frame, packet_size, |
427 frame_duration_ms, sigma_ms); | 432 frame_duration_ms, sigma_ms); |
428 EXPECT_EQ(0, unique_overuse); | 433 EXPECT_EQ(0, unique_overuse); |
429 int frames_until_overuse = RunUntilOveruse(packets_per_frame, packet_size, | 434 int frames_until_overuse = RunUntilOveruse(packets_per_frame, packet_size, |
430 frame_duration_ms, sigma_ms, drift_per_frame_ms); | 435 frame_duration_ms, sigma_ms, drift_per_frame_ms); |
431 EXPECT_NEAR(79, frames_until_overuse, 15); | 436 EXPECT_NEAR(109, frames_until_overuse, 15); |
432 } | 437 } |
433 | 438 |
434 TEST_F(OveruseDetectorTest, | 439 TEST_F(OveruseDetectorTest, |
435 DISABLED_ON_ANDROID(LowGaussianVariance300Kbit30fps)) { | 440 DISABLED_ON_ANDROID(LowGaussianVariance300Kbit30fps)) { |
436 size_t packet_size = 1200; | 441 size_t packet_size = 1200; |
437 int packets_per_frame = 1; | 442 int packets_per_frame = 1; |
438 int frame_duration_ms = 33; | 443 int frame_duration_ms = 33; |
439 int drift_per_frame_ms = 1; | 444 int drift_per_frame_ms = 1; |
440 int sigma_ms = 3; | 445 int sigma_ms = 3; |
441 int unique_overuse = Run100000Samples(packets_per_frame, packet_size, | 446 int unique_overuse = Run100000Samples(packets_per_frame, packet_size, |
(...skipping 152 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
594 int frame_duration_ms = 33; | 599 int frame_duration_ms = 33; |
595 int drift_per_frame_ms = 10; | 600 int drift_per_frame_ms = 10; |
596 int sigma_ms = 10; | 601 int sigma_ms = 10; |
597 int unique_overuse = Run100000Samples(packets_per_frame, packet_size, | 602 int unique_overuse = Run100000Samples(packets_per_frame, packet_size, |
598 frame_duration_ms, sigma_ms); | 603 frame_duration_ms, sigma_ms); |
599 EXPECT_EQ(0, unique_overuse); | 604 EXPECT_EQ(0, unique_overuse); |
600 int frames_until_overuse = RunUntilOveruse(packets_per_frame, packet_size, | 605 int frames_until_overuse = RunUntilOveruse(packets_per_frame, packet_size, |
601 frame_duration_ms, sigma_ms, drift_per_frame_ms); | 606 frame_duration_ms, sigma_ms, drift_per_frame_ms); |
602 EXPECT_NEAR(12, frames_until_overuse, 2); | 607 EXPECT_NEAR(12, frames_until_overuse, 2); |
603 } | 608 } |
| 609 |
| 610 class AdaptiveThresholdDetector : public OveruseDetector { |
| 611 public: |
| 612 explicit AdaptiveThresholdDetector(const OverUseDetectorOptions& options) |
| 613 : OveruseDetector(options) {} |
| 614 |
| 615 virtual ~AdaptiveThresholdDetector() {} |
| 616 |
| 617 bool AdaptiveThresholdExperimentIsEnabled() const override { return true; } |
| 618 bool ExperimentVariationIsEnabled(const char* variation) const override { |
| 619 return true; |
| 620 } |
| 621 }; |
| 622 |
| 623 TEST_F(OveruseDetectorTest, ThresholdAdapts) { |
| 624 overuse_detector_.reset(new AdaptiveThresholdDetector(options_)); |
| 625 const double kOffset = 0.21; |
| 626 double kTsDelta = 3000.0; |
| 627 const int kIncomingBitrateBps = 1500000; |
| 628 int64_t now_ms = 0; |
| 629 int num_deltas = 60; |
| 630 const int kBatchLength = 10; |
| 631 |
| 632 // Pass in a positive offset and verify it triggers overuse. |
| 633 bool overuse_detected = false; |
| 634 for (int i = 0; i < kBatchLength; ++i) { |
| 635 BandwidthUsage overuse_state = overuse_detector_->Detect( |
| 636 kOffset, kTsDelta, num_deltas, now_ms, kIncomingBitrateBps); |
| 637 if (overuse_state == kBwOverusing) { |
| 638 overuse_detected = true; |
| 639 } |
| 640 ++num_deltas; |
| 641 now_ms += 5; |
| 642 } |
| 643 EXPECT_TRUE(overuse_detected); |
| 644 |
| 645 // Force the threshold to increase by passing in a higher offset. |
| 646 overuse_detected = false; |
| 647 for (int i = 0; i < kBatchLength; ++i) { |
| 648 BandwidthUsage overuse_state = overuse_detector_->Detect( |
| 649 1.1 * kOffset, kTsDelta, num_deltas, now_ms, kIncomingBitrateBps); |
| 650 if (overuse_state == kBwOverusing) { |
| 651 overuse_detected = true; |
| 652 } |
| 653 ++num_deltas; |
| 654 now_ms += 5; |
| 655 } |
| 656 EXPECT_TRUE(overuse_detected); |
| 657 |
| 658 // Verify that the same offset as before no longer triggers overuse. |
| 659 overuse_detected = false; |
| 660 for (int i = 0; i < kBatchLength; ++i) { |
| 661 BandwidthUsage overuse_state = overuse_detector_->Detect( |
| 662 kOffset, kTsDelta, num_deltas, now_ms, kIncomingBitrateBps); |
| 663 if (overuse_state == kBwOverusing) { |
| 664 overuse_detected = true; |
| 665 } |
| 666 ++num_deltas; |
| 667 now_ms += 5; |
| 668 } |
| 669 EXPECT_FALSE(overuse_detected); |
| 670 |
| 671 // Pass in a low offset to make the threshold adapt down. |
| 672 for (int i = 0; i < 10 * kBatchLength; ++i) { |
| 673 BandwidthUsage overuse_state = overuse_detector_->Detect( |
| 674 0.7 * kOffset, kTsDelta, num_deltas, now_ms, kIncomingBitrateBps); |
| 675 if (overuse_state == kBwOverusing) { |
| 676 overuse_detected = true; |
| 677 } |
| 678 ++num_deltas; |
| 679 now_ms += 5; |
| 680 } |
| 681 EXPECT_FALSE(overuse_detected); |
| 682 |
| 683 // Make sure the original offset now again triggers overuse. |
| 684 for (int i = 0; i < kBatchLength; ++i) { |
| 685 BandwidthUsage overuse_state = overuse_detector_->Detect( |
| 686 kOffset, kTsDelta, num_deltas, now_ms, kIncomingBitrateBps); |
| 687 if (overuse_state == kBwOverusing) { |
| 688 overuse_detected = true; |
| 689 } |
| 690 ++num_deltas; |
| 691 now_ms += 5; |
| 692 } |
| 693 EXPECT_TRUE(overuse_detected); |
| 694 } |
| 695 |
| 696 TEST_F(OveruseDetectorTest, DoesntAdaptToSpikes) { |
| 697 overuse_detector_.reset(new AdaptiveThresholdDetector(options_)); |
| 698 const double kOffset = 1.0; |
| 699 const double kLargeOffset = 20.0; |
| 700 double kTsDelta = 3000.0; |
| 701 const int kIncomingBitrateBps = 1500000; |
| 702 int64_t now_ms = 0; |
| 703 int num_deltas = 60; |
| 704 const int kBatchLength = 10; |
| 705 const int kShortBatchLength = 3; |
| 706 |
| 707 // Pass in a positive offset and verify it triggers overuse. |
| 708 bool overuse_detected = false; |
| 709 for (int i = 0; i < kBatchLength; ++i) { |
| 710 BandwidthUsage overuse_state = overuse_detector_->Detect( |
| 711 kOffset, kTsDelta, num_deltas, now_ms, kIncomingBitrateBps); |
| 712 if (overuse_state == kBwOverusing) { |
| 713 overuse_detected = true; |
| 714 } |
| 715 ++num_deltas; |
| 716 now_ms += 5; |
| 717 } |
| 718 |
| 719 // Pass in a large offset. This shouldn't have a too big impact on the |
| 720 // threshold, but still trigger an overuse. |
| 721 now_ms += 100; |
| 722 overuse_detected = false; |
| 723 for (int i = 0; i < kShortBatchLength; ++i) { |
| 724 BandwidthUsage overuse_state = overuse_detector_->Detect( |
| 725 kLargeOffset, kTsDelta, num_deltas, now_ms, kIncomingBitrateBps); |
| 726 if (overuse_state == kBwOverusing) { |
| 727 overuse_detected = true; |
| 728 } |
| 729 ++num_deltas; |
| 730 now_ms += 5; |
| 731 } |
| 732 EXPECT_TRUE(overuse_detected); |
| 733 |
| 734 // Pass in a positive normal offset and verify it still triggers. |
| 735 overuse_detected = false; |
| 736 for (int i = 0; i < kBatchLength; ++i) { |
| 737 BandwidthUsage overuse_state = overuse_detector_->Detect( |
| 738 kOffset, kTsDelta, num_deltas, now_ms, kIncomingBitrateBps); |
| 739 if (overuse_state == kBwOverusing) { |
| 740 overuse_detected = true; |
| 741 } |
| 742 ++num_deltas; |
| 743 now_ms += 5; |
| 744 } |
| 745 EXPECT_TRUE(overuse_detected); |
| 746 } |
604 } // namespace testing | 747 } // namespace testing |
605 } // namespace webrtc | 748 } // namespace webrtc |
OLD | NEW |