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

Side by Side Diff: content/test/data/media/webrtc_test_utilities.js

Issue 1132333006: Try switching black frame algorithm to a luma-based algorithm. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 7 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 | « content/browser/media/webrtc_browsertest.cc ('k') | 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 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 // These must match with how the video and canvas tags are declared in html. 5 // These must match with how the video and canvas tags are declared in html.
6 const VIDEO_TAG_WIDTH = 320; 6 const VIDEO_TAG_WIDTH = 320;
7 const VIDEO_TAG_HEIGHT = 240; 7 const VIDEO_TAG_HEIGHT = 240;
8 8
9 // Fake video capture background green is of value 135. 9 // Fake video capture background green is of value 135.
10 const COLOR_BACKGROUND_GREEN = 135; 10 const COLOR_BACKGROUND_GREEN = 135;
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
59 }, 59 },
60 callback); 60 callback);
61 } 61 }
62 62
63 function detectVideo(videoElementName, predicate, callback) { 63 function detectVideo(videoElementName, predicate, callback) {
64 console.log('Looking at video in element ' + videoElementName); 64 console.log('Looking at video in element ' + videoElementName);
65 65
66 var width = VIDEO_TAG_WIDTH; 66 var width = VIDEO_TAG_WIDTH;
67 var height = VIDEO_TAG_HEIGHT; 67 var height = VIDEO_TAG_HEIGHT;
68 var videoElement = $(videoElementName); 68 var videoElement = $(videoElementName);
69 var canvas = $(videoElementName + '-canvas');
70 var oldPixels = []; 69 var oldPixels = [];
70 var startTimeMs = new Date().getTime();
71 var waitVideo = setInterval(function() { 71 var waitVideo = setInterval(function() {
72 var canvas = $(videoElementName + '-canvas');
73 if (canvas == null) {
74 console.log('Waiting for ' + videoElementName + '-canvas' + ' to appear');
75 return;
76 }
72 var context = canvas.getContext('2d'); 77 var context = canvas.getContext('2d');
73 context.drawImage(videoElement, 0, 0, width, height); 78 context.drawImage(videoElement, 0, 0, width, height);
74 var pixels = context.getImageData(0, 0 , width, height / 3).data; 79 var pixels = context.getImageData(0, 0 , width, height / 3).data;
75 // Check that there is an old and a new picture with the same size to 80 // Check that there is an old and a new picture with the same size to
76 // compare and use the function |predicate| to detect the video state in 81 // compare and use the function |predicate| to detect the video state in
77 // that case. 82 // that case.
78 if (oldPixels.length == pixels.length && 83 if (oldPixels.length == pixels.length &&
79 predicate(pixels, oldPixels)) { 84 predicate(pixels, oldPixels)) {
80 console.log('Done looking at video in element ' + videoElementName); 85 console.log('Done looking at video in element ' + videoElementName);
81 clearInterval(waitVideo); 86 clearInterval(waitVideo);
82 callback(videoElement.videoWidth, videoElement.videoHeight); 87 callback(videoElement.videoWidth, videoElement.videoHeight);
83 } 88 }
84 oldPixels = pixels; 89 oldPixels = pixels;
90 var elapsedTime = new Date().getTime() - startTimeMs;
91 if (elapsedTime > 3000) {
92 startTimeMs = new Date().getTime();
93 console.log('Still waiting for video to satisfy ' + predicate.toString());
94 }
85 }, 200); 95 }, 200);
86 } 96 }
87 97
88 function waitForVideoWithResolution(element, expected_width, expected_height) { 98 function waitForVideoWithResolution(element, expected_width, expected_height) {
89 addExpectedEvent(); 99 addExpectedEvent();
90 detectVideoPlaying(element, 100 detectVideoPlaying(element,
91 function (width, height) { 101 function (width, height) {
92 assertEquals(expected_width, width); 102 assertEquals(expected_width, width);
93 assertEquals(expected_height, height); 103 assertEquals(expected_height, height);
94 eventOccured(); 104 eventOccured();
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after
180 function isVideoPlaying(pixels, previousPixels) { 190 function isVideoPlaying(pixels, previousPixels) {
181 for (var i = 0; i < pixels.length; i++) { 191 for (var i = 0; i < pixels.length; i++) {
182 if (pixels[i] != previousPixels[i]) { 192 if (pixels[i] != previousPixels[i]) {
183 return true; 193 return true;
184 } 194 }
185 } 195 }
186 return false; 196 return false;
187 } 197 }
188 198
189 function isVideoBlack(pixels) { 199 function isVideoBlack(pixels) {
190 for (var i = 0; i < pixels.length; i++) { 200 var threshold = 20;
201 var accumulatedLuma = 0;
202 for (var i = 4; i < pixels.length; i += 4) {
191 // |pixels| is in RGBA. Ignore the alpha channel. 203 // |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
192 // We allow it to be off by 1, to account for rounding errors in YUV 204 accumulatedLuma += rec702Luma_(pixels[i], pixels[i + 1], pixels[i + 2]);
193 // conversion. 205 if (accumulatedLuma > threshold * i / 4)
194 if (pixels[i] != 0 && pixels[i] != 1 && (i + 1) % 4 != 0) {
195 return false; 206 return false;
196 }
197 } 207 }
198 return true; 208 return true;
199 } 209 }
200 210
211 function rec702Luma_(r, g, b) {
212 // 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.
213 return 0.2126 * r + 0.7152 * g + 0.0722 * b;
214 }
215
201 // This function matches |left| and |right| and fails the test if the 216 // This function matches |left| and |right| and fails the test if the
202 // values don't match using normal javascript equality (i.e. the hard 217 // values don't match using normal javascript equality (i.e. the hard
203 // types of the operands aren't checked). 218 // types of the operands aren't checked).
204 function assertEquals(expected, actual) { 219 function assertEquals(expected, actual) {
205 if (actual != expected) { 220 if (actual != expected) {
206 failTest("expected '" + expected + "', got '" + actual + "'."); 221 failTest("expected '" + expected + "', got '" + actual + "'.");
207 } 222 }
208 } 223 }
209 224
210 function assertNotEquals(expected, actual) { 225 function assertNotEquals(expected, actual) {
(...skipping 11 matching lines...) Expand all
222 if (device.kind == 'video') 237 if (device.kind == 'video')
223 hasVideoInputDevice = true; 238 hasVideoInputDevice = true;
224 }); 239 });
225 240
226 if (hasVideoInputDevice) 241 if (hasVideoInputDevice)
227 sendValueToTest('has-video-input-device'); 242 sendValueToTest('has-video-input-device');
228 else 243 else
229 sendValueToTest('no-video-input-devices'); 244 sendValueToTest('no-video-input-devices');
230 }); 245 });
231 } 246 }
OLDNEW
« no previous file with comments | « content/browser/media/webrtc_browsertest.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698