public override bool Parse(AviParser parser) { const short MaxLongsPerEntryCount = 16; // Random choice. The only value I've seen up till now is 4. if (!base.Parse(parser)) { return(false); } ushort longsPerEntry = (ushort)parser.GetShort(Attribute.LongsPerEntry); if (longsPerEntry > MaxLongsPerEntryCount) { return(false); } parser.GetByte(Attribute.IndexSubType); parser.GetByte(Attribute.IndexType); parser.GetInt(Attribute.EntriesInUse); parser.GetInt(Attribute.ChunkId); parser.GetInt(Attribute.Reserved); parser.GetInt(Attribute.Reserved); parser.GetInt(Attribute.Reserved); if (longsPerEntry > 0) { ulong bytesRemaining = parser.BytesRemaining; parser.Parse(new IndexTableAttribute(longsPerEntry, bytesRemaining)); ulong numberOfEntriesInTable = bytesRemaining / (uint)(longsPerEntry * 4); parser.CheckAttribute(Attribute.IndexTable, numberOfEntriesInTable * longsPerEntry * 4 == bytesRemaining, false); } return(Valid); }
public override bool Parse(AviParser parser) { // Call the Parse method of the parent to initialise the header and // allow parsing the containing header if there is one. if (!base.Parse(parser)) { return(false); } // Now parse the header. LstType = parser.GetFourCC(Attribute.ListType); if (LstType == (uint)ListType.Info) { do { Valid = parser.Parse(new InfoAttribute(parser.BytesRemaining)); }while (parser.BytesRemaining > 0 && Valid); } else if (LstType == (uint)ListType.Prmi) { uint maxPrmiLength = (uint)AviDetector.Configurable[AviDetector.ConfigurationKey.HeaderListMaxPrmiLength]; parser.GetInt(Attribute.Unknown); parser.GetInt(Attribute.Unknown); parser.GetInt(Attribute.Unknown); if (parser.BytesRemaining > maxPrmiLength) { return(false); // Sanity check } parser.GetString(Attribute.AviAdobePremiereInfoList, parser.BytesRemaining); } return(Valid); }
private void ParseStreamType(AviParser parser) { byte streamTypeByte0 = parser.GetByte(); byte streamTypeByte1 = parser.GetByte(); StreamType = (InformationType)(((short)streamTypeByte0 << 8) | streamTypeByte1); parser.AddAttribute(new FormattedAttribute <Attribute, InformationType>(Attribute.InformationType, StreamType)); }
public override bool Parse(AviParser parser) { if (!base.Parse(parser)) { return(false); } // The 'Size' property is not set in the base class because this // class does not have the ChunkFlags.SizeAndType attribute set. Size = 1; parser.GetByte(Attribute.PaddingByte); return(this.Valid); }
public override bool Parse(AviParser parser) { if (!base.Parse(parser)) { return(false); } const uint EntrySize = 16; uint numberOfEntries = Size / EntrySize; parser.GetTable(Attribute.IndexChunkTable, numberOfEntries, EntrySize, () => new IndexChunkEntry()); return(Valid); }
private bool ParseChannel(AviParser parser) { byte AsciiValueOfCharacterZero = Convert.ToByte('0'); byte channelByte0 = parser.GetByte(); byte channelByte1 = parser.GetByte(); if (!((char)channelByte0).IsHexDigit() || !((char)channelByte1).IsHexDigit()) { this.Valid = false; return(this.Valid); } Channel = (byte)((16 * (channelByte0 - AsciiValueOfCharacterZero)) + (channelByte1 - AsciiValueOfCharacterZero)); parser.AddAttribute(new FormattedAttribute <Attribute, byte>(Attribute.Channel, Channel)); return(true); }
public override bool Parse(AviParser parser) { if (!base.Parse(parser)) { return(false); } if ((uint)Size > MaxUnparsedBytes) { return(false); } // Put the position back to the beginning of the header. // We want to be able the read the channel property. parser.Position -= 8; // Read the channel property (first 2 bytes of fourcc) if (!ParseChannel(parser)) { return(false); } // Read the information type property (last 2 bytes of fourcc) ParseStreamType(parser); // Skip the 'Size' bytes parser.Position += 4; ulong size = Math.Min(Size, parser.BytesRemaining); if (size > 0) { StreamData = parser.GetDataPacket(parser.Position, (long)size); } // Show the number of bytes that go to the codec detector parser.AddAttribute(new FormattedAttribute <Attribute, ulong>(Attribute.NumberOfBytesForCodecDetector, parser.BytesRemaining)); // Prevent AviChunk.ParseEnd() from displaying the unparsed bytes as hex dump parser.Position += (long)parser.BytesRemaining; return(Valid); }
public override bool Parse(AviParser parser) { if (_frameFieldType == FrameFieldType.Short) { short leftEdge = parser.GetShort(LAttribute.LeftEdge); short topEdge = parser.GetShort(LAttribute.TopEdge); short rightEdge = parser.GetShort(LAttribute.RightEdge); short bottomEdge = parser.GetShort(LAttribute.BottomEdge); TypedValue = string.Format("({0}, {1}, {2}, {3})", leftEdge, topEdge, rightEdge, bottomEdge); } else { int leftEdge = parser.GetInt(LAttribute.LeftEdge); int topEdge = parser.GetInt(LAttribute.TopEdge); int rightEdge = parser.GetInt(LAttribute.RightEdge); int bottomEdge = parser.GetInt(LAttribute.BottomEdge); TypedValue = string.Format("({0}, {1}, {2}, {3})", leftEdge, topEdge, rightEdge, bottomEdge); } return(Valid); }
public override bool Parse(AviParser parser) { if (!base.Parse(parser)) { return(false); } switch (_aviStreamFormatType) { case AviStreamFormatType.Video: parser.GetInt(Attribute.Size); parser.GetInt(Attribute.Width); parser.GetInt(Attribute.Height); parser.GetShort(Attribute.Planes); parser.GetShort(Attribute.BitCount); Compression = parser.GetFourCC(Attribute.Compression); parser.GetInt(Attribute.SizeImage); parser.GetInt(Attribute.XPelsPerMeter); parser.GetInt(Attribute.YPelsPerMeter); parser.GetInt(Attribute.ClrUsed); parser.GetInt(Attribute.ClrImportant); ulong extraDataSize = parser.BytesRemaining; if ((extraDataSize >= 17) && (extraDataSize < 256)) { ExtraData = parser.GetDataPacket(parser.Position, (int)extraDataSize); Attributes.Add(new FormattedAttribute <Attribute, ulong>(Attribute.ExtraDataSize, extraDataSize)); } break; case AviStreamFormatType.Audio: FormatTagValue = parser.GetShort(Attribute.FormatTag, typeof(FormatTag)); parser.GetShort(Attribute.Channels); parser.GetInt(Attribute.SamplesPerSec); parser.GetInt(Attribute.AvgBytesPerSec); parser.GetShort(Attribute.BlockAlign); parser.GetShort(Attribute.BitsPerSample); if (FormatTagValue != (short)FormatTag.WAVE_FORMAT_PCM && parser.BytesRemaining > 0) { parser.GetShort(Attribute.ExtraSize); } // TODO parse the other audio formats switch (FormatTagValue) { case (short)FormatTag.WAVE_FORMAT_MPEGLAYER3: if (parser.BytesRemaining > 0) { parser.GetShort(Attribute.Id); parser.GetInt(Attribute.Flags); // TODO Parse the flags parser.GetShort(Attribute.BlockSize); parser.GetShort(Attribute.FramesPerBlock); // Some file I found did not have this last field if (parser.BytesRemaining > 0) { parser.GetShort(Attribute.CodecDelay); } } break; } break; default: break; } return(Valid); }