shithub: h264bsd

Download patch

ref: b56a0e8ba7ba51fa0cda00ced01711159cf0c686
parent: 7ff43ca6eef03fffdb38694fb9542c7723c8da27
author: Sam Leitch <[email protected]>
date: Wed Mar 12 13:05:04 EDT 2014

Moved js test to js folder. Made it loop forever.

--- a/README.md
+++ b/README.md
@@ -9,6 +9,7 @@
 ## Directories
 
 * *src* The modified source.
+* *test* Contains test data available for all platforms.
 * *win* Visual Studio project files for building.
 * *js* JavaScript version of the library created using [emscripten](http://emscripten.org/).
 * *flex* ActionScript version of the library built using [CrossBridge](http://adobe-flash.github.io/crossbridge/).
--- /dev/null
+++ b/js/test.html
@@ -1,0 +1,97 @@
+<!doctype html>
+  <head>
+    <meta charset="utf-8">
+    <meta http-equiv="X-UA-Compatible" content="IE=edge">
+    <title>h.264bsd test</title>
+</head>
+<body>
+    <input type="file" id="file" name="file" />
+    <span id="fps_display"></span>
+    <br/>
+
+    <!--This is where we will display decoded frames-->
+    <canvas id="canvas" width="640" height="480" style="border:solid;"></canvas>
+
+    <script src="../js/h264bsd_asm.js"></script>
+    <script src="../js/h264bsd_decoder.js"></script>
+    <script src="../js/h264bsd_canvas.js"></script>
+       
+    <!--<script src="../js/h264bsd.min.js"></script>-->
+
+    <script type="text/javascript">         
+        var canvas = document.getElementById('canvas');             
+
+        var pictureCount = 0;
+        var lastPictureCount = 0;
+
+        // Create the decoder and canvas
+        var d = new H264bsdDecoder(Module);
+        var c = new H264bsdCanvas(canvas);
+        console.log('Created decoder and canvas');
+
+        // Render for each picture
+        d.onPictureReady = function () {
+            c.drawNextOutputPicture(d);
+            ++pictureCount;
+        }
+
+        // Render for each picture
+        d.onHeadersReady = function () {
+            canvas.width = d.outputPictureWidth();
+            canvas.height = d.outputPictureHeight();
+        }
+
+        // Loop with setTimeout delay to allow UI to update.
+        var loopBody = function() {
+            var retCode = d.decode();
+            //console.log('Decoded data. Return code: ', retCode, ' bytes remaining: ', d.inputBytesRemaining());
+
+            switch(retCode) {
+                case H264bsdDecoder.NO_INPUT:
+                    //console.log('Decoding complete');
+                    //d.release();
+                    d.queueInput(buf);
+                    setTimeout(loopBody, 0);
+                    break;
+                default:
+                    setTimeout(loopBody, 0);
+                    break;
+            }
+        }
+
+        function updateFpsCount() {
+            var picturesSinceLastUpdate = pictureCount - lastPictureCount;
+            var fpsDisplay = document.getElementById('fps_display');
+
+            fps_display.innerHTML = 'FPS: ' + picturesSinceLastUpdate;
+
+            lastPictureCount = pictureCount;
+        }
+
+        var buf = null;
+
+        // Use the FileReader to get the bytes into the decoder
+        function handleFileSelect(evt) {
+            var f = evt.target.files[0]; // FileList object
+            
+            var reader = new FileReader();
+
+            // Closure to capture the file information.
+            reader.onload = function(e) {
+                console.log('Queueing file data...');
+                buf = e.target.result;
+                d.queueInput(buf);
+                setInterval(updateFpsCount, 1000);
+
+                console.log('Starting encode loop');
+                loopBody();
+            };
+
+            // Read in the image file as a data URL.
+            reader.readAsArrayBuffer(f);
+        }
+
+        document.getElementById('file').addEventListener('change', handleFileSelect, false);
+    </script>
+</body>
+</html>
--- a/test/h264bsd.html
+++ /dev/null
@@ -1,76 +1,0 @@
-<!doctype html>
-  <head>
-    <meta charset="utf-8">
-    <meta http-equiv="X-UA-Compatible" content="IE=edge">
-    <title>h.264bsd test</title>
-</head>
-<body>
-    <input type="file" id="file" name="file" /><br/>
-
-    <!--This is where we will display decoded frames-->
-    <canvas id="canvas" width="640" height="480" style="border:solid;"></canvas>
-
-    <script src="../js/h264bsd_asm.js"></script>
-    <script src="../js/h264bsd_decoder.js"></script>
-    <script src="../js/h264bsd_canvas.js"></script>
-       
-    <!--<script src="../js/h264bsd.min.js"></script>-->
-
-    <script type="text/javascript">         
-        var canvas = document.getElementById('canvas');             
-
-        // Create the decoder and canvas
-        var d = new H264bsdDecoder(Module);
-        var c = new H264bsdCanvas(canvas);
-        console.log('Created decoder and canvas');
-
-        // Render for each picture
-        d.onPictureReady = function () {
-            console.log('Drawing next output picture...');
-            c.drawNextOutputPicture(d);
-        }
-
-        // Render for each picture
-        d.onHeadersReady = function () {
-            canvas.width = d.outputPictureWidth();
-            canvas.height = d.outputPictureHeight();
-        }
-
-        // Loop with setTimeout delay to allow UI to update.
-        var loopBody = function() {
-            var retCode = d.decode();
-            console.log('Decoded data. Return code: ', retCode, ' bytes remaining: ', d.inputBytesRemaining());
-
-            switch(retCode) {
-                case H264bsdDecoder.NO_INPUT:
-                    console.log('Decoding complete');
-                    d.release();
-                    break;
-                default:
-                    setTimeout(loopBody, 0);
-                    break;
-            }
-        }
-
-        // Use the FileReader to get the bytes into the decoder
-        function handleFileSelect(evt) {
-            var f = evt.target.files[0]; // FileList object
-            
-            var reader = new FileReader();
-
-            // Closure to capture the file information.
-            reader.onload = function(e) {
-                console.log('Queueing file data...');
-                var buf = e.target.result;
-                d.queueInput(buf);
-                loopBody();
-            };
-
-            // Read in the image file as a data URL.
-            reader.readAsArrayBuffer(f);
-        }
-
-        document.getElementById('file').addEventListener('change', handleFileSelect, false);
-    </script>
-</body>
-</html>