688c83bc by David LaPalomento

Add trun parsing to the inspector

Parse out sample metadata stored in a track run box.
1 parent ef4460ad
......@@ -669,6 +669,41 @@ test('can parse a moof', function() {
}]);
});
test('can parse a trun', function() {
var data = box('trun',
0x00, // version
0x00, 0x0b, 0x05, // flags
0x00, 0x00, 0x00, 0x02, // sample_count
0x00, 0x00, 0x00, 0x01, // data_offset
0x01, 0x02, 0x03, 0x04, // first_sample_flags
0x00, 0x00, 0x00, 0x09, // sample_duration
0x00, 0x00, 0x00, 0xff, // sample_size
0x00, 0x00, 0x00, 0x00, // sample_composition_time_offset
0x00, 0x00, 0x00, 0x08, // sample_duration
0x00, 0x00, 0x00, 0xfe, // sample_size
0x00, 0x00, 0x00, 0x00); // sample_composition_time_offset
deepEqual(videojs.inspectMp4(new Uint8Array(data)),
[{
type: 'trun',
version: 0,
size: 48,
flags: new Uint8Array([0, 0x0b, 0x05]),
dataOffset: 1,
samples: [{
duration: 9,
size: 0xff,
flags: 0x01020304,
compositionTimeOffset: 0
}, {
duration: 8,
size: 0xfe,
compositionTimeOffset: 0
}]
}]);
});
test('can parse a series of boxes', function() {
var ftyp = [
0x00, 0x00, 0x00, 0x18 // size 4 * 6 = 24
......
......@@ -456,6 +456,70 @@ var
sampleDegradationPriority: view.getUint16(22)
};
},
trun: function(data) {
var
result = {
version: data[0],
flags: new Uint8Array(data.subarray(1, 4)),
samples: []
},
view = new DataView(data.buffer, data.byteOffset, data.byteLength),
dataOffsetPresent = result.flags[2] & 0x01,
firstSampleFlagsPresent = result.flags[2] & 0x04,
sampleDurationPresent = result.flags[1] & 0x01,
sampleSizePresent = result.flags[1] & 0x02,
sampleFlagsPresent = result.flags[1] & 0x04,
sampleCompositionTimeOffsetPresent = result.flags[1] & 0x08,
sampleCount = view.getUint32(4),
offset = 8,
sample;
if (dataOffsetPresent) {
result.dataOffset = view.getUint32(offset);
offset += 4;
}
if (firstSampleFlagsPresent && sampleCount) {
sample = {
flags: view.getUint32(offset)
};
offset += 4;
if (sampleDurationPresent) {
sample.duration = view.getUint32(offset);
offset += 4;
}
if (sampleSizePresent) {
sample.size = view.getUint32(offset);
offset += 4;
}
if (sampleCompositionTimeOffsetPresent) {
sample.compositionTimeOffset = view.getUint32(offset);
offset += 4;
}
result.samples.push(sample);
sampleCount--;
};
while (sampleCount--) {
sample = {};
if (sampleFlagsPresent) {
sample.flags = view.getUint32(offset);
offset += 4;
}
if (sampleDurationPresent) {
sample.duration = view.getUint32(offset);
offset += 4;
}
if (sampleSizePresent) {
sample.size = view.getUint32(offset);
offset += 4;
}
if (sampleCompositionTimeOffsetPresent) {
sample.compositionTimeOffset = view.getUint32(offset);
offset += 4;
}
result.samples.push(sample);
}
return result;
},
'url ': function(data) {
return {
version: data[0],
......