9513e960 by David LaPalomento

Sample durations should be in 90kHz timescales

Scale sample durations so to match the timescales specified elsewhere in the media segment. Recreate Uint8Arrays for testing so that equality tests pass in phantomjs. Phantom apparently counts typed arrays with different byteOffsets as not equal.
1 parent 54ca5993
......@@ -721,7 +721,9 @@ VideoSegmentStream = function(track) {
// flush the sample we've been building when a new sample is started
if (currentNal.nalUnitType === 'access_unit_delimiter_rbsp') {
if (startUnit) {
sample.duration = currentNal.dts - startUnit.dts;
// convert the duration to 90kHZ timescale to match the
// timescales specified in the init segment
sample.duration = (currentNal.dts - startUnit.dts) * 90;
track.samples.push(sample);
}
sample = {
......
......@@ -107,7 +107,7 @@ var
for (i = 0; i < numOfSequenceParameterSets; i++) {
nalSize = view.getUint16(offset);
offset += 2;
result.sps.push(data.subarray(offset, offset + nalSize));
result.sps.push(new Uint8Array(data.subarray(offset, offset + nalSize)));
offset += nalSize;
}
// iterate past any PPSs
......@@ -116,7 +116,7 @@ var
for (i = 0; i < numOfPictureParameterSets; i++) {
nalSize = view.getUint16(offset);
offset += 2;
result.pps.push(data.subarray(offset, offset + nalSize));
result.pps.push(new Uint8Array(data.subarray(offset, offset + nalSize)));
offset += nalSize;
}
return result;
......
......@@ -834,12 +834,12 @@ test('strips byte stream framing during parsing', function() {
0x08,
0x01, 0x02, 0x03, 0x04,
0x05, 0x06, 0x07
]), data[0].data, 'parsed the first NAL unit');
]), new Uint8Array(data[0].data), 'parsed the first NAL unit');
deepEqual(new Uint8Array([
0x09,
0x06, 0x05, 0x04, 0x03,
0x02, 0x01, 0x00
]), data[1].data, 'parsed the second NAL unit');
]), new Uint8Array(data[1].data), 'parsed the second NAL unit');
});
module('VideoSegmentStream', {
......@@ -881,6 +881,36 @@ test('concatenates NAL units into AVC elementary streams', function() {
]), 'wrote an AVC stream into the mdat');
});
test('scales DTS values from milliseconds to 90kHz', function() {
var segment, boxes, samples;
videoSegmentStream.on('data', function(data) {
segment = data;
});
videoSegmentStream.push({
data: new Uint8Array([0x09, 0x01]),
nalUnitType: 'access_unit_delimiter_rbsp',
dts: 1
});
videoSegmentStream.push({
data: new Uint8Array([0x09, 0x01]),
nalUnitType: 'access_unit_delimiter_rbsp',
dts: 2
});
videoSegmentStream.push({
data: new Uint8Array([0x09, 0x01]),
nalUnitType: 'access_unit_delimiter_rbsp',
dts: 4
});
videoSegmentStream.end();
boxes = videojs.inspectMp4(segment);
samples = boxes[0].boxes[1].boxes[2].samples;
equal(samples.length, 3, 'generated two samples');
equal(samples[0].duration, 1 * 90, 'multiplied DTS duration by 90');
equal(samples[1].duration, 2 * 90, 'multiplied DTS duration by 90');
equal(samples[2].duration, 2 * 90, 'inferred the final sample duration');
});
module('Transmuxer', {
setup: function() {
transmuxer = new Transmuxer();
......