]> 105106.c2e0p.group Git - movie_parser.git/blobdiff - AtomTester.html
Upload Dropbox.com versions of everything
[movie_parser.git] / AtomTester.html
old mode 100644 (file)
new mode 100755 (executable)
index 2617264..1ff5f4e
             var reader = new FileReader();
             output.innerHTML = '';
             
             var reader = new FileReader();
             output.innerHTML = '';
             
-            function checkForMoovAtom(offset) {
+            function checkForAtom(offset) {
                 reader.onload = function(e) {
                 reader.onload = function(e) {
-                    var result = e.target.result;
-                    var basicAtom = new Atom(result);
-                    if (!basicAtom)
-                        return;
-                    else if (basicAtom.type == 'moov') 
-                        readMoovAtom(offset, basicAtom.size);
-                    else
-                        checkForMoovAtom(offset + basicAtom.size);
+                    var atom = new Atom();
+                    if (atom) {
+                        atom.parse(e.target.result, 0);
+                        readAtom(offset, atom.size);
+                    }
                 };
                 };
-                var subset = file.slice(offset, offset + 16);
+                var subset = file.slice(offset, offset + 36);
                 reader.readAsArrayBuffer(subset);
                 reader.readAsArrayBuffer(subset);
-            };
-            
-            function readMoovAtom(offset, length) {
-                reader.onload = function(e) { 
-                    moovAtom = Atom.create(e.target.result);
+            }
+
+            function readAtom(offset, length) {
+                reader.onload = function(e) {
+                    atom = Atom.create(e.target.result);
+                    if (!atom)
+                        return;
                     var output = document.getElementById('output');
                     var output = document.getElementById('output');
-                    output.appendChild(toDOMNode(moovAtom));
+                    output.appendChild(toDOMNode(atom));
+                    if (file.size > offset + length)
+                        checkForAtom(offset + length);
                 };
                 var subset = file.slice(offset, offset + length);
                 reader.readAsArrayBuffer(subset);
                 };
                 var subset = file.slice(offset, offset + length);
                 reader.readAsArrayBuffer(subset);
-            };
+            }
             
             
-            checkForMoovAtom(0);
+            checkForAtom(0);
         }
         }
-        
         function toDOMRepresentation(object)
         {
             if (object instanceof Atom)
                 return toDOMNode(object);
         function toDOMRepresentation(object)
         {
             if (object instanceof Atom)
                 return toDOMNode(object);
-            else if (object instanceof Array) {
+            else if (object instanceof Array || object instanceof Uint32Array)  {
                 var span = document.createElement('span');
                 span.appendChild(document.createTextNode('['));
                 for (var i = 0; i < object.length; ++i) {
                 var span = document.createElement('span');
                 span.appendChild(document.createTextNode('['));
                 for (var i = 0; i < object.length; ++i) {
                 return document.createTextNode('"' + object + '"');
             else if (object instanceof Date)
                 return document.createTextNode(object.toLocaleString());
                 return document.createTextNode('"' + object + '"');
             else if (object instanceof Date)
                 return document.createTextNode(object.toLocaleString());
-            else
+            else if (object instanceof Uint8Array) {
+                return Uint8ArrayNode(object);
+            } else if (object instanceof Object)
+                return toDOMNode(object);
+            else if (object === null)
+                               return document.createTextNode('[null]');
+                       else
                 return document.createTextNode(object.toString());
         }
         
         function toDOMNode(object)
         {
             var output = document.createElement('dl');
                 return document.createTextNode(object.toString());
         }
         
         function toDOMNode(object)
         {
             var output = document.createElement('dl');
+            
+            if (typeof(object.description) == 'string') {
+                var div = document.createElement('div');
+                div.classList.add('description');
+                div.appendChild(document.createTextNode(object.description));
+                output.appendChild(div);
+            }
 
             for (property in object) {
                 var value = object[property];
 
             for (property in object) {
                 var value = object[property];
@@ -74,7 +87,7 @@
                     continue;
                 var div = document.createElement('div');
                 var dt = document.createElement('dt');
                     continue;
                 var div = document.createElement('div');
                 var dt = document.createElement('dt');
-                dt.appendChild(document.createTextNode(property));
+                dt.appendChild(document.createTextNode(property + ': '));
                 var dd = document.createElement('dd');
                 dd.appendChild(toDOMRepresentation(value));
                 div.appendChild(dt);
                 var dd = document.createElement('dd');
                 dd.appendChild(toDOMRepresentation(value));
                 div.appendChild(dt);
             }
             return output;
         }
             }
             return output;
         }
+
+        function Uint8ArrayNode(array)
+        {
+            var table = document.createElement('table');
+            var width = 16;
+            for (var offset = 0; offset <= array.length; offset += width) {
+                var tr = document.createElement('tr');
+                table.appendChild(tr);
+
+                var th = document.createElement('th');
+                tr.appendChild(th);
+                th.innerText = ('0000000' + offset.toString(16)).substr(-8) + ':';
+
+                for (var column = 0; column < width && offset + column < array.length; column += 2) {
+                    var td = document.createElement('td');
+                    tr.appendChild(td);
+                    td.innerText = ('00' + array[offset + column].toString(16)).substr(-2);
+                    if (offset + column + 1 < array.length)
+                        td.innerText += ('00' + array[offset + column + 1].toString(16)).substr(-2);
+                }
+            }
+            return table;
+        }
         
         function setup() {
             document.getElementById('file').addEventListener('change', onFileSelect, false);
         
         function setup() {
             document.getElementById('file').addEventListener('change', onFileSelect, false);
     <style>
         dl { border: 1px solid black; padding: 1px; }
         dt, dd { display: inline; }
     <style>
         dl { border: 1px solid black; padding: 1px; }
         dt, dd { display: inline; }
-        dt:after { content:": " }
+        /*dt:after { content:": " }*/
         dd:after { content:"\A"; white-space:pre; }
         dd dl { margin: 0; vertical-align: top }
         dd span { display: inline-block; vertical-align: top; }
 
         dd:after { content:"\A"; white-space:pre; }
         dd dl { margin: 0; vertical-align: top }
         dd span { display: inline-block; vertical-align: top; }
 
-        dt, dd { display: inline-block; min-width: 8em; }
+        dt, dd { display: inline-block; min-width: 14em; }
         dd { margin-left: 1em; }
         dd { margin-left: 1em; }
+        dd th { font-weight: normal; text-align: right; }
+        .description { text-align: center; font-weight: bold; }
         
         /* make the output display as a table */
         /*
         
         /* make the output display as a table */
         /*