+
+ if (this.size == 1) {
+ this.is64bit = true;
+ if (buffer.byteLength - offset < 8)
+ return false;
+
+ // NOTE: JavaScript can only represent up to 2^53 as precise integer.
+ // This calculation may result in incorrect values.
+ var view = new DataView(buffer, offset, 8);
+ offset += 8;
+ var upper = view.getUint32(0);
+ var lower = view.getUint32(4);
+ this.size = (upper << 32) + lower;
+ }
+
+ return true;
+};
+
+Atom.prototype.toDOMNode = function()
+{
+ var output = document.createElement('dl');
+
+ for (property in this) {
+ var value = this[property];
+ if (typeof(value) == 'function')
+ continue;
+ var div = document.createElement('div');
+ var dt = document.createElement('dt');
+ dt.innerText = property;
+
+ var dd = document.createElement('dd');
+ if (value instanceof Atom)
+ dd.appendChild(value.toDOMNode());
+ else if (value instanceof Array) {
+ var ol = document.createElement('ol');
+ for (index in value) {
+ var li = document.createElement('li');
+ li.value = index;
+ if (value[index] instanceof Atom)
+ li.appendChild(value[index].toDOMNode())
+ else
+ li.innerText = value[index];
+ ol.appendChild(li);
+ }
+ dd.appendChild(ol);
+ }
+ else if (typeof(value) == "string")
+ dd.innerText = '"' + value + '"';
+ else
+ dd.innerText = value;
+
+ div.appendChild(dt);
+ div.appendChild(dd);
+ output.appendChild(div);
+ }
+ return output;
+}
+
+var FtypAtom = function(buffer, offset) {
+ this.minimumSize = 16;
+ this.brand = "";
+ this.version = 0;
+ this.compatible_brands = [];
+
+ return Object.getPrototypeOf(FtypAtom.prototype).constructor.call(this, buffer, offset)
+}
+
+FtypAtom.prototype = Object.create(Atom.prototype);
+
+FtypAtom.prototype.parse = function(buffer, offset) {
+ if (!Atom.prototype.parse.call(this, buffer, offset))
+ return false;
+
+ var begin = offset;
+ var end = begin + this.size;
+ offset += this.is64bit ? 16 : 8;
+
+ var brandArrayView = new Uint8Array(buffer, offset, 4);
+ offset += 4;
+ this.brand = String.fromCharCode.apply(null, brandArrayView);
+
+ var view = new DataView(buffer, offset, 4);
+ offset += 4;
+ this.version = view.getUint32(0);
+
+ while (offset <= end - 4) {
+ var brandArrayView = new Uint8Array(buffer, offset, 4);
+ offset += 4;
+ this.compatible_brands.push(String.fromCharCode.apply(null, brandArrayView));
+ }
+
+ return true;
+}
+
+var ContainerAtom = function(buffer, offset) {
+ this.childAtoms = [];
+
+ return Object.getPrototypeOf(ContainerAtom.prototype).constructor.call(this, buffer, offset);
+}
+
+ContainerAtom.prototype = Object.create(Atom.prototype);
+
+ContainerAtom.prototype.parse = function(buffer, offset) {
+ if (!Atom.prototype.parse.call(this, buffer, offset))
+ return false;
+
+ var begin = offset;
+ var end = begin + this.size;
+ offset += this.is64bit ? 16 : 8;
+
+ while (offset < end) {
+ var childAtom = Atom.create(buffer, offset);
+ if (!childAtom)
+ break;
+ offset += childAtom.size;
+ this.childAtoms.push(childAtom);
+ }
+}
+
+var MvhdAtom = function(buffer, offset) {
+ this.version = 0;
+ this.creationTime = 0;
+ this.modificationTime = 0;
+ this.timeScale = 0;
+ this.duration = 0;
+ this.preferredRate = 0.0;
+ this.preferredVolume = 0.0;
+ this.movieMatrix = [[]];
+ this.previewTime = 0;
+ this.posterTime = 0;
+ this.selectionTime = 0;
+ this.selectionDuration = 0;
+ this.nextTrackID = 0;
+
+ return Object.getPrototypeOf(MvhdAtom.prototype).constructor.call(this, buffer, offset);
+}
+
+MvhdAtom.prototype = Object.create(Atom.prototype);
+
+MvhdAtom.prototype.parse = function(buffer, offset) {
+ if (!Atom.prototype.parse.call(this, buffer, offset))
+ return false;
+
+ offset += this.is64bit ? 16 : 8;
+
+ var headerOffset = 0;
+ var view = new DataView(buffer, offset);
+
+ this.version = view.getUint8(headerOffset);
+ headerOffset += 4;
+
+ this.creationTime = view.getUint32(headerOffset);
+ headerOffset += 4;
+
+ this.modificationTime = view.getUint32(headerOffset);
+ headerOffset += 4;
+
+ this.timeScale = view.getUint32(headerOffset);
+ headerOffset += 4;