| OLD | NEW |
| (Empty) |
| 1 <!-- Used by media_fps_perf to calculate <video> performance statistics. --> | |
| 2 | |
| 3 <!DOCTYPE html> | |
| 4 <html lang="en-US"> | |
| 5 <head> | |
| 6 <title>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 var decodedFrames = 0; | |
| 20 var droppedFrames = 0; | |
| 21 var decodedFPS = []; | |
| 22 var droppedFPS = []; | |
| 23 var startTime = 0; | |
| 24 var intID = 0; // interval ID, used to end the window intervals. | |
| 25 | |
| 26 function calculateStats() { | |
| 27 if (video.readyState <= HTMLMediaElement.HAVE_CURRENT_DATA || | |
| 28 video.paused || video.ended) | |
| 29 return; | |
| 30 | |
| 31 currentTime = new Date().getTime(); | |
| 32 deltaTime = (currentTime - startTime) / 1000; | |
| 33 startTime = currentTime; | |
| 34 | |
| 35 // Calculate decoded frames per sec. | |
| 36 var fps = (video.webkitDecodedFrameCount - decodedFrames) / deltaTime; | |
| 37 decodedFrames = video.webkitDecodedFrameCount; | |
| 38 decodedFPS.push(fps); | |
| 39 | |
| 40 // Calculate dropped frames per sec. | |
| 41 fps = (video.webkitDroppedFrameCount - droppedFrames) / deltaTime; | |
| 42 droppedFrames = video.webkitDroppedFrameCount; | |
| 43 droppedFPS.push(fps); | |
| 44 | |
| 45 var d = document.getElementById("log"); | |
| 46 d.innerHTML = | |
| 47 "Decoded frames: " + decodedFrames + | |
| 48 " Avg: " + decodedFPS + " fps.<br>" + | |
| 49 "Dropped frames: " + droppedFrames + | |
| 50 " Avg: " + droppedFPS + " fps.<br>"; | |
| 51 } | |
| 52 | |
| 53 video.addEventListener("playing", function(event) { | |
| 54 decodedFrames = 0; | |
| 55 droppedFrames = 0; | |
| 56 decodedFPS = []; | |
| 57 droppedFPS = []; | |
| 58 startTime = new Date().getTime(); | |
| 59 intID = window.setInterval(calculateStats, 1000); | |
| 60 }); | |
| 61 | |
| 62 video.addEventListener("error", function() { endTest(false); }, false); | |
| 63 video.addEventListener("ended", function() { endTest(true); }, false); | |
| 64 | |
| 65 function endTest(successFlag) { | |
| 66 window.clearInterval(intID); | |
| 67 // Notify PyAuto that we've completed the test run. | |
| 68 if (window.domAutomationController) | |
| 69 window.domAutomationController.send(successFlag); | |
| 70 } | |
| 71 | |
| 72 function startTest(url) { | |
| 73 // End any previously started tests. | |
| 74 window.clearInterval(intID); | |
| 75 | |
| 76 video.src = url; | |
| 77 video.play(); | |
| 78 } | |
| 79 </script> | |
| 80 </html> | |
| OLD | NEW |