#pragma warning disable IDE1006 // Naming Styles using System; using System.Runtime.InteropServices; using static Vanara.PInvoke.AviFil32; namespace Vanara.PInvoke { /// Items from the AviFil32.dll public static partial class AviFil32 { /// /// The IAVIEditStream interface supports manipulating and modifying editable streams. Uses IUnknown::QueryInterface, /// IUnknown::AddRef, IUnknown::Release in addition to the following custom methods: /// // https://docs.microsoft.com/en-us/windows/win32/api/vfw/nn-vfw-iavieditstream [PInvokeData("vfw.h", MSDNShortId = "NN:vfw.IAVIEditStream")] [ComImport, Guid("00020024-0000-0000-C000-000000000046"), InterfaceType(ComInterfaceType.InterfaceIsIUnknown)] public interface IAVIEditStream { /// /// The Cut method removes a portion of a stream and places it in a temporary stream. Called when an application uses the /// EditStreamCut function. /// /// Pointer to a buffer that receives the starting position of the operation. /// Pointer to a buffer that receives the length, in frames, of the operation. /// Pointer to a buffer that receives a pointer to the interface to the new stream. // https://docs.microsoft.com/en-us/windows/win32/api/vfw/nf-vfw-iavieditstream-cut HRESULT Cut( LONG *plStart, LONG *plLength, // PAVISTREAM *ppResult ); IAVIStream Cut(ref int plStart, ref int plLength); /// /// The Copy method copies a stream or a portion of it to a temporary stream. Called when an application uses the /// EditStreamCopy function. /// /// Pointer to a buffer that receives the starting position of the operation. /// Pointer to a buffer that receives the length, in frames, of the operation. /// Pointer to a buffer that receives a pointer to the interface to the new stream. // https://docs.microsoft.com/en-us/windows/win32/api/vfw/nf-vfw-iavieditstream-copy HRESULT Copy( LONG *plStart, LONG // *plLength, PAVISTREAM *ppResult ); IAVIStream Copy(ref int plStart, ref int plLength); /// /// The Paste method copies a stream or a portion of it in another stream. Called when an application uses the /// EditStreamPaste function. /// /// Pointer to a buffer that receives the starting position of the operation. /// Pointer to a buffer that receives the length, in bytes, of the data to paste from the source stream. /// Pointer to the interface to the source stream. /// Starting position of the copy operation within the source stream. /// Ending position of the copy operation within the source stream. // https://docs.microsoft.com/en-us/windows/win32/api/vfw/nf-vfw-iavieditstream-paste HRESULT Paste( LONG *plPos, LONG // *plLength, PAVISTREAM pstream, LONG lStart, LONG lEnd ); void Paste(ref int plPos, ref int plLength, [In, Out] IAVIStream pstream, [In] int lStart, [In] int lEnd); /// The Clone method duplicates a stream. Called when an application uses the EditStreamClone function. /// Receives a pointer to the interface to the new stream. // https://docs.microsoft.com/en-us/windows/win32/api/vfw/nf-vfw-iavieditstream-clone HRESULT Clone( PAVISTREAM *ppResult ); IAVIStream Clone(); /// /// The SetInfo method changes the characteristics of a stream. Called when an application uses the EditStreamSetInfo function. /// /// Pointer to an AVISTREAMINFO structure containing the new stream characteristics. /// Size, in bytes, of the buffer. /// Returns the HRESULT defined by OLE. /// /// For handlers written in C++, SetInfo has the following syntax: /// /// HRESULT SetInfo(AVISTREAMINFO *lpInfo, LONG cbInfo); /// /// // https://docs.microsoft.com/en-us/windows/win32/api/vfw/nf-vfw-iavieditstream-setinfo HRESULT SetInfo( AVISTREAMINFOW *lpInfo, // LONG cbInfo ); void SetInfo(in AVISTREAMINFO lpInfo, [In] int cbInfo); }; /// /// The IAVIFile interface supports opening and manipulating files and file headers, and creating and obtaining stream /// interfaces. Uses IUnknown::QueryInterface, IUnknown::AddRef, and IUnknown::Release in addition to the following custom methods: /// // https://docs.microsoft.com/en-us/windows/win32/api/vfw/nn-vfw-iavifile [PInvokeData("vfw.h", MSDNShortId = "NN:vfw.IAVIFile")] [ComImport, Guid("00020020-0000-0000-C000-000000000046"), InterfaceType(ComInterfaceType.InterfaceIsIUnknown)] public interface IAVIFile { /// /// The Info method returns with information about an AVI file. Called when an application uses the AVIFileInfo function. /// /// A pointer to an AVIFILEINFO structure. The method fills the structure with information about the file. /// The size, in bytes, of the buffer specified by pfi. /// /// /// If the buffer allocated is too small for the structure, this method should fail the call by returning AVIERR_BUFFERTOOSMALL. /// Otherwise, it should fill the structure and return its size. /// /// // https://docs.microsoft.com/en-us/windows/win32/api/vfw/nf-vfw-iavifile-info HRESULT Info( AVIFILEINFOW *pfi, LONG lSize ); void Info(out AVIFILEINFO pfi, [In] int lSize); /// /// The GetStream method opens a stream by accessing it in a file. Called when an application uses the AVIFileGetStream function. /// /// Pointer to a buffer that receives a pointer to the interface to a stream. /// Four-character code indicating the type of stream to locate. /// Stream number. /// /// /// It is typically easier to implement this method by creating all of the stream objects in advance by using the IAVIFile::Open /// method. Then, this method accesses the interface to the specified stream. /// /// /// Remember to increment the reference count maintained by the AddRef method for the stream when this method is used. /// /// // https://docs.microsoft.com/en-us/windows/win32/api/vfw/nf-vfw-iavifile-getstream HRESULT GetStream( PAVISTREAM *ppStream, // DWORD fccType, LONG lParam ); void GetStream(out IAVIStream ppStream, [In] uint fccType, [In] int lParam); /// /// The CreateStream method creates a stream for writing. Called when an application uses the AVIFileCreateStream function. /// /// Pointer to a buffer that receives a pointer to the interface to the new stream. /// Pointer to an AVISTREAMINFO structure defining the stream to create. // https://docs.microsoft.com/en-us/windows/win32/api/vfw/nf-vfw-iavifile-createstream HRESULT CreateStream( PAVISTREAM // *ppStream, AVISTREAMINFOW *psi ); void CreateStream(out IAVIStream ppStream, in AVISTREAMINFO psi); /// The WriteData method writes file headers. Called when an application uses the AVIFileWriteData function. /// A chunk ID. /// A pointer specifying the memory from which the data is written. /// A LONG specifying the number of bytes to write. // https://docs.microsoft.com/en-us/windows/win32/api/vfw/nf-vfw-iavifile-writedata HRESULT WriteData( DWORD ckid, LPVOID // lpData, LONG cbData ); void WriteData([In] uint ckid, [In] IntPtr lpData, [In] int cbData); /// The ReadData method reads file headers. Called when an application uses the AVIFileReadData function. /// A chunk identfier. /// A pointer specifying the memory into which the data is read. /// A pointer to a LONG specifying the number of bytes read. // https://docs.microsoft.com/en-us/windows/win32/api/vfw/nf-vfw-iavifile-readdata HRESULT ReadData( DWORD ckid, LPVOID lpData, // LONG *lpcbData ); void ReadData([In] uint ckid, [Out] IntPtr lpData, ref int lpcbData); /// /// The EndRecord method writes the "REC" chunk in a tightly interleaved AVI file (having a one-to-one interleave factor /// of audio to video). Called when an application uses the AVIFileEndRecord function. /// /// /// This file handler method is typically not used. /// // https://docs.microsoft.com/en-us/windows/win32/api/vfw/nf-vfw-iavifile-endrecord HRESULT EndRecord(); void EndRecord(); /// Deletes the stream. /// Four-character code indicating the type of stream to delete. /// Stream number. void DeleteStream([In] uint fccType, [In] int lParam); } /// /// The IAVIStream interface supports creating and manipulating data streams within a file. Uses IUnknown::QueryInterface, /// IUnknown::AddRef, IUnknown::Release in addition to the following custom methods: /// // https://docs.microsoft.com/en-us/windows/win32/api/vfw/nn-vfw-iavistream [PInvokeData("vfw.h", MSDNShortId = "NN:vfw.IAVIStream")] [ComImport, Guid("00020021-0000-0000-C000-000000000046"), InterfaceType(ComInterfaceType.InterfaceIsIUnknown)] public interface IAVIStream { /// /// The Create method initializes a stream handler that is not associated with any file. Called when an application uses /// the AVIStreamCreate function. /// /// Stream handler-specific data. /// Stream handler-specific data. // https://docs.microsoft.com/en-us/windows/win32/api/vfw/nf-vfw-iavistream-create HRESULT Create( LPARAM lParam1, LPARAM // lParam2 ); void Create(IntPtr lParam1, IntPtr lParam2); /// /// The Info method fills and returns an AVISTREAMINFO structure with information about a stream. Called when an /// application uses the AVIStreamInfo function. /// /// Pointer to an AVISTREAMINFO structure to contain stream information. /// Size, in bytes, of the structure specified by psi. /// /// /// If the buffer allocated is too small for the structure, the Info method should fail the call by returning /// AVIERR_BUFFERTOOSMALL. Otherwise, it should fill the structure and return its size. /// /// // https://docs.microsoft.com/en-us/windows/win32/api/vfw/nf-vfw-iavistream-info HRESULT Info( AVISTREAMINFOW *psi, LONG lSize ); void Info(out AVISTREAMINFO psi, [In] int lSize); /// /// The FindSample method obtains the position in a stream of a key frame or a nonempty frame. Called when an application /// uses the AVIStreamFindSample function. /// /// Position of the sample or frame. /// /// Applicable flags. The following values are defined. /// /// /// Value /// Description /// /// /// FIND_ANY /// Searches for a nonempty frame. /// /// /// FIND_FORMAT /// Searches for a format change. /// /// /// FIND_KEY /// Searches for a key frame. /// /// /// FIND_NEXT /// Searches forward through a stream, beginning with the current frame. /// /// /// FIND_PREV /// Searches backward through a stream, beginning with the current frame. /// /// /// /// The FIND_ANY, FIND_KEY, and FIND_FORMAT flags are mutually exclusive, as are the FIND_NEXT and FIND_PREV flags. You must /// specify one value from each group. /// /// /// Returns the location of the key frame corresponding to the frame specified by the application. /// /// If key frames are not significant in your custom format, return the position specified for lPos. /// // https://docs.microsoft.com/en-us/windows/win32/api/vfw/nf-vfw-iavistream-findsample LONG FindSample( LONG lPos, LONG lFlags ); [PreserveSig] int FindSample([In] int lPos, [In] FINDF lFlags); /// /// The ReadFormat method obtains format information from a stream. Fills and returns a structure with the data in an /// application-defined buffer. If no buffer is supplied, determines the buffer size needed to retrieve the buffer of format /// data. Called when an application uses the AVIStreamReadFormat function. /// /// Position of the sample or frame. /// /// Pointer to the buffer for the format data. Specify NULL to request the required size of the buffer. /// /// /// Pointer to a buffer that receives the size, in bytes, of the buffer specified by lpFormat. When this method is called, the /// contents of this parameter indicates the size of the buffer specified by lpFormat. When this method returns control to the /// application, the contents of this parameter specifies the amount of data read or the required size of the buffer. /// /// /// /// The type of data stored in a stream dictates the format information and the structure that contains the format information. /// A stream handler should return all applicable format information in this structure, including palette information when the /// format uses a palette. A stream handler should not return stream data with the structure. /// /// /// Standard video stream handlers provide format information in a BITMAPINFOHEADER structure. Standard audio stream /// handlers provide format information in a PCMWAVEFORMAT structure. Other data streams can use other structures that /// describe the stream data. /// /// // https://docs.microsoft.com/en-us/windows/win32/api/vfw/nf-vfw-iavistream-readformat HRESULT ReadFormat( LONG lPos, LPVOID // lpFormat, LONG *lpcbFormat ); void ReadFormat([In] int lPos, [Out, Optional] IntPtr lpFormat, ref int lpcbFormat); /// /// The SetFormat method sets format information in a stream. Called when an application uses the AVIStreamSetFormat function. /// /// Pointer to the interface to a stream. /// Pointer to the buffer for the format data. /// Address containing the size, in bytes, of the buffer specified by lpFormat. /// /// /// Standard video stream handlers provide format information in a BITMAPINFOHEADER structure. Standard audio stream /// handlers provide format information in a PCMWAVEFORMAT structure. Other data streams can use other structures that /// describe the stream data. /// /// // https://docs.microsoft.com/en-us/windows/win32/api/vfw/nf-vfw-iavistream-setformat HRESULT SetFormat( LONG lPos, LPVOID // lpFormat, LONG cbFormat ); void SetFormat([In] int lPos, [In] IntPtr lpFormat, [In] int cbFormat); /// /// The Read method reads data from a stream and copies it to an application-defined buffer. If no buffer is supplied, it /// determines the buffer size needed to retrieve the next buffer of data. Called when an application uses the AVIStreamRead function. /// /// Starting sample or frame number to read. /// Number of samples to read. /// /// Pointer to the application-defined buffer to contain the stream data. You can also specify NULL to request the /// required size of the buffer. Many applications precede each read operation with a query for the buffer size to see how large /// a buffer is needed. /// /// Size, in bytes, of the buffer specified by lpBuffer. /// Pointer to a buffer that receives the number of bytes read. /// Pointer to a buffer that receives the number of samples read. // https://docs.microsoft.com/en-us/windows/win32/api/vfw/nf-vfw-iavistream-read HRESULT Read( LONG lStart, LONG lSamples, // LPVOID lpBuffer, LONG cbBuffer, LONG *plBytes, LONG *plSamples ); void Read([In] int lStart, [In] int lSamples, [Out, Optional] IntPtr lpBuffer, [In] int cbBuffer, out int plBytes, out int plSamples); /// The Write method writes data to a stream. Called when an application uses the AVIStreamWrite function. /// Starting sample or frame number to write. /// Number of samples to write. /// Pointer to the buffer for the data. /// Size, in bytes, of the buffer specified by lpBuffer. /// /// Applicable flags. The AVIF_KEYFRAME flag is defined and indicates that this frame contains all the information needed for a /// complete image. /// /// Pointer to a buffer used to contain the number of samples written. /// Pointer to a buffer that receives the number of bytes written. // https://docs.microsoft.com/en-us/windows/win32/api/vfw/nf-vfw-iavistream-write HRESULT Write( LONG lStart, LONG lSamples, // LPVOID lpBuffer, LONG cbBuffer, DWORD dwFlags, LONG *plSampWritten, LONG *plBytesWritten ); void Write([In] int lStart, [In] int lSamples, [In] IntPtr lpBuffer, [In] int cbBuffer, [In] AVIIF dwFlags, out int plSampWritten, out int plBytesWritten); /// The Delete method deletes data from a stream. /// Starting sample or frame number to delete. /// Number of samples to delete. // https://docs.microsoft.com/en-us/windows/win32/api/vfw/nf-vfw-iavistream-delete HRESULT Delete( LONG lStart, LONG lSamples ); void Delete([In] int lStart, [In] int lSamples); /// /// The ReadData method reads data headers of a stream. Called when an application uses the AVIStreamReadData function. /// /// Four-character code of the stream header to read. /// Pointer to the buffer to contain the header data. /// /// Size, in bytes, of the buffer specified by lpBuffer. When this method returns control to the application, the contents of /// this parameter specifies the amount of data read. /// // https://docs.microsoft.com/en-us/windows/win32/api/vfw/nf-vfw-iavistream-readdata HRESULT ReadData( DWORD fcc, LPVOID lp, // LONG *lpcb ); void ReadData([In] uint fcc, [Out, Optional] IntPtr lp, ref int lpcb); /// /// The WriteData method writes headers for a stream. Called when an application uses the AVIStreamWriteData function. /// /// Four-character code of the stream header to write. /// Pointer to the buffer that contains the header data to write. /// Size, in bytes, of the buffer specified by lpBuffer. // https://docs.microsoft.com/en-us/windows/win32/api/vfw/nf-vfw-iavistream-writedata HRESULT WriteData( DWORD fcc, LPVOID lp, // LONG cb ); void WriteData([In] uint fcc, [In] IntPtr lp, [In] int cb); } /// /// The IAVIStreaming interface supports preparing open data streams for playback in streaming operations. Uses /// IUnknown::QueryInterface, IUnknown::AddRef, IUnknown::Release in addition to the following custom methods: /// // https://docs.microsoft.com/en-us/windows/win32/api/vfw/nn-vfw-iavistreaming [PInvokeData("vfw.h", MSDNShortId = "NN:vfw.IAVIStreaming")] [ComImport, Guid("00020022-0000-0000-C000-000000000046"), InterfaceType(ComInterfaceType.InterfaceIsIUnknown)] public interface IAVIStreaming { /// /// The Begin method prepares for the streaming operation. Called when an application uses the AVIStreamBeginStreaming function. /// /// Starting frame for streaming. /// Ending frame for streaming. /// /// Speed at which the file is read relative to its normal playback rate. Normal speed is 1000. Larger values indicate faster /// speeds; smaller values indicate slower speeds. /// // https://docs.microsoft.com/en-us/windows/win32/api/vfw/nf-vfw-iavistreaming-begin HRESULT Begin( LONG lStart, LONG lEnd, LONG // lRate ); void Begin([In] int lStart, [In] int lEnd, [In] int lRate); /// /// The End method ends the streaming operation. Called when an application uses the AVIStreamEndStreaming function. /// // https://docs.microsoft.com/en-us/windows/win32/api/vfw/nf-vfw-iavistreaming-end HRESULT End(); void End(); }; //[ComImport, Guid("00020025-0000-0000-C000-000000000046"), InterfaceType(ComInterfaceType.InterfaceIsIUnknown)] //public interface IAVIPersistFile : System.Runtime.InteropServices.ComTypes.IPersistFile //{ // new void GetClassID(out Guid pClassID); // new int IsDirty(); // new void Load(string pszFileName, int dwMode); // new void Save(string pszFileName, bool fRemember); // new void SaveCompleted(string pszFileName); // new void GetCurFile(out string ppszFileName); // void Reserved1(); //} /// /// The IGetFrame interface supports extracting, decompressing, and displaying individual frames from an open stream. Uses /// IUnknown::QueryInterface, IUnknown::AddRef, IUnknown::Release in addition to the following custom methods: /// // https://docs.microsoft.com/en-us/windows/win32/api/vfw/nn-vfw-igetframe [PInvokeData("vfw.h", MSDNShortId = "NN:vfw.IGetFrame")] [ComImport, Guid("00020023-0000-0000-C000-000000000046"), InterfaceType(ComInterfaceType.InterfaceIsIUnknown)] public interface IGetFrame { /// /// The GetFrame method retrieves a decompressed copy of a frame from a stream. Called when an application uses the /// AVIStreamGetFrame function. /// /// Frame to copy and decompress. /// Returns the address of the decompressed frame data. // https://docs.microsoft.com/en-us/windows/win32/api/vfw/nf-vfw-igetframe-getframe LPVOID GetFrame( LONG lPos ); [PreserveSig] IntPtr GetFrame([In] int lPos); /// /// The Begin method prepares to extract and decompress copies of frames from a stream. Called when an application uses /// the AVIStreamGetFrameOpen function. /// /// Starting frame for extracting and decompressing. /// Ending frame for extracting and decompressing. /// /// Speed at which the file is read relative to its normal playback rate. Normal speed is 1000. Larger values indicate faster /// speeds; smaller values indicate slower speeds. /// // https://docs.microsoft.com/en-us/windows/win32/api/vfw/nf-vfw-igetframe-begin HRESULT Begin( LONG lStart, LONG lEnd, LONG // lRate ); void Begin([In] int lStart, [In] int lEnd, [In] int lRate); /// /// The End method ends frame extraction and decompression. Called when an application uses the AVIStreamGetFrameClose function. /// // https://docs.microsoft.com/en-us/windows/win32/api/vfw/nf-vfw-igetframe-end HRESULT End(); void End(); /// /// The SetFormat method sets the decompressed image format of the frames being extracted and optionally provides a /// buffer for the decompression operation. /// /// /// Pointer to a BITMAPINFOHEADER structure defining the decompressed image format. You can also specify NULL or the value /// ((LPBITMAPINFOHEADER) 1) /// for this parameter. NULL causes the decompressor to choose a format that is appropriate for editing (normally a /// 24-bit image depth format). The value /// ((LPBITMAPINFOHEADER) 1) /// causes the decompressor to choose a format appropriate for the current display mode. /// /// /// Pointer to a buffer to contain the decompressed image data. Specify NULL to have this method allocate a buffer. /// /// /// The x-coordinate of the destination rectangle within the DIB specified by lpbi. This parameter is used when lpBits is not NULL. /// /// /// The y-coordinate of the destination rectangle within the DIB specified by lpbi. This parameter is used when lpBits is not NULL. /// /// Width of the destination rectangle. This parameter is used when lpBits is not NULL. /// Height of the destination rectangle. This parameter is used when lpBits is not NULL. /// /// /// The x, y, dx, and dy parameters identify the portion of the bitmap specified by lpbi and lpBits that receives the /// decompressed image. /// /// // https://docs.microsoft.com/en-us/windows/win32/api/vfw/nf-vfw-igetframe-setformat HRESULT SetFormat( LPBITMAPINFOHEADER lpbi, // LPVOID lpBits, int x, int y, int dx, int dy ); void SetFormat(in Gdi32.BITMAPINFOHEADER lpbi, [In, Optional] IntPtr lpBits, [In] int x, [In] int y, [In] int dx, [In] int dy); } } }