public override bool Parse(AviParser parser) { if (!base.Parse(parser)) { return(false); } const int IntFieldsCount = 17; const int ExpectedSize = IntFieldsCount * sizeof(int); if (Size < ExpectedSize) // invalidate the size attribute { parser.CheckAttribute(AviChunk.Attribute.Size, Size == ExpectedSize, false); } else if (Size > ExpectedSize) // invalidate the complete header { parser.CheckAttribute(AviChunk.Attribute.Size, Size == ExpectedSize, true); } if (parser.BytesRemaining >= 4) { parser.GetInt(Attribute.VideoFormatToken, typeof(VideoFormatToken)); } if (parser.BytesRemaining >= 4) { parser.GetInt(Attribute.VideoStandard, typeof(VideoStandard)); } if (parser.BytesRemaining >= 4) { parser.GetInt(Attribute.VerticalRefreshRate); } if (parser.BytesRemaining >= 4) { parser.GetInt(Attribute.HorizontalTotalInT); } if (parser.BytesRemaining >= 4) { parser.GetInt(Attribute.VerticalTotalInLines); } if (parser.BytesRemaining >= 4) { parser.GetFrameAspectRatio(Attribute.FrameAspectRatio); } if (parser.BytesRemaining >= 4) { parser.GetInt(Attribute.FrameWidthInPixels); } if (parser.BytesRemaining >= 4) { parser.GetInt(Attribute.FrameHeightInLines); } if (parser.BytesRemaining >= 4) { parser.GetInt(Attribute.FieldPerFrame); } if (parser.BytesRemaining >= 4) { parser.GetInt(Attribute.CompressedBitmapHeight); } if (parser.BytesRemaining >= 4) { parser.GetInt(Attribute.CompressedBitmapWidth); } if (parser.BytesRemaining >= 4) { parser.GetInt(Attribute.ValidBitmapHeight); } if (parser.BytesRemaining >= 4) { parser.GetInt(Attribute.ValidBitmapWidth); } if (parser.BytesRemaining >= 4) { parser.GetInt(Attribute.ValidBitmapXOffset); } if (parser.BytesRemaining >= 4) { parser.GetInt(Attribute.ValidBitmapYOffset); } if (parser.BytesRemaining >= 4) { parser.GetInt(Attribute.VideoXOffsetInT); } if (parser.BytesRemaining >= 4) { parser.GetInt(Attribute.VideoYValidStartLine); } return(Valid); }
public override bool Parse(AviParser parser) { if (!base.Parse(parser)) { return(false); } const int FrameSize = 4 * sizeof(short); const int IntFieldCount = 11; const int ShortFieldCount = 2; const int ExpectedSize = IntFieldCount * sizeof(int) + ShortFieldCount * sizeof(short) + FrameSize; // One sample had 8 bytes more. // The assumption is made that the frame is written in four ints // instead of in four shorts. const int ExtraBytesAllowed = 8; if ((Size < ExpectedSize) || (Size > ExpectedSize && Size <= ExpectedSize + ExtraBytesAllowed)) // invalidate the size attribute { parser.CheckAttribute(AviChunk.Attribute.Size, Size == ExpectedSize, false); } else if (Size > ExpectedSize + ExtraBytesAllowed) // invalidate the complete header { parser.CheckAttribute(AviChunk.Attribute.Size, Size == ExpectedSize, true); } if (parser.BytesRemaining >= 4) { StreamType = parser.GetFourCC(Attribute.StreamType); } if (parser.BytesRemaining >= 4) { Handler = parser.GetFourCC(Attribute.Handler); } if (parser.BytesRemaining >= 4) { parser.GetInt(Attribute.Flags); } // TODO parse flags // // AVISF_DISABLED = 0x00000001 // Indicates this stream should not be enabled by default // // AVISF_VIDEO_PALCHANGES = 0x00010000 // Indicates this video stream contains palette changes. // This flag warns the playback software that it will need to // animate the palette. // if (parser.BytesRemaining >= 2) { parser.GetShort(Attribute.Priority); } if (parser.BytesRemaining >= 2) { parser.GetShort(Attribute.Language); } if (parser.BytesRemaining >= 4) { parser.GetInt(Attribute.InitialFrames); } if (parser.BytesRemaining >= 4) { parser.GetInt(Attribute.Scale); } if (parser.BytesRemaining >= 4) { parser.GetInt(Attribute.Rate); } if (parser.BytesRemaining >= 4) { parser.GetInt(Attribute.Start); } if (parser.BytesRemaining >= 4) { parser.GetInt(Attribute.Length); } if (parser.BytesRemaining >= 4) { parser.GetInt(Attribute.SuggestedBufferSize); } if (parser.BytesRemaining >= 4) { parser.GetInt(Attribute.Quality); } if (parser.BytesRemaining >= 4) { parser.GetInt(Attribute.SampleSize); } if (Size == ExpectedSize) { if (parser.BytesRemaining >= 8) { parser.GetFrame(Attribute.Frame, FrameFieldType.Short); } } else if (Size == ExpectedSize + 4 * sizeof(short)) { if (parser.BytesRemaining >= 16) { parser.GetFrame(Attribute.Frame, FrameFieldType.Int); } } return(Valid); }