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

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

Issue 1108803002: Re-enable local video test with better logging and higher tolerance. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Addressed comment 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
91 var elapsedTime = new Date().getTime() - startTimeMs;
92 if (elapsedTime > 3000) {
93 startTimeMs = new Date().getTime();
94 console.log('Still waiting for video to satisfy ' + predicate.toString());
95 }
85 }, 200); 96 }, 200);
86 } 97 }
87 98
88 function waitForVideoWithResolution(element, expected_width, expected_height) { 99 function waitForVideoWithResolution(element, expected_width, expected_height) {
89 addExpectedEvent(); 100 addExpectedEvent();
90 detectVideoPlaying(element, 101 detectVideoPlaying(element,
91 function (width, height) { 102 function (width, height) {
92 assertEquals(expected_width, width); 103 assertEquals(expected_width, width);
93 assertEquals(expected_height, height); 104 assertEquals(expected_height, height);
94 eventOccured(); 105 eventOccured();
(...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after
179 // pixels are changed. 190 // pixels are changed.
180 function isVideoPlaying(pixels, previousPixels) { 191 function isVideoPlaying(pixels, previousPixels) {
181 for (var i = 0; i < pixels.length; i++) { 192 for (var i = 0; i < pixels.length; i++) {
182 if (pixels[i] != previousPixels[i]) { 193 if (pixels[i] != previousPixels[i]) {
183 return true; 194 return true;
184 } 195 }
185 } 196 }
186 return false; 197 return false;
187 } 198 }
188 199
200 // Pixels is an array where pixels[0] is the R value for the first pixel,
201 // pixels[1] is the G value, and so on.
189 function isVideoBlack(pixels) { 202 function isVideoBlack(pixels) {
190 for (var i = 0; i < pixels.length; i++) { 203 for (var i = 0; i < pixels.length; i++) {
191 // |pixels| is in RGBA. Ignore the alpha channel. 204 if ((i + 1) % 4 == 0) {
192 // We allow it to be off by 1, to account for rounding errors in YUV 205 // Ignore the alpha channel.
193 // conversion. 206 continue;
194 if (pixels[i] != 0 && pixels[i] != 1 && (i + 1) % 4 != 0) { 207 }
208
209 // A black pixel has 0 for R,G and B but allow a bit more here to account
210 // for rounding errors in libyuv.
211 if (pixels[i] > 3) {
212 console.log('Found nonblack pixel at ' + i + ', was ' + pixels[i]);
195 return false; 213 return false;
196 } 214 }
197 } 215 }
198 return true; 216 return true;
199 } 217 }
200 218
201 // This function matches |left| and |right| and fails the test if the 219 // 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 220 // values don't match using normal javascript equality (i.e. the hard
203 // types of the operands aren't checked). 221 // types of the operands aren't checked).
204 function assertEquals(expected, actual) { 222 function assertEquals(expected, actual) {
(...skipping 17 matching lines...) Expand all
222 if (device.kind == 'video') 240 if (device.kind == 'video')
223 hasVideoInputDevice = true; 241 hasVideoInputDevice = true;
224 }); 242 });
225 243
226 if (hasVideoInputDevice) 244 if (hasVideoInputDevice)
227 sendValueToTest('has-video-input-device'); 245 sendValueToTest('has-video-input-device');
228 else 246 else
229 sendValueToTest('no-video-input-devices'); 247 sendValueToTest('no-video-input-devices');
230 }); 248 });
231 } 249 }
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