Skip to content
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

Added CameraControlProperty interface #64

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open

Conversation

macaba
Copy link

@macaba macaba commented Jun 19, 2023

An implementation of the CameraControlProperty interface, only tested on DirectShow.

I needed this for a thermal camera where it uses the Zoom property in two ways: to switch frame data to raw thermal values (for further processing by the application), and to calibrate the camera (it has an internal shutter for calibration).

Example usage for the thermal camera:

this.captureDevice.SetControlProperty(CameraControlProperty.Zoom, 0x8000);    // 0x8000 = Calibrate
this.captureDevice.SetControlProperty(CameraControlProperty.Zoom, 0x8004);    // 0x8004 = Raw mode

This is incomplete however I wanted to create this PR to start some discussion about how this could be integrated into the main repo in a correct way.

@kekyo
Copy link
Owner

kekyo commented Jun 20, 2023

@macaba Thank you your PR!

I will review it within a couple of days, so please give me a moment.

Copy link
Owner

@kekyo kekyo left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would be willing to accept the points raised once they are corrected. Thanks for your contribution!

  • Please switch base branch develop instead of main.
  • I'll implement the F# support after the merge.

@@ -183,6 +187,20 @@ private sealed class SampleGrabberSink :

///////////////////////////////

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)
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unfortunately, the GUID property did not declare in netstandard1.3. So switch using self-declared field instead of it. Example and good place at IID_ICaptureGraphBuilder2 symbol.

@@ -0,0 +1,13 @@
namespace FlashCap
{
public enum CameraControlProperty
Copy link
Owner

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.

{
if (this.IsRunning)
{
cameraControl.Set(property, value, CameraControlFlags.None);
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This call to Set() corresponds to a cross-apartment call on COM interface, so a procedure over the apartment is required. Use this.workingContext.InvokeAsync() to ensure that it is called on the correct thread. The implementation of the OnStartAsync() method will be helpful.
Perhaps it needs to be asynchronized, like SetControlPropertyAsync().

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants