3

I'm developing a UVC utility that uses WebUSB, but I'm having trouble getting it to list out ONLY webcams. I should be able to add filters based on deviceClass and deviceSubClass, but it's returning an empty list.

Here's a webcam device...

0: USBDevice
configuration: USBConfiguration {configurationName: null, configurationValue: 1, interfaces: Array(5)}
configurations: [USBConfiguration]
deviceClass: 239
deviceProtocol: 1
deviceSubclass: 2
deviceVersionMajor: 1
deviceVersionMinor: 1
deviceVersionSubminor: 3
manufacturerName: "Microsoft"
opened: false
productId: 1906
productName: "Microsoft® LifeCam Studio(TM)"
serialNumber: ""
usbVersionMajor: 2
usbVersionMinor: 0
usbVersionSubminor: 0
vendorId: 1118

You can see deviceClass is 239 (0xEF), and the deviceSubClass is 2, so I should be able to filter on these criteria, but I'm not getting any results back.

https://www.xmos.com/download/AN00127:-USB-Video-Class-Device(2.0.2rc1).pdf

For Video class device, it is mandatory to set the ‘bDeviceClass’, ‘bDeviceSubClass’ and ‘bDeviceProtocol’ fields to 0xEF, 0x02 and 0x01 respectively.

const opts = {
  filters: [{
    classCode: 239, // 0xEF
    subclassCode: 2, // 0x02
  }]
}
const device = await navigator.usb.requestDevice(opts)

enter image description here

Without filters, I can see all of the USB devices

enter image description here

I have also tried adding protocolCode, but that doesn't work either, and I don't think it's necessary. Even passing only the classCode field returns an empty list.

WebUSB API spec

posit labs
  • 8,951
  • 4
  • 36
  • 66
  • What platform are you running on? You fill find that on most platforms the operating system prevents the browser from claiming a UVC USB interface directly because the default class driver has already claimed it. Visit chrome://usb-internals to see what class code the browser has detected for the device. – Reilly Grant Jun 29 '19 at 20:13
  • I'm on Chrome / MacOS. I can get the device if I don't specify the filters, but that's not an ideal UX flow because of all of the other USB junk that shows up. The class code and subclass code match the info on chrome://usb-internals – posit labs Jun 29 '19 at 21:05
  • This is a fools errand. Chrome blocks access to webcams via usb... https://stackoverflow.com/questions/54289929/usb-device-interface-has-been-blocked – posit labs Jun 29 '19 at 22:24
  • This is true (sorry for not mentioning that in my previous question) however as an editor on the WebUSB specification and author of the implementation in Chrome I'd like to know what use case you have for wanting to use this camera with WebUSB. Perhaps there is an existing web API (or an improvement to one) that will achieve what you are looking for. – Reilly Grant Jun 30 '19 at 18:59
  • I just want to control camera settings, e.g. contrast, exposure, etc. There is a vaporware web API (https://developer.mozilla.org/en-US/docs/Web/API/MediaDevices/getSupportedConstraints) that I've been trying to use for years, but I think implementation is slow, so I was trying to access this stuff via USB/UVC. – posit labs Jul 01 '19 at 16:23

1 Answers1

3

I have filed issue 980281 against Chromium to resolve the device filtering problem.

As discussed in the comments it will be difficult to get direct control over a UVC camera because operating systems typically claim these devices with kernel drivers, blocking the web browser. Blink also explicitly blocks access to this class of devices as a security/privacy measure in favor of using the web platform media APIs.

The author of the question is looking for the ability to control parameters such as contrast and exposure. These are supported by extensions to the media track constrainable properties included in the Image Capture API. However, not all of these capabilities are supported by browsers on all platforms. For example, Chromium does not support many constraints on macOS as it is constrained by what can be controlled via AVFoundation. This is tracked by issue 817805 in the Chromium bug tracker.

Reilly Grant
  • 5,590
  • 1
  • 13
  • 23
  • 1
    Thanks for filing that bug report and clearing this up for me. Until the extensions are implemented, I will be working on this UVC lib https://github.com/makenai/node-uvc-control – posit labs Jul 02 '19 at 13:51