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) { ...@@ -721,7 +721,9 @@ VideoSegmentStream = function(track) {
721 // flush the sample we've been building when a new sample is started 721 // flush the sample we've been building when a new sample is started
722 if (currentNal.nalUnitType === 'access_unit_delimiter_rbsp') { 722 if (currentNal.nalUnitType === 'access_unit_delimiter_rbsp') {
723 if (startUnit) { 723 if (startUnit) {
724 sample.duration = currentNal.dts - startUnit.dts; 724 // convert the duration to 90kHZ timescale to match the
725 // timescales specified in the init segment
726 sample.duration = (currentNal.dts - startUnit.dts) * 90;
725 track.samples.push(sample); 727 track.samples.push(sample);
726 } 728 }
727 sample = { 729 sample = {
......
...@@ -107,7 +107,7 @@ var ...@@ -107,7 +107,7 @@ var
107 for (i = 0; i < numOfSequenceParameterSets; i++) { 107 for (i = 0; i < numOfSequenceParameterSets; i++) {
108 nalSize = view.getUint16(offset); 108 nalSize = view.getUint16(offset);
109 offset += 2; 109 offset += 2;
110 result.sps.push(data.subarray(offset, offset + nalSize)); 110 result.sps.push(new Uint8Array(data.subarray(offset, offset + nalSize)));
111 offset += nalSize; 111 offset += nalSize;
112 } 112 }
113 // iterate past any PPSs 113 // iterate past any PPSs
...@@ -116,7 +116,7 @@ var ...@@ -116,7 +116,7 @@ var
116 for (i = 0; i < numOfPictureParameterSets; i++) { 116 for (i = 0; i < numOfPictureParameterSets; i++) {
117 nalSize = view.getUint16(offset); 117 nalSize = view.getUint16(offset);
118 offset += 2; 118 offset += 2;
119 result.pps.push(data.subarray(offset, offset + nalSize)); 119 result.pps.push(new Uint8Array(data.subarray(offset, offset + nalSize)));
120 offset += nalSize; 120 offset += nalSize;
121 } 121 }
122 return result; 122 return result;
......
...@@ -834,12 +834,12 @@ test('strips byte stream framing during parsing', function() { ...@@ -834,12 +834,12 @@ test('strips byte stream framing during parsing', function() {
834 0x08, 834 0x08,
835 0x01, 0x02, 0x03, 0x04, 835 0x01, 0x02, 0x03, 0x04,
836 0x05, 0x06, 0x07 836 0x05, 0x06, 0x07
837 ]), data[0].data, 'parsed the first NAL unit'); 837 ]), new Uint8Array(data[0].data), 'parsed the first NAL unit');
838 deepEqual(new Uint8Array([ 838 deepEqual(new Uint8Array([
839 0x09, 839 0x09,
840 0x06, 0x05, 0x04, 0x03, 840 0x06, 0x05, 0x04, 0x03,
841 0x02, 0x01, 0x00 841 0x02, 0x01, 0x00
842 ]), data[1].data, 'parsed the second NAL unit'); 842 ]), new Uint8Array(data[1].data), 'parsed the second NAL unit');
843 }); 843 });
844 844
845 module('VideoSegmentStream', { 845 module('VideoSegmentStream', {
...@@ -881,6 +881,36 @@ test('concatenates NAL units into AVC elementary streams', function() { ...@@ -881,6 +881,36 @@ test('concatenates NAL units into AVC elementary streams', function() {
881 ]), 'wrote an AVC stream into the mdat'); 881 ]), 'wrote an AVC stream into the mdat');
882 }); 882 });
883 883
884 test('scales DTS values from milliseconds to 90kHz', function() {
885 var segment, boxes, samples;
886 videoSegmentStream.on('data', function(data) {
887 segment = data;
888 });
889 videoSegmentStream.push({
890 data: new Uint8Array([0x09, 0x01]),
891 nalUnitType: 'access_unit_delimiter_rbsp',
892 dts: 1
893 });
894 videoSegmentStream.push({
895 data: new Uint8Array([0x09, 0x01]),
896 nalUnitType: 'access_unit_delimiter_rbsp',
897 dts: 2
898 });
899 videoSegmentStream.push({
900 data: new Uint8Array([0x09, 0x01]),
901 nalUnitType: 'access_unit_delimiter_rbsp',
902 dts: 4
903 });
904 videoSegmentStream.end();
905
906 boxes = videojs.inspectMp4(segment);
907 samples = boxes[0].boxes[1].boxes[2].samples;
908 equal(samples.length, 3, 'generated two samples');
909 equal(samples[0].duration, 1 * 90, 'multiplied DTS duration by 90');
910 equal(samples[1].duration, 2 * 90, 'multiplied DTS duration by 90');
911 equal(samples[2].duration, 2 * 90, 'inferred the final sample duration');
912 });
913
884 module('Transmuxer', { 914 module('Transmuxer', {
885 setup: function() { 915 setup: function() {
886 transmuxer = new Transmuxer(); 916 transmuxer = new Transmuxer();
......