1 <!-- Used by media_stat_perf to calculate <video> performance statistics. -->
6 <title>CPU, Memory, and FPS Perf Test</title>
10 Decoded frames: 0 Avg: 0<br>
11 Dropped frames: 0 Avg: 0<br>
13 <video preload controls></video>
16 <script type="text/javascript">
17 var video = document.querySelector("video");
19 function calculateStats() {
20 if (video.readyState <= HTMLMediaElement.HAVE_CURRENT_DATA ||
21 video.paused || video.ended)
23 // Not all test files have same duration, so to make the tests run shorter
24 // we need a time limit.
25 // From aggregated data, 5 seconds is enough time to get reliable results.
26 if (video.currentTime > 5) {
27 video.currentTime = video.duration;
30 currentTime = new Date().getTime();
31 deltaTime = (currentTime - startTime) / 1000;
32 startTime = currentTime;
34 // Calculate decoded frames per sec.
35 var fps = (video.webkitDecodedFrameCount - decodedFrames) / deltaTime;
36 decodedFrames = video.webkitDecodedFrameCount;
39 // Calculate dropped frames per sec.
40 fps = (video.webkitDroppedFrameCount - droppedFrames) / deltaTime;
41 droppedFrames = video.webkitDroppedFrameCount;
44 var d = document.getElementById("log");
46 "Decoded frames: " + decodedFrames +
47 " Avg: " + decodedFPS + " fps.<br>" +
48 "Dropped frames: " + droppedFrames +
49 " Avg: " + droppedFPS + " fps.<br>";
52 video.addEventListener("playing", function(event) {
57 startTime = new Date().getTime();
58 intID = window.setInterval(calculateStats, 1000);
61 video.addEventListener("error", function() { endTest(false); }, false);
62 video.addEventListener("ended", function() { endTest(true); }, false);
64 function endTest(successFlag) {
65 window.clearInterval(intID);
66 // Notify PyAuto that we've completed the test run.
67 if (window.domAutomationController)
68 window.domAutomationController.send(successFlag);
71 function startTest(url) {