/// <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 (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(); }
/// <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 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 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 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 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); }
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); }
private uint ReadIntValueFromBytes(BoxBinaryReader reader, byte numberOfBytes) { switch (numberOfBytes) { case 0: return(reader.ReadByte()); case 1: return(reader.ReadUInt16()); case 2: return(reader.ReadUInt24()); case 3: return(reader.ReadUInt32()); default: throw new BoxException("Specified number of bytes to parse an integer is not supported in the traf box."); } }
/// <summary> /// Reads the sample entry properties from stream. /// </summary> /// <param name="reader">The stream reader.</param> internal override void ReadSampleEntryPropertiesFromStream(BoxBinaryReader reader) { this.reserved1 = reader.ReadUInt16(); this.reserved2 = reader.ReadUInt16(); this.reserved3 = reader.ReadUInt32(); this.ChannelCount = reader.ReadUInt16(); this.SampleSize = reader.ReadUInt16(); this.predefined = reader.ReadUInt16(); this.reserved4 = reader.ReadUInt16(); this.SampleRate = reader.ReadUInt32(); if (reader.PeekNextBoxType() != BoxType.Null) { ReadInnerBoxes(reader, BoxType.Esds, BoxType.Wfex, BoxType.Sinf, BoxType.Dec3, BoxType.Dac3, BoxType.Dmlp, BoxType.Ddts); this.AudioCodecData = GetAudioCodecDataFromInnerBoxes(); } else { var waveFormatEx = new WaveFormatEx(reader); this.AudioCodecData = new AudioTrackCodecData(waveFormatEx); } }
private uint ReadIntValueFromBytes(BoxBinaryReader reader, byte numberOfBytes) { switch (numberOfBytes) { case 0: return reader.ReadByte(); case 1: return reader.ReadUInt16(); case 2: return reader.ReadUInt24(); case 3: return reader.ReadUInt32(); default: throw new BoxException("Specified number of bytes to parse an integer is not supported in the traf box."); } }