PageRenderTime 38ms CodeModel.GetById 16ms RepoModel.GetById 1ms app.codeStats 0ms

/Demo/broadway-new.html

http://github.com/mbebenita/Broadway
HTML | 231 lines | 207 code | 23 blank | 1 comment | 0 complexity | 7a488d08948a27f02efbb157a6091d7a MD5 | raw file
Possible License(s): BSD-3-Clause
  1. <!DOCTYPE html>
  2. <html>
  3. <head>
  4. <link type="text/css" href="screen.css" rel="stylesheet" />
  5. <link type="text/css" href="jquery/theme/jquery-ui.css" rel="stylesheet" />
  6. </head>
  7. <body>
  8. <script type="text/javascript" src="jquery/jquery.min.js"></script>
  9. <script type="text/javascript" src="jquery/jquery-ui.min.js"></script>
  10. <script type='text/javascript'>
  11. var Module = {
  12. noInitialRun : true
  13. };
  14. </script>
  15. <script src="sylvester.js" type="text/javascript"></script>
  16. <script src="glUtils.js" type="text/javascript"></script>
  17. <script src='util.js' type='text/javascript'></script>
  18. <script src='canvas.js' type='text/javascript'></script>
  19. <script src='broadway-new.js' type='text/javascript'></script>
  20. <script type="text/javascript">
  21. $(function() {
  22. $("#tabs").tabs();
  23. $("#play").button();
  24. $("#play").click(function() {
  25. play();
  26. });
  27. $( "#scrubber" ).slider({
  28. range: false,
  29. min: 0,
  30. max: 500,
  31. value: 0,
  32. slide: function( event, ui ) {
  33. var pos = ui.value / 500;
  34. _setPosition(pos);
  35. }
  36. });
  37. });
  38. function load() {
  39. document.getElementById('downloadProgress').innerHTML = "Downloading, Please Wait ...";
  40. var clip = $("#clip").val();
  41. var mode = $("#mode").val();
  42. var xhr = new XMLHttpRequest();
  43. xhr.open("GET", clip, false);
  44. xhr.responseType = "arraybuffer";
  45. xhr.send(null);
  46. var arrayBuffer = xhr.response;
  47. if (arrayBuffer) {
  48. var byteArray = new Uint8Array(arrayBuffer);
  49. var array = Array.prototype.slice.apply(byteArray);
  50. Module.FS.createDataFile('/', 'video.264', array, true, false);
  51. } else {
  52. alert('load fail :(');
  53. }
  54. document.getElementById('downloadProgress').innerHTML = "Download Complete, Playing ...";
  55. // Pass canvas and context to the generated code, and do the actual run() here
  56. Module.canvas = document.getElementById('canvas');
  57. if (mode == "none") {
  58. Module.paint = function() {};
  59. } else if (mode == "webgl") {
  60. Module.paint = webGLPaint;
  61. } else {
  62. Module.ctx2D = Module.canvas.getContext('2d');
  63. if (!Module.ctx2D) {
  64. alert('Canvas not available :(');
  65. return;
  66. }
  67. }
  68. console.info("Running: " + clip);
  69. Module.run(['video.264']);
  70. }
  71. var loaded = false;
  72. var playing = false;
  73. function play() {
  74. if (!loaded) {
  75. load();
  76. loaded = true;
  77. }
  78. if (playing == false) {
  79. $('#play').children().first().html("Pause");
  80. playing = true;
  81. Module.play();
  82. } else {
  83. Module['CorrectionsMonitor'].print();
  84. $('#play').children().first().html("Play");
  85. playing = false;
  86. Module.stop();
  87. return;
  88. }
  89. }
  90. var webGLCanvas = null;
  91. var videoFrameCounter = 0;
  92. var windowFrameCounter = 0;
  93. var videoStartTime;
  94. var windowStartTime;
  95. var scoreFrameCount = 1200;
  96. var scoreCalculated = false;
  97. Module.onFrameDecoded = function() {
  98. videoFrameCounter += 1;
  99. windowFrameCounter += 1;
  100. var now = Date.now();
  101. if (!videoStartTime) {
  102. videoStartTime = now;
  103. }
  104. var videoElapsedTime = now - videoStartTime;
  105. if (!windowStartTime) {
  106. windowStartTime = now;
  107. } else if ((now - windowStartTime) > 1000) {
  108. var windowElapsedTime = now - windowStartTime;
  109. var fps = (windowFrameCounter / windowElapsedTime) * 1000;
  110. document.getElementById('fps').innerHTML = fps.toFixed(2);
  111. windowStartTime = now;
  112. windowFrameCounter = 0;
  113. }
  114. if (videoFrameCounter % 10 == 0) {
  115. var fps = (videoFrameCounter / videoElapsedTime) * 1000;
  116. document.getElementById('fpsSinceStart').innerHTML = fps.toFixed(2);
  117. }
  118. if (!scoreCalculated) {
  119. if (videoFrameCounter % 10 == 0) {
  120. document.getElementById('score').innerHTML = "Calculating: " + (scoreFrameCount - videoFrameCounter);
  121. }
  122. if (videoFrameCounter == scoreFrameCount) {
  123. var fps = (videoFrameCounter / videoElapsedTime) * 1000;
  124. document.getElementById('score').innerHTML = fps.toFixed(2);
  125. scoreCalculated = true;
  126. }
  127. }
  128. }
  129. function updateScrubber() {
  130. $("#scrubber").slider('value', _getPosition() * 500);
  131. }
  132. function webGLPaint($luma, $cb, $cr, width, height) {
  133. if (!webGLCanvas) {
  134. webGLCanvas = new YUVWebGLCanvas(Module.canvas, new Size(width, height));
  135. }
  136. var luma = Module.HEAPU8.subarray($luma);
  137. var cb = Module.HEAPU8.subarray($cb);
  138. var cr = Module.HEAPU8.subarray($cr);
  139. webGLCanvas.YTexture.fill(luma);
  140. webGLCanvas.UTexture.fill(cb);
  141. webGLCanvas.VTexture.fill(cr);
  142. webGLCanvas.drawScene();
  143. }
  144. </script>
  145. <div id="doc">
  146. <header>
  147. <h1 id="site-title"><b>Broadway.js (NEW)</b></h1>
  148. <p id="tagline">An H.264 Decoder in Pure JavaScript <a href="broadway.html">(Try Old Codec)</a></p>
  149. </header>
  150. <div>
  151. <div id="setting">
  152. <span>Clip:
  153. <select id="clip" style="margin-left: 10px;">
  154. <option value="mozilla.264">Mozilla</option>
  155. <option value="admiral.264">Admiral</option>
  156. <option value="matrix.264">Matrix SD</option>
  157. <option value="matrix_large.264">Matrix HD</option>
  158. </select>
  159. </span>
  160. </div>
  161. <div id="setting">
  162. <span>Render Mode:
  163. <select id="mode" style="margin-left: 10px;">
  164. <option value="canvas">Canvas</option>
  165. <option value="webgl">Canvas w/ WebGL</option>
  166. <option value="none">None</option>
  167. </select>
  168. </span>
  169. <span style="margin-left: 10px; border: 0px" id="downloadProgress"></span>
  170. </div>
  171. <div id="setting">
  172. <div style="margin-left: 10px; border: 0px; clear: both;" id="downloadProgress"></div>
  173. </div>
  174. <div>
  175. <div id="player" style="background-color: black; float: left;">
  176. <canvas id='canvas' width="640" height="100" style="background-color: #333333;"></canvas>
  177. <div id="controls">
  178. <button id="play">Play</button>
  179. <div id="scrubber"></div>
  180. </div>
  181. </div>
  182. </div>
  183. <!-- Stats -->
  184. <div
  185. style="height: 480px; margin-top: 30px; margin-bottom: 10px; clear: both;">
  186. <table style="margin-top: 10px; width: 300;">
  187. <tr>
  188. <th>FPS</th>
  189. <td><span id='fps' style="color: red;"></span></td>
  190. </tr>
  191. <tr>
  192. <th>Average FPS (All / Steady)</th>
  193. <td><span id='fpsSinceStart' style="color: green;"></span> /
  194. <span id='fpsSinceSteady' style="color: green;"></span></td>
  195. </tr>
  196. <tr>
  197. <th>Elapsed</th>
  198. <td><span id='elapsed'></span></td>
  199. </tr>
  200. <tr>
  201. <th>Score</th>
  202. <td><span id='score' style="color: brown;"></span></td>
  203. </tr>
  204. </table>
  205. </div>
  206. </div>
  207. </body>
  208. </html>