public override void Read(BoxReader reader)
 {
     using (new SizeChecker(this, reader))
     {
         base.Read(reader);
         this.TrackId = reader.ReadUInt32();
         if (EnumUtils.IsBitSet <TrackFragmentHeaderBoxFlags>((TrackFragmentHeaderBoxFlags)base.Flags, TrackFragmentHeaderBoxFlags.BaseDataOffsetPresent))
         {
             this._baseDataOffset = reader.ReadUInt64();
         }
         if (EnumUtils.IsBitSet <TrackFragmentHeaderBoxFlags>((TrackFragmentHeaderBoxFlags)base.Flags, TrackFragmentHeaderBoxFlags.SampleDescriptionIndexPresent))
         {
             this._sampleDescriptionIndex = reader.ReadUInt32();
         }
         if (EnumUtils.IsBitSet <TrackFragmentHeaderBoxFlags>((TrackFragmentHeaderBoxFlags)base.Flags, TrackFragmentHeaderBoxFlags.DefaultSampleDurationPresent))
         {
             this._defaultSampleDuration = reader.ReadUInt32();
         }
         if (EnumUtils.IsBitSet <TrackFragmentHeaderBoxFlags>((TrackFragmentHeaderBoxFlags)base.Flags, TrackFragmentHeaderBoxFlags.DefaultSampleSizePresent))
         {
             this._defaultSampleSize = reader.ReadUInt32();
         }
         if (EnumUtils.IsBitSet <TrackFragmentHeaderBoxFlags>((TrackFragmentHeaderBoxFlags)base.Flags, TrackFragmentHeaderBoxFlags.DefaultSampleFlagsPresent))
         {
             this._defaultSampleFlags = reader.ReadUInt32();
         }
     }
 }
示例#2
0
        public override void Read(BoxReader reader)
        {
            using (new SizeChecker(this, reader)) {
                base.Read(reader);
                if (Version == 1)
                {
                    creationTime     = reader.ReadUInt64();
                    modificationTime = reader.ReadUInt64();
                    TrackID          = reader.ReadUInt32();
                    UInt32 reserved = reader.ReadUInt32(); // reserved = 0
                    Duration = reader.ReadUInt64();
                }
                else
                {
                    creationTime     = (UInt32)reader.ReadUInt32();
                    modificationTime = (UInt32)reader.ReadUInt32();
                    TrackID          = reader.ReadUInt32();
                    reader.ReadUInt32(); // reserved = 0
                    Duration = (UInt32)reader.ReadUInt32();
                }

                for (int x = 0; x < 2; x++)
                {
                    reader.ReadUInt32();              // int(32)[2] - reserved = 0  - 40 bytes
                }
                Layer          = reader.ReadUInt16(); // layer = 0
                AlternateGroup = reader.ReadUInt16(); // alternate_group = 0
                _volume        = reader.ReadUInt16();
                reader.ReadUInt16();                  // reserved = 0   -  48 bytes
                this.Matrix.Read(reader);
                _width  = reader.ReadUInt32();
                _height = reader.ReadUInt32();
            }
        }
示例#3
0
 public override void Read(BoxReader reader)
 {
     using (new SizeChecker(this, reader)) {
         base.Read(reader);
         TrackID = reader.ReadUInt32();
         DefaultSampleDescriptionIndex = reader.ReadUInt32();
         DefaultSampleDuration         = reader.ReadUInt32();
         DefaultSampleSize             = reader.ReadUInt32();
         DefaultSampleFlags            = reader.ReadUInt32();
     }
 }
        public override void Read(BoxReader reader)
        {
            using (new SizeChecker(this, reader)) {
            base.Read(reader);

            EntryCount = reader.ReadUInt32();
            SampleCount = new uint[EntryCount];
            SampleDelta = new uint[EntryCount];
            for (int i=0; i<EntryCount; i++) {
              SampleCount[i] = reader.ReadUInt32();
              SampleDelta[i] = reader.ReadUInt32();
            }
              }
        }
示例#5
0
        /// <summary>
        /// Read - read chunk offset box from input MP4 stream.
        /// </summary>
        /// <param name="reader">BoxReader</param>
        public override void Read(BoxReader reader)
        {
            using (new SizeChecker(this, reader)) {
            base.Read(reader);

            entryCount = reader.ReadUInt32();
            chunkOffsetArray = new uint[entryCount];
            for (int i = 0; i < entryCount; i++) {
              chunkOffsetArray[i] = reader.ReadUInt32();
            }
              }
              if (parent.SampleToChunkBox != null)
              parent.SampleToChunkBox.TotalChunks = entryCount;
        }
示例#6
0
        public override void Read(BoxReader reader)
        {
            using (new SizeChecker(this, reader))
            {
                base.Read(reader);

                EntryCount    = reader.ReadUInt32();
                SampleNumbers = new uint[EntryCount];
                for (int i = 0; i < EntryCount; i++)
                {
                    SampleNumbers[i] = reader.ReadUInt32();
                }
            }
        }
示例#7
0
 public void Read(BoxReader reader)
 {
     for (int i = 0; i < 9; i++)
     {
         matrix[i] = reader.ReadUInt32();                   // int(32)[9] - matrix
     }
 }
示例#8
0
        public virtual void Read(BoxReader reader)
        {
            this.Offset = (ulong)reader.BaseStream.Position;
            this.size   = reader.ReadUInt32();

            if (size == 0)
            {
                this.type = BoxTypes.Error;
                return;
            }

            this.type = reader.ReadBoxType();
            if (this.size == 1)
            {
                this.largeSize = reader.ReadUInt64();
            }
            if (this.expectedType == BoxTypes.Any)
            {
                reader.BaseStream.Seek((long)(this.size - 8), SeekOrigin.Current);
            }
            else if (this.expectedType == BoxTypes.AnyDescription)
            {
                return;
            }
            else if (this.type != this.expectedType)
            {
                throw new UnexpectedBoxException(this.expectedType, this.type);
            }
        }
示例#9
0
        public override void Read(BoxReader reader)
        {
            using (new SizeChecker(this, reader)) {
                long curpos = reader.BaseStream.Position;

                base.Read(reader);
                major_brand   = reader.ReadUInt32();
                minor_version = reader.ReadUInt32();
                int brand_count = (int)(this.Size - (ulong)(reader.BaseStream.Position - curpos)) / 4;
                compatible_brands = new uint[brand_count];
                for (int i = 0; i < brand_count; i++)
                {
                    compatible_brands[i] = reader.ReadUInt32();
                }
            }
        }
示例#10
0
文件: Box.cs 项目: ctapang/GPUCyclops
        public virtual void Read(BoxReader reader)
        {
            this.Offset = (ulong)reader.BaseStream.Position;
            this.size = reader.ReadUInt32();

            if (size == 0) {
              this.type = BoxTypes.Error;
              return;
            }

            this.type = reader.ReadBoxType();
            if (this.size == 1) {
              this.largeSize = reader.ReadUInt64();
            }
            if (this.expectedType == BoxTypes.Any)
            {
                reader.BaseStream.Seek((long) (this.size - 8), SeekOrigin.Current);
            }
            else if (this.expectedType == BoxTypes.AnyDescription)
            {
                return;
            }
            else if (this.type != this.expectedType)
            {
              throw new UnexpectedBoxException(this.expectedType, this.type);
            }
        }
示例#11
0
        /// <summary>
        /// Read - read chunk offset box from input MP4 stream.
        /// </summary>
        /// <param name="reader">BoxReader</param>
        public override void Read(BoxReader reader)
        {
            using (new SizeChecker(this, reader)) {
                base.Read(reader);

                entryCount       = reader.ReadUInt32();
                chunkOffsetArray = new uint[entryCount];
                for (int i = 0; i < entryCount; i++)
                {
                    chunkOffsetArray[i] = reader.ReadUInt32();
                }
            }
            if (parent.SampleToChunkBox != null)
            {
                parent.SampleToChunkBox.TotalChunks = entryCount;
            }
        }
示例#12
0
        public override void Read(BoxReader reader)
        {
            using (new SizeChecker(this, reader)) {
                base.Read(reader);

                sampleSize  = reader.ReadUInt32();
                sampleCount = reader.ReadUInt32();
                if (sampleSize == 0)
                {
                    sampleSizeArray = new uint[sampleCount];
                    for (int i = 0; i < sampleCount; i++)
                    {
                        sampleSizeArray[i] = reader.ReadUInt32();
                    }
                }
            }
        }
示例#13
0
 public override void Read(BoxReader reader)
 {
     using (new SizeChecker(this, reader))
     {
         base.Read(reader);
         this.MfraSize = reader.ReadUInt32();
     }
 }
示例#14
0
 public override void Read(BoxReader reader)
 {
     base.Read(reader);
       trackID = new uint[(int)((long)Size - (reader.BaseStream.Position - (long)Offset)) / 4];
       for (int i = 0; i < trackID.Length; i++) {
     trackID[i] = reader.ReadUInt32();
       }
 }
 public override void Read(BoxReader reader)
 {
     using (new SizeChecker(this, reader))
     {
         base.Read(reader);
         this.SequenceNumber = reader.ReadUInt32();
     }
 }
 public override void Read(BoxReader reader)
 {
     using (new SizeChecker(this, reader))
     {
         base.Read(reader);
         this.SequenceNumber = reader.ReadUInt32();
     }
 }
 public override void Read(BoxReader reader)
 {
     using (new SizeChecker(this, reader))
     {
         base.Read(reader);
         this.MfraSize = reader.ReadUInt32();
     }
 }
示例#18
0
 public override void  Read(BoxReader reader)
 {
     base.Read(reader);
     trackID = new uint[(int)((long)Size - (reader.BaseStream.Position - (long)Offset)) / 4];
     for (int i = 0; i < trackID.Length; i++)
     {
         trackID[i] = reader.ReadUInt32();
     }
 }
 public void Read(BoxReader reader, uint flags)
 {
     if (EnumUtils.IsBitSet<TrackFragmentRunBoxFlags>((TrackFragmentRunBoxFlags) flags, TrackFragmentRunBoxFlags.SampleDurationPresent)) {
       this.SampleDuration = reader.ReadUInt32();
     //System.Diagnostics.Debug.WriteLine("Sample Duraiton: " + SampleDuration);
             }
       if (EnumUtils.IsBitSet<TrackFragmentRunBoxFlags>((TrackFragmentRunBoxFlags) flags, TrackFragmentRunBoxFlags.SampleSizePresent)) {
       this.SampleSize = reader.ReadUInt32();
       }
       // We follow the logic in  Blue: presence of SampleFlags solely depends on SampleFlagsPresent
       if (EnumUtils.IsBitSet<TrackFragmentRunBoxFlags>((TrackFragmentRunBoxFlags) flags, TrackFragmentRunBoxFlags.SampleFlagsPresent))
       {
       this.SampleFlags = reader.ReadUInt32();
       }
       if (EnumUtils.IsBitSet<TrackFragmentRunBoxFlags>((TrackFragmentRunBoxFlags) flags, TrackFragmentRunBoxFlags.SampleCompositionTimeOffsetsPresent)) {
       this.SampleCompositionTimeOffset = reader.ReadUInt32();
       }
 }
示例#20
0
 public override void Read(BoxReader reader)
 {
     using (new SizeChecker(this, reader)) {
     base.Read(reader);
     if (Version == 1) {
       FragmentDuration = reader.ReadUInt64();
     } else {
       FragmentDuration = (UInt64)reader.ReadUInt32();
     }
       }
 }
        public void Read(BoxReader reader, uint flags)
        {
            if (EnumUtils.IsBitSet <TrackFragmentRunBoxFlags>((TrackFragmentRunBoxFlags)flags, TrackFragmentRunBoxFlags.SampleDurationPresent))
            {
                this.SampleDuration = reader.ReadUInt32();
//System.Diagnostics.Debug.WriteLine("Sample Duraiton: " + SampleDuration);
            }
            if (EnumUtils.IsBitSet <TrackFragmentRunBoxFlags>((TrackFragmentRunBoxFlags)flags, TrackFragmentRunBoxFlags.SampleSizePresent))
            {
                this.SampleSize = reader.ReadUInt32();
            }
            // We follow the logic in  Blue: presence of SampleFlags solely depends on SampleFlagsPresent
            if (EnumUtils.IsBitSet <TrackFragmentRunBoxFlags>((TrackFragmentRunBoxFlags)flags, TrackFragmentRunBoxFlags.SampleFlagsPresent))
            {
                this.SampleFlags = reader.ReadUInt32();
            }
            if (EnumUtils.IsBitSet <TrackFragmentRunBoxFlags>((TrackFragmentRunBoxFlags)flags, TrackFragmentRunBoxFlags.SampleCompositionTimeOffsetsPresent))
            {
                this.SampleCompositionTimeOffset = reader.ReadUInt32();
            }
        }
示例#22
0
        public override void Read(BoxReader reader)
        {
            using (new SizeChecker(this, reader)) {
                base.Read(reader);

                EntryCount   = reader.ReadUInt32();
                ChunkEntries = new ChunkEntry[EntryCount];

                for (int i = 0; i < EntryCount; i++)
                {
                    ChunkEntries[i]                        = new ChunkEntry();
                    ChunkEntries[i].firstChunk             = reader.ReadUInt32();
                    ChunkEntries[i].samplesPerChunk        = reader.ReadUInt32();
                    ChunkEntries[i].sampleDescriptionIndex = reader.ReadUInt32();
                }
            }
            if (parent.ChunkOffSetBox != null)
            {
                TotalChunks = parent.ChunkOffSetBox.EntryCount;
            }
        }
示例#23
0
 /// <summary>
 /// Read
 /// NOTE: FirstSampleFlags and the flags in TrackFragmentRunSample are as follows:
 /// bit(6) reserved=0;                              // 6 bits reserved
 /// unsigned int(2) sample_depends_on;              // 2 bits used as int
 /// unsigned int(2) sample_is_depended_on;          // 2 bits used as int
 /// unsigned int(2) sample_has_redundancy;          // 2 bits used as int
 /// bit(3) sample_padding_value;                    // 3 bits
 /// bit(1) sample_is_difference_sample;             // 1 bit i.e. when 1 signals a non-key or non-sync sample
 /// unsigned int(16) sample_degradation_priority;   // 16 bits, total of 32 bits
 /// </summary>
 /// <param name="reader"></param>
 public override void Read(BoxReader reader)
 {
     using (new SizeChecker(this, reader)) {
         base.Read(reader);
         this.SampleCount = reader.ReadUInt32();
         if (EnumUtils.IsBitSet <TrackFragmentRunBoxFlags>((TrackFragmentRunBoxFlags)base.Flags, TrackFragmentRunBoxFlags.DataOffsetPresent))
         {
             this.DataOffset = reader.ReadUInt32();
         }
         if (EnumUtils.IsBitSet <TrackFragmentRunBoxFlags>((TrackFragmentRunBoxFlags)base.Flags, TrackFragmentRunBoxFlags.FirstSampleFlagsPresent))
         {
             this.FirstSampleFlags = reader.ReadUInt32();
         }
         this.Samples = new List <TrackFragmentRunSample>((int)this.SampleCount);
         for (int i = 0; i < this.SampleCount; i++)
         {
             TrackFragmentRunSample item = new TrackFragmentRunSample();
             item.Read(reader, base.Flags);
             this.Samples.Add(item);
             this.Duration += item.SampleDuration;
         }
     }
 }
示例#24
0
        public override void Read(BoxReader reader)
        {
            using (new SizeChecker(this, reader)) {
                base.Read(reader);
                if (Version == 1)
                {
                    creationTime     = reader.ReadUInt64();
                    modificationTime = reader.ReadUInt64();
                    TimeScale        = reader.ReadUInt32();
                    Duration         = reader.ReadUInt64();
                }
                else
                {
                    creationTime     = (UInt32)reader.ReadUInt32();
                    modificationTime = (UInt32)reader.ReadUInt32();
                    TimeScale        = reader.ReadUInt32();
                    Duration         = (UInt32)reader.ReadUInt32();
                }

                language = reader.ReadUInt16();
                reader.ReadUInt16(); // pre_defined = 0
            }
        }
 public override void Read(BoxReader reader)
 {
     using (new SizeChecker(this, reader)) {
         base.Read(reader);
         if (Version == 1)
         {
             FragmentDuration = reader.ReadUInt64();
         }
         else
         {
             FragmentDuration = (UInt64)reader.ReadUInt32();
         }
     }
 }
示例#26
0
 public override void Read(BoxReader reader)
 {
     using (new SizeChecker(this, reader))
     {
         base.Read(reader);
         this.TrackId = reader.ReadUInt32();
         uint num = reader.ReadUInt32();
         if ((num & 0xfffc) != 0)
         {
             throw new InvalidBoxException(base.Type, reader.BaseStream.Position, "top 26 bits of length field reserved");
         }
         this.LengthSizeOfTrafNum              = (uint)((num & 12) >> 4);
         this.LengthSizeOfTrunNum              = (uint)((num & 6) >> 2);
         this.LengthSizeOfSampleNum            = num & 3;
         this.NumberOfEntry                    = reader.ReadUInt32();
         this.TrackFragmentRandomAccessEntries = new List <TrackFragmentRandomAccessEntry>((int)this.NumberOfEntry);
         for (int i = 0; i < this.NumberOfEntry; i++)
         {
             TrackFragmentRandomAccessEntry item = new TrackFragmentRandomAccessEntry();
             item.Read(reader, base.Version, this.LengthSizeOfTrafNum, this.LengthSizeOfTrunNum, this.LengthSizeOfSampleNum);
             this.TrackFragmentRandomAccessEntries.Add(item);
         }
     }
 }
示例#27
0
 public override void Read(BoxReader reader)
 {
     using (new SizeChecker(this, reader))
     {
         base.Read(reader);
         entryCount = reader.ReadUInt32();
         editList   = new EditList[entryCount];
         for (int i = 0; i < entryCount; i++)
         {
             if (Version == 0)
             {
                 editList[i].segmentDuration = reader.ReadUInt32();
                 editList[i].mediaTime       = reader.ReadInt32();
             }
             else // must be 1
             {
                 editList[i].segmentDuration = reader.ReadUInt64();
                 editList[i].mediaTime       = reader.ReadInt64();
             }
             editList[i].mediaRateInteger  = (short)reader.ReadInt16();
             editList[i].mediaRateFraction = (short)reader.ReadInt16();
         }
     }
 }
 public override void Read(BoxReader reader)
 {
     using (new SizeChecker(this, reader))
     {
         base.Read(reader);
         this.TrackId = reader.ReadUInt32();
         uint num = reader.ReadUInt32();
         if ((num & 0xfffc) != 0)
         {
             throw new InvalidBoxException(base.Type, reader.BaseStream.Position, "top 26 bits of length field reserved");
         }
         this.LengthSizeOfTrafNum = (uint) ((num & 12) >> 4);
         this.LengthSizeOfTrunNum = (uint) ((num & 6) >> 2);
         this.LengthSizeOfSampleNum = num & 3;
         this.NumberOfEntry = reader.ReadUInt32();
         this.TrackFragmentRandomAccessEntries = new List<TrackFragmentRandomAccessEntry>((int) this.NumberOfEntry);
         for (int i = 0; i < this.NumberOfEntry; i++)
         {
             TrackFragmentRandomAccessEntry item = new TrackFragmentRandomAccessEntry();
             item.Read(reader, base.Version, this.LengthSizeOfTrafNum, this.LengthSizeOfTrunNum, this.LengthSizeOfSampleNum);
             this.TrackFragmentRandomAccessEntries.Add(item);
         }
     }
 }
示例#29
0
        public override void Read(BoxReader reader)
        {
            using (new SizeChecker(this, reader)) {
                base.Read(reader);
                if (Version == 1)
                {
                    creationTime     = reader.ReadUInt64();
                    modificationTime = reader.ReadUInt64();
                    TimeScale        = reader.ReadUInt32();
                    Duration         = reader.ReadUInt64();
                }
                else
                {
                    creationTime     = (UInt64)reader.ReadUInt32();
                    modificationTime = (UInt64)reader.ReadUInt32();
                    TimeScale        = reader.ReadUInt32();
                    Duration         = (UInt64)reader.ReadUInt32();
                }

                // Set rate 16.16.
                rate[0] = reader.ReadUInt16();
                rate[1] = reader.ReadUInt16();

                // Set _volume.
                reader.Read(volume, 0, 2);

                reader.ReadInt16(); // bit[16] - reserved = 0
                for (int x = 0; x < 2; x++)
                {
                    reader.ReadUInt32();                 // bit(32)[2] - pre_defined = 0
                }
                this.Matrix.Read(reader);
                for (int x = 0; x < 6; x++)
                {
                    reader.ReadUInt32();                 // bit(32)[6] - pre_defined = 0
                }
                NextTrackID = reader.ReadUInt32();
            }
        }
示例#30
0
 public override void Read(BoxReader reader)
 {
     using (new SizeChecker(this, reader)) {
         base.Read(reader);
         reader.ReadInt32();
         reader.Read(handler_type, 0, 4);
         for (int i = 0; i < 3; i++)
         {
             reader.ReadUInt32();
         }
         Name = reader.ReadNullTerminatedString();
         // special case to take care of Apple's bug
         // (Apple and GoPro prepends the string with char count, but then adds one byte too many to the box size.)
         if (reader.BaseStream.Position != (long)(this.Size + this.Offset))
         {
             reader.BaseStream.Position = (long)(this.Size + this.Offset);
             Name = Name.Substring(1);
         }
     }
 }
示例#31
0
        public override void Read(BoxReader reader)
        {
            using (new SizeChecker(this, reader)) {
                base.Read(reader);

                EntryCount = reader.ReadUInt32();
                DataEntry  = new DataEntry[EntryCount];

                for (int i = 0; i < EntryCount; i++)
                {
                    long pos  = reader.BaseStream.Position;
                    Box  test = new Box(BoxTypes.Any);
                    test.Read(reader);
                    reader.BaseStream.Position = pos;

                    DataEntry entry = new DataEntry();
                    if (test.Type == BoxTypes.DataEntryUrn)
                    {
                        entry.DataEntryUrnBox = new DataEntryUrnBox();
                        entry.DataEntryUrnBox.Read(reader);
                    }

                    else if (test.Type == BoxTypes.DataEntryUrl)
                    {
                        entry.DataEntryUrlBox = new DataEntryUrlBox();
                        entry.DataEntryUrlBox.Read(reader);
                        //            if (entry.DataEntryUrlBox.bBug == true) this.Size += 1;
                    }

                    else
                    {
                        test.Read(reader); // skip
                        Debug.WriteLine(string.Format("Unknown box type {0} in DataReferenceBox (dref), skipped", test.Type.ToString()));
                    }

                    DataEntry[i] = entry;
                }
            }
        }
示例#32
0
        public override void Read(BoxReader reader)
        {
            using (new SizeChecker(this, reader)) {
            base.Read(reader);

            EntryCount = reader.ReadUInt32();
            DataEntry = new DataEntry[EntryCount];

            for (int i=0; i<EntryCount; i++) {
              long pos = reader.BaseStream.Position;
              Box test = new Box(BoxTypes.Any);
              test.Read(reader);
              reader.BaseStream.Position = pos;

              DataEntry entry = new DataEntry();
              if (test.Type == BoxTypes.DataEntryUrn) {
            entry.DataEntryUrnBox = new DataEntryUrnBox();
            entry.DataEntryUrnBox.Read(reader);
              }

              else if (test.Type == BoxTypes.DataEntryUrl)
              {
              entry.DataEntryUrlBox = new DataEntryUrlBox();
              entry.DataEntryUrlBox.Read(reader);
              //            if (entry.DataEntryUrlBox.bBug == true) this.Size += 1;
              }

              else
              {
              test.Read(reader); // skip
              Debug.WriteLine(string.Format("Unknown box type {0} in DataReferenceBox (dref), skipped", test.Type.ToString()));
              }

              DataEntry[i] = entry;
            }
              }
        }
        public void Read(BoxReader reader, byte version, uint LengthSizeOfTrafNum, uint LengthSizeOfTrunNum, uint LengthSizeOfSampleNum)
        {
            if (version == 1)
            {
              ulong tmpTime = reader.ReadUInt64();
            //              if (tmpTime < LastTime) BaseTime = LastTime;
                this.Time = BaseTime + tmpTime;
                this.MoofOffset = reader.ReadUInt64();
                LastTime = Time;
            }
            else
            {
                this.Time = reader.ReadUInt32();
                this.MoofOffset = reader.ReadUInt32();
            }

            switch (((LengthSizeOfTrafNum + 1) * 8))
            {
                case 0x18:
                    this.TrafNumber = reader.ReadUInt24();
                    break;

                case 0x20:
                    this.TrafNumber = reader.ReadUInt32();
                    break;

                case 8:
                    this.TrafNumber = reader.ReadByte();
                    break;

                case 0x10:
                    this.TrafNumber = reader.ReadUInt16();
                    break;
            }

            switch (((LengthSizeOfTrunNum + 1) * 8))
            {
                case 0x18:
                    this.TrunNumber = reader.ReadUInt24();
                    break;

                case 0x20:
                    this.TrunNumber = reader.ReadUInt32();
                    break;

                case 8:
                    this.TrunNumber = reader.ReadByte();
                    break;

                case 0x10:
                    this.TrunNumber = reader.ReadUInt16();
                    break;
            }

            switch (((LengthSizeOfSampleNum + 1) * 8))
            {
                case 8:
                    this.SampleNumber = reader.ReadByte();
                    return;

                case 0x10:
                    this.SampleNumber = reader.ReadUInt16();
                    break;

                case 0x18:
                    this.SampleNumber = reader.ReadUInt24();
                    return;

                case 0x20:
                    this.SampleNumber = reader.ReadUInt32();
                    return;
            }
        }
示例#34
0
        public override void Read(BoxReader reader)
        {
            using (new SizeChecker(this, reader)) {
            long pos = reader.BaseStream.Position;

            base.Read(reader);
            for (int i = 0; i < 2; i++) reader.ReadUInt32();  // unsigned int(32)[2] reserved = 0
            ChannelCount = reader.ReadUInt16();
            SampleSize = reader.ReadUInt16();
            PreDefined = reader.ReadUInt16(); // unsigned int(16) pre_defined = 0
            reader.ReadUInt16(); // unsigned int(16) reserved = 0
            SampleRate = reader.ReadUInt32() >> 16;

              // read esds or avcc boxes
            BoxType bt = reader.PeekNextBoxType();
            switch (bt.ToString().ToLower())
            {
            case "esds": // AudioSampleEntry type is mp4a (denotes AAC encoding)
            case "avcc":
                PrivDataFullBox = new AnyPrivFullBox(bt, string.Empty);
                PrivDataFullBox.Read(reader);
                break;
            case "wfex": // AudioSampleEntry type is wma
                PrivDataBox = new AnyPrivBox(bt, string.Empty);
                PrivDataBox.Read(reader);
                break;
               case "damr": // 3gpp sound
                PrivDataFullBox = new AnyPrivFullBox(bt, string.Empty);
                PrivDataFullBox.Read(reader);
                break;
            default:
                throw new Exception(string.Format("AudioSampleEntry has unknown contents: {0}", bt.ToString()));
            }
              }
        }
示例#35
0
 public override void Read(BoxReader reader)
 {
     using (new SizeChecker(this, reader)) {
     base.Read(reader);
     reader.ReadInt32();
     reader.Read(handler_type, 0, 4);
     for (int i = 0; i < 3; i++) reader.ReadUInt32();
     Name = reader.ReadNullTerminatedString();
       // special case to take care of Apple's bug
       // (Apple and GoPro prepends the string with char count, but then adds one byte too many to the box size.)
     if (reader.BaseStream.Position != (long)(this.Size + this.Offset))
     {
     reader.BaseStream.Position = (long)(this.Size + this.Offset);
     Name = Name.Substring(1);
     }
       }
 }
示例#36
0
        public override void Read(BoxReader reader)
        {
            using (new SizeChecker(this, reader)) {
            base.Read(reader);

            EntryCount = reader.ReadUInt32();
            ChunkEntries = new ChunkEntry[EntryCount];

            for (int i = 0; i < EntryCount; i++) {
              ChunkEntries[i] = new ChunkEntry();
              ChunkEntries[i].firstChunk = reader.ReadUInt32();
              ChunkEntries[i].samplesPerChunk = reader.ReadUInt32();
              ChunkEntries[i].sampleDescriptionIndex = reader.ReadUInt32();
            }
              }
              if (parent.ChunkOffSetBox != null)
              TotalChunks = parent.ChunkOffSetBox.EntryCount;
        }
示例#37
0
        public override void Read(BoxReader reader)
        {
            using (new SizeChecker(this, reader)) {
            long curpos = reader.BaseStream.Position;

            base.Read(reader);
            major_brand = reader.ReadUInt32();
            minor_version = reader.ReadUInt32();
            int brand_count = (int)(this.Size - (ulong)(reader.BaseStream.Position - curpos)) / 4;
            compatible_brands = new uint[brand_count];
            for (int i=0; i<brand_count; i++) {
              compatible_brands[i] = reader.ReadUInt32();
            }
              }
        }
示例#38
0
        public override void Read(BoxReader reader)
        {
            using (new SizeChecker(this, reader)) {
            base.Read(reader);
            if (Version == 1) {
              creationTime = reader.ReadUInt64();
              modificationTime = reader.ReadUInt64();
              TimeScale = reader.ReadUInt32();
              Duration = reader.ReadUInt64();
            } else {
              creationTime = (UInt64)reader.ReadUInt32();
              modificationTime = (UInt64)reader.ReadUInt32();
              TimeScale = reader.ReadUInt32();
              Duration = (UInt64)reader.ReadUInt32();
            }

            // Set rate 16.16.
            rate[0] = reader.ReadUInt16();
            rate[1] = reader.ReadUInt16();

            // Set _volume.
            reader.Read(volume, 0, 2);

            reader.ReadInt16(); // bit[16] - reserved = 0
            for (int x = 0; x < 2; x++) reader.ReadUInt32(); // bit(32)[2] - pre_defined = 0
            this.Matrix.Read(reader);
            for (int x = 0; x < 6; x++) reader.ReadUInt32(); // bit(32)[6] - pre_defined = 0

            NextTrackID = reader.ReadUInt32();
              }
        }
示例#39
0
 public override void Read(BoxReader reader)
 {
     base.Read(reader);
       bufferSizeDB = reader.ReadUInt32();
       maxBitrate = reader.ReadUInt32();
       avgBitrate = reader.ReadUInt32();
 }
示例#40
0
 public override void Read(BoxReader reader)
 {
     using (new SizeChecker(this, reader))
       {
     base.Read(reader);
     hSpacing = reader.ReadUInt32();
     vSpacing = reader.ReadUInt32();
       }
 }
示例#41
0
 public override void Read(BoxReader reader)
 {
     using (new SizeChecker(this, reader))
       {
     base.Read(reader);
     CleanApertureWidthN = reader.ReadUInt32();
     CleanApertureWidthD = reader.ReadUInt32();
     CleanApertureHeightN = reader.ReadUInt32();
     CleanApertureHeightD = reader.ReadUInt32();
     HorizOffN = reader.ReadUInt32();
     HorizOffD = reader.ReadUInt32();
     VertOffN = reader.ReadUInt32();
     VertOffD = reader.ReadUInt32();
       }
 }
示例#42
0
        public override void Read(BoxReader reader)
        {
            using (new SizeChecker(this, reader)) {
            base.Read(reader);
            if (Version == 1) {
              creationTime = reader.ReadUInt64();
              modificationTime = reader.ReadUInt64();
              TrackID = reader.ReadUInt32();
              UInt32 reserved = reader.ReadUInt32(); // reserved = 0
              Duration = reader.ReadUInt64();
            } else {
              creationTime = (UInt32)reader.ReadUInt32();
              modificationTime = (UInt32)reader.ReadUInt32();
              TrackID = reader.ReadUInt32();
              reader.ReadUInt32(); // reserved = 0
              Duration = (UInt32)reader.ReadUInt32();
            }

            for (int x = 0; x < 2; x++) reader.ReadUInt32(); // int(32)[2] - reserved = 0  - 40 bytes
            Layer = reader.ReadUInt16(); // layer = 0
            AlternateGroup = reader.ReadUInt16(); // alternate_group = 0
            _volume = reader.ReadUInt16();
            reader.ReadUInt16(); // reserved = 0   -  48 bytes
            this.Matrix.Read(reader);
            _width = reader.ReadUInt32();
            _height = reader.ReadUInt32();
              }
        }
示例#43
0
        public override void Read(BoxReader reader)
        {
            using (new SizeChecker(this, reader)) {
            base.Read(reader);
            EntryCount = reader.ReadUInt32();
            Entries = new SampleEntry[EntryCount];
            for (int i=0; i<EntryCount; i++) {
              string FormatType = parent.parent.parent.HandlerReferenceBox.HandlerType;

              long pos = reader.BaseStream.Position;
              Box test = new Box(BoxTypes.Any);
              test.Read(reader);
              reader.BaseStream.Position = pos;

              switch (FormatType) {
            case "soun":
              AudioSampleEntry ase = new AudioSampleEntry(test.Type);
              ase.Read(reader);
              Entries[i] = ase;
              break;
            case "vide":
              VisualSampleEntry vse = new VisualSampleEntry(test.Type); // usually 'mp4v'
              vse.Read(reader);
              Entries[i] = vse;
              break;
            case "hint":
              HintSampleEntry hse = new HintSampleEntry(test.Type);
              hse.Read(reader);
              Entries[i] = hse;
              break;
            case "meta":
              switch (test.Type.ToString()) {
                case "metx":
                  XMLMetaDataSampleEntry xse = new XMLMetaDataSampleEntry();
                  xse.Read(reader);
                  Entries[i] = xse;
                  break;
                case "mett":
                  TextMetaDataSampleEntry tds = new TextMetaDataSampleEntry();
                  tds.Read(reader);
                  Entries[i] = tds;
                  break;
                default:
                  throw new Exception("Invalid Metadata Sample Entry in track");
              }
              break;
            //case "avcC":
            //    break;
            case "sdsm": // Apple MPEG-4 Scene Media Handler
              UnknownEntry ue = new UnknownEntry(test.Type);
              ue.Read(reader);
              Entries[i] = ue;
              break;
            case "odsm": // Apple MPEG-4 ODSM Media Handler
              UnknownEntry ue2 = new UnknownEntry(test.Type);
              ue2.Read(reader);
              Entries[i] = ue2;
              break;
            case "alis": // Apple iPhone
              UnknownEntry ue3 = new UnknownEntry(test.Type);
              ue3.Read(reader);
              Entries[i] = ue3;
              break;
            default:
              UnknownEntry ue4 = new UnknownEntry(test.Type);
              ue4.Read(reader);
              Entries[i] = ue4;
              break;
              }
            }
              }
        }
 public override void Read(BoxReader reader)
 {
     using (new SizeChecker(this, reader))
     {
       base.Read(reader);
       this.TrackId = reader.ReadUInt32();
       if (EnumUtils.IsBitSet<TrackFragmentHeaderBoxFlags>((TrackFragmentHeaderBoxFlags)base.Flags, TrackFragmentHeaderBoxFlags.BaseDataOffsetPresent))
       {
           this._baseDataOffset = reader.ReadUInt64();
       }
       if (EnumUtils.IsBitSet<TrackFragmentHeaderBoxFlags>((TrackFragmentHeaderBoxFlags)base.Flags, TrackFragmentHeaderBoxFlags.SampleDescriptionIndexPresent))
       {
           this._sampleDescriptionIndex = reader.ReadUInt32();
       }
       if (EnumUtils.IsBitSet<TrackFragmentHeaderBoxFlags>((TrackFragmentHeaderBoxFlags) base.Flags, TrackFragmentHeaderBoxFlags.DefaultSampleDurationPresent)) {
           this._defaultSampleDuration = reader.ReadUInt32();
       }
       if (EnumUtils.IsBitSet<TrackFragmentHeaderBoxFlags>((TrackFragmentHeaderBoxFlags) base.Flags, TrackFragmentHeaderBoxFlags.DefaultSampleSizePresent)) {
           this._defaultSampleSize = reader.ReadUInt32();
       }
       if (EnumUtils.IsBitSet<TrackFragmentHeaderBoxFlags>((TrackFragmentHeaderBoxFlags) base.Flags, TrackFragmentHeaderBoxFlags.DefaultSampleFlagsPresent)) {
           this._defaultSampleFlags = reader.ReadUInt32();
       }
     }
 }
示例#45
0
 public override void Read(BoxReader reader)
 {
     using (new SizeChecker(this, reader))
       {
     base.Read(reader);
     entryCount = reader.ReadUInt32();
     editList = new EditList[entryCount];
     for (int i = 0; i < entryCount; i++)
     {
       if (Version == 0)
       {
     editList[i].segmentDuration = reader.ReadUInt32();
     editList[i].mediaTime = reader.ReadInt32();
       }
       else // must be 1
       {
     editList[i].segmentDuration = reader.ReadUInt64();
     editList[i].mediaTime = reader.ReadInt64();
       }
       editList[i].mediaRateInteger = (short)reader.ReadInt16();
       editList[i].mediaRateFraction = (short)reader.ReadInt16();
     }
       }
 }
示例#46
0
        public override void Read(BoxReader reader)
        {
            using (new SizeChecker(this, reader)) {
            base.Read(reader);
            if (Version == 1) {
              creationTime = reader.ReadUInt64();
              modificationTime = reader.ReadUInt64();
              TimeScale = reader.ReadUInt32();
              Duration = reader.ReadUInt64();
            } else {
              creationTime = (UInt32)reader.ReadUInt32();
              modificationTime = (UInt32)reader.ReadUInt32();
              TimeScale = reader.ReadUInt32();
              Duration = (UInt32)reader.ReadUInt32();
            }

            language = reader.ReadUInt16();
            reader.ReadUInt16(); // pre_defined = 0
              }
        }
示例#47
0
        public void Read(BoxReader reader, byte version, uint LengthSizeOfTrafNum, uint LengthSizeOfTrunNum, uint LengthSizeOfSampleNum)
        {
            if (version == 1)
            {
                ulong tmpTime = reader.ReadUInt64();
//              if (tmpTime < LastTime) BaseTime = LastTime;
                this.Time       = BaseTime + tmpTime;
                this.MoofOffset = reader.ReadUInt64();
                LastTime        = Time;
            }
            else
            {
                this.Time       = reader.ReadUInt32();
                this.MoofOffset = reader.ReadUInt32();
            }

            switch (((LengthSizeOfTrafNum + 1) * 8))
            {
            case 0x18:
                this.TrafNumber = reader.ReadUInt24();
                break;

            case 0x20:
                this.TrafNumber = reader.ReadUInt32();
                break;

            case 8:
                this.TrafNumber = reader.ReadByte();
                break;

            case 0x10:
                this.TrafNumber = reader.ReadUInt16();
                break;
            }

            switch (((LengthSizeOfTrunNum + 1) * 8))
            {
            case 0x18:
                this.TrunNumber = reader.ReadUInt24();
                break;

            case 0x20:
                this.TrunNumber = reader.ReadUInt32();
                break;

            case 8:
                this.TrunNumber = reader.ReadByte();
                break;

            case 0x10:
                this.TrunNumber = reader.ReadUInt16();
                break;
            }

            switch (((LengthSizeOfSampleNum + 1) * 8))
            {
            case 8:
                this.SampleNumber = reader.ReadByte();
                return;

            case 0x10:
                this.SampleNumber = reader.ReadUInt16();
                break;

            case 0x18:
                this.SampleNumber = reader.ReadUInt24();
                return;

            case 0x20:
                this.SampleNumber = reader.ReadUInt32();
                return;
            }
        }
示例#48
0
 public void Read(BoxReader reader)
 {
     for (int i = 0; i < 9; i++) matrix[i] = reader.ReadUInt32(); // int(32)[9] - matrix
 }
示例#49
0
        public override void Read(BoxReader reader)
        {
            using (new SizeChecker(this, reader)) {
            long startpos = reader.BaseStream.Position;

            base.Read(reader);
            reader.ReadUInt16(); // pre_defined = 0;
            reader.ReadUInt16(); // reserved = 0;
            for (int i = 0; i < 3; i++) reader.ReadUInt32();  // unsigned int(32)[3] pre_defined = 0
            Width = reader.ReadUInt16();
            Height = reader.ReadUInt16();
            HorizResolution = reader.ReadUInt32(); // = 0x0048000 = 72 dpi
            VertResolution = reader.ReadUInt32(); // = 0x0048000 = 72 dpi
            reader.ReadUInt32(); // reserved = 0
            FrameCount = reader.ReadUInt16(); // frame_count = 1

            // Compressor name has first 2 bytes which is the readable length, the rest are char's or null bytes
            CompressorName = "";
            ushort len = reader.ReadUInt16();
            // NOTE: Some encoders use only one byte for count of compressor name, so here
            // we test for whether the length is valid. If not valid, only the first byte is
            // used as the length.
            if (len > 30)
            {
              byte[] b = BitConverter.GetBytes(len);
              if (BitConverter.IsLittleEndian)
              {
            len = (ushort)b[1];
            CompressorName += (char)b[0];
              }
              else
              {
            len = (ushort)b[0];
            CompressorName += (char)b[1];
              }
            }
            for (int i=0; i<30; i++) {
              if (i < len)
            CompressorName += reader.ReadChar();
              else
            reader.ReadChar();
            }
            CompressorName = CompressorName.Trim().Replace("\0","");
            Depth = reader.ReadUInt16(); // depth = 0x0018
            reader.ReadUInt16();  // pre_defined = -1

            bool bOptionalBoxFound = true;
            while (bOptionalBoxFound) {
              bOptionalBoxFound = false;
              long pos = reader.BaseStream.Position;
              Box test = new Box(BoxTypes.Any);
              test.Read(reader);
              reader.BaseStream.Position = pos;

              if (test.Type == BoxTypes.CleanApertureBox) {
            CleanApertureBox = new CleanApertureBox();
            CleanApertureBox.Read(reader);
            bOptionalBoxFound = true;
              } else

              if (test.Type == BoxTypes.PixelAspectRatio) {
            PixelAspectRatioBox = new PixelAspectRatioBox();
            PixelAspectRatioBox.Read(reader);
            bOptionalBoxFound = true;
              } else

              // retrieve CodecPrivateData from avcC
              if (test.Type == BoxTypes.AvcC) {
            AvcCBox = new AvcCBox();
            AvcCBox.Read(reader);

            //if ((ulong) (reader.BaseStream.Position - pos) < this.Size) {
            //  // klude to work around Expression problem (missing uuid, but box size large enough for it)
            //  pos = reader.BaseStream.Position;
            //  test = new Box(BoxTypes.Any);
            //  test.Read(reader);
            //  reader.BaseStream.Position = pos;

            //  if (test.Type == BoxTypes.UUID) {
            //    Uuid = new UuidBox();
            //    Uuid.Read(reader);
            //  }
            //}
            bOptionalBoxFound = true;
              } else

              if (test.Type == BoxTypes.UUID) {
            Uuid = new UuidBox();
            Uuid.Read(reader);
              } else

              if (test.Type == BoxTypes.Mp4v) {
            PrivDataFullBox = new AnyPrivFullBox();
            PrivDataFullBox.Read(reader);
            bOptionalBoxFound = true;
              } else

              if (test.Type == BoxTypes.Vc1) {
            PrivDataBox = new AnyPrivBox();
            PrivDataBox.Read(reader);
            bOptionalBoxFound = true;
              }
            }
              }
        }
示例#50
0
        public override void Read(BoxReader reader)
        {
            using (new SizeChecker(this, reader)) {
            base.Read(reader);

            sampleSize = reader.ReadUInt32();
            sampleCount = reader.ReadUInt32();
            if (sampleSize == 0)
            {
            sampleSizeArray = new uint[sampleCount];
            for (int i = 0; i < sampleCount; i++)
            {
              sampleSizeArray[i] = reader.ReadUInt32();
            }
            }

              }
        }
示例#51
0
 public override void Read(BoxReader reader)
 {
     using (new SizeChecker(this, reader)) {
     base.Read(reader);
     TrackID = reader.ReadUInt32();
     DefaultSampleDescriptionIndex = reader.ReadUInt32();
     DefaultSampleDuration = reader.ReadUInt32();
     DefaultSampleSize = reader.ReadUInt32();
     DefaultSampleFlags = reader.ReadUInt32();
       }
 }
示例#52
0
 /// <summary>
 /// Read
 /// NOTE: FirstSampleFlags and the flags in TrackFragmentRunSample are as follows:
 /// bit(6) reserved=0;                              // 6 bits reserved
 /// unsigned int(2) sample_depends_on;              // 2 bits used as int
 /// unsigned int(2) sample_is_depended_on;          // 2 bits used as int
 /// unsigned int(2) sample_has_redundancy;          // 2 bits used as int
 /// bit(3) sample_padding_value;                    // 3 bits
 /// bit(1) sample_is_difference_sample;             // 1 bit i.e. when 1 signals a non-key or non-sync sample
 /// unsigned int(16) sample_degradation_priority;   // 16 bits, total of 32 bits
 /// </summary>
 /// <param name="reader"></param>
 public override void Read(BoxReader reader)
 {
     using (new SizeChecker(this, reader)) {
     base.Read(reader);
     this.SampleCount = reader.ReadUInt32();
     if (EnumUtils.IsBitSet<TrackFragmentRunBoxFlags>((TrackFragmentRunBoxFlags)base.Flags, TrackFragmentRunBoxFlags.DataOffsetPresent))
     {
         this.DataOffset = reader.ReadUInt32();
     }
     if (EnumUtils.IsBitSet<TrackFragmentRunBoxFlags>((TrackFragmentRunBoxFlags)base.Flags, TrackFragmentRunBoxFlags.FirstSampleFlagsPresent))
     {
       this.FirstSampleFlags = reader.ReadUInt32();
     }
     this.Samples = new List<TrackFragmentRunSample>((int) this.SampleCount);
     for (int i = 0; i < this.SampleCount; i++) {
       TrackFragmentRunSample item = new TrackFragmentRunSample();
       item.Read(reader, base.Flags);
       this.Samples.Add(item);
       this.Duration += item.SampleDuration;
     }
       }
 }