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

Side by Side Diff: webrtc/modules/remote_bitrate_estimator/overuse_detector_unittest.cc

Issue 2800633004: Resolve dependency between rtc_event_log_api and remote_bitrate_estimator (Closed)
Patch Set: Rebased Created 3 years, 8 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
OLDNEW
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
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
52 for (int i = 0; i < 100000; ++i) { 52 for (int i = 0; i < 100000; ++i) {
53 for (int j = 0; j < packets_per_frame; ++j) { 53 for (int j = 0; j < packets_per_frame; ++j) {
54 UpdateDetector(rtp_timestamp_, receive_time_ms_, packet_size); 54 UpdateDetector(rtp_timestamp_, receive_time_ms_, packet_size);
55 } 55 }
56 rtp_timestamp_ += mean_ms * 90; 56 rtp_timestamp_ += mean_ms * 90;
57 now_ms_ += mean_ms; 57 now_ms_ += mean_ms;
58 receive_time_ms_ = std::max<int64_t>( 58 receive_time_ms_ = std::max<int64_t>(
59 receive_time_ms_, 59 receive_time_ms_,
60 now_ms_ + static_cast<int64_t>( 60 now_ms_ + static_cast<int64_t>(
61 random_.Gaussian(0, standard_deviation_ms) + 0.5)); 61 random_.Gaussian(0, standard_deviation_ms) + 0.5));
62 if (kBwOverusing == overuse_detector_->State()) { 62 if (BandwidthUsage::kBwOverusing == overuse_detector_->State()) {
63 if (last_overuse + 1 != i) { 63 if (last_overuse + 1 != i) {
64 unique_overuse++; 64 unique_overuse++;
65 } 65 }
66 last_overuse = i; 66 last_overuse = i;
67 } 67 }
68 } 68 }
69 return unique_overuse; 69 return unique_overuse;
70 } 70 }
71 71
72 int RunUntilOveruse(int packets_per_frame, size_t packet_size, int mean_ms, 72 int RunUntilOveruse(int packets_per_frame, size_t packet_size, int mean_ms,
73 int standard_deviation_ms, int drift_per_frame_ms) { 73 int standard_deviation_ms, int drift_per_frame_ms) {
74 // Simulate a higher send pace, that is too high. 74 // Simulate a higher send pace, that is too high.
75 for (int i = 0; i < 1000; ++i) { 75 for (int i = 0; i < 1000; ++i) {
76 for (int j = 0; j < packets_per_frame; ++j) { 76 for (int j = 0; j < packets_per_frame; ++j) {
77 UpdateDetector(rtp_timestamp_, receive_time_ms_, packet_size); 77 UpdateDetector(rtp_timestamp_, receive_time_ms_, packet_size);
78 } 78 }
79 rtp_timestamp_ += mean_ms * 90; 79 rtp_timestamp_ += mean_ms * 90;
80 now_ms_ += mean_ms + drift_per_frame_ms; 80 now_ms_ += mean_ms + drift_per_frame_ms;
81 receive_time_ms_ = std::max<int64_t>( 81 receive_time_ms_ = std::max<int64_t>(
82 receive_time_ms_, 82 receive_time_ms_,
83 now_ms_ + static_cast<int64_t>( 83 now_ms_ + static_cast<int64_t>(
84 random_.Gaussian(0, standard_deviation_ms) + 0.5)); 84 random_.Gaussian(0, standard_deviation_ms) + 0.5));
85 if (kBwOverusing == overuse_detector_->State()) { 85 if (BandwidthUsage::kBwOverusing == overuse_detector_->State()) {
86 return i + 1; 86 return i + 1;
87 } 87 }
88 } 88 }
89 return -1; 89 return -1;
90 } 90 }
91 91
92 void UpdateDetector(uint32_t rtp_timestamp, int64_t receive_time_ms, 92 void UpdateDetector(uint32_t rtp_timestamp, int64_t receive_time_ms,
93 size_t packet_size) { 93 size_t packet_size) {
94 uint32_t timestamp_delta; 94 uint32_t timestamp_delta;
95 int64_t time_delta; 95 int64_t time_delta;
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
132 TEST_F(OveruseDetectorTest, SimpleNonOveruse30fps) { 132 TEST_F(OveruseDetectorTest, SimpleNonOveruse30fps) {
133 size_t packet_size = 1200; 133 size_t packet_size = 1200;
134 uint32_t frame_duration_ms = 33; 134 uint32_t frame_duration_ms = 33;
135 uint32_t rtp_timestamp = 10 * 90; 135 uint32_t rtp_timestamp = 10 * 90;
136 136
137 // No variance. 137 // No variance.
138 for (int i = 0; i < 1000; ++i) { 138 for (int i = 0; i < 1000; ++i) {
139 UpdateDetector(rtp_timestamp, now_ms_, packet_size); 139 UpdateDetector(rtp_timestamp, now_ms_, packet_size);
140 now_ms_ += frame_duration_ms; 140 now_ms_ += frame_duration_ms;
141 rtp_timestamp += frame_duration_ms * 90; 141 rtp_timestamp += frame_duration_ms * 90;
142 EXPECT_EQ(kBwNormal, overuse_detector_->State()); 142 EXPECT_EQ(BandwidthUsage::kBwNormal, overuse_detector_->State());
143 } 143 }
144 } 144 }
145 145
146 // Roughly 1 Mbit/s 146 // Roughly 1 Mbit/s
147 TEST_F(OveruseDetectorTest, SimpleNonOveruseWithReceiveVariance) { 147 TEST_F(OveruseDetectorTest, SimpleNonOveruseWithReceiveVariance) {
148 uint32_t frame_duration_ms = 10; 148 uint32_t frame_duration_ms = 10;
149 uint32_t rtp_timestamp = 10 * 90; 149 uint32_t rtp_timestamp = 10 * 90;
150 size_t packet_size = 1200; 150 size_t packet_size = 1200;
151 151
152 for (int i = 0; i < 1000; ++i) { 152 for (int i = 0; i < 1000; ++i) {
153 UpdateDetector(rtp_timestamp, now_ms_, packet_size); 153 UpdateDetector(rtp_timestamp, now_ms_, packet_size);
154 rtp_timestamp += frame_duration_ms * 90; 154 rtp_timestamp += frame_duration_ms * 90;
155 if (i % 2) { 155 if (i % 2) {
156 now_ms_ += frame_duration_ms - 5; 156 now_ms_ += frame_duration_ms - 5;
157 } else { 157 } else {
158 now_ms_ += frame_duration_ms + 5; 158 now_ms_ += frame_duration_ms + 5;
159 } 159 }
160 EXPECT_EQ(kBwNormal, overuse_detector_->State()); 160 EXPECT_EQ(BandwidthUsage::kBwNormal, overuse_detector_->State());
161 } 161 }
162 } 162 }
163 163
164 TEST_F(OveruseDetectorTest, SimpleNonOveruseWithRtpTimestampVariance) { 164 TEST_F(OveruseDetectorTest, SimpleNonOveruseWithRtpTimestampVariance) {
165 // Roughly 1 Mbit/s. 165 // Roughly 1 Mbit/s.
166 uint32_t frame_duration_ms = 10; 166 uint32_t frame_duration_ms = 10;
167 uint32_t rtp_timestamp = 10 * 90; 167 uint32_t rtp_timestamp = 10 * 90;
168 size_t packet_size = 1200; 168 size_t packet_size = 1200;
169 169
170 for (int i = 0; i < 1000; ++i) { 170 for (int i = 0; i < 1000; ++i) {
171 UpdateDetector(rtp_timestamp, now_ms_, packet_size); 171 UpdateDetector(rtp_timestamp, now_ms_, packet_size);
172 now_ms_ += frame_duration_ms; 172 now_ms_ += frame_duration_ms;
173 if (i % 2) { 173 if (i % 2) {
174 rtp_timestamp += (frame_duration_ms - 5) * 90; 174 rtp_timestamp += (frame_duration_ms - 5) * 90;
175 } else { 175 } else {
176 rtp_timestamp += (frame_duration_ms + 5) * 90; 176 rtp_timestamp += (frame_duration_ms + 5) * 90;
177 } 177 }
178 EXPECT_EQ(kBwNormal, overuse_detector_->State()); 178 EXPECT_EQ(BandwidthUsage::kBwNormal, overuse_detector_->State());
179 } 179 }
180 } 180 }
181 181
182 TEST_F(OveruseDetectorTest, SimpleOveruse2000Kbit30fps) { 182 TEST_F(OveruseDetectorTest, SimpleOveruse2000Kbit30fps) {
183 size_t packet_size = 1200; 183 size_t packet_size = 1200;
184 int packets_per_frame = 6; 184 int packets_per_frame = 6;
185 int frame_duration_ms = 33; 185 int frame_duration_ms = 33;
186 int drift_per_frame_ms = 1; 186 int drift_per_frame_ms = 1;
187 int sigma_ms = 0; // No variance. 187 int sigma_ms = 0; // No variance.
188 int unique_overuse = Run100000Samples(packets_per_frame, packet_size, 188 int unique_overuse = Run100000Samples(packets_per_frame, packet_size,
(...skipping 30 matching lines...) Expand all
219 // Run 1000 samples to reach steady state. 219 // Run 1000 samples to reach steady state.
220 for (int i = 0; i < 1000; ++i) { 220 for (int i = 0; i < 1000; ++i) {
221 UpdateDetector(rtp_timestamp, now_ms_, packet_size); 221 UpdateDetector(rtp_timestamp, now_ms_, packet_size);
222 rtp_timestamp += frame_duration_ms * 90; 222 rtp_timestamp += frame_duration_ms * 90;
223 if (i % 2) { 223 if (i % 2) {
224 offset = random_.Rand(0, 49); 224 offset = random_.Rand(0, 49);
225 now_ms_ += frame_duration_ms - offset; 225 now_ms_ += frame_duration_ms - offset;
226 } else { 226 } else {
227 now_ms_ += frame_duration_ms + offset; 227 now_ms_ += frame_duration_ms + offset;
228 } 228 }
229 EXPECT_EQ(kBwNormal, overuse_detector_->State()); 229 EXPECT_EQ(BandwidthUsage::kBwNormal, overuse_detector_->State());
230 } 230 }
231 // Simulate a higher send pace, that is too high. 231 // Simulate a higher send pace, that is too high.
232 // Above noise generate a standard deviation of approximately 28 ms. 232 // Above noise generate a standard deviation of approximately 28 ms.
233 // Total build up of 150 ms. 233 // Total build up of 150 ms.
234 for (int j = 0; j < 15; ++j) { 234 for (int j = 0; j < 15; ++j) {
235 UpdateDetector(rtp_timestamp, now_ms_, packet_size); 235 UpdateDetector(rtp_timestamp, now_ms_, packet_size);
236 now_ms_ += frame_duration_ms + drift_per_frame_ms; 236 now_ms_ += frame_duration_ms + drift_per_frame_ms;
237 rtp_timestamp += frame_duration_ms * 90; 237 rtp_timestamp += frame_duration_ms * 90;
238 EXPECT_EQ(kBwNormal, overuse_detector_->State()); 238 EXPECT_EQ(BandwidthUsage::kBwNormal, overuse_detector_->State());
239 } 239 }
240 UpdateDetector(rtp_timestamp, now_ms_, packet_size); 240 UpdateDetector(rtp_timestamp, now_ms_, packet_size);
241 EXPECT_EQ(kBwOverusing, overuse_detector_->State()); 241 EXPECT_EQ(BandwidthUsage::kBwOverusing, overuse_detector_->State());
242 } 242 }
243 243
244 TEST_F(OveruseDetectorTest, DISABLED_OveruseWithLowVariance100Kbit10fps) { 244 TEST_F(OveruseDetectorTest, DISABLED_OveruseWithLowVariance100Kbit10fps) {
245 uint32_t frame_duration_ms = 100; 245 uint32_t frame_duration_ms = 100;
246 uint32_t drift_per_frame_ms = 1; 246 uint32_t drift_per_frame_ms = 1;
247 uint32_t rtp_timestamp = frame_duration_ms * 90; 247 uint32_t rtp_timestamp = frame_duration_ms * 90;
248 size_t packet_size = 1200; 248 size_t packet_size = 1200;
249 int offset = 10; 249 int offset = 10;
250 250
251 // Run 1000 samples to reach steady state. 251 // Run 1000 samples to reach steady state.
252 for (int i = 0; i < 1000; ++i) { 252 for (int i = 0; i < 1000; ++i) {
253 UpdateDetector(rtp_timestamp, now_ms_, packet_size); 253 UpdateDetector(rtp_timestamp, now_ms_, packet_size);
254 rtp_timestamp += frame_duration_ms * 90; 254 rtp_timestamp += frame_duration_ms * 90;
255 if (i % 2) { 255 if (i % 2) {
256 offset = random_.Rand(0, 1); 256 offset = random_.Rand(0, 1);
257 now_ms_ += frame_duration_ms - offset; 257 now_ms_ += frame_duration_ms - offset;
258 } else { 258 } else {
259 now_ms_ += frame_duration_ms + offset; 259 now_ms_ += frame_duration_ms + offset;
260 } 260 }
261 EXPECT_EQ(kBwNormal, overuse_detector_->State()); 261 EXPECT_EQ(BandwidthUsage::kBwNormal, overuse_detector_->State());
262 } 262 }
263 // Simulate a higher send pace, that is too high. 263 // Simulate a higher send pace, that is too high.
264 // Total build up of 6 ms. 264 // Total build up of 6 ms.
265 for (int j = 0; j < 6; ++j) { 265 for (int j = 0; j < 6; ++j) {
266 UpdateDetector(rtp_timestamp, now_ms_, packet_size); 266 UpdateDetector(rtp_timestamp, now_ms_, packet_size);
267 now_ms_ += frame_duration_ms + drift_per_frame_ms; 267 now_ms_ += frame_duration_ms + drift_per_frame_ms;
268 rtp_timestamp += frame_duration_ms * 90; 268 rtp_timestamp += frame_duration_ms * 90;
269 EXPECT_EQ(kBwNormal, overuse_detector_->State()); 269 EXPECT_EQ(BandwidthUsage::kBwNormal, overuse_detector_->State());
270 } 270 }
271 UpdateDetector(rtp_timestamp, now_ms_, packet_size); 271 UpdateDetector(rtp_timestamp, now_ms_, packet_size);
272 EXPECT_EQ(kBwOverusing, overuse_detector_->State()); 272 EXPECT_EQ(BandwidthUsage::kBwOverusing, overuse_detector_->State());
273 } 273 }
274 274
275 TEST_F(OveruseDetectorTest, OveruseWithLowVariance2000Kbit30fps) { 275 TEST_F(OveruseDetectorTest, OveruseWithLowVariance2000Kbit30fps) {
276 uint32_t frame_duration_ms = 33; 276 uint32_t frame_duration_ms = 33;
277 uint32_t drift_per_frame_ms = 1; 277 uint32_t drift_per_frame_ms = 1;
278 uint32_t rtp_timestamp = frame_duration_ms * 90; 278 uint32_t rtp_timestamp = frame_duration_ms * 90;
279 size_t packet_size = 1200; 279 size_t packet_size = 1200;
280 int offset = 0; 280 int offset = 0;
281 281
282 // Run 1000 samples to reach steady state. 282 // Run 1000 samples to reach steady state.
283 for (int i = 0; i < 1000; ++i) { 283 for (int i = 0; i < 1000; ++i) {
284 UpdateDetector(rtp_timestamp, now_ms_, packet_size); 284 UpdateDetector(rtp_timestamp, now_ms_, packet_size);
285 UpdateDetector(rtp_timestamp, now_ms_, packet_size); 285 UpdateDetector(rtp_timestamp, now_ms_, packet_size);
286 UpdateDetector(rtp_timestamp, now_ms_, packet_size); 286 UpdateDetector(rtp_timestamp, now_ms_, packet_size);
287 UpdateDetector(rtp_timestamp, now_ms_, packet_size); 287 UpdateDetector(rtp_timestamp, now_ms_, packet_size);
288 UpdateDetector(rtp_timestamp, now_ms_, packet_size); 288 UpdateDetector(rtp_timestamp, now_ms_, packet_size);
289 UpdateDetector(rtp_timestamp, now_ms_, packet_size); 289 UpdateDetector(rtp_timestamp, now_ms_, packet_size);
290 rtp_timestamp += frame_duration_ms * 90; 290 rtp_timestamp += frame_duration_ms * 90;
291 if (i % 2) { 291 if (i % 2) {
292 offset = random_.Rand(0, 1); 292 offset = random_.Rand(0, 1);
293 now_ms_ += frame_duration_ms - offset; 293 now_ms_ += frame_duration_ms - offset;
294 } else { 294 } else {
295 now_ms_ += frame_duration_ms + offset; 295 now_ms_ += frame_duration_ms + offset;
296 } 296 }
297 EXPECT_EQ(kBwNormal, overuse_detector_->State()); 297 EXPECT_EQ(BandwidthUsage::kBwNormal, overuse_detector_->State());
298 } 298 }
299 // Simulate a higher send pace, that is too high. 299 // Simulate a higher send pace, that is too high.
300 // Total build up of 30 ms. 300 // Total build up of 30 ms.
301 for (int j = 0; j < 3; ++j) { 301 for (int j = 0; j < 3; ++j) {
302 UpdateDetector(rtp_timestamp, now_ms_, packet_size); 302 UpdateDetector(rtp_timestamp, now_ms_, packet_size);
303 UpdateDetector(rtp_timestamp, now_ms_, packet_size); 303 UpdateDetector(rtp_timestamp, now_ms_, packet_size);
304 UpdateDetector(rtp_timestamp, now_ms_, packet_size); 304 UpdateDetector(rtp_timestamp, now_ms_, packet_size);
305 UpdateDetector(rtp_timestamp, now_ms_, packet_size); 305 UpdateDetector(rtp_timestamp, now_ms_, packet_size);
306 UpdateDetector(rtp_timestamp, now_ms_, packet_size); 306 UpdateDetector(rtp_timestamp, now_ms_, packet_size);
307 UpdateDetector(rtp_timestamp, now_ms_, packet_size); 307 UpdateDetector(rtp_timestamp, now_ms_, packet_size);
308 now_ms_ += frame_duration_ms + drift_per_frame_ms * 6; 308 now_ms_ += frame_duration_ms + drift_per_frame_ms * 6;
309 rtp_timestamp += frame_duration_ms * 90; 309 rtp_timestamp += frame_duration_ms * 90;
310 EXPECT_EQ(kBwNormal, overuse_detector_->State()); 310 EXPECT_EQ(BandwidthUsage::kBwNormal, overuse_detector_->State());
311 } 311 }
312 UpdateDetector(rtp_timestamp, now_ms_, packet_size); 312 UpdateDetector(rtp_timestamp, now_ms_, packet_size);
313 EXPECT_EQ(kBwOverusing, overuse_detector_->State()); 313 EXPECT_EQ(BandwidthUsage::kBwOverusing, overuse_detector_->State());
314 } 314 }
315 315
316 #if defined(WEBRTC_ANDROID) 316 #if defined(WEBRTC_ANDROID)
317 #define MAYBE_LowGaussianVariance30Kbit3fps \ 317 #define MAYBE_LowGaussianVariance30Kbit3fps \
318 DISABLED_LowGaussianVariance30Kbit3fps 318 DISABLED_LowGaussianVariance30Kbit3fps
319 #else 319 #else
320 #define MAYBE_LowGaussianVariance30Kbit3fps LowGaussianVariance30Kbit3fps 320 #define MAYBE_LowGaussianVariance30Kbit3fps LowGaussianVariance30Kbit3fps
321 #endif 321 #endif
322 TEST_F(OveruseDetectorTest, MAYBE_LowGaussianVariance30Kbit3fps) { 322 TEST_F(OveruseDetectorTest, MAYBE_LowGaussianVariance30Kbit3fps) {
323 size_t packet_size = 1200; 323 size_t packet_size = 1200;
(...skipping 336 matching lines...) Expand 10 before | Expand all | Expand 10 after
660 double kTsDelta = 3000.0; 660 double kTsDelta = 3000.0;
661 int64_t now_ms = 0; 661 int64_t now_ms = 0;
662 int num_deltas = 60; 662 int num_deltas = 60;
663 const int kBatchLength = 10; 663 const int kBatchLength = 10;
664 664
665 // Pass in a positive offset and verify it triggers overuse. 665 // Pass in a positive offset and verify it triggers overuse.
666 bool overuse_detected = false; 666 bool overuse_detected = false;
667 for (int i = 0; i < kBatchLength; ++i) { 667 for (int i = 0; i < kBatchLength; ++i) {
668 BandwidthUsage overuse_state = 668 BandwidthUsage overuse_state =
669 overuse_detector_->Detect(kOffset, kTsDelta, num_deltas, now_ms); 669 overuse_detector_->Detect(kOffset, kTsDelta, num_deltas, now_ms);
670 if (overuse_state == kBwOverusing) { 670 if (overuse_state == BandwidthUsage::kBwOverusing) {
671 overuse_detected = true; 671 overuse_detected = true;
672 } 672 }
673 ++num_deltas; 673 ++num_deltas;
674 now_ms += 5; 674 now_ms += 5;
675 } 675 }
676 EXPECT_TRUE(overuse_detected); 676 EXPECT_TRUE(overuse_detected);
677 677
678 // Force the threshold to increase by passing in a higher offset. 678 // Force the threshold to increase by passing in a higher offset.
679 overuse_detected = false; 679 overuse_detected = false;
680 for (int i = 0; i < kBatchLength; ++i) { 680 for (int i = 0; i < kBatchLength; ++i) {
681 BandwidthUsage overuse_state = 681 BandwidthUsage overuse_state =
682 overuse_detector_->Detect(1.1 * kOffset, kTsDelta, num_deltas, now_ms); 682 overuse_detector_->Detect(1.1 * kOffset, kTsDelta, num_deltas, now_ms);
683 if (overuse_state == kBwOverusing) { 683 if (overuse_state == BandwidthUsage::kBwOverusing) {
684 overuse_detected = true; 684 overuse_detected = true;
685 } 685 }
686 ++num_deltas; 686 ++num_deltas;
687 now_ms += 5; 687 now_ms += 5;
688 } 688 }
689 EXPECT_TRUE(overuse_detected); 689 EXPECT_TRUE(overuse_detected);
690 690
691 // Verify that the same offset as before no longer triggers overuse. 691 // Verify that the same offset as before no longer triggers overuse.
692 overuse_detected = false; 692 overuse_detected = false;
693 for (int i = 0; i < kBatchLength; ++i) { 693 for (int i = 0; i < kBatchLength; ++i) {
694 BandwidthUsage overuse_state = 694 BandwidthUsage overuse_state =
695 overuse_detector_->Detect(kOffset, kTsDelta, num_deltas, now_ms); 695 overuse_detector_->Detect(kOffset, kTsDelta, num_deltas, now_ms);
696 if (overuse_state == kBwOverusing) { 696 if (overuse_state == BandwidthUsage::kBwOverusing) {
697 overuse_detected = true; 697 overuse_detected = true;
698 } 698 }
699 ++num_deltas; 699 ++num_deltas;
700 now_ms += 5; 700 now_ms += 5;
701 } 701 }
702 EXPECT_FALSE(overuse_detected); 702 EXPECT_FALSE(overuse_detected);
703 703
704 // Pass in a low offset to make the threshold adapt down. 704 // Pass in a low offset to make the threshold adapt down.
705 for (int i = 0; i < 15 * kBatchLength; ++i) { 705 for (int i = 0; i < 15 * kBatchLength; ++i) {
706 BandwidthUsage overuse_state = 706 BandwidthUsage overuse_state =
707 overuse_detector_->Detect(0.7 * kOffset, kTsDelta, num_deltas, now_ms); 707 overuse_detector_->Detect(0.7 * kOffset, kTsDelta, num_deltas, now_ms);
708 if (overuse_state == kBwOverusing) { 708 if (overuse_state == BandwidthUsage::kBwOverusing) {
709 overuse_detected = true; 709 overuse_detected = true;
710 } 710 }
711 ++num_deltas; 711 ++num_deltas;
712 now_ms += 5; 712 now_ms += 5;
713 } 713 }
714 EXPECT_FALSE(overuse_detected); 714 EXPECT_FALSE(overuse_detected);
715 715
716 // Make sure the original offset now again triggers overuse. 716 // Make sure the original offset now again triggers overuse.
717 for (int i = 0; i < kBatchLength; ++i) { 717 for (int i = 0; i < kBatchLength; ++i) {
718 BandwidthUsage overuse_state = 718 BandwidthUsage overuse_state =
719 overuse_detector_->Detect(kOffset, kTsDelta, num_deltas, now_ms); 719 overuse_detector_->Detect(kOffset, kTsDelta, num_deltas, now_ms);
720 if (overuse_state == kBwOverusing) { 720 if (overuse_state == BandwidthUsage::kBwOverusing) {
721 overuse_detected = true; 721 overuse_detected = true;
722 } 722 }
723 ++num_deltas; 723 ++num_deltas;
724 now_ms += 5; 724 now_ms += 5;
725 } 725 }
726 EXPECT_TRUE(overuse_detected); 726 EXPECT_TRUE(overuse_detected);
727 } 727 }
728 728
729 TEST_F(OveruseDetectorExperimentTest, DoesntAdaptToSpikes) { 729 TEST_F(OveruseDetectorExperimentTest, DoesntAdaptToSpikes) {
730 const double kOffset = 1.0; 730 const double kOffset = 1.0;
731 const double kLargeOffset = 20.0; 731 const double kLargeOffset = 20.0;
732 double kTsDelta = 3000.0; 732 double kTsDelta = 3000.0;
733 int64_t now_ms = 0; 733 int64_t now_ms = 0;
734 int num_deltas = 60; 734 int num_deltas = 60;
735 const int kBatchLength = 10; 735 const int kBatchLength = 10;
736 const int kShortBatchLength = 3; 736 const int kShortBatchLength = 3;
737 737
738 // Pass in a positive offset and verify it triggers overuse. 738 // Pass in a positive offset and verify it triggers overuse.
739 bool overuse_detected = false; 739 bool overuse_detected = false;
740 for (int i = 0; i < kBatchLength; ++i) { 740 for (int i = 0; i < kBatchLength; ++i) {
741 BandwidthUsage overuse_state = 741 BandwidthUsage overuse_state =
742 overuse_detector_->Detect(kOffset, kTsDelta, num_deltas, now_ms); 742 overuse_detector_->Detect(kOffset, kTsDelta, num_deltas, now_ms);
743 if (overuse_state == kBwOverusing) { 743 if (overuse_state == BandwidthUsage::kBwOverusing) {
744 overuse_detected = true; 744 overuse_detected = true;
745 } 745 }
746 ++num_deltas; 746 ++num_deltas;
747 now_ms += 5; 747 now_ms += 5;
748 } 748 }
749 749
750 // Pass in a large offset. This shouldn't have a too big impact on the 750 // Pass in a large offset. This shouldn't have a too big impact on the
751 // threshold, but still trigger an overuse. 751 // threshold, but still trigger an overuse.
752 now_ms += 100; 752 now_ms += 100;
753 overuse_detected = false; 753 overuse_detected = false;
754 for (int i = 0; i < kShortBatchLength; ++i) { 754 for (int i = 0; i < kShortBatchLength; ++i) {
755 BandwidthUsage overuse_state = 755 BandwidthUsage overuse_state =
756 overuse_detector_->Detect(kLargeOffset, kTsDelta, num_deltas, now_ms); 756 overuse_detector_->Detect(kLargeOffset, kTsDelta, num_deltas, now_ms);
757 if (overuse_state == kBwOverusing) { 757 if (overuse_state == BandwidthUsage::kBwOverusing) {
758 overuse_detected = true; 758 overuse_detected = true;
759 } 759 }
760 ++num_deltas; 760 ++num_deltas;
761 now_ms += 5; 761 now_ms += 5;
762 } 762 }
763 EXPECT_TRUE(overuse_detected); 763 EXPECT_TRUE(overuse_detected);
764 764
765 // Pass in a positive normal offset and verify it still triggers. 765 // Pass in a positive normal offset and verify it still triggers.
766 overuse_detected = false; 766 overuse_detected = false;
767 for (int i = 0; i < kBatchLength; ++i) { 767 for (int i = 0; i < kBatchLength; ++i) {
768 BandwidthUsage overuse_state = 768 BandwidthUsage overuse_state =
769 overuse_detector_->Detect(kOffset, kTsDelta, num_deltas, now_ms); 769 overuse_detector_->Detect(kOffset, kTsDelta, num_deltas, now_ms);
770 if (overuse_state == kBwOverusing) { 770 if (overuse_state == BandwidthUsage::kBwOverusing) {
771 overuse_detected = true; 771 overuse_detected = true;
772 } 772 }
773 ++num_deltas; 773 ++num_deltas;
774 now_ms += 5; 774 now_ms += 5;
775 } 775 }
776 EXPECT_TRUE(overuse_detected); 776 EXPECT_TRUE(overuse_detected);
777 } 777 }
778 } // namespace testing 778 } // namespace testing
779 } // namespace webrtc 779 } // namespace webrtc
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698