Exemple #1
0
        private AudioHeader(ByteVector data, TagLib.File file, long position)
        {
            this.duration = TimeSpan.Zero;
            stream_length = 0;
            string error = GetHeaderError(data);

            if (error != null)
            {
                throw new CorruptFileException(error);
            }
            flags       = data.ToUInt();
            xing_header = XingHeader.Unknown;
            vbri_header = VBRIHeader.Unknown;
            file.Seek(position + XingHeader.XingHeaderOffset(Version, ChannelMode));
            ByteVector xing_data = file.ReadBlock(16);

            if (xing_data.Count == 16 && xing_data.StartsWith(XingHeader.FileIdentifier))
            {
                xing_header = new XingHeader(xing_data);
            }
            if (xing_header.Present)
            {
                return;
            }
            file.Seek(position + VBRIHeader.VBRIHeaderOffset());
            ByteVector vbri_data = file.ReadBlock(24);

            if (vbri_data.Count == 24 && vbri_data.StartsWith(VBRIHeader.FileIdentifier))
            {
                vbri_header = new VBRIHeader(vbri_data);
            }
        }
Exemple #2
0
 private AudioHeader(uint flags, long streamLength, XingHeader xingHeader, VBRIHeader vbriHeader)
 {
     this.flags         = flags;
     this.stream_length = streamLength;
     this.xing_header   = xingHeader;
     this.vbri_header   = vbriHeader;
     this.duration      = TimeSpan.Zero;
 }
Exemple #3
0
        /// <summary>
        ///    Constructs and initializes a new instance of <see
        ///    cref="AudioHeader" /> by reading its contents from a
        ///    <see cref="ByteVector" /> object and its Xing Header from
        ///    the appropriate location in the specified file.
        /// </summary>
        /// <param name="data">
        ///    A <see cref="ByteVector" /> object containing the header
        ///    to read.
        /// </param>
        /// <param name="file">
        ///    A <see cref="TagLib.File" /> object to read the Xing
        ///    header 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="CorruptFileException">
        ///    <paramref name="data" /> is less than 4 bytes long,
        ///    does not begin with a MPEG audio synch, has a negative
        ///    bitrate, or has a sample rate of zero.
        /// </exception>
        private AudioHeader(ByteVector data, TagLib.File file,
                            long position)
        {
            this.duration = TimeSpan.Zero;
            stream_length = 0;

            string error = GetHeaderError(data);

            if (error != null)
            {
                throw new CorruptFileException(error);
            }

            flags = data.ToUInt();

            xing_header = XingHeader.Unknown;

            vbri_header = VBRIHeader.Unknown;

            // Check for a Xing header that will help us in
            // gathering information about a VBR stream.
            file.Seek(position + XingHeader.XingHeaderOffset(
                          Version, ChannelMode));

            ByteVector xing_data = file.ReadBlock(16);

            if (xing_data.Count == 16 && xing_data.StartsWith(
                    XingHeader.FileIdentifier))
            {
                xing_header = new XingHeader(xing_data);
            }

            if (xing_header.Present)
            {
                return;
            }

            // A Xing header could not be found, next chec for a
            // Fraunhofer VBRI header.
            file.Seek(position + VBRIHeader.VBRIHeaderOffset());

            // Only get the first 24 bytes of the Header.
            // We're not interested in the TOC entries.
            ByteVector vbri_data = file.ReadBlock(24);

            if (vbri_data.Count == 24 &&
                vbri_data.StartsWith(VBRIHeader.FileIdentifier))
            {
                vbri_header = new VBRIHeader(vbri_data);
            }
        }
		/// <summary>
		///    Constructs and initializes a new instance of <see
		///    cref="AudioHeader" /> by reading its contents from a
		///    <see cref="ByteVector" /> object and its Xing Header from
		///    the appropriate location in the specified file.
		/// </summary>
		/// <param name="data">
		///    A <see cref="ByteVector" /> object containing the header
		///    to read.
		/// </param>
		/// <param name="file">
		///    A <see cref="TagLib.File" /> object to read the Xing
		///    header 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="CorruptFileException">
		///    <paramref name="data" /> is less than 4 bytes long,
		///    does not begin with a MPEG audio synch, has a negative
		///    bitrate, or has a sample rate of zero.
		/// </exception>
		private AudioHeader (ByteVector data, TagLib.File file,
		                     long position)
		{
			this.duration = TimeSpan.Zero;
			stream_length = 0;
			
			if (data.Count < 4)
				throw new CorruptFileException (
					"Insufficient header length.");
			
			if (data [0] != 0xFF)
				throw new CorruptFileException (
					"First byte did not match MPEG synch.");
			
			// Checking bits from high to low:
			//
			// First 3 bits MUST be set. Bits 4 and 5 can
			// be 00, 10, or 11 but not 01. One or more of
			// bits 6 and 7 must be set. Bit 8 can be
			// anything.
			if ((data [1] & 0xE6) <= 0xE0 || (data [1] & 0x18) == 0x08)
				throw new CorruptFileException (
					"Second byte did not match MPEG synch.");
			
			flags = data.ToUInt ();
			
			if (((flags >> 12) & 0x0F) == 0x0F)
				throw new CorruptFileException (
					"Header uses invalid bitrate index.");
			
			if (((flags >> 10) & 0x03) == 0x03)
				throw new CorruptFileException (
					"Invalid sample rate.");

			xing_header = XingHeader.Unknown;
			
			vbri_header = VBRIHeader.Unknown;
			
			// Check for a Xing header that will help us in
			// gathering information about a VBR stream.
			file.Seek (position + XingHeader.XingHeaderOffset (
				Version, ChannelMode));
				
			ByteVector xing_data = file.ReadBlock (16);
			if (xing_data.Count == 16 && xing_data.StartsWith (
				XingHeader.FileIdentifier))
				xing_header = new XingHeader (xing_data);

			if (xing_header.Present)
				return;
			
			// A Xing header could not be found, next chec for a
			// Fraunhofer VBRI header.
			file.Seek (position + VBRIHeader.VBRIHeaderOffset ());

			// Only get the first 24 bytes of the Header.
			// We're not interested in the TOC entries.
			ByteVector vbri_data = file.ReadBlock (24);
			if (vbri_data.Count == 24 &&
				vbri_data.StartsWith(VBRIHeader.FileIdentifier))
			vbri_header = new VBRIHeader (vbri_data);
		}
		/// <summary>
		///    Constructs and initializes a new instance of <see
		///    cref="AudioHeader" /> by populating it with specified
		///    values.
		/// </summary>
		/// <param name="flags">
		///    A <see cref="uint" /> value specifying flags for the new
		///    instance.
		/// </param>
		/// <param name="streamLength">
		///    A <see cref="long" /> value specifying the stream length
		///    of the new instance.
		/// </param>
		/// <param name="xingHeader">
		///    A <see cref="XingHeader" /> object representing the Xing
		///    header associated with the new instance.
		/// </param>
		/// <param name="vbriHeader">
		///    A <see cref="VBRIHeader" /> object representing the VBRI
		///    header associated with the new instance.
		/// </param>
		private AudioHeader (uint flags, long streamLength,
		                     XingHeader xingHeader,
		                     VBRIHeader vbriHeader)
		{
			this.flags = flags;
			this.stream_length = streamLength;
			this.xing_header = xingHeader;
			this.vbri_header = vbriHeader;
			this.duration = TimeSpan.Zero;
		}
        /// <summary>
        ///    Constructs and initializes a new instance of <see
        ///    cref="AudioHeader" /> by reading its contents from a
        ///    <see cref="ByteVector" /> object and its Xing Header from
        ///    the appropriate location in the specified file.
        /// </summary>
        /// <param name="data">
        ///    A <see cref="ByteVector" /> object containing the header
        ///    to read.
        /// </param>
        /// <param name="file">
        ///    A <see cref="TagLib.File" /> object to read the Xing
        ///    header 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="CorruptFileException">
        ///    <paramref name="data" /> is less than 4 bytes long,
        ///    does not begin with a MPEG audio synch, has a negative
        ///    bitrate, or has a sample rate of zero.
        /// </exception>
        private AudioHeader(ByteVector data, TagLib.File file,
                            long position)
        {
            this.duration = TimeSpan.Zero;
            stream_length = 0;

            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] < 0xE0)
            {
                throw new CorruptFileException(
                          "Second byte did not match MPEG synch.");
            }

            flags = data.ToUInt();

            if (((flags >> 12) & 0x0F) == 0x0F)
            {
                throw new CorruptFileException(
                          "Header uses invalid bitrate index.");
            }

            if (((flags >> 10) & 0x03) == 0x03)
            {
                throw new CorruptFileException(
                          "Invalid sample rate.");
            }

            xing_header = XingHeader.Unknown;

            vbri_header = VBRIHeader.Unknown;

            // Check for a Xing header that will help us in
            // gathering information about a VBR stream.
            file.Seek(position + XingHeader.XingHeaderOffset(
                          Version, ChannelMode));

            ByteVector xing_data = file.ReadBlock(16);

            if (xing_data.Count == 16 && xing_data.StartsWith(
                    XingHeader.FileIdentifier))
            {
                xing_header = new XingHeader(xing_data);
            }

            if (xing_header.Present)
            {
                return;
            }

            // A Xing header could not be found, next chec for a
            // Fraunhofer VBRI header.
            file.Seek(position + VBRIHeader.VBRIHeaderOffset());

            // Only get the first 24 bytes of the Header.
            // We're not interested in the TOC entries.
            ByteVector vbri_data = file.ReadBlock(24);

            if (vbri_data.Count == 24 &&
                vbri_data.StartsWith(VBRIHeader.FileIdentifier))
            {
                vbri_header = new VBRIHeader(vbri_data);
            }
        }
        /// <summary>
        ///    Constructs and initializes a new instance of <see
        ///    cref="AudioHeader" /> by reading its contents from a
        ///    <see cref="ByteVector" /> object and its Xing Header from
        ///    the appropriate location in the specified file.
        /// </summary>
        /// <param name="data">
        ///    A <see cref="ByteVector" /> object containing the header
        ///    to read.
        /// </param>
        /// <param name="file">
        ///    A <see cref="TagLib.File" /> object to read the Xing
        ///    header 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="CorruptFileException">
        ///    <paramref name="data" /> is less than 4 bytes long,
        ///    does not begin with a MPEG audio synch, has a negative
        ///    bitrate, or has a sample rate of zero.
        /// </exception>
        private AudioHeader(ByteVector data, TagLib.File file,
		                     long position)
        {
            this.duration = TimeSpan.Zero;
            stream_length = 0;

            string error = GetHeaderError(data);
            if (error != null) {
                throw new CorruptFileException (error);
            }

            flags = data.ToUInt ();

            xing_header = XingHeader.Unknown;

            vbri_header = VBRIHeader.Unknown;

            info_header = XingHeader.Unknown;

            // Check for a Xing header that will help us in
            // gathering information about a VBR stream.
            file.Seek (position + XingHeader.XingHeaderOffset (
                Version, ChannelMode));

            ByteVector xing_data = file.ReadBlock (16);
            if (xing_data.Count == 16)
            {
                if (xing_data.StartsWith(XingHeader.XingFileIdentifier))
                {
                    xing_header = new XingHeader(xing_data);

                    if (xing_header.Present)
                        return;
                }

                if (xing_data.StartsWith(XingHeader.InfoFileIdentifier))
                {
                    info_header = new XingHeader(xing_data);

                    if (info_header.Present)
                        return;
                }
            }

            // A Xing header could not be found, next chec for a
            // Fraunhofer VBRI header.
            file.Seek (position + VBRIHeader.VBRIHeaderOffset ());

            // Only get the first 24 bytes of the Header.
            // We're not interested in the TOC entries.
            ByteVector vbri_data = file.ReadBlock (24);
            if (vbri_data.Count == 24 &&
                vbri_data.StartsWith(VBRIHeader.FileIdentifier))
            vbri_header = new VBRIHeader (vbri_data);
        }
 static VBRIHeader()
 {
     FileIdentifier = "VBRI";
     Unknown = new VBRIHeader(0, 0);
 }