diff --git a/VAR.Toolbox/Code/DirectShow/CameraControlProperty.cs b/VAR.Toolbox/Code/DirectShow/CameraControlProperty.cs new file mode 100644 index 0000000..7ccb10e --- /dev/null +++ b/VAR.Toolbox/Code/DirectShow/CameraControlProperty.cs @@ -0,0 +1,59 @@ +namespace VAR.Toolbox.Code.DirectShow +{ + using System; + + /// + /// The enumeration specifies a setting on a camera. + /// + public enum CameraControlProperty + { + /// + /// Pan control. + /// + Pan = 0, + /// + /// Tilt control. + /// + Tilt, + /// + /// Roll control. + /// + Roll, + /// + /// Zoom control. + /// + Zoom, + /// + /// Exposure control. + /// + Exposure, + /// + /// Iris control. + /// + Iris, + /// + /// Focus control. + /// + Focus + } + + /// + /// The enumeration defines whether a camera setting is controlled manually or automatically. + /// + [Flags] + public enum CameraControlFlags + { + /// + /// No control flag. + /// + None = 0x0, + /// + /// Auto control Flag. + /// + Auto = 0x0001, + /// + /// Manual control Flag. + /// + Manual = 0x0002 + } +} diff --git a/VAR.Toolbox/Code/DirectShow/IAMCameraControl.cs b/VAR.Toolbox/Code/DirectShow/IAMCameraControl.cs new file mode 100644 index 0000000..f62b58a --- /dev/null +++ b/VAR.Toolbox/Code/DirectShow/IAMCameraControl.cs @@ -0,0 +1,73 @@ +namespace VAR.Toolbox.Code.DirectShow +{ + using System; + using System.Runtime.InteropServices; + + /// + /// The IAMCameraControl interface controls camera settings such as zoom, pan, aperture adjustment, + /// or shutter speed. To obtain this interface, query the filter that controls the camera. + /// + [ComImport, + Guid( "C6E13370-30AC-11d0-A18C-00A0C9118956" ), + InterfaceType( ComInterfaceType.InterfaceIsIUnknown )] + internal interface IAMCameraControl + { + /// + /// Gets the range and default value of a specified camera property. + /// + /// + /// Specifies the property to query. + /// Receives the minimum value of the property. + /// Receives the maximum value of the property. + /// Receives the step size for the property. + /// Receives the default value of the property. + /// Receives a member of the CameraControlFlags enumeration, indicating whether the property is controlled automatically or manually. + /// + /// Return's HRESULT error code. + /// + [PreserveSig] + int GetRange( + [In] CameraControlProperty Property, + [Out] out int pMin, + [Out] out int pMax, + [Out] out int pSteppingDelta, + [Out] out int pDefault, + [Out] out CameraControlFlags pCapsFlags + ); + + /// + /// Sets a specified property on the camera. + /// + /// + /// Specifies the property to set. + /// Specifies the new value of the property. + /// Specifies the desired control setting, as a member of the CameraControlFlags enumeration. + /// + /// Return's HRESULT error code. + /// + [PreserveSig] + int Set( + [In] CameraControlProperty Property, + [In] int lValue, + [In] CameraControlFlags Flags + ); + + /// + /// Gets the current setting of a camera property. + /// + /// + /// Specifies the property to retrieve. + /// Receives the value of the property. + /// Receives a member of the CameraControlFlags enumeration. + /// The returned value indicates whether the setting is controlled manually or automatically. + /// + /// Return's HRESULT error code. + /// + [PreserveSig] + int Get( + [In] CameraControlProperty Property, + [Out] out int lValue, + [Out] out CameraControlFlags Flags + ); + } +} diff --git a/VAR.Toolbox/Code/DirectShow/IAMCrossbar.cs b/VAR.Toolbox/Code/DirectShow/IAMCrossbar.cs new file mode 100644 index 0000000..faef3fe --- /dev/null +++ b/VAR.Toolbox/Code/DirectShow/IAMCrossbar.cs @@ -0,0 +1,80 @@ +using System; +using System.Runtime.InteropServices; + +namespace VAR.Toolbox.Code.DirectShow +{ + /// + /// The IAMCrossbar interface routes signals from an analog or digital source to a video capture filter. + /// + [ComImport, System.Security.SuppressUnmanagedCodeSecurity, + Guid( "C6E13380-30AC-11D0-A18C-00A0C9118956" ), + InterfaceType( ComInterfaceType.InterfaceIsIUnknown )] + internal interface IAMCrossbar + { + /// + /// Retrieves the number of input and output pins on the crossbar filter. + /// + /// + /// Variable that receives the number of output pins. + /// Variable that receives the number of input pins. + /// + /// Return's HRESULT error code. + /// + [PreserveSig] + int get_PinCounts( [Out] out int outputPinCount, [Out] out int inputPinCount ); + + /// + /// Queries whether a specified input pin can be routed to a specified output pin. + /// + /// + /// Specifies the index of the output pin. + /// Specifies the index of input pin. + /// + /// Return's HRESULT error code. + /// + [PreserveSig] + int CanRoute( [In] int outputPinIndex, [In] int inputPinIndex ); + + /// + /// Routes an input pin to an output pin. + /// + /// + /// Specifies the index of the output pin. + /// Specifies the index of the input pin. + /// + /// Return's HRESULT error code. + /// + [PreserveSig] + int Route( [In] int outputPinIndex, [In] int inputPinIndex ); + + /// + /// Retrieves the input pin that is currently routed to the specified output pin. + /// + /// + /// Specifies the index of the output pin. + /// Variable that receives the index of the input pin, or -1 if no input pin is routed to this output pin. + /// + /// Return's HRESULT error code. + /// + [PreserveSig] + int get_IsRoutedTo( [In] int outputPinIndex, [Out] out int inputPinIndex ); + + /// + /// Retrieves information about a specified pin. + /// + /// + /// Specifies the direction of the pin. Use one of the following values. + /// Specifies the index of the pin. + /// Variable that receives the index of the related pin, or –1 if no pin is related to this pin. + /// Variable that receives a member of the PhysicalConnectorType enumeration, indicating the pin's physical type. + /// + /// Return's HRESULT error code. + /// + [PreserveSig] + int get_CrossbarPinInfo( + [In, MarshalAs( UnmanagedType.Bool )] bool isInputPin, + [In] int pinIndex, + [Out] out int pinIndexRelated, + [Out] out PhysicalConnectorType physicalType ); + } +} diff --git a/VAR.Toolbox/Code/DirectShow/IAMStreamConfig.cs b/VAR.Toolbox/Code/DirectShow/IAMStreamConfig.cs new file mode 100644 index 0000000..d14e163 --- /dev/null +++ b/VAR.Toolbox/Code/DirectShow/IAMStreamConfig.cs @@ -0,0 +1,67 @@ +namespace VAR.Toolbox.Code.DirectShow +{ + using System; + using System.Runtime.InteropServices; + + /// + /// This interface sets the output format on certain capture and compression filters, + /// for both audio and video. + /// + /// + [ComImport, + Guid( "C6E13340-30AC-11d0-A18C-00A0C9118956" ), + InterfaceType( ComInterfaceType.InterfaceIsIUnknown )] + internal interface IAMStreamConfig + { + /// + /// Set the output format on the pin. + /// + /// + /// Media type to set. + /// + /// Return's HRESULT error code. + /// + [PreserveSig] + int SetFormat( [In, MarshalAs( UnmanagedType.LPStruct )] AMMediaType mediaType ); + + /// + /// Retrieves the audio or video stream's format. + /// + /// + /// Retrieved media type. + /// + /// Return's HRESULT error code. + /// + [PreserveSig] + int GetFormat( [Out, MarshalAs( UnmanagedType.LPStruct )] out AMMediaType mediaType ); + + /// + /// Retrieve the number of format capabilities that this pin supports. + /// + /// + /// Variable that receives the number of format capabilities. + /// Variable that receives the size of the configuration structure in bytes. + /// + /// Return's HRESULT error code. + /// + [PreserveSig] + int GetNumberOfCapabilities( out int count, out int size ); + + /// + /// Retrieve a set of format capabilities. + /// + /// + /// Specifies the format capability to retrieve, indexed from zero. + /// Retrieved media type. + /// Byte array, which receives information about capabilities. + /// + /// Return's HRESULT error code. + /// + [PreserveSig] + int GetStreamCaps( + [In] int index, + [Out, MarshalAs( UnmanagedType.LPStruct )] out AMMediaType mediaType, + [In, MarshalAs( UnmanagedType.LPStruct )] VideoStreamConfigCaps streamConfigCaps + ); + } +} diff --git a/VAR.Toolbox/Code/DirectShow/IAMVideoControl.cs b/VAR.Toolbox/Code/DirectShow/IAMVideoControl.cs new file mode 100644 index 0000000..b15e655 --- /dev/null +++ b/VAR.Toolbox/Code/DirectShow/IAMVideoControl.cs @@ -0,0 +1,104 @@ +namespace VAR.Toolbox.Code.DirectShow +{ + using System; + using System.Runtime.InteropServices; + + /// + /// The interface controls certain video capture operations such as enumerating available + /// frame rates and image orientation. + /// + /// + [ComImport, + Guid( "6A2E0670-28E4-11D0-A18c-00A0C9118956" ), + InterfaceType( ComInterfaceType.InterfaceIsIUnknown )] + internal interface IAMVideoControl + { + /// + /// Retrieves the capabilities of the underlying hardware. + /// + /// + /// Pin to query capabilities from. + /// Get capabilities of the specified pin. + /// + /// Return's HRESULT error code. + /// + [PreserveSig] + int GetCaps( [In] IPin pin, [Out, MarshalAs( UnmanagedType.I4 )] out VideoControlFlags flags ); + + /// + /// Sets the video control mode of operation. + /// + /// + /// The pin to set the video control mode on. + /// Value specifying a combination of the flags to set the video control mode. + /// + /// Return's HRESULT error code. + /// + [PreserveSig] + int SetMode( [In] IPin pin, [In, MarshalAs( UnmanagedType.I4 )] VideoControlFlags mode ); + + /// + /// Retrieves the video control mode of operation. + /// + /// + /// The pin to retrieve the video control mode from. + /// Gets combination of flags, which specify the video control mode. + /// + /// Return's HRESULT error code. + /// + [PreserveSig] + int GetMode( [In] IPin pin, [Out, MarshalAs( UnmanagedType.I4 )] out VideoControlFlags mode ); + + /// + /// The method retrieves the actual frame rate, expressed as a frame duration in 100-nanosecond units. + /// USB (Universal Serial Bus) and IEEE 1394 cameras may provide lower frame rates than requested + /// because of bandwidth availability. This is only available during video streaming. + /// + /// + /// The pin to retrieve the frame rate from. + /// Gets frame rate in frame duration in 100-nanosecond units. + /// + /// Return's HRESULT error code. + /// + [PreserveSig] + int GetCurrentActualFrameRate( [In] IPin pin, [Out, MarshalAs( UnmanagedType.I8 )] out long actualFrameRate ); + + /// + /// Retrieves the maximum frame rate currently available based on bus bandwidth usage for connections + /// such as USB and IEEE 1394 camera devices where the maximum frame rate can be limited by bandwidth + /// availability. + /// + /// + /// The pin to retrieve the maximum frame rate from. + /// Index of the format to query for maximum frame rate. This index corresponds + /// to the order in which formats are enumerated by . + /// Frame image size (width and height) in pixels. + /// Gets maximum available frame rate. The frame rate is expressed as frame duration in 100-nanosecond units. + /// + /// Return's HRESULT error code. + /// + [PreserveSig] + int GetMaxAvailableFrameRate( [In] IPin pin, [In] int index, + [In] System.Drawing.Size dimensions, + [Out] out long maxAvailableFrameRate ); + + /// + /// Retrieves a list of available frame rates. + /// + /// + /// The pin to retrieve the maximum frame rate from. + /// Index of the format to query for maximum frame rate. This index corresponds + /// to the order in which formats are enumerated by . + /// Frame image size (width and height) in pixels. + /// Number of elements in the list of frame rates. + /// Array of frame rates in 100-nanosecond units. + /// + /// Return's HRESULT error code. + /// + [PreserveSig] + int GetFrameRateList( [In] IPin pin, [In] int index, + [In] System.Drawing.Size dimensions, + [Out] out int listSize, + [Out] out IntPtr frameRate ); + } +} diff --git a/VAR.Toolbox/Code/DirectShow/IBaseFilter.cs b/VAR.Toolbox/Code/DirectShow/IBaseFilter.cs new file mode 100644 index 0000000..7a48890 --- /dev/null +++ b/VAR.Toolbox/Code/DirectShow/IBaseFilter.cs @@ -0,0 +1,154 @@ +namespace VAR.Toolbox.Code.DirectShow +{ + using System; + using System.Runtime.InteropServices; + + /// + /// The IBaseFilter interface provides methods for controlling a filter. + /// All DirectShow filters expose this interface + /// + /// + [ComImport, + Guid( "56A86895-0AD4-11CE-B03A-0020AF0BA770" ), + InterfaceType( ComInterfaceType.InterfaceIsIUnknown )] + internal interface IBaseFilter + { + // --- IPersist Methods + + /// + /// Returns the class identifier (CLSID) for the component object. + /// + /// + /// Points to the location of the CLSID on return. + /// + /// Return's HRESULT error code. + /// + [PreserveSig] + int GetClassID( [Out] out Guid ClassID ); + + // --- IMediaFilter Methods + + /// + /// Stops the filter. + /// + /// + /// Return's HRESULT error code. + /// + [PreserveSig] + int Stop( ); + + /// + /// Pauses the filter. + /// + /// + /// Return's HRESULT error code. + /// + [PreserveSig] + int Pause( ); + + /// + /// Runs the filter. + /// + /// + /// Reference time corresponding to stream time 0. + /// + /// Return's HRESULT error code. + /// + [PreserveSig] + int Run( long start ); + + /// + /// Retrieves the state of the filter (running, stopped, or paused). + /// + /// + /// Time-out interval, in milliseconds. + /// Pointer to a variable that receives filter's state. + /// + /// Return's HRESULT error code. + /// + [PreserveSig] + int GetState( int milliSecsTimeout, [Out] out int filterState ); + + /// + /// Sets the reference clock for the filter or the filter graph. + /// + /// + /// Pointer to the clock's IReferenceClock interface, or NULL. + /// + /// Return's HRESULT error code. + /// + [PreserveSig] + int SetSyncSource( [In] IntPtr clock ); + + /// + /// Retrieves the current reference clock. + /// + /// + /// Address of a variable that receives a pointer to the clock's IReferenceClock interface. + /// + /// Return's HRESULT error code. + /// + [PreserveSig] + int GetSyncSource( [Out] out IntPtr clock ); + + // --- IBaseFilter Methods + + /// + /// Enumerates the pins on this filter. + /// + /// + /// Address of a variable that receives a pointer to the IEnumPins interface. + /// + /// Return's HRESULT error code. + /// + [PreserveSig] + int EnumPins( [Out] out IEnumPins enumPins ); + + /// + /// Retrieves the pin with the specified identifier. + /// + /// + /// Pointer to a constant wide-character string that identifies the pin. + /// Address of a variable that receives a pointer to the pin's IPin interface. + /// + /// Return's HRESULT error code. + /// + [PreserveSig] + int FindPin( [In, MarshalAs( UnmanagedType.LPWStr )] string id, [Out] out IPin pin ); + + /// + /// Retrieves information about the filter. + /// + /// + /// Pointer to FilterInfo structure. + /// + /// Return's HRESULT error code. + /// + [PreserveSig] + int QueryFilterInfo( [Out] out FilterInfo filterInfo ); + + /// + /// Notifies the filter that it has joined or left the filter graph. + /// + /// + /// Pointer to the Filter Graph Manager's IFilterGraph interface, or NULL + /// if the filter is leaving the graph. + /// String that specifies a name for the filter. + /// + /// Return's HRESULT error code. + /// + [PreserveSig] + int JoinFilterGraph( [In] IFilterGraph graph, [In, MarshalAs( UnmanagedType.LPWStr )] string name ); + + /// + /// Retrieves a string containing vendor information. + /// + /// + /// Receives a string containing the vendor information. + /// + /// Return's HRESULT error code. + /// + [PreserveSig] + int QueryVendorInfo( [Out, MarshalAs( UnmanagedType.LPWStr )] out string vendorInfo ); + } +} diff --git a/VAR.Toolbox/Code/DirectShow/ICaptureGraphBuilder2.cs b/VAR.Toolbox/Code/DirectShow/ICaptureGraphBuilder2.cs new file mode 100644 index 0000000..7a1ce42 --- /dev/null +++ b/VAR.Toolbox/Code/DirectShow/ICaptureGraphBuilder2.cs @@ -0,0 +1,185 @@ +namespace VAR.Toolbox.Code.DirectShow +{ + using System; + using System.Runtime.InteropServices; + + /// + /// This interface builds capture graphs and other custom filter graphs. + /// + /// + [ComImport, + Guid( "93E5A4E0-2D50-11d2-ABFA-00A0C9C6E38D" ), + InterfaceType( ComInterfaceType.InterfaceIsIUnknown )] + internal interface ICaptureGraphBuilder2 + { + /// + /// Specify filter graph for the capture graph builder to use. + /// + /// + /// Filter graph's interface. + /// + /// Return's HRESULT error code. + /// + [PreserveSig] + int SetFiltergraph( [In] IGraphBuilder graphBuilder ); + + /// + /// Retrieve the filter graph that the builder is using. + /// + /// + /// Filter graph's interface. + /// + /// Return's HRESULT error code. + /// + [PreserveSig] + int GetFiltergraph( [Out] out IGraphBuilder graphBuilder ); + + /// + /// Create file writing section of the filter graph. + /// + /// + /// GUID that represents either the media subtype of the output or the + /// class identifier (CLSID) of a multiplexer filter or file writer filter. + /// Output file name. + /// Receives the multiplexer's interface. + /// Receives the file writer's IFileSinkFilter interface. Can be NULL. + /// + /// Return's HRESULT error code. + /// + [PreserveSig] + int SetOutputFileName( + [In, MarshalAs( UnmanagedType.LPStruct )] Guid type, + [In, MarshalAs( UnmanagedType.LPWStr )] string fileName, + [Out] out IBaseFilter baseFilter, + [Out] out IntPtr fileSinkFilter + ); + + /// + /// Searche the graph for a specified interface, starting from a specified filter. + /// + /// + /// GUID that specifies the search criteria. + /// GUID that specifies the major media type of an output pin, or NULL. + /// interface of the filter. The method begins searching from this filter. + /// Interface identifier (IID) of the interface to locate. + /// Receives found interface. + /// + /// Return's HRESULT error code. + /// + [PreserveSig] + int FindInterface( + [In, MarshalAs( UnmanagedType.LPStruct )] Guid category, + [In, MarshalAs( UnmanagedType.LPStruct )] Guid type, + [In] IBaseFilter baseFilter, + [In, MarshalAs( UnmanagedType.LPStruct )] Guid interfaceID , + [Out, MarshalAs( UnmanagedType.IUnknown )] out object retInterface + ); + + /// + /// Connect an output pin on a source filter to a rendering filter, optionally through a compression filter. + /// + /// + /// Pin category. + /// Major-type GUID that specifies the media type of the output pin. + /// Starting filter for the connection. + /// Interface of an intermediate filter, such as a compression filter. Can be NULL. + /// Sink filter, such as a renderer or mux filter. + /// + /// Return's HRESULT error code. + /// + [PreserveSig] + int RenderStream( + [In, MarshalAs( UnmanagedType.LPStruct )] Guid category, + [In, MarshalAs( UnmanagedType.LPStruct )] Guid mediaType, + [In, MarshalAs( UnmanagedType.IUnknown )] object source, + [In] IBaseFilter compressor, + [In] IBaseFilter renderer + ); + + /// + /// Set the start and stop times for one or more streams of captured data. + /// + /// + /// Pin category. + /// Major-type GUID that specifies the media type. + /// interface that specifies which filter to control. + /// Start time. + /// Stop time. + /// Value that is sent as the second parameter of the + /// EC_STREAM_CONTROL_STARTED event notification. + /// Value that is sent as the second parameter of the + /// EC_STREAM_CONTROL_STOPPED event notification. + /// + /// Return's HRESULT error code. + /// + [PreserveSig] + int ControlStream( + [In, MarshalAs( UnmanagedType.LPStruct )] Guid category, + [In, MarshalAs( UnmanagedType.LPStruct )] Guid mediaType, + [In, MarshalAs( UnmanagedType.Interface )] IBaseFilter filter, + [In] long start, + [In] long stop, + [In] short startCookie, + [In] short stopCookie + ); + + /// + /// Preallocate a capture file to a specified size. + /// + /// + /// File name to create or resize. + /// Size of the file to allocate, in bytes. + /// + /// Return's HRESULT error code. + /// + [PreserveSig] + int AllocCapFile( + [In, MarshalAs( UnmanagedType.LPWStr )] string fileName, + [In] long size + ); + + /// + /// Copy the valid media data from a capture file. + /// + /// + /// Old file name. + /// New file name. + /// Boolean value that specifies whether pressing the ESC key cancels the copy operation. + /// IAMCopyCaptureFileProgress interface to display progress information, or NULL. + /// + /// Return's HRESULT error code. + /// + [PreserveSig] + int CopyCaptureFile( + [In, MarshalAs( UnmanagedType.LPWStr )] string oldFileName, + [In, MarshalAs( UnmanagedType.LPWStr )] string newFileName, + [In, MarshalAs( UnmanagedType.Bool )] bool allowEscAbort, + [In] IntPtr callback + ); + + /// + /// + /// + /// + /// Interface on a filter, or to an interface on a pin. + /// Pin direction (input or output). + /// Pin category. + /// Media type. + /// Boolean value that specifies whether the pin must be unconnected. + /// Zero-based index of the pin to retrieve, from the set of matching pins. + /// Interface of the matching pin. + /// + /// Return's HRESULT error code. + /// + [PreserveSig] + int FindPin( + [In, MarshalAs( UnmanagedType.IUnknown )] object source, + [In] PinDirection pinDirection, + [In, MarshalAs( UnmanagedType.LPStruct )] Guid category, + [In, MarshalAs( UnmanagedType.LPStruct )] Guid mediaType, + [In, MarshalAs( UnmanagedType.Bool )] bool unconnected, + [In] int index, + [Out, MarshalAs( UnmanagedType.Interface )] out IPin pin + ); + } +} diff --git a/VAR.Toolbox/Code/DirectShow/ICreateDevEnum.cs b/VAR.Toolbox/Code/DirectShow/ICreateDevEnum.cs new file mode 100644 index 0000000..c2e36ae --- /dev/null +++ b/VAR.Toolbox/Code/DirectShow/ICreateDevEnum.cs @@ -0,0 +1,30 @@ +namespace VAR.Toolbox.Code.DirectShow +{ + using System; + using System.Runtime.InteropServices; + using System.Runtime.InteropServices.ComTypes; + + /// + /// The ICreateDevEnum interface creates an enumerator for devices within a particular category, + /// such as video capture devices, audio capture devices, video compressors, and so forth. + /// + /// + [ComImport, + Guid( "29840822-5B84-11D0-BD3B-00A0C911CE86" ), + InterfaceType( ComInterfaceType.InterfaceIsIUnknown )] + internal interface ICreateDevEnum + { + /// + /// Creates a class enumerator for a specified device category. + /// + /// + /// Specifies the class identifier of the device category. + /// Address of a variable that receives an IEnumMoniker interface pointer + /// Bitwise combination of zero or more flags. If zero, the method enumerates every filter in the category. + /// + /// Return's HRESULT error code. + /// + [PreserveSig] + int CreateClassEnumerator( [In] ref Guid type, [Out] out IEnumMoniker enumMoniker, [In] int flags ); + } +} diff --git a/VAR.Toolbox/Code/DirectShow/IEnumFilters.cs b/VAR.Toolbox/Code/DirectShow/IEnumFilters.cs new file mode 100644 index 0000000..9d5272d --- /dev/null +++ b/VAR.Toolbox/Code/DirectShow/IEnumFilters.cs @@ -0,0 +1,64 @@ +namespace VAR.Toolbox.Code.DirectShow +{ + using System; + using System.Runtime.InteropServices; + + /// + /// This interface is used by applications or other filters to determine + /// what filters exist in the filter graph. + /// + /// + [ComImport, + Guid( "56A86893-0AD4-11CE-B03A-0020AF0BA770" ), + InterfaceType( ComInterfaceType.InterfaceIsIUnknown )] + internal interface IEnumFilters + { + /// + /// Retrieves the specified number of filters in the enumeration sequence. + /// + /// + /// Number of filters to retrieve. + /// Array in which to place interfaces. + /// Actual number of filters placed in the array. + /// + /// Return's HRESULT error code. + /// + [PreserveSig] + int Next( [In] int cFilters, + [Out, MarshalAs( UnmanagedType.LPArray, SizeParamIndex = 0 )] IBaseFilter[] filters, + [Out] out int filtersFetched ); + + /// + /// Skips a specified number of filters in the enumeration sequence. + /// + /// + /// Number of filters to skip. + /// + /// Return's HRESULT error code. + /// + [PreserveSig] + int Skip( [In] int cFilters ); + + /// + /// Resets the enumeration sequence to the beginning. + /// + /// + /// Return's HRESULT error code. + /// + [PreserveSig] + int Reset( ); + + /// + /// Makes a copy of the enumerator with the same enumeration state. + /// + /// + /// Duplicate of the enumerator. + /// + /// + /// Return's HRESULT error code. + /// + /// + [PreserveSig] + int Clone( [Out] out IEnumFilters enumFilters ); + } +} diff --git a/VAR.Toolbox/Code/DirectShow/IEnumPins.cs b/VAR.Toolbox/Code/DirectShow/IEnumPins.cs new file mode 100644 index 0000000..9d72823 --- /dev/null +++ b/VAR.Toolbox/Code/DirectShow/IEnumPins.cs @@ -0,0 +1,61 @@ +namespace VAR.Toolbox.Code.DirectShow +{ + using System; + using System.Runtime.InteropServices; + + /// + /// Enumerates pins on a filter. + /// + /// + [ComImport, + Guid( "56A86892-0AD4-11CE-B03A-0020AF0BA770" ), + InterfaceType( ComInterfaceType.InterfaceIsIUnknown )] + internal interface IEnumPins + { + /// + /// Retrieves a specified number of pins. + /// + /// + /// Number of pins to retrieve. + /// Array of size cPins that is filled with IPin pointers. + /// Receives the number of pins retrieved. + /// + /// Return's HRESULT error code. + /// + [PreserveSig] + int Next( [In] int cPins, + [Out, MarshalAs( UnmanagedType.LPArray, SizeParamIndex = 0 )] IPin[] pins, + [Out] out int pinsFetched ); + + /// + /// Skips a specified number of pins in the enumeration sequence. + /// + /// + /// Number of pins to skip. + /// + /// Return's HRESULT error code. + /// + [PreserveSig] + int Skip( [In] int cPins ); + + /// + /// Resets the enumeration sequence to the beginning. + /// + /// + /// Return's HRESULT error code. + /// + [PreserveSig] + int Reset( ); + + /// + /// Makes a copy of the enumerator with the same enumeration state. + /// + /// + /// Duplicate of the enumerator. + /// + /// Return's HRESULT error code. + /// + [PreserveSig] + int Clone( [Out] out IEnumPins enumPins ); + } +} diff --git a/VAR.Toolbox/Code/DirectShow/IFileSourceFilter.cs b/VAR.Toolbox/Code/DirectShow/IFileSourceFilter.cs new file mode 100644 index 0000000..c3cceaf --- /dev/null +++ b/VAR.Toolbox/Code/DirectShow/IFileSourceFilter.cs @@ -0,0 +1,41 @@ +namespace VAR.Toolbox.Code.DirectShow +{ + using System; + using System.Runtime.InteropServices; + + /// + /// The interface is exposed by source filters to set the file name and media type of the media file that they are to render. + /// + /// + [ComImport, + Guid( "56A868A6-0Ad4-11CE-B03A-0020AF0BA770" ), + InterfaceType( ComInterfaceType.InterfaceIsIUnknown )] + internal interface IFileSourceFilter + { + /// + /// Loads the source filter with the file. + /// + /// + /// The name of the file to open. + /// Media type of the file. This can be null. + /// + /// Return's HRESULT error code. + /// + [PreserveSig] + int Load( [In, MarshalAs( UnmanagedType.LPWStr )] string fileName, + [In, MarshalAs( UnmanagedType.LPStruct )] AMMediaType mediaType ); + + /// + /// Retrieves the current file. + /// + /// + /// Name of media file. + /// Receives media type. + /// + /// Return's HRESULT error code. + /// + [PreserveSig] + int GetCurFile([Out, MarshalAs( UnmanagedType.LPWStr )] out string fileName, + [Out, MarshalAs( UnmanagedType.LPStruct )] AMMediaType mediaType ); + } +} diff --git a/VAR.Toolbox/Code/DirectShow/IFilterGraph.cs b/VAR.Toolbox/Code/DirectShow/IFilterGraph.cs new file mode 100644 index 0000000..af1bb74 --- /dev/null +++ b/VAR.Toolbox/Code/DirectShow/IFilterGraph.cs @@ -0,0 +1,106 @@ +namespace VAR.Toolbox.Code.DirectShow +{ + using System; + using System.Runtime.InteropServices; + + /// + /// The interface provides methods for building a filter graph. An application can use it to add filters to + /// the graph, connect or disconnect filters, remove filters, and perform other basic operations. + /// + /// + [ComImport, + Guid( "56A8689F-0AD4-11CE-B03A-0020AF0BA770" ), + InterfaceType( ComInterfaceType.InterfaceIsIUnknown )] + internal interface IFilterGraph + { + /// + /// Adds a filter to the graph and gives it a name. + /// + /// + /// Filter to add to the graph. + /// Name of the filter. + /// + /// Return's HRESULT error code. + /// + [PreserveSig] + int AddFilter( [In] IBaseFilter filter, [In, MarshalAs( UnmanagedType.LPWStr )] string name ); + + /// + /// Removes a filter from the graph. + /// + /// + /// Filter to be removed from the graph. + /// + /// Return's HRESULT error code. + /// + [PreserveSig] + int RemoveFilter( [In] IBaseFilter filter ); + + /// + /// Provides an enumerator for all filters in the graph. + /// + /// + /// Filter enumerator. + /// + /// Return's HRESULT error code. + /// + [PreserveSig] + int EnumFilters( [Out] out IntPtr enumerator ); + + /// + /// Finds a filter that was added with a specified name. + /// + /// + /// Name of filter to search for. + /// Interface of found filter. + /// + /// Return's HRESULT error code. + /// + [PreserveSig] + int FindFilterByName( [In, MarshalAs( UnmanagedType.LPWStr )] string name, [Out] out IBaseFilter filter ); + + /// + /// Connects two pins directly (without intervening filters). + /// + /// + /// Output pin. + /// Input pin. + /// Media type to use for the connection. + /// + /// Return's HRESULT error code. + /// + [PreserveSig] + int ConnectDirect( [In] IPin pinOut, [In] IPin pinIn, [In, MarshalAs( UnmanagedType.LPStruct )] AMMediaType mediaType ); + + /// + /// Breaks the existing pin connection and reconnects it to the same pin. + /// + /// + /// Pin to disconnect and reconnect. + /// + /// Return's HRESULT error code. + /// + [PreserveSig] + int Reconnect( [In] IPin pin ); + + /// + /// Disconnects a specified pin. + /// + /// + /// Pin to disconnect. + /// + /// Return's HRESULT error code. + /// + [PreserveSig] + int Disconnect( [In] IPin pin ); + + /// + /// Sets the reference clock to the default clock. + /// + /// + /// Return's HRESULT error code. + /// + [PreserveSig] + int SetDefaultSyncSource( ); + } +} diff --git a/VAR.Toolbox/Code/DirectShow/IFilterGraph2.cs b/VAR.Toolbox/Code/DirectShow/IFilterGraph2.cs new file mode 100644 index 0000000..213754c --- /dev/null +++ b/VAR.Toolbox/Code/DirectShow/IFilterGraph2.cs @@ -0,0 +1,250 @@ +namespace VAR.Toolbox.Code.DirectShow +{ + using System; + using System.Runtime.InteropServices; + using System.Runtime.InteropServices.ComTypes; + + /// + /// This interface extends the and + /// interfaces, which contain methods for building filter graphs. + /// + /// + [ComImport, + Guid("36B73882-C2C8-11CF-8B46-00805F6CEF60"), + InterfaceType(ComInterfaceType.InterfaceIsIUnknown)] + internal interface IFilterGraph2 + { + // --- IFilterGraph Methods + + /// + /// Adds a filter to the graph and gives it a name. + /// + /// + /// Filter to add to the graph. + /// Name of the filter. + /// + /// Return's HRESULT error code. + /// + [PreserveSig] + int AddFilter( [In] IBaseFilter filter, [In, MarshalAs( UnmanagedType.LPWStr )] string name ); + + /// + /// Removes a filter from the graph. + /// + /// + /// Filter to be removed from the graph. + /// + /// Return's HRESULT error code. + /// + [PreserveSig] + int RemoveFilter( [In] IBaseFilter filter ); + + /// + /// Provides an enumerator for all filters in the graph. + /// + /// + /// Filter enumerator. + /// + /// Return's HRESULT error code. + /// + [PreserveSig] + int EnumFilters( [Out] out IEnumFilters enumerator ); + + /// + /// Finds a filter that was added with a specified name. + /// + /// + /// Name of filter to search for. + /// Interface of found filter. + /// + /// Return's HRESULT error code. + /// + [PreserveSig] + int FindFilterByName( [In, MarshalAs( UnmanagedType.LPWStr )] string name, [Out] out IBaseFilter filter ); + + /// + /// Connects two pins directly (without intervening filters). + /// + /// + /// Output pin. + /// Input pin. + /// Media type to use for the connection. + /// + /// Return's HRESULT error code. + /// + [PreserveSig] + int ConnectDirect( [In] IPin pinOut, [In] IPin pinIn, [In, MarshalAs( UnmanagedType.LPStruct )] AMMediaType mediaType ); + + /// + /// Breaks the existing pin connection and reconnects it to the same pin. + /// + /// + /// Pin to disconnect and reconnect. + /// + /// Return's HRESULT error code. + /// + [PreserveSig] + int Reconnect( [In] IPin pin ); + + /// + /// Disconnects a specified pin. + /// + /// + /// Pin to disconnect. + /// + /// Return's HRESULT error code. + /// + [PreserveSig] + int Disconnect( [In] IPin pin ); + + /// + /// Sets the reference clock to the default clock. + /// + /// + /// Return's HRESULT error code. + /// + [PreserveSig] + int SetDefaultSyncSource( ); + + // --- IGraphBuilder methods + + /// + /// Connects two pins. If they will not connect directly, this method connects them with intervening transforms. + /// + /// + /// Output pin. + /// Input pin. + /// + /// Return's HRESULT error code. + /// + [PreserveSig] + int Connect( [In] IPin pinOut, [In] IPin pinIn ); + + /// + /// Adds a chain of filters to a specified output pin to render it. + /// + /// + /// Output pin. + /// + /// Return's HRESULT error code. + /// + [PreserveSig] + int Render( [In] IPin pinOut ); + + /// + /// Builds a filter graph that renders the specified file. + /// + /// + /// Specifies a string that contains file name or device moniker. + /// Reserved. + /// + /// Return's HRESULT error code. + /// + [PreserveSig] + int RenderFile( + [In, MarshalAs( UnmanagedType.LPWStr )] string file, + [In, MarshalAs( UnmanagedType.LPWStr )] string playList ); + + /// + /// Adds a source filter to the filter graph for a specific file. + /// + /// + /// Specifies the name of the file to load. + /// Specifies a name for the source filter. + /// Variable that receives the interface of the source filter. + /// + /// Return's HRESULT error code. + /// + [PreserveSig] + int AddSourceFilter( + [In, MarshalAs( UnmanagedType.LPWStr )] string fileName, + [In, MarshalAs( UnmanagedType.LPWStr )] string filterName, + [Out] out IBaseFilter filter ); + + /// + /// Sets the file for logging actions taken when attempting to perform an operation. + /// + /// + /// Handle to the log file. + /// + /// Return's HRESULT error code. + /// + [PreserveSig] + int SetLogFile( IntPtr hFile ); + + /// + /// Requests that the graph builder return as soon as possible from its current task. + /// + /// + /// Return's HRESULT error code. + /// + [PreserveSig] + int Abort( ); + + /// + /// Queries whether the current operation should continue. + /// + /// + /// Return's HRESULT error code. + /// + [PreserveSig] + int ShouldOperationContinue( ); + + + // --- IFilterGraph2 methods + + /// + /// + /// + /// + /// Moniker interface. + /// Bind context interface. + /// Name for the filter. + /// Receives source filter's IBaseFilter interface. + /// The caller must release the interface. + /// + /// Return's HRESULT error code. + /// + [PreserveSig] + int AddSourceFilterForMoniker( + [In] IMoniker moniker, + [In] IBindCtx bindContext, + [In, MarshalAs( UnmanagedType.LPWStr )] string filterName, + [Out] out IBaseFilter filter + ); + + /// + /// Breaks the existing pin connection and reconnects it to the same pin, + /// using a specified media type. + /// + /// + /// Pin to disconnect and reconnect. + /// Media type to reconnect with. + /// + /// Return's HRESULT error code. + /// + [PreserveSig] + int ReconnectEx( + [In] IPin pin, + [In, MarshalAs( UnmanagedType.LPStruct )] AMMediaType mediaType + ); + + /// + /// Render an output pin, with an option to use existing renderers only. + /// + /// + /// Interface of the output pin. + /// Flag that specifies how to render the pin. + /// Reserved. + /// + /// Return's HRESULT error code. + /// + [PreserveSig] + int RenderEx( + [In] IPin outputPin, + [In] int flags, + [In] IntPtr context + ); + + } +} diff --git a/VAR.Toolbox/Code/DirectShow/IGraphBuilder.cs b/VAR.Toolbox/Code/DirectShow/IGraphBuilder.cs new file mode 100644 index 0000000..3f97930 --- /dev/null +++ b/VAR.Toolbox/Code/DirectShow/IGraphBuilder.cs @@ -0,0 +1,191 @@ +namespace VAR.Toolbox.Code.DirectShow +{ + using System; + using System.Runtime.InteropServices; + + /// + /// This interface provides methods that enable an application to build a filter graph. + /// + /// + [ComImport, + Guid( "56A868A9-0AD4-11CE-B03A-0020AF0BA770" ), + InterfaceType( ComInterfaceType.InterfaceIsIUnknown )] + internal interface IGraphBuilder + { + // --- IFilterGraph Methods + + /// + /// Adds a filter to the graph and gives it a name. + /// + /// + /// Filter to add to the graph. + /// Name of the filter. + /// + /// Return's HRESULT error code. + /// + [PreserveSig] + int AddFilter( [In] IBaseFilter filter, [In, MarshalAs( UnmanagedType.LPWStr )] string name ); + + /// + /// Removes a filter from the graph. + /// + /// + /// Filter to be removed from the graph. + /// + /// Return's HRESULT error code. + /// + [PreserveSig] + int RemoveFilter( [In] IBaseFilter filter ); + + /// + /// Provides an enumerator for all filters in the graph. + /// + /// + /// Filter enumerator. + /// + /// Return's HRESULT error code. + /// + [PreserveSig] + int EnumFilters( [Out] out IEnumFilters enumerator ); + + /// + /// Finds a filter that was added with a specified name. + /// + /// + /// Name of filter to search for. + /// Interface of found filter. + /// + /// Return's HRESULT error code. + /// + [PreserveSig] + int FindFilterByName( [In, MarshalAs( UnmanagedType.LPWStr )] string name, [Out] out IBaseFilter filter ); + + /// + /// Connects two pins directly (without intervening filters). + /// + /// + /// Output pin. + /// Input pin. + /// Media type to use for the connection. + /// + /// Return's HRESULT error code. + /// + [PreserveSig] + int ConnectDirect( [In] IPin pinOut, [In] IPin pinIn, [In, MarshalAs( UnmanagedType.LPStruct )] AMMediaType mediaType ); + + /// + /// Breaks the existing pin connection and reconnects it to the same pin. + /// + /// + /// Pin to disconnect and reconnect. + /// + /// Return's HRESULT error code. + /// + [PreserveSig] + int Reconnect( [In] IPin pin ); + + /// + /// Disconnects a specified pin. + /// + /// + /// Pin to disconnect. + /// + /// Return's HRESULT error code. + /// + [PreserveSig] + int Disconnect( [In] IPin pin ); + + /// + /// Sets the reference clock to the default clock. + /// + /// + /// Return's HRESULT error code. + /// + [PreserveSig] + int SetDefaultSyncSource( ); + + // --- IGraphBuilder methods + + /// + /// Connects two pins. If they will not connect directly, this method connects them with intervening transforms. + /// + /// + /// Output pin. + /// Input pin. + /// + /// Return's HRESULT error code. + /// + [PreserveSig] + int Connect( [In] IPin pinOut, [In] IPin pinIn ); + + /// + /// Adds a chain of filters to a specified output pin to render it. + /// + /// + /// Output pin. + /// + /// Return's HRESULT error code. + /// + [PreserveSig] + int Render( [In] IPin pinOut ); + + /// + /// Builds a filter graph that renders the specified file. + /// + /// + /// Specifies a string that contains file name or device moniker. + /// Reserved. + /// + /// Return's HRESULT error code. + /// + [PreserveSig] + int RenderFile( + [In, MarshalAs( UnmanagedType.LPWStr )] string file, + [In, MarshalAs( UnmanagedType.LPWStr )] string playList); + + /// + /// Adds a source filter to the filter graph for a specific file. + /// + /// + /// Specifies the name of the file to load. + /// Specifies a name for the source filter. + /// Variable that receives the interface of the source filter. + /// + /// Return's HRESULT error code. + /// + [PreserveSig] + int AddSourceFilter( + [In, MarshalAs( UnmanagedType.LPWStr )] string fileName, + [In, MarshalAs( UnmanagedType.LPWStr )] string filterName, + [Out] out IBaseFilter filter ); + + /// + /// Sets the file for logging actions taken when attempting to perform an operation. + /// + /// + /// Handle to the log file. + /// + /// Return's HRESULT error code. + /// + [PreserveSig] + int SetLogFile( IntPtr hFile ); + + /// + /// Requests that the graph builder return as soon as possible from its current task. + /// + /// + /// Return's HRESULT error code. + /// + [PreserveSig] + int Abort( ); + + /// + /// Queries whether the current operation should continue. + /// + /// + /// Return's HRESULT error code. + /// + [PreserveSig] + int ShouldOperationContinue( ); + } +} diff --git a/VAR.Toolbox/Code/DirectShow/IMediaControl.cs b/VAR.Toolbox/Code/DirectShow/IMediaControl.cs new file mode 100644 index 0000000..c000863 --- /dev/null +++ b/VAR.Toolbox/Code/DirectShow/IMediaControl.cs @@ -0,0 +1,111 @@ +namespace VAR.Toolbox.Code.DirectShow +{ + using System; + using System.Runtime.InteropServices; + + /// + /// The interface provides methods for controlling the flow of data through the filter graph. + /// It includes methods for running, pausing, and stopping the graph. + /// + /// + [ComImport, + Guid( "56A868B1-0AD4-11CE-B03A-0020AF0BA770" ), + InterfaceType(ComInterfaceType.InterfaceIsDual)] + internal interface IMediaControl + { + /// + /// Runs all the filters in the filter graph. + /// + /// + /// Return's HRESULT error code. + /// + [PreserveSig] + int Run( ); + + /// + /// Pauses all filters in the filter graph. + /// + /// + /// Return's HRESULT error code. + /// + [PreserveSig] + int Pause( ); + + /// + /// Stops all the filters in the filter graph. + /// + /// + /// Return's HRESULT error code. + /// + [PreserveSig] + int Stop( ); + + /// + /// Retrieves the state of the filter graph. + /// + /// + /// Duration of the time-out, in milliseconds, or INFINITE to specify an infinite time-out. + /// Ìariable that receives a member of the FILTER_STATE enumeration. + /// + /// Return's HRESULT error code. + /// + [PreserveSig] + int GetState( int timeout, out int filterState ); + + /// + /// Builds a filter graph that renders the specified file. + /// + /// + /// Name of the file to render + /// + /// Return's HRESULT error code. + /// + [PreserveSig] + int RenderFile( string fileName ); + + /// + /// Adds a source filter to the filter graph, for a specified file. + /// + /// + /// Name of the file containing the source video. + /// Receives interface of filter information object. + /// + /// Return's HRESULT error code. + /// + [PreserveSig] + int AddSourceFilter( [In] string fileName, [Out, MarshalAs( UnmanagedType.IDispatch )] out object filterInfo ); + + /// + /// Retrieves a collection of the filters in the filter graph. + /// + /// + /// Receives the IAMCollection interface. + /// + /// Return's HRESULT error code. + /// + [PreserveSig] + int get_FilterCollection( + [Out, MarshalAs( UnmanagedType.IDispatch )] out object collection ); + + /// + /// Retrieves a collection of all the filters listed in the registry. + /// + /// + /// Receives the IDispatch interface of IAMCollection object. + /// + /// Return's HRESULT error code. + /// + [PreserveSig] + int get_RegFilterCollection( + [Out, MarshalAs( UnmanagedType.IDispatch )] out object collection ); + + /// + /// Pauses the filter graph, allowing filters to queue data, and then stops the filter graph. + /// + /// + /// Return's HRESULT error code. + /// + [PreserveSig] + int StopWhenReady( ); + } +} diff --git a/VAR.Toolbox/Code/DirectShow/IMediaEventEx.cs b/VAR.Toolbox/Code/DirectShow/IMediaEventEx.cs new file mode 100644 index 0000000..ddc1c87 --- /dev/null +++ b/VAR.Toolbox/Code/DirectShow/IMediaEventEx.cs @@ -0,0 +1,119 @@ +namespace VAR.Toolbox.Code.DirectShow +{ + using System; + using System.Runtime.InteropServices; + + /// + /// The interface inherits contains methods for retrieving event notifications and for overriding the + /// filter graph's default handling of events. + /// + [ComVisible( true ), ComImport, + Guid( "56a868c0-0ad4-11ce-b03a-0020af0ba770" ), + InterfaceType( ComInterfaceType.InterfaceIsDual )] + internal interface IMediaEventEx + { + /// + /// Retrieves a handle to a manual-reset event that remains signaled while the queue contains event notifications. + /// + /// Pointer to a variable that receives the event handle. + /// + /// Return's HRESULT error code. + /// + [PreserveSig] + int GetEventHandle( out IntPtr hEvent ); + + /// + /// Retrieves the next event notification from the event queue. + /// + /// + /// Variable that receives the event code. + /// Pointer to a variable that receives the first event parameter. + /// Pointer to a variable that receives the second event parameter. + /// Time-out interval, in milliseconds. + /// + /// Return's HRESULT error code. + /// + [PreserveSig] + int GetEvent( [Out, MarshalAs( UnmanagedType.I4 )] out DsEvCode lEventCode, [Out] out IntPtr lParam1, [Out] out IntPtr lParam2, int msTimeout ); + + /// + /// Waits for the filter graph to render all available data. + /// + /// + /// Time-out interval, in milliseconds. Pass zero to return immediately. + /// Pointer to a variable that receives an event code. + /// + /// Return's HRESULT error code. + /// + [PreserveSig] + int WaitForCompletion( int msTimeout, [Out] out int pEvCode ); + + /// + /// Cancels the Filter Graph Manager's default handling for a specified event. + /// + /// + /// Event code for which to cancel default handling. + /// + /// Return's HRESULT error code. + /// + [PreserveSig] + int CancelDefaultHandling( int lEvCode ); + + /// + /// Restores the Filter Graph Manager's default handling for a specified event. + /// + /// Event code for which to restore default handling. + /// + /// Return's HRESULT error code. + /// + [PreserveSig] + int RestoreDefaultHandling( int lEvCode ); + + /// + /// Frees resources associated with the parameters of an event. + /// + /// Event code. + /// First event parameter. + /// Second event parameter. + /// + /// Return's HRESULT error code. + /// + [PreserveSig] + int FreeEventParams( [In, MarshalAs( UnmanagedType.I4 )] DsEvCode lEvCode, IntPtr lParam1, IntPtr lParam2 ); + + /// + /// Registers a window to process event notifications. + /// + /// + /// Handle to the window, or to stop receiving event messages. + /// Window message to be passed as the notification. + /// Value to be passed as the lParam parameter for the lMsg message. + /// + /// Return's HRESULT error code. + /// + [PreserveSig] + int SetNotifyWindow( IntPtr hwnd, int lMsg, IntPtr lInstanceData ); + + /// + /// Enables or disables event notifications. + /// + /// + /// Value indicating whether to enable or disable event notifications. + /// + /// Return's HRESULT error code. + /// + [PreserveSig] + int SetNotifyFlags( int lNoNotifyFlags ); + + /// + /// Determines whether event notifications are enabled. + /// + /// + /// Variable that receives current notification status. + /// + /// Return's HRESULT error code. + /// + [PreserveSig] + int GetNotifyFlags( out int lplNoNotifyFlags ); + } +} diff --git a/VAR.Toolbox/Code/DirectShow/IMediaFilter.cs b/VAR.Toolbox/Code/DirectShow/IMediaFilter.cs new file mode 100644 index 0000000..d07ed04 --- /dev/null +++ b/VAR.Toolbox/Code/DirectShow/IMediaFilter.cs @@ -0,0 +1,91 @@ +namespace VAR.Toolbox.Code.DirectShow +{ + using System; + using System.Runtime.InteropServices; + + /// + /// The interface provides methods for controlling the flow of data through the filter graph. + /// It includes methods for running, pausing, and stopping the graph. + /// + /// + [ComImport, System.Security.SuppressUnmanagedCodeSecurity, + Guid( "56a86899-0ad4-11ce-b03a-0020af0ba770" ), + InterfaceType( ComInterfaceType.InterfaceIsIUnknown )] + internal interface IMediaFilter : IPersist + { + #region IPersist Methods + + [PreserveSig] + new int GetClassID( + [Out] out Guid pClassID ); + + #endregion + + /// + /// This method informs the filter to transition to the new state. + /// + /// + /// Return's HRESULT error code. + /// + [PreserveSig] + int Stop( ); + + /// + /// This method informs the filter to transition to the new state. + /// + /// + /// Return's HRESULT error code. + /// + [PreserveSig] + int Pause( ); + + /// + /// This method informs the filter to transition to the new (running) state. Passes a time value to synchronize independent streams. + /// + /// + /// Time value of the reference clock. The amount to be added to the IMediaSample time stamp to determine the time at which that sample should be rendered according to the reference clock. That is, it is the reference time at which a sample with a stream time of zero should be rendered. + /// + /// Return's HRESULT error code. + /// + [PreserveSig] + int Run( [In] long tStart ); + + /// + /// This method determines the filter's state. + /// + /// + /// Duration of the time-out, in milliseconds. To block indefinitely, pass INFINITE. + /// Returned state of the filter. States include stopped, paused, running, or intermediate (in the process of changing). + /// + /// Return's HRESULT error code. + /// + [PreserveSig] + int GetState( + [In] int dwMilliSecsTimeout, + [Out] out FilterState filtState ); + + /// + /// This method identifies the reference clock to which the filter should synchronize activity. + /// + /// + /// Pointer to the IReferenceClock interface. + /// + /// Return's HRESULT error code. + /// + [PreserveSig] + int SetSyncSource( [In] IReferenceClock pClock ); + + /// + /// This method retrieves the current reference clock in use by this filter. + /// + /// + /// Pointer to a reference clock; it will be set to the IReferenceClock interface. + /// + /// + /// Return's HRESULT error code. + /// + [PreserveSig] + int GetSyncSource( [Out] out IReferenceClock pClock ); + } +} + diff --git a/VAR.Toolbox/Code/DirectShow/IPersist.cs b/VAR.Toolbox/Code/DirectShow/IPersist.cs new file mode 100644 index 0000000..c42bdbc --- /dev/null +++ b/VAR.Toolbox/Code/DirectShow/IPersist.cs @@ -0,0 +1,23 @@ +namespace VAR.Toolbox.Code.DirectShow +{ + using System; + using System.Runtime.InteropServices; + + /// + /// Provides the CLSID of an object that can be stored persistently in the system. Allows the object to specify which object + /// handler to use in the client process, as it is used in the default implementation of marshaling. + /// + [ComImport, + Guid("0000010c-0000-0000-C000-000000000046"), + InterfaceType(ComInterfaceType.InterfaceIsDual)] + internal interface IPersist + { + /// + /// Retrieves the class identifier (CLSID) of the object. + /// + /// + /// + [PreserveSig] + int GetClassID([Out] out Guid pClassID); + } +} diff --git a/VAR.Toolbox/Code/DirectShow/IPin.cs b/VAR.Toolbox/Code/DirectShow/IPin.cs new file mode 100644 index 0000000..b91b418 --- /dev/null +++ b/VAR.Toolbox/Code/DirectShow/IPin.cs @@ -0,0 +1,184 @@ +namespace VAR.Toolbox.Code.DirectShow +{ + using System; + using System.Runtime.InteropServices; + + /// + /// This interface is exposed by all input and output pins of DirectShow filters. + /// + /// + [ComImport, + Guid( "56A86891-0AD4-11CE-B03A-0020AF0BA770" ), + InterfaceType( ComInterfaceType.InterfaceIsIUnknown )] + internal interface IPin + { + /// + /// Connects the pin to another pin. + /// + /// + /// Other pin to connect to. + /// Type to use for the connections (optional). + /// + /// Return's HRESULT error code. + /// + [PreserveSig] + int Connect( [In] IPin receivePin, [In, MarshalAs( UnmanagedType.LPStruct )] AMMediaType mediaType ); + + /// + /// Makes a connection to this pin and is called by a connecting pin. + /// + /// + /// Connecting pin. + /// Media type of the samples to be streamed. + /// + /// Return's HRESULT error code. + /// + [PreserveSig] + int ReceiveConnection( [In] IPin receivePin, [In, MarshalAs( UnmanagedType.LPStruct )] AMMediaType mediaType ); + + /// + /// Breaks the current pin connection. + /// + /// + /// Return's HRESULT error code. + /// + [PreserveSig] + int Disconnect( ); + + /// + /// Returns a pointer to the connecting pin. + /// + /// + /// Receives IPin interface of connected pin (if any). + /// + /// Return's HRESULT error code. + /// + [PreserveSig] + int ConnectedTo( [Out] out IPin pin ); + + /// + /// Returns the media type of this pin's connection. + /// + /// + /// Pointer to an structure. If the pin is connected, + /// the media type is returned. Otherwise, the structure is initialized to a default state in which + /// all elements are 0, with the exception of lSampleSize, which is set to 1, and + /// FixedSizeSamples, which is set to true. + /// + /// Return's HRESULT error code. + /// + [PreserveSig] + int ConnectionMediaType( [Out, MarshalAs( UnmanagedType.LPStruct )] AMMediaType mediaType ); + + /// + /// Retrieves information about this pin (for example, the name, owning filter, and direction). + /// + /// + /// structure that receives the pin information. + /// + /// Return's HRESULT error code. + /// + [PreserveSig] + int QueryPinInfo( [Out] out PinInfo pinInfo ); + + /// + /// Retrieves the direction for this pin. + /// + /// + /// Receives direction of the pin. + /// + /// Return's HRESULT error code. + /// + [PreserveSig] + int QueryDirection( out PinDirection pinDirection ); + + /// + /// Retrieves an identifier for the pin. + /// + /// + /// Pin identifier. + /// + /// Return's HRESULT error code. + /// + [PreserveSig] + int QueryId( [Out, MarshalAs( UnmanagedType.LPWStr )] out string id ); + + /// + /// Queries whether a given media type is acceptable by the pin. + /// + /// + /// structure that specifies the media type. + /// + /// Return's HRESULT error code. + /// + [PreserveSig] + int QueryAccept( [In, MarshalAs( UnmanagedType.LPStruct )] AMMediaType mediaType ); + + /// + /// Provides an enumerator for this pin's preferred media types. + /// + /// + /// Address of a variable that receives a pointer to the IEnumMediaTypes interface. + /// + /// Return's HRESULT error code. + /// + [PreserveSig] + int EnumMediaTypes( IntPtr enumerator ); + + /// + /// Provides an array of the pins to which this pin internally connects. + /// + /// + /// Address of an array of IPin pointers. + /// On input, specifies the size of the array. When the method returns, + /// the value is set to the number of pointers returned in the array. + /// + /// Return's HRESULT error code. + /// + [PreserveSig] + int QueryInternalConnections( IntPtr apPin, [In, Out] ref int nPin ); + + /// + /// Notifies the pin that no additional data is expected. + /// + /// + /// Return's HRESULT error code. + /// + [PreserveSig] + int EndOfStream( ); + + /// + /// Begins a flush operation. + /// + /// + /// Return's HRESULT error code. + /// + [PreserveSig] + int BeginFlush( ); + + /// + /// Ends a flush operation. + /// + /// + /// Return's HRESULT error code. + /// + [PreserveSig] + int EndFlush( ); + + /// + /// Specifies that samples following this call are grouped as a segment with a given start time, stop time, and rate. + /// + /// + /// Start time of the segment, relative to the original source, in 100-nanosecond units. + /// End time of the segment, relative to the original source, in 100-nanosecond units. + /// Rate at which this segment should be processed, as a percentage of the original rate. + /// + /// Return's HRESULT error code. + /// + [PreserveSig] + int NewSegment( + long start, + long stop, + double rate ); + } +} diff --git a/VAR.Toolbox/Code/DirectShow/IPropertyBag.cs b/VAR.Toolbox/Code/DirectShow/IPropertyBag.cs new file mode 100644 index 0000000..1536bb3 --- /dev/null +++ b/VAR.Toolbox/Code/DirectShow/IPropertyBag.cs @@ -0,0 +1,46 @@ +namespace VAR.Toolbox.Code.DirectShow +{ + using System; + using System.Runtime.InteropServices; + + /// + /// The IPropertyBag interface provides an object with a property bag in + /// which the object can persistently save its properties. + /// + /// + [ComImport, + Guid( "55272A00-42CB-11CE-8135-00AA004BB851" ), + InterfaceType( ComInterfaceType.InterfaceIsIUnknown )] + internal interface IPropertyBag + { + /// + /// Read a property from property bag. + /// + /// + /// Property name to read. + /// Property value. + /// Caller's error log. + /// + /// Return's HRESULT error code. + /// + [PreserveSig] + int Read( + [In, MarshalAs( UnmanagedType.LPWStr )] string propertyName, + [In, Out, MarshalAs( UnmanagedType.Struct )] ref object pVar, + [In] IntPtr pErrorLog ); + + /// + /// Write property to property bag. + /// + /// + /// Property name to read. + /// Property value. + /// + /// Return's HRESULT error code. + /// + [PreserveSig] + int Write( + [In, MarshalAs( UnmanagedType.LPWStr )] string propertyName, + [In, MarshalAs( UnmanagedType.Struct )] ref object pVar ); + } +} diff --git a/VAR.Toolbox/Code/DirectShow/IReferenceClock.cs b/VAR.Toolbox/Code/DirectShow/IReferenceClock.cs new file mode 100644 index 0000000..b63ac3e --- /dev/null +++ b/VAR.Toolbox/Code/DirectShow/IReferenceClock.cs @@ -0,0 +1,76 @@ +namespace VAR.Toolbox.Code.DirectShow +{ + using System; + using System.Runtime.InteropServices; + + /// + /// The IReferenceClock interface provides the reference time for the filter graph. + /// + /// Filters that can act as a reference clock can expose this interface. It is also exposed by the System Reference Clock. + /// The filter graph manager uses this interface to synchronize the filter graph. Applications can use this interface to + /// retrieve the current reference time, or to request notification of an elapsed time. + /// + [ComImport, System.Security.SuppressUnmanagedCodeSecurity, + Guid( "56a86897-0ad4-11ce-b03a-0020af0ba770" ), + InterfaceType( ComInterfaceType.InterfaceIsIUnknown )] + internal interface IReferenceClock + { + /// + /// The GetTime method retrieves the current reference time. + /// + /// + /// Pointer to a variable that receives the current time, in 100-nanosecond units. + /// + /// Return's HRESULT error code. + /// + [PreserveSig] + int GetTime( [Out] out long pTime ); + + /// + /// The AdviseTime method creates a one-shot advise request. + /// + /// + /// Base reference time, in 100-nanosecond units. See Remarks. + /// Stream offset time, in 100-nanosecond units. See Remarks. + /// Handle to an event, created by the caller. + /// Pointer to a variable that receives an identifier for the advise request. + /// + /// Return's HRESULT error code. + /// + [PreserveSig] + int AdviseTime( + [In] long baseTime, + [In] long streamTime, + [In] IntPtr hEvent, + [Out] out int pdwAdviseCookie ); + + /// + /// The AdvisePeriodic method creates a periodic advise request. + /// + /// + /// Time of the first notification, in 100-nanosecond units. Must be greater than zero and less than MAX_TIME. + /// Time between notifications, in 100-nanosecond units. Must be greater than zero. + /// Handle to a semaphore, created by the caller. + /// Pointer to a variable that receives an identifier for the advise request. + /// + /// Return's HRESULT error code. + /// + [PreserveSig] + int AdvisePeriodic( + [In] long startTime, + [In] long periodTime, + [In] IntPtr hSemaphore, + [Out] out int pdwAdviseCookie ); + + /// + /// The Unadvise method removes a pending advise request. + /// + /// + /// Identifier of the request to remove. Use the value returned by IReferenceClock::AdviseTime or IReferenceClock::AdvisePeriodic in the pdwAdviseToken parameter. + /// + /// Return's HRESULT error code. + /// + [PreserveSig] + int Unadvise( [In] int dwAdviseCookie ); + } +} diff --git a/VAR.Toolbox/Code/DirectShow/ISampleGrabber.cs b/VAR.Toolbox/Code/DirectShow/ISampleGrabber.cs new file mode 100644 index 0000000..987d8a3 --- /dev/null +++ b/VAR.Toolbox/Code/DirectShow/ISampleGrabber.cs @@ -0,0 +1,96 @@ +namespace VAR.Toolbox.Code.DirectShow +{ + using System; + using System.Runtime.InteropServices; + + /// + /// The interface is exposed by the Sample Grabber Filter. It enables an application to retrieve + /// individual media samples as they move through the filter graph. + /// + /// + [ComImport, + Guid("6B652FFF-11FE-4FCE-92AD-0266B5D7C78F"), + InterfaceType(ComInterfaceType.InterfaceIsIUnknown)] + internal interface ISampleGrabber + { + /// + /// Specifies whether the filter should stop the graph after receiving one sample. + /// + /// + /// Boolean value specifying whether the filter should stop the graph after receiving one sample. + /// + /// Return's HRESULT error code. + /// + [PreserveSig] + int SetOneShot( [In, MarshalAs( UnmanagedType.Bool )] bool oneShot ); + + /// + /// Specifies the media type for the connection on the Sample Grabber's input pin. + /// + /// + /// Specifies the required media type. + /// + /// Return's HRESULT error code. + /// + [PreserveSig] + int SetMediaType( [In, MarshalAs( UnmanagedType.LPStruct )] AMMediaType mediaType ); + + /// + /// Retrieves the media type for the connection on the Sample Grabber's input pin. + /// + /// + /// structure, which receives media type. + /// + /// Return's HRESULT error code. + /// + [PreserveSig] + int GetConnectedMediaType( [Out, MarshalAs( UnmanagedType.LPStruct )] AMMediaType mediaType ); + + /// + /// Specifies whether to copy sample data into a buffer as it goes through the filter. + /// + /// + /// Boolean value specifying whether to buffer sample data. + /// If true, the filter copies sample data into an internal buffer. + /// + /// Return's HRESULT error code. + /// + [PreserveSig] + int SetBufferSamples( [In, MarshalAs( UnmanagedType.Bool )] bool bufferThem ); + + /// + /// Retrieves a copy of the sample that the filter received most recently. + /// + /// + /// Pointer to the size of the buffer. If pBuffer is NULL, this parameter receives the required size. + /// Pointer to a buffer to receive a copy of the sample, or NULL. + /// + /// Return's HRESULT error code. + /// + [PreserveSig] + int GetCurrentBuffer( ref int bufferSize, IntPtr buffer ); + + /// + /// Not currently implemented. + /// + /// + /// + /// + /// Return's HRESULT error code. + /// + [PreserveSig] + int GetCurrentSample( IntPtr sample ); + + /// + /// Specifies a callback method to call on incoming samples. + /// + /// + /// interface containing the callback method, or NULL to cancel the callback. + /// Index specifying the callback method. + /// + /// Return's HRESULT error code. + /// + [PreserveSig] + int SetCallback( ISampleGrabberCB callback, int whichMethodToCallback ); + } +} diff --git a/VAR.Toolbox/Code/DirectShow/ISampleGrabberCB.cs b/VAR.Toolbox/Code/DirectShow/ISampleGrabberCB.cs new file mode 100644 index 0000000..680701f --- /dev/null +++ b/VAR.Toolbox/Code/DirectShow/ISampleGrabberCB.cs @@ -0,0 +1,40 @@ +namespace VAR.Toolbox.Code.DirectShow +{ + using System; + using System.Runtime.InteropServices; + + /// + /// The interface provides callback methods for the method. + /// + /// + [ComImport, + Guid("0579154A-2B53-4994-B0D0-E773148EFF85"), + InterfaceType(ComInterfaceType.InterfaceIsIUnknown)] + internal interface ISampleGrabberCB + { + /// + /// Callback method that receives a pointer to the media sample. + /// + /// + /// Starting time of the sample, in seconds. + /// Pointer to the sample's IMediaSample interface. + /// + /// Return's HRESULT error code. + /// + [PreserveSig] + int SampleCB( double sampleTime, IntPtr sample ); + + /// + /// Callback method that receives a pointer to the sample bufferþ + /// + /// + /// Starting time of the sample, in seconds. + /// Pointer to a buffer that contains the sample data. + /// Length of the buffer pointed to by buffer, in bytes + /// + /// Return's HRESULT error code. + /// + [PreserveSig] + int BufferCB( double sampleTime, IntPtr buffer, int bufferLen ); + } +} diff --git a/VAR.Toolbox/Code/DirectShow/ISpecifyPropertyPages.cs b/VAR.Toolbox/Code/DirectShow/ISpecifyPropertyPages.cs new file mode 100644 index 0000000..e0ccd89 --- /dev/null +++ b/VAR.Toolbox/Code/DirectShow/ISpecifyPropertyPages.cs @@ -0,0 +1,29 @@ +namespace VAR.Toolbox.Code.DirectShow +{ + using System; + using System.Runtime.InteropServices; + + /// + /// The interface indicates that an object supports property pages. + /// + /// + [ComImport, + Guid( "B196B28B-BAB4-101A-B69C-00AA00341D07" ), + InterfaceType( ComInterfaceType.InterfaceIsIUnknown )] + internal interface ISpecifyPropertyPages + { + /// + /// Fills a counted array of GUID values where each GUID specifies the + /// CLSID of each property page that can be displayed in the property + /// sheet for this object. + /// + /// + /// Pointer to a CAUUID structure that must be initialized + /// and filled before returning. + /// + /// Return's HRESULT error code. + /// + [PreserveSig] + int GetPages( out CAUUID pPages ); + } +} diff --git a/VAR.Toolbox/Code/DirectShow/IVideoWindow.cs b/VAR.Toolbox/Code/DirectShow/IVideoWindow.cs new file mode 100644 index 0000000..a073122 --- /dev/null +++ b/VAR.Toolbox/Code/DirectShow/IVideoWindow.cs @@ -0,0 +1,459 @@ +namespace VAR.Toolbox.Code.DirectShow +{ + using System; + using System.Runtime.InteropServices; + + /// + /// The interface sets properties on the video window. + /// + /// + [ComImport, + Guid("56A868B4-0AD4-11CE-B03A-0020AF0BA770"), + InterfaceType(ComInterfaceType.InterfaceIsDual)] + internal interface IVideoWindow + { + /// + /// Sets the video window caption. + /// + /// + /// Caption. + /// + /// Return's HRESULT error code. + /// + [PreserveSig] + int put_Caption( string caption ); + + /// + /// Retrieves the video window caption. + /// + /// + /// Caption. + /// + /// Return's HRESULT error code. + /// + [PreserveSig] + int get_Caption( [Out] out string caption ); + + /// + /// Sets the window style on the video window. + /// + /// + /// Window style flags. + /// + /// Return's HRESULT error code. + /// + [PreserveSig] + int put_WindowStyle( int windowStyle ); + + /// + /// Retrieves the window style on the video window. + /// + /// + /// Window style flags. + /// + /// Return's HRESULT error code. + /// + [PreserveSig] + int get_WindowStyle( out int windowStyle ); + + /// + /// Sets the extended window style on the video window. + /// + /// + /// Window extended style flags. + /// + /// Return's HRESULT error code. + /// + [PreserveSig] + int put_WindowStyleEx( int windowStyleEx ); + + /// + /// Retrieves the extended window style on the video window. + /// + /// + /// Window extended style flags. + /// + /// Return's HRESULT error code. + /// + [PreserveSig] + int get_WindowStyleEx( out int windowStyleEx ); + + /// + /// Specifies whether the video renderer automatically shows the video window when it receives video data. + /// + /// + /// Specifies whether the video renderer automatically shows the video window. + /// + /// Return's HRESULT error code. + /// + [PreserveSig] + int put_AutoShow( [In, MarshalAs( UnmanagedType.Bool )] bool autoShow ); + + /// + /// Queries whether the video renderer automatically shows the video window when it receives video data. + /// + /// + /// REceives window auto show flag. + /// + /// Return's HRESULT error code. + /// + [PreserveSig] + int get_AutoShow( [Out, MarshalAs( UnmanagedType.Bool )] out bool autoShow ); + + /// + /// Shows, hides, minimizes, or maximizes the video window. + /// + /// + /// Window state. + /// + /// Return's HRESULT error code. + /// + [PreserveSig] + int put_WindowState( int windowState ); + + /// + /// Queries whether the video window is visible, hidden, minimized, or maximized. + /// + /// + /// Window state. + /// + /// Return's HRESULT error code. + /// + [PreserveSig] + int get_WindowState( out int windowState ); + + /// + /// Specifies whether the video window realizes its palette in the background. + /// + /// + /// Value that specifies whether the video renderer realizes it palette in the background. + /// + /// Return's HRESULT error code. + /// + [PreserveSig] + int put_BackgroundPalette( [In, MarshalAs( UnmanagedType.Bool )] bool backgroundPalette ); + + /// + /// Queries whether the video window realizes its palette in the background. + /// + /// + /// Receives state of background palette flag. + /// + /// Return's HRESULT error code. + /// + [PreserveSig] + int get_BackgroundPalette( [Out, MarshalAs( UnmanagedType.Bool )] out bool backgroundPalette ); + + /// + /// Shows or hides the video window. + /// + /// + /// Value that specifies whether to show or hide the window. + /// + /// Return's HRESULT error code. + /// + [PreserveSig] + int put_Visible( [In, MarshalAs( UnmanagedType.Bool )] bool visible ); + + /// + /// Queries whether the video window is visible. + /// + /// + /// Visibility flag. + /// + /// Return's HRESULT error code. + /// + [PreserveSig] + int get_Visible( [Out, MarshalAs( UnmanagedType.Bool )] out bool visible ); + + /// + /// Sets the video window's x-coordinate. + /// + /// + /// Specifies the x-coordinate, in pixels. + /// + /// Return's HRESULT error code. + /// + [PreserveSig] + int put_Left( int left ); + + /// + /// Retrieves the video window's x-coordinate. + /// + /// + /// x-coordinate, in pixels. + /// + /// Return's HRESULT error code. + /// + [PreserveSig] + int get_Left( out int left ); + + /// + /// Sets the width of the video window. + /// + /// + /// Specifies the width, in pixels. + /// + /// Return's HRESULT error code. + /// + [PreserveSig] + int put_Width( int width ); + + /// + /// Retrieves the width of the video window. + /// + /// + /// Width, in pixels. + /// + /// Return's HRESULT error code. + /// + [PreserveSig] + int get_Width( out int width ); + + /// + /// Sets the video window's y-coordinate. + /// + /// + /// Specifies the y-coordinate, in pixels. + /// + /// Return's HRESULT error code. + /// + [PreserveSig] + int put_Top( int top ); + + /// + /// Retrieves the video window's y-coordinate. + /// + /// + /// y-coordinate, in pixels. + /// + /// Return's HRESULT error code. + /// + [PreserveSig] + int get_Top( out int top ); + + /// + /// Sets the height of the video window. + /// + /// + /// Specifies the height, in pixels. + /// + /// Return's HRESULT error code. + /// + [PreserveSig] + int put_Height( int height ); + + /// + /// Retrieves the height of the video window. + /// + /// + /// Height, in pixels. + /// + /// Return's HRESULT error code. + /// + [PreserveSig] + int get_Height( out int height ); + + /// + /// Specifies a parent window for the video windowþ + /// + /// + /// Specifies a handle to the parent window. + /// + /// Return's HRESULT error code. + /// + [PreserveSig] + int put_Owner( IntPtr owner ); + + /// + /// Retrieves the video window's parent window, if anyþ + /// + /// + /// Parent window's handle. + /// + /// Return's HRESULT error code. + /// + [PreserveSig] + int get_Owner( out IntPtr owner ); + + /// + /// Specifies a window to receive mouse and keyboard messages from the video window. + /// + /// + /// Specifies a handle to the window. + /// + /// Return's HRESULT error code. + /// + [PreserveSig] + int put_MessageDrain( IntPtr drain ); + + /// + /// Retrieves the window that receives mouse and keyboard messages from the video window, if any. + /// + /// + /// Window's handle. + /// + /// Return's HRESULT error code. + /// + [PreserveSig] + int get_MessageDrain( out IntPtr drain ); + + /// + /// Retrieves the color that appears around the edges of the destination rectangle. + /// + /// + /// Border's color. + /// + /// Return's HRESULT error code. + /// + [PreserveSig] + int get_BorderColor( out int color ); + + /// + /// Sets the color that appears around the edges of the destination rectangle. + /// + /// + /// Specifies the border color. + /// + /// Return's HRESULT error code. + /// + [PreserveSig] + int put_BorderColor( int color ); + + /// + /// Queries whether the video renderer is in full-screen mode. + /// + /// + /// Full-screen mode. + /// + /// Return's HRESULT error code. + /// + [PreserveSig] + int get_FullScreenMode( + [Out, MarshalAs( UnmanagedType.Bool )] out bool fullScreenMode ); + + /// + /// Enables or disables full-screen mode. + /// + /// + /// Boolean value that specifies whether to enable or disable full-screen mode. + /// + /// Return's HRESULT error code. + /// + [PreserveSig] + int put_FullScreenMode( [In, MarshalAs( UnmanagedType.Bool )] bool fullScreenMode ); + + /// + /// Places the video window at the top of the Z order. + /// + /// + /// Value that specifies whether to give the window focus. + /// + /// Return's HRESULT error code. + /// + [PreserveSig] + int SetWindowForeground( int focus ); + + /// + /// Forwards a message to the video window. + /// + /// + /// Handle to the window. + /// Specifies the message. + /// Message parameter. + /// Message parameter. + /// + /// Return's HRESULT error code. + /// + [PreserveSig] + int NotifyOwnerMessage( IntPtr hwnd, int msg, IntPtr wParam, IntPtr lParam ); + + /// + /// Sets the position of the video windowþ + /// + /// + /// Specifies the x-coordinate, in pixels. + /// Specifies the y-coordinate, in pixels. + /// Specifies the width, in pixels. + /// Specifies the height, in pixels. + /// + /// Return's HRESULT error code. + /// + [PreserveSig] + int SetWindowPosition( int left, int top, int width, int height ); + + /// + /// Retrieves the position of the video window. + /// + /// + /// x-coordinate, in pixels. + /// y-coordinate, in pixels. + /// Width, in pixels. + /// Height, in pixels. + /// + /// Return's HRESULT error code. + /// + [PreserveSig] + int GetWindowPosition( out int left, out int top, out int width, out int height ); + + /// + /// Retrieves the minimum ideal size for the video image. + /// + /// + /// Receives the minimum ideal width, in pixels. + /// Receives the minimum ideal height, in pixels. + /// + /// Return's HRESULT error code. + /// + [PreserveSig] + int GetMinIdealImageSize( out int width, out int height ); + + /// + /// Retrieves the maximum ideal size for the video image. + /// + /// + /// Receives the maximum ideal width, in pixels. + /// Receives the maximum ideal height, in pixels. + /// + /// Return's HRESULT error code. + /// + [PreserveSig] + int GetMaxIdealImageSize( out int width, out int height ); + + /// + /// Retrieves the restored window position. + /// + /// + /// x-coordinate, in pixels. + /// y-coordinate, in pixels. + /// Width, in pixels. + /// Height, in pixels. + /// + /// Return's HRESULT error code. + /// + [PreserveSig] + int GetRestorePosition( out int left, out int top, out int width, out int height ); + + /// + /// Hides the cursor. + /// + /// + /// Specifies whether to hide or display the cursor. + /// + /// Return's HRESULT error code. + /// + [PreserveSig] + int HideCursor( [In, MarshalAs( UnmanagedType.Bool )] bool hideCursor ); + + /// + /// Queries whether the cursor is hidden. + /// + /// + /// Specifies if cursor is hidden or not. + /// + /// Return's HRESULT error code. + /// + [PreserveSig] + int IsCursorHidden( [Out, MarshalAs( UnmanagedType.Bool )] out bool hideCursor ); + } +} diff --git a/VAR.Toolbox/Code/DirectShow/PhysicalConnectorType.cs b/VAR.Toolbox/Code/DirectShow/PhysicalConnectorType.cs new file mode 100644 index 0000000..f4fc0d3 --- /dev/null +++ b/VAR.Toolbox/Code/DirectShow/PhysicalConnectorType.cs @@ -0,0 +1,115 @@ +namespace VAR.Toolbox.Code.DirectShow +{ + /// + /// Specifies the physical type of pin (audio or video). + /// + public enum PhysicalConnectorType + { + /// + /// Default value of connection type. Physically it does not exist, but just either to specify that + /// connection type should not be changed (input) or was not determined (output). + /// + Default = 0, + /// + /// Specifies a tuner pin for video. + /// + VideoTuner = 1, + /// + /// Specifies a composite pin for video. + /// + VideoComposite, + /// + /// Specifies an S-Video (Y/C video) pin. + /// + VideoSVideo, + /// + /// Specifies an RGB pin for video. + /// + VideoRGB, + /// + /// Specifies a YRYBY (Y, R–Y, B–Y) pin for video. + /// + VideoYRYBY, + /// + /// Specifies a serial digital pin for video. + /// + VideoSerialDigital, + /// + /// Specifies a parallel digital pin for video. + /// + VideoParallelDigital, + /// + /// Specifies a SCSI (Small Computer System Interface) pin for video. + /// + VideoSCSI, + /// + /// Specifies an AUX (auxiliary) pin for video. + /// + VideoAUX, + /// + /// Specifies an IEEE 1394 pin for video. + /// + Video1394, + /// + /// Specifies a USB (Universal Serial Bus) pin for video. + /// + VideoUSB, + /// + /// Specifies a video decoder pin. + /// + VideoDecoder, + /// + /// Specifies a video encoder pin. + /// + VideoEncoder, + /// + /// Specifies a SCART (Peritel) pin for video. + /// + VideoSCART, + /// + /// Not used. + /// + VideoBlack, + + /// + /// Specifies a tuner pin for audio. + /// + AudioTuner = 4096, + /// + /// Specifies a line pin for audio. + /// + AudioLine, + /// + /// Specifies a microphone pin. + /// + AudioMic, + /// + /// Specifies an AES/EBU (Audio Engineering Society/European Broadcast Union) digital pin for audio. + /// + AudioAESDigital, + /// + /// Specifies an S/PDIF (Sony/Philips Digital Interface Format) digital pin for audio. + /// + AudioSPDIFDigital, + /// + /// Specifies a SCSI pin for audio. + /// + AudioSCSI, + /// + /// Specifies an AUX pin for audio. + /// + AudioAUX, + /// + /// Specifies an IEEE 1394 pin for audio. + /// + Audio1394, + /// + /// Specifies a USB pin for audio. + /// + AudioUSB, + /// + /// Specifies an audio decoder pin. + /// + AudioDecoder + } +} diff --git a/VAR.Toolbox/Code/DirectShow/Structures.cs b/VAR.Toolbox/Code/DirectShow/Structures.cs new file mode 100644 index 0000000..626bba4 --- /dev/null +++ b/VAR.Toolbox/Code/DirectShow/Structures.cs @@ -0,0 +1,510 @@ +namespace VAR.Toolbox.Code.DirectShow +{ + using System; + using System.Runtime.InteropServices; + using System.Drawing; + + // PIN_DIRECTION + + /// + /// This enumeration indicates a pin's direction. + /// + /// + [ComVisible( false )] + internal enum PinDirection + { + /// + /// Input pin. + /// + Input, + + /// + /// Output pin. + /// + Output + } + + // AM_MEDIA_TYPE + + /// + /// The structure describes the format of a media sample. + /// + /// + [ComVisible( false ), + StructLayout( LayoutKind.Sequential )] + internal class AMMediaType : IDisposable + { + /// + /// Globally unique identifier (GUID) that specifies the major type of the media sample. + /// + public Guid MajorType; + + /// + /// GUID that specifies the subtype of the media sample. + /// + public Guid SubType; + + /// + /// If true, samples are of a fixed size. + /// + [MarshalAs( UnmanagedType.Bool )] + public bool FixedSizeSamples = true; + + /// + /// If true, samples are compressed using temporal (interframe) compression. + /// + [MarshalAs( UnmanagedType.Bool )] + public bool TemporalCompression; + + /// + /// Size of the sample in bytes. For compressed data, the value can be zero. + /// + public int SampleSize = 1; + + /// + /// GUID that specifies the structure used for the format block. + /// + public Guid FormatType; + + /// + /// Not used. + /// + public IntPtr unkPtr; + + /// + /// Size of the format block, in bytes. + /// + public int FormatSize; + + /// + /// Pointer to the format block. + /// + public IntPtr FormatPtr; + + /// + /// Destroys the instance of the class. + /// + /// + ~AMMediaType( ) + { + Dispose( false ); + } + + /// + /// Dispose the object. + /// + /// + public void Dispose( ) + { + Dispose( true ); + // remove me from the Finalization queue + GC.SuppressFinalize( this ); + } + + /// + /// Dispose the object + /// + /// + /// Indicates if disposing was initiated manually. + /// + protected virtual void Dispose( bool disposing ) + { + if ( ( FormatSize != 0 ) && ( FormatPtr != IntPtr.Zero ) ) + { + Marshal.FreeCoTaskMem( FormatPtr ); + FormatSize = 0; + } + + if ( unkPtr != IntPtr.Zero ) + { + Marshal.Release( unkPtr ); + unkPtr = IntPtr.Zero; + } + } + } + + + // PIN_INFO + + /// + /// The structure contains information about a pin. + /// + /// + [ComVisible( false ), + StructLayout( LayoutKind.Sequential, Pack = 1, CharSet = CharSet.Unicode )] + internal struct PinInfo + { + /// + /// Owning filter. + /// + public IBaseFilter Filter; + + /// + /// Direction of the pin. + /// + public PinDirection Direction; + + /// + /// Name of the pin. + /// + [MarshalAs( UnmanagedType.ByValTStr, SizeConst = 128 )] + public string Name; + } + + // FILTER_INFO + [ComVisible( false ), + StructLayout( LayoutKind.Sequential, Pack = 1, CharSet = CharSet.Unicode )] + internal struct FilterInfo + { + /// + /// Filter's name. + /// + [MarshalAs( UnmanagedType.ByValTStr, SizeConst = 128 )] + public string Name; + + /// + /// Owning graph. + /// + public IFilterGraph FilterGraph; + } + + // VIDEOINFOHEADER + + /// + /// The structure describes the bitmap and color information for a video image. + /// + /// + [ComVisible( false ), + StructLayout( LayoutKind.Sequential )] + internal struct VideoInfoHeader + { + /// + /// structure that specifies the source video window. + /// + public RECT SrcRect; + + /// + /// structure that specifies the destination video window. + /// + public RECT TargetRect; + + /// + /// Approximate data rate of the video stream, in bits per second. + /// + public int BitRate; + + /// + /// Data error rate, in bit errors per second. + /// + public int BitErrorRate; + + /// + /// The desired average display time of the video frames, in 100-nanosecond units. + /// + public long AverageTimePerFrame; + + /// + /// structure that contains color and dimension information for the video image bitmap. + /// + public BitmapInfoHeader BmiHeader; + } + + // VIDEOINFOHEADER2 + + /// + /// The structure describes the bitmap and color information for a video image (v2). + /// + /// + [ComVisible( false ), + StructLayout( LayoutKind.Sequential )] + internal struct VideoInfoHeader2 + { + /// + /// structure that specifies the source video window. + /// + public RECT SrcRect; + + /// + /// structure that specifies the destination video window. + /// + public RECT TargetRect; + + /// + /// Approximate data rate of the video stream, in bits per second. + /// + public int BitRate; + + /// + /// Data error rate, in bit errors per second. + /// + public int BitErrorRate; + + /// + /// The desired average display time of the video frames, in 100-nanosecond units. + /// + public long AverageTimePerFrame; + + /// + /// Flags that specify how the video is interlaced. + /// + public int InterlaceFlags; + + /// + /// Flag set to indicate that the duplication of the stream should be restricted. + /// + public int CopyProtectFlags; + + /// + /// The X dimension of picture aspect ratio. + /// + public int PictAspectRatioX; + + /// + /// The Y dimension of picture aspect ratio. + /// + public int PictAspectRatioY; + + /// + /// Reserved for future use. + /// + public int Reserved1; + + /// + /// Reserved for future use. + /// + public int Reserved2; + + /// + /// structure that contains color and dimension information for the video image bitmap. + /// + public BitmapInfoHeader BmiHeader; + } + + /// + /// The structure contains information about the dimensions and color format of a device-independent bitmap (DIB). + /// + /// + [ComVisible( false ), + StructLayout( LayoutKind.Sequential, Pack = 2 )] + internal struct BitmapInfoHeader + { + /// + /// Specifies the number of bytes required by the structure. + /// + public int Size; + + /// + /// Specifies the width of the bitmap. + /// + public int Width; + + /// + /// Specifies the height of the bitmap, in pixels. + /// + public int Height; + + /// + /// Specifies the number of planes for the target device. This value must be set to 1. + /// + public short Planes; + + /// + /// Specifies the number of bits per pixel. + /// + public short BitCount; + + /// + /// If the bitmap is compressed, this member is a FOURCC the specifies the compression. + /// + public int Compression; + + /// + /// Specifies the size, in bytes, of the image. + /// + public int ImageSize; + + /// + /// Specifies the horizontal resolution, in pixels per meter, of the target device for the bitmap. + /// + public int XPelsPerMeter; + + /// + /// Specifies the vertical resolution, in pixels per meter, of the target device for the bitmap. + /// + public int YPelsPerMeter; + + /// + /// Specifies the number of color indices in the color table that are actually used by the bitmap. + /// + public int ColorsUsed; + + /// + /// Specifies the number of color indices that are considered important for displaying the bitmap. + /// + public int ColorsImportant; + } + + // RECT + + /// + /// The structure defines the coordinates of the upper-left and lower-right corners of a rectangle. + /// + /// + [ComVisible( false ), + StructLayout( LayoutKind.Sequential )] + internal struct RECT + { + /// + /// Specifies the x-coordinate of the upper-left corner of the rectangle. + /// + public int Left; + + /// + /// Specifies the y-coordinate of the upper-left corner of the rectangle. + /// + public int Top; + + /// + /// Specifies the x-coordinate of the lower-right corner of the rectangle. + /// + public int Right; + + /// + /// Specifies the y-coordinate of the lower-right corner of the rectangle. + /// + public int Bottom; + } + + // CAUUID + + /// + /// The CAUUID structure is a Counted Array of UUID or GUID types. + /// + /// + [ComVisible( false ), + StructLayout( LayoutKind.Sequential )] + internal struct CAUUID + { + /// + /// Size of the array pointed to by pElems. + /// + public int cElems; + + /// + /// Pointer to an array of UUID values, each of which specifies UUID. + /// + public IntPtr pElems; + + /// + /// Performs manual marshaling of pElems to retrieve an array of Guid objects. + /// + /// + /// A managed representation of pElems. + /// + public Guid[] ToGuidArray( ) + { + Guid[] retval = new Guid[cElems]; + + for ( int i = 0; i < cElems; i++ ) + { + IntPtr ptr = new IntPtr( pElems.ToInt64( ) + i * Marshal.SizeOf( typeof( Guid ) ) ); + retval[i] = (Guid) Marshal.PtrToStructure( ptr, typeof( Guid ) ); + } + + return retval; + } + } + + /// + /// Enumeration of DirectShow event codes. + /// + internal enum DsEvCode + { + None, + Complete = 0x01, // EC_COMPLETE + DeviceLost = 0x1F, // EC_DEVICE_LOST + //(...) not yet interested in other events + } + + [Flags, ComVisible( false )] + internal enum AnalogVideoStandard + { + None = 0x00000000, // This is a digital sensor + NTSC_M = 0x00000001, // 75 IRE Setup + NTSC_M_J = 0x00000002, // Japan, 0 IRE Setup + NTSC_433 = 0x00000004, + PAL_B = 0x00000010, + PAL_D = 0x00000020, + PAL_G = 0x00000040, + PAL_H = 0x00000080, + PAL_I = 0x00000100, + PAL_M = 0x00000200, + PAL_N = 0x00000400, + PAL_60 = 0x00000800, + SECAM_B = 0x00001000, + SECAM_D = 0x00002000, + SECAM_G = 0x00004000, + SECAM_H = 0x00008000, + SECAM_K = 0x00010000, + SECAM_K1 = 0x00020000, + SECAM_L = 0x00040000, + SECAM_L1 = 0x00080000, + PAL_N_COMBO = 0x00100000 // Argentina + } + + [Flags, ComVisible( false )] + internal enum VideoControlFlags + { + FlipHorizontal = 0x0001, + FlipVertical = 0x0002, + ExternalTriggerEnable = 0x0004, + Trigger = 0x0008 + } + + [StructLayout( LayoutKind.Sequential ), ComVisible( false )] + internal class VideoStreamConfigCaps // VIDEO_STREAM_CONFIG_CAPS + { + public Guid Guid; + public AnalogVideoStandard VideoStandard; + public Size InputSize; + public Size MinCroppingSize; + public Size MaxCroppingSize; + public int CropGranularityX; + public int CropGranularityY; + public int CropAlignX; + public int CropAlignY; + public Size MinOutputSize; + public Size MaxOutputSize; + public int OutputGranularityX; + public int OutputGranularityY; + public int StretchTapsX; + public int StretchTapsY; + public int ShrinkTapsX; + public int ShrinkTapsY; + public long MinFrameInterval; + public long MaxFrameInterval; + public int MinBitsPerSecond; + public int MaxBitsPerSecond; + } + + /// + /// Specifies a filter's state or the state of the filter graph. + /// + internal enum FilterState + { + /// + /// Stopped. The filter is not processing data. + /// + State_Stopped, + + /// + /// Paused. The filter is processing data, but not rendering it. + /// + State_Paused, + + /// + /// Running. The filter is processing and rendering data. + /// + State_Running + } +} diff --git a/VAR.Toolbox/Code/DirectShow/Tools.cs b/VAR.Toolbox/Code/DirectShow/Tools.cs new file mode 100644 index 0000000..05850f8 --- /dev/null +++ b/VAR.Toolbox/Code/DirectShow/Tools.cs @@ -0,0 +1,88 @@ +namespace VAR.Toolbox.Code.DirectShow +{ + using System; + using System.Runtime.InteropServices; + + /// + /// Some miscellaneous functions. + /// + /// + internal static class Tools + { + /// + /// Get filter's pin. + /// + /// + /// Filter to get pin of. + /// Pin's direction. + /// Pin's number. + /// + /// Returns filter's pin. + /// + public static IPin GetPin( IBaseFilter filter, PinDirection dir, int num ) + { + IPin[] pin = new IPin[1]; + IEnumPins pinsEnum = null; + + // enum filter pins + if ( filter.EnumPins( out pinsEnum ) == 0 ) + { + PinDirection pinDir; + int n; + + try + { + // get next pin + while ( pinsEnum.Next( 1, pin, out n ) == 0 ) + { + // query pin`s direction + pin[0].QueryDirection( out pinDir ); + + if ( pinDir == dir ) + { + if ( num == 0 ) + return pin[0]; + num--; + } + + Marshal.ReleaseComObject( pin[0] ); + pin[0] = null; + } + } + finally + { + Marshal.ReleaseComObject( pinsEnum ); + } + } + return null; + } + + /// + /// Get filter's input pin. + /// + /// + /// Filter to get pin of. + /// Pin's number. + /// + /// Returns filter's pin. + /// + public static IPin GetInPin( IBaseFilter filter, int num ) + { + return GetPin( filter, PinDirection.Input, num ); + } + + /// + /// Get filter's output pin. + /// + /// + /// Filter to get pin of. + /// Pin's number. + /// + /// Returns filter's pin. + /// + public static IPin GetOutPin( IBaseFilter filter, int num ) + { + return GetPin( filter, PinDirection.Output, num ); + } + } +} diff --git a/VAR.Toolbox/Code/DirectShow/Uuids.cs b/VAR.Toolbox/Code/DirectShow/Uuids.cs new file mode 100644 index 0000000..84db266 --- /dev/null +++ b/VAR.Toolbox/Code/DirectShow/Uuids.cs @@ -0,0 +1,327 @@ +namespace VAR.Toolbox.Code.DirectShow +{ + using System; + using System.Runtime.InteropServices; + + /// + /// DirectShow class IDs. + /// + [ComVisible( false )] + static internal class Clsid + { + /// + /// System device enumerator. + /// + /// + /// Equals to CLSID_SystemDeviceEnum. + /// + public static readonly Guid SystemDeviceEnum = + new Guid( 0x62BE5D10, 0x60EB, 0x11D0, 0xBD, 0x3B, 0x00, 0xA0, 0xC9, 0x11, 0xCE, 0x86 ); + + /// + /// Filter graph. + /// + /// + /// Equals to CLSID_FilterGraph. + /// + public static readonly Guid FilterGraph = + new Guid( 0xE436EBB3, 0x524F, 0x11CE, 0x9F, 0x53, 0x00, 0x20, 0xAF, 0x0B, 0xA7, 0x70 ); + + /// + /// Sample grabber. + /// + /// + /// Equals to CLSID_SampleGrabber. + /// + public static readonly Guid SampleGrabber = + new Guid( 0xC1F400A0, 0x3F08, 0x11D3, 0x9F, 0x0B, 0x00, 0x60, 0x08, 0x03, 0x9E, 0x37 ); + + /// + /// Capture graph builder. + /// + /// + /// Equals to CLSID_CaptureGraphBuilder2. + /// + public static readonly Guid CaptureGraphBuilder2 = + new Guid( 0xBF87B6E1, 0x8C27, 0x11D0, 0xB3, 0xF0, 0x00, 0xAA, 0x00, 0x37, 0x61, 0xC5 ); + + /// + /// Async reader. + /// + /// + /// Equals to CLSID_AsyncReader. + /// + public static readonly Guid AsyncReader = + new Guid( 0xE436EBB5, 0x524F, 0x11CE, 0x9F, 0x53, 0x00, 0x20, 0xAF, 0x0B, 0xA7, 0x70 ); + + + public static readonly Guid NullRenderer = + new Guid(0xC1F400A4, 0x3F08, 0x11d3, 0x9F, 0x0B, 0x00, 0x60, 0x08, 0x03, 0x9E, 0x37); + + } + + /// + /// DirectShow format types. + /// + /// + [ComVisible( false )] + static internal class FormatType + { + /// + /// VideoInfo. + /// + /// + /// Equals to FORMAT_VideoInfo. + /// + public static readonly Guid VideoInfo = + new Guid( 0x05589F80, 0xC356, 0x11CE, 0xBF, 0x01, 0x00, 0xAA, 0x00, 0x55, 0x59, 0x5A ); + + /// + /// VideoInfo2. + /// + /// + /// Equals to FORMAT_VideoInfo2. + /// + public static readonly Guid VideoInfo2 = + new Guid( 0xf72A76A0, 0xEB0A, 0x11D0, 0xAC, 0xE4, 0x00, 0x00, 0xC0, 0xCC, 0x16, 0xBA ); + } + + /// + /// DirectShow media types. + /// + /// + [ComVisible( false )] + static internal class MediaType + { + /// + /// Video. + /// + /// + /// Equals to MEDIATYPE_Video. + /// + public static readonly Guid Video = + new Guid( 0x73646976, 0x0000, 0x0010, 0x80, 0x00, 0x00, 0xAA, 0x00, 0x38, 0x9B, 0x71 ); + + /// + /// Interleaved. Used by Digital Video (DV). + /// + /// + /// Equals to MEDIATYPE_Interleaved. + /// + public static readonly Guid Interleaved = + new Guid( 0x73766169, 0x0000, 0x0010, 0x80, 0x00, 0x00, 0xAA, 0x00, 0x38, 0x9B, 0x71 ); + + /// + /// Audio. + /// + /// + /// Equals to MEDIATYPE_Audio. + /// + public static readonly Guid Audio = + new Guid( 0x73647561, 0x0000, 0x0010, 0x80, 0x00, 0x00, 0xAA, 0x00, 0x38, 0x9B, 0x71 ); + + /// + /// Text. + /// + /// + /// Equals to MEDIATYPE_Text. + /// + public static readonly Guid Text = + new Guid( 0x73747874, 0x0000, 0x0010, 0x80, 0x00, 0x00, 0xAA, 0x00, 0x38, 0x9B, 0x71 ); + + /// + /// Byte stream with no time stamps. + /// + /// + /// Equals to MEDIATYPE_Stream. + /// + public static readonly Guid Stream = + new Guid( 0xE436EB83, 0x524F, 0x11CE, 0x9F, 0x53, 0x00, 0x20, 0xAF, 0x0B, 0xA7, 0x70 ); + } + + /// + /// DirectShow media subtypes. + /// + /// + [ComVisible( false )] + static internal class MediaSubType + { + /// + /// YUY2 (packed 4:2:2). + /// + /// + /// Equals to MEDIASUBTYPE_YUYV. + /// + public static readonly Guid YUYV = + new Guid( 0x56595559, 0x0000, 0x0010, 0x80, 0x00, 0x00, 0xAA, 0x00, 0x38, 0x9B, 0x71 ); + + /// + /// IYUV. + /// + /// + /// Equals to MEDIASUBTYPE_IYUV. + /// + public static readonly Guid IYUV = + new Guid( 0x56555949, 0x0000, 0x0010, 0x80, 0x00, 0x00, 0xAA, 0x00, 0x38, 0x9B, 0x71 ); + + /// + /// A DV encoding format. (FOURCC 'DVSD') + /// + /// + /// Equals to MEDIASUBTYPE_DVSD. + /// + public static readonly Guid DVSD = + new Guid( 0x44535644, 0x0000, 0x0010, 0x80, 0x00, 0x00, 0xAA, 0x00, 0x38, 0x9B, 0x71 ); + + /// + /// RGB, 1 bit per pixel (bpp), palettized. + /// + /// + /// Equals to MEDIASUBTYPE_RGB1. + /// + public static readonly Guid RGB1 = + new Guid( 0xE436EB78, 0x524F, 0x11CE, 0x9F, 0x53, 0x00, 0x20, 0xAF, 0x0B, 0xA7, 0x70 ); + + /// + /// RGB, 4 bpp, palettized. + /// + /// + /// Equals to MEDIASUBTYPE_RGB4. + /// + public static readonly Guid RGB4 = + new Guid( 0xE436EB79, 0x524F, 0x11CE, 0x9F, 0x53, 0x00, 0x20, 0xAF, 0x0B, 0xA7, 0x70 ); + + /// + /// RGB, 8 bpp. + /// + /// + /// Equals to MEDIASUBTYPE_RGB8. + /// + public static readonly Guid RGB8 = + new Guid( 0xE436EB7A, 0x524F, 0x11CE, 0x9F, 0x53, 0x00, 0x20, 0xAF, 0x0B, 0xA7, 0x70 ); + + /// + /// RGB 565, 16 bpp. + /// + /// + /// Equals to MEDIASUBTYPE_RGB565. + /// + public static readonly Guid RGB565 = + new Guid( 0xE436EB7B, 0x524F, 0x11CE, 0x9F, 0x53, 0x00, 0x20, 0xAF, 0x0B, 0xA7, 0x70 ); + + /// + /// RGB 555, 16 bpp. + /// + /// + /// Equals to MEDIASUBTYPE_RGB555. + /// + public static readonly Guid RGB555 = + new Guid( 0xE436EB7C, 0x524F, 0x11CE, 0x9F, 0x53, 0x00, 0x20, 0xAF, 0x0B, 0xA7, 0x70 ); + + /// + /// RGB, 24 bpp. + /// + /// + /// Equals to MEDIASUBTYPE_RGB24. + /// + public static readonly Guid RGB24 = + new Guid( 0xE436Eb7D, 0x524F, 0x11CE, 0x9F, 0x53, 0x00, 0x20, 0xAF, 0x0B, 0xA7, 0x70 ); + + /// + /// RGB, 32 bpp, no alpha channel. + /// + /// + /// Equals to MEDIASUBTYPE_RGB32. + /// + public static readonly Guid RGB32 = + new Guid( 0xE436EB7E, 0x524F, 0x11CE, 0x9F, 0x53, 0x00, 0x20, 0xAF, 0x0B, 0xA7, 0x70 ); + + /// + /// Data from AVI file. + /// + /// + /// Equals to MEDIASUBTYPE_Avi. + /// + public static readonly Guid Avi = + new Guid( 0xE436EB88, 0x524F, 0x11CE, 0x9F, 0x53, 0x00, 0x20, 0xAF, 0x0B, 0xA7, 0x70 ); + + /// + /// Advanced Streaming Format (ASF). + /// + /// + /// Equals to MEDIASUBTYPE_Asf. + /// + public static readonly Guid Asf = + new Guid( 0x3DB80F90, 0x9412, 0x11D1, 0xAD, 0xED, 0x00, 0x00, 0xF8, 0x75, 0x4B, 0x99 ); + } + + /// + /// DirectShow pin categories. + /// + /// + [ComVisible( false )] + static internal class PinCategory + { + /// + /// Capture pin. + /// + /// + /// Equals to PIN_CATEGORY_CAPTURE. + /// + public static readonly Guid Capture = + new Guid( 0xFB6C4281, 0x0353, 0x11D1, 0x90, 0x5F, 0x00, 0x00, 0xC0, 0xCC, 0x16, 0xBA ); + + /// + /// Preview pin. + /// + /// + /// Equals to PIN_CATEGORY_PREVIEW. + /// + public static readonly Guid Preview = + new Guid(0xfb6c4282, 0x0353, 0x11d1, 0x90, 0x5f, 0x00, 0x00, 0xc0, 0xcc, 0x16, 0xba); + + } + + /// + /// DirectShow filter categories. + /// + [ComVisible(false)] + public static class FilterCategory + { + /// + /// Audio input device category. + /// + /// + /// Equals to CLSID_AudioInputDeviceCategory. + /// + public static readonly Guid AudioInputDevice = + new Guid(0x33D9A762, 0x90C8, 0x11D0, 0xBD, 0x43, 0x00, 0xA0, 0xC9, 0x11, 0xCE, 0x86); + + /// + /// Video input device category. + /// + /// + /// Equals to CLSID_VideoInputDeviceCategory. + /// + public static readonly Guid VideoInputDevice = + new Guid(0x860BB310, 0x5D01, 0x11D0, 0xBD, 0x3B, 0x00, 0xA0, 0xC9, 0x11, 0xCE, 0x86); + + /// + /// Video compressor category. + /// + /// + /// Equals to CLSID_VideoCompressorCategory. + /// + public static readonly Guid VideoCompressorCategory = + new Guid(0x33D9A760, 0x90C8, 0x11D0, 0xBD, 0x43, 0x00, 0xA0, 0xC9, 0x11, 0xCE, 0x86); + + /// + /// Audio compressor category + /// + /// + /// Equals to CLSID_AudioCompressorCategory. + /// + public static readonly Guid AudioCompressorCategory = + new Guid(0x33D9A761, 0x90C8, 0x11D0, 0xBD, 0x43, 0x00, 0xA0, 0xC9, 0x11, 0xCE, 0x86); + } +} diff --git a/VAR.Toolbox/Code/DirectShow/Win32.cs b/VAR.Toolbox/Code/DirectShow/Win32.cs new file mode 100644 index 0000000..7751789 --- /dev/null +++ b/VAR.Toolbox/Code/DirectShow/Win32.cs @@ -0,0 +1,94 @@ +namespace VAR.Toolbox.Code.DirectShow +{ + using System; + using System.Runtime.InteropServices; + using System.Runtime.InteropServices.ComTypes; + + /// + /// Some Win32 API used internally. + /// + /// + internal static class Win32 + { + /// + /// Supplies a pointer to an implementation of IBindCtx (a bind context object). + /// This object stores information about a particular moniker-binding operation. + /// + /// + /// Reserved for future use; must be zero. + /// Address of IBindCtx* pointer variable that receives the + /// interface pointer to the new bind context object. + /// + /// Returns S_OK on success. + /// + [DllImport( "ole32.dll" )] + public static extern + int CreateBindCtx( int reserved, out IBindCtx ppbc ); + + /// + /// Converts a string into a moniker that identifies the object named by the string. + /// + /// + /// Pointer to the IBindCtx interface on the bind context object to be used in this binding operation. + /// Pointer to a zero-terminated wide character string containing the display name to be parsed. + /// Pointer to the number of characters of szUserName that were consumed. + /// Address of IMoniker* pointer variable that receives the interface pointer + /// to the moniker that was built from szUserName. + /// + /// Returns S_OK on success. + /// + [DllImport( "ole32.dll", CharSet = CharSet.Unicode )] + public static extern + int MkParseDisplayName( IBindCtx pbc, string szUserName, + ref int pchEaten, out IMoniker ppmk ); + + /// + /// Copy a block of memory. + /// + /// + /// Destination pointer. + /// Source pointer. + /// Memory block's length to copy. + /// + /// Return's the value of dst - pointer to destination. + /// + [DllImport("ntdll.dll", CallingConvention = CallingConvention.Cdecl)] + public static unsafe extern int memcpy( + byte* dst, + byte* src, + int count); + + /// + /// Invokes a new property frame, that is, a property sheet dialog box. + /// + /// + /// Parent window of property sheet dialog box. + /// Horizontal position for dialog box. + /// Vertical position for dialog box. + /// Dialog box caption. + /// Number of object pointers in ppUnk. + /// Pointer to the objects for property sheet. + /// Number of property pages in lpPageClsID. + /// Array of CLSIDs for each property page. + /// Locale identifier for property sheet locale. + /// Reserved. + /// Reserved. + /// + /// Returns S_OK on success. + /// + [DllImport( "oleaut32.dll" )] + public static extern int OleCreatePropertyFrame( + IntPtr hwndOwner, + int x, + int y, + [MarshalAs( UnmanagedType.LPWStr )] string caption, + int cObjects, + [MarshalAs( UnmanagedType.Interface, ArraySubType = UnmanagedType.IUnknown )] + ref object ppUnk, + int cPages, + IntPtr lpPageClsID, + int lcid, + int dwReserved, + IntPtr lpvReserved ); + } +} diff --git a/VAR.Toolbox/Code/Webcam.cs b/VAR.Toolbox/Code/Webcam.cs new file mode 100644 index 0000000..4b4c513 --- /dev/null +++ b/VAR.Toolbox/Code/Webcam.cs @@ -0,0 +1,322 @@ +using System; +using System.Collections.Generic; +using System.Drawing; +using System.Drawing.Imaging; +using System.Runtime.InteropServices; +using System.Runtime.InteropServices.ComTypes; +using VAR.Toolbox.Code.DirectShow; + +namespace VAR.Toolbox.Code +{ + public class Webcam + { + #region Declarations + + private IFilterGraph2 graph; + private ICaptureGraphBuilder2 capture; + private IMediaControl control; + private IBaseFilter sourceFilter; + private IBaseFilter samplegrabberfilter; + private IBaseFilter nullrenderer; + + private Grabber grabber; + + private int width = 0; + private int height = 0; + private int bpp = 0; + + private bool active = false; + + private static Dictionary _deviceDescriptions; + + #endregion Declarations + + #region Properties + + public int Width { get { return width; } } + public int Height { get { return height; } } + public int BPP { get { return bpp; } } + + public bool Active { get { return active; } } + + #endregion Properties + + #region Lifecycle + + public Webcam(string monikerString) + { + int result; + + graph = CreateInstanceFromClsid(Clsid.FilterGraph); + capture = CreateInstanceFromClsid(Clsid.CaptureGraphBuilder2); + control = (IMediaControl)graph; + capture.SetFiltergraph((IGraphBuilder)graph); + + IBindCtx bindCtx = null; + IMoniker moniker = null; + + int n = 0; + + if (Win32.CreateBindCtx(0, out bindCtx) != 0) + { + throw new Exception("Failed to create binding context"); + } + if (Win32.MkParseDisplayName(bindCtx, monikerString, ref n, out moniker) != 0) + { + throw new Exception("Failed to create binding moniker"); + } + + graph.AddSourceFilterForMoniker(moniker, bindCtx, monikerString, out sourceFilter); + + samplegrabberfilter = CreateInstanceFromClsid(Clsid.SampleGrabber); + graph.AddFilter(samplegrabberfilter, string.Format("SampleGrabber {0}", monikerString)); + + ISampleGrabber sampleGrabber = (ISampleGrabber)samplegrabberfilter; + + // Set media type + AMMediaType mediaType = new AMMediaType(); + mediaType.MajorType = MediaType.Video; + mediaType.SubType = MediaSubType.RGB24; + sampleGrabber.SetMediaType(mediaType); + + grabber = new Grabber(this); + result = sampleGrabber.SetCallback(grabber, 1); + if (result < 0) throw new Exception("Failure creating Webcam device"); + + //set the null renderer + nullrenderer = CreateInstanceFromClsid(Clsid.NullRenderer); + graph.AddFilter(nullrenderer, string.Format("NullRenderer {0}", monikerString)); + + result = capture.RenderStream(PinCategory.Preview, MediaType.Video, sourceFilter, samplegrabberfilter, nullrenderer); + if (result < 0) throw new Exception("Failure creating Webcam device"); + + AMMediaType queryMediaType = new AMMediaType(); + result = sampleGrabber.GetConnectedMediaType(queryMediaType); + if (result == 0) + { + if (queryMediaType.FormatType == FormatType.VideoInfo) + { + VideoInfoHeader videoInfo = (VideoInfoHeader)Marshal.PtrToStructure(queryMediaType.FormatPtr, typeof(VideoInfoHeader)); + width = videoInfo.BmiHeader.Width; + height = videoInfo.BmiHeader.Height; + bpp = videoInfo.BmiHeader.BitCount; + } + } + + control.Run(); + Stop(); + } + + #endregion Lifecycle + + #region Public methods + + public void Start() + { + int result; + result = nullrenderer.Run(0); + if (result < 0) throw new Exception("Webcam Start failure"); + result = samplegrabberfilter.Run(0); + if (result < 0) throw new Exception("Webcam Start failure"); + result = sourceFilter.Run(0); + if (result < 0) throw new Exception("Webcam Start failure"); + active = true; + } + + public void Stop() + { + int result; + result = sourceFilter.Stop(); + if (result < 0) throw new Exception("Webcam Stop failure"); + result = samplegrabberfilter.Stop(); + if (result < 0) throw new Exception("Webcam Stop failure"); + result = nullrenderer.Stop(); + if (result < 0) throw new Exception("Webcam Stop failure"); + active = false; + } + + public static Dictionary ListDevices() + { + if (_deviceDescriptions != null) { return _deviceDescriptions; } + + int result; + Dictionary devices = new Dictionary(); + ICreateDevEnum devEnum = CreateInstanceFromClsid(Clsid.SystemDeviceEnum); + + IEnumMoniker enumMon = null; + Guid category = FilterCategory.VideoInputDevice; + result = devEnum.CreateClassEnumerator(ref category, out enumMon, 0); + if (result != 0) + throw new ApplicationException("No devices of the category"); + + IMoniker[] devMoniker = new IMoniker[1]; + IntPtr n = IntPtr.Zero; + while (true) + { + // Get next filter + result = enumMon.Next(1, devMoniker, n); + if ((result != 0) || (devMoniker[0] == null)) + break; + + // Add device description + string deviceName = new String(GetMonikerName(devMoniker[0]).ToCharArray()); + string deviceString = new String(GetMonikerString(devMoniker[0]).ToCharArray()); + devices.Add(deviceName, deviceString); + + // Release COM object + Marshal.ReleaseComObject(devMoniker[0]); + devMoniker[0] = null; + } + _deviceDescriptions = devices; + + Marshal.ReleaseComObject(devEnum); + Marshal.ReleaseComObject(enumMon); + + return devices; + } + + #endregion Public methods + + #region Private methods + + private static T CreateInstanceFromClsid(Guid clsid) + { + Type srvType = Type.GetTypeFromCLSID(clsid); + if (srvType == null) + throw new ApplicationException("Failed creating device enumerator"); + + object comObj = Activator.CreateInstance(srvType); + return (T)comObj; + } + + // + // Get moniker string of the moniker + // + private static string GetMonikerString(IMoniker moniker) + { + string str; + moniker.GetDisplayName(null, null, out str); + return str; + } + + // + // Get moniker name represented + // + private static string GetMonikerName(IMoniker moniker) + { + Object bagObj = null; + IPropertyBag bag = null; + + try + { + Guid bagId = typeof(IPropertyBag).GUID; + // get property bag of the moniker + moniker.BindToStorage(null, null, ref bagId, out bagObj); + bag = (IPropertyBag)bagObj; + + // read FriendlyName + object val = ""; + int hr = bag.Read("FriendlyName", ref val, IntPtr.Zero); + if (hr != 0) + Marshal.ThrowExceptionForHR(hr); + + // get it as string + string ret = (string)val; + if ((ret == null) || (ret.Length < 1)) + throw new ApplicationException(); + + return ret; + } + catch (Exception) + { + return string.Empty; + } + finally + { + // release all COM objects + bag = null; + if (bagObj != null) + { + Marshal.ReleaseComObject(bagObj); + bagObj = null; + } + } + } + + #endregion Private methods + + #region NewFrameEvent + + public delegate void NewFrameEventHandler(object sender, Bitmap frame); + + public event NewFrameEventHandler NewFrame; + + private void OnNewFrame(Bitmap frame) + { + if (NewFrame != null) + NewFrame(this, frame); + } + + #endregion NewFrameEvent + + #region Grabber + + private class Grabber : ISampleGrabberCB + { + private Webcam _parent; + + public Grabber(Webcam parent) + { + _parent = parent; + } + + public int SampleCB(double sampleTime, IntPtr sample) + { + return 0; + } + + public int BufferCB(double sampleTime, IntPtr buffer, int bufferLen) + { + if (_parent.NewFrame != null) + { + // create new image + Bitmap _image = new Bitmap(_parent.width, _parent.height, PixelFormat.Format24bppRgb); + Rectangle _imageRect = new Rectangle(0, 0, _parent.width, _parent.height); + + // lock bitmap data + BitmapData imageData = _image.LockBits( + _imageRect, + ImageLockMode.ReadWrite, + PixelFormat.Format24bppRgb); + + // copy image data + int srcStride = imageData.Stride; + int dstStride = imageData.Stride; + + unsafe + { + byte* dst = (byte*)imageData.Scan0.ToPointer() + dstStride * (_parent.height - 1); + byte* src = (byte*)buffer.ToPointer(); + + for (int y = 0; y < _parent.height; y++) + { + Win32.memcpy(dst, src, srcStride); + dst -= dstStride; + src += srcStride; + } + } + + // unlock bitmap data + _image.UnlockBits(imageData); + + // notify parent + _parent.OnNewFrame(_image); + } + + return 0; + } + } + + #endregion Grabber + } +} diff --git a/VAR.Toolbox/Controls/CtrImageViewer.cs b/VAR.Toolbox/Controls/CtrImageViewer.cs new file mode 100644 index 0000000..341cdf3 --- /dev/null +++ b/VAR.Toolbox/Controls/CtrImageViewer.cs @@ -0,0 +1,125 @@ +using System; +using System.Drawing; +using System.Windows.Forms; + +namespace VAR.Toolbox.Controls +{ + public class CtrImageViewer : PictureBox + { + #region Declarations + + Image _imageShow = null; + + // Image projection + private double offsetX = 0; + private double offsetY = 0; + private double scaleX = 1.0f; + private double scaleY = 1.0f; + + #endregion + + #region Properties + + public Image ImageShow + { + get { return _imageShow; } + set + { + lock (this) + { + _imageShow = value; + this.Invalidate(); + } + } + } + + #endregion + + #region Control life cycle + + public CtrImageViewer() + { + BackColor = Color.Black; + } + + protected override void OnPaint(PaintEventArgs pe) + { + base.OnPaint(pe); + Redraw(pe.Graphics); + } + + protected override void OnResize(EventArgs e) + { + base.OnResize(e); + //Redraw(null); + this.Invalidate(); + } + + #endregion + + #region Private methods + + private void Redraw(Graphics graph) + { + if (_imageShow == null) + { + return; + } + lock (_imageShow) + { + if (graph == null) + { + graph = this.CreateGraphics(); + } + + // Calcular dimensiones a dibujar y centrar + int imgDrawWidth; + int imgDrawHeight; + float imgDrawX = 0; + float imgDrawY = 0; + float relation = (float)_imageShow.Width / (float)_imageShow.Height; + if (relation > 0) + { + // Imagen mas ancha que alta + imgDrawHeight = (int)(this.Width / relation); + if (imgDrawHeight > this.Height) + { + imgDrawHeight = this.Height; + imgDrawWidth = (int)(this.Height * relation); + imgDrawX = ((this.Width - imgDrawWidth) / 2.0f); + } + else + { + imgDrawWidth = this.Width; + imgDrawY = ((this.Height - imgDrawHeight) / 2.0f); + } + } + else + { + // Imagen mas alta que ancha + imgDrawWidth = (int)(this.Width * relation); + if (imgDrawWidth > this.Width) + { + imgDrawWidth = this.Width; + imgDrawHeight = (int)(this.Height / relation); + imgDrawY = ((this.Height - imgDrawHeight) / 2.0f); + } + else + { + imgDrawHeight = this.Height; + imgDrawX = ((this.Width - imgDrawWidth) / 2.0f); + } + } + + graph.DrawImage(_imageShow, imgDrawX, imgDrawY, imgDrawWidth, imgDrawHeight); + offsetX = imgDrawX; + offsetY = imgDrawY; + scaleX = (double)imgDrawWidth / (double)_imageShow.Width; + scaleY = (double)imgDrawHeight / (double)_imageShow.Height; + } + } + + #endregion + + } +} diff --git a/VAR.Toolbox/UI/FrmToolbox.Designer.cs b/VAR.Toolbox/UI/FrmToolbox.Designer.cs index e32ca0e..9ff2373 100644 --- a/VAR.Toolbox/UI/FrmToolbox.Designer.cs +++ b/VAR.Toolbox/UI/FrmToolbox.Designer.cs @@ -30,6 +30,7 @@ { this.btnBase64 = new System.Windows.Forms.Button(); this.btnProxyCmd = new System.Windows.Forms.Button(); + this.btnWebcam = new System.Windows.Forms.Button(); this.SuspendLayout(); // // btnBase64 @@ -52,11 +53,22 @@ this.btnProxyCmd.UseVisualStyleBackColor = true; this.btnProxyCmd.Click += new System.EventHandler(this.btnProxyCmd_Click); // + // btnWebcam + // + this.btnWebcam.Location = new System.Drawing.Point(12, 94); + this.btnWebcam.Name = "btnWebcam"; + this.btnWebcam.Size = new System.Drawing.Size(209, 36); + this.btnWebcam.TabIndex = 2; + this.btnWebcam.Text = "Webcam"; + this.btnWebcam.UseVisualStyleBackColor = true; + this.btnWebcam.Click += new System.EventHandler(this.btnWebcam_Click); + // // FrmToolbox // this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F); this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; this.ClientSize = new System.Drawing.Size(233, 391); + this.Controls.Add(this.btnWebcam); this.Controls.Add(this.btnProxyCmd); this.Controls.Add(this.btnBase64); this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.Fixed3D; @@ -71,6 +83,7 @@ private System.Windows.Forms.Button btnBase64; private System.Windows.Forms.Button btnProxyCmd; + private System.Windows.Forms.Button btnWebcam; } } diff --git a/VAR.Toolbox/UI/FrmToolbox.cs b/VAR.Toolbox/UI/FrmToolbox.cs index 0dba63a..fec4574 100644 --- a/VAR.Toolbox/UI/FrmToolbox.cs +++ b/VAR.Toolbox/UI/FrmToolbox.cs @@ -21,5 +21,11 @@ namespace VAR.Toolbox.UI var frmProxyCmd = new FrmProxyCmd(); frmProxyCmd.Show(); } + + private void btnWebcam_Click(object sender, EventArgs e) + { + var frmWebcam = new FrmWebcam(); + frmWebcam.Show(); + } } } diff --git a/VAR.Toolbox/UI/FrmWebcam.Designer.cs b/VAR.Toolbox/UI/FrmWebcam.Designer.cs new file mode 100644 index 0000000..90a6f0f --- /dev/null +++ b/VAR.Toolbox/UI/FrmWebcam.Designer.cs @@ -0,0 +1,99 @@ +namespace VAR.Toolbox +{ + partial class FrmWebcam + { + /// + /// Required designer variable. + /// + private System.ComponentModel.IContainer components = null; + + /// + /// Clean up any resources being used. + /// + /// true if managed resources should be disposed; otherwise, false. + protected override void Dispose(bool disposing) + { + if (disposing && (components != null)) + { + components.Dispose(); + } + base.Dispose(disposing); + } + + #region Windows Form Designer generated code + + /// + /// Required method for Designer support - do not modify + /// the contents of this method with the code editor. + /// + private void InitializeComponent() + { + this.btnStartStop = new System.Windows.Forms.Button(); + this.cboWebcams = new System.Windows.Forms.ComboBox(); + this.picWebcam = new VAR.Toolbox.Controls.CtrImageViewer(); + ((System.ComponentModel.ISupportInitialize)(this.picWebcam)).BeginInit(); + this.SuspendLayout(); + // + // btnStartStop + // + this.btnStartStop.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left))); + this.btnStartStop.Location = new System.Drawing.Point(18, 500); + this.btnStartStop.Margin = new System.Windows.Forms.Padding(4, 5, 4, 5); + this.btnStartStop.Name = "btnStartStop"; + this.btnStartStop.Size = new System.Drawing.Size(112, 35); + this.btnStartStop.TabIndex = 4; + this.btnStartStop.Text = "Start"; + this.btnStartStop.UseVisualStyleBackColor = true; + this.btnStartStop.Click += new System.EventHandler(this.btnStartStop_Click); + // + // cboWebcams + // + this.cboWebcams.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left) + | System.Windows.Forms.AnchorStyles.Right))); + this.cboWebcams.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList; + this.cboWebcams.FormattingEnabled = true; + this.cboWebcams.Location = new System.Drawing.Point(140, 500); + this.cboWebcams.Margin = new System.Windows.Forms.Padding(4, 5, 4, 5); + this.cboWebcams.Name = "cboWebcams"; + this.cboWebcams.Size = new System.Drawing.Size(397, 28); + this.cboWebcams.TabIndex = 5; + // + // picWebcam + // + this.picWebcam.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom) + | System.Windows.Forms.AnchorStyles.Left) + | System.Windows.Forms.AnchorStyles.Right))); + this.picWebcam.BackColor = System.Drawing.Color.Black; + this.picWebcam.ImageShow = null; + this.picWebcam.Location = new System.Drawing.Point(18, 18); + this.picWebcam.Margin = new System.Windows.Forms.Padding(4, 5, 4, 5); + this.picWebcam.Name = "picWebcam"; + this.picWebcam.Size = new System.Drawing.Size(520, 472); + this.picWebcam.TabIndex = 0; + this.picWebcam.TabStop = false; + // + // FrmWebcam + // + this.AutoScaleDimensions = new System.Drawing.SizeF(9F, 20F); + this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + this.ClientSize = new System.Drawing.Size(558, 554); + this.Controls.Add(this.cboWebcams); + this.Controls.Add(this.btnStartStop); + this.Controls.Add(this.picWebcam); + this.Margin = new System.Windows.Forms.Padding(4, 5, 4, 5); + this.Name = "FrmWebcam"; + this.Text = "Webcam"; + this.FormClosed += new System.Windows.Forms.FormClosedEventHandler(this.FrmWebcam_FormClosed); + this.Load += new System.EventHandler(this.FrmWebcam_Load); + ((System.ComponentModel.ISupportInitialize)(this.picWebcam)).EndInit(); + this.ResumeLayout(false); + + } + + #endregion + + private VAR.Toolbox.Controls.CtrImageViewer picWebcam; + private System.Windows.Forms.Button btnStartStop; + private System.Windows.Forms.ComboBox cboWebcams; + } +} \ No newline at end of file diff --git a/VAR.Toolbox/UI/FrmWebcam.cs b/VAR.Toolbox/UI/FrmWebcam.cs new file mode 100644 index 0000000..b7926c1 --- /dev/null +++ b/VAR.Toolbox/UI/FrmWebcam.cs @@ -0,0 +1,98 @@ +using System; +using System.Collections.Generic; +using System.Drawing; +using System.Linq; +using System.Windows.Forms; +using VAR.Toolbox.Code; + +namespace VAR.Toolbox +{ + public partial class FrmWebcam : Form + { + private Webcam webcam = null; + + public FrmWebcam() + { + InitializeComponent(); + } + + private void FrmWebcam_Load(object sender, EventArgs e) + { + cboWebcams_LoadData(); + } + + void webcam_NewFrame(object sender, Bitmap frame) + { + picWebcam.ImageShow = frame; + } + + private void FrmWebcam_FormClosed(object sender, FormClosedEventArgs e) + { + if(webcam!=null){ + webcam.Stop(); + } + } + + private void btnStartStop_Click(object sender, EventArgs e) + { + if (webcam == null) + { + InitWebcam(); + } + if (webcam != null) + { + if (webcam.Active) + { + webcam.Stop(); + btnStartStop.Text = "Start"; + picWebcam.ImageShow = null; + webcam = null; + } + else + { + webcam.Start(); + btnStartStop.Text = "Stop"; + } + } + } + + private void InitWebcam() + { + if (cboWebcams.SelectedIndex < 0) { return; } + WebcamObject webcamObject = (WebcamObject)cboWebcams.SelectedItem; + webcam = new Webcam(webcamObject.Moniker); + webcam.NewFrame += webcam_NewFrame; + } + + private class WebcamObject + { + public string Name; + public string Moniker; + + public override string ToString() + { + return Name; + } + }; + + private void cboWebcams_LoadData() + { + try + { + Dictionary devices = Webcam.ListDevices(); + foreach (KeyValuePair pair in devices) + { + cboWebcams.Items.Add(new WebcamObject { Name = pair.Key, Moniker = pair.Value }); + } + if (cboWebcams.Items.Count > 0) + { + cboWebcams.SelectedIndex = 0; + } + } + catch (Exception) + { + cboWebcams.Items.Clear(); + } + } + } +} diff --git a/VAR.Toolbox/UI/FrmWebcam.resx b/VAR.Toolbox/UI/FrmWebcam.resx new file mode 100644 index 0000000..7080a7d --- /dev/null +++ b/VAR.Toolbox/UI/FrmWebcam.resx @@ -0,0 +1,120 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + \ No newline at end of file diff --git a/VAR.Toolbox/VAR.Toolbox.csproj b/VAR.Toolbox/VAR.Toolbox.csproj index 99f844c..092126b 100644 --- a/VAR.Toolbox/VAR.Toolbox.csproj +++ b/VAR.Toolbox/VAR.Toolbox.csproj @@ -22,6 +22,7 @@ DEBUG;TRACE prompt 4 + true AnyCPU @@ -46,6 +47,40 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Component + Form @@ -71,6 +106,12 @@ True Settings.settings + + Form + + + FrmWebcam.cs + @@ -82,6 +123,9 @@ FrmToolbox.cs + + FrmWebcam.cs +