Example #1
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 #2
0
        public Mp4Descriptor Read(Mp4Stream stream)
        {
            if ((stream.Length - stream.Position) == 0L)
            {
                return(null);
            }
            Mp4Descriptor    descriptor  = null;
            long             position    = stream.Position;
            Mp4DescriptorTag tag         = (Mp4DescriptorTag)stream.ReadUInt08();
            uint             payloadSize = 0;
            uint             headerSize  = 1;
            uint             num4        = 4;
            byte             num5        = 0;

            do
            {
                headerSize++;
                num5        = stream.ReadUInt08();
                payloadSize = (payloadSize << 7) + ((uint)(num5 & 0x7f));
            }while ((--num4 != 0) && ((num5 & 0x80) != 0));
            switch (tag)
            {
            case Mp4DescriptorTag.OD:
            case Mp4DescriptorTag.MP4_OD:
                descriptor = new Mp4ObjectDescriptor(stream, tag, headerSize, payloadSize);
                break;

            case Mp4DescriptorTag.ES:
                descriptor = new Mp4EsDescriptor(stream, headerSize, payloadSize);
                break;

            case Mp4DescriptorTag.DECODER_CONFIG:
                descriptor = new Mp4DecoderConfigDescriptor(stream, headerSize, payloadSize);
                break;

            case Mp4DescriptorTag.DECODER_SPECIFIC_INFO:
                descriptor = new Mp4DecoderSpecificInfoDescriptor(stream, headerSize, payloadSize);
                break;

            case Mp4DescriptorTag.SL_CONFIG:
                if (payloadSize != 1)
                {
                    throw new Exception("INVALID_FORMAT");
                }
                descriptor = new Mp4SLConfigDescriptor(stream, headerSize, payloadSize);
                break;

            default:
                descriptor = new Mp4UnknownDescriptor(stream, tag, headerSize, payloadSize);
                break;
            }
            stream.Seek((position + headerSize) + payloadSize);
            return(descriptor);
        }
Example #3
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);
                    }
                }
            }
        }