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

Side by Side Diff: content/test/data/media/getusermedia.html

Issue 638423002: Massively speed up aspect ratio-detecting WebRTC tests. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 6 years, 2 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
« no previous file with comments | « no previous file | 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 <html> 1 <html>
2 <head> 2 <head>
3 <script type="text/javascript" src="webrtc_test_utilities.js"></script> 3 <script type="text/javascript" src="webrtc_test_utilities.js"></script>
4 <script type="text/javascript"> 4 <script type="text/javascript">
5 $ = function(id) { 5 $ = function(id) {
6 return document.getElementById(id); 6 return document.getElementById(id);
7 }; 7 };
8 8
9 setAllEventsOccuredHandler(function() { 9 setAllEventsOccuredHandler(function() {
10 reportTestSuccess(); 10 reportTestSuccess();
(...skipping 375 matching lines...) Expand 10 before | Expand all | Expand 10 after
386 // pixels are not the same along the X and Y axis. 386 // pixels are not the same along the X and Y axis.
387 // The result of the analysis is sent back to the test as a string on the 387 // The result of the analysis is sent back to the test as a string on the
388 // format "w=xxx:h=yyy". 388 // format "w=xxx:h=yyy".
389 function detectAspectRatio(callback, videoElementName) { 389 function detectAspectRatio(callback, videoElementName) {
390 var videoElement = $(videoElementName); 390 var videoElement = $(videoElementName);
391 var canvas = $(videoElementName + '-canvas'); 391 var canvas = $(videoElementName + '-canvas');
392 392
393 var maxLightGreenPixelsX = 0; 393 var maxLightGreenPixelsX = 0;
394 var maxLightGreenPixelsY = 0; 394 var maxLightGreenPixelsY = 0;
395 395
396 var iterations = 0; 396 var attempt = 0;
397 var maxIterations = 10; 397 var maxAttempts = 10;
398 398
399 var detectorFunction = function() { 399 var detectorFunction = function() {
400 var width = videoElement.videoWidth; 400 var width = videoElement.videoWidth;
401 var height = videoElement.videoHeight; 401 var height = videoElement.videoHeight;
402 if (width == 0 || height == 0) 402 if (width == 0 || height == 0)
403 return; 403 return;
404 404
405 canvas.width = width; 405 canvas.width = width;
406 canvas.height = height; 406 canvas.height = height;
407 var aperture = Math.min(width, height) / 2; 407 var aperture = Math.min(width, height) / 2;
(...skipping 16 matching lines...) Expand all
424 // Walk vertically counting light green pixels. 424 // Walk vertically counting light green pixels.
425 for (var y = 0; y < aperture; ++y) { 425 for (var y = 0; y < aperture; ++y) {
426 if (pixels.data[4 * y * aperture + 1] != COLOR_BACKGROUND_GREEN) 426 if (pixels.data[4 * y * aperture + 1] != COLOR_BACKGROUND_GREEN)
427 lightGreenPixelsY++; 427 lightGreenPixelsY++;
428 } 428 }
429 if (lightGreenPixelsX > maxLightGreenPixelsX) 429 if (lightGreenPixelsX > maxLightGreenPixelsX)
430 maxLightGreenPixelsX = lightGreenPixelsX; 430 maxLightGreenPixelsX = lightGreenPixelsX;
431 if (lightGreenPixelsY > maxLightGreenPixelsY) 431 if (lightGreenPixelsY > maxLightGreenPixelsY)
432 maxLightGreenPixelsY = lightGreenPixelsY; 432 maxLightGreenPixelsY = lightGreenPixelsY;
433 433
434 if (++iterations > maxIterations) { 434 // Allow maxLightGreenPixelsY = maxLightGreenPixelsX +-1 due to
435 clearInterval(detectorInterval); 435 // possible subpixel rendering on Mac and Android.
perkj_chrome 2014/10/09 14:43:22 I think you should clear the interval even if the
phoglund_chromium 2014/10/09 15:04:37 Done.
436 // Allow maxLightGreenPixelsY = maxLightGreenPixelsX +-1 due to 436 if (maxLightGreenPixelsY > maxLightGreenPixelsX + 1 ||
437 // possible subpixel rendering on Mac and Android. 437 maxLightGreenPixelsY < maxLightGreenPixelsX -1 ||
438 if (maxLightGreenPixelsY > maxLightGreenPixelsX + 1 || 438 maxLightGreenPixelsY == 0 ||
439 maxLightGreenPixelsY < maxLightGreenPixelsX -1 || 439 maxLightGreenPixelsX == width / 2 ||
440 maxLightGreenPixelsY == 0 || 440 maxLightGreenPixelsY == height / 2) {
441 maxLightGreenPixelsX == width / 2 || 441 if (++attempt > maxAttempts) {
442 maxLightGreenPixelsY == height / 2) {
443 failTest("Aspect ratio corrupted. X " + maxLightGreenPixelsX + 442 failTest("Aspect ratio corrupted. X " + maxLightGreenPixelsX +
444 " Y " + maxLightGreenPixelsY); 443 " Y " + maxLightGreenPixelsY);
445 } 444 }
445 else {
446 // We have a bad aspect ratio now; give a chance to shape up.
447 return;
448 }
449 }
446 450
447 var result = "w=" + width + ":h=" + height; 451 clearInterval(detectorInterval);
448 console.log(result); 452 var result = "w=" + width + ":h=" + height;
449 callback(result); 453 callback(result);
450 }
451 } 454 }
452 var detectorInterval = setInterval(detectorFunction, 50); 455 var detectorInterval = setInterval(detectorFunction, 50);
453 } 456 }
454 </script> 457 </script>
455 </head> 458 </head>
456 <body> 459 <body>
457 <table border="0"> 460 <table border="0">
458 <!-- Canvases are named after their corresponding video elements. --> 461 <!-- Canvases are named after their corresponding video elements. -->
459 <tr> 462 <tr>
460 <td><video id="local-view-1" width="320" height="240" autoplay 463 <td><video id="local-view-1" width="320" height="240" autoplay
461 style="display:none"></video></td> 464 style="display:none"></video></td>
462 <td><canvas id="local-view-1-canvas" width="320" height="240" 465 <td><canvas id="local-view-1-canvas" width="320" height="240"
463 style="display:none"></canvas></td> 466 style="display:none"></canvas></td>
464 </tr> 467 </tr>
465 <tr> 468 <tr>
466 <td><video id="local-view-2" width="320" height="240" autoplay 469 <td><video id="local-view-2" width="320" height="240" autoplay
467 style="display:none"></video></td> 470 style="display:none"></video></td>
468 <td><canvas id="local-view-2-canvas" width="320" height="240" 471 <td><canvas id="local-view-2-canvas" width="320" height="240"
469 style="display:none"></canvas></td> 472 style="display:none"></canvas></td>
470 </tr> 473 </tr>
471 </table> 474 </table>
472 </body> 475 </body>
473 </html> 476 </html>
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698