feat: add cross-platform libuvc UVC camera support (Linux + Windows) - #83
feat: add cross-platform libuvc UVC camera support (Linux + Windows)#83mathieucarbou wants to merge 6 commits into
Conversation
1244005 to
2d82463
Compare
|
Tested on macos ✅ |
Introduce libuvc-based UVC camera detection and control on Linux and
Windows, alongside the existing V4l2 and DShow paths (kept for testing).
New files:
- Services/LinuxCameraDetect.cs — scans /sys/class/video4linux/, walks
sysfs to find USB idVendor/idProduct, returns APIType.Uvc cameras
- Services/WindowsUvcCameraDetect.cs — uses SetupAPI to enumerate USB
Video Class (CC_VIDEO=0x0E) devices, extracts VID/PID from hardware IDs
- Libraries/libusb/win/{x64,arm64}/build.sh — download libusb-1.0.dll
via vcpkg at build time
Changes:
- CameraControlService: dispatch Set/SetAuto/GetCameraList to the new
LinuxCameraDetect or WindowsUvcCameraDetect for APIType.Uvc cameras
- UvcFrameSource.OpenDevice: guard macOS IOKit kernel driver detach
with OperatingSystem.IsMacOS(); skip it on Linux/Windows
- UvcFrameSource.CloseDevice, TryRecoverUvcDevice: macOS-only kernel
driver restore
- CollimationCircles.csproj: add CopyLibUsbWin, CopyLibUvcWin,
CopyLibUvcLinux MSBuild targets
- .github/workflows/build-and-release.yml: copy libusb + libuvc
binaries on Windows and Linux during publish
refactor: standardize UVC file naming and extract macOS UVC detection
- Rename LinuxCameraDetect.cs → UvcCameraDetectLinux.cs
- Rename WindowsUvcCameraDetect.cs → UvcCameraDetectWindows.cs
- Create UvcCameraDetectMac.cs in Services/Uvc/ with UVC-specific
detection (system_profiler VID/PID parsing) and control routing
- Update MacOSCameraDetect.cs to only handle QTCapture cameras
(UVC cameras now detected by UvcCameraDetectMac)
- Update CameraControlService.cs to use new class names and add
macOS UVC detection via UvcCameraDetectMac
2d82463 to
a757bd3
Compare
|
@sajmons : this PR is in draft because still a work in progress (need to remove V4L2 code and libvlc), but would you be able to test on your end before the removal? |
|
@mathieucarbou I have made a small fix for detecting UVC cameras on Windows with libusb. |
Ok! I will do some deeper testing with VMs. The problem is that libuvc compilation for windows produces a small dll of about 11ko which is just a stub and exports nothing. So there is something wrong in the compilation. |
f2e2733 to
22f5737
Compare
22f5737 to
a744220
Compare
Introduce libuvc-based UVC camera detection and control on Linux and
Windows, alongside the existing V4l2 and DShow paths (kept for testing).
New files:
- Services/LinuxCameraDetect.cs — scans /sys/class/video4linux/, walks
sysfs to find USB idVendor/idProduct, returns APIType.Uvc cameras
- Services/WindowsUvcCameraDetect.cs — uses SetupAPI to enumerate USB
Video Class (CC_VIDEO=0x0E) devices, extracts VID/PID from hardware IDs
- Libraries/libusb/win/{x64,arm64}/build.sh — download libusb-1.0.dll
via vcpkg at build time
Changes:
- CameraControlService: dispatch Set/SetAuto/GetCameraList to the new
LinuxCameraDetect or WindowsUvcCameraDetect for APIType.Uvc cameras
- UvcFrameSource.OpenDevice: guard macOS IOKit kernel driver detach
with OperatingSystem.IsMacOS(); skip it on Linux/Windows
- UvcFrameSource.CloseDevice, TryRecoverUvcDevice: macOS-only kernel
driver restore
- CollimationCircles.csproj: add CopyLibUsbWin, CopyLibUvcWin,
CopyLibUvcLinux MSBuild targets
- .github/workflows/build-and-release.yml: copy libusb + libuvc
binaries on Windows and Linux during publish
refactor: standardize UVC file naming and extract macOS UVC detection
- Rename LinuxCameraDetect.cs → UvcCameraDetectLinux.cs
- Rename WindowsUvcCameraDetect.cs → UvcCameraDetectWindows.cs
- Create UvcCameraDetectMac.cs in Services/Uvc/ with UVC-specific
detection (system_profiler VID/PID parsing) and control routing
- Update MacOSCameraDetect.cs to only handle QTCapture cameras
(UVC cameras now detected by UvcCameraDetectMac)
- Update CameraControlService.cs to use new class names and add
macOS UVC detection via UvcCameraDetectMac
a744220 to
051cdea
Compare
@SimonSander : where is your fix btw ? I don't see any commit on main or in this branch ? |
|
@SimonSander FYI, I am currently working on fixing the libuvc github workflow for windows thanks to these refs:
Apparently people have succeeded with MingW. |
|
@SimonSander CI tasks now can build libuvc for win correctly with MingW. See: https://github.com/sajmons/CollimationCircles/actions/workflows/build-libuvc.yml I have updated the libs in main branch. |
2fc220d to
ef6d438
Compare
Introduce libuvc-based UVC camera detection and control on Linux and
Windows, alongside the existing V4l2 and DShow paths (kept for testing).
New files:
- Services/LinuxCameraDetect.cs — scans /sys/class/video4linux/, walks
sysfs to find USB idVendor/idProduct, returns APIType.Uvc cameras
- Services/WindowsUvcCameraDetect.cs — uses SetupAPI to enumerate USB
Video Class (CC_VIDEO=0x0E) devices, extracts VID/PID from hardware IDs
- Libraries/libusb/win/{x64,arm64}/build.sh — download libusb-1.0.dll
via vcpkg at build time
Changes:
- CameraControlService: dispatch Set/SetAuto/GetCameraList to the new
LinuxCameraDetect or WindowsUvcCameraDetect for APIType.Uvc cameras
- UvcFrameSource.OpenDevice: guard macOS IOKit kernel driver detach
with OperatingSystem.IsMacOS(); skip it on Linux/Windows
- UvcFrameSource.CloseDevice, TryRecoverUvcDevice: macOS-only kernel
driver restore
- CollimationCircles.csproj: add CopyLibUsbWin, CopyLibUvcWin,
CopyLibUvcLinux MSBuild targets
- .github/workflows/build-and-release.yml: copy libusb + libuvc
binaries on Windows and Linux during publish
refactor: standardize UVC file naming and extract macOS UVC detection
- Rename LinuxCameraDetect.cs → UvcCameraDetectLinux.cs
- Rename WindowsUvcCameraDetect.cs → UvcCameraDetectWindows.cs
- Create UvcCameraDetectMac.cs in Services/Uvc/ with UVC-specific
detection (system_profiler VID/PID parsing) and control routing
- Update MacOSCameraDetect.cs to only handle QTCapture cameras
(UVC cameras now detected by UvcCameraDetectMac)
- Update CameraControlService.cs to use new class names and add
macOS UVC detection via UvcCameraDetectMac
ef6d438 to
b638ae4
Compare
|
@SimonSander : I have updated this branch. # refresh git repo metadata
> git fetch
# set your local branch content to origin/feature/libuvc
> git reset --hard origin/feature/libuvcThe DLL is loading correctly but I get no stream: This is the classic Windows problem described in issues #12 and #136. The DLL works correctly (uvc_init succeeds, uvc_find_device finds the camera), but uvc_open fails with ERROR_NOT_FOUND because the default Windows UVC driver has exclusive access to the camera's USB interfaces. On macOS we detach the kernel driver via IOKit, on Linux libusb detaches the driver automatically, but on Windows you must manually replace the driver using Zadig: Download Zadig However, the camera will no longer be available in other Windows applications (OBS, Camera app, etc.) as long as the WinUSB driver is installed. This is a fundamental limitation of Windows — not a code bug. It is documented in the pupil-labs/pyuvc WINDOWS_USER.md and in all the libuvc Windows issues. This driver replacement is not possible on ARM64 since there is no arm drivers for that. => So I propose we leave this PR as draft, we leave the issue open, we only use UVC camera support throuhg libuvc on macOS since this is the only ways to have UVC cameras working on macOS. Side note: on windoss arm64 I am not able to open cameras with DShow also: That being done, my next step will be to tryout the new added features features in v5 during next time I will collimate. |
|
@mathieucarbou when referencing me, please use @sajmons not @SimonSander. Thank you! |
There was a problem hiding this comment.
💡 Codex Review
https://github.com/sajmons/CollimationCircles/blob/b638ae4a367cf5396a275170a258ed1f50c24d98/Services/Uvc/UvcCameraDetectWindows.cs#L160
Preserve distinct devices with the same VID/PID
When two physical UVC cameras of the same model are connected on Windows, they share the same vendor/product IDs, so this check drops every camera after the first even though instanceId was just collected as a per-device path. That leaves users unable to select the second camera from the UVC list; de-duplication should use the device instance/interface identity instead of only VID/PID.
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| 'linux-x64' { | ||
| Copy-Item -Force './CollimationCircles/Libraries/ASI_linux_mac_SDK_V1.41/lib/x64/libASICamera2.so*' $output | ||
| # Copy libuvc for UVC camera control and streaming via libuvc on Linux | ||
| Copy-Item -Force './CollimationCircles/Libraries/libuvc/linux/x64/libuvc.so' $output |
There was a problem hiding this comment.
Bundle libusb with Linux libuvc artifacts
For the Linux release artifacts this copies only libuvc.so, but the checked-in Linux libuvc.so has a dynamic NEEDED dependency on libusb-1.0.so.0 (I verified with readelf -d, and ldd reports it as not found in this environment). On systems without a system libusb package, the first DllImport("libuvc") will fail before any UVC camera can open, so the self-contained Linux builds won't actually provide the new UVC path unless libusb is packaged or libuvc is linked statically.
Useful? React with 👍 / 👎.
…onCircles into feature/libuvc
Fixes #78.
This PR adds support using cameras with libuvc for streaming and control on all platforms.
This PR does not yet remove the existing libvlc (V4L2) camera detect code but just adds on top of it camera support through libuvc so that features can be compared.
So all UVC cameras should be seen several times in the list, and even maybe 3 times on Windows with DxShow.
Example on macOS: UVC camera is discovered through the avcapture (QT) system and through libuvc, but the controls are different.
with macOS AVFoundation:
with libuvc: