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

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

Issue 1142643004: Revert of Re-enable local video test with better logging and higher tolerance. (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');
69 var oldPixels = []; 70 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 }
77 var context = canvas.getContext('2d'); 72 var context = canvas.getContext('2d');
78 context.drawImage(videoElement, 0, 0, width, height); 73 context.drawImage(videoElement, 0, 0, width, height);
79 var pixels = context.getImageData(0, 0 , width, height / 3).data; 74 var pixels = context.getImageData(0, 0 , width, height / 3).data;
80 // Check that there is an old and a new picture with the same size to 75 // Check that there is an old and a new picture with the same size to
81 // compare and use the function |predicate| to detect the video state in 76 // compare and use the function |predicate| to detect the video state in
82 // that case. 77 // that case.
83 if (oldPixels.length == pixels.length && 78 if (oldPixels.length == pixels.length &&
84 predicate(pixels, oldPixels)) { 79 predicate(pixels, oldPixels)) {
85 console.log('Done looking at video in element ' + videoElementName); 80 console.log('Done looking at video in element ' + videoElementName);
86 clearInterval(waitVideo); 81 clearInterval(waitVideo);
87 callback(videoElement.videoWidth, videoElement.videoHeight); 82 callback(videoElement.videoWidth, videoElement.videoHeight);
88 } 83 }
89 oldPixels = pixels; 84 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 }
96 }, 200); 85 }, 200);
97 } 86 }
98 87
99 function waitForVideoWithResolution(element, expected_width, expected_height) { 88 function waitForVideoWithResolution(element, expected_width, expected_height) {
100 addExpectedEvent(); 89 addExpectedEvent();
101 detectVideoPlaying(element, 90 detectVideoPlaying(element,
102 function (width, height) { 91 function (width, height) {
103 assertEquals(expected_width, width); 92 assertEquals(expected_width, width);
104 assertEquals(expected_height, height); 93 assertEquals(expected_height, height);
105 eventOccured(); 94 eventOccured();
(...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after
190 // pixels are changed. 179 // pixels are changed.
191 function isVideoPlaying(pixels, previousPixels) { 180 function isVideoPlaying(pixels, previousPixels) {
192 for (var i = 0; i < pixels.length; i++) { 181 for (var i = 0; i < pixels.length; i++) {
193 if (pixels[i] != previousPixels[i]) { 182 if (pixels[i] != previousPixels[i]) {
194 return true; 183 return true;
195 } 184 }
196 } 185 }
197 return false; 186 return false;
198 } 187 }
199 188
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.
202 function isVideoBlack(pixels) { 189 function isVideoBlack(pixels) {
203 for (var i = 0; i < pixels.length; i++) { 190 for (var i = 0; i < pixels.length; i++) {
204 if ((i + 1) % 4 == 0) { 191 // |pixels| is in RGBA. Ignore the alpha channel.
205 // Ignore the alpha channel. 192 // We allow it to be off by 1, to account for rounding errors in YUV
206 continue; 193 // conversion.
207 } 194 if (pixels[i] != 0 && pixels[i] != 1 && (i + 1) % 4 != 0) {
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]);
213 return false; 195 return false;
214 } 196 }
215 } 197 }
216 return true; 198 return true;
217 } 199 }
218 200
219 // This function matches |left| and |right| and fails the test if the 201 // This function matches |left| and |right| and fails the test if the
220 // values don't match using normal javascript equality (i.e. the hard 202 // values don't match using normal javascript equality (i.e. the hard
221 // types of the operands aren't checked). 203 // types of the operands aren't checked).
222 function assertEquals(expected, actual) { 204 function assertEquals(expected, actual) {
(...skipping 17 matching lines...) Expand all
240 if (device.kind == 'video') 222 if (device.kind == 'video')
241 hasVideoInputDevice = true; 223 hasVideoInputDevice = true;
242 }); 224 });
243 225
244 if (hasVideoInputDevice) 226 if (hasVideoInputDevice)
245 sendValueToTest('has-video-input-device'); 227 sendValueToTest('has-video-input-device');
246 else 228 else
247 sendValueToTest('no-video-input-devices'); 229 sendValueToTest('no-video-input-devices');
248 }); 230 });
249 } 231 }
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