PageRenderTime 71ms CodeModel.GetById 20ms RepoModel.GetById 0ms app.codeStats 0ms

/Demo/broadway.html

http://github.com/mbebenita/Broadway
HTML | 342 lines | 296 code | 45 blank | 1 comment | 0 complexity | 6629aa1e70acce3e6520b12614d8ae4b MD5 | raw file
Possible License(s): BSD-3-Clause
  1. <!DOCTYPE html>
  2. <html>
  3. <head>
  4. <style>
  5. /* MetaWebPro font family licensed from fontshop.com. WOFF-FTW! */
  6. @font-face {
  7. font-family: 'MetaBlack';
  8. src: url('http://mozcom-cdn.mozilla.net/img/fonts/MetaWebPro-Black.eot');
  9. src: local('☺'),
  10. url('http://mozcom-cdn.mozilla.net/img/fonts/MetaWebPro-Black.woff')
  11. format('woff');
  12. font-weight: bold;
  13. }
  14. </style>
  15. </head>
  16. <body>
  17. <meta charset="utf-8">
  18. <style>
  19. #site-title {
  20. display: block;
  21. font: normal bold 60px/.738 MetaBlack, "Arial Black", sans-serif;
  22. letter-spacing: -0.02em;
  23. }
  24. #doc {
  25. margin: 0 auto;
  26. width: 1200px;
  27. padding: 10px;
  28. }
  29. #setting {
  30. margin-top: 10px;
  31. }
  32. #tagline {
  33. clear: both;
  34. font: 1.538em/1.4 Georgia, sans-serif;
  35. color: #484848;
  36. padding: 0 430px 0 0px;
  37. }
  38. body {
  39. font: normal 16px/.738 MetaBlack, "Arial Black", sans-serif;
  40. color: #6D7581;
  41. }
  42. select {
  43. font: normal 16px "Arial", sans-serif;
  44. padding: 1px;
  45. color: #6D7581;
  46. }
  47. th {
  48. text-align: left;
  49. padding: 4px 4px 4px 12px;
  50. background: no-repeat;
  51. }
  52. td {
  53. padding-left: 8px;
  54. text-align: right;
  55. }
  56. #controls {
  57. background-color: black;
  58. padding: 10px;
  59. height: 40px;
  60. }
  61. #play {
  62. width: 100px;
  63. float: left;
  64. }
  65. #scrubber {
  66. margin-left: 120px;
  67. margin-top: 12px;
  68. margin-right: 10px;
  69. }
  70. </style>
  71. <link type="text/css" href="jquery/theme/jquery-ui.css" rel="stylesheet" />
  72. <script type="text/javascript" src="jquery/jquery.min.js"></script>
  73. <script type="text/javascript" src="jquery/jquery-ui.min.js"></script>
  74. <script type='text/javascript'>
  75. var Module = {
  76. noInitialRun : true
  77. };
  78. </script>
  79. <script src="sylvester.js" type="text/javascript"></script>
  80. <script src="glUtils.js" type="text/javascript"></script>
  81. <script src='util.js' type='text/javascript'></script>
  82. <script src='canvas.js' type='text/javascript'></script>
  83. <script src='broadway.js' type='text/javascript'></script>
  84. <script type="text/javascript">
  85. $(function() {
  86. $("#tabs").tabs();
  87. $("#play").button();
  88. $("#play").click(function() {
  89. play();
  90. });
  91. $( "#scrubber" ).slider({
  92. range: false,
  93. min: 0,
  94. max: 500,
  95. value: 0,
  96. slide: function( event, ui ) {
  97. var pos = ui.value / 500;
  98. _setPosition(pos);
  99. }
  100. });
  101. });
  102. var scoreCalculated = false;
  103. var steadySampleCounter = 0;
  104. var steadyFpsCounter = 0;
  105. function updateStats(fps, fpsSinceStart, frames, elapsed) {
  106. var steadyElapsedThreshold = 5;
  107. if (elapsed > steadyElapsedThreshold) {
  108. steadySampleCounter++;
  109. steadyFpsCounter += fps;
  110. }
  111. document.getElementById('fps').innerHTML = fps.toFixed(2);
  112. document.getElementById('fpsSinceStart').innerHTML = fpsSinceStart.toFixed(2);
  113. document.getElementById('fpsSinceSteady').innerHTML = (steadyFpsCounter / steadySampleCounter).toFixed(2);
  114. document.getElementById('elapsed').innerHTML = elapsed.toFixed(2);
  115. var scoreTimeout = 60;
  116. if (elapsed > scoreTimeout && scoreCalculated == false) {
  117. scoreCalculated = true;
  118. document.getElementById('score').innerHTML = fpsSinceStart.toFixed(2);
  119. }
  120. if (scoreCalculated == false) {
  121. document.getElementById('score').innerHTML = "Calculating: " + (scoreTimeout - elapsed).toFixed(0);
  122. }
  123. }
  124. function load() {
  125. document.getElementById('downloadProgress').innerHTML = "Downloading, Please Wait ...";
  126. var clip = $("#clip").val();
  127. var mode = $("#mode").val();
  128. var xhr = new XMLHttpRequest();
  129. xhr.open("GET", clip, false);
  130. xhr.responseType = "arraybuffer";
  131. xhr.send(null);
  132. var arrayBuffer = xhr.response;
  133. if (arrayBuffer) {
  134. var byteArray = new Uint8Array(arrayBuffer);
  135. var array = Array.prototype.slice.apply(byteArray);
  136. Module.FS.createDataFile('/', 'video.264', array, true, false);
  137. } else {
  138. alert('load fail :(');
  139. }
  140. document.getElementById('downloadProgress').innerHTML = "Download Complete, Playing ...";
  141. // Pass canvas and context to the generated code, and do the actual run() here
  142. Module.canvas = document.getElementById('canvas');
  143. if (mode == "none") {
  144. _paint = function() {
  145. };
  146. _SDL_LockSurface = function() {
  147. }
  148. } else if (mode == "webgl") {
  149. _paint = paint;
  150. _SDL_LockSurface = function() {};
  151. _SDL_Quit = function() {};
  152. } else {
  153. Module.ctx2D = Module.canvas.getContext('2d');
  154. if (!Module.ctx2D) {
  155. alert('Canvas not available :(');
  156. return;
  157. }
  158. }
  159. console.info("Running: " + clip);
  160. Module.run(['video.264']);
  161. }
  162. var loaded = false;
  163. var playing = false;
  164. function play() {
  165. if (!loaded) {
  166. load();
  167. loaded = true;
  168. }
  169. if (playing == false) {
  170. $('#play').children().first().html("Pause");
  171. playing = true;
  172. Module.play();
  173. } else {
  174. $('#play').children().first().html("Play");
  175. playing = false;
  176. Module.stop();
  177. return;
  178. }
  179. }
  180. var webGLCanvas = null;
  181. var videoFrameCounter = 0;
  182. var windowFrameCounter = 0;
  183. var videoStartTime;
  184. var windowStartTime;
  185. var scoreFrameCount = 1200;
  186. function onFrameDecoded() {
  187. videoFrameCounter += 1;
  188. windowFrameCounter += 1;
  189. var now = Date.now();
  190. if (!videoStartTime) {
  191. videoStartTime = now;
  192. }
  193. var videoElapsedTime = now - videoStartTime;
  194. if (!windowStartTime) {
  195. windowStartTime = now;
  196. } else if ((now - windowStartTime) > 1000) {
  197. var windowElapsedTime = now - windowStartTime;
  198. var fps = (windowFrameCounter / windowElapsedTime) * 1000;
  199. document.getElementById('fps').innerHTML = fps.toFixed(2);
  200. windowStartTime = now;
  201. windowFrameCounter = 0;
  202. }
  203. if (videoFrameCounter % 10 == 0) {
  204. var fps = (videoFrameCounter / videoElapsedTime) * 1000;
  205. document.getElementById('fpsSinceStart').innerHTML = fps.toFixed(2);
  206. }
  207. if (!scoreCalculated) {
  208. if (videoFrameCounter % 10 == 0) {
  209. document.getElementById('score').innerHTML = "Calculating: " + (scoreFrameCount - videoFrameCounter);
  210. }
  211. if (videoFrameCounter == scoreFrameCount) {
  212. var fps = (videoFrameCounter / videoElapsedTime) * 1000;
  213. document.getElementById('score').innerHTML = fps.toFixed(2);
  214. scoreCalculated = true;
  215. }
  216. }
  217. }
  218. function updateScrubber() {
  219. $("#scrubber").slider('value', _getPosition() * 500);
  220. }
  221. function paint($luma, $cb, $cr, width, height) {
  222. if (!webGLCanvas) {
  223. webGLCanvas = new YUVWebGLCanvas(Module.canvas, new Size(width, height));
  224. }
  225. var luma = HEAPU8.subarray($luma);
  226. var cb = HEAPU8.subarray($cb);
  227. var cr = HEAPU8.subarray($cr);
  228. webGLCanvas.YTexture.fill(luma);
  229. webGLCanvas.UTexture.fill(cb);
  230. webGLCanvas.VTexture.fill(cr);
  231. webGLCanvas.drawScene();
  232. }
  233. </script>
  234. <div id="doc">
  235. <header>
  236. <h1 id="site-title"><b>Broadway.js</b></h1>
  237. <p id="tagline">An H.264 Decoder in Pure JavaScript <a href="broadway-new.html">(Try New Codec)</a></p>
  238. </header>
  239. <div>
  240. <div id="setting">
  241. <span>Clip:
  242. <select id="clip" style="margin-left: 10px;">
  243. <option value="mozilla.264">Mozilla</option>
  244. <option value="admiral.264">Admiral</option>
  245. <option value="matrix.264">Matrix SD</option>
  246. <option value="matrix_large.264">Matrix HD</option>
  247. </select>
  248. </span>
  249. </div>
  250. <div id="setting">
  251. <span>Render Mode:
  252. <select id="mode" style="margin-left: 10px;">
  253. <option value="canvas">Canvas</option>
  254. <option value="webgl">Canvas w/ WebGL</option>
  255. <option value="none">None</option>
  256. </select>
  257. </span>
  258. <span style="margin-left: 10px; border: 0px" id="downloadProgress"></span>
  259. </div>
  260. <div id="setting">
  261. <div style="margin-left: 10px; border: 0px; clear: both;" id="downloadProgress"></div>
  262. </div>
  263. <div>
  264. <div id="player" style="background-color: black; float: left;">
  265. <canvas id='canvas' width="640" height="100" style="background-color: #333333;"></canvas>
  266. <div id="controls">
  267. <button id="play">Play</button>
  268. <div id="scrubber"></div>
  269. </div>
  270. </div>
  271. </div>
  272. <!-- Stats -->
  273. <div
  274. style="height: 480px; margin-top: 30px; margin-bottom: 10px; clear: both;">
  275. <table style="margin-top: 10px; width: 300;">
  276. <tr>
  277. <th>FPS</th>
  278. <td><span id='fps' style="color: red;"></span></td>
  279. </tr>
  280. <tr>
  281. <th>Average FPS (All / Steady)</th>
  282. <td><span id='fpsSinceStart' style="color: green;"></span> /
  283. <span id='fpsSinceSteady' style="color: green;"></span></td>
  284. </tr>
  285. <tr>
  286. <th>Elapsed</th>
  287. <td><span id='elapsed'></span></td>
  288. </tr>
  289. <tr>
  290. <th>Score</th>
  291. <td><span id='score' style="color: brown;"></span></td>
  292. </tr>
  293. </table>
  294. </div>
  295. </div>
  296. </body>
  297. </html>