/// <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) { // There is a maximum of 16 stuffing bytes, read up to the PTS/DTS flags ByteVector packetHeaderBytes = this.ReadBlock(19); int i = 0; while (i < packetHeaderBytes.Count && packetHeaderBytes[i] == 0xFF) { // Byte is a stuffing byte i++; } if ((packetHeaderBytes[i] & 0x40) != 0) { // STD buffer size is unexpected for audio packets, but whatever i++; } // Decode the PTS/DTS flags byte timestampFlags = packetHeaderBytes[i]; long dataOffset = 4 + 2 + i + // Packet marker + packet length + stuffing bytes/STD buffer size ((timestampFlags & 0x20) > 0 ? 4 : 0) + // Presentation timestamp ((timestampFlags & 0x10) > 0 ? 4 : 0); // Decode timestamp audio_found = AudioHeader.Find(out audio_header, this, position + dataOffset, length - 9); } position += length; }
protected override void ReadStart(long start, ReadStyle propertiesStyle) { if (propertiesStyle != ReadStyle.None && !AudioHeader.Find(out first_header, this, start, 0x4000)) { throw new CorruptFileException("MPEG audio header not found."); } }
/// <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.Average) != 0 && !AudioHeader.Find(out first_header, this, start, 0x4000)) { throw new CorruptFileException("MPEG audio header not found."); } }
/// <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; }