]> id.pley.net Git - movie_parser.git/blobdiff - AtomTester.html
Add new atom types: SampleSize, TrackExtends, OriginalFormat, SchemeType, and SchemeInfo.
[movie_parser.git] / AtomTester.html
index 04199880eaf42f8b2120f540b5b397d14016d519..78587ca5ae7d9660dd4cde017e421e910ddadee1 100644 (file)
@@ -3,31 +3,76 @@
     <title>AtomTester</title>
     <script src=Atom.js></script>
     <script>
     <title>AtomTester</title>
     <script src=Atom.js></script>
     <script>
-        var atoms = [];
+        // Add Blob.prototype.slice if it does not already exist:
+        if (typeof(Blob.prototype.slice) == 'undefined' && typeof(Blob.prototype.webkitSlice) != 'undefined')
+            Blob.prototype.slice = Blob.prototype.webkitSlice;
+
+        var moovAtom;
         function onFileSelect(e) {
             var file = e.target.files[0];
             var reader = new FileReader();
         function onFileSelect(e) {
             var file = e.target.files[0];
             var reader = new FileReader();
-            reader.onload = (function(file) {
-                return function(e) {
-                    var offset = 0;
+            output.innerHTML = '';
+            
+            function checkForAtom(offset) {
+                reader.onload = function(e) {
+                    var atom = new Atom(e.target.result);
+                    if (atom)
+                        readAtom(offset, atom.size);
+                };
+                var subset = file.slice(offset, offset + 16);
+                reader.readAsArrayBuffer(subset);
+            }
+
+            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.innerHTML = '';
-                    while (offset < e.target.result.byteLength) {
-                        var atom = Atom.create(e.target.result, offset);
-                        if (!atom)
-                            break;
-                        atoms.push(atom);
-                        output.appendChild(toDOMNode(atom));
-                        offset += atom.size;
-                    }
+                    output.appendChild(toDOMNode(atom));
+                    if (file.size > offset + length)
+                        checkForAtom(offset + length);
                 };
                 };
-            })(file);
-            reader.readAsArrayBuffer(file);
+                var subset = file.slice(offset, offset + length);
+                reader.readAsArrayBuffer(subset);
+            }
+            
+            checkForAtom(0);
+        }
+        
+        function toDOMRepresentation(object)
+        {
+            if (object instanceof Atom)
+                return toDOMNode(object);
+            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) {
+                    span.appendChild(toDOMRepresentation(object[i]));
+                    if (i + 1 < object.length)
+                        span.appendChild(document.createTextNode(', '));
+                }
+                span.appendChild(document.createTextNode(']'));
+                return span;
+            }
+            else if (typeof(object) == "string")
+                return document.createTextNode('"' + object + '"');
+            else if (object instanceof Date)
+                return document.createTextNode(object.toLocaleString());
+            else
+                return document.createTextNode(object.toString());
         }
         
         function toDOMNode(object)
         {
             var output = document.createElement('dl');
         }
         
         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];
                     continue;
                 var div = document.createElement('div');
                 var dt = document.createElement('dt');
                     continue;
                 var div = document.createElement('div');
                 var dt = document.createElement('dt');
-                dt.innerText = property;
-
+                dt.appendChild(document.createTextNode(property));
                 var dd = document.createElement('dd');
                 var dd = document.createElement('dd');
-                if (value instanceof Atom)
-                    dd.appendChild(toDOMNode(value));
-                else if (value instanceof Array) {
-                    dd.appendChild(toDOMNode(value));
-                }
-                else if (typeof(value) == "string")
-                    dd.innerText = '"' + value + '"';
-                else if (value instanceof Date)
-                    dd.innerText = value.toLocaleString();
-                else
-                    dd.innerText = value;
-
+                dd.appendChild(toDOMRepresentation(value));
                 div.appendChild(dt);
                 div.appendChild(dd);
                 output.appendChild(div);
                 div.appendChild(dt);
                 div.appendChild(dd);
                 output.appendChild(div);
         }
     </script>
     <style>
         }
     </script>
     <style>
-        dl { border: 1px solid black; }
+        dl { border: 1px solid black; padding: 1px; }
         dt, dd { display: inline; }
         dt:after { content:": " }
         dd:after { content:"\A"; white-space:pre; }
         dd dl { margin: 0; vertical-align: top }
         dt, dd { display: inline; }
         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; }
+
+        dt, dd { display: inline-block; min-width: 8em; }
+        dd { margin-left: 1em; }
+        .description { text-align: center; font-weight: bold; }
         
         /* make the output display as a table */
         
         /* make the output display as a table */
+        /*
         dl { display: table; }
         dl div { display: table-row; }
         dt, dd { display: table-cell; }
         dl { display: table; }
         dl div { display: table-row; }
         dt, dd { display: table-cell; }
+        */
     </style>
 </head>
 <body id="atomtester" onload="setup()">
     </style>
 </head>
 <body id="atomtester" onload="setup()">