public IsoAudioSampleEntry(BoxHeader header, TagLib.File file, IsoHandlerBox handler) : base(header, file, handler) { if (file == null) { throw new ArgumentNullException("file"); } file.Seek(base.DataPosition + 8L); this.channel_count = file.ReadBlock(2).ToUShort(); this.sample_size = file.ReadBlock(2).ToUShort(); file.Seek(base.DataPosition + 0x10L); this.sample_rate = file.ReadBlock(4).ToUInt(); this.children = base.LoadChildren(file); }
/// <summary> /// Constructs and initializes a new instance of <see /// cref="IsoVisualSampleEntry" /> with a provided header and /// handler by reading the contents from a specified file. /// </summary> /// <param name="header"> /// A <see cref="BoxHeader" /> object containing the header /// to use for the new instance. /// </param> /// <param name="file"> /// A <see cref="TagLib.File" /> object to read the contents /// of the box from. /// </param> /// <param name="handler"> /// A <see cref="IsoHandlerBox" /> object containing the /// handler that applies to the new instance. /// </param> /// <exception cref="ArgumentNullException"> /// <paramref name="file" /> is <see langword="null" />. /// </exception> public IsoVisualSampleEntry(BoxHeader header, TagLib.File file, IsoHandlerBox handler) : base(header, file, handler) { file.Seek (base.DataPosition + 16); width = file.ReadBlock (2).ToUShort (); height = file.ReadBlock (2).ToUShort (); /* TODO: What are the children anyway? children = LoadChildren (file); */ }
/// <summary> /// Constructs and initializes a new instance of <see /// cref="AppleAdditionalInfoBox" /> with a provided header /// and handler by reading the contents from a specified /// file. /// </summary> /// <param name="header"> /// A <see cref="BoxHeader" /> object containing the header /// to use for the new instance. /// </param> /// <param name="file"> /// A <see cref="TagLib.File" /> object to read the contents /// of the box from. /// </param> /// <param name="handler"> /// A <see cref="IsoHandlerBox" /> object containing the /// handler that applies to the new instance. /// </param> /// <exception cref="ArgumentNullException"> /// <paramref name="file" /> is <see langword="null" />. /// </exception> public AppleAdditionalInfoBox(BoxHeader header, TagLib.File file, IsoHandlerBox handler) : base(header, file, handler) { // We do not care what is in this custom data section // see: https://developer.apple.com/library/mac/#documentation/QuickTime/QTFF/QTFFChap2/qtff2.html Data = file.ReadBlock(DataSize > 0 ? DataSize : 0); ; }
protected void Read(TagLib.File file) { if (file == null) return; try { file.Mode = FileAccessMode.Read; } catch (TagLibException) { return; } file.Seek(tagOffset); header.SetData(file.ReadBlock((int)Id3v2Header.Size)); // if the tag size is 0, then this is an invalid tag (tags must contain // at least one frame) if (header.TagSize == 0) return; Parse(file.ReadBlock((int)header.TagSize)); }
public PageHeader(TagLib.Ogg.File file, long position) { if (file == null) { throw new ArgumentNullException("file"); } if ((position < 0L) || (position > (file.Length - 0x1bL))) { throw new ArgumentOutOfRangeException("position"); } file.Seek(position); ByteVector vector = file.ReadBlock(0x1b); if ((vector.Count < 0x1b) || !vector.StartsWith("OggS")) { throw new CorruptFileException("Error reading page header"); } this.version = vector[4]; this.flags = (PageFlags) vector[5]; this.absolute_granular_position = vector.Mid(6, 8).ToULong(false); this.stream_serial_number = vector.Mid(14, 4).ToUInt(false); this.page_sequence_number = vector.Mid(0x12, 4).ToUInt(false); int length = vector[0x1a]; ByteVector vector2 = file.ReadBlock(length); if ((length < 1) || (vector2.Count != length)) { throw new CorruptFileException("Incorrect number of page segments"); } this.size = (uint) (0x1b + length); this.packet_sizes = new List<int>(); int item = 0; this.data_size = 0; for (int i = 0; i < length; i++) { this.data_size += vector2[i]; item += vector2[i]; if (vector2[i] < 0xff) { this.packet_sizes.Add(item); item = 0; } } if (item > 0) { this.packet_sizes.Add(item); } }
public Page(TagLib.Ogg.File file, long position) : this(new PageHeader(file, position)) { file.Seek(position + this.header.Size); foreach (int num in this.header.PacketSizes) { this.packets.Add(file.ReadBlock(num)); } }
protected ListTag (TagLib.File file, long position, int length) { if (file == null) throw new System.ArgumentNullException ("file"); file.Seek (position); fields = new List (file.ReadBlock (length)); }
public IsoSampleEntry(BoxHeader header, TagLib.File file, IsoHandlerBox handler) : base(header, handler) { if (file == null) { throw new ArgumentNullException("file"); } file.Seek(base.DataPosition + 6L); this.data_reference_index = file.ReadBlock(2).ToUShort(); }
public IsoSampleDescriptionBox(BoxHeader header, TagLib.File file, IsoHandlerBox handler) : base(header, file, handler) { if (file == null) { throw new ArgumentNullException("file"); } this.entry_count = file.ReadBlock(4).ToUInt(); this.children = base.LoadChildren(file); }
public IsoChunkOffsetBox(BoxHeader header, TagLib.File file, IsoHandlerBox handler) : base(header, file, handler) { ByteVector vector = file.ReadBlock(base.DataSize); this.offsets = new uint[vector.Mid(0, 4).ToUInt()]; for (int i = 0; i < this.offsets.Length; i++) { this.offsets[i] = vector.Mid(4 + (i * 4), 4).ToUInt(); } }
private AudioHeader(ByteVector data, TagLib.File file, long position) { this.duration = TimeSpan.Zero; this.stream_length = 0L; if (data.Count < 4) { throw new CorruptFileException("Insufficient header length."); } if (data[0] != 0xff) { throw new CorruptFileException("First byte did not match MPEG synch."); } if (((data[1] & 230) <= 0xe0) || ((data[1] & 0x18) == 8)) { throw new CorruptFileException("Second byte did not match MPEG synch."); } this.flags = data.ToUInt(); if (((this.flags >> 12) & 15) == 15) { throw new CorruptFileException("Header uses invalid bitrate index."); } if (((this.flags >> 10) & 3) == 3) { throw new CorruptFileException("Invalid sample rate."); } this.xing_header = TagLib.Mpeg.XingHeader.Unknown; this.vbri_header = TagLib.Mpeg.VBRIHeader.Unknown; file.Seek(position + TagLib.Mpeg.XingHeader.XingHeaderOffset(this.Version, this.ChannelMode)); ByteVector vector = file.ReadBlock(0x10); if ((vector.Count == 0x10) && vector.StartsWith(TagLib.Mpeg.XingHeader.FileIdentifier)) { this.xing_header = new TagLib.Mpeg.XingHeader(vector); } if (!this.xing_header.Present) { file.Seek(position + TagLib.Mpeg.VBRIHeader.VBRIHeaderOffset()); ByteVector vector2 = file.ReadBlock(0x18); if ((vector2.Count == 0x18) && vector2.StartsWith(TagLib.Mpeg.VBRIHeader.FileIdentifier)) { this.vbri_header = new TagLib.Mpeg.VBRIHeader(vector2); } } }
public StreamPropertiesObject(TagLib.Asf.File file, long position) : base(file, position) { if (!base.Guid.Equals(TagLib.Asf.Guid.AsfStreamPropertiesObject)) { throw new CorruptFileException("Object GUID incorrect."); } if (base.OriginalSize < 0x4eL) { throw new CorruptFileException("Object size too small."); } this.stream_type = file.ReadGuid(); this.error_correction_type = file.ReadGuid(); this.time_offset = file.ReadQWord(); int length = (int) file.ReadDWord(); int num2 = (int) file.ReadDWord(); this.flags = file.ReadWord(); this.reserved = file.ReadDWord(); this.type_specific_data = file.ReadBlock(length); this.error_correction_data = file.ReadBlock(num2); }
protected FullBox(BoxHeader header, TagLib.File file, IsoHandlerBox handler) : base(header, handler) { if (file == null) { throw new ArgumentNullException("file"); } file.Seek(base.DataPosition); ByteVector vector = file.ReadBlock(4); this.version = vector[0]; this.flags = vector.Mid(1, 3).ToUInt(); }
/// <summary> /// Constructs and initializes a new instance of <see /// cref="FullBox" /> with a provided header and handler by /// reading the contents from a specified file. /// </summary> /// <param name="header"> /// A <see cref="BoxHeader" /> object containing the header /// to use for the new instance. /// </param> /// <param name="file"> /// A <see cref="TagLib.File" /> object to read the contents /// of the box from. /// </param> /// <param name="handler"> /// A <see cref="IsoHandlerBox" /> object containing the /// handler that applies to the new instance. /// </param> /// <exception cref="ArgumentNullException"> /// <paramref name="file" /> is <see langword="null" />. /// </exception> protected FullBox(BoxHeader header, TagLib.File file, IsoHandlerBox handler) : base(header, handler) { if (file == null) throw new ArgumentNullException ("file"); file.Seek (base.DataPosition); ByteVector header_data = file.ReadBlock (4); version = header_data [0]; flags = header_data.Mid (1, 3).ToUInt (); }
/// <summary> /// Constructs and initializes a new instance of <see /// cref="IsoChunkOffsetBox" /> with a provided header and /// handler by reading the contents from a specified file. /// </summary> /// <param name="header"> /// A <see cref="BoxHeader" /> object containing the header /// to use for the new instance. /// </param> /// <param name="file"> /// A <see cref="TagLib.File" /> object to read the contents /// of the box from. /// </param> /// <param name="handler"> /// A <see cref="IsoHandlerBox" /> object containing the /// handler that applies to the new instance. /// </param> public IsoChunkOffsetBox (BoxHeader header, TagLib.File file, IsoHandlerBox handler) : base (header, file, handler) { ByteVector box_data = file.ReadBlock (DataSize); offsets = new uint [(int) box_data.Mid (0, 4).ToUInt ()]; for (int i = 0; i < offsets.Length; i ++) offsets [i] = box_data.Mid (4 + i * 4, 4).ToUInt (); }
public HeaderObject(TagLib.Asf.File file, long position) : base(file, position) { if (!base.Guid.Equals(TagLib.Asf.Guid.AsfHeaderObject)) { throw new CorruptFileException("Object GUID incorrect."); } if (base.OriginalSize < 0x1aL) { throw new CorruptFileException("Object size too small."); } this.children = new List<TagLib.Asf.Object>(); uint count = file.ReadDWord(); this.reserved = file.ReadBlock(2); this.children.AddRange(file.ReadObjects(count, file.Tell)); }
public IsoHandlerBox(BoxHeader header, TagLib.File file, IsoHandlerBox handler) : base(header, file, handler) { if (file == null) { throw new ArgumentNullException("file"); } file.Seek(this.DataPosition + 4L); ByteVector vector = file.ReadBlock(base.DataSize - 4); this.handler_type = vector.Mid(0, 4); int count = vector.Find(0, 0x10); if (count < 0x10) { count = vector.Count; } this.name = vector.ToString(StringType.UTF8, 0x10, count - 0x10); }
/// <summary> /// Constructs and initializes a new instance of <see /// cref="IsoHandlerBox" /> with a provided header and /// handler by reading the contents from a specified file. /// </summary> /// <param name="header"> /// A <see cref="BoxHeader" /> object containing the header /// to use for the new instance. /// </param> /// <param name="file"> /// A <see cref="TagLib.File" /> object to read the contents /// of the box from. /// </param> /// <param name="handler"> /// A <see cref="IsoHandlerBox" /> object containing the /// handler that applies to the new instance. /// </param> /// <exception cref="ArgumentNullException"> /// <paramref name="file" /> is <see langword="null" />. /// </exception> public IsoHandlerBox(BoxHeader header, TagLib.File file, IsoHandlerBox handler) : base(header, file, handler) { if (file == null) throw new System.ArgumentNullException ("file"); file.Seek (DataPosition + 4); ByteVector box_data = file.ReadBlock (DataSize - 4); handler_type = box_data.Mid (0, 4); int end = box_data.Find ((byte) 0, 16); if (end < 16) end = box_data.Count; name = box_data.ToString (StringType.UTF8, 16, end - 16); }
public VideoHeader(TagLib.File file, long position) { if (file == null) { throw new ArgumentNullException("file"); } file.Seek(position); ByteVector vector = file.ReadBlock(7); if (vector.Count < 7) { throw new CorruptFileException("Insufficient data in header."); } this.width = vector.Mid(0, 2).ToUShort() >> 4; this.height = vector.Mid(1, 2).ToUShort() & 0xfff; this.frame_rate_index = vector[3] & 15; this.bitrate = ((int) (vector.Mid(4, 3).ToUInt() >> 6)) & 0x3ffff; }
public AppleElementaryStreamDescriptor(BoxHeader header, TagLib.File file, IsoHandlerBox handler) : base(header, file, handler) { int offset = 0; ByteVector data = file.ReadBlock(base.DataSize); this.decoder_config = new ByteVector(); if (data[offset++] == 3) { if (ReadLength(data, ref offset) < 20) { throw new CorruptFileException("Insufficient data present."); } this.es_id = data.Mid(offset, 2).ToUShort(); offset += 2; this.stream_priority = data[offset++]; } else { this.es_id = data.Mid(offset, 2).ToUShort(); offset += 2; } if (data[offset++] != 4) { throw new CorruptFileException("Could not identify decoder configuration descriptor."); } if (ReadLength(data, ref offset) < 15) { throw new CorruptFileException("Could not read data. Too small."); } this.object_type_id = data[offset++]; this.stream_type = data[offset++]; this.buffer_size_db = data.Mid(offset, 3).ToUInt(); offset += 3; this.max_bitrate = data.Mid(offset, 4).ToUInt(); offset += 4; this.average_bitrate = data.Mid(offset, 4).ToUInt(); offset += 4; if (data[offset++] != 5) { throw new CorruptFileException("Could not identify decoder specific descriptor."); } uint num2 = ReadLength(data, ref offset); this.decoder_config = data.Mid(offset, (int) num2); }
public BoxHeader(TagLib.File file, long position) { if (file == null) { throw new ArgumentNullException("file"); } this.box = null; this.from_disk = true; this.position = position; file.Seek(position); ByteVector vector = file.ReadBlock(0x20); int startIndex = 0; if (vector.Count < (8 + startIndex)) { throw new CorruptFileException("Not enough data in box header."); } this.header_size = 8; this.box_size = vector.Mid(startIndex, 4).ToUInt(); this.box_type = vector.Mid(startIndex + 4, 4); if (this.box_size == 1L) { if (vector.Count < (8 + startIndex)) { throw new CorruptFileException("Not enough data in box header."); } this.header_size += 8; this.box_size = vector.Mid(startIndex, 8).ToULong(); startIndex += 8; } if (this.box_type == TagLib.Mpeg4.BoxType.Uuid) { if (vector.Count < (0x10 + startIndex)) { throw new CorruptFileException("Not enough data in box header."); } this.header_size += 0x10; this.extended_type = vector.Mid(startIndex, 0x10); } else { this.extended_type = null; } }
public DivXTag(TagLib.Riff.File file, long position) { if (file == null) { throw new ArgumentNullException("file"); } file.Mode = TagLib.File.AccessMode.Read; if ((position < 0L) || (position > (file.Length - 0x80L))) { throw new ArgumentOutOfRangeException("position"); } file.Seek(position); ByteVector data = file.ReadBlock(0x80); if (!data.EndsWith(FileIdentifier)) { throw new CorruptFileException("DivX tag data does not end with identifier."); } this.Parse(data); }
protected bool Parse(TagLib.Asf.File file) { int length = file.ReadWord(); this.name = file.ReadUnicode(length); this.type = (DataType) file.ReadWord(); int num2 = file.ReadWord(); switch (this.type) { case DataType.Unicode: this.strValue = file.ReadUnicode(num2); break; case DataType.Bytes: this.byteValue = file.ReadBlock(num2); break; case DataType.Bool: this.longValue = file.ReadDWord(); break; case DataType.DWord: this.longValue = file.ReadDWord(); break; case DataType.QWord: this.longValue = file.ReadQWord(); break; case DataType.Word: this.longValue = file.ReadWord(); break; default: return false; } return true; }
/// <summary> /// Constructs and initializes a new instance of <see /// cref="VideoHeader" /> by reading it from a specified /// location in a specified file. /// </summary> /// <param name="file"> /// A <see cref="TagLib.File" /> object to read from. /// </param> /// <param name="position"> /// A <see cref="long" /> value indicating the position in /// <paramref name="file" /> at which the header begins. /// </param> /// <exception cref="ArgumentNullException"> /// <paramref name="file" /> is <see langref="null" />. /// </exception> /// <exception cref="CorruptFileException"> /// Insufficient data could be read for the header. /// </exception> public VideoHeader (TagLib.File file, long position) { if (file == null) throw new ArgumentNullException ("file"); file.Seek (position); ByteVector data = file.ReadBlock (7); if (data.Count < 7) throw new CorruptFileException ( "Insufficient data in header."); width = data.Mid (0, 2).ToUShort () >> 4; height = data.Mid (1, 2).ToUShort () & 0x0FFF; frame_rate_index = data [3] & 0x0F; bitrate = (int) ((data.Mid (4, 3).ToUInt () >> 6) & 0x3FFFF); }
public IsoMovieHeaderBox(BoxHeader header, TagLib.File file, IsoHandlerBox handler) : base(header, file, handler) { ByteVector vector; if (file == null) { throw new ArgumentNullException("file"); } int dataSize = base.DataSize; if (base.Version == 1) { vector = file.ReadBlock(Math.Min(0x1c, dataSize)); if (vector.Count >= 8) { this.creation_time = vector.Mid(0, 8).ToULong(); } if (vector.Count >= 0x10) { this.modification_time = vector.Mid(8, 8).ToULong(); } if (vector.Count >= 20) { this.timescale = vector.Mid(0x10, 4).ToUInt(); } if (vector.Count >= 0x1c) { this.duration = vector.Mid(20, 8).ToULong(); } dataSize -= 0x1c; } else { vector = file.ReadBlock(Math.Min(0x10, dataSize)); if (vector.Count >= 4) { this.creation_time = vector.Mid(0, 4).ToUInt(); } if (vector.Count >= 8) { this.modification_time = vector.Mid(4, 4).ToUInt(); } if (vector.Count >= 12) { this.timescale = vector.Mid(8, 4).ToUInt(); } if (vector.Count >= 0x10) { this.duration = vector.Mid(12, 4).ToUInt(); } dataSize -= 0x10; } vector = file.ReadBlock(Math.Min(6, dataSize)); if (vector.Count >= 4) { this.rate = vector.Mid(0, 4).ToUInt(); } if (vector.Count >= 6) { this.volume = vector.Mid(4, 2).ToUShort(); } file.Seek(file.Tell + 70L); dataSize -= 0x4c; vector = file.ReadBlock(Math.Min(4, dataSize)); if (vector.Count >= 4) { this.next_track_id = vector.Mid(0, 4).ToUInt(); } }
/// <summary> /// Loads the data of the current instance from a specified /// file using the internal data position and size. /// </summary> /// <param name="file"> /// The <see cref="TagLib.File" /> from which the current /// instance was read and from which to read the data. /// </param> /// <returns> /// A <see cref="ByteVector" /> object containing the data /// read from the file. /// </returns> /// <exception cref="ArgumentNullException"> /// <paramref name="file" /> is <see langref="null" />. /// </exception> protected ByteVector LoadData (TagLib.File file) { if (file == null) throw new ArgumentNullException ("file"); file.Seek (DataPosition); return file.ReadBlock (DataSize); }
public IsoVisualSampleEntry(BoxHeader header, TagLib.File file, IsoHandlerBox handler) : base(header, file, handler) { file.Seek(base.DataPosition + 0x10L); this.width = file.ReadBlock(2).ToUShort(); this.height = file.ReadBlock(2).ToUShort(); }
public AppleAdditionalInfoBox(BoxHeader header, TagLib.File file, IsoHandlerBox handler) : base(header, file, handler) { this.Data = file.ReadBlock(base.DataSize); }
/// <summary> /// Constructs and initializes a new instance of <see /// cref="BoxHeader" /> by reading it from a specified seek /// position in a specified file. /// </summary> /// <param name="file"> /// A <see cref="TagLib.File" /> object to read the new /// instance from. /// </param> /// <param name="position"> /// A <see cref="long" /> value specifiying the seek position /// in <paramref name="file" /> at which to start reading. /// </param> /// <exception cref="ArgumentNullException"> /// <paramref name="file" /> is <see langword="null" />. /// </exception> /// <exception cref="CorruptFileException"> /// There isn't enough data in the file to read the complete /// header. /// </exception> public BoxHeader (TagLib.File file, long position) { if (file == null) throw new ArgumentNullException ("file"); this.box = null; this.from_disk = true; this.position = position; file.Seek (position); ByteVector data = file.ReadBlock (32); int offset = 0; if (data.Count < 8 + offset) throw new CorruptFileException ( "Not enough data in box header."); header_size = 8; box_size = data.Mid (offset, 4).ToUInt (); box_type = data.Mid (offset + 4, 4); // If the size is 1, that just tells us we have a // massive ULONG size waiting for us in the next 8 // bytes. if (box_size == 1) { if (data.Count < 8 + offset) throw new CorruptFileException ( "Not enough data in box header."); header_size += 8; box_size = data.Mid (offset, 8).ToULong (); offset += 8; } // UUID has a special header with 16 extra bytes. if (box_type == Mpeg4.BoxType.Uuid) { if (data.Count < 16 + offset) throw new CorruptFileException ( "Not enough data in box header."); header_size += 16; extended_type = data.Mid (offset, 16); } else extended_type = null; }
/// <summary> /// Searches for an audio header in a <see cref="TagLib.File" /// /> starting at a specified position and searching through /// a specified number of bytes. /// </summary> /// <param name="header"> /// A <see cref="AudioHeader" /> object in which the found /// header will be stored. /// </param> /// <param name="file"> /// A <see cref="TagLib.File" /> object to search. /// </param> /// <param name="position"> /// A <see cref="long" /> value specifying the seek position /// in <paramref name="file" /> at which to start searching. /// </param> /// <param name="length"> /// A <see cref="int" /> value specifying the maximum number /// of bytes to search before aborting. /// </param> /// <returns> /// A <see cref="bool" /> value indicating whether or not a /// header was found. /// </returns> /// <exception cref="ArgumentNullException"> /// <paramref name="file" /> is <see langref="null" />. /// </exception> public static bool Find (out AudioHeader header, TagLib.File file, long position, int length) { if (file == null) throw new ArgumentNullException ("file"); long end = position + length; header = AudioHeader.Unknown; file.Seek (position); ByteVector buffer = file.ReadBlock (3); if (buffer.Count < 3) return false; do { file.Seek (position + 3); buffer = buffer.Mid (buffer.Count - 3); buffer.Add (file.ReadBlock ( (int) File.BufferSize)); for (int i = 0; i < buffer.Count - 3 && (length < 0 || position + i < end); i++) if (buffer [i] == 0xFF && buffer [i + 1] > 0xE0) try { header = new AudioHeader ( buffer.Mid (i, 4), file, position + i); return true; } catch (CorruptFileException) { } position += File.BufferSize; } while (buffer.Count > 3 && (length < 0 || position < end)); return false; }