Example #1
0
        void InitializeSampleCountsInChunk(int trackIndex)
        {
            SampleCountsInChunk[trackIndex] = new List <uint>();
            SampleCountsInChunk[trackIndex].Clear();
            TrackBox[]       tracks      = this.mmb.TrackBoxes;
            SampleTableBox   sampleTable = tracks[trackIndex].MediaBox.MediaInformationBox.SampleTableBox;
            SampleToChunkBox stsc        = sampleTable.SampleToChunkBox;
            uint             totalChunks = sampleTable.ChunkOffSetBox.EntryCount;
            int  chunkEntryIndex;
            uint samplesPerChunk;

            for (chunkEntryIndex = 0; chunkEntryIndex < (stsc.EntryCount - 1); chunkEntryIndex++)
            {
                for (uint chunkCount = stsc.ChunkEntries[chunkEntryIndex].firstChunk; chunkCount < stsc.ChunkEntries[chunkEntryIndex + 1].firstChunk;
                     chunkCount++)
                {
                    samplesPerChunk = stsc.ChunkEntries[chunkEntryIndex].samplesPerChunk;
                    SampleCountsInChunk[trackIndex].Add(samplesPerChunk);
                }
            }
            uint remainingChunkCount = (uint)sampleTable.ChunkOffSetBox.ChunkOffsets.Length - stsc.ChunkEntries[chunkEntryIndex].firstChunk + 1;

            samplesPerChunk = stsc.ChunkEntries[chunkEntryIndex].samplesPerChunk;
            for (; remainingChunkCount > 0; remainingChunkCount--)
            {
                SampleCountsInChunk[trackIndex].Add(samplesPerChunk);
            }
        }
Example #2
0
 /// <summary>
 /// Constructor to use when building the box from scratch.
 /// NOTE: We don't compute the Size of this box in this constructor.
 /// The Size of this box is computed during FinalizeBox.
 /// NOTE: The ordering of the sub-boxes is not determined in the constructor.
 /// Writing out the sub-boxes (see the Write method below) determines the order of sub-boxes.
 /// </summary>
 /// <param name="inParent">MediaInformationBox</param>
 /// <param name="trackInfo">IsochronousTrackInfo</param>
 public SampleTableBox(MediaInformationBox inParent, IsochronousTrackInfo trackInfo)
     : this(inParent)
 {
     CTTSOut                 = trackInfo.CTTSOut;
     fragmented              = trackInfo.IsFragment;
     SampleDescriptionsBox   = new SampleDescriptionsBox(this, trackInfo);
     DecodingTimeToSampleBox = new DecodingTimeToSampleBox(this);
     SampleToChunkBox        = new SampleToChunkBox(this);
     SampleSizeBox           = new SampleSizeBox(this);
     ChunkOffSetBox          = new ChunkOffSetBox(this);
     if ((trackInfo is RawVideoTrackInfo) && !fragmented)
     {
         SyncSampleMapBox = new SyncSampleMapBox();
         //CompositionTimeToSample = new CompositionTimeToSample(this);
     }
 }
Example #3
0
        /// <summary>
        /// Read - read in the SampleTableBox from the input MP4 file.
        /// Sub-boxes can come in in any order.
        /// </summary>
        /// <param name="reader">BoxReader</param>
        public override void Read(BoxReader reader)
        {
            using (new SizeChecker(this, reader)) {
                base.Read(reader);

                while (reader.BaseStream.Position < (long)(this.Size + this.Offset))
                {
                    long pos  = reader.BaseStream.Position;
                    Box  test = new Box(BoxTypes.Any);
                    test.Read(reader);
                    reader.BaseStream.Position = pos;

                    if (test.Type == BoxTypes.TimeToSample)
                    {
                        this.DecodingTimeToSampleBox = new DecodingTimeToSampleBox(this);
                        DecodingTimeToSampleBox.Read(reader);
                    }

                    else if (test.Type == BoxTypes.CompositionOffset)
                    {
                        this.CompositionTimeToSample = new CompositionTimeToSample(this);
                        CompositionTimeToSample.Read(reader);
                    }

                    else if (test.Type == BoxTypes.SampleDescription)
                    {
                        this.SampleDescriptionsBox = new SampleDescriptionsBox(this);
                        SampleDescriptionsBox.Read(reader);
                    }

                    else if (test.Type == BoxTypes.SampleToChunk)
                    {
                        this.SampleToChunkBox = new SampleToChunkBox(this);
                        SampleToChunkBox.Read(reader);
                    }

                    else if (test.Type == BoxTypes.SampleSize)
                    {
                        this.SampleSizeBox = new SampleSizeBox(this);
                        SampleSizeBox.Read(reader);
                    }

                    else if (test.Type == BoxTypes.ChunkOffset) // FIXME: this can be a "co64" box
                    {
                        this.ChunkOffSetBox = new ChunkOffSetBox(this);
                        ChunkOffSetBox.Read(reader);
                    }

                    else if (test.Type == BoxTypes.SyncSampleMap)
                    {
                        this.SyncSampleMapBox = new SyncSampleMapBox();
                        SyncSampleMapBox.Read(reader);
                    }

                    else
                    {
                        reader.BaseStream.Position = (long)(test.Size + test.Offset); // skip unknown box
                        Debug.WriteLine(string.Format("Unknown box type {0} in SampleTableBox (stbl), skipped", test.Type.ToString()));
                    }
                } // end of while

                if (SampleToChunkBox != null)
                {
                    SampleToChunkBox.CheckIntegrityOfChunkData();
                }
            }
        }
Example #4
0
 /// <summary>
 /// Constructor to use when building the box from scratch.
 /// NOTE: We don't compute the Size of this box in this constructor.
 /// The Size of this box is computed during FinalizeBox.
 /// NOTE: The ordering of the sub-boxes is not determined in the constructor.
 /// Writing out the sub-boxes (see the Write method below) determines the order of sub-boxes.
 /// </summary>
 /// <param name="inParent">MediaInformationBox</param>
 /// <param name="trackInfo">IsochronousTrackInfo</param>
 public SampleTableBox(MediaInformationBox inParent, IsochronousTrackInfo trackInfo)
     : this(inParent)
 {
     CTTSOut = trackInfo.CTTSOut;
       fragmented = trackInfo.IsFragment;
       SampleDescriptionsBox = new SampleDescriptionsBox(this, trackInfo);
       DecodingTimeToSampleBox = new DecodingTimeToSampleBox(this);
       SampleToChunkBox = new SampleToChunkBox(this);
       SampleSizeBox = new SampleSizeBox(this);
       ChunkOffSetBox = new ChunkOffSetBox(this);
       if ((trackInfo is RawVideoTrackInfo) && !fragmented)
       {
     SyncSampleMapBox = new SyncSampleMapBox();
     //CompositionTimeToSample = new CompositionTimeToSample(this);
       }
 }
Example #5
0
        /// <summary>
        /// Read - read in the SampleTableBox from the input MP4 file.
        /// Sub-boxes can come in in any order.
        /// </summary>
        /// <param name="reader">BoxReader</param>
        public override void Read(BoxReader reader)
        {
            using (new SizeChecker(this, reader)) {
            base.Read(reader);

            while (reader.BaseStream.Position < (long)(this.Size + this.Offset)) {
              long pos = reader.BaseStream.Position;
              Box test = new Box(BoxTypes.Any);
              test.Read(reader);
              reader.BaseStream.Position = pos;

              if (test.Type == BoxTypes.TimeToSample) {
            this.DecodingTimeToSampleBox = new DecodingTimeToSampleBox(this);
            DecodingTimeToSampleBox.Read(reader);
              }

              else if (test.Type == BoxTypes.CompositionOffset) {
            this.CompositionTimeToSample = new CompositionTimeToSample(this);
            CompositionTimeToSample.Read(reader);
              }

              else if (test.Type == BoxTypes.SampleDescription) {
            this.SampleDescriptionsBox = new SampleDescriptionsBox(this);
            SampleDescriptionsBox.Read(reader);
              }

              else if (test.Type == BoxTypes.SampleToChunk) {
            this.SampleToChunkBox = new SampleToChunkBox(this);
            SampleToChunkBox.Read(reader);
              }

              else if (test.Type == BoxTypes.SampleSize) {
            this.SampleSizeBox = new SampleSizeBox(this);
            SampleSizeBox.Read(reader);
              }

              else if (test.Type == BoxTypes.ChunkOffset) {      // FIXME: this can be a "co64" box
            this.ChunkOffSetBox = new ChunkOffSetBox(this);
            ChunkOffSetBox.Read(reader);
              }

              else if (test.Type == BoxTypes.SyncSampleMap)
              {
              this.SyncSampleMapBox = new SyncSampleMapBox();
              SyncSampleMapBox.Read(reader);
              }

              else
              {
            reader.BaseStream.Position = (long)(test.Size + test.Offset); // skip unknown box
            Debug.WriteLine(string.Format("Unknown box type {0} in SampleTableBox (stbl), skipped", test.Type.ToString()));
              }
            } // end of while

            if (SampleToChunkBox != null)
              SampleToChunkBox.CheckIntegrityOfChunkData();
              }
        }