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); }
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); } }
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); } }
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); } }
public Mp4SdtpBox(uint size, Mp4Stream stream) : base(size, Mp4BoxType.SDTP, 0L, stream) { int capacity = ((int)size) - 12; this.Entries = new List <Mp4SdtpEntry>(capacity); for (int i = 0; i < capacity; i++) { byte num3 = stream.ReadUInt08(); int sampleDependsOn = (num3 & 0x30) >> 4; int sampleIsDependOn = (num3 & 12) >> 2; int sampleHasRedundancy = num3 & 3; this.Entries.Add(new Mp4SdtpEntry(sampleDependsOn, sampleIsDependOn, sampleHasRedundancy)); } }
public Mp4DecoderConfigDescriptor(Mp4Stream stream, uint headerSize, uint payloadSize) : base(Mp4DescriptorTag.DECODER_CONFIG, headerSize, payloadSize) { Mp4Descriptor descriptor; long position = stream.Position; this.ObjectTypeIndication = (Mp4ObjectTypeIndication)stream.ReadUInt08(); byte num2 = stream.ReadUInt08(); this.StreamType = (byte)((num2 >> 2) & 0x3f); this.UpStream = (num2 & 2) != 0; this.BufferSize = stream.ReadUInt24(); this.MaxBitrate = stream.ReadUInt32(); this.AverageBitrate = stream.ReadUInt32(); 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); } }
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 Mp4SLConfigDescriptor(Mp4Stream stream, uint headerSize, uint payloadSize) : base(Mp4DescriptorTag.SL_CONFIG, headerSize, payloadSize) { this.Predefined = stream.ReadUInt08(); }
public Mp4TfraBox(uint size, Mp4Stream stream) : base(size, Mp4BoxType.TFRA, 0L, stream) { this.TrackId = stream.ReadUInt32(); uint num = stream.ReadUInt32(); this.Reserved = ((int)(num >> 6)) & 0x3ffffff; this.LengthSizeOfTrafNum = (byte)((num >> 4) & 3); this.LengthSizeOfTrunNum = (byte)((num >> 2) & 3); this.LengthSizeOfSampleNum = (byte)(num & 3); uint num2 = stream.ReadUInt32(); this.Entries = new List <Mp4TfraEntry>(); for (int i = 0; i < num2; i++) { Mp4TfraEntry item = new Mp4TfraEntry(); if (base.Version == 1) { item.Time = stream.ReadUInt64(); item.MoofOffset = stream.ReadUInt64(); } else { item.Time = stream.ReadUInt32(); item.MoofOffset = stream.ReadUInt32(); } switch (this.LengthSizeOfTrafNum) { case 0: item.TrafNumber = stream.ReadUInt08(); break; case 1: item.TrafNumber = stream.ReadUInt16(); break; case 2: item.TrafNumber = stream.ReadUInt24(); break; case 3: item.TrafNumber = stream.ReadUInt32(); break; } switch (this.LengthSizeOfTrunNum) { case 0: item.TrunNumber = stream.ReadUInt08(); break; case 1: item.TrunNumber = stream.ReadUInt16(); break; case 2: item.TrunNumber = stream.ReadUInt24(); break; case 3: item.TrunNumber = stream.ReadUInt32(); break; } switch (this.LengthSizeOfSampleNum) { case 0: item.SampleNumber = stream.ReadUInt08(); break; case 1: item.SampleNumber = stream.ReadUInt16(); break; case 2: item.SampleNumber = stream.ReadUInt24(); break; case 3: item.SampleNumber = stream.ReadUInt32(); break; } this.Entries.Add(item); } }