Commit 859d9a26 authored by phoglund's avatar phoglund Committed by Commit bot

Try switching black frame algorithm to a luma-based algorithm.

Sheriffs: if WebRtcBrowserTest.CanSetupVideoCallAndDisableLocalVideo
flakes, revert this patch. It shouldn't flake after this fix.

Instead of looking at color values of individual pixels, see if we can
get more reliable results by looking at luma values instead. This way
we can detect black frames more reliably in the tests.

This is a partial re-land of codereview.chromium.org/1108803002.

This is essentially the black frame algorithm used in testrtc.

BUG=477498

Review URL: https://codereview.chromium.org/1132333006

Cr-Commit-Position: refs/heads/master@{#330539}
parent 87e0b313
......@@ -144,9 +144,15 @@ IN_PROC_BROWSER_TEST_F(MAYBE_WebRtcBrowserTest,
}
// Flaky on TSAN v2. http://crbug.com/408006
// Flaky everywhere: http://crbug.com/477498
#if defined(THREAD_SANITIZER)
#define MAYBE_CanSetupVideoCallAndDisableLocalVideo \
DISABLED_CanSetupVideoCallAndDisableLocalVideo
#else
#define MAYBE_CanSetupVideoCallAndDisableLocalVideo \
CanSetupVideoCallAndDisableLocalVideo
#endif
IN_PROC_BROWSER_TEST_F(MAYBE_WebRtcBrowserTest,
DISABLED_CanSetupVideoCallAndDisableLocalVideo) {
MAYBE_CanSetupVideoCallAndDisableLocalVideo) {
const std::string javascript =
"callAndDisableLocalVideo({video: true});";
MakeTypicalPeerConnectionCall(javascript);
......
......@@ -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);
}
......@@ -186,18 +196,26 @@ function isVideoPlaying(pixels, previousPixels) {
return false;
}
// Checks if the frame is black. |pixels| is in RGBA (i.e. pixels[0] is the R
// value for the first pixel).
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) {
var threshold = 20;
var accumulatedLuma = 0;
for (var i = 0; i < pixels.length; i += 4) {
// Ignore the alpha channel.
accumulatedLuma += rec702Luma_(pixels[i], pixels[i + 1], pixels[i + 2]);
if (accumulatedLuma > threshold * (i / 4 + 1))
return false;
}
}
return true;
}
// Use Luma as in Rec. 709: Y′709 = 0.2126R + 0.7152G + 0.0722B;
// See http://en.wikipedia.org/wiki/Rec._709.
function rec702Luma_(r, g, b) {
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).
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment