Added the sidx parsing and test file from mp4 spec
Showing
2 changed files
with
75 additions
and
0 deletions
... | @@ -704,6 +704,54 @@ test('can parse a trun', function() { | ... | @@ -704,6 +704,54 @@ test('can parse a trun', function() { |
704 | }]); | 704 | }]); |
705 | }); | 705 | }); |
706 | 706 | ||
707 | test('can parse a sidx', function(){ | ||
708 | var data = box('sidx', | ||
709 | 0x00, // version | ||
710 | 0x00, 0x00, 0x00, // flags | ||
711 | 0x00, 0x00, 0x00, 0x02, // reference_ID | ||
712 | 0x00, 0x00, 0x00, 0x01, // timescale | ||
713 | 0x01, 0x02, 0x03, 0x04, // earliest_presentation_time | ||
714 | 0x00, 0x00, 0x00, 0x00, // first_offset | ||
715 | 0x00, 0x00, // reserved | ||
716 | 0x00, 0x02, // reference_count | ||
717 | // first reference | ||
718 | 0x80, 0x00, 0x00, 0x07, // reference_type(1) + referenced_size(31) | ||
719 | 0x00, 0x00, 0x00, 0x08, // subsegment_duration | ||
720 | 0x80, 0x00, 0x00, 0x09, // starts_with_SAP(1) + SAP_type(3) + SAP_delta_time(28) | ||
721 | // second reference | ||
722 | 0x00, 0x00, 0x00, 0x03, // reference_type(1) + referenced_size(31) | ||
723 | 0x00, 0x00, 0x00, 0x04, // subsegment_duration | ||
724 | 0x10, 0x00, 0x00, 0x05 // starts_with_SAP(1) + SAP_type(3) + SAP_delta_time(28) | ||
725 | ); | ||
726 | deepEqual(videojs.inspectMp4(new Uint8Array(data)), | ||
727 | [{ | ||
728 | type: 'sidx', | ||
729 | version: 0, | ||
730 | flags: new Uint8Array([0, 0x00, 0x00]), | ||
731 | timescale: 1, | ||
732 | earliestPresentationTime: 0x01020304, | ||
733 | firstOffset: 0, | ||
734 | referenceId: 2, | ||
735 | size: 56, | ||
736 | references: [{ | ||
737 | referenceType: 1, | ||
738 | referencedSize: 7, | ||
739 | subsegmentDuration: 8, | ||
740 | startsWithSap: true, | ||
741 | sapType: 0, | ||
742 | sapDeltaTime: 9 | ||
743 | },{ | ||
744 | referenceType: 0, | ||
745 | referencedSize: 3, | ||
746 | subsegmentDuration: 4, | ||
747 | startsWithSap: false, | ||
748 | sapType: 1, | ||
749 | sapDeltaTime: 5 | ||
750 | }] | ||
751 | |||
752 | }]); | ||
753 | }); | ||
754 | |||
707 | test('can parse a series of boxes', function() { | 755 | test('can parse a series of boxes', function() { |
708 | var ftyp = [ | 756 | var ftyp = [ |
709 | 0x00, 0x00, 0x00, 0x18 // size 4 * 6 = 24 | 757 | 0x00, 0x00, 0x00, 0x18 // size 4 * 6 = 24 | ... | ... |
... | @@ -266,6 +266,33 @@ var | ... | @@ -266,6 +266,33 @@ var |
266 | initialDelay: view.getUint32(8) | 266 | initialDelay: view.getUint32(8) |
267 | }; | 267 | }; |
268 | }, | 268 | }, |
269 | sidx: function(data) { | ||
270 | var view = new DataView(data.buffer, data.byteOffset, data.byteLength), | ||
271 | result = { | ||
272 | version: data[0], | ||
273 | flags: new Uint8Array(data.subarray(1, 4)), | ||
274 | references: [], | ||
275 | referenceId: view.getUint32(4), | ||
276 | timescale: view.getUint32(8), | ||
277 | earliestPresentationTime: view.getUint32(12), | ||
278 | firstOffset: view.getUint32(16) | ||
279 | }, | ||
280 | referenceCount = view.getUint16(22), | ||
281 | i; | ||
282 | |||
283 | for (i = 24; referenceCount; i += 12, referenceCount-- ) { | ||
284 | result.references.push({ | ||
285 | referenceType: (data[i] & 0x80) >>> 7, | ||
286 | referencedSize: view.getUint32(i) & 0x7FFFFFFF, | ||
287 | subsegmentDuration: view.getUint32(i + 4), | ||
288 | startsWithSap: !!(data[i + 8] & 0x80), | ||
289 | sapType: (data[i + 8] & 0x70) >>> 4, | ||
290 | sapDeltaTime: view.getUint32(i + 8) & 0x0FFFFFFF | ||
291 | }); | ||
292 | } | ||
293 | |||
294 | return result; | ||
295 | }, | ||
269 | stbl: function(data) { | 296 | stbl: function(data) { |
270 | return { | 297 | return { |
271 | boxes: videojs.inspectMp4(data) | 298 | boxes: videojs.inspectMp4(data) | ... | ... |
-
Please register or sign in to post a comment