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..8f5f5c01a60ff72ec271209683a85dc3c8dbf9fe 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,11 @@ 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); |
} |
@@ -187,17 +197,22 @@ function isVideoPlaying(pixels, previousPixels) { |
} |
function isVideoBlack(pixels) { |
- for (var i = 0; i < pixels.length; i++) { |
+ var threshold = 20; |
+ var accumulatedLuma = 0; |
+ for (var i = 4; i < pixels.length; i += 4) { |
// |pixels| is in RGBA. Ignore the alpha channel. |
kjellander_chromium
2015/05/19 09:10:01
I'm still missing the explanation on why we ignore
phoglund_chromium
2015/05/19 09:37:08
Oh sorry, I misread your comment and thought you w
kjellander_chromium
2015/05/19 10:06:22
Hmm, it sounds a bit risky to just assume that's a
|
- // 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) { |
+ accumulatedLuma += rec702Luma_(pixels[i], pixels[i + 1], pixels[i + 2]); |
+ if (accumulatedLuma > threshold * i / 4) |
return false; |
- } |
} |
return true; |
} |
+function rec702Luma_(r, g, b) { |
+ // Use Luma as in Rec. 709: Y′709 = 0.2126R + 0.7152G + 0.0722B; |
kjellander_chromium
2015/05/19 09:10:01
Can you move this up to be function documentation
phoglund_chromium
2015/05/19 09:37:08
Done.
|
+ return 0.2126 * r + 0.7152 * g + 0.0722 * b; |
+} |
+ |
// This function matches |left| and |right| and fails the test if the |
// values don't match using normal javascript equality (i.e. the hard |
// types of the operands aren't checked). |