- add sources.
[platform/framework/web/crosswalk.git] / src / chrome / test / data / media / html / media_stat_perf.html
1 <!-- Used by media_stat_perf to calculate <video> performance statistics. -->
2
3 <!DOCTYPE html>
4 <html lang="en-US">
5   <head>
6     <title>CPU, Memory, and FPS Perf Test</title>
7   </head>
8   <body>
9     <div id="log">
10       Decoded frames: 0 Avg: 0<br>
11       Dropped frames: 0 Avg: 0<br>
12     </div>
13     <video preload controls></video>
14   </body>
15
16   <script type="text/javascript">
17     var video = document.querySelector("video");
18
19     function calculateStats() {
20       if (video.readyState <= HTMLMediaElement.HAVE_CURRENT_DATA ||
21           video.paused || video.ended)
22         return;
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;
28       }
29
30       currentTime = new Date().getTime();
31       deltaTime = (currentTime - startTime) / 1000;
32       startTime = currentTime;
33
34       // Calculate decoded frames per sec.
35       var fps = (video.webkitDecodedFrameCount - decodedFrames) / deltaTime;
36       decodedFrames = video.webkitDecodedFrameCount;
37       decodedFPS.push(fps);
38
39       // Calculate dropped frames per sec.
40       fps = (video.webkitDroppedFrameCount - droppedFrames) / deltaTime;
41       droppedFrames = video.webkitDroppedFrameCount;
42       droppedFPS.push(fps);
43
44       var d = document.getElementById("log");
45       d.innerHTML =
46         "Decoded frames: " + decodedFrames +
47         " Avg: " + decodedFPS + " fps.<br>" +
48         "Dropped frames: " + droppedFrames +
49         " Avg: " + droppedFPS + " fps.<br>";
50     }
51
52     video.addEventListener("playing", function(event) {
53       decodedFrames = 0;
54       droppedFrames = 0;
55       decodedFPS = [];
56       droppedFPS = [];
57       startTime = new Date().getTime();
58       intID = window.setInterval(calculateStats, 1000);
59     });
60
61     video.addEventListener("error", function() { endTest(false); }, false);
62     video.addEventListener("ended", function() { endTest(true); }, false);
63
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);
69     }
70
71     function startTest(url) {
72       video.src = url;
73       video.play();
74     }
75   </script>
76 </html>