/// <summary> /// Reads an audio packet, assigning the audio header and /// advancing the position to the next packet position. /// </summary> /// <param name="position"> /// A <see cref="long" /> value reference specifying the /// position at which to start reading the packet. This value /// is updated to the position of the next packet. /// </param> void ReadAudioPacket(ref long position) { Seek(position + 4); int length = ReadBlock(2).ToUShort(); if (!audio_found) { audio_found = AudioHeader.Find( out audio_header, this, position + 15, length - 9); } position += length; }
/// <summary> /// Reads format specific information at the start of the /// file. /// </summary> /// <param name="start"> /// A <see cref="long" /> value containing the seek position /// at which the tags end and the media data begins. /// </param> /// <param name="propertiesStyle"> /// A <see cref="ReadStyle" /> value specifying at what level /// of accuracy to read the media properties, or <see /// cref="ReadStyle.None" /> to ignore the properties. /// </param> /// <remarks> /// This method only searches for an audio header in the /// first 16384 bytes of code to avoid searching forever in /// corrupt files. /// </remarks> protected override void ReadStart(long start, ReadStyle propertiesStyle) { // Only check the first 16 bytes so we're not stuck // reading a bad file forever. if (propertiesStyle != ReadStyle.None && !AudioHeader.Find(out first_header, this, start, 0x4000)) { throw new CorruptFileException( "MPEG audio header not found."); } }
/// <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); }
/// <summary> /// Searches for an audio header in a <see cref="TagLib.File" /// /> starting at a specified position and searching to the /// end of the file. /// </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> /// <returns> /// A <see cref="bool" /> value indicating whether or not a /// header was found. /// </returns> /// <remarks> /// Searching to the end of the file can be very, very slow /// especially for corrupt or non-MPEG files. It is /// recommended to use <see /// cref="Find(AudioHeader&,TagLib.File,long,int)" /> /// instead. /// </remarks> public static bool Find(out AudioHeader header, TagLib.File file, long position) { return(Find(out header, file, position, -1)); }
/// <summary> /// Searches for an audio header in a <see cref="TagLib.File" /// /> starting at a specified position and searching to the /// end of the file. /// </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> /// <returns> /// A <see cref="bool" /> value indicating whether or not a /// header was found. /// </returns> /// <remarks> /// Searching to the end of the file can be very, very slow /// especially for corrupt or non-MPEG files. It is /// recommended to use <see /// cref="Find(AudioHeader&,TagLib.File,long,int)" /> /// instead. /// </remarks> public static bool Find (out AudioHeader header, TagLib.File file, long position) { return Find (out header, file, position, -1); }
/// <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; }