Repository navigation
Home
libuvc is a cross-platform library for USB video devices, built atop libusb. It enables fine-grained control over USB video devices exporting the standard USB Video Class (UVC) interface, enabling developers to write drivers for previously unsupported devices, or just access UVC devices in a generic fashion.
https://github.com/libusb/libusb/wiki/FAQ
How can I run libusb applications under macOS if there is already a kernel extension installed for the device and claim exclusive access?
If there is no existing kernel extension installed for the device, libusb will run out of the box, you do not even need to have root privilege and there is no need to set up udev rules like Linux. However, if there is an existing kernel extension (driver) installed for the device, then it is more troublesome.
Since version 1.0.25 libusb supports detaching kernel drivers with authorization (PR #911). Take note the underlying macOS capture APIs only work on the whole device and not on individual interfaces. So this will force all the kernel extensions (drivers) bound to all the interfaces of a USB Composite devices to be released (Issue #920). You will need to get the entitlement from Apple Developer support, create a provisioning profile with that entitlement, and build your app with that profile.
IMPORTANT Note: Please take note that command line apps cannot use provisioning profiles and therefore cannot hold this entitlement so you have to run as root. As for the GUI application, as of now Apple support is saying that com.apple.vm.device-access entitlement is not the right entitlement. So basically there is no solution as of now. This means libusb (and libraries like libuvc which uses libusb) may not be the right library to use if you hit this issue (Issue #972 and Issue #1014).
One potential workaround is to develop a command line helper to detach/attach the kernel driver (this helper will run with sudo). Then you can run the main GUI application as a normal user.
Specifically for UVC device, there is a way to override the default USB video class extension by creating a simple DriverKit extension to override the default driver-matching behavior for USB devices. https://developer.apple.com/documentation/coremediaio/overriding_the_default_usb_video_class_extension?language=objc
This may be possible as well for other USB devices. You may want to check with Apple.