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() { ...@@ -669,6 +669,41 @@ test('can parse a moof', function() {
669 }]); 669 }]);
670 }); 670 });
671 671
672 test('can parse a trun', function() {
673 var data = box('trun',
674 0x00, // version
675 0x00, 0x0b, 0x05, // flags
676 0x00, 0x00, 0x00, 0x02, // sample_count
677 0x00, 0x00, 0x00, 0x01, // data_offset
678 0x01, 0x02, 0x03, 0x04, // first_sample_flags
679
680 0x00, 0x00, 0x00, 0x09, // sample_duration
681 0x00, 0x00, 0x00, 0xff, // sample_size
682 0x00, 0x00, 0x00, 0x00, // sample_composition_time_offset
683
684 0x00, 0x00, 0x00, 0x08, // sample_duration
685 0x00, 0x00, 0x00, 0xfe, // sample_size
686 0x00, 0x00, 0x00, 0x00); // sample_composition_time_offset
687 deepEqual(videojs.inspectMp4(new Uint8Array(data)),
688 [{
689 type: 'trun',
690 version: 0,
691 size: 48,
692 flags: new Uint8Array([0, 0x0b, 0x05]),
693 dataOffset: 1,
694 samples: [{
695 duration: 9,
696 size: 0xff,
697 flags: 0x01020304,
698 compositionTimeOffset: 0
699 }, {
700 duration: 8,
701 size: 0xfe,
702 compositionTimeOffset: 0
703 }]
704 }]);
705 });
706
672 test('can parse a series of boxes', function() { 707 test('can parse a series of boxes', function() {
673 var ftyp = [ 708 var ftyp = [
674 0x00, 0x00, 0x00, 0x18 // size 4 * 6 = 24 709 0x00, 0x00, 0x00, 0x18 // size 4 * 6 = 24
......
...@@ -456,6 +456,70 @@ var ...@@ -456,6 +456,70 @@ var
456 sampleDegradationPriority: view.getUint16(22) 456 sampleDegradationPriority: view.getUint16(22)
457 }; 457 };
458 }, 458 },
459 trun: function(data) {
460 var
461 result = {
462 version: data[0],
463 flags: new Uint8Array(data.subarray(1, 4)),
464 samples: []
465 },
466 view = new DataView(data.buffer, data.byteOffset, data.byteLength),
467 dataOffsetPresent = result.flags[2] & 0x01,
468 firstSampleFlagsPresent = result.flags[2] & 0x04,
469 sampleDurationPresent = result.flags[1] & 0x01,
470 sampleSizePresent = result.flags[1] & 0x02,
471 sampleFlagsPresent = result.flags[1] & 0x04,
472 sampleCompositionTimeOffsetPresent = result.flags[1] & 0x08,
473 sampleCount = view.getUint32(4),
474 offset = 8,
475 sample;
476
477 if (dataOffsetPresent) {
478 result.dataOffset = view.getUint32(offset);
479 offset += 4;
480 }
481 if (firstSampleFlagsPresent && sampleCount) {
482 sample = {
483 flags: view.getUint32(offset)
484 };
485 offset += 4;
486 if (sampleDurationPresent) {
487 sample.duration = view.getUint32(offset);
488 offset += 4;
489 }
490 if (sampleSizePresent) {
491 sample.size = view.getUint32(offset);
492 offset += 4;
493 }
494 if (sampleCompositionTimeOffsetPresent) {
495 sample.compositionTimeOffset = view.getUint32(offset);
496 offset += 4;
497 }
498 result.samples.push(sample);
499 sampleCount--;
500 };
501 while (sampleCount--) {
502 sample = {};
503 if (sampleFlagsPresent) {
504 sample.flags = view.getUint32(offset);
505 offset += 4;
506 }
507 if (sampleDurationPresent) {
508 sample.duration = view.getUint32(offset);
509 offset += 4;
510 }
511 if (sampleSizePresent) {
512 sample.size = view.getUint32(offset);
513 offset += 4;
514 }
515 if (sampleCompositionTimeOffsetPresent) {
516 sample.compositionTimeOffset = view.getUint32(offset);
517 offset += 4;
518 }
519 result.samples.push(sample);
520 }
521 return result;
522 },
459 'url ': function(data) { 523 'url ': function(data) {
460 return { 524 return {
461 version: data[0], 525 version: data[0],
......