Chromium Code Reviews| Index: content/test/data/media/webrtc_test_utilities.js |
| diff --git a/content/test/data/media/webrtc_test_utilities.js b/content/test/data/media/webrtc_test_utilities.js |
| index 5fd38113882b7c6bf7f9db219850291da9e4d2c6..88fe4b2926dd33cd3c8ea58de24c0f3d3f4e4810 100644 |
| --- a/content/test/data/media/webrtc_test_utilities.js |
| +++ b/content/test/data/media/webrtc_test_utilities.js |
| @@ -66,9 +66,14 @@ function detectVideo(videoElementName, predicate, callback) { |
| var width = VIDEO_TAG_WIDTH; |
| var height = VIDEO_TAG_HEIGHT; |
| var videoElement = $(videoElementName); |
| - var canvas = $(videoElementName + '-canvas'); |
| var oldPixels = []; |
| + var startTimeMs = new Date().getTime(); |
| var waitVideo = setInterval(function() { |
| + var canvas = $(videoElementName + '-canvas'); |
| + if (canvas == null) { |
| + console.log('Waiting for ' + videoElementName + '-canvas' + ' to appear'); |
| + return; |
| + } |
| var context = canvas.getContext('2d'); |
| context.drawImage(videoElement, 0, 0, width, height); |
| var pixels = context.getImageData(0, 0 , width, height / 3).data; |
| @@ -82,6 +87,12 @@ function detectVideo(videoElementName, predicate, callback) { |
| callback(videoElement.videoWidth, videoElement.videoHeight); |
| } |
| oldPixels = pixels; |
| + |
| + var elapsedTime = new Date().getTime() - startTimeMs; |
| + if (elapsedTime > 3000) { |
| + startTimeMs = new Date().getTime(); |
| + console.log('Still waiting for video to satisfy ' + predicate.toString()); |
| + } |
| }, 200); |
| } |
| @@ -186,12 +197,18 @@ function isVideoPlaying(pixels, previousPixels) { |
| return false; |
| } |
| +// Pixels is an array where pixels[0] is the R value for the first pixel, |
| +// pixels[1] is the G value, and so on. |
| function isVideoBlack(pixels) { |
| for (var i = 0; i < pixels.length; i++) { |
| - // |pixels| is in RGBA. Ignore the alpha channel. |
| - // We allow it to be off by 1, to account for rounding errors in YUV |
| - // conversion. |
| - if (pixels[i] != 0 && pixels[i] != 1 && (i + 1) % 4 != 0) { |
| + if ((i + 1) % 4 == 0) { |
| + // Ignore the alpha channel. |
| + continue; |
| + } |
| + |
| + // Should be == 0, but account for rounding errors in YUV conversion. |
|
kjellander_chromium
2015/05/12 13:35:46
Clarify in the comment that a black pixel is == 0.
phoglund_chromium
2015/05/13 08:47:35
Done.
|
| + if (pixels[i] > 3) { |
| + console.log('Found nonblack pixel at ' + i + ', was ' + pixels[i]); |
| return false; |
| } |
| } |