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 95 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
106 } | 106 } |
107 | 107 |
108 function waitForBlackVideo(videoElement) { | 108 function waitForBlackVideo(videoElement) { |
109 addExpectedEvent(); | 109 addExpectedEvent(); |
110 detectBlackVideo(videoElement, function () { eventOccured(); }); | 110 detectBlackVideo(videoElement, function () { eventOccured(); }); |
111 } | 111 } |
112 | 112 |
113 // Calculates the current frame rate and compares to |expected_frame_rate| | 113 // Calculates the current frame rate and compares to |expected_frame_rate| |
114 // |callback| is triggered with value |true| if the calculated frame rate | 114 // |callback| is triggered with value |true| if the calculated frame rate |
115 // is +-1 the expected or |false| if five calculations fail to match | 115 // is +-1 the expected or |false| if five calculations fail to match |
116 // |expected_frame_rate|. | 116 // |expected_frame_rate|. Calls back with OK if the check passed, otherwise |
| 117 // an error message. |
117 function validateFrameRate(videoElementName, expected_frame_rate, callback) { | 118 function validateFrameRate(videoElementName, expected_frame_rate, callback) { |
118 var videoElement = $(videoElementName); | 119 var videoElement = $(videoElementName); |
119 var startTime = new Date().getTime(); | 120 var startTime = new Date().getTime(); |
120 var decodedFrames = videoElement.webkitDecodedFrameCount; | 121 var decodedFrames = videoElement.webkitDecodedFrameCount; |
121 var attempts = 0; | 122 var attempts = 0; |
122 | 123 |
123 if (videoElement.readyState <= HTMLMediaElement.HAVE_CURRENT_DATA || | 124 if (videoElement.readyState <= HTMLMediaElement.HAVE_CURRENT_DATA || |
124 videoElement.paused || videoElement.ended) { | 125 videoElement.paused || videoElement.ended) { |
125 failTest("getFrameRate - " + videoElementName + " is not plaing."); | 126 failTest("getFrameRate - " + videoElementName + " is not plaing."); |
126 return; | 127 return; |
127 } | 128 } |
128 | 129 |
129 var waitVideo = setInterval(function() { | 130 var waitVideo = setInterval(function() { |
130 attempts++; | 131 attempts++; |
131 currentTime = new Date().getTime(); | 132 currentTime = new Date().getTime(); |
132 deltaTime = (currentTime - startTime) / 1000; | 133 deltaTime = (currentTime - startTime) / 1000; |
133 startTime = currentTime; | 134 startTime = currentTime; |
134 | 135 |
135 // Calculate decoded frames per sec. | 136 // Calculate decoded frames per sec. |
136 var fps = | 137 var fps = |
137 (videoElement.webkitDecodedFrameCount - decodedFrames) / deltaTime; | 138 (videoElement.webkitDecodedFrameCount - decodedFrames) / deltaTime; |
138 decodedFrames = videoElement.webkitDecodedFrameCount; | 139 decodedFrames = videoElement.webkitDecodedFrameCount; |
139 | 140 |
140 console.log('FrameRate in ' + videoElementName + ' is ' + fps); | 141 console.log('FrameRate in ' + videoElementName + ' is ' + fps); |
141 if (fps < expected_frame_rate + 1 && fps > expected_frame_rate - 1) { | 142 if (fps < expected_frame_rate + 1 && fps > expected_frame_rate - 1) { |
142 clearInterval(waitVideo); | 143 clearInterval(waitVideo); |
143 callback(true); | 144 callback('OK'); |
144 } else if (attempts == 5) { | 145 } else if (attempts == 5) { |
145 clearInterval(waitVideo); | 146 clearInterval(waitVideo); |
146 callback(false); | 147 callback('Expected frame rate ' + expected_frame_rate + ' for ' + |
| 148 'element ' + videoElementName + ', but got ' + fps); |
147 } | 149 } |
148 }, 1000); | 150 }, 1000); |
149 } | 151 } |
150 | 152 |
151 function waitForConnectionToStabilize(peerConnection, callback) { | 153 function waitForConnectionToStabilize(peerConnection, callback) { |
152 peerConnection.onsignalingstatechange = function(event) { | 154 peerConnection.onsignalingstatechange = function(event) { |
153 if (peerConnection.signalingState == 'stable') { | 155 if (peerConnection.signalingState == 'stable') { |
154 peerConnection.onsignalingstatechange = null; | 156 peerConnection.onsignalingstatechange = null; |
155 callback(); | 157 callback(); |
156 } | 158 } |
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
204 failTest("expected '" + expected + "', got '" + actual + "'."); | 206 failTest("expected '" + expected + "', got '" + actual + "'."); |
205 } | 207 } |
206 } | 208 } |
207 | 209 |
208 function assertNotEquals(expected, actual) { | 210 function assertNotEquals(expected, actual) { |
209 if (actual === expected) { | 211 if (actual === expected) { |
210 failTest("expected '" + expected + "', got '" + actual + "'."); | 212 failTest("expected '" + expected + "', got '" + actual + "'."); |
211 } | 213 } |
212 } | 214 } |
213 | 215 |
OLD | NEW |