Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

audio sample entries ver1. improved hdlr. #77

Open
wants to merge 11 commits into
base: master
Choose a base branch
from
6 changes: 5 additions & 1 deletion src/DataStream.js
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,11 @@ Object.defineProperty(DataStream.prototype, 'buffer',
},
set: function(v) {
this._buffer = v;
this._dataView = new DataView(this._buffer, this._byteOffset);
if (this._buffer.byteLength === 0 && !this._byteOffset) {
this._dataView = new DataView(this._buffer);
} else {
this._dataView = new DataView(this._buffer, this._byteOffset);
}
this._byteLength = this._buffer.byteLength;
} });

Expand Down
4 changes: 4 additions & 0 deletions src/box-parse.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,10 @@ BoxParser.parseOneBox = function(stream, headerOnly, parentSize) {
return { code: BoxParser.ERR_NOT_ENOUGH_DATA };
}
var size = stream.readUint32();
if (size === 0) {
Log.debug("BoxParser", "Found terminator box at " + start);
return { code: BoxParser.OK };
}
var type = stream.readString(4);
Log.debug("BoxParser", "Found box of type "+type+" and size "+size+" at position "+start);
hdr_size = 8;
Expand Down
1 change: 1 addition & 0 deletions src/box.js
Original file line number Diff line number Diff line change
Expand Up @@ -192,6 +192,7 @@ BoxParser.initialize();
BoxParser.TKHD_FLAG_ENABLED = 0x000001;
BoxParser.TKHD_FLAG_IN_MOVIE = 0x000002;
BoxParser.TKHD_FLAG_IN_PREVIEW = 0x000004;
BoxParser.TKHD_FLAG_IN_POSTER = 0x000008;

BoxParser.TFHD_FLAG_BASE_DATA_OFFSET = 0x01;
BoxParser.TFHD_FLAG_SAMPLE_DESC = 0x02;
Expand Down
2 changes: 1 addition & 1 deletion src/isofile-item-processing.js
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,7 @@ ISOFile.prototype.getMetaHandler = function() {
if (!this.meta) {
return null;
} else {
return this.meta.hdlr.handler;
return this.meta.hdlr.componentSubType;
}
}

Expand Down
16 changes: 9 additions & 7 deletions src/parsing/hdlr.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
BoxParser.hdlrBox.prototype.parse = function(stream) {
this.parseFullHeader(stream);
if (this.version === 0) {
stream.readUint32();
this.handler = stream.readString(4);
this.componentType = stream.readString(4);
this.componentSubType = stream.readString(4);
stream.readUint32Array(3);
this.name = stream.readString(this.size-this.hdr_size-20);
if (this.name[this.name.length-1]==='\0') {
this.name = this.name.slice(0,-1);
}
}
this.name = stream.readCString(this.size-this.hdr_size-20);
if (this.name[this.name.length-1]==='\0') {
this.name = this.name.slice(0,-1);
}
} else {
this.data = stream.readUint8Array(this.size-this.hdr_size);
}
}

33 changes: 23 additions & 10 deletions src/parsing/sampleentries/sampleentry.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,13 @@ BoxParser.SampleEntry.prototype.parseFooter = function(stream) {
ret = BoxParser.parseOneBox(stream, false, this.size - (stream.getPosition() - this.start));
if (ret.code === BoxParser.OK) {
box = ret.box;
this.boxes.push(box);
this[box.type] = box;
if (box) {
this.boxes.push(box);
this[box.type] = box;
} else {
// encountered terminator box
stream.position = this.start + this.size;
}
} else {
return;
}
Expand All @@ -51,13 +56,21 @@ BoxParser.VisualSampleEntry.prototype.parse = function(stream) {
}

BoxParser.AudioSampleEntry.prototype.parse = function(stream) {
this.parseHeader(stream);
stream.readUint32Array(2);
this.channel_count = stream.readUint16();
this.samplesize = stream.readUint16();
stream.readUint16();
stream.readUint16();
this.samplerate = (stream.readUint32()/(1<<16));
this.parseFooter(stream);
this.parseHeader(stream);
this.version = stream.readUint16();
this.revision = stream.readUint16();
this.vendor = stream.readUint32();
this.channel_count = stream.readUint16();
this.samplesize = stream.readUint16();
this.compressionId = stream.readInt16();
this.packetSize = stream.readUint16();
this.samplerate = (stream.readUint32() / (1 << 16));
if (this.version == 1) {
this.samplesPerPacket = stream.readUint32();
this.bytesPerPacket = stream.readUint32();
this.bytesPerFrame = stream.readUint32();
this.bytesPerSample = stream.readUint32();
}
this.parseFooter(stream);
}

4 changes: 2 additions & 2 deletions src/writing/hdlr.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ BoxParser.hdlrBox.prototype.write = function(stream) {
this.version = 0;
this.flags = 0;
this.writeHeader(stream);
stream.writeUint32(0);
stream.writeString(this.handler, null, 4);
stream.writeString(this.componentType, null, 4);
stream.writeString(this.componentSubType, null, 4);
stream.writeUint32(0);
stream.writeUint32(0);
stream.writeUint32(0);
Expand Down
31 changes: 23 additions & 8 deletions src/writing/sampleentry.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,13 +49,28 @@ BoxParser.VisualSampleEntry.prototype.write = function(stream) {

BoxParser.AudioSampleEntry.prototype.write = function(stream) {
this.writeHeader(stream);
this.size += 2*4+3*4;
stream.writeUint32(0);
stream.writeUint32(0);
stream.writeUint16(this.channel_count);
stream.writeUint16(this.samplesize);
stream.writeUint16(0);
stream.writeUint16(0);
stream.writeUint32(this.samplerate<<16);
this.size += 2+2+4;
stream.writeUint16(this.version);
stream.writeUint16(this.revision);
stream.writeUint32(this.vendor);
if (!this.version) { // version == 0
this.size += 2*4+4;
stream.writeUint16(this.channel_count);
stream.writeUint16(this.samplesize);
stream.writeUint16(0);
stream.writeUint16(0);
stream.writeUint32(this.samplerate<<16);
} else if (this.version == 1) {
this.size += 2*4+4*5;
stream.writeUint16(this.channel_count);
stream.writeUint16(this.samplesize);
stream.writeInt16(this.compressionId);
stream.writeUint16(this.packetSize);
stream.writeUint32(this.samplerate<<16);
stream.writeUint32(this.samplesPerPacket);
stream.writeUint32(this.bytesPerPacket);
stream.writeUint32(this.bytesPerFrame);
stream.writeUint32(this.bytesPerSample);
}
this.writeFooter(stream);
}
1 change: 0 additions & 1 deletion src/writing/tfdt.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
BoxParser.tfdtBox.prototype.write = function(stream) {
this.version = 0;
this.flags = 0;
this.size = 4;
if (this.version === 1) {
Expand Down
15 changes: 14 additions & 1 deletion test/qunit-box-data.js
Original file line number Diff line number Diff line change
Expand Up @@ -127,5 +127,18 @@ var boxtests = [
event_duration: 1,
id: 1
}
}
},
{
url: boxTestBaseUrl + "/mp4/box/sidx.mp4",
rangeStart: 972,
rangeSize: 45,
boxname: "hdlr",
data: {
type: "hdlr",
size: 45,
componentType: "\u0000\u0000\u0000\u0000",
componentSubType: "soun",
name: "SoundHandler"
}
}
];