}
}
+Atom.prototype.super = function(object) {
+ return Object.getPrototypeOf(object.prototype);
+}
+
Atom.prototype.setDefaults = function() {
Object.defineProperty(this, "is64bit", {
value: false,
};
var FileTypeAtom = function(buffer, offset) {
- Object.getPrototypeOf(FileTypeAtom.prototype).constructor.call(this, buffer, offset);
+ this.super(FileTypeAtom).constructor.call(this, buffer, offset);
}
FileTypeAtom.prototype = Object.create(Atom.prototype);
FileTypeAtom.prototype.setDefaults = function() {
- Object.getPrototypeOf(FileTypeAtom.prototype).setDefaults.call(this);
+ this.super(FileTypeAtom).setDefaults.call(this);
this.minimumSize = 16;
this.brand = "";
this.version = 0;
}
FileTypeAtom.prototype.parse = function(buffer, offset) {
- var headerOffset = Object.getPrototypeOf(FileTypeAtom.prototype).parse.call(this, buffer, offset);
+ var headerOffset = this.super(FileTypeAtom).parse.call(this, buffer, offset);
if (!headerOffset)
return 0;
}
var ContainerAtom = function(buffer, offset) {
- Object.getPrototypeOf(ContainerAtom.prototype).constructor.call(this, buffer, offset);
+ this.super(ContainerAtom).constructor.call(this, buffer, offset);
}
ContainerAtom.prototype = Object.create(Atom.prototype);
ContainerAtom.prototype.setDefaults = function() {
- Object.getPrototypeOf(ContainerAtom.prototype).setDefaults.call(this);
+ this.super(ContainerAtom).setDefaults.call(this);
this.childAtoms = [];
}
ContainerAtom.prototype.parse = function(buffer, offset) {
- var headerOffset = Object.getPrototypeOf(ContainerAtom.prototype).parse.call(this, buffer, offset);
+ var headerOffset = this.super(ContainerAtom).parse.call(this, buffer, offset);
if (!headerOffset)
return 0;
}
var VersionFlagsAtom = function(buffer, offset) {
- Object.getPrototypeOf(VersionFlagsAtom.prototype).constructor.call(this, buffer, offset);
+ this.super(VersionFlagsAtom).constructor.call(this, buffer, offset);
}
VersionFlagsAtom.prototype = Object.create(Atom.prototype);
VersionFlagsAtom.prototype.setDefaults = function() {
- Object.getPrototypeOf(VersionFlagsAtom.prototype).setDefaults.call(this);
+ this.super(VersionFlagsAtom).setDefaults.call(this);
this.version = 0;
this.flags = 0;
}
VersionFlagsAtom.prototype.parse = function(buffer, offset) {
- var headerOffset = Object.getPrototypeOf(VersionFlagsAtom.prototype).parse.call(this, buffer, offset);
+ var headerOffset = this.super(VersionFlagsAtom).parse.call(this, buffer, offset);
if (!headerOffset)
return 0;
}
var MovieHeaderAtom = function(buffer, offset) {
- return Object.getPrototypeOf(MovieHeaderAtom.prototype).constructor.call(this, buffer, offset);
+ return this.super(MovieHeaderAtom).constructor.call(this, buffer, offset);
}
MovieHeaderAtom.prototype = Object.create(VersionFlagsAtom.prototype);
MovieHeaderAtom.prototype.setDefaults = function() {
- Object.getPrototypeOf(MovieHeaderAtom.prototype).setDefaults.call(this);
+ this.super(MovieHeaderAtom).setDefaults.call(this);
this.creationTime = 0;
this.modificationTime = 0;
this.timeScale = 0;
}
MovieHeaderAtom.prototype.parse = function(buffer, offset) {
- var headerOffset = Object.getPrototypeOf(MovieHeaderAtom.prototype).parse.call(this, buffer, offset);
+ var headerOffset = this.super(MovieHeaderAtom).parse.call(this, buffer, offset);
if (!headerOffset)
return 0;
}
var TrackHeaderAtom = function(buffer, offset) {
- Object.getPrototypeOf(TrackHeaderAtom.prototype).constructor.call(this, buffer, offset);
+ this.super(TrackHeaderAtom).constructor.call(this, buffer, offset);
}
TrackHeaderAtom.prototype = Object.create(Atom.prototype);
TrackHeaderAtom.prototype.setDefaults = function() {
- Object.getPrototypeOf(TrackHeaderAtom.prototype).setDefaults.call(this);
+ this.super(TrackHeaderAtom).setDefaults.call(this);
this.creationTime = 0;
this.modificationTime = 0;
}
TrackHeaderAtom.prototype.parse = function(buffer, offset) {
- var headerOffset = Object.getPrototypeOf(TrackHeaderAtom.prototype).parse.call(this, buffer, offset);
+ var headerOffset = this.super(TrackHeaderAtom).parse.call(this, buffer, offset);
if (!headerOffset)
return 0;
}
var MediaHeaderAtom = function(buffer, offset) {
- Object.getPrototypeOf(MediaHeaderAtom.prototype).constructor.call(this, buffer, offset);
+ this.super(MediaHeaderAtom).constructor.call(this, buffer, offset);
}
MediaHeaderAtom.prototype = Object.create(VersionFlagsAtom.prototype);
MediaHeaderAtom.prototype.setDefaults = function() {
- Object.getPrototypeOf(MediaHeaderAtom.prototype).setDefaults.call(this);
+ this.super(MediaHeaderAtom).setDefaults.call(this);
this.creationTime = 0;
this.modificationTime = 0;
}
MediaHeaderAtom.prototype.parse = function(buffer, offset) {
- var headerOffset = Object.getPrototypeOf(MediaHeaderAtom.prototype).parse.call(this, buffer, offset);
+ var headerOffset = this.super(MediaHeaderAtom).parse.call(this, buffer, offset);
if (!headerOffset)
return 0;
}
var SyncSampleAtom = function(buffer, offset) {
- Object.getPrototypeOf(SyncSampleAtom.prototype).constructor.call(this, buffer, offset);
+ this.super(SyncSampleAtom).constructor.call(this, buffer, offset);
}
SyncSampleAtom.prototype = Object.create(Atom.prototype);
SyncSampleAtom.prototype.setDefaults = function() {
- Object.getPrototypeOf(SyncSampleAtom.prototype).setDefaults.call(this);
+ this.super(SyncSampleAtom).setDefaults.call(this);
this.version = 0;
this.flags = 0;
}
SyncSampleAtom.prototype.parse = function(buffer, offset) {
- var headerOffset = Object.getPrototypeOf(SyncSampleAtom.prototype).parse.call(this, buffer, offset);
+ var headerOffset = this.super(SyncSampleAtom).parse.call(this, buffer, offset);
if (!headerOffset)
return 0;
}
var TimeToSampleAtom = function(buffer, offset) {
- Object.getPrototypeOf(TimeToSampleAtom.prototype).constructor.call(this, buffer, offset);
+ this.super(TimeToSampleAtom).constructor.call(this, buffer, offset);
}
TimeToSampleAtom.prototype = Object.create(VersionFlagsAtom.prototype);
TimeToSampleAtom.prototype.setDefaults = function() {
- Object.getPrototypeOf(TimeToSampleAtom.prototype).setDefaults.call(this);
+ this.super(TimeToSampleAtom).setDefaults.call(this);
this.entries = 0;
}
TimeToSampleAtom.prototype.parse = function(buffer, offset) {
- var headerOffset = Object.getPrototypeOf(TimeToSampleAtom.prototype).parse.call(this, buffer, offset);
+ var headerOffset = this.super(TimeToSampleAtom).parse.call(this, buffer, offset);
if (!headerOffset)
return 0;
<title>AtomTester</title>
<script src=Atom.js></script>
<script>
- var atoms = [];
+ var moovAtom;
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 checkForMoovAtom(offset) {
+ 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 subset = file.webkitSlice(offset, offset + 16);
+ reader.readAsArrayBuffer(subset);
+ };
+
+ function readMoovAtom(offset, length) {
+ reader.onload = function(e) {
+ moovAtom = Atom.create(e.target.result);
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(moovAtom));
};
- })(file);
- reader.readAsArrayBuffer(file);
+ var subset = file.webkitSlice(offset, offset + length);
+ reader.readAsArrayBuffer(subset);
+ };
+
+ checkForMoovAtom(0);
+ }
+
+ function toDOMRepresentation(object)
+ {
+ if (object instanceof Atom)
+ return toDOMNode(object);
+ else if (object instanceof Array) {
+ 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 div = document.createElement('div');
var dt = document.createElement('dt');
dt.innerText = property;
-
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);
}
</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 }
+ dd span { display: inline-block; vertical-align: top; }
+
+ dt, dd { display: inline-block; min-width: 8em; }
+ dd { margin-left: 1em; }
/* make the output display as a table */
+ /*
dl { display: table; }
dl div { display: table-row; }
dt, dd { display: table-cell; }
+ */
</style>
</head>
<body id="atomtester" onload="setup()">