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

Side by Side Diff: chrome/test/data/webrtc/video_extraction.js

Issue 2123133003: Make video quality test fail cleaner if video hasn't started yet. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Repurpose patch to fail test faster. Created 4 years, 5 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 | « no previous file | 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 /** 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 /** 7 /**
8 * The gStartedAt when the capturing begins. Used for timeout adjustments. 8 * The gStartedAt when the capturing begins. Used for timeout adjustments.
9 * @private 9 * @private
10 */ 10 */
(...skipping 18 matching lines...) Expand all
29 */ 29 */
30 var gFrames = []; 30 var gFrames = [];
31 31
32 /** 32 /**
33 * We need to skip the first two frames due to timing issues. 33 * We need to skip the first two frames due to timing issues.
34 * @private 34 * @private
35 */ 35 */
36 var gHasThrownAwayFirstTwoFrames = false; 36 var gHasThrownAwayFirstTwoFrames = false;
37 37
38 /** 38 /**
39 * We need this global variable to synchronize with the test how long to run the 39 * A string to be returned to the test about the current status of capture.
40 * call between the two peers.
41 */ 40 */
42 var gDoneFrameCapturing = false; 41 var gCapturingStatus = 'capturing-not-started';
43 42
44 /** 43 /**
45 * Starts the frame capturing. 44 * Starts the frame capturing.
46 * 45 *
47 * @param {!Object} The video tag from which the height and width parameters are 46 * @param {!Object} The video tag from which the height and width parameters are
48 to be extracted. 47 to be extracted.
49 * @param {Number} The frame rate at which we would like to capture frames. 48 * @param {Number} The frame rate at which we would like to capture frames.
50 * @param {Number} The duration of the frame capture in seconds. 49 * @param {Number} The duration of the frame capture in seconds.
51 */ 50 */
52 function startFrameCapture(videoTag, frameRate, duration) { 51 function startFrameCapture(videoTag, frameRate, duration) {
53 gFrameCaptureInterval = 1000 / frameRate; 52 gFrameCaptureInterval = 1000 / frameRate;
54 gCaptureDuration = 1000 * duration; 53 gCaptureDuration = 1000 * duration;
55 inputElement = document.getElementById("local-view"); 54 inputElement = document.getElementById("local-view");
56 var width = inputElement.videoWidth; 55 var width = inputElement.videoWidth;
57 var height = inputElement.videoHeight; 56 var height = inputElement.videoHeight;
57
58 // The WebRTC code is free to start in VGA, so make sure that the output video 58 // The WebRTC code is free to start in VGA, so make sure that the output video
59 // tag scales up to whatever the input size is (otherwise the video quality 59 // tag scales up to whatever the input size is (otherwise the video quality
60 // comparison will go poorly. 60 // comparison will go poorly.
61 videoTag.width = width; 61 videoTag.width = width;
62 videoTag.height = height; 62 videoTag.height = height;
63 63
64 if (width == 0 || height == 0) { 64 if (width == 0 || height == 0) {
65 throw failTest('Trying to capture from ' + videoTag.id + 65 // Video must be playing at this point since this function is invoked from
66 ' but it is not playing any video.'); 66 // onplay on the <video> tag. See http://crbug.com/625943.
67 gCapturingStatus = 'failed-video-was-0x0-after-onplay'
68 return;
67 } 69 }
68 70
69 console.log('Received width is: ' + width + ', received height is: ' + height 71 console.log('Received width is: ' + width + ', received height is: ' + height
70 + ', capture interval is: ' + gFrameCaptureInterval + 72 + ', capture interval is: ' + gFrameCaptureInterval +
71 ', duration is: ' + gCaptureDuration); 73 ', duration is: ' + gCaptureDuration);
74 gCapturingStatus = 'still-capturing';
72 75
73 var remoteCanvas = document.createElement('canvas'); 76 var remoteCanvas = document.createElement('canvas');
74 remoteCanvas.width = width; 77 remoteCanvas.width = width;
75 remoteCanvas.height = height; 78 remoteCanvas.height = height;
76 document.body.appendChild(remoteCanvas); 79 document.body.appendChild(remoteCanvas);
77 80
78 gStartedAt = new Date().getTime(); 81 gStartedAt = new Date().getTime();
79 gFrames = []; 82 gFrames = [];
80 setTimeout(function() { shoot_(videoTag, remoteCanvas, width, height); }, 83 setTimeout(function() { shoot_(videoTag, remoteCanvas, width, height); },
81 gFrameCaptureInterval); 84 gFrameCaptureInterval);
82 } 85 }
83 86
84 /** 87 /**
85 * Queries if we're done with the frame capturing yet. 88 * Queries if we're done with the frame capturing yet.
86 */ 89 */
87 function doneFrameCapturing() { 90 function doneFrameCapturing() {
88 if (gDoneFrameCapturing) { 91 returnToTest(gCapturingStatus);
89 returnToTest('done-capturing');
90 } else {
91 returnToTest('still-capturing');
92 }
93 } 92 }
94 93
95 /** 94 /**
96 * Retrieves the number of captured frames. 95 * Retrieves the number of captured frames.
97 */ 96 */
98 function getTotalNumberCapturedFrames() { 97 function getTotalNumberCapturedFrames() {
99 returnToTest(gFrames.length.toString()); 98 returnToTest(gFrames.length.toString());
100 } 99 }
101 100
102 /** 101 /**
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after
162 var idealTime = gFrames.length * gFrameCaptureInterval; 161 var idealTime = gFrames.length * gFrameCaptureInterval;
163 var realTimeElapsed = currentTime - gStartedAt; 162 var realTimeElapsed = currentTime - gStartedAt;
164 var diff = realTimeElapsed - idealTime; 163 var diff = realTimeElapsed - idealTime;
165 164
166 if (realTimeElapsed < gCaptureDuration) { 165 if (realTimeElapsed < gCaptureDuration) {
167 // If duration isn't over shoot_ again. 166 // If duration isn't over shoot_ again.
168 setTimeout(function() { shoot_(video, canvas, width, height); }, 167 setTimeout(function() { shoot_(video, canvas, width, height); },
169 gFrameCaptureInterval - diff); 168 gFrameCaptureInterval - diff);
170 } else { 169 } else {
171 // Done capturing! 170 // Done capturing!
172 gDoneFrameCapturing = true; 171 gCapturingStatus = 'done-capturing';
173 prepareProgressBar_(); 172 prepareProgressBar_();
174 } 173 }
175 } 174 }
176 175
177 /** 176 /**
178 * @private 177 * @private
179 */ 178 */
180 function captureFrame_(video, context, width, height) { 179 function captureFrame_(video, context, width, height) {
181 context.drawImage(video, 0, 0, width, height); 180 context.drawImage(video, 0, 0, width, height);
182 return context.getImageData(0, 0, width, height); 181 return context.getImageData(0, 0, width, height);
(...skipping 11 matching lines...) Expand all
194 } 193 }
195 194
196 /** 195 /**
197 * @private 196 * @private
198 */ 197 */
199 function updateProgressBar_(currentFrame) { 198 function updateProgressBar_(currentFrame) {
200 progressBar.innerHTML = 199 progressBar.innerHTML =
201 'Transferring captured frames: ' + '(' + currentFrame + '/' + 200 'Transferring captured frames: ' + '(' + currentFrame + '/' +
202 gFrames.length + ')'; 201 gFrames.length + ')';
203 } 202 }
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698