Example #1
0
 public Mp4MvhdBox(uint size, Mp4Stream stream) : base(size, Mp4BoxType.MVHD, 0L, stream)
 {
     this.Reserved1  = new byte[2];
     this.Reserved2  = new byte[8];
     this.Matrix     = new uint[9];
     this.Predefined = new byte[0x18];
     if (base.Version == 0)
     {
         this.CreationTime     = stream.ReadUInt32();
         this.ModificationTime = stream.ReadUInt32();
         this.TimeScale        = stream.ReadUInt32();
         this.Duration         = stream.ReadUInt32();
     }
     else
     {
         this.CreationTime     = stream.ReadUInt64();
         this.ModificationTime = stream.ReadUInt64();
         this.TimeScale        = stream.ReadUInt32();
         this.Duration         = stream.ReadUInt64();
     }
     this.Rate   = stream.ReadUInt32();
     this.Volume = stream.ReadUInt16();
     stream.Read(this.Reserved1, this.Reserved1.Length);
     stream.Read(this.Reserved2, this.Reserved2.Length);
     for (int i = 0; i < 9; i++)
     {
         this.Matrix[i] = stream.ReadUInt32();
     }
     stream.Read(this.Predefined, this.Predefined.Length);
     this.NextTrackId = stream.ReadUInt32();
 }
Example #2
0
        public Mp4AvccBox(uint size, Mp4Stream stream) : base(size, Mp4BoxType.AVCC)
        {
            long position = stream.Position;

            this.RawBytes = new byte[size];
            stream.Read(this.RawBytes, this.RawBytes.Length);
            stream.Seek(position);
            this.ConfigurationVersion  = stream.ReadUInt08();
            this.AVCProfileIndication  = stream.ReadUInt08();
            this.AVCCompatibleProfiles = stream.ReadUInt08();
            this.AVCLevelIndication    = stream.ReadUInt08();
            byte num2 = stream.ReadUInt08();

            this.NaluLengthSize = (byte)(1 + (num2 & 3));
            byte capacity = (byte)(stream.ReadUInt08() & 0x1f);

            this.SequenceParameters = new List <byte[]>(capacity);
            for (uint i = 0; i < capacity; i++)
            {
                byte[] buffer = new byte[stream.ReadUInt16()];
                stream.Read(buffer, buffer.Length);
                this.SequenceParameters.Add(buffer);
            }
            byte num6 = stream.ReadUInt08();

            this.PictureParameters = new List <byte[]>();
            for (uint j = 0; j < num6; j++)
            {
                byte[] buffer = new byte[stream.ReadUInt16()];
                stream.Read(buffer, buffer.Length);
                this.PictureParameters.Add(buffer);
            }
        }
Example #3
0
 public Mp4UuidBox(uint size, Mp4Stream stream) : base(size, Mp4BoxType.UUID)
 {
     this.Uuid = new byte[0x10];
     stream.Read(this.Uuid, 0x10);
     this.Stream   = stream;
     this.Position = stream.Position;
 }
Example #4
0
        public Mp4MdhdBox(uint size, Mp4Stream stream) : base(size, Mp4BoxType.MDHD, 0L, stream)
        {
            if (base.Version == 0)
            {
                this.CreationTime     = stream.ReadUInt32();
                this.ModificationTime = stream.ReadUInt32();
                this.TimeScale        = stream.ReadUInt32();
                this.Duration         = stream.ReadUInt32();
            }
            else
            {
                this.CreationTime     = stream.ReadUInt64();
                this.ModificationTime = stream.ReadUInt64();
                this.TimeScale        = stream.ReadUInt32();
                this.Duration         = stream.ReadUInt64();
            }
            byte[] buffer = new byte[2];
            stream.Read(buffer, 2);
            byte num  = (byte)(((byte)(buffer[0] >> 2)) & 0x1f);
            byte num2 = (byte)((((byte)(buffer[0] & 3)) << 3) | ((buffer[1] >> 5) & 7));
            byte num3 = (byte)(buffer[1] & 0x1f);

            if (((num != 0) && (num2 != 0)) && (num3 != 0))
            {
                char[] chArray = new char[] { (char)(num + 0x60), (char)(num2 + 0x60), (char)(num3 + 0x60) };
                this.Language = new string(chArray);
            }
            else
            {
                this.Language = "```";
            }
        }
Example #5
0
        public Mp4StscBox(uint size, Mp4Stream stream) : base(size, Mp4BoxType.STSC, 0L, stream)
        {
            uint num  = 1;
            uint num2 = stream.ReadUInt32();

            this.Entries = new List <Mp4StscEntry>((int)num2);
            byte[] buffer = new byte[num2 * 12];
            stream.Read(buffer, (int)(num2 * 12));
            for (int i = 0; i < num2; i++)
            {
                uint num4 = Mp4Util.BytesToUInt32BE(buffer, i * 12);
                uint num5 = Mp4Util.BytesToUInt32BE(buffer, (i * 12) + 4);
                uint num6 = Mp4Util.BytesToUInt32BE(buffer, (i * 12) + 8);
                if (i > 0)
                {
                    int num7 = i - 1;
                    this.Entries[num7].ChunkCount = num4 - this.Entries[num7].FirstChunk;
                    num += this.Entries[num7].ChunkCount * this.Entries[num7].SamplesPerChunk;
                }
                this.Entries.Add(new Mp4StscEntry());
                this.Entries[i].ChunkCount             = 0;
                this.Entries[i].FirstChunk             = num4;
                this.Entries[i].FirstSample            = num;
                this.Entries[i].SamplesPerChunk        = num5;
                this.Entries[i].SampleDescriptionIndex = num6;
            }
        }
Example #6
0
        public Mp4HdlrBox(uint size, Mp4Stream stream) : base(size, Mp4BoxType.HDLR, 0L, stream)
        {
            this.Reserved    = new uint[3];
            this.PreDefined  = stream.ReadUInt32();
            this.HandlerType = stream.ReadUInt32();
            this.Reserved[0] = stream.ReadUInt32();
            this.Reserved[1] = stream.ReadUInt32();
            this.Reserved[2] = stream.ReadUInt32();
            int count = ((int)size) - 0x1c;

            if (count > 0)
            {
                byte[] buffer = new byte[count];
                stream.Read(buffer, count);
                if (buffer[0] == (count - 1))
                {
                    this.Name = Encoding.UTF8.GetString(buffer, 1, buffer.Length - 1);
                }
                else
                {
                    this.Name = Encoding.UTF8.GetString(buffer);
                    int index = this.Name.IndexOf('\0');
                    if (index != -1)
                    {
                        this.Name = this.Name.Substring(0, index);
                    }
                }
            }
            else
            {
                this.Name = string.Empty;
            }
        }
Example #7
0
 public Mp4TkhdBox(uint size, Mp4Stream stream) : base(size, Mp4BoxType.TKHD, 0L, stream)
 {
     this.Reserved2 = new byte[8];
     this.Matrix    = new uint[9];
     if (base.Version == 0)
     {
         this.CreationTime     = stream.ReadUInt32();
         this.ModificationTime = stream.ReadUInt32();
         this.TrackId          = stream.ReadUInt32();
         this.Reserved1        = stream.ReadUInt32();
         this.Duration         = stream.ReadUInt32();
     }
     else
     {
         this.CreationTime     = stream.ReadUInt64();
         this.ModificationTime = stream.ReadUInt64();
         this.TrackId          = stream.ReadUInt32();
         this.Reserved1        = stream.ReadUInt32();
         this.Duration         = stream.ReadUInt64();
     }
     stream.Read(this.Reserved2, 8);
     this.Layer          = stream.ReadUInt16();
     this.AlternateGroup = stream.ReadUInt16();
     this.Volume         = stream.ReadUInt16();
     this.Reserved3      = stream.ReadUInt16();
     for (int i = 0; i < 9; i++)
     {
         this.Matrix[i] = stream.ReadUInt32();
     }
     this.Width  = stream.ReadUInt32();
     this.Height = stream.ReadUInt32();
 }
Example #8
0
 public Mp48bdlBox(uint size, Mp4Stream stream) : base(size, Mp4BoxType.LDB8)
 {
     this.Encoding        = stream.ReadUInt32();
     this.EncodingVersion = stream.ReadUInt32();
     this.BundleData      = new byte[(size - 8) - 8];
     stream.Read(this.BundleData, this.BundleData.Length);
 }
        public Mp4ObjectDescriptor(Mp4Stream stream, Mp4DescriptorTag tag, uint headerSize, uint payloadSize) : base(tag, headerSize, payloadSize)
        {
            Mp4Descriptor descriptor;
            long          position = stream.Position;
            ushort        num2     = stream.ReadUInt16();

            this.ObjectDescriptorId = (ushort)(num2 >> 6);
            this.UrlFlag            = (num2 & 0x20) != 0;
            if (this.UrlFlag)
            {
                byte   count  = stream.ReadUInt08();
                byte[] buffer = new byte[0x100];
                stream.Read(buffer, count);
                buffer[count] = 0;
                this.Url      = Encoding.ASCII.GetString(buffer, 0, count);
            }
            long offset = stream.Position;

            this.SubDescriptors = new List <Mp4Descriptor>();
            Mp4DescriptorFactory factory = new Mp4DescriptorFactory();
            Mp4SubStream         stream2 = new Mp4SubStream(stream, offset, (long)(payloadSize - ((uint)(offset - position))));

            while ((descriptor = factory.Read(stream2)) != null)
            {
                this.SubDescriptors.Add(descriptor);
            }
        }
Example #10
0
        public Mp48idBox(uint size, Mp4Stream stream) : base(size, Mp4BoxType._DI8)
        {
            int count = ((int)size) - 8;

            byte[] buffer = new byte[count];
            stream.Read(buffer, count);
            buffer[count - 1] = 0;
            this.Value        = Encoding.ASCII.GetString(buffer);
        }
 public override void ReadFields(Mp4Stream stream)
 {
     base.ReadFields(stream);
     this.QtVersion       = stream.ReadUInt16();
     this.QtRevision      = stream.ReadUInt16();
     this.QtVendor        = stream.ReadUInt32();
     this.ChannelCount    = stream.ReadUInt16();
     this.SampleSize      = stream.ReadUInt16();
     this.QtCompressionId = stream.ReadUInt16();
     this.QtPacketSize    = stream.ReadUInt16();
     this.SampleRate      = stream.ReadUInt32();
     if (this.QtVersion == 1)
     {
         this.QtV1SamplesPerPacket = stream.ReadUInt32();
         this.QtV1BytesPerPacket   = stream.ReadUInt32();
         this.QtV1BytesPerFrame    = stream.ReadUInt32();
         this.QtV1BytesPerSample   = stream.ReadUInt32();
     }
     else if (this.QtVersion == 2)
     {
         uint num2;
         uint num3;
         this.QtV2StructSize               = stream.ReadUInt32();
         this.QtV2SampleRate64             = stream.ReadDouble();
         this.QtV2ChannelCount             = stream.ReadUInt32();
         this.QtV2Reserved                 = stream.ReadUInt32();
         this.QtV2BitsPerChannel           = stream.ReadUInt32();
         this.QtV2FormatSpecificFlags      = stream.ReadUInt32();
         this.QtV2BytesPerAudioPacket      = stream.ReadUInt32();
         this.QtV2LPCMFramesPerAudioPacket = stream.ReadUInt32();
         if (this.QtV2StructSize > 0x48)
         {
             uint num = this.QtV2StructSize - 0x48;
             this.QtV2Extension = new byte[num];
             stream.Read(this.QtV2Extension, (int)num);
         }
         this.QtV1BytesPerSample   = num2 = 0;
         this.QtV1BytesPerFrame    = num3 = num2;
         this.QtV1SamplesPerPacket = this.QtV1BytesPerPacket = num3;
     }
     else
     {
         this.QtV1SamplesPerPacket         = 0;
         this.QtV1BytesPerPacket           = 0;
         this.QtV1BytesPerFrame            = 0;
         this.QtV1BytesPerSample           = 0;
         this.QtV2StructSize               = 0;
         this.QtV2SampleRate64             = 0.0;
         this.QtV2ChannelCount             = 0;
         this.QtV2Reserved                 = 0;
         this.QtV2BitsPerChannel           = 0;
         this.QtV2FormatSpecificFlags      = 0;
         this.QtV2BytesPerAudioPacket      = 0;
         this.QtV2LPCMFramesPerAudioPacket = 0;
     }
 }
Example #12
0
        public Mp4RtpBox(uint size, Mp4Stream stream) : base(size, Mp4BoxType.RTP_, 0L)
        {
            this.DescriptionFormat = stream.ReadUInt32();
            int count = ((int)size) - 12;

            if (count > 0)
            {
                byte[] buffer = new byte[count];
                stream.Read(buffer, count);
                this.Text = Encoding.ASCII.GetString(buffer);
            }
        }
Example #13
0
 public Mp4UrlBox(uint size, Mp4Stream stream) : base(size, Mp4BoxType.URL_, 0L, stream)
 {
     if ((base.Flags & 1) == 0)
     {
         int count = ((int)size) - 12;
         if (count > 0)
         {
             byte[] buffer = new byte[count];
             stream.Read(buffer, count);
             this.Location = Encoding.ASCII.GetString(buffer);
         }
     }
 }
Example #14
0
        public override void ReadFields(Mp4Stream stream)
        {
            base.ReadFields(stream);
            this.Predefined1 = stream.ReadUInt16();
            this.Reserved2   = stream.ReadUInt16();
            stream.Read(this.Predefined2, this.Predefined2.Length);
            this.Width           = stream.ReadUInt16();
            this.Height          = stream.ReadUInt16();
            this.HorizResolution = stream.ReadUInt32();
            this.VertResolution  = stream.ReadUInt32();
            this.Reserved3       = stream.ReadUInt32();
            this.FrameCount      = stream.ReadUInt16();
            byte[] buffer = new byte[0x20];
            stream.Read(buffer, 0x20);
            int count = buffer[0];

            if (count < 0x20)
            {
                this.CompressorName = Encoding.ASCII.GetString(buffer, 1, count);
            }
            this.Depth       = stream.ReadUInt16();
            this.Predefined3 = stream.ReadUInt16();
        }
Example #15
0
        public Mp4EsDescriptor(Mp4Stream stream, uint headerSize, uint payloadSize) : base(Mp4DescriptorTag.ES, headerSize, payloadSize)
        {
            Mp4Descriptor descriptor;
            long          position = stream.Position;

            this.EsId = stream.ReadUInt16();
            byte num2 = stream.ReadUInt08();

            this.Flags          = (uint)((num2 >> 5) & 7);
            this.StreamPriority = (byte)(num2 & 0x1f);
            if ((this.Flags & 1) != 0)
            {
                this.DependsOn = stream.ReadUInt16();
            }
            else
            {
                this.DependsOn = 0;
            }
            if ((this.Flags & 2) != 0)
            {
                byte count = stream.ReadUInt08();
                if (count != 0)
                {
                    byte[] buffer = new byte[count + 1];
                    stream.Read(buffer, count);
                    buffer[count] = 0;
                    this.Url      = Encoding.ASCII.GetString(buffer, 0, count);
                }
            }
            if ((this.Flags & 2) != 0)
            {
                this.OcrEsId = stream.ReadUInt16();
            }
            else
            {
                this.OcrEsId = 0;
            }
            long offset = stream.Position;

            this.SubDescriptors = new List <Mp4Descriptor>();
            Mp4DescriptorFactory factory = new Mp4DescriptorFactory();
            Mp4SubStream         stream2 = new Mp4SubStream(stream, offset, (long)(payloadSize - ((uint)(offset - position))));

            while ((descriptor = factory.Read(stream2)) != null)
            {
                this.SubDescriptors.Add(descriptor);
            }
        }
Example #16
0
        public Mp4StcoBox(uint size, Mp4Stream stream) : base(size, Mp4BoxType.STCO, 0L, stream)
        {
            uint num = stream.ReadUInt32();

            if (num > (((size - 12) - 4) / 4))
            {
                num = ((size - 12) - 4) / 4;
            }
            this.Entries = new List <uint>((int)num);
            byte[] buffer = new byte[num * 4];
            stream.Read(buffer, (int)(num * 4));
            for (int i = 0; i < num; i++)
            {
                this.Entries.Add(Mp4Util.BytesToUInt32BE(buffer, i * 4));
            }
        }
Example #17
0
        public Mp4StszBox(uint size, Mp4Stream stream) : base(size, Mp4BoxType.STSZ, 0L, stream)
        {
            this.SampleSize = stream.ReadUInt32();
            uint num = stream.ReadUInt32();

            if (this.SampleSize == 0)
            {
                this.Entries = new List <uint>((int)num);
                byte[] buffer = new byte[num * 4];
                stream.Read(buffer, (int)(num * 4));
                for (uint i = 0; i < num; i++)
                {
                    this.Entries.Add(Mp4Util.BytesToUInt32BE(buffer, (int)(i * 4)));
                }
            }
            else
            {
                this.Entries = new List <uint>();
            }
        }
Example #18
0
        public Mp4CttsBox(uint size, Mp4Stream stream) : base(size, Mp4BoxType.CTTS, 0L, stream)
        {
            this.lookupCache = new LookupCache();
            uint num = stream.ReadUInt32();

            this.Entries = new List <Mp4CttsEntry>((int)num);
            byte[] buffer = new byte[num * 8];
            stream.Read(buffer, (int)(num * 8));
            bool flag = false;
            int  num2 = 0;

            for (int i = 0; i < num; i++)
            {
                this.Entries.Add(new Mp4CttsEntry());
                this.Entries[i].SampleCount = Mp4Util.BytesToUInt32BE(buffer, i * 8);
                uint num4 = Mp4Util.BytesToUInt32BE(buffer, (i * 8) + 4);
                if ((num4 & 0x80000000) != 0)
                {
                    flag = true;
                    int num5 = (int)num4;
                    if (num5 < num2)
                    {
                        num2 = num5;
                    }
                }
                this.Entries[i].SampleOffset = num4;
            }
            if (flag)
            {
                for (int j = 0; j < num; j++)
                {
                    Mp4CttsEntry local1 = this.Entries[j];
                    local1.SampleOffset -= (uint)num2;
                }
            }
        }
Example #19
0
 public Mp4DecoderSpecificInfoDescriptor(Mp4Stream stream, uint headerSize, uint payloadSize) : base(Mp4DescriptorTag.DECODER_SPECIFIC_INFO, headerSize, payloadSize)
 {
     this.Info = new byte[payloadSize];
     stream.Read(this.Info, (int)payloadSize);
 }
Example #20
0
        public Mp4HvccBox(uint size, Mp4Stream stream) : base(size, Mp4BoxType.HVCC)
        {
            long position = stream.Position;

            this.RawBytes = new byte[size];
            stream.Read(this.RawBytes, this.RawBytes.Length);
            stream.Seek(position);
            this.ConfigurationVersion = stream.ReadUInt08();
            byte temp = stream.ReadUInt08();

            GeneralProfileSpace = ((byte)(temp & 0xc0)) >> 6;
            GeneralTierFlag     = ((byte)(temp & 0x20)) >> 5;
            GeneralProfileIdc   = (byte)(temp & 0x1f);
            GeneralProfileCompatibilityFlags = stream.ReadUInt32();
            GeneralConstraintIndicatorFlags  = (ulong)(stream.ReadUInt32()) << 16;
            GeneralConstraintIndicatorFlags += stream.ReadUInt16();
            //GeneralConstraintIndicatorFlags |= (ulong)stream.ReadInt16();
            GeneralLevelIdc           = stream.ReadUInt08();
            MinSpatialSegmentationIdc = (uint)(stream.ReadUInt16() & 0xff);
            ParallelismType           = (byte)(stream.ReadUInt08() & 0x3);
            ChromaFormat         = (byte)(stream.ReadUInt08() & 0x3);
            BitDepthLumaMinus8   = (byte)(stream.ReadUInt08() & 0x7);
            BitDepthChromaMinus8 = (byte)(stream.ReadUInt08() & 0x7);
            avgFrameRate         = stream.ReadUInt16();
            temp = stream.ReadUInt08();
            constantFrameRate  = ((byte)(temp & 0xc0)) >> 6;
            numTemporalLayers  = ((byte)(temp & 0x38)) >> 3;
            temporalIdNested   = (byte)(temp & 0x4) >> 2;
            lengthSizeMinusOne = (byte)(temp & 0x3);
            numOfArrays        = stream.ReadUInt08();
            for (var i = 0; i < numOfArrays; i++)
            {
                byte ArrayCompleteness, NALUType;
                temp = stream.ReadUInt08();
                ArrayCompleteness = (byte)(temp & 0x80);
                NALUType          = (byte)(temp & 0x3f);
                var NumNALUs = stream.ReadUInt16();
                if (NALUType == 0x20)
                {
                    VideoParameters = new List <byte[]>(NumNALUs);
                    for (var j = 0; j < NumNALUs; j++)
                    {
                        var    NALULength = stream.ReadUInt16();
                        byte[] buffer     = new byte[NALULength];
                        stream.Read(buffer, buffer.Length);
                        VideoParameters.Add(buffer);
                    }
                }
                else if (NALUType == 0x21)
                {
                    SequenceParameters = new List <byte[]>(NumNALUs);
                    for (var j = 0; j < NumNALUs; j++)
                    {
                        var    NALULength = stream.ReadUInt16();
                        byte[] buffer     = new byte[NALULength];
                        stream.Read(buffer, buffer.Length);
                        SequenceParameters.Add(buffer);
                    }
                }
                else if (NALUType == 0x22)
                {
                    PictureParameters = new List <byte[]>(NumNALUs);
                    for (var j = 0; j < NumNALUs; j++)
                    {
                        var    NALULength = stream.ReadUInt16();
                        byte[] buffer     = new byte[NALULength];
                        stream.Read(buffer, buffer.Length);
                        PictureParameters.Add(buffer);
                    }
                }
            }
        }
 public Mp4UnknownDescriptor(Mp4Stream stream, Mp4DescriptorTag tag, uint headerSize, uint payloadSize) : base(tag, headerSize, payloadSize)
 {
     this.Data = new byte[payloadSize];
     stream.Read(this.Data, (int)payloadSize);
 }
Example #22
0
 public Mp4NameBox(uint size, Mp4Stream stream) : base(size, Mp4BoxType.NAME)
 {
     byte[] buffer = new byte[size - this.HeaderSize];
     stream.Read(buffer, buffer.Length);
     this.Name = Encoding.ASCII.GetString(buffer);
 }
Example #23
0
 public virtual void ReadFields(Mp4Stream stream)
 {
     stream.Read(this.Reserved, this.Reserved.Length);
     this.DataReferenceIndex = stream.ReadUInt16();
 }