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); } }
/// <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) { 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); }
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); }
/// <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) { reader.GotoEndOfBox(this.Offset, this.Size); }
/// <summary> /// Creates a new Box instance that matches the BoxType specified. This will position the /// reader to the end of the box that was read in. /// </summary> /// <param name="stream">The stream that contains the bytes for the box.</param> /// <returns>Returns the box read from the stream; if there was no box to read it /// will return null.</returns> public static Box Create(BoxBinaryReader stream) { Box box = null; var offset = stream.Offset; var size = stream.ReadBoxSize(); var boxType = stream.ReadBoxType(); switch (boxType) { case BoxType.Moov: box = new MovieBox(offset, size); break; case BoxType.Mvhd: box = new MovieHeaderFullBox(offset, size); break; case BoxType.Trak: box = new TrackBox(offset, size); break; case BoxType.Tkhd: box = new TrackHeaderFullBox(offset, size); break; case BoxType.Tref: box = new TrackReferenceBox(offset, size); break; case BoxType.Mdia: box = new MediaBox(offset, size); break; case BoxType.Mdhd: box = new MediaHeaderFullBox(offset, size); break; case BoxType.Hdlr: box = new HandlerReferenceFullBox(offset, size); break; case BoxType.Minf: box = new MediaInformationBox(offset, size); break; case BoxType.Vmhd: box = new VideoMediaHeaderFullBox(offset, size); break; case BoxType.Smhd: box = new SoundMediaHeaderFullBox(offset, size); break; case BoxType.Nmhd: box = new NullMediaHeaderFullBox(offset, size); break; case BoxType.Dinf: box = new DataInformationBox(offset, size); break; case BoxType.Stbl: box = new SampleTableBox(offset, size); break; case BoxType.Stts: box = new DecodingTimeToSampleFullBox(offset, size); break; case BoxType.Stss: box = new SyncSamplesBox(offset, size); break; case BoxType.Ctts: box = new CompositionTimeToSampleFullBox(offset, size); break; case BoxType.Stsd: box = new SampleDescriptionFullBox(offset, size); break; case BoxType.Mp4a: case BoxType.Wma: case BoxType.Ac_3: case BoxType.Ec_3: case BoxType.Mlpa: case BoxType.Dtsc: case BoxType.Dtsh: case BoxType.Dtsl: case BoxType.Dtse: box = new AudioSampleEntryBox(offset, size); break; case BoxType.Dec3: box = new EC3SpecificBox(offset, size); break; case BoxType.Dac3: box = new AC3SpecificBox(offset, size); break; case BoxType.Dmlp: box = new MLPSpecificBox(offset, size); break; case BoxType.Ddts: box = new DTSSpecificBox(offset, size); break; case BoxType.Avc1: case BoxType.Vc_1: box = new VisualSampleEntryBox(offset, size); break; case BoxType.Stpp: box = new SubtitleSampleEntryBox(offset, size); break; case BoxType.Encv: case BoxType.Enca: case BoxType.Enct: case BoxType.Encs: box = new ProtectedSampleEntryBox(offset, size, boxType); break; case BoxType.Esds: box = new ElementaryStreamDescriptorFullBox(offset, size); break; case BoxType.Avcc: box = new AdvancedVideoCodingBox(offset, size); break; case BoxType.Wfex: box = new WaveFormatExBox(offset, size); break; case BoxType.Dvc1: box = new DigitalVideoCodingBox(offset, size); break; case BoxType.Mvex: box = new MovieExtendsBox(offset, size); break; case BoxType.Ftyp: box = new FileTypeBox(offset, size); break; case BoxType.Mdat: box = new MediaDataBox(offset, size); break; case BoxType.Moof: box = new MovieFragmentBox(offset, size); break; case BoxType.Mfra: box = new MovieFragmentRandomAccessBox(offset, size); break; case BoxType.Tfra: box = new TrackFragmentRandomAccessFullBox(offset, size); break; case BoxType.Mfro: box = new MovieFragmentRandomAccessOffsetFullBox(offset, size); break; case BoxType.Mfhd: box = new MovieFragmentHeaderFullBox(offset, size); break; case BoxType.Traf: box = new TrackFragmentBox(offset, size); break; case BoxType.Tfhd: box = new TrackFragmentHeaderFullBox(offset, size); break; case BoxType.Trun: box = new TrackFragmentRunFullBox(offset, size); break; case BoxType.Sdtp: box = new IndependentAndDisposableSamplesFullBox(offset, size); break; case BoxType.Uuid: box = ExtensionBox.GetNextBoxFromStream(stream, offset, (uint)size); box.ExtendedType = stream.ReadGuid(); break; case BoxType.Pdin: box = new ProgressiveDownloadInfoFullBox(offset, size); break; case BoxType.Bloc: box = new BaseLocationFullBox(offset, size); break; case BoxType.Ainf: box = new AssetInformationFullBox(offset, size); break; case BoxType.Xml: box = new XmlFullBox(offset, size); break; case BoxType.Bxml: box = new BinaryXmlFullBox(offset, size); break; case BoxType.Iloc: box = new ItemLocationFullBox(offset, size); break; case BoxType.Idat: box = new ItemDataBox(offset, size); break; case BoxType.Meta: box = new MetaFullBox(offset, size); break; case BoxType.Free: case BoxType.Skip: box = new FreeSpaceBox(offset, size); break; case BoxType.Trik: box = new TrickPlayFullBox(offset, size); break; case BoxType.Btrt: box = new BitRateBox(offset, size); break; case BoxType.Sthd: box = new SubtitleMediaHeaderFullBox(offset, size); break; case BoxType.Subs: box = new SubSampleInformationFullBox(offset, size); break; case BoxType.Tfdt: box = new TrackFragmentBaseMediaDecodeTimeFullBox(offset, size); break; case BoxType.Saiz: box = new SampleAuxiliaryInformationSizesFullBox(offset, size); break; case BoxType.Saio: box = new SampleAuxiliaryInformationOffsetsFullBox(offset, size); break; case BoxType.Prft: box = new ProducerReferenceTimeFullBox(offset, size); break; case BoxType.Pssh: box = new ProtectionSystemSpecificHeaderFullBox(offset, size); break; case BoxType.Tenc: box = new TrackEncryptionFullBox(offset, size); break; case BoxType.Senc: box = new SampleEncryptionFullBox(offset, size); break; case BoxType.Schi: box = new SchemeInformationBox(offset, size); break; case BoxType.Sinf: box = new ProtectedSchemeInformationBox(offset, size); break; case BoxType.Avcn: box = new AVCNALBox(offset, size); break; case BoxType.Sidx: box = new SegmentIndexBox(offset, size); break; case BoxType.Stsc: box = new SampleChunkBox(offset, size); break; case BoxType.Stsz: box = new SampleSizeBox(offset, size); break; case BoxType.Stco: box = new SampleChunkOffsetBox(offset, size); break; case BoxType.Iods: box = new InitialObjectDescriptorBox(offset, size); break; default: stream.GotoEndOfBox(offset, size); break; } if (box != null) { box.ReadBoxFromStream(stream); } return(box); }
protected override void ReadBoxPropertiesFromStream(BoxBinaryReader reader) { 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) { // TODO: Do we need to read this data? reader.GotoEndOfBox(this.Offset, this.Size); }
/// <summary> /// Reads the box properties from stream. /// </summary> /// <param name="reader">The binary reader with the stream.</param> protected override void ReadBoxPropertiesFromStream(BoxBinaryReader reader) { // TODO: Do we need this information? reader.GotoEndOfBox(this.Offset, this.Size); }
/// <summary> /// Creates a new Box instance that matches the BoxType specified. This will position the /// reader to the end of the box that was read in. /// </summary> /// <param name="stream">The stream that contains the bytes for the box.</param> /// <returns>Returns the box read from the stream; if there was no box to read it /// will return null.</returns> public static Box Create(BoxBinaryReader stream) { Box box = null; var offset = stream.Offset; var size = stream.ReadBoxSize(); var boxType = stream.ReadBoxType(); switch (boxType) { case BoxType.Moov: box = new MovieBox(offset, size); break; case BoxType.Mvhd: box = new MovieHeaderFullBox(offset, size); break; case BoxType.Trak: box = new TrackBox(offset, size); break; case BoxType.Tkhd: box = new TrackHeaderFullBox(offset, size); break; case BoxType.Tref: box = new TrackReferenceBox(offset, size); break; case BoxType.Mdia: box = new MediaBox(offset, size); break; case BoxType.Mdhd: box = new MediaHeaderFullBox(offset, size); break; case BoxType.Hdlr: box = new HandlerReferenceFullBox(offset, size); break; case BoxType.Minf: box = new MediaInformationBox(offset, size); break; case BoxType.Vmhd: box = new VideoMediaHeaderFullBox(offset, size); break; case BoxType.Smhd: box = new SoundMediaHeaderFullBox(offset, size); break; case BoxType.Nmhd: box = new NullMediaHeaderFullBox(offset, size); break; case BoxType.Dinf: box = new DataInformationBox(offset, size); break; case BoxType.Stbl: box = new SampleTableBox(offset, size); break; case BoxType.Stts: box = new DecodingTimeToSampleFullBox(offset, size); break; case BoxType.Stss: box = new SyncSamplesBox(offset, size); break; case BoxType.Ctts: box = new CompositionTimeToSampleFullBox(offset, size); break; case BoxType.Stsd: box = new SampleDescriptionFullBox(offset, size); break; case BoxType.Mp4a: case BoxType.Wma: case BoxType.Ac_3: case BoxType.Ec_3: case BoxType.Mlpa: case BoxType.Dtsc: case BoxType.Dtsh: case BoxType.Dtsl: case BoxType.Dtse: box = new AudioSampleEntryBox(offset, size); break; case BoxType.Dec3: box = new EC3SpecificBox(offset, size); break; case BoxType.Dac3: box = new AC3SpecificBox(offset, size); break; case BoxType.Dmlp: box = new MLPSpecificBox(offset, size); break; case BoxType.Ddts: box = new DTSSpecificBox(offset, size); break; case BoxType.Avc1: case BoxType.Vc_1: box = new VisualSampleEntryBox(offset, size); break; case BoxType.Stpp: box = new SubtitleSampleEntryBox(offset, size); break; case BoxType.Encv: case BoxType.Enca: case BoxType.Enct: case BoxType.Encs: box = new ProtectedSampleEntryBox(offset, size, boxType); break; case BoxType.Esds: box = new ElementaryStreamDescriptorFullBox(offset, size); break; case BoxType.Avcc: box = new AdvancedVideoCodingBox(offset, size); break; case BoxType.Wfex: box = new WaveFormatExBox(offset, size); break; case BoxType.Dvc1: box = new DigitalVideoCodingBox(offset, size); break; case BoxType.Mvex: box = new MovieExtendsBox(offset, size); break; case BoxType.Ftyp: box = new FileTypeBox(offset, size); break; case BoxType.Mdat: box = new MediaDataBox(offset, size); break; case BoxType.Moof: box = new MovieFragmentBox(offset, size); break; case BoxType.Mfra: box = new MovieFragmentRandomAccessBox(offset, size); break; case BoxType.Tfra: box = new TrackFragmentRandomAccessFullBox(offset, size); break; case BoxType.Mfro: box = new MovieFragmentRandomAccessOffsetFullBox(offset, size); break; case BoxType.Mfhd: box = new MovieFragmentHeaderFullBox(offset, size); break; case BoxType.Traf: box = new TrackFragmentBox(offset, size); break; case BoxType.Tfhd: box = new TrackFragmentHeaderFullBox(offset, size); break; case BoxType.Trun: box = new TrackFragmentRunFullBox(offset, size); break; case BoxType.Sdtp: box = new IndependentAndDisposableSamplesFullBox(offset, size); break; case BoxType.Uuid: box = ExtensionBox.GetNextBoxFromStream(stream, offset, (uint)size); box.ExtendedType = stream.ReadGuid(); break; case BoxType.Pdin: box = new ProgressiveDownloadInfoFullBox(offset, size); break; case BoxType.Bloc: box = new BaseLocationFullBox(offset, size); break; case BoxType.Ainf: box = new AssetInformationFullBox(offset, size); break; case BoxType.Xml: box = new XmlFullBox(offset, size); break; case BoxType.Bxml: box = new BinaryXmlFullBox(offset, size); break; case BoxType.Iloc: box = new ItemLocationFullBox(offset, size); break; case BoxType.Idat: box = new ItemDataBox(offset, size); break; case BoxType.Meta: box = new MetaFullBox(offset, size); break; case BoxType.Free: case BoxType.Skip: box = new FreeSpaceBox(offset, size); break; case BoxType.Trik: box = new TrickPlayFullBox(offset, size); break; case BoxType.Btrt: box = new BitRateBox(offset, size); break; case BoxType.Sthd: box = new SubtitleMediaHeaderFullBox(offset, size); break; case BoxType.Subs: box = new SubSampleInformationFullBox(offset, size); break; case BoxType.Tfdt: box = new TrackFragmentBaseMediaDecodeTimeFullBox(offset, size); break; case BoxType.Saiz: box = new SampleAuxiliaryInformationSizesFullBox(offset, size); break; case BoxType.Saio: box = new SampleAuxiliaryInformationOffsetsFullBox(offset, size); break; case BoxType.Prft: box = new ProducerReferenceTimeFullBox(offset, size); break; case BoxType.Pssh: box = new ProtectionSystemSpecificHeaderFullBox(offset, size); break; case BoxType.Tenc: box = new TrackEncryptionFullBox(offset, size); break; case BoxType.Senc: box = new SampleEncryptionFullBox(offset, size); break; case BoxType.Schi: box = new SchemeInformationBox(offset, size); break; case BoxType.Sinf: box = new ProtectedSchemeInformationBox(offset, size); break; case BoxType.Avcn: box = new AVCNALBox(offset, size); break; case BoxType.Sidx: box = new SegmentIndexBox(offset, size); break; case BoxType.Stsc: box = new SampleChunkBox(offset, size); break; case BoxType.Stsz: box = new SampleSizeBox(offset, size); break; case BoxType.Stco: box = new SampleChunkOffsetBox(offset, size); break; case BoxType.Iods: box = new InitialObjectDescriptorBox(offset, size); break; default: stream.GotoEndOfBox(offset, size); break; } if (box != null) { box.ReadBoxFromStream(stream); } return box; }
///// <summary> ///// Gets or sets the stream with the data. ///// </summary> //public Stream DataStream { get; private set; } /// <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.DataStream = reader.BaseStream; reader.GotoEndOfBox(this.Offset, this.Size); }