diff --git a/Sources/Video.DirectShow/Internals/IAMVideoProcAmp.cs b/Sources/Video.DirectShow/Internals/IAMVideoProcAmp.cs new file mode 100644 index 00000000..002ba8db --- /dev/null +++ b/Sources/Video.DirectShow/Internals/IAMVideoProcAmp.cs @@ -0,0 +1,44 @@ +// AForge Direct Show Library +// AForge.NET framework +// http://www.aforgenet.com/framework/ +// +// Copyright © AForge.NET, 2009-2011 +// contacts@aforgenet.com +// + +namespace AForge.Video.DirectShow.Internals +{ + using System; + using System.Runtime.InteropServices; + + [ComImport, System.Security.SuppressUnmanagedCodeSecurity, + Guid("C6E13360-30AC-11d0-A18C-00A0C9118956"), + InterfaceType(ComInterfaceType.InterfaceIsIUnknown)] + public interface IAMVideoProcAmp + { + [PreserveSig] + int GetRange( + [In] VideoProcAmpProperty Property, + [Out] out int pMin, + [Out] out int pMax, + [Out] out int pSteppingDelta, + [Out] out int pDefault, + [Out] out VideoProcAmpFlags pCapsFlags + ); + + [PreserveSig] + int Set( + [In] VideoProcAmpProperty Property, + [In] int lValue, + [In] VideoProcAmpFlags Flags + ); + + [PreserveSig] + int Get( + [In] VideoProcAmpProperty Property, + [Out] out int lValue, + [Out] out VideoProcAmpFlags Flags + ); + } + +} diff --git a/Sources/Video.DirectShow/VideoCaptureDevice.cs b/Sources/Video.DirectShow/VideoCaptureDevice.cs index d2ba52fe..086fda93 100644 --- a/Sources/Video.DirectShow/VideoCaptureDevice.cs +++ b/Sources/Video.DirectShow/VideoCaptureDevice.cs @@ -971,6 +971,171 @@ public bool GetCameraPropertyRange( CameraControlProperty property, out int minV return ret; } + /// + /// Sets a specified property on the video. + /// + /// + /// Specifies the property to set. + /// Specifies the new value of the property. + /// Specifies the desired control setting. + /// + /// Returns true on sucee or false otherwise. + /// + /// Video source is not specified - device moniker is not set. + /// Failed creating device object for moniker. + /// The video source does not support video control. + /// + public bool SetVideoProperty(VideoProcAmpProperty property, int value, VideoProcAmpFlags controlFlags) + { + bool ret = true; + + // check if source was set + if ((deviceMoniker == null) || (string.IsNullOrEmpty(deviceMoniker))) + { + throw new ArgumentException("Video source is not specified."); + } + + lock (sync) + { + object tempSourceObject = null; + + // create source device's object + try + { + tempSourceObject = FilterInfo.CreateFilter(deviceMoniker); + } + catch + { + throw new ApplicationException("Failed creating device object for moniker."); + } + + if (!(tempSourceObject is IAMVideoProcAmp)) + { + throw new NotSupportedException("The video source does not support video control."); + } + + IAMVideoProcAmp pCamControl = (IAMVideoProcAmp)tempSourceObject; + int hr = pCamControl.Set(property, value, controlFlags); + + ret = (hr >= 0); + + Marshal.ReleaseComObject(tempSourceObject); + } + + return ret; + } + + /// + /// Gets the current setting of a video property. + /// + /// + /// Specifies the property to retrieve. + /// Receives the value of the property. + /// Receives the value indicating whether the setting is controlled manually or automatically + /// + /// Returns true on sucee or false otherwise. + /// + /// Video source is not specified - device moniker is not set. + /// Failed creating device object for moniker. + /// The video source does not support video control. + /// + public bool GetVideoProperty(VideoProcAmpProperty property, out int value, out VideoProcAmpFlags controlFlags) + { + bool ret = true; + + // check if source was set + if ((deviceMoniker == null) || (string.IsNullOrEmpty(deviceMoniker))) + { + throw new ArgumentException("Video source is not specified."); + } + + lock (sync) + { + object tempSourceObject = null; + + // create source device's object + try + { + tempSourceObject = FilterInfo.CreateFilter(deviceMoniker); + } + catch + { + throw new ApplicationException("Failed creating device object for moniker."); + } + + if (!(tempSourceObject is IAMVideoProcAmp)) + { + throw new NotSupportedException("The video source does not support video control."); + } + + IAMVideoProcAmp pCamControl = (IAMVideoProcAmp)tempSourceObject; + int hr = pCamControl.Get(property, out value, out controlFlags); + + ret = (hr >= 0); + + Marshal.ReleaseComObject(tempSourceObject); + } + + return ret; + } + + /// + /// Gets the range and default value of a specified video 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 enumeration, indicating whether the property is controlled automatically or manually. + /// + /// Returns true on sucee or false otherwise. + /// + /// Video source is not specified - device moniker is not set. + /// Failed creating device object for moniker. + /// The video source does not support video control. + /// + public bool GetVideoPropertyRange(VideoProcAmpProperty property, out int minValue, out int maxValue, out int stepSize, out int defaultValue, out VideoProcAmpFlags controlFlags) + { + bool ret = true; + + // check if source was set + if ((deviceMoniker == null) || (string.IsNullOrEmpty(deviceMoniker))) + { + throw new ArgumentException("Video source is not specified."); + } + + lock (sync) + { + object tempSourceObject = null; + + // create source device's object + try + { + tempSourceObject = FilterInfo.CreateFilter(deviceMoniker); + } + catch + { + throw new ApplicationException("Failed creating device object for moniker."); + } + + if (!(tempSourceObject is IAMVideoProcAmp)) + { + throw new NotSupportedException("The video source does not support video control."); + } + + IAMVideoProcAmp pCamControl = (IAMVideoProcAmp)tempSourceObject; + int hr = pCamControl.GetRange(property, out minValue, out maxValue, out stepSize, out defaultValue, out controlFlags); + + ret = (hr >= 0); + + Marshal.ReleaseComObject(tempSourceObject); + } + + return ret; + } + /// /// Worker thread. /// diff --git a/Sources/Video.DirectShow/VideoProcAmpProperty.cs b/Sources/Video.DirectShow/VideoProcAmpProperty.cs new file mode 100644 index 00000000..61f4609d --- /dev/null +++ b/Sources/Video.DirectShow/VideoProcAmpProperty.cs @@ -0,0 +1,83 @@ +using System; +using System.Collections.Generic; +using System.Text; + +namespace AForge.Video.DirectShow +{ + + /// + /// From VideoProcAmpProperty + /// + public enum VideoProcAmpProperty + { + /// + /// + /// + Brightness, + + /// + /// + /// + Contrast, + + /// + /// + /// + Hue, + + /// + /// + /// + Saturation, + + /// + /// + /// + Sharpness, + + /// + /// + /// + Gamma, + + /// + /// + /// + ColorEnable, + + /// + /// + /// + WhiteBalance, + + /// + /// + /// + BacklightCompensation, + + /// + /// + /// + Gain + } + + /// + /// From VideoProcAmpFlags + /// + [Flags] + public enum VideoProcAmpFlags + { + /// + /// No control flag. + /// + None = 0x0, + /// + /// Auto control Flag. + /// + Auto = 0x0001, + /// + /// Manual control Flag. + /// + Manual = 0x0002 + } +}