/// <summary>
        /// Reads the box properties from stream.
        /// </summary>
        /// <param name="reader">The binary reader with the stream.</param>
        protected override void ReadBoxPropertiesFromStream(BoxBinaryReader reader)
        {
            this.reserved = reader.ReadBytes(6);
            this.DataReferenceIndex = reader.ReadUInt16();

            ReadSampleEntryPropertiesFromStream(reader);
        }
        /// <summary>
        /// Reads the full box properties from stream.
        /// </summary>
        /// <param name="reader">The binary reader with the stream.</param>
        protected override void ReadFullBoxPropertiesFromStream(BoxBinaryReader reader)
        {
            var sampleCount = reader.ReadUInt32();
            this.samples = new Sample[sampleCount];

            for (int i = 0; i < sampleCount; i++)
            {
                // TODO: Figure out the iv_size to read this value correctly.
                ulong initializationVector = reader.ReadUInt64();
                SubSample[] subSamples;

                if ((this.Flags & 0x02) == 0x02)
                {
                    var subSampleCount = reader.ReadUInt16();
                    subSamples = new SubSample[subSampleCount];

                    for (int j = 0; j < subSampleCount; j++)
                    {
                        subSamples[j] = new SubSample(
                            reader.ReadUInt16(),
                            reader.ReadUInt32());
                    }
                }
                else
                {
                    subSamples = new SubSample[0];
                }

                this.samples[i] = new Sample(initializationVector, subSamples);
            }
        }
        /// <summary>
        /// Reads the full box properties from stream.
        /// </summary>
        /// <param name="reader">The binary reader with the stream.</param>
        protected override void ReadFullBoxPropertiesFromStream(BoxBinaryReader reader)
        {
            this.TrackId = reader.ReadUInt32();
            
            uint num = reader.ReadUInt32();
            this.reserved = ((int)(num >> 6)) & 0x3ffffff;
            this.LengthSizeOfTrafNum = (byte)((num >> 4) & 3);
            this.LengthSizeOfTrunNum = (byte)((num >> 2) & 3);
            this.LengthSizeOfSampleNum = (byte)(num & 3);

            this.NumberOfEntry = reader.ReadUInt32();

            for (int i = 0; i < this.NumberOfEntry; i++)
            {
                TrackFragmentRandomAccessEntry entry = new TrackFragmentRandomAccessEntry();
                
                if (base.Version == 1)
                {
                    entry.Time = reader.ReadUInt64();
                    entry.MoofOffset = reader.ReadUInt64();
                }
                else
                {
                    entry.Time = reader.ReadUInt32();
                    entry.MoofOffset = reader.ReadUInt32();
                }

                entry.TrafNumber = ReadIntValueFromBytes(reader, this.LengthSizeOfTrafNum);
                entry.TrunNumber = ReadIntValueFromBytes(reader, this.LengthSizeOfTrunNum);
                entry.SampleNumber = ReadIntValueFromBytes(reader, this.LengthSizeOfSampleNum);
                               
                this.TrackFragmentRandomAccessEntries.Add(entry);
            }
        }
 /// <summary>
 /// Reads the full box properties from stream.
 /// </summary>
 /// <param name="reader">The binary reader with the stream.</param>
 protected override void ReadFullBoxPropertiesFromStream(BoxBinaryReader reader)
 {
     
     if (this.Version == 0)
     {
         this.CreationTime = Converter.SecondsOffsetToDateTimeUtc(reader.ReadUInt32());
         this.ModificationTime = Converter.SecondsOffsetToDateTimeUtc(reader.ReadUInt32());
         this.TrackId = reader.ReadUInt32();
         reserved1 = reader.ReadUInt32();
         this.Duration = reader.ReadUInt32();
     }
     else
     {
         this.CreationTime = Converter.SecondsOffsetToDateTimeUtc(reader.ReadUInt64());
         this.ModificationTime = Converter.SecondsOffsetToDateTimeUtc(reader.ReadUInt64());
         this.TrackId = reader.ReadUInt32();
         reserved1 = reader.ReadUInt32();
         this.Duration = reader.ReadUInt64();
     }
     reader.Read(reserved2, 0, 8);
     this.Layer = reader.ReadUInt16();
     this.AlternateGroup = reader.ReadUInt16();
     this.Volume = reader.ReadUInt16();
     reserved3 = reader.ReadUInt16();
     for (int i = 0; i < 9; i++)
     {
         matrix[i] = reader.ReadUInt32();
     }
     this.Width = reader.ReadUInt32();
     this.Height = reader.ReadUInt32();
 }
Example #5
0
        private static Stream TrimToBox(Stream stream, BoxType boxType)
        {
            long offset = 0;

            BoxBinaryReader reader = new BoxBinaryReader(stream);
            Box             box    = null;

            do
            {
                box = reader.ReadNextBox();
                if (box != null && box.Type == boxType)
                {
                    offset = box.Offset;
                    break;
                }
            } while (box != null);

            if (offset == 0)
            {
                return(stream);
            }
            else
            {
                stream.Seek(offset, SeekOrigin.Begin);
                var buffer = new byte[stream.Length - offset];
                stream.Read(buffer, 0, buffer.Length);
                return(new MemoryStream(buffer));
            }
        }
Example #6
0
        internal void ReadBoxFromStream(BoxBinaryReader reader)
        {
            if (this.Size == 0)
            {
                throw new BoxException("Zero size not supported!");
            }

            if (this.Size == 1)
            {
                this.Size = (long)reader.ReadUInt64();
            }

            ReadBoxPropertiesFromStream(reader);

            if (reader.Offset != this.Size + this.Offset)
            {
                string message = string.Format("The box was not totally read from the stream.\n\tBox Type: {0}, Reader Offset: {1}, Box Size: {2}, Box Offset {3}",
                                               this.GetType().Name, reader.Offset, this.Size, this.Offset);

#if DEBUG
                System.Diagnostics.Debug.WriteLine(message);
#endif
                reader.GotoEndOfBox(this.Offset, this.Size);
            }
        }
Example #7
0
 /// <summary>
 /// Reads the sub descriptors from the stream.
 /// </summary>
 /// <param name="reader">The binary stream reader.</param>
 /// <param name="initialOffset">The initial offset.</param>
 protected void ReadSubDescriptors(BoxBinaryReader reader, long initialOffset)
 {
     while (this.PayloadSize - (long)(reader.Offset - initialOffset) > 0)
     {
         this.SubDescriptors.Add(Descriptor.GetNextDescriptorFromStream(reader));
     }
 }
        /// <summary>
        /// Reads the box properties from stream.
        /// </summary>
        /// <param name="reader">The binary reader with the stream.</param>
        protected override void ReadBoxPropertiesFromStream(BoxBinaryReader reader)
        {
            var offset = reader.Offset;

            this.RawBytes = reader.ReadBytes((int)this.Size);
            reader.GotoPosition(offset);

            this.ConfigurationVersion = reader.ReadByte();
            this.AvcProfileIndication = reader.ReadByte();
            this.AvcCompatibleProfiles = reader.ReadByte();
            this.AvcLevelIndication = reader.ReadByte();            
            this.NaluLengthSize = (byte)(1 + (reader.ReadByte() & 3));

            var numSequenceParameters = (byte)(reader.ReadByte() & 0x1f);            
            for (uint i = 0; i < numSequenceParameters; i++)
            {
                var length = reader.ReadUInt16();
                this.SequenceParameters.Add(reader.ReadBytes(length));
            }

            var numPictureParameters = reader.ReadByte();            
            for (uint j = 0; j < numPictureParameters; j++)
            {
                var length = reader.ReadUInt16();
                this.PictureParameters.Add(reader.ReadBytes(length));
            }
        }
        /// <summary>
        /// Reads the box properties from stream.
        /// </summary>
        /// <param name="reader">The binary reader with the stream.</param>
        protected override void ReadBoxPropertiesFromStream(BoxBinaryReader reader)
        {
            var offset = reader.Offset;

            this.RawBytes = reader.ReadBytes((int)this.Size);
            reader.GotoPosition(offset);

            this.ConfigurationVersion  = reader.ReadByte();
            this.AvcProfileIndication  = reader.ReadByte();
            this.AvcCompatibleProfiles = reader.ReadByte();
            this.AvcLevelIndication    = reader.ReadByte();
            this.NaluLengthSize        = (byte)(1 + (reader.ReadByte() & 3));

            var numSequenceParameters = (byte)(reader.ReadByte() & 0x1f);

            for (uint i = 0; i < numSequenceParameters; i++)
            {
                var length = reader.ReadUInt16();
                this.SequenceParameters.Add(reader.ReadBytes(length));
            }

            var numPictureParameters = reader.ReadByte();

            for (uint j = 0; j < numPictureParameters; j++)
            {
                var length = reader.ReadUInt16();
                this.PictureParameters.Add(reader.ReadBytes(length));
            }
        }
Example #10
0
        /// <summary>
        /// Reads the box properties from stream.
        /// </summary>
        /// <param name="reader">The binary reader with the stream.</param>
        protected override void ReadBoxPropertiesFromStream(BoxBinaryReader reader)
        {
            this.reserved           = reader.ReadBytes(6);
            this.DataReferenceIndex = reader.ReadUInt16();

            ReadSampleEntryPropertiesFromStream(reader);
        }
        /// <summary>
        /// Reads the full box properties from stream.
        /// </summary>
        /// <param name="reader">The binary reader with the stream.</param>
        protected override void ReadFullBoxPropertiesFromStream(BoxBinaryReader reader)
        {
            var sampleCount = reader.ReadUInt32();

            this.samples = new Sample[sampleCount];

            for (int i = 0; i < sampleCount; i++)
            {
                // TODO: Figure out the iv_size to read this value correctly.
                ulong       initializationVector = reader.ReadUInt64();
                SubSample[] subSamples;

                if ((this.Flags & 0x02) == 0x02)
                {
                    var subSampleCount = reader.ReadUInt16();
                    subSamples = new SubSample[subSampleCount];

                    for (int j = 0; j < subSampleCount; j++)
                    {
                        subSamples[j] = new SubSample(
                            reader.ReadUInt16(),
                            reader.ReadUInt32());
                    }
                }
                else
                {
                    subSamples = new SubSample[0];
                }

                this.samples[i] = new Sample(initializationVector, subSamples);
            }
        }
        /// <summary>
        /// Reads the full box properties from stream.
        /// </summary>
        /// <param name="reader">The binary reader with the stream.</param>
        protected override void ReadFullBoxPropertiesFromStream(BoxBinaryReader reader)
        {
            if (base.Version == 0)
            {
                this.CreationTimeUtc     = Converter.SecondsOffsetToDateTimeUtc(reader.ReadUInt32());
                this.ModificationTimeUtc = Converter.SecondsOffsetToDateTimeUtc(reader.ReadUInt32());
                this.TimeScale           = reader.ReadUInt32();
                this.Duration            = reader.ReadUInt32();
            }
            else
            {
                this.CreationTimeUtc     = Converter.SecondsOffsetToDateTimeUtc(reader.ReadUInt64());
                this.ModificationTimeUtc = Converter.SecondsOffsetToDateTimeUtc(reader.ReadUInt64());
                this.TimeScale           = reader.ReadUInt32();
                this.Duration            = reader.ReadUInt64();
            }

            this.Rate   = reader.ReadUInt32();
            this.Volume = reader.ReadUInt16();
            reader.Read(reserved1, 0, reserved1.Length);
            reader.Read(reserved2, 0, reserved2.Length);
            for (int i = 0; i < 9; i++)
            {
                matrix[i] = reader.ReadUInt32();
            }
            reader.Read(predefined, 0, predefined.Length);
            this.NextTrackId = reader.ReadUInt32();
        }
        /// <summary>
        /// Reads the sample entry properties from stream.
        /// </summary>
        /// <param name="reader">The stream reader.</param>
        internal override void ReadSampleEntryPropertiesFromStream(BoxBinaryReader reader)
        {
            predefined1          = reader.ReadUInt16();
            reserved1            = reader.ReadUInt16();
            predefined2          = reader.ReadBytes(12);
            this.Width           = reader.ReadUInt16();
            this.Height          = reader.ReadUInt16();
            this.HorizResolution = reader.ReadUInt32();
            this.VertResolution  = reader.ReadUInt32();
            reserved2            = reader.ReadUInt32();
            this.FrameCount      = reader.ReadUInt16();

            byte[] buffer = new byte[0x20];
            reader.Read(buffer, 0, 0x20);
            int count = buffer[0];

            if (count < 0x20)
            {
                this.CompressorName = Encoding.UTF8.GetString(buffer, 1, count);
            }
            this.Depth  = reader.ReadUInt16();
            predefined3 = reader.ReadUInt16();

            if (reader.PeekNextBoxType() != BoxType.Null)
            {
                ReadInnerBoxes(reader, BoxType.Esds, BoxType.Avcc, BoxType.Avc1, BoxType.Dvc1, BoxType.Btrt, BoxType.Sinf);
                this.VideoCodecData = GetVideoCodecDataFromInnerBoxes();
            }
            else
            {
                var videoInfoHeader = new VideoInfoHeader2(reader);
                this.VideoCodecData = new VideoTrackCodecData(videoInfoHeader);
            }
        }
        /// <summary>
        /// Reads the full box properties from stream.
        /// </summary>
        /// <param name="reader">The binary reader with the stream.</param>
        protected override void ReadFullBoxPropertiesFromStream(BoxBinaryReader reader)
        {          
            if (base.Version == 0)
            {
                this.CreationTimeUtc = Converter.SecondsOffsetToDateTimeUtc(reader.ReadUInt32());
                this.ModificationTimeUtc = Converter.SecondsOffsetToDateTimeUtc(reader.ReadUInt32());
                this.TimeScale = reader.ReadUInt32();
                this.Duration = reader.ReadUInt32();
            }
            else
            {
                this.CreationTimeUtc = Converter.SecondsOffsetToDateTimeUtc(reader.ReadUInt64());
                this.ModificationTimeUtc = Converter.SecondsOffsetToDateTimeUtc(reader.ReadUInt64());
                this.TimeScale = reader.ReadUInt32();
                this.Duration = reader.ReadUInt64();
            }

            this.Rate = reader.ReadUInt32();
            this.Volume = reader.ReadUInt16();
            reader.Read(reserved1, 0, reserved1.Length);
            reader.Read(reserved2, 0, reserved2.Length);
            for (int i = 0; i < 9; i++)
            {
                matrix[i] = reader.ReadUInt32();
            }
            reader.Read(predefined, 0, predefined.Length);
            this.NextTrackId = reader.ReadUInt32();

        }
        /// <summary>
        /// Reads the full box properties from stream.
        /// </summary>
        /// <param name="reader">The binary reader with the stream.</param>
        protected override void ReadFullBoxPropertiesFromStream(BoxBinaryReader reader)
        {
            this.TrackId = reader.ReadUInt32();

            uint num = reader.ReadUInt32();

            this.reserved              = ((int)(num >> 6)) & 0x3ffffff;
            this.LengthSizeOfTrafNum   = (byte)((num >> 4) & 3);
            this.LengthSizeOfTrunNum   = (byte)((num >> 2) & 3);
            this.LengthSizeOfSampleNum = (byte)(num & 3);

            this.NumberOfEntry = reader.ReadUInt32();

            for (int i = 0; i < this.NumberOfEntry; i++)
            {
                TrackFragmentRandomAccessEntry entry = new TrackFragmentRandomAccessEntry();

                if (base.Version == 1)
                {
                    entry.Time       = reader.ReadUInt64();
                    entry.MoofOffset = reader.ReadUInt64();
                }
                else
                {
                    entry.Time       = reader.ReadUInt32();
                    entry.MoofOffset = reader.ReadUInt32();
                }

                entry.TrafNumber   = ReadIntValueFromBytes(reader, this.LengthSizeOfTrafNum);
                entry.TrunNumber   = ReadIntValueFromBytes(reader, this.LengthSizeOfTrunNum);
                entry.SampleNumber = ReadIntValueFromBytes(reader, this.LengthSizeOfSampleNum);

                this.TrackFragmentRandomAccessEntries.Add(entry);
            }
        }
Example #16
0
        private async Task <Box> GetBox(BoxType boxType)
        {
            // get the box size
            var size = await this.GetBoxSize(this.fileOffset);

            // gets the box
            var stream = await WebRequestor.GetStreamRangeAsync(this.fileUri, this.fileOffset, this.fileOffset + (long)size);

            Box box = null;

            using (var boxReader = new BoxBinaryReader(stream))
            {
                box              = boxReader.ReadNextBox();
                this.fileOffset += (long)size;
            }

            if (box.Type == boxType)
            {
                return(box);
            }
            else
            {
                return(await this.GetBox(boxType));
            }
        }
 /// <summary>
 /// Initializes a new instance of the <see cref="Rectangle"/> class.
 /// </summary>
 /// <param name="reader">The box binary reader.</param>
 public Rectangle(BoxBinaryReader reader)
 {
     this.Left = reader.ReadUInt32();
     this.Top = reader.ReadUInt32();
     this.Right = reader.ReadUInt32();
     this.Bottom = reader.ReadUInt32();
 }
Example #18
0
 /// <summary>
 /// Initializes a new instance of the <see cref="Rectangle"/> class.
 /// </summary>
 /// <param name="reader">The box binary reader.</param>
 public Rectangle(BoxBinaryReader reader)
 {
     this.Left   = reader.ReadUInt32();
     this.Top    = reader.ReadUInt32();
     this.Right  = reader.ReadUInt32();
     this.Bottom = reader.ReadUInt32();
 }
Example #19
0
 /// <summary>
 /// Reads the full box properties from stream.
 /// </summary>
 /// <param name="reader">The binary reader with the stream.</param>
 protected override void ReadFullBoxPropertiesFromStream(BoxBinaryReader reader)
 {
     if (this.Version == 0)
     {
         this.CreationTime     = Converter.SecondsOffsetToDateTimeUtc(reader.ReadUInt32());
         this.ModificationTime = Converter.SecondsOffsetToDateTimeUtc(reader.ReadUInt32());
         this.TrackId          = reader.ReadUInt32();
         reserved1             = reader.ReadUInt32();
         this.Duration         = reader.ReadUInt32();
     }
     else
     {
         this.CreationTime     = Converter.SecondsOffsetToDateTimeUtc(reader.ReadUInt64());
         this.ModificationTime = Converter.SecondsOffsetToDateTimeUtc(reader.ReadUInt64());
         this.TrackId          = reader.ReadUInt32();
         reserved1             = reader.ReadUInt32();
         this.Duration         = reader.ReadUInt64();
     }
     reader.Read(reserved2, 0, 8);
     this.Layer          = reader.ReadUInt16();
     this.AlternateGroup = reader.ReadUInt16();
     this.Volume         = reader.ReadUInt16();
     reserved3           = reader.ReadUInt16();
     for (int i = 0; i < 9; i++)
     {
         matrix[i] = reader.ReadUInt32();
     }
     this.Width  = reader.ReadUInt32();
     this.Height = reader.ReadUInt32();
 }
Example #20
0
        /// <summary>
        /// Read the next descriptor from the stream.
        /// </summary>
        /// <param name="reader">The stream reader.</param>
        public static Descriptor GetNextDescriptorFromStream(BoxBinaryReader reader)
        {
            if (reader == null || reader.AtEndOfStream)
            {
                return(null);
            }

            Descriptor descriptor = null;

            var offset = reader.Offset;
            var tag    = (DescriptorTag)reader.ReadByte();


            uint payloadSize   = 0;
            uint headerSize    = 1;
            uint maxHeaderSize = 4;
            byte num;

            do
            {
                headerSize++;
                num         = reader.ReadByte();
                payloadSize = (payloadSize << 7) + ((uint)(num & 0x7f));
            }while ((--maxHeaderSize != 0) && ((num & 0x80) != 0));

            switch (tag)
            {
            case DescriptorTag.ES:
                descriptor = new ElementaryStreamDescriptor(headerSize, payloadSize);
                break;

            case DescriptorTag.DECODER_CONFIG:
                descriptor = new DecoderConfigurationDescriptor(headerSize, payloadSize);
                break;

            case DescriptorTag.DECODER_SPECIFIC_INFO:
                descriptor = new DecoderSpecificInformationDescriptor(headerSize, payloadSize);
                break;

            case DescriptorTag.SL_CONFIG:
                descriptor = new SyncronizationConfigurationDescriptor(headerSize, payloadSize);
                break;

            default:
                break;
            }

            if (descriptor != null)
            {
                descriptor.ReadDescriptorPropertiesFromStream(reader);
            }

            if (reader.Offset != offset + descriptor.PayloadSize + descriptor.HeaderSize)
            {
                throw new BoxException(string.Format("The descriptor {0} was not totally read from the stream", tag));
            }

            return(descriptor);
        }
        /// <summary>
        /// Reads the box properties from stream.
        /// </summary>
        /// <param name="reader">The binary reader with the stream.</param>
        protected override void ReadBoxPropertiesFromStream(BoxBinaryReader reader)
        {
            uint versionAndFlags = reader.ReadUInt32();
            this.Version = (versionAndFlags >> 0x18) & 0xff;
            this.Flags = versionAndFlags & 0xffffff;

            ReadFullBoxPropertiesFromStream(reader);
        }
Example #22
0
        /// <summary>
        /// Reads the sample entry properties from stream.
        /// </summary>
        /// <param name="reader">The stream reader.</param>
        internal override void ReadSampleEntryPropertiesFromStream(BoxBinaryReader reader)
        {
            this.Namespace      = reader.ReadNullTerminatedString();
            this.SchemaLocation = reader.ReadNullTerminatedString();
            this.ImageMimeType  = reader.ReadNullTerminatedString();

            ReadInnerBoxes(reader, BoxType.Btrt);
        }
 /// <summary>
 /// Reads the full box properties from stream.
 /// </summary>
 /// <param name="reader">The binary reader with the stream.</param>
 protected override void ReadFullBoxPropertiesFromStream(BoxBinaryReader reader)
 {
     OffsetCount = reader.ReadUInt32();
     for (int i = 0; i < OffsetCount; i++)
     {
         Offsets.Add(reader.ReadUInt32());
     }
 }
        /// <summary>
        /// Reads the full box properties from stream.
        /// </summary>
        /// <param name="reader">The binary reader with the stream.</param>
        protected override void ReadFullBoxPropertiesFromStream(BoxBinaryReader reader)
        {
            ProfileVersion = reader.ReadString(4);      // Is this actually a string?
            Apid = reader.ReadNullTerminatedString();

            // TODO: Do we need to read in the other_boxes?
            reader.GotoEndOfBox(this.Offset, this.Size);
        }
 /// <summary>
 /// Reads the full box properties from stream.
 /// </summary>
 /// <param name="reader">The binary reader with the stream.</param>
 protected override void ReadFullBoxPropertiesFromStream(BoxBinaryReader reader)
 {
     OffsetCount = reader.ReadUInt32();
     for (int i = 0; i < OffsetCount; i++)
     {
         Offsets.Add(reader.ReadUInt32());
     }
 }
        /// <summary>
        /// Reads the full box properties from stream.
        /// </summary>
        /// <param name="reader">The binary reader with the stream.</param>
        protected override void ReadFullBoxPropertiesFromStream(BoxBinaryReader reader)
        {
            ProfileVersion = reader.ReadString(4);      // Is this actually a string?
            Apid           = reader.ReadNullTerminatedString();

            // TODO: Do we need to read in the other_boxes?
            reader.GotoEndOfBox(this.Offset, this.Size);
        }
        /// <summary>
        /// Reads the sample entry properties from stream.
        /// </summary>
        /// <param name="reader">The stream reader.</param>
        internal override void ReadSampleEntryPropertiesFromStream(BoxBinaryReader reader)
        {
            this.Namespace = reader.ReadNullTerminatedString();
            this.SchemaLocation = reader.ReadNullTerminatedString();
            this.ImageMimeType = reader.ReadNullTerminatedString();

            ReadInnerBoxes(reader, BoxType.Btrt);
        }
 /// <summary>
 /// Reads the full box properties from stream.
 /// </summary>
 /// <param name="reader">The binary reader with the stream.</param>
 protected override void ReadFullBoxPropertiesFromStream(BoxBinaryReader reader)
 {
     Count = reader.ReadUInt32();
     for (int i = 0; i < Count; i++)
     {
         var entry = new DecodingTimeToSampleFullBoxEntry(reader.ReadUInt32(), reader.ReadUInt32());
         Entries.Add(entry);
     }
 }
 /// <summary>
 /// Reads the box properties from stream.
 /// </summary>
 /// <param name="reader">The binary reader with the stream.</param>
 protected override void ReadBoxPropertiesFromStream(BoxBinaryReader reader)
 {
     long num = this.Size - 8;
     while (num >= 4)
     {
         this.TrackIds.Add(reader.ReadUInt32());
         num -= 4;
     }
 }
Example #30
0
        /// <summary>
        /// Reads the box properties from stream.
        /// </summary>
        /// <param name="reader">The binary reader with the stream.</param>
        protected override void ReadBoxPropertiesFromStream(BoxBinaryReader reader)
        {
            uint versionAndFlags = reader.ReadUInt32();

            this.Version = (versionAndFlags >> 0x18) & 0xff;
            this.Flags   = versionAndFlags & 0xffffff;

            ReadFullBoxPropertiesFromStream(reader);
        }
 /// <summary>
 /// Reads the full box properties from stream.
 /// </summary>
 /// <param name="reader">The binary reader with the stream.</param>
 protected override void ReadFullBoxPropertiesFromStream(BoxBinaryReader reader)
 {
     Count = reader.ReadUInt32();
     for (int i = 0; i < Count; i++)
     {
         var entry = new DecodingTimeToSampleFullBoxEntry(reader.ReadUInt32(), reader.ReadUInt32());
         Entries.Add(entry);
     }
 }
Example #32
0
        private async Task <ulong> GetBoxSize(long position)
        {
            var stream = await WebRequestor.GetStreamRangeAsync(this.fileUri, position, position + 16);

            using (var reader = new BoxBinaryReader(stream))
            {
                var size = this.ReadBoxSize(reader);
                return(size);
            }
        }
 /// <summary>
 /// Reads the box properties from stream.
 /// </summary>
 /// <param name="reader">The binary reader with the stream.</param>
 /// <remarks>
 /// The CFF format makes the following changes.
 /// * MajorBrand will be set to "ccff"
 /// * MinorVersion will be set to 0x00000000
 /// * CompatibleBrands will have at least one additional brand encoded with "iso6"
 /// </remarks>
 protected override void ReadBoxPropertiesFromStream(BoxBinaryReader reader)
 {
     this.MajorBrand = reader.ReadString(4);
     this.MinorVersion = reader.ReadUInt32();
     
     while (reader.Offset < this.Offset + this.Size)
     {
         this.CompatibleBrands.Add(reader.ReadString(4));
     }
 }
 private static async Task <IList <Box> > GetBoxesAsync(Uri uri, WebRequestor.Range range)
 {
     using (var stream = await WebRequestor.GetStreamRangeAsync(uri, range))
     {
         using (var reader = new BoxBinaryReader(stream))
         {
             return(reader.GetAllBoxes());
         }
     }
 }
Example #35
0
        /// <summary>
        /// Reads the box properties from stream.
        /// </summary>
        /// <param name="reader">The binary reader with the stream.</param>
        /// <remarks>
        /// The CFF format makes the following changes.
        /// * MajorBrand will be set to "ccff"
        /// * MinorVersion will be set to 0x00000000
        /// * CompatibleBrands will have at least one additional brand encoded with "iso6"
        /// </remarks>
        protected override void ReadBoxPropertiesFromStream(BoxBinaryReader reader)
        {
            this.MajorBrand   = reader.ReadString(4);
            this.MinorVersion = reader.ReadUInt32();

            while (reader.Offset < this.Offset + this.Size)
            {
                this.CompatibleBrands.Add(reader.ReadString(4));
            }
        }
Example #36
0
        /// <summary>
        /// Reads the box properties from stream.
        /// </summary>
        /// <param name="reader">The binary reader with the stream.</param>
        protected override void ReadBoxPropertiesFromStream(BoxBinaryReader reader)
        {
            long num = this.Size - 8;

            while (num >= 4)
            {
                this.TrackIds.Add(reader.ReadUInt32());
                num -= 4;
            }
        }
        /// <summary>
        /// Reads the box properties from stream.
        /// </summary>
        /// <param name="reader">The binary reader with the stream.</param>
        protected override void ReadBoxPropertiesFromStream(BoxBinaryReader reader)
        {
            var num = reader.ReadByte();

            this.Profile = (num >> 6);
            this.Level = (num & 0xF) >> 1;
            this.AdvancedProfileLevel = reader.ReadByte() >> 5;
            this.flags = reader.ReadByte(); //no_interlace, no_multiple_seq, no_multiple_entry, no_slice_code, no_bframe            
            this.Framerate = reader.ReadUInt32();
            this.CodecPrivateData = reader.ReadBytes((int)(this.Size - (reader.Offset - this.Offset)));
        }
        /// <summary>
        /// Reads the full box properties from stream.
        /// </summary>
        /// <param name="reader">The binary reader with the stream.</param>
        protected override void ReadFullBoxPropertiesFromStream(BoxBinaryReader reader)
        {
            this.SystemId = reader.ReadGuid();
            if (string.Compare(this.SystemId.ToString(), "9A04F079-9840-4286-AB92-E65BE0885F95", StringComparison.OrdinalIgnoreCase) != 0)
            {
                throw new BoxException(string.Format("The specified protection system id \"{0}\" is not supported", this.SystemId));
            }

            this.DataSize = reader.ReadUInt32();
            this.Data = reader.ReadBytes(System.Convert.ToInt32(this.DataSize));
        }
        /// <summary>
        /// Reads the full box properties from stream.
        /// </summary>
        /// <param name="reader">The binary reader with the stream.</param>
        protected override void ReadFullBoxPropertiesFromStream(BoxBinaryReader reader)
        {
            predefined = reader.ReadUInt32();
            this.HandlerType = new string(reader.ReadChars(4));
            
            reserved[0] = reader.ReadUInt32();
            reserved[1] = reader.ReadUInt32();
            reserved[2] = reader.ReadUInt32();

            this.Name = reader.ReadNullTerminatedString();
        }
Example #40
0
        /// <summary>
        /// Reads the box properties from stream.
        /// </summary>
        /// <param name="reader">The binary reader with the stream.</param>
        protected override void ReadBoxPropertiesFromStream(BoxBinaryReader reader)
        {
            var num = reader.ReadByte();

            this.Profile = (num >> 6);
            this.Level   = (num & 0xF) >> 1;
            this.AdvancedProfileLevel = reader.ReadByte() >> 5;
            this.flags            = reader.ReadByte(); //no_interlace, no_multiple_seq, no_multiple_entry, no_slice_code, no_bframe
            this.Framerate        = reader.ReadUInt32();
            this.CodecPrivateData = reader.ReadBytes((int)(this.Size - (reader.Offset - this.Offset)));
        }
        /// <summary>
        /// Reads the full box properties from stream.
        /// </summary>
        /// <param name="reader">The binary reader with the stream.</param>
        protected override void ReadFullBoxPropertiesFromStream(BoxBinaryReader reader)
        {
            predefined       = reader.ReadUInt32();
            this.HandlerType = new string(reader.ReadChars(4));

            reserved[0] = reader.ReadUInt32();
            reserved[1] = reader.ReadUInt32();
            reserved[2] = reader.ReadUInt32();

            this.Name = reader.ReadNullTerminatedString();
        }
        /// <summary>
        /// Reads the full box properties from stream.
        /// </summary>
        /// <param name="reader">The binary reader with the stream.</param>
        protected override void ReadFullBoxPropertiesFromStream(BoxBinaryReader reader)
        {
            this.SystemId = reader.ReadGuid();
            if (string.Compare(this.SystemId.ToString(), "9A04F079-9840-4286-AB92-E65BE0885F95", StringComparison.OrdinalIgnoreCase) != 0)
            {
                throw new BoxException(string.Format("The specified protection system id \"{0}\" is not supported", this.SystemId));
            }

            this.DataSize = reader.ReadUInt32();
            this.Data     = reader.ReadBytes(System.Convert.ToInt32(this.DataSize));
        }
 /// <summary>
 /// Reads the full box properties from stream.
 /// </summary>
 /// <param name="reader">The binary reader with the stream.</param>
 protected override void ReadFullBoxPropertiesFromStream(BoxBinaryReader reader)
 {
     ConstantSize = reader.ReadUInt32();
     SizeCount = reader.ReadUInt32();
     if (ConstantSize == 0)
     {
         for (int i = 0; i < SizeCount; i++)
         {
             SizeTable.Add(reader.ReadUInt32());
         }
     }
 }
Example #44
0
 /// <summary>
 /// Reads the full box properties from stream.
 /// </summary>
 /// <param name="reader">The binary reader with the stream.</param>
 protected override void ReadFullBoxPropertiesFromStream(BoxBinaryReader reader)
 {
     ConstantSize = reader.ReadUInt32();
     SizeCount    = reader.ReadUInt32();
     if (ConstantSize == 0)
     {
         for (int i = 0; i < SizeCount; i++)
         {
             SizeTable.Add(reader.ReadUInt32());
         }
     }
 }
 /// <summary>
 /// Reads the full box properties from stream.
 /// </summary>
 /// <param name="reader">The binary reader with the stream.</param>
 protected override void ReadFullBoxPropertiesFromStream(BoxBinaryReader reader)
 {
     switch (this.Version)
     {
         case 1:
             this.BaseMediaDecodeTime = reader.ReadInt64();
             break;
         case 0:
             this.BaseMediaDecodeTime = reader.ReadInt32();
             break;
     }
 }
        /// <summary>
        /// Reads the full box properties from stream.
        /// </summary>
        /// <param name="reader">The binary reader with the stream.</param>
        protected override void ReadFullBoxPropertiesFromStream(BoxBinaryReader reader)
        {
            this.GroupingType = reader.ReadUInt32();
            this.EntryCount = reader.ReadUInt32();

            for (var i = 0; i < this.EntryCount; i++)
            {
                uint sampleCount = reader.ReadUInt32();
                uint groupDescriptionIndex = reader.ReadUInt32();

                this.Entries.Add(new SampleToGroupFullBoxEntry(sampleCount, groupDescriptionIndex));
            }
        }
Example #47
0
        /// <summary>
        /// Reads the full box properties from stream.
        /// </summary>
        /// <param name="reader">The binary reader with the stream.</param>
        protected override void ReadFullBoxPropertiesFromStream(BoxBinaryReader reader)
        {
            this.GroupingType = reader.ReadUInt32();
            this.EntryCount   = reader.ReadUInt32();

            for (var i = 0; i < this.EntryCount; i++)
            {
                uint sampleCount           = reader.ReadUInt32();
                uint groupDescriptionIndex = reader.ReadUInt32();

                this.Entries.Add(new SampleToGroupFullBoxEntry(sampleCount, groupDescriptionIndex));
            }
        }
        /// <summary>
        /// Reads the full box properties from stream.
        /// </summary>
        /// <param name="reader">The binary reader with the stream.</param>
        protected override void ReadFullBoxPropertiesFromStream(BoxBinaryReader reader)
        {
            switch (this.Version)
            {
            case 1:
                this.BaseMediaDecodeTime = reader.ReadInt64();
                break;

            case 0:
                this.BaseMediaDecodeTime = reader.ReadInt32();
                break;
            }
        }
        /// <summary>
        /// Reads the box properties from stream.
        /// </summary>
        /// <param name="reader">The binary reader with the stream.</param>
        protected override void ReadFullBoxPropertiesFromStream(BoxBinaryReader reader)
        {
            this.ReferenceTrackID = reader.ReadUInt32();
            this.NtpTimestamp = reader.ReadUInt64();

            if (this.Version == 0)
            {
                this.MediaTime = reader.ReadUInt32();
            }
            else
            {
                this.MediaTime = reader.ReadUInt64();
            }
        }
Example #50
0
        protected ulong ReadBoxSize(BoxBinaryReader reader)
        {
            ulong size = 0;

            size = reader.ReadUInt32();

            if (size == 1)
            {
                reader.BaseStream.Seek(4, SeekOrigin.Current);  // Skip over the box type
                size = reader.ReadUInt64();
            }

            return(size);
        }
 /// <summary>
 /// Initializes a new instance of the <see cref="WaveFormatEx"/> class.
 /// </summary>
 /// <param name="reader">The binary stream reader.</param>
 public WaveFormatEx(BoxBinaryReader reader)
 {
     this.FormatTag = reader.ReadInt16();
     this.Channels = reader.ReadInt16();
     this.SamplesPerSec = reader.ReadInt32();
     this.AvgBytesPerSec = reader.ReadInt32(); ;
     this.BlockAlign = reader.ReadInt16();
     this.BitsPerSample = reader.ReadInt16();
     this.Size = reader.ReadInt16();
     if (this.Size > 0)
     {
         this.ExtendedData = reader.ReadBytes(this.Size);
     }
 }
        /// <summary>
        /// Reads the full box properties from stream.
        /// </summary>
        /// <param name="reader">The binary reader with the stream.</param>
        protected override void ReadFullBoxPropertiesFromStream(BoxBinaryReader reader)
        {
            int capacity = ((int)Size) - 12;
            for (int i = 0; i < capacity; i++)
            {
                var sample = new Sample();

                byte num = reader.ReadByte();
                sample.SampleDependsOn = (num & 0x30) >> 4;
                sample.SampleIsDependedOn = (num & 12) >> 2;
                sample.SampleHasRedundancy = num & 3;
                this.Samples.Add(sample);
            }
        }
Example #53
0
 /// <summary>
 /// Initializes a new instance of the <see cref="WaveFormatEx"/> class.
 /// </summary>
 /// <param name="reader">The binary stream reader.</param>
 public WaveFormatEx(BoxBinaryReader reader)
 {
     this.FormatTag      = reader.ReadInt16();
     this.Channels       = reader.ReadInt16();
     this.SamplesPerSec  = reader.ReadInt32();
     this.AvgBytesPerSec = reader.ReadInt32();;
     this.BlockAlign     = reader.ReadInt16();
     this.BitsPerSample  = reader.ReadInt16();
     this.Size           = reader.ReadInt16();
     if (this.Size > 0)
     {
         this.ExtendedData = reader.ReadBytes(this.Size);
     }
 }
        /// <summary>
        /// Reads the descriptor properties from stream.
        /// </summary>
        /// <param name="reader">The binary reader with the stream.</param>
        protected override void ReadDescriptorPropertiesFromStream(BoxBinaryReader reader)
        {

            var initialOffset = reader.Offset;

            this.ObjectTypeIndication = (DecoderObjectTypes)reader.ReadByte();
            byte num = reader.ReadByte();
            this.StreamType = (byte)((num >> 2) & 0x3f);
            this.UpStream = (num & 2) != 0;
            this.BufferSize = reader.ReadUInt24();
            this.MaxBitrate = reader.ReadUInt32();
            this.AverageBitrate = reader.ReadUInt32();

            ReadSubDescriptors(reader, initialOffset);
        }
        /// <summary>
        /// Reads the sample entry properties from stream.
        /// </summary>
        /// <param name="reader">The stream reader.</param>
        internal override void ReadSampleEntryPropertiesFromStream(BoxBinaryReader reader)
        {           
            switch(this.Type)
            {
                case BoxType.Enca:
                    this.OriginalSampleEntryData = new AudioSampleEntryBox(reader.Offset, this.Size - (reader.Offset - this.Offset));                    
                    break;
                case BoxType.Encv:
                    this.OriginalSampleEntryData = new VisualSampleEntryBox(reader.Offset, this.Size - (reader.Offset - this.Offset));
                    break;
            }

            this.OriginalSampleEntryData.ReadSampleEntryPropertiesFromStream(reader);
            
            ReadInnerBoxes(reader, BoxType.Sinf);
        }
        /// <summary>
        /// Reads the box properties from stream.
        /// </summary>
        /// <param name="reader">The binary reader with the stream.</param>
        protected override void ReadFullBoxPropertiesFromStream(BoxBinaryReader reader)
        {
            if ((this.Flags & 1) != 0)
            {
                this.AuxInfoType = reader.ReadUInt32();
                this.AuxInfoTypeParameter = reader.ReadUInt32();
            }

            this.DefaultSampleInfoSize = reader.ReadByte();
            this.SampleCount = reader.ReadUInt32();

            if (this.DefaultSampleInfoSize == 0)
            {
                this.SampleInfoSize = reader.ReadBytes(System.Convert.ToInt32(this.SampleCount));
            }
        }
        /// <summary>
        /// Gets the next extension box from stream.
        /// </summary>
        /// <param name="reader">The box stream reader.</param>
        /// <param name="offset">The current box stream offset.</param>
        /// <param name="size">The box size.</param>
        /// <returns></returns>
        public static Box GetNextBoxFromStream(BoxBinaryReader reader, long offset, uint size)
        {
            Guid extendedType = reader.PeekEntensionType(size == 1 ? 8 : 0);

            switch (extendedType.ToString().ToUpper())
            {
                case "A2394F52-5A9B-4F14-A244-6C427C648DF4":
                    return new SampleEncryptionFullBox(offset, size);
                case "6D1D9B05-42D5-44E6-80E2-141DAFF757B2":
                    return new TrackFragmentExtendedHeaderBox(offset, size);
                //case "6B6840F2-5F24-4FC5-BA39-A51BCF0323F3": ???
                //case "D08A4F18-10F3-4A82-B6C8-32D8ABA183D3":
                //    return new ProtectionSystemSpecificHeaderFullBox(offset, size);
                default:
                    return new UnknownBox(offset, size);
                    //reader.GotoEndOfBox(offset, size);
                    //return null;
            }
        }
        /// <summary>
        /// Reads the full box properties from stream.
        /// </summary>
        /// <param name="reader">The binary reader with the stream.</param>
        protected override void ReadFullBoxPropertiesFromStream(BoxBinaryReader reader)
        {
            if (this.Version == 1)
            {
                reader.BaseStream.Seek(16, System.IO.SeekOrigin.Current);
                this.Timescale = reader.ReadUInt32();
                this.Duration = reader.ReadUInt64();
            }
            else
            {
                reader.BaseStream.Seek(8, System.IO.SeekOrigin.Current);
                this.Timescale = reader.ReadUInt32();
                this.Duration = reader.ReadUInt32();
            }

            this.Language = reader.ReadUInt16PackedCharacters();

            reader.GotoEndOfBox(Offset, Size);
        }
        /// <summary>
        /// Reads the descriptor properties from stream.
        /// </summary>
        /// <param name="reader">The binary reader with the stream.</param>
        protected override void ReadDescriptorPropertiesFromStream(BoxBinaryReader reader)
        {
            var initialOffset = reader.Offset;

            this.ElementaryStreamId = reader.ReadUInt16();
            byte num = reader.ReadByte();
            this.Flags = (uint)((num >> 5) & 7);
            this.StreamPriority = (byte)(num & 0x1f);

            if ((this.Flags & 1) != 0)
            {
                this.DependsOn = reader.ReadUInt16();
            }
            else
            {
                this.DependsOn = 0;
            }

            if ((this.Flags & 2) != 0)
            {
                byte count = reader.ReadByte();
                if (count != 0)
                {
                    byte[] buffer = new byte[count + 1];
                    reader.Read(buffer, 0, count);
                    buffer[count] = 0;
                    this.Url = Encoding.UTF8.GetString(buffer, 0, count);
                }
            }

            if ((this.Flags & 2) != 0)
            {
                this.OcrElementaryStreamId = reader.ReadUInt16();
            }
            else
            {
                this.OcrElementaryStreamId = 0;
            }

            ReadSubDescriptors(reader, initialOffset);
        }
        protected override void ReadFullBoxPropertiesFromStream(BoxBinaryReader reader)
        {
            this.ReferenceId = reader.ReadUInt32();
            this.Timescale = reader.ReadUInt32();

            if (this.Version == 1)
            {
                this.EarliestPresentationTime = reader.ReadUInt64();
                this.FirstOffset = reader.ReadUInt64();
            }
            else
            {
                this.EarliestPresentationTime = reader.ReadUInt32();
                this.FirstOffset = reader.ReadUInt32();
            }

            this.Reserved = reader.ReadUInt16();
            this.ReferenceCount = reader.ReadUInt16();

            Subsegments = new List<Subsegment>();
            for (int i = 0; i < this.ReferenceCount; i++)
            {
                var subsegment = new Subsegment();

                uint referenceNum = reader.ReadUInt32();
                subsegment.ReferenceType = System.Convert.ToBoolean(referenceNum >> 31); // 1 bit
                subsegment.ReferencedSize = (referenceNum << 1) >> 1; // 31 bits

                subsegment.Duration = reader.ReadUInt32();

                uint sapNum = reader.ReadUInt32();
                subsegment.StartsWithSAP = System.Convert.ToBoolean(sapNum >> 31); // 1 bit
                subsegment.SAPType = System.Convert.ToUInt16((sapNum << 1) >> 29); // 3 bits
                subsegment.SAPDeltaTime = (sapNum << 4) >> 4; // 28 bits

                Subsegments.Add(subsegment);
            }

            reader.GotoEndOfBox(Offset, Size);
        }