Skip to content

Add a UVC extension project for Unix and Windows#56

Open
tmittet wants to merge 28 commits into
mainfrom
add_project_and_test_scaffolding_for_an_UVC_extension_2
Open

Add a UVC extension project for Unix and Windows#56
tmittet wants to merge 28 commits into
mainfrom
add_project_and_test_scaffolding_for_an_UVC_extension_2

Conversation

@tmittet
Copy link
Copy Markdown
Owner

@tmittet tmittet commented Sep 1, 2025

An updated version of #49, the difference is mainly that standard control request has also been moved to the extensions project.

Original PR description:
This is a suggested template for how we can do USB device class specific extensions. Let me know what you think.

The idea is that the integrator can get access to an extension, simply by adding e.g. using LibUsbSharp.Extensions.Uvc; to their implementation. This pattern can be reused for future extensions and we can choose to put each (or very large) extensions in completely separate projects and thereby separate Nuget packages.

I think this keeps a clear separation between the core project and extensions.

Adds a new UsbDotNet.Extensions.Uvc project providing cross-platform USB Video Class (UVC) control support, along with integration tests.

New addtions last 30 days:

  • Extension methods (UsbDeviceExtension) - ControlReadUvc, ControlWriteUvc, and most importantly OpenUvcControl to access the platform-agnostic UVC API
  • IUvcControl interface; a platform-agnostic API for reading/writing UVC camera and image processing controls (brightness, contrast, exposure, white balance, zoom, etc.)
  • Linux/macOS implementation (UnixUvcControl) - uses libusb UVC control transfers directly
  • UVC descriptor parsing (UsbDeviceDescriptorExtension) to reads UVC unit/node descriptors from USB device configuration to resolve entity IDs automatically; mainly for the Unix implementation
  • Windows implementation (WindowsUvcControl) - uses DirectShow and Kernel Streaming via P/Invoke
  • Integration tests covering control reads/writes for camera and image processing controls against real USB video devices
  • CI build step added for the new extensions project

Design decisions:

  • IUvcControl returns UsbResult for soft errors instead of throwing exceptions, aligning with the existing UsbDotNet error handling pattern
  • Entity ID (unit/node) is resolved internally from descriptors - per the USB spec, duplicate GUIDs on an interface aren't possible, so callers don't need to provide entity IDs

pkhansen
pkhansen previously approved these changes Sep 3, 2025
Copy link
Copy Markdown
Collaborator

@pkhansen pkhansen left a comment

Choose a reason for hiding this comment

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

I prefer this way of doing it as the sort of baseline for uvc control requests. I think there is room for more convenience, but that should be at a higher level anyway.
Tests are a-okay on mac

Comment thread src/LibUsbSharp.Extensions/ControlTransfer/Uvc/UsbDeviceExtension.cs Outdated
@tmittet tmittet force-pushed the add_project_and_test_scaffolding_for_an_UVC_extension_2 branch from cceec5a to 7b94699 Compare September 4, 2025 08:01
@tmittet tmittet changed the base branch from main to add_a_LibUsbSharp.Extensions_project_and_move_standard_control_request_implementation September 4, 2025 08:01
@tmittet
Copy link
Copy Markdown
Owner Author

tmittet commented Sep 4, 2025

I've addressed your comments @pkhansen and split this PR into: #59 and this draft PR.

We could merge this PR too, after adding e.g. if (OperatingSystem.IsWindows()) throw new SkipException("UVC control requests inaccessible on Windows.") to the UVC tests.

@tmittet tmittet mentioned this pull request Sep 4, 2025
Base automatically changed from add_a_LibUsbSharp.Extensions_project_and_move_standard_control_request_implementation to main September 4, 2025 15:42
@tmittet tmittet force-pushed the add_project_and_test_scaffolding_for_an_UVC_extension_2 branch 2 times, most recently from 4986e0f to 7983a2f Compare January 19, 2026 13:00
Copilot AI review requested due to automatic review settings January 19, 2026 13:00
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR adds scaffolding for a UVC (USB Video Class) extension project, enabling device class-specific functionality through extension methods. The extension allows developers to interact with UVC devices using simplified APIs by importing using UsbDotNet.Extensions.ControlTransfer.Uvc.

Changes:

  • Introduced ControlRequestUvc enum defining UVC-specific control request codes
  • Added extension methods ControlReadUvc and ControlWriteUvc for simplified UVC device communication
  • Created comprehensive test coverage for UVC control read/write operations

Reviewed changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated 2 comments.

File Description
UsbDotNet.Extensions.Tests.csproj Added project reference to UsbDotNet.Core to support test infrastructure
Given_a_video_class_USB_device_with_UVC.cs Added test class with read/write tests for UVC brightness control
UsbDeviceExtension.cs Implemented extension methods for UVC control transfers
ControlRequestUvc.cs Defined enum of UVC control request codes with detailed documentation

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread src/UsbDotNet.Extensions.Uvc/UsbDeviceExtension.cs Outdated
Comment thread src/UsbDotNet.Extensions.Uvc/UsbDeviceExtension.cs Outdated
@tmittet tmittet force-pushed the add_project_and_test_scaffolding_for_an_UVC_extension_2 branch from 7983a2f to e411c06 Compare January 19, 2026 15:12
@tmittet tmittet force-pushed the main branch 3 times, most recently from 2b3dd7b to f967b1c Compare March 7, 2026 08:22
@tmittet tmittet force-pushed the add_project_and_test_scaffolding_for_an_UVC_extension_2 branch from e411c06 to de1b1db Compare March 11, 2026 06:40
@tmittet tmittet force-pushed the add_project_and_test_scaffolding_for_an_UVC_extension_2 branch from 9d98a82 to 89f3a5c Compare March 29, 2026 14:59
@tmittet tmittet marked this pull request as ready for review March 29, 2026 15:01
@tmittet tmittet changed the title Add project and test scaffolding for an uvc extension 2 Add a UVC extension project for Unix and Windows Mar 29, 2026
@tmittet tmittet force-pushed the add_project_and_test_scaffolding_for_an_UVC_extension_2 branch 2 times, most recently from 1f4e0ac to 89b37d1 Compare April 13, 2026 19:07
tmittet added 19 commits April 27, 2026 10:37
it was poorly structured and hard to read
type, and move it to the root of the UVC extension project
The entityId is completely redundant. According to the USB spec, having
multiple nodes/units with the same GUID on a USB interface is not
possible. Hence, we can always resolve the unit/node ID internally.
and fix issues uncovered by tests
for all "soft" errors. This aligns UvcControls error handling with other
extensions like ControlRead, ControlWrite, ControlReadUvc and
ControlWriteUvc.
Type names should not be plural.
Most of the calls will never throw that exception.
for slightly improved performance during concurrent read
@tmittet tmittet force-pushed the add_project_and_test_scaffolding_for_an_UVC_extension_2 branch from 89b37d1 to 48627c9 Compare April 27, 2026 08:51
@tmittet
Copy link
Copy Markdown
Owner Author

tmittet commented Apr 27, 2026

Rebased on main and resolved conflicts

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.

3 participants