OLD | NEW |
---|---|
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 169 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
180 function isVideoPlaying(pixels, previousPixels) { | 180 function isVideoPlaying(pixels, previousPixels) { |
181 for (var i = 0; i < pixels.length; i++) { | 181 for (var i = 0; i < pixels.length; i++) { |
182 if (pixels[i] != previousPixels[i]) { | 182 if (pixels[i] != previousPixels[i]) { |
183 return true; | 183 return true; |
184 } | 184 } |
185 } | 185 } |
186 return false; | 186 return false; |
187 } | 187 } |
188 | 188 |
189 function isVideoBlack(pixels) { | 189 function isVideoBlack(pixels) { |
190 for (var i = 0; i < pixels.length; i++) { | 190 var threshold = 20; |
191 // |pixels| is in RGBA. Ignore the alpha channel. | 191 var accumulatedLuma = 0; |
192 // We allow it to be off by 1, to account for rounding errors in YUV | 192 for (var i = 4; i < pixels.length; i += 4) { |
kjellander_chromium
2015/05/19 08:08:54
Please keep the comment about that |pixels| is in
phoglund_chromium
2015/05/19 09:01:19
Done.
| |
193 // conversion. | 193 // Use Luma as in Rec. 709: Y′709 = 0.21R + 0.72G + 0.07B; |
kjellander_chromium
2015/05/19 08:08:54
I'm new to color space standards, but according to
phoglund_chromium
2015/05/19 09:01:20
Done.
| |
194 if (pixels[i] != 0 && pixels[i] != 1 && (i + 1) % 4 != 0) { | 194 accumulatedLuma += |
195 0.21 * pixels[i] + 0.72 * pixels[i + 1] + 0.07 * pixels[i + 2]; | |
kjellander_chromium
2015/05/19 08:08:54
Can you extract what's after += to a function?
phoglund_chromium
2015/05/19 09:01:19
Done.
| |
196 if (accumulatedLuma > threshold * i / 4) | |
195 return false; | 197 return false; |
196 } | |
197 } | 198 } |
198 return true; | 199 return true; |
199 } | 200 } |
200 | 201 |
201 // This function matches |left| and |right| and fails the test if the | 202 // 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 | 203 // values don't match using normal javascript equality (i.e. the hard |
203 // types of the operands aren't checked). | 204 // types of the operands aren't checked). |
204 function assertEquals(expected, actual) { | 205 function assertEquals(expected, actual) { |
205 if (actual != expected) { | 206 if (actual != expected) { |
206 failTest("expected '" + expected + "', got '" + actual + "'."); | 207 failTest("expected '" + expected + "', got '" + actual + "'."); |
(...skipping 15 matching lines...) Expand all Loading... | |
222 if (device.kind == 'video') | 223 if (device.kind == 'video') |
223 hasVideoInputDevice = true; | 224 hasVideoInputDevice = true; |
224 }); | 225 }); |
225 | 226 |
226 if (hasVideoInputDevice) | 227 if (hasVideoInputDevice) |
227 sendValueToTest('has-video-input-device'); | 228 sendValueToTest('has-video-input-device'); |
228 else | 229 else |
229 sendValueToTest('no-video-input-devices'); | 230 sendValueToTest('no-video-input-devices'); |
230 }); | 231 }); |
231 } | 232 } |
OLD | NEW |