| OLD | NEW |
| 1 /** | 1 /** |
| 2 * Copyright (c) 2012 The Chromium Authors. All rights reserved. | 2 * Copyright (c) 2012 The Chromium Authors. All rights reserved. |
| 3 * Use of this source code is governed by a BSD-style license that can be | 3 * Use of this source code is governed by a BSD-style license that can be |
| 4 * found in the LICENSE file. | 4 * found in the LICENSE file. |
| 5 */ | 5 */ |
| 6 | 6 |
| 7 // This file requires the functions defined in test_functions.js. | 7 // This file requires the functions defined in test_functions.js. |
| 8 | 8 |
| 9 var gFingerprints = []; | 9 var gFingerprints = []; |
| 10 | 10 |
| 11 // Public interface. | 11 // Public interface. |
| 12 | 12 |
| 13 /** | 13 /** |
| 14 * Starts capturing frames from a video tag. The algorithm will fingerprint a | 14 * Starts capturing frames from a video tag. The algorithm will fingerprint a |
| 15 * a frame every now and then. After calling this function and running for a | 15 * a frame every now and then. After calling this function and running for a |
| 16 * while (at least 200 ms) you will be able to call isVideoPlaying to see if | 16 * while (at least 200 ms) you will be able to call isVideoPlaying to see if |
| 17 * we detected any video. | 17 * we detected any video. |
| 18 * | 18 * |
| 19 * @param {string} videoElementId The video element to analyze. | 19 * @param {string} videoElementId The video element to analyze. |
| 20 * @param {string} canvasId A canvas element to write fingerprints into. | 20 * @param {string} canvasId A canvas element to write fingerprints into. |
| 21 * @param {int} width The video element's width. | 21 * @param {int} width The video element's width. |
| 22 * @param {int} width The video element's height. | 22 * @param {int} width The video element's height. |
| 23 * | 23 * |
| 24 * @return {string} Returns ok-started to PyAuto. | 24 * @return {string} Returns ok-started to the test. |
| 25 */ | 25 */ |
| 26 // | 26 // |
| 27 function startDetection(videoElementId, canvasId, width, height) { | 27 function startDetection(videoElementId, canvasId, width, height) { |
| 28 var video = document.getElementById(videoElementId); | 28 var video = document.getElementById(videoElementId); |
| 29 var canvas = document.getElementById(canvasId); | 29 var canvas = document.getElementById(canvasId); |
| 30 var NUM_FINGERPRINTS_TO_SAVE = 5; | 30 var NUM_FINGERPRINTS_TO_SAVE = 5; |
| 31 | 31 |
| 32 setInterval(function() { | 32 setInterval(function() { |
| 33 var context = canvas.getContext('2d'); | 33 var context = canvas.getContext('2d'); |
| 34 captureFrame_(video, context, width, height); | 34 captureFrame_(video, context, width, height); |
| (...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 90 function fingerprint_(canvasContext, width, height) { | 90 function fingerprint_(canvasContext, width, height) { |
| 91 var imageData = canvasContext.getImageData(0, 0, width, height); | 91 var imageData = canvasContext.getImageData(0, 0, width, height); |
| 92 var pixels = imageData.data; | 92 var pixels = imageData.data; |
| 93 | 93 |
| 94 var fingerprint = 0; | 94 var fingerprint = 0; |
| 95 for (var i = 0; i < pixels.length; i++) { | 95 for (var i = 0; i < pixels.length; i++) { |
| 96 fingerprint += pixels[i]; | 96 fingerprint += pixels[i]; |
| 97 } | 97 } |
| 98 return fingerprint; | 98 return fingerprint; |
| 99 } | 99 } |
| OLD | NEW |