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

Side by Side Diff: media/capture/content/video_capture_oracle_unittest.cc

Issue 2518143004: [Mojo Video Capture] Replace RESOURCE_UTILIZATION with interface ReceiverLoadObserver (Closed)
Patch Set: Fix for android-only code Created 4 years 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 // Copyright (c) 2015 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2015 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "media/capture/content/video_capture_oracle.h" 5 #include "media/capture/content/video_capture_oracle.h"
6 6
7 #include "base/strings/stringprintf.h" 7 #include "base/strings/stringprintf.h"
8 #include "testing/gtest/include/gtest/gtest.h" 8 #include "testing/gtest/include/gtest/gtest.h"
9 9
10 namespace media { 10 namespace media {
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after
76 76
77 // Most basic scenario: Frames delivered one at a time, with no additional 77 // Most basic scenario: Frames delivered one at a time, with no additional
78 // captures in-between deliveries. 78 // captures in-between deliveries.
79 base::TimeTicks t = InitialTestTimeTicks(); 79 base::TimeTicks t = InitialTestTimeTicks();
80 int last_frame_number; 80 int last_frame_number;
81 base::TimeTicks ignored; 81 base::TimeTicks ignored;
82 for (int i = 0; i < 10; ++i) { 82 for (int i = 0; i < 10; ++i) {
83 t += event_increment; 83 t += event_increment;
84 ASSERT_TRUE(oracle.ObserveEventAndDecideCapture( 84 ASSERT_TRUE(oracle.ObserveEventAndDecideCapture(
85 VideoCaptureOracle::kCompositorUpdate, damage_rect, t)); 85 VideoCaptureOracle::kCompositorUpdate, damage_rect, t));
86 last_frame_number = oracle.RecordCapture(0.0); 86 last_frame_number = oracle.next_frame_number();
87 oracle.RecordCapture(0.0);
87 ASSERT_TRUE(oracle.CompleteCapture(last_frame_number, true, &ignored)); 88 ASSERT_TRUE(oracle.CompleteCapture(last_frame_number, true, &ignored));
88 } 89 }
89 90
90 // Basic pipelined scenario: More than one frame in-flight at delivery points. 91 // Basic pipelined scenario: More than one frame in-flight at delivery points.
91 for (int i = 0; i < 50; ++i) { 92 for (int i = 0; i < 50; ++i) {
92 const int num_in_flight = 1 + i % 3; 93 const int num_in_flight = 1 + i % 3;
93 for (int j = 0; j < num_in_flight; ++j) { 94 for (int j = 0; j < num_in_flight; ++j) {
94 t += event_increment; 95 t += event_increment;
95 ASSERT_TRUE(oracle.ObserveEventAndDecideCapture( 96 ASSERT_TRUE(oracle.ObserveEventAndDecideCapture(
96 VideoCaptureOracle::kCompositorUpdate, damage_rect, t)); 97 VideoCaptureOracle::kCompositorUpdate, damage_rect, t));
97 last_frame_number = oracle.RecordCapture(0.0); 98 last_frame_number = oracle.next_frame_number();
99 oracle.RecordCapture(0.0);
98 } 100 }
99 for (int j = num_in_flight - 1; j >= 0; --j) { 101 for (int j = num_in_flight - 1; j >= 0; --j) {
100 ASSERT_TRUE( 102 ASSERT_TRUE(
101 oracle.CompleteCapture(last_frame_number - j, true, &ignored)); 103 oracle.CompleteCapture(last_frame_number - j, true, &ignored));
102 } 104 }
103 } 105 }
104 106
105 // Pipelined scenario with successful out-of-order delivery attempts 107 // Pipelined scenario with successful out-of-order delivery attempts
106 // rejected. 108 // rejected.
107 for (int i = 0; i < 50; ++i) { 109 for (int i = 0; i < 50; ++i) {
108 const int num_in_flight = 1 + i % 3; 110 const int num_in_flight = 1 + i % 3;
109 for (int j = 0; j < num_in_flight; ++j) { 111 for (int j = 0; j < num_in_flight; ++j) {
110 t += event_increment; 112 t += event_increment;
111 ASSERT_TRUE(oracle.ObserveEventAndDecideCapture( 113 ASSERT_TRUE(oracle.ObserveEventAndDecideCapture(
112 VideoCaptureOracle::kCompositorUpdate, damage_rect, t)); 114 VideoCaptureOracle::kCompositorUpdate, damage_rect, t));
113 last_frame_number = oracle.RecordCapture(0.0); 115 last_frame_number = oracle.next_frame_number();
116 oracle.RecordCapture(0.0);
114 } 117 }
115 ASSERT_TRUE(oracle.CompleteCapture(last_frame_number, true, &ignored)); 118 ASSERT_TRUE(oracle.CompleteCapture(last_frame_number, true, &ignored));
116 for (int j = 1; j < num_in_flight; ++j) { 119 for (int j = 1; j < num_in_flight; ++j) {
117 ASSERT_FALSE( 120 ASSERT_FALSE(
118 oracle.CompleteCapture(last_frame_number - j, true, &ignored)); 121 oracle.CompleteCapture(last_frame_number - j, true, &ignored));
119 } 122 }
120 } 123 }
121 124
122 // Pipelined scenario with successful delivery attempts accepted after an 125 // Pipelined scenario with successful delivery attempts accepted after an
123 // unsuccessful out of order delivery attempt. 126 // unsuccessful out of order delivery attempt.
124 for (int i = 0; i < 50; ++i) { 127 for (int i = 0; i < 50; ++i) {
125 const int num_in_flight = 1 + i % 3; 128 const int num_in_flight = 1 + i % 3;
126 for (int j = 0; j < num_in_flight; ++j) { 129 for (int j = 0; j < num_in_flight; ++j) {
127 t += event_increment; 130 t += event_increment;
128 ASSERT_TRUE(oracle.ObserveEventAndDecideCapture( 131 ASSERT_TRUE(oracle.ObserveEventAndDecideCapture(
129 VideoCaptureOracle::kCompositorUpdate, damage_rect, t)); 132 VideoCaptureOracle::kCompositorUpdate, damage_rect, t));
130 last_frame_number = oracle.RecordCapture(0.0); 133 last_frame_number = oracle.next_frame_number();
134 oracle.RecordCapture(0.0);
131 } 135 }
132 // Report the last frame as an out of order failure. 136 // Report the last frame as an out of order failure.
133 ASSERT_FALSE(oracle.CompleteCapture(last_frame_number, false, &ignored)); 137 ASSERT_FALSE(oracle.CompleteCapture(last_frame_number, false, &ignored));
134 for (int j = 1; j < num_in_flight - 1; ++j) { 138 for (int j = 1; j < num_in_flight - 1; ++j) {
135 ASSERT_TRUE( 139 ASSERT_TRUE(
136 oracle.CompleteCapture(last_frame_number - j, true, &ignored)); 140 oracle.CompleteCapture(last_frame_number - j, true, &ignored));
137 } 141 }
138 } 142 }
139 } 143 }
140 144
(...skipping 30 matching lines...) Expand all
171 provide_animated_content_event ? animation_damage_rect : gfx::Rect(), 175 provide_animated_content_event ? animation_damage_rect : gfx::Rect(),
172 t); 176 t);
173 if (require_oracle_says_sample) 177 if (require_oracle_says_sample)
174 ASSERT_TRUE(oracle_says_sample); 178 ASSERT_TRUE(oracle_says_sample);
175 if (!oracle_says_sample) { 179 if (!oracle_says_sample) {
176 ASSERT_EQ(base::TimeDelta(), oracle.estimated_frame_duration()); 180 ASSERT_EQ(base::TimeDelta(), oracle.estimated_frame_duration());
177 continue; 181 continue;
178 } 182 }
179 ASSERT_LT(base::TimeDelta(), oracle.estimated_frame_duration()); 183 ASSERT_LT(base::TimeDelta(), oracle.estimated_frame_duration());
180 184
181 const int frame_number = oracle.RecordCapture(0.0); 185 const int frame_number = oracle.next_frame_number();
186 oracle.RecordCapture(0.0);
182 187
183 base::TimeTicks frame_timestamp; 188 base::TimeTicks frame_timestamp;
184 ASSERT_TRUE(oracle.CompleteCapture(frame_number, true, &frame_timestamp)); 189 ASSERT_TRUE(oracle.CompleteCapture(frame_number, true, &frame_timestamp));
185 ASSERT_FALSE(frame_timestamp.is_null()); 190 ASSERT_FALSE(frame_timestamp.is_null());
186 if (!last_frame_timestamp.is_null()) { 191 if (!last_frame_timestamp.is_null()) {
187 const base::TimeDelta delta = frame_timestamp - last_frame_timestamp; 192 const base::TimeDelta delta = frame_timestamp - last_frame_timestamp;
188 EXPECT_LE(event_increment.InMicroseconds(), delta.InMicroseconds()); 193 EXPECT_LE(event_increment.InMicroseconds(), delta.InMicroseconds());
189 // Right after the AnimatedContentSampler lock-out transition, there were 194 // Right after the AnimatedContentSampler lock-out transition, there were
190 // a few frames dropped, so allow a gap in the timestamps. Otherwise, the 195 // a few frames dropped, so allow a gap in the timestamps. Otherwise, the
191 // delta between frame timestamps should never be more than 2X the 196 // delta between frame timestamps should never be more than 2X the
(...skipping 18 matching lines...) Expand all
210 215
211 // Have the oracle observe some compositor events. Simulate that each capture 216 // Have the oracle observe some compositor events. Simulate that each capture
212 // completes successfully. 217 // completes successfully.
213 base::TimeTicks t = InitialTestTimeTicks(); 218 base::TimeTicks t = InitialTestTimeTicks();
214 base::TimeTicks ignored; 219 base::TimeTicks ignored;
215 bool did_complete_a_capture = false; 220 bool did_complete_a_capture = false;
216 for (int i = 0; i < 10; ++i) { 221 for (int i = 0; i < 10; ++i) {
217 t += vsync_interval; 222 t += vsync_interval;
218 if (oracle.ObserveEventAndDecideCapture( 223 if (oracle.ObserveEventAndDecideCapture(
219 VideoCaptureOracle::kCompositorUpdate, gfx::Rect(), t)) { 224 VideoCaptureOracle::kCompositorUpdate, gfx::Rect(), t)) {
220 ASSERT_TRUE( 225 const int frame_number = oracle.next_frame_number();
221 oracle.CompleteCapture(oracle.RecordCapture(0.0), true, &ignored)); 226 oracle.RecordCapture(0.0);
227 ASSERT_TRUE(oracle.CompleteCapture(frame_number, true, &ignored));
222 did_complete_a_capture = true; 228 did_complete_a_capture = true;
223 } 229 }
224 } 230 }
225 ASSERT_TRUE(did_complete_a_capture); 231 ASSERT_TRUE(did_complete_a_capture);
226 232
227 // Start one more compositor-based capture, but do not notify of completion 233 // Start one more compositor-based capture, but do not notify of completion
228 // yet. 234 // yet.
229 for (int i = 0; i <= 10; ++i) { 235 for (int i = 0; i <= 10; ++i) {
230 ASSERT_GT(10, i) << "BUG: Seems like it'll never happen!"; 236 ASSERT_GT(10, i) << "BUG: Seems like it'll never happen!";
231 t += vsync_interval; 237 t += vsync_interval;
232 if (oracle.ObserveEventAndDecideCapture( 238 if (oracle.ObserveEventAndDecideCapture(
233 VideoCaptureOracle::kCompositorUpdate, gfx::Rect(), t)) { 239 VideoCaptureOracle::kCompositorUpdate, gfx::Rect(), t)) {
234 break; 240 break;
235 } 241 }
236 } 242 }
237 int frame_number = oracle.RecordCapture(0.0); 243 int frame_number = oracle.next_frame_number();
244 oracle.RecordCapture(0.0);
238 245
239 // Stop providing the compositor events and start providing refresh request 246 // Stop providing the compositor events and start providing refresh request
240 // events. No overdue samplings should be recommended because of the 247 // events. No overdue samplings should be recommended because of the
241 // not-yet-complete compositor-based capture. 248 // not-yet-complete compositor-based capture.
242 for (int i = 0; i < 10; ++i) { 249 for (int i = 0; i < 10; ++i) {
243 t += refresh_interval; 250 t += refresh_interval;
244 ASSERT_FALSE(oracle.ObserveEventAndDecideCapture( 251 ASSERT_FALSE(oracle.ObserveEventAndDecideCapture(
245 VideoCaptureOracle::kPassiveRefreshRequest, gfx::Rect(), t)); 252 VideoCaptureOracle::kPassiveRefreshRequest, gfx::Rect(), t));
246 } 253 }
247 254
248 // Now, complete the oustanding compositor-based capture and continue 255 // Now, complete the oustanding compositor-based capture and continue
249 // providing refresh request events. The oracle should start recommending 256 // providing refresh request events. The oracle should start recommending
250 // sampling again. 257 // sampling again.
251 ASSERT_TRUE(oracle.CompleteCapture(frame_number, true, &ignored)); 258 ASSERT_TRUE(oracle.CompleteCapture(frame_number, true, &ignored));
252 did_complete_a_capture = false; 259 did_complete_a_capture = false;
253 for (int i = 0; i < 10; ++i) { 260 for (int i = 0; i < 10; ++i) {
254 t += refresh_interval; 261 t += refresh_interval;
255 if (oracle.ObserveEventAndDecideCapture( 262 if (oracle.ObserveEventAndDecideCapture(
256 VideoCaptureOracle::kPassiveRefreshRequest, gfx::Rect(), t)) { 263 VideoCaptureOracle::kPassiveRefreshRequest, gfx::Rect(), t)) {
257 ASSERT_TRUE( 264 const int frame_number = oracle.next_frame_number();
258 oracle.CompleteCapture(oracle.RecordCapture(0.0), true, &ignored)); 265 oracle.RecordCapture(0.0);
266 ASSERT_TRUE(oracle.CompleteCapture(frame_number, true, &ignored));
259 did_complete_a_capture = true; 267 did_complete_a_capture = true;
260 } 268 }
261 } 269 }
262 ASSERT_TRUE(did_complete_a_capture); 270 ASSERT_TRUE(did_complete_a_capture);
263 271
264 // Start one more "refresh" capture, but do not notify of completion yet. 272 // Start one more "refresh" capture, but do not notify of completion yet.
265 for (int i = 0; i <= 10; ++i) { 273 for (int i = 0; i <= 10; ++i) {
266 ASSERT_GT(10, i) << "BUG: Seems like it'll never happen!"; 274 ASSERT_GT(10, i) << "BUG: Seems like it'll never happen!";
267 t += refresh_interval; 275 t += refresh_interval;
268 if (oracle.ObserveEventAndDecideCapture( 276 if (oracle.ObserveEventAndDecideCapture(
269 VideoCaptureOracle::kPassiveRefreshRequest, gfx::Rect(), t)) { 277 VideoCaptureOracle::kPassiveRefreshRequest, gfx::Rect(), t)) {
270 break; 278 break;
271 } 279 }
272 } 280 }
273 frame_number = oracle.RecordCapture(0.0); 281 frame_number = oracle.next_frame_number();
282 oracle.RecordCapture(0.0);
274 283
275 // Confirm that the oracle does not recommend sampling until the outstanding 284 // Confirm that the oracle does not recommend sampling until the outstanding
276 // "refresh" capture completes. 285 // "refresh" capture completes.
277 for (int i = 0; i < 10; ++i) { 286 for (int i = 0; i < 10; ++i) {
278 t += refresh_interval; 287 t += refresh_interval;
279 ASSERT_FALSE(oracle.ObserveEventAndDecideCapture( 288 ASSERT_FALSE(oracle.ObserveEventAndDecideCapture(
280 VideoCaptureOracle::kPassiveRefreshRequest, gfx::Rect(), t)); 289 VideoCaptureOracle::kPassiveRefreshRequest, gfx::Rect(), t));
281 } 290 }
282 ASSERT_TRUE(oracle.CompleteCapture(frame_number, true, &ignored)); 291 ASSERT_TRUE(oracle.CompleteCapture(frame_number, true, &ignored));
283 for (int i = 0; i <= 10; ++i) { 292 for (int i = 0; i <= 10; ++i) {
(...skipping 15 matching lines...) Expand all
299 308
300 // Run 30 seconds of frame captures without any source size changes. 309 // Run 30 seconds of frame captures without any source size changes.
301 base::TimeTicks t = InitialTestTimeTicks(); 310 base::TimeTicks t = InitialTestTimeTicks();
302 const base::TimeDelta event_increment = Get30HzPeriod() * 2; 311 const base::TimeDelta event_increment = Get30HzPeriod() * 2;
303 base::TimeTicks end_t = t + base::TimeDelta::FromSeconds(30); 312 base::TimeTicks end_t = t + base::TimeDelta::FromSeconds(30);
304 for (; t < end_t; t += event_increment) { 313 for (; t < end_t; t += event_increment) {
305 ASSERT_TRUE(oracle.ObserveEventAndDecideCapture( 314 ASSERT_TRUE(oracle.ObserveEventAndDecideCapture(
306 VideoCaptureOracle::kCompositorUpdate, gfx::Rect(), t)); 315 VideoCaptureOracle::kCompositorUpdate, gfx::Rect(), t));
307 ASSERT_EQ(Get720pSize(), oracle.capture_size()); 316 ASSERT_EQ(Get720pSize(), oracle.capture_size());
308 base::TimeTicks ignored; 317 base::TimeTicks ignored;
309 ASSERT_TRUE( 318 const int frame_number = oracle.next_frame_number();
310 oracle.CompleteCapture(oracle.RecordCapture(0.0), true, &ignored)); 319 oracle.RecordCapture(0.0);
320 ASSERT_TRUE(oracle.CompleteCapture(frame_number, true, &ignored));
311 } 321 }
312 322
313 // Now run 30 seconds of frame captures with lots of random source size 323 // Now run 30 seconds of frame captures with lots of random source size
314 // changes. Check that there was no more than one size change per second. 324 // changes. Check that there was no more than one size change per second.
315 gfx::Size source_size = oracle.capture_size(); 325 gfx::Size source_size = oracle.capture_size();
316 base::TimeTicks time_of_last_size_change = InitialTestTimeTicks(); 326 base::TimeTicks time_of_last_size_change = InitialTestTimeTicks();
317 gfx::Size last_capture_size = oracle.capture_size(); 327 gfx::Size last_capture_size = oracle.capture_size();
318 end_t = t + base::TimeDelta::FromSeconds(30); 328 end_t = t + base::TimeDelta::FromSeconds(30);
319 for (; t < end_t; t += event_increment) { 329 for (; t < end_t; t += event_increment) {
320 // Change the source size every frame to a random non-empty size. 330 // Change the source size every frame to a random non-empty size.
321 const gfx::Size last_source_size = source_size; 331 const gfx::Size last_source_size = source_size;
322 source_size.SetSize(((last_source_size.width() * 11 + 12345) % 1280) + 1, 332 source_size.SetSize(((last_source_size.width() * 11 + 12345) % 1280) + 1,
323 ((last_source_size.height() * 11 + 12345) % 720) + 1); 333 ((last_source_size.height() * 11 + 12345) % 720) + 1);
324 ASSERT_NE(last_source_size, source_size); 334 ASSERT_NE(last_source_size, source_size);
325 oracle.SetSourceSize(source_size); 335 oracle.SetSourceSize(source_size);
326 336
327 ASSERT_TRUE(oracle.ObserveEventAndDecideCapture( 337 ASSERT_TRUE(oracle.ObserveEventAndDecideCapture(
328 VideoCaptureOracle::kCompositorUpdate, gfx::Rect(), t)); 338 VideoCaptureOracle::kCompositorUpdate, gfx::Rect(), t));
329 339
330 if (oracle.capture_size() != last_capture_size) { 340 if (oracle.capture_size() != last_capture_size) {
331 ASSERT_GE(t - time_of_last_size_change, base::TimeDelta::FromSeconds(1)); 341 ASSERT_GE(t - time_of_last_size_change, base::TimeDelta::FromSeconds(1));
332 time_of_last_size_change = t; 342 time_of_last_size_change = t;
333 last_capture_size = oracle.capture_size(); 343 last_capture_size = oracle.capture_size();
334 } 344 }
335 345
336 base::TimeTicks ignored; 346 base::TimeTicks ignored;
337 ASSERT_TRUE( 347 const int frame_number = oracle.next_frame_number();
338 oracle.CompleteCapture(oracle.RecordCapture(0.0), true, &ignored)); 348 oracle.RecordCapture(0.0);
349 ASSERT_TRUE(oracle.CompleteCapture(frame_number, true, &ignored));
339 } 350 }
340 } 351 }
341 352
342 namespace { 353 namespace {
343 354
344 // Tests that VideoCaptureOracle can auto-throttle by stepping the capture size 355 // Tests that VideoCaptureOracle can auto-throttle by stepping the capture size
345 // up or down. When |is_content_animating| is false, there is more 356 // up or down. When |is_content_animating| is false, there is more
346 // aggressiveness expected in the timing of stepping upwards. If 357 // aggressiveness expected in the timing of stepping upwards. If
347 // |with_consumer_feedback| is false, only buffer pool utilization varies and no 358 // |with_consumer_feedback| is false, only buffer pool utilization varies and no
348 // consumer feedback is provided. If |with_consumer_feedback| is true, the 359 // consumer feedback is provided. If |with_consumer_feedback| is true, the
(...skipping 14 matching lines...) Expand all
363 base::TimeTicks t = InitialTestTimeTicks(); 374 base::TimeTicks t = InitialTestTimeTicks();
364 base::TimeTicks time_of_last_size_change = t; 375 base::TimeTicks time_of_last_size_change = t;
365 const base::TimeDelta event_increment = Get30HzPeriod() * 2; 376 const base::TimeDelta event_increment = Get30HzPeriod() * 2;
366 base::TimeTicks end_t = t + base::TimeDelta::FromSeconds(10); 377 base::TimeTicks end_t = t + base::TimeDelta::FromSeconds(10);
367 for (; t < end_t; t += event_increment) { 378 for (; t < end_t; t += event_increment) {
368 ASSERT_TRUE(oracle.ObserveEventAndDecideCapture( 379 ASSERT_TRUE(oracle.ObserveEventAndDecideCapture(
369 VideoCaptureOracle::kCompositorUpdate, 380 VideoCaptureOracle::kCompositorUpdate,
370 is_content_animating ? gfx::Rect(Get720pSize()) : gfx::Rect(), t)); 381 is_content_animating ? gfx::Rect(Get720pSize()) : gfx::Rect(), t));
371 ASSERT_EQ(Get720pSize(), oracle.capture_size()); 382 ASSERT_EQ(Get720pSize(), oracle.capture_size());
372 const double utilization = 0.9; 383 const double utilization = 0.9;
373 const int frame_number = 384 const int frame_number = oracle.next_frame_number();
374 oracle.RecordCapture(with_consumer_feedback ? 0.25 : utilization); 385 oracle.RecordCapture(with_consumer_feedback ? 0.25 : utilization);
375 base::TimeTicks ignored; 386 base::TimeTicks ignored;
376 ASSERT_TRUE(oracle.CompleteCapture(frame_number, true, &ignored)); 387 ASSERT_TRUE(oracle.CompleteCapture(frame_number, true, &ignored));
377 if (with_consumer_feedback) 388 if (with_consumer_feedback)
378 oracle.RecordConsumerFeedback(frame_number, utilization); 389 oracle.RecordConsumerFeedback(frame_number, utilization);
379 } 390 }
380 391
381 // Cause two downward steppings in resolution. First, indicate overload 392 // Cause two downward steppings in resolution. First, indicate overload
382 // until the resolution steps down. Then, indicate a 90% utilization and 393 // until the resolution steps down. Then, indicate a 90% utilization and
383 // expect the resolution to remain constant. Repeat. 394 // expect the resolution to remain constant. Repeat.
384 for (int i = 0; i < 2; ++i) { 395 for (int i = 0; i < 2; ++i) {
(...skipping 14 matching lines...) Expand all
399 time_of_last_size_change = t; 410 time_of_last_size_change = t;
400 stepped_down_size = oracle.capture_size(); 411 stepped_down_size = oracle.capture_size();
401 ASSERT_GT(starting_size.width(), stepped_down_size.width()); 412 ASSERT_GT(starting_size.width(), stepped_down_size.width());
402 ASSERT_GT(starting_size.height(), stepped_down_size.height()); 413 ASSERT_GT(starting_size.height(), stepped_down_size.height());
403 } 414 }
404 } else { 415 } else {
405 ASSERT_EQ(stepped_down_size, oracle.capture_size()); 416 ASSERT_EQ(stepped_down_size, oracle.capture_size());
406 } 417 }
407 418
408 const double utilization = stepped_down_size.IsEmpty() ? 1.5 : 0.9; 419 const double utilization = stepped_down_size.IsEmpty() ? 1.5 : 0.9;
409 const int frame_number = 420 const int frame_number = oracle.next_frame_number();
410 oracle.RecordCapture(with_consumer_feedback ? 0.25 : utilization); 421 oracle.RecordCapture(with_consumer_feedback ? 0.25 : utilization);
411 base::TimeTicks ignored; 422 base::TimeTicks ignored;
412 ASSERT_TRUE(oracle.CompleteCapture(frame_number, true, &ignored)); 423 ASSERT_TRUE(oracle.CompleteCapture(frame_number, true, &ignored));
413 if (with_consumer_feedback) 424 if (with_consumer_feedback)
414 oracle.RecordConsumerFeedback(frame_number, utilization); 425 oracle.RecordConsumerFeedback(frame_number, utilization);
415 } 426 }
416 } 427 }
417 428
418 // Now, cause two upward steppings in resolution. First, indicate 429 // Now, cause two upward steppings in resolution. First, indicate
419 // under-utilization until the resolution steps up. Then, indicate a 90% 430 // under-utilization until the resolution steps up. Then, indicate a 90%
420 // utilization and expect the resolution to remain constant. Repeat. 431 // utilization and expect the resolution to remain constant. Repeat.
(...skipping 19 matching lines...) Expand all
440 time_of_last_size_change = t; 451 time_of_last_size_change = t;
441 stepped_up_size = oracle.capture_size(); 452 stepped_up_size = oracle.capture_size();
442 ASSERT_LT(starting_size.width(), stepped_up_size.width()); 453 ASSERT_LT(starting_size.width(), stepped_up_size.width());
443 ASSERT_LT(starting_size.height(), stepped_up_size.height()); 454 ASSERT_LT(starting_size.height(), stepped_up_size.height());
444 } 455 }
445 } else { 456 } else {
446 ASSERT_EQ(stepped_up_size, oracle.capture_size()); 457 ASSERT_EQ(stepped_up_size, oracle.capture_size());
447 } 458 }
448 459
449 const double utilization = stepped_up_size.IsEmpty() ? 0.0 : 0.9; 460 const double utilization = stepped_up_size.IsEmpty() ? 0.0 : 0.9;
450 const int frame_number = 461 const int frame_number = oracle.next_frame_number();
451 oracle.RecordCapture(with_consumer_feedback ? 0.25 : utilization); 462 oracle.RecordCapture(with_consumer_feedback ? 0.25 : utilization);
452 base::TimeTicks ignored; 463 base::TimeTicks ignored;
453 ASSERT_TRUE(oracle.CompleteCapture(frame_number, true, &ignored)); 464 ASSERT_TRUE(oracle.CompleteCapture(frame_number, true, &ignored));
454 if (with_consumer_feedback) 465 if (with_consumer_feedback)
455 oracle.RecordConsumerFeedback(frame_number, utilization); 466 oracle.RecordConsumerFeedback(frame_number, utilization);
456 } 467 }
457 } 468 }
458 } 469 }
459 470
460 } // namespace 471 } // namespace
461 472
(...skipping 25 matching lines...) Expand all
487 base::TimeTicks t = InitialTestTimeTicks(); 498 base::TimeTicks t = InitialTestTimeTicks();
488 const base::TimeDelta event_increment = Get30HzPeriod() * 2; 499 const base::TimeDelta event_increment = Get30HzPeriod() * 2;
489 base::TimeTicks end_t = t + base::TimeDelta::FromSeconds(10); 500 base::TimeTicks end_t = t + base::TimeDelta::FromSeconds(10);
490 for (; t < end_t; t += event_increment) { 501 for (; t < end_t; t += event_increment) {
491 if (!oracle.ObserveEventAndDecideCapture( 502 if (!oracle.ObserveEventAndDecideCapture(
492 VideoCaptureOracle::kCompositorUpdate, gfx::Rect(Get360pSize()), 503 VideoCaptureOracle::kCompositorUpdate, gfx::Rect(Get360pSize()),
493 t)) { 504 t)) {
494 continue; 505 continue;
495 } 506 }
496 ASSERT_EQ(Get360pSize(), oracle.capture_size()); 507 ASSERT_EQ(Get360pSize(), oracle.capture_size());
497 const int frame_number = oracle.RecordCapture(0.25); 508 const int frame_number = oracle.next_frame_number();
509 oracle.RecordCapture(0.25);
498 base::TimeTicks ignored; 510 base::TimeTicks ignored;
499 ASSERT_TRUE(oracle.CompleteCapture(frame_number, true, &ignored)); 511 ASSERT_TRUE(oracle.CompleteCapture(frame_number, true, &ignored));
500 } 512 }
501 513
502 // Now, set the source size to 720p, continuing to report under-utilization, 514 // Now, set the source size to 720p, continuing to report under-utilization,
503 // and expect the capture size increases to reach a full 720p within 15 515 // and expect the capture size increases to reach a full 720p within 15
504 // seconds. 516 // seconds.
505 oracle.SetSourceSize(Get720pSize()); 517 oracle.SetSourceSize(Get720pSize());
506 gfx::Size last_capture_size = oracle.capture_size(); 518 gfx::Size last_capture_size = oracle.capture_size();
507 end_t = t + base::TimeDelta::FromSeconds(15); 519 end_t = t + base::TimeDelta::FromSeconds(15);
508 for (; t < end_t; t += event_increment) { 520 for (; t < end_t; t += event_increment) {
509 if (!oracle.ObserveEventAndDecideCapture( 521 if (!oracle.ObserveEventAndDecideCapture(
510 VideoCaptureOracle::kCompositorUpdate, gfx::Rect(Get720pSize()), 522 VideoCaptureOracle::kCompositorUpdate, gfx::Rect(Get720pSize()),
511 t)) { 523 t)) {
512 continue; 524 continue;
513 } 525 }
514 ASSERT_LE(last_capture_size.width(), oracle.capture_size().width()); 526 ASSERT_LE(last_capture_size.width(), oracle.capture_size().width());
515 ASSERT_LE(last_capture_size.height(), oracle.capture_size().height()); 527 ASSERT_LE(last_capture_size.height(), oracle.capture_size().height());
516 last_capture_size = oracle.capture_size(); 528 last_capture_size = oracle.capture_size();
517 const int frame_number = oracle.RecordCapture(0.25); 529 const int frame_number = oracle.next_frame_number();
530 oracle.RecordCapture(0.25);
518 base::TimeTicks ignored; 531 base::TimeTicks ignored;
519 ASSERT_TRUE(oracle.CompleteCapture(frame_number, true, &ignored)); 532 ASSERT_TRUE(oracle.CompleteCapture(frame_number, true, &ignored));
520 } 533 }
521 ASSERT_EQ(Get720pSize(), oracle.capture_size()); 534 ASSERT_EQ(Get720pSize(), oracle.capture_size());
522 535
523 // Now, change the source size again, but report over-utilization so the 536 // Now, change the source size again, but report over-utilization so the
524 // capture size will decrease. Once it decreases one step, report 90% 537 // capture size will decrease. Once it decreases one step, report 90%
525 // utilization to achieve a steady-state. 538 // utilization to achieve a steady-state.
526 oracle.SetSourceSize(Get1080pSize()); 539 oracle.SetSourceSize(Get1080pSize());
527 gfx::Size stepped_down_size; 540 gfx::Size stepped_down_size;
528 end_t = t + base::TimeDelta::FromSeconds(10); 541 end_t = t + base::TimeDelta::FromSeconds(10);
529 for (; t < end_t; t += event_increment) { 542 for (; t < end_t; t += event_increment) {
530 if (!oracle.ObserveEventAndDecideCapture( 543 if (!oracle.ObserveEventAndDecideCapture(
531 VideoCaptureOracle::kCompositorUpdate, gfx::Rect(Get1080pSize()), 544 VideoCaptureOracle::kCompositorUpdate, gfx::Rect(Get1080pSize()),
532 t)) { 545 t)) {
533 continue; 546 continue;
534 } 547 }
535 548
536 if (stepped_down_size.IsEmpty()) { 549 if (stepped_down_size.IsEmpty()) {
537 if (oracle.capture_size() != Get720pSize()) { 550 if (oracle.capture_size() != Get720pSize()) {
538 stepped_down_size = oracle.capture_size(); 551 stepped_down_size = oracle.capture_size();
539 ASSERT_GT(Get720pSize().width(), stepped_down_size.width()); 552 ASSERT_GT(Get720pSize().width(), stepped_down_size.width());
540 ASSERT_GT(Get720pSize().height(), stepped_down_size.height()); 553 ASSERT_GT(Get720pSize().height(), stepped_down_size.height());
541 } 554 }
542 } else { 555 } else {
543 ASSERT_EQ(stepped_down_size, oracle.capture_size()); 556 ASSERT_EQ(stepped_down_size, oracle.capture_size());
544 } 557 }
545 558
546 const double utilization = stepped_down_size.IsEmpty() ? 1.5 : 0.9; 559 const double utilization = stepped_down_size.IsEmpty() ? 1.5 : 0.9;
547 const int frame_number = oracle.RecordCapture(utilization); 560 const int frame_number = oracle.next_frame_number();
561 oracle.RecordCapture(utilization);
548 base::TimeTicks ignored; 562 base::TimeTicks ignored;
549 ASSERT_TRUE(oracle.CompleteCapture(frame_number, true, &ignored)); 563 ASSERT_TRUE(oracle.CompleteCapture(frame_number, true, &ignored));
550 } 564 }
551 ASSERT_FALSE(stepped_down_size.IsEmpty()); 565 ASSERT_FALSE(stepped_down_size.IsEmpty());
552 566
553 // Now, if we report under-utilization again (without any source size change), 567 // Now, if we report under-utilization again (without any source size change),
554 // there should be a long "proving period" before there is any increase in 568 // there should be a long "proving period" before there is any increase in
555 // capture size made by the oracle. 569 // capture size made by the oracle.
556 const base::TimeTicks proving_period_end_time = 570 const base::TimeTicks proving_period_end_time =
557 t + base::TimeDelta::FromSeconds(15); 571 t + base::TimeDelta::FromSeconds(15);
(...skipping 11 matching lines...) Expand all
569 ASSERT_LT(proving_period_end_time, t); 583 ASSERT_LT(proving_period_end_time, t);
570 stepped_up_size = oracle.capture_size(); 584 stepped_up_size = oracle.capture_size();
571 ASSERT_LT(stepped_down_size.width(), stepped_up_size.width()); 585 ASSERT_LT(stepped_down_size.width(), stepped_up_size.width());
572 ASSERT_LT(stepped_down_size.height(), stepped_up_size.height()); 586 ASSERT_LT(stepped_down_size.height(), stepped_up_size.height());
573 } 587 }
574 } else { 588 } else {
575 ASSERT_EQ(stepped_up_size, oracle.capture_size()); 589 ASSERT_EQ(stepped_up_size, oracle.capture_size());
576 } 590 }
577 591
578 const double utilization = stepped_up_size.IsEmpty() ? 0.25 : 0.9; 592 const double utilization = stepped_up_size.IsEmpty() ? 0.25 : 0.9;
579 const int frame_number = oracle.RecordCapture(utilization); 593 const int frame_number = oracle.next_frame_number();
594 oracle.RecordCapture(utilization);
580 base::TimeTicks ignored; 595 base::TimeTicks ignored;
581 ASSERT_TRUE(oracle.CompleteCapture(frame_number, true, &ignored)); 596 ASSERT_TRUE(oracle.CompleteCapture(frame_number, true, &ignored));
582 } 597 }
583 ASSERT_FALSE(stepped_up_size.IsEmpty()); 598 ASSERT_FALSE(stepped_up_size.IsEmpty());
584 } 599 }
585 600
586 // Tests that VideoCaptureOracle does not change the capture size if 601 // Tests that VideoCaptureOracle does not change the capture size if
587 // auto-throttling is enabled when using a fixed resolution policy. 602 // auto-throttling is enabled when using a fixed resolution policy.
588 TEST(VideoCaptureOracleTest, DoesNotAutoThrottleWhenResolutionIsFixed) { 603 TEST(VideoCaptureOracleTest, DoesNotAutoThrottleWhenResolutionIsFixed) {
589 VideoCaptureOracle oracle(Get30HzPeriod(), Get720pSize(), 604 VideoCaptureOracle oracle(Get30HzPeriod(), Get720pSize(),
590 media::RESOLUTION_POLICY_FIXED_RESOLUTION, true); 605 media::RESOLUTION_POLICY_FIXED_RESOLUTION, true);
591 606
592 // Run 10 seconds of frame captures with 90% utilization expect no capture 607 // Run 10 seconds of frame captures with 90% utilization expect no capture
593 // size changes. 608 // size changes.
594 base::TimeTicks t = InitialTestTimeTicks(); 609 base::TimeTicks t = InitialTestTimeTicks();
595 const base::TimeDelta event_increment = Get30HzPeriod() * 2; 610 const base::TimeDelta event_increment = Get30HzPeriod() * 2;
596 base::TimeTicks end_t = t + base::TimeDelta::FromSeconds(10); 611 base::TimeTicks end_t = t + base::TimeDelta::FromSeconds(10);
597 for (; t < end_t; t += event_increment) { 612 for (; t < end_t; t += event_increment) {
598 ASSERT_TRUE(oracle.ObserveEventAndDecideCapture( 613 ASSERT_TRUE(oracle.ObserveEventAndDecideCapture(
599 VideoCaptureOracle::kCompositorUpdate, gfx::Rect(), t)); 614 VideoCaptureOracle::kCompositorUpdate, gfx::Rect(), t));
600 ASSERT_EQ(Get720pSize(), oracle.capture_size()); 615 ASSERT_EQ(Get720pSize(), oracle.capture_size());
601 base::TimeTicks ignored; 616 base::TimeTicks ignored;
602 ASSERT_TRUE( 617 const int frame_number = oracle.next_frame_number();
603 oracle.CompleteCapture(oracle.RecordCapture(0.9), true, &ignored)); 618 oracle.RecordCapture(0.9);
619 ASSERT_TRUE(oracle.CompleteCapture(frame_number, true, &ignored));
604 } 620 }
605 621
606 // Now run 10 seconds with overload indicated. Still, expect no capture size 622 // Now run 10 seconds with overload indicated. Still, expect no capture size
607 // changes. 623 // changes.
608 end_t = t + base::TimeDelta::FromSeconds(10); 624 end_t = t + base::TimeDelta::FromSeconds(10);
609 for (; t < end_t; t += event_increment) { 625 for (; t < end_t; t += event_increment) {
610 ASSERT_TRUE(oracle.ObserveEventAndDecideCapture( 626 ASSERT_TRUE(oracle.ObserveEventAndDecideCapture(
611 VideoCaptureOracle::kCompositorUpdate, gfx::Rect(), t)); 627 VideoCaptureOracle::kCompositorUpdate, gfx::Rect(), t));
612 ASSERT_EQ(Get720pSize(), oracle.capture_size()); 628 ASSERT_EQ(Get720pSize(), oracle.capture_size());
613 base::TimeTicks ignored; 629 base::TimeTicks ignored;
614 ASSERT_TRUE( 630 const int frame_number = oracle.next_frame_number();
615 oracle.CompleteCapture(oracle.RecordCapture(2.0), true, &ignored)); 631 oracle.RecordCapture(2.0);
632 ASSERT_TRUE(oracle.CompleteCapture(frame_number, true, &ignored));
616 } 633 }
617 } 634 }
618 635
619 } // namespace media 636 } // namespace media
OLDNEW
« no previous file with comments | « media/capture/content/video_capture_oracle.cc ('k') | media/capture/video/fake_video_capture_device.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698