Skip to content

Add set video features. #27

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 44 additions & 0 deletions Sources/Video.DirectShow/Internals/IAMVideoProcAmp.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
// AForge Direct Show Library
// AForge.NET framework
// http://www.aforgenet.com/framework/
//
// Copyright © AForge.NET, 2009-2011
// [email protected]
//

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
);
}

}
165 changes: 165 additions & 0 deletions Sources/Video.DirectShow/VideoCaptureDevice.cs
Original file line number Diff line number Diff line change
Expand Up @@ -971,6 +971,171 @@ public bool GetCameraPropertyRange( CameraControlProperty property, out int minV
return ret;
}

/// <summary>
/// Sets a specified property on the video.
/// </summary>
///
/// <param name="property">Specifies the property to set.</param>
/// <param name="value">Specifies the new value of the property.</param>
/// <param name="controlFlags">Specifies the desired control setting.</param>
///
/// <returns>Returns true on sucee or false otherwise.</returns>
///
/// <exception cref="ArgumentException">Video source is not specified - device moniker is not set.</exception>
/// <exception cref="ApplicationException">Failed creating device object for moniker.</exception>
/// <exception cref="NotSupportedException">The video source does not support video control.</exception>
///
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;
}

/// <summary>
/// Gets the current setting of a video property.
/// </summary>
///
/// <param name="property">Specifies the property to retrieve.</param>
/// <param name="value">Receives the value of the property.</param>
/// <param name="controlFlags">Receives the value indicating whether the setting is controlled manually or automatically</param>
///
/// <returns>Returns true on sucee or false otherwise.</returns>
///
/// <exception cref="ArgumentException">Video source is not specified - device moniker is not set.</exception>
/// <exception cref="ApplicationException">Failed creating device object for moniker.</exception>
/// <exception cref="NotSupportedException">The video source does not support video control.</exception>
///
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;
}

/// <summary>
/// Gets the range and default value of a specified video property.
/// </summary>
///
/// <param name="property">Specifies the property to query.</param>
/// <param name="minValue">Receives the minimum value of the property.</param>
/// <param name="maxValue">Receives the maximum value of the property.</param>
/// <param name="stepSize">Receives the step size for the property.</param>
/// <param name="defaultValue">Receives the default value of the property.</param>
/// <param name="controlFlags">Receives a member of the <see cref="VideoProcAmpFlags"/> enumeration, indicating whether the property is controlled automatically or manually.</param>
///
/// <returns>Returns true on sucee or false otherwise.</returns>
///
/// <exception cref="ArgumentException">Video source is not specified - device moniker is not set.</exception>
/// <exception cref="ApplicationException">Failed creating device object for moniker.</exception>
/// <exception cref="NotSupportedException">The video source does not support video control.</exception>
///
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;
}

/// <summary>
/// Worker thread.
/// </summary>
Expand Down
83 changes: 83 additions & 0 deletions Sources/Video.DirectShow/VideoProcAmpProperty.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
using System;
using System.Collections.Generic;
using System.Text;

namespace AForge.Video.DirectShow
{

/// <summary>
/// From VideoProcAmpProperty
/// </summary>
public enum VideoProcAmpProperty
{
/// <summary>
///
/// </summary>
Brightness,

/// <summary>
///
/// </summary>
Contrast,

/// <summary>
///
/// </summary>
Hue,

/// <summary>
///
/// </summary>
Saturation,

/// <summary>
///
/// </summary>
Sharpness,

/// <summary>
///
/// </summary>
Gamma,

/// <summary>
///
/// </summary>
ColorEnable,

/// <summary>
///
/// </summary>
WhiteBalance,

/// <summary>
///
/// </summary>
BacklightCompensation,

/// <summary>
///
/// </summary>
Gain
}

/// <summary>
/// From VideoProcAmpFlags
/// </summary>
[Flags]
public enum VideoProcAmpFlags
{
/// <summary>
/// No control flag.
/// </summary>
None = 0x0,
/// <summary>
/// Auto control Flag.
/// </summary>
Auto = 0x0001,
/// <summary>
/// Manual control Flag.
/// </summary>
Manual = 0x0002
}
}