makenai / node-uvc-control

Control UVC compliant USB webcams from node
80 stars 28 forks source link

Setting UVCC autoWhiteBalance to 0 Getting LIBUSB_ERROR_IO #58

Open mesalagagan opened 5 years ago

mesalagagan commented 5 years ago

sudo uvcc devices

Optical Mouse [ vId: 0x458  / pId: 0x3a  ]
USB Keyboard [ vId: 0x4d9  / pId: 0x1702  ]
EHCI Host Controller [ vId: 0x1d6b  / pId: 0x2  ]
EHCI Host Controller [ vId: 0x1d6b  / pId: 0x2  ]
USB 2.0 Camera [ vId: 0xc45  / pId: 0x6366  ]

sudo uvcc --vendor 0xc45 --product 0x6366 set autoWhiteBalance 0

Error: LIBUSB_ERROR_IO

Screenshot from 2019-07-24 17-18-41

positlabs commented 5 years ago

I've seen IO error before, but it meant I didn't have permission to use the usb device.

joelpurra commented 5 years ago

@GaganMeesala: I can confirm the problem -- am also getting LIBUSB_ERROR_IO on ubuntu. The same webcam works on macOS without any issue. Looks like the problem isn't in uvcc though, but in upstream code. Perhaps a change in libusb's nodejs wrapper?

joelpurra commented 5 years ago

@positlabs: I've set permissions according to the (newly added) link in README.md, but it didn't fix this LIBUSB_ERROR_IO issue.

Note that the suggested fix is for LIBUSB_ERROR_ACCESS, not LIBUSB_ERROR_IO. Running as a superuser (in my case in a sudo su - shell) still gives LIBUSB_ERROR_IO. Looked through issues in node-usb, but didn't come up with anything substantial so far.

joelpurra commented 4 years ago

Did some more testing in ubuntu 19 with a c920 webcam.

Note: seems usb v1.6.0 is required in node v12.11.1 -- or at least it's more convenient as it uses prebuild.

Looking at the constants in uvc-control and usb, it seems (based on bmRequestType) that uvc-control reads/writes using a camera interface rather than the camera device. Writing to an interface (on linux) requires claiming ("locking"?) the interface first. While it is possible to do so when another application (or the kernel?) is using the webcam, it will basically kill their interface and sort of crash the camera so it can't be opened (for video) again. Unplugging/plugging in the device makes it usable again, although a software reset might also work.

I have pushed unfinished patches for the two "current" uvc-control versions.

Added various (temporary) branches in case you'd like to check them out already. Tested on ubuntu 19 and macos 10.14. Does it work for you @GaganMeesala, @positlabs?

Targeting the device in controlTransfer

You can install and run tests from the uvcc branches. Run ./index.js to use the local branch version and configure --verbose to see debug logs/warnings.

cd uvcc
rm -r node_modules
npm install
# NOTE: might need to configure your vendor/product.
./index.js --verbose export
./index.js --verbose ranges

v1-next

./index.js --verbose range absoluteZoom
./index.js --verbose get absoluteZoom
./index.js --verbose set absoluteZoom 150

v2-next

./index.js --verbose range absolute_zoom
./index.js --verbose get absolute_zoom
./index.js --verbose set absolute_zoom 150

Constant value debugging

Just getting the runtime values of constants, and printing numbers in decimal/binary/hexadecimal. Helped finding the interface/device fix.

Print constants to the console.

arielweinberger commented 4 years ago

@joelpurra Looking forward to the fix. Thanks for your effort.

joelpurra commented 4 years ago

Did anyone test the experimental branches so far? Might use the forked version of node-uvc-control to get uvcc running on linux, so a new version can be published on npm. It'd be nice to have someone else confirm the functionality first though.

joelpurra commented 4 years ago

See #64.

joelpurra commented 4 years ago

@gaganmesala: this should be fixed in uvcc v2.0.0, which was just released. Let me know if it works!