OLD | NEW |
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 370 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
381 // pixels are not the same along the X and Y axis. | 381 // pixels are not the same along the X and Y axis. |
382 // The result of the analysis is sent back to the test as a string on the | 382 // The result of the analysis is sent back to the test as a string on the |
383 // format "w=xxx:h=yyy". | 383 // format "w=xxx:h=yyy". |
384 function detectAspectRatio(callback, videoElementName) { | 384 function detectAspectRatio(callback, videoElementName) { |
385 var videoElement = $(videoElementName); | 385 var videoElement = $(videoElementName); |
386 var canvas = $(videoElementName + '-canvas'); | 386 var canvas = $(videoElementName + '-canvas'); |
387 | 387 |
388 var maxLightGreenPixelsX = 0; | 388 var maxLightGreenPixelsX = 0; |
389 var maxLightGreenPixelsY = 0; | 389 var maxLightGreenPixelsY = 0; |
390 | 390 |
391 // TODO(phoglund): don't iterate 10 times - too slow on Windows. | 391 var attempt = 0; |
392 var iterations = 0; | 392 var maxAttempts = 10; |
393 var maxIterations = 10; | |
394 | 393 |
395 var detectorFunction = function() { | 394 var detectorFunction = function() { |
396 var width = videoElement.videoWidth; | 395 var width = videoElement.videoWidth; |
397 var height = videoElement.videoHeight; | 396 var height = videoElement.videoHeight; |
398 if (width == 0 || height == 0) | 397 if (width == 0 || height == 0) |
399 return; | 398 return; |
400 | 399 |
401 canvas.width = width; | 400 canvas.width = width; |
402 canvas.height = height; | 401 canvas.height = height; |
403 var aperture = Math.min(width, height) / 2; | 402 var aperture = Math.min(width, height) / 2; |
(...skipping 16 matching lines...) Expand all Loading... |
420 // Walk vertically counting light green pixels. | 419 // Walk vertically counting light green pixels. |
421 for (var y = 0; y < aperture; ++y) { | 420 for (var y = 0; y < aperture; ++y) { |
422 if (pixels.data[4 * y * aperture + 1] != COLOR_BACKGROUND_GREEN) | 421 if (pixels.data[4 * y * aperture + 1] != COLOR_BACKGROUND_GREEN) |
423 lightGreenPixelsY++; | 422 lightGreenPixelsY++; |
424 } | 423 } |
425 if (lightGreenPixelsX > maxLightGreenPixelsX) | 424 if (lightGreenPixelsX > maxLightGreenPixelsX) |
426 maxLightGreenPixelsX = lightGreenPixelsX; | 425 maxLightGreenPixelsX = lightGreenPixelsX; |
427 if (lightGreenPixelsY > maxLightGreenPixelsY) | 426 if (lightGreenPixelsY > maxLightGreenPixelsY) |
428 maxLightGreenPixelsY = lightGreenPixelsY; | 427 maxLightGreenPixelsY = lightGreenPixelsY; |
429 | 428 |
430 if (++iterations > maxIterations) { | 429 // Allow maxLightGreenPixelsY = maxLightGreenPixelsX +-1 due to |
431 clearInterval(detectorInterval); | 430 // possible subpixel rendering on Mac and Android. |
432 // Allow maxLightGreenPixelsY = maxLightGreenPixelsX +-1 due to | 431 if (maxLightGreenPixelsY > maxLightGreenPixelsX + 1 || |
433 // possible subpixel rendering on Mac and Android. | 432 maxLightGreenPixelsY < maxLightGreenPixelsX -1 || |
434 if (maxLightGreenPixelsY > maxLightGreenPixelsX + 1 || | 433 maxLightGreenPixelsY == 0 || |
435 maxLightGreenPixelsY < maxLightGreenPixelsX -1 || | 434 maxLightGreenPixelsX == width / 2 || |
436 maxLightGreenPixelsY == 0 || | 435 maxLightGreenPixelsY == height / 2) { |
437 maxLightGreenPixelsX == width / 2 || | 436 if (++attempt > maxAttempts) { |
438 maxLightGreenPixelsY == height / 2) { | 437 clearInterval(detectorInterval); |
439 failTest("Aspect ratio corrupted. X " + maxLightGreenPixelsX + | 438 failTest("Aspect ratio corrupted. X " + maxLightGreenPixelsX + |
440 " Y " + maxLightGreenPixelsY); | 439 " Y " + maxLightGreenPixelsY); |
441 } | 440 } |
| 441 else { |
| 442 // We have a bad aspect ratio now; give a chance to shape up. |
| 443 return; |
| 444 } |
| 445 } |
442 | 446 |
443 var result = "w=" + width + ":h=" + height; | 447 clearInterval(detectorInterval); |
444 console.log(result); | 448 var result = "w=" + width + ":h=" + height; |
445 callback(result); | 449 callback(result); |
446 } | |
447 } | 450 } |
448 var detectorInterval = setInterval(detectorFunction, 50); | 451 var detectorInterval = setInterval(detectorFunction, 50); |
449 } | 452 } |
450 </script> | 453 </script> |
451 </head> | 454 </head> |
452 <body> | 455 <body> |
453 <table border="0"> | 456 <table border="0"> |
454 <!-- Canvases are named after their corresponding video elements. --> | 457 <!-- Canvases are named after their corresponding video elements. --> |
455 <tr> | 458 <tr> |
456 <td><video id="local-view-1" width="320" height="240" autoplay | 459 <td><video id="local-view-1" width="320" height="240" autoplay |
457 style="display:none"></video></td> | 460 style="display:none"></video></td> |
458 <td><canvas id="local-view-1-canvas" width="320" height="240" | 461 <td><canvas id="local-view-1-canvas" width="320" height="240" |
459 style="display:none"></canvas></td> | 462 style="display:none"></canvas></td> |
460 </tr> | 463 </tr> |
461 <tr> | 464 <tr> |
462 <td><video id="local-view-2" width="320" height="240" autoplay | 465 <td><video id="local-view-2" width="320" height="240" autoplay |
463 style="display:none"></video></td> | 466 style="display:none"></video></td> |
464 <td><canvas id="local-view-2-canvas" width="320" height="240" | 467 <td><canvas id="local-view-2-canvas" width="320" height="240" |
465 style="display:none"></canvas></td> | 468 style="display:none"></canvas></td> |
466 </tr> | 469 </tr> |
467 </table> | 470 </table> |
468 </body> | 471 </body> |
469 </html> | 472 </html> |
OLD | NEW |