ae126725 by Simeon Bateman Committed by David LaPalomento

Added the sidx parsing and test file from mp4 spec

1 parent e5b1ef5b
......@@ -704,6 +704,54 @@ test('can parse a trun', function() {
}]);
});
test('can parse a sidx', function(){
var data = box('sidx',
0x00, // version
0x00, 0x00, 0x00, // flags
0x00, 0x00, 0x00, 0x02, // reference_ID
0x00, 0x00, 0x00, 0x01, // timescale
0x01, 0x02, 0x03, 0x04, // earliest_presentation_time
0x00, 0x00, 0x00, 0x00, // first_offset
0x00, 0x00, // reserved
0x00, 0x02, // reference_count
// first reference
0x80, 0x00, 0x00, 0x07, // reference_type(1) + referenced_size(31)
0x00, 0x00, 0x00, 0x08, // subsegment_duration
0x80, 0x00, 0x00, 0x09, // starts_with_SAP(1) + SAP_type(3) + SAP_delta_time(28)
// second reference
0x00, 0x00, 0x00, 0x03, // reference_type(1) + referenced_size(31)
0x00, 0x00, 0x00, 0x04, // subsegment_duration
0x10, 0x00, 0x00, 0x05 // starts_with_SAP(1) + SAP_type(3) + SAP_delta_time(28)
);
deepEqual(videojs.inspectMp4(new Uint8Array(data)),
[{
type: 'sidx',
version: 0,
flags: new Uint8Array([0, 0x00, 0x00]),
timescale: 1,
earliestPresentationTime: 0x01020304,
firstOffset: 0,
referenceId: 2,
size: 56,
references: [{
referenceType: 1,
referencedSize: 7,
subsegmentDuration: 8,
startsWithSap: true,
sapType: 0,
sapDeltaTime: 9
},{
referenceType: 0,
referencedSize: 3,
subsegmentDuration: 4,
startsWithSap: false,
sapType: 1,
sapDeltaTime: 5
}]
}]);
});
test('can parse a series of boxes', function() {
var ftyp = [
0x00, 0x00, 0x00, 0x18 // size 4 * 6 = 24
......
......@@ -266,6 +266,33 @@ var
initialDelay: view.getUint32(8)
};
},
sidx: function(data) {
var view = new DataView(data.buffer, data.byteOffset, data.byteLength),
result = {
version: data[0],
flags: new Uint8Array(data.subarray(1, 4)),
references: [],
referenceId: view.getUint32(4),
timescale: view.getUint32(8),
earliestPresentationTime: view.getUint32(12),
firstOffset: view.getUint32(16)
},
referenceCount = view.getUint16(22),
i;
for (i = 24; referenceCount; i += 12, referenceCount-- ) {
result.references.push({
referenceType: (data[i] & 0x80) >>> 7,
referencedSize: view.getUint32(i) & 0x7FFFFFFF,
subsegmentDuration: view.getUint32(i + 4),
startsWithSap: !!(data[i + 8] & 0x80),
sapType: (data[i + 8] & 0x70) >>> 4,
sapDeltaTime: view.getUint32(i + 8) & 0x0FFFFFFF
});
}
return result;
},
stbl: function(data) {
return {
boxes: videojs.inspectMp4(data)
......