-
Notifications
You must be signed in to change notification settings - Fork 35
Added CameraControlProperty interface #64
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
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,13 @@ | ||
| namespace FlashCap | ||
| { | ||
| public enum CameraControlProperty | ||
| { | ||
| Pan = 0, | ||
| Tilt, | ||
| Roll, | ||
| Zoom, | ||
| Exposure, | ||
| Iris, | ||
| Focus | ||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -15,6 +15,7 @@ | |
| using System.Runtime.InteropServices; | ||
| using System.Threading; | ||
| using System.Threading.Tasks; | ||
| using static FlashCap.Internal.NativeMethods_DirectShow; | ||
|
|
||
| namespace FlashCap.Devices; | ||
|
|
||
|
|
@@ -40,12 +41,14 @@ public void ResetFrameIndex() => | |
| this.frameIndex = 0; | ||
|
|
||
| // whichMethodToCallback: 0 | ||
| [PreserveSig] public int SampleCB( | ||
| [PreserveSig] | ||
| public int SampleCB( | ||
| double sampleTime, NativeMethods_DirectShow.IMediaSample sample) => | ||
| unchecked((int)0x80004001); // E_NOTIMPL | ||
|
|
||
| // whichMethodToCallback: 1 | ||
| [PreserveSig] public int BufferCB( | ||
| [PreserveSig] | ||
| public int BufferCB( | ||
| double sampleTime, IntPtr pBuffer, int bufferLen) | ||
| { | ||
| // HACK: Avoid stupid camera devices... | ||
|
|
@@ -75,6 +78,7 @@ [PreserveSig] public int BufferCB( | |
| private NativeMethods_DirectShow.IGraphBuilder? graphBuilder; | ||
| private SampleGrabberSink? sampleGrabberSink; | ||
| private IntPtr pBih; | ||
| private IAMCameraControl cameraControl; | ||
|
|
||
| #pragma warning disable CS8618 | ||
| internal DirectShowDevice(object identity, string name) : | ||
|
|
@@ -183,6 +187,20 @@ protected override Task OnInitializeAsync( | |
|
|
||
| /////////////////////////////// | ||
|
|
||
| Guid PinCategory_Capture = new(0xfb6c4281, 0x0353, 0x11d1, 0x90, 0x5f, 0x00, 0x00, 0xc0, 0xcc, 0x16, 0xba); | ||
| Guid MediaType_Interleaved = new(0x73766169, 0x0000, 0x0010, 0x80, 0x00, 0x00, 0xaa, 0x00, 0x38, 0x9b, 0x71); | ||
| if (captureGraphBuilder.FindInterface(PinCategory_Capture, MediaType_Interleaved, captureSource, typeof(IAMCameraControl).GUID, out object? intf) < 0) | ||
|
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Unfortunately, the |
||
| { | ||
| // Maybe there are cameras that don't have a camera control interface? | ||
| throw new ArgumentException($"FlashCap: Couldn't get camera control interface: DevicePath={devicePath}"); | ||
| } | ||
| if (intf != null) | ||
| { | ||
| cameraControl = (IAMCameraControl)intf; | ||
| } | ||
|
|
||
| /////////////////////////////// | ||
|
|
||
| if (captureGraphBuilder.RenderStream( | ||
| in NativeMethods_DirectShow.PIN_CATEGORY_CAPTURE, | ||
| in NativeMethods_DirectShow.MEDIATYPE_Video, | ||
|
|
@@ -320,4 +338,15 @@ protected override void OnCapture( | |
| long timestampMicroseconds, long frameIndex, | ||
| PixelBuffer buffer) => | ||
| buffer.CopyIn(this.pBih, pData, size, timestampMicroseconds, frameIndex, this.transcodeIfYUV); | ||
|
|
||
| protected override void SetControlProperty(CameraControlProperty property, int value) | ||
| { | ||
| lock (this) | ||
| { | ||
| if (this.IsRunning) | ||
| { | ||
| cameraControl.Set(property, value, CameraControlFlags.None); | ||
|
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This call to |
||
| } | ||
| } | ||
| } | ||
| } | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
NOTE: This seems to expose the raw definition of DirectShow. Perhaps there is a better way to define it, considering multi-platform. But for now I think this is fine as it is; we may change it when we consider making it V4L2 compliant.