├── .gitignore ├── img └── usbprobe.png ├── test ├── supported-controls.js ├── still-image.js ├── set-arg-spread.js ├── discover.js ├── get.js ├── get-info.js ├── get-defaults.js ├── defaults.js ├── vid.js ├── range.js ├── vid-pid.js └── vid-pid-deviceaddress.js ├── package.json ├── examples ├── server.js └── index.html ├── README.md ├── lib ├── constants.js └── controls.js └── index.js /.gitignore: -------------------------------------------------------------------------------- 1 | node_modules 2 | scratch 3 | -------------------------------------------------------------------------------- /img/usbprobe.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/makenai/node-uvc-control/HEAD/img/usbprobe.png -------------------------------------------------------------------------------- /test/supported-controls.js: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env node 2 | 3 | const UVCControl = require('../index') 4 | const cam = new UVCControl() 5 | console.log(cam.supportedControls) 6 | -------------------------------------------------------------------------------- /test/still-image.js: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env node 2 | 3 | 4 | const UVCControl = require('../index') 5 | const cam = new UVCControl() 6 | 7 | const name = 'still_image_trigger' 8 | const trigger = UVCControl.controls[name] 9 | // cam.set(name, trigger.fields[0].options.TRANSMIT_BULK) 10 | -------------------------------------------------------------------------------- /test/set-arg-spread.js: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env node 2 | 3 | const UVCControl = require('../index') 4 | const cam = new UVCControl() 5 | 6 | const pan = 34 7 | const tilt = 27 8 | cam.set('absolute_pan_tilt', pan, tilt) 9 | .then(val => console.log('set absolute_pan_tilt to', val)) 10 | .catch(err => console.error(err)) 11 | -------------------------------------------------------------------------------- /test/discover.js: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env node 2 | 3 | /* 4 | List UVC devices 5 | */ 6 | 7 | const UVCControl = require('../index') 8 | 9 | UVCControl.discover().then(results => { 10 | results.forEach(result => { 11 | console.log({ 12 | name: result.name, 13 | vendorId: result.deviceDescriptor.idVendor, 14 | productId: result.deviceDescriptor.idProduct, 15 | deviceAddress: result.deviceAddress, 16 | }) 17 | }) 18 | }).catch(err => console.error(err)) 19 | -------------------------------------------------------------------------------- /test/get.js: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env node 2 | 3 | const UVCControl = require('../index') 4 | const cam = new UVCControl() 5 | const name = process.argv[2] || 'all' 6 | let controlNames = [name] 7 | if (name === 'all') { 8 | controlNames = cam.supportedControls.filter(name => { 9 | return UVCControl.controls[name].requests.indexOf(UVCControl.REQUEST.GET_CUR) !== -1 10 | }) 11 | } 12 | controlNames.forEach(name => { 13 | cam.get(name).then(def => { 14 | console.log('current', name, def) 15 | }).catch(err => console.log(err)) 16 | }) 17 | -------------------------------------------------------------------------------- /test/get-info.js: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env node 2 | 3 | const UVCControl = require('../index') 4 | const cam = new UVCControl() 5 | const name = process.argv[2] || 'all' 6 | let controlNames = [name] 7 | 8 | if (name === 'all') { 9 | controlNames = cam.supportedControls.filter(name => { 10 | return UVCControl.controls[name].requests.indexOf(UVCControl.REQUEST.GET_INFO) !== -1 11 | }) 12 | } 13 | 14 | controlNames.map(name => { 15 | cam.getInfo(name).then(info => { 16 | console.log(name, info) 17 | }).catch(err => console.log(err)) 18 | }) 19 | -------------------------------------------------------------------------------- /test/get-defaults.js: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env node 2 | 3 | const UVCControl = require('../index') 4 | const cam = new UVCControl() 5 | const name = process.argv[2] || 'all' 6 | let controlNames = [name] 7 | if (name === 'all') { 8 | controlNames = cam.supportedControls.filter(name => { 9 | return UVCControl.controls[name].requests.indexOf(UVCControl.REQUEST.GET_DEF) !== -1 10 | }) 11 | } 12 | controlNames.forEach(name => { 13 | cam.getDefault(name).then(def => { 14 | console.log('default', name, def) 15 | }).catch(err => console.log(err)) 16 | }) 17 | -------------------------------------------------------------------------------- /test/defaults.js: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env node 2 | 3 | /* 4 | List default values 5 | */ 6 | 7 | const UVCControl = require('../index') 8 | const cam = new UVCControl() 9 | const supportedControls = cam.supportedControls.filter(name => { 10 | const control = UVCControl.controls[name] 11 | return control.requests.indexOf(UVCControl.REQUEST.GET_DEF) !== -1 12 | }) 13 | console.log(supportedControls) 14 | const run = async () => { 15 | supportedControls.forEach((name) => { 16 | cam.getDefault(name) 17 | .then(def => console.log(def)) 18 | .catch(err => console.error(err)) 19 | }) 20 | } 21 | run() 22 | -------------------------------------------------------------------------------- /test/vid.js: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env node 2 | 3 | /* 4 | Get a device based on vendor ID 5 | These values can be found by running ./discover.js 6 | 7 | Usage: ./test/vid.js 1133 8 | */ 9 | 10 | const UVCControl = require('../index') 11 | const vid = parseInt(process.argv[2]) || 1133 12 | 13 | const cam = new UVCControl({ 14 | vid: vid 15 | }) 16 | 17 | if (cam.device.deviceDescriptor.idVendor !== vid) console.error(`Input vendor ID (${vid}) does not match device vendor ID (${cam.device.deviceDescriptor.idVendor})`) 18 | 19 | console.log(cam) 20 | 21 | UVCControl.controls.map(name => { 22 | cam.get(name, (err, val) => { 23 | if (err) throw err 24 | console.log(name, val) 25 | }) 26 | }) 27 | -------------------------------------------------------------------------------- /test/range.js: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env node 2 | 3 | const UVCControl = require('../index') 4 | const cam = new UVCControl() 5 | const name = process.argv[2] || 'all' 6 | let controlNames = [name] 7 | if (name === 'all') { 8 | controlNames = cam.supportedControls.filter(name => { 9 | return UVCControl.controls[name].requests.indexOf(UVCControl.REQUEST.GET_MIN) !== -1 10 | }) 11 | } 12 | console.log('controls with range support:', controlNames) 13 | controlNames.forEach((name, i) => { 14 | // setTimeout(() => { 15 | // console.log('getting range for', name) 16 | cam.range(name).then(def => { 17 | console.log('range', name, def) 18 | }).catch(err => console.log(name, err)) 19 | // }, i * 1000) 20 | }) 21 | -------------------------------------------------------------------------------- /test/vid-pid.js: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env node 2 | 3 | /* 4 | Get a device based on vendor ID and product ID 5 | These values can be found by running ./discover.js 6 | 7 | Usage: ./test/vid-pid.js 1133 2142 8 | */ 9 | 10 | const UVCControl = require('../index') 11 | const vid = parseInt(process.argv[2]) || 1133 12 | const pid = parseInt(process.argv[3]) || 2142 13 | 14 | const cam = new UVCControl({ 15 | vid: vid, 16 | pid: pid 17 | }) 18 | 19 | if (cam.device.deviceDescriptor.idVendor !== vid) console.error(`Input vendor ID (${vid}) does not match device vendor ID (${cam.device.deviceDescriptor.idVendor})`) 20 | if (cam.device.deviceDescriptor.idProduct !== pid) console.error(`Input product ID (${pid}) does not match device vendor ID (${cam.device.deviceDescriptor.idProduct})`) 21 | 22 | console.log(cam) 23 | 24 | UVCControl.controls.map(name => { 25 | cam.get(name, (err, val) => { 26 | if (err) throw err 27 | console.log(name, val) 28 | }) 29 | }) 30 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "uvc-control", 3 | "version": "2.0.0", 4 | "description": "Control UVC compliant webcams from node", 5 | "main": "index.js", 6 | "scripts": { 7 | "preview": "node ./examples/server.js" 8 | }, 9 | "repository": { 10 | "type": "git", 11 | "url": "git+https://github.com/makenai/node-uvc-control.git" 12 | }, 13 | "keywords": [ 14 | "webcam", 15 | "uvc", 16 | "quickcam", 17 | "logitech", 18 | "lifecam", 19 | "usb", 20 | "c920" 21 | ], 22 | "author": "Pawel Szymczykowski ", 23 | "contributors": [ 24 | "Josh Beckwith (https://github.com/positlabs/)" 25 | ], 26 | "license": "ISC", 27 | "bugs": { 28 | "url": "https://github.com/makenai/node-uvc-control/issues" 29 | }, 30 | "homepage": "https://github.com/makenai/node-uvc-control#readme", 31 | "dependencies": { 32 | "usb": "^1.1.2" 33 | }, 34 | "engines": { 35 | "node": ">=8" 36 | }, 37 | "devDependencies": { 38 | "express": "^4.17.1", 39 | "serve": "^11.0.2" 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /test/vid-pid-deviceaddress.js: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env node 2 | 3 | /* 4 | Get a device based on vendor ID, product ID, and device address. 5 | Useful if using multiple of the same webcam 6 | These values can be found by running ./discover.js 7 | 8 | Usage: ./test/vid-pid-deviceaddress.js 1133 2142 25 9 | */ 10 | 11 | const UVCControl = require('../index') 12 | const vid = parseInt(process.argv[2]) || 1133 13 | const pid = parseInt(process.argv[3]) || 2142 14 | const deviceAddress = parseInt(process.argv[4]) || 25 15 | 16 | const cam = new UVCControl({ 17 | vid: vid, 18 | pid: pid, 19 | deviceAddress: deviceAddress 20 | }) 21 | 22 | if (cam.device.deviceDescriptor.idVendor !== vid) console.error(`Input vendor ID (${vid}) does not match device vendor ID (${cam.device.deviceDescriptor.idVendor})`) 23 | if (cam.device.deviceDescriptor.idProduct !== pid) console.error(`Input product ID (${pid}) does not match device vendor ID (${cam.device.deviceDescriptor.idProduct})`) 24 | if (cam.device.deviceAddress !== deviceAddress) console.error(`Input device address (${deviceAddress}) does not match device address (${cam.device.deviceAddress})`) 25 | 26 | console.log(cam) 27 | 28 | UVCControl.controls.map(name => { 29 | cam.get(name).then(val => console.log(name, val)) 30 | }) 31 | -------------------------------------------------------------------------------- /examples/server.js: -------------------------------------------------------------------------------- 1 | const express = require('express') 2 | const app = express() 3 | const port = 3000 4 | const UVCControl = require('../index') 5 | const cam = new UVCControl() 6 | 7 | app.get('/', (req, res) => { 8 | res.sendFile(__dirname + '/index.html') 9 | }) 10 | 11 | app.get('/supported-controls', (req, res) => { 12 | res.send(cam.supportedControls) 13 | }) 14 | 15 | app.get('/get/:control', (req, res) => { 16 | cam.get(req.params.control) 17 | .then(val => res.send(val)) 18 | .catch(err => { 19 | console.error(err) 20 | res.status(500).send(err) 21 | }) 22 | }) 23 | 24 | app.get('/describe/:control', (req, res) => { 25 | const controlDescription = UVCControl.controls[req.params.control] 26 | controlDescription ? res.send(controlDescription) : res.status(500).send({ 27 | error: `No control named ${req.params.control}` 28 | }) 29 | }) 30 | 31 | app.get('/range/:control', (req, res) => { 32 | cam.range(req.params.control) 33 | .then(range => res.send(range)) 34 | .catch(err => { 35 | console.error(err) 36 | res.status(500).send(err) 37 | }) 38 | }) 39 | 40 | app.post('/set/:control/:values', (req, res) => { 41 | let values = req.params.values.split(',') 42 | console.log('setting', req.params.control, values) 43 | cam.set(req.params.control, ...values).then(vals => { 44 | res.send('ok') 45 | }).catch(err => { 46 | console.error(err) 47 | res.status(500).send(err) 48 | }) 49 | }) 50 | 51 | app.listen(port, () => console.log(`Example app listening on port ${port}!`)) 52 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # uvc-control 2 | 3 | Control a USB Video Class compliant webcam from node. Most modern USB webcams use a common set of controls standardized by the USB Implementers Forum. You can use this set of controls to change certain things on the camera, such as the brightness, contrast, zoom level, focus and so on. 4 | 5 | See also [`uvcc`](https://github.com/joelpurra/uvcc), which wraps uvc-control in a command line tool. 6 | 7 | ## Example 8 | 9 | ```javascript 10 | const UVCControl = require('uvc-control') 11 | 12 | // get the first camera by default 13 | const camera = new UVCControl() 14 | // or get a specific camera 15 | const camera = new UVCControl({vid: 0x046d, pid: 0x082d}) 16 | 17 | camera.get('autoFocus').then(value) => console.log('AutoFocus setting:', value)) 18 | camera.set('brightness', 100).then(() => console.log('Brightness set!')) 19 | ``` 20 | 21 | For an interactive demo, run `npm run serve` and open http://localhost:3000. 22 | 23 | ## Finding Your vendorId / productId 24 | 25 | Use test/discover.js to find the right paramters. 26 | 27 | ``` 28 | $ node test/discover.js 29 | [ { name: 'Logitech BRIO', 30 | vendorId: 1133, 31 | productId: 2142, 32 | deviceAddress: 7 }, 33 | { name: 'Microsoft® LifeCam Studio(TM)', 34 | vendorId: 1118, 35 | productId: 1906, 36 | deviceAddress: 22 } ] 37 | ``` 38 | 39 | ## Installation 40 | 41 | Libusb is included as a submodule. 42 | 43 | On Linux, you'll need libudev to build libusb. On Ubuntu/Debian: `sudo apt-get install build-essential libudev-dev` 44 | 45 | On Windows, use [Zadig](https://sourceforge.net/projects/libwdi/files/zadig/) to install the WinUSB driver. 46 | 47 | Then, just run `npm install uvc-control` 48 | 49 | 50 | ## API 51 | 52 | ```javascript 53 | const UVCControl = require('uvc-control') 54 | ``` 55 | 56 | ### new UVCControl(options) 57 | 58 | * **options** - object containing options 59 | * **options.vid** - vendor id of your device 60 | * **options.pid** - product id of your device 61 | * **options.deviceAddress** - device address 62 | 63 | ```javaScript 64 | const camera = new UVCControl(options) 65 | ``` 66 | 67 | ### List controls 68 | 69 | Log the names of controls. You can get all controls, or a list of controls supported by the device. 70 | 71 | ```javascript 72 | UVCControl.controls.forEach(name => console.log(name)) 73 | console.log(cam.supportedControls) 74 | ``` 75 | 76 | ### camera.get( control_name ) 77 | 78 | Get the current value of the specified control by name. 79 | 80 | ```javascript 81 | camera.get('sharpness').then(value => console.log('sharpness', value)) 82 | ``` 83 | 84 | ### camera.range( control_name ) 85 | 86 | Get the min and max value of the specified control by name. Some controls do not support this method. 87 | 88 | ```javascript 89 | camera.range('absolute_focus').then(range => { 90 | console.log(range) // { min: 0, max: 250 } 91 | }) 92 | ``` 93 | 94 | ### camera.set( control_name, value ) 95 | 96 | Set the value of the specified control by name. 97 | 98 | ```javascript 99 | camera.set('saturation', 100).then(() => console.log('saturation set!')) 100 | ``` 101 | 102 | ### camera.set( control_name, ...values ) 103 | 104 | Some controls have multiple fields. You can pass multiple values that align with the field offsets. 105 | 106 | ```javascript 107 | const pan = 34 108 | const tilt = 27 109 | camera.set('absolute_pan_tilt', pan, tilt).then(() => { 110 | console.log('absolute_pan_tilt set!') 111 | }) 112 | ``` 113 | 114 | ### camera.close() 115 | 116 | Done? Good. Put away your toys and release the USB device. 117 | 118 | ```javascript 119 | camera.close() 120 | ``` 121 | 122 | ### Notes 123 | 124 | You can find the full list of specs at the USB Implmentors Forum. Look for a document called *USB Device Class Definition for Video Devices Revision 1.1* at their site here: [http://www.usb.org/developers/docs/devclass_docs/](http://www.usb.org/developers/docs/devclass_docs/) [pdf mirror](http://www.cajunbot.com/wiki/images/8/85/USB_Video_Class_1.1.pdf) 125 | 126 | To debug the USB descriptors, open chrome://usb-internals in Chrome 127 | 128 | On Raspberry Pi, you need to run node as root in order to access USB devices. If you don't have access, you'll get a `LIBUSB_ERROR_IO` error on initialization. Alternatively, you can add a udev rule to grant access to the default user, as described in [this AskUbuntu answer](https://askubuntu.com/questions/978552/how-do-i-make-libusb-work-as-non-root). 129 | 130 | Pull requests and testers welcome! 131 | 132 | ### Credits 133 | 134 | Written by [Pawel Szymczykowski](http://twitter.com/makenai) and based on some Objective C examples by [Dominic Szablewski](https://twitter.com/phoboslab) found at [http://phoboslab.org/log/2009/07/uvc-camera-control-for-mac-os-x](http://phoboslab.org/log/2009/07/uvc-camera-control-for-mac-os-x). Maintained by [Josh Beckwith](https://github.com/positlabs). 135 | -------------------------------------------------------------------------------- /lib/constants.js: -------------------------------------------------------------------------------- 1 | const KEY = { 2 | scanning_mode: 'scanning_mode', 3 | auto_exposure_mode: 'auto_exposure_mode', 4 | auto_exposure_priority: 'auto_exposure_priority', 5 | absolute_exposure_time: 'absolute_exposure_time', 6 | relative_exposure_time: 'relative_exposure_time', 7 | absolute_focus: 'absolute_focus', 8 | relative_focus: 'relative_focus', 9 | absolute_iris: 'absolute_iris', 10 | relative_iris: 'relative_iris', 11 | absolute_zoom: 'absolute_zoom', 12 | relative_zoom: 'relative_zoom', 13 | absolute_pan_tilt: 'absolute_pan_tilt', 14 | relative_pan_tilt: 'relative_pan_tilt', 15 | absolute_roll: 'absolute_roll', 16 | relative_roll: 'relative_roll', 17 | auto_focus: 'auto_focus', 18 | privacy: 'privacy', 19 | brightness: 'brightness', 20 | contrast: 'contrast', 21 | hue: 'hue', 22 | saturation: 'saturation', 23 | sharpness: 'sharpness', 24 | gamma: 'gamma', 25 | white_balance_temperature: 'white_balance_temperature', 26 | white_balance_component: 'white_balance_component', 27 | backlight_compensation: 'backlight_compensation', 28 | gain: 'gain', 29 | power_line_frequency: 'power_line_frequency', 30 | auto_hue: 'auto_hue', 31 | auto_white_balance_temperature: 'auto_white_balance_temperature', 32 | auto_white_balance_component: 'auto_white_balance_component', 33 | digital_multiplier: 'digital_multiplier', 34 | digital_multiplier_limit: 'digital_multiplier_limit', 35 | analog_video_standard: 'analog_video_standard', 36 | analog_lock_status: 'analog_lock_status', 37 | NONE: 'NONE', 38 | NTSC_525_60: 'NTSC_525_60', 39 | PAL_625_50: 'PAL_625_50', 40 | SECAM_625_50: 'SECAM_625_50', 41 | NTSC_625_50: 'NTSC_625_50', 42 | PAL_525_60: 'PAL_525_60', 43 | } 44 | 45 | const FIELD_TYPE = { 46 | BOOLEAN: 'BOOLEAN', 47 | BITMAP: 'BITMAP', 48 | NUMBER: 'NUMBER', 49 | } 50 | 51 | const BM_REQUEST_TYPE = { 52 | GET: 0b10100001, 53 | SET: 0b00100001, 54 | } 55 | 56 | const CS = { 57 | UNDEFINED: 0x20, 58 | DEVICE: 0x21, 59 | CONFIGURATION: 0x22, 60 | STRING: 0x23, 61 | INTERFACE: 0x24, 62 | ENDPOINT: 0x25, 63 | } 64 | 65 | const REQUEST = { 66 | RC_UNDEFINED: 0x00, 67 | SET_CUR: 0x01, 68 | GET_CUR: 0x81, 69 | GET_MIN: 0x82, 70 | GET_MAX: 0x83, 71 | GET_RES: 0x84, 72 | GET_LEN: 0x85, 73 | GET_INFO: 0x86, 74 | GET_DEF: 0x87, 75 | } 76 | 77 | const VS = { 78 | UNDEFINED: 0x00, 79 | PROBE_CONTROL: 0x01, 80 | COMMIT_CONTROL: 0x02, 81 | STILL_PROBE_CONTROL: 0x03, 82 | STILL_COMMIT_CONTROL: 0x04, 83 | STILL_IMAGE_TRIGGER_CONTROL: 0x05, 84 | STREAM_ERROR_CODE_CONTROL: 0x06, 85 | GENERATE_KEY_FRAME_CONTROL: 0x07, 86 | UPDATE_FRAME_SEGMENT_CONTROL: 0x08, 87 | SYNCH_DELAY_CONTROL: 0x09, 88 | } 89 | 90 | // A.6. Video Class-Specific VS Interface Descriptor Subtypes 91 | const VS_DESCRIPTOR_SUBTYPE = { 92 | UNDEFINED: 0x00, 93 | INPUT_HEADER: 0x01, 94 | OUTPUT_HEADER: 0x02, 95 | STILL_IMAGE_FRAME: 0x03, 96 | FORMAT_UNCOMPRESSED: 0x04, 97 | FRAME_UNCOMPRESSED: 0x05, 98 | FORMAT_MJPEG: 0x06, 99 | FRAME_MJPEG: 0x07, 100 | FORMAT_MPEG2TS: 0x0A, 101 | FORMAT_DV: 0x0C, 102 | COLORFORMAT: 0x0D, 103 | FORMAT_FRAME_BASED: 0x10, 104 | FRAME_FRAME_BASED: 0x11, 105 | FORMAT_STREAM_BASED: 0x12, 106 | } 107 | 108 | const PU = { 109 | CONTROL_UNDEFINED: 0x00, 110 | BACKLIGHT_COMPENSATION_CONTROL: 0x01, 111 | BRIGHTNESS_CONTROL: 0x02, 112 | CONTRAST_CONTROL: 0x03, 113 | GAIN_CONTROL: 0x04, 114 | POWER_LINE_FREQUENCY_CONTROL: 0x05, 115 | HUE_CONTROL: 0x06, 116 | SATURATION_CONTROL: 0x07, 117 | SHARPNESS_CONTROL: 0x08, 118 | GAMMA_CONTROL: 0x09, 119 | WHITE_BALANCE_TEMPERATURE_CONTROL: 0x0A, 120 | WHITE_BALANCE_TEMPERATURE_AUTO_CONTROL: 0x0B, 121 | WHITE_BALANCE_COMPONENT_CONTROL: 0x0C, 122 | WHITE_BALANCE_COMPONENT_AUTO_CONTROL: 0x0D, 123 | DIGITAL_MULTIPLIER_CONTROL: 0x0E, 124 | DIGITAL_MULTIPLIER_LIMIT_CONTROL: 0x0F, 125 | HUE_AUTO_CONTROL: 0x10, 126 | ANALOG_VIDEO_STANDARD_CONTROL: 0x11, 127 | ANALOG_LOCK_STATUS_CONTROL: 0x12, 128 | } 129 | 130 | const CT = { 131 | CONTROL_UNDEFINED: 0x00, 132 | SCANNING_MODE_CONTROL: 0x01, 133 | AE_MODE_CONTROL: 0x02, 134 | AE_PRIORITY_CONTROL: 0x03, 135 | EXPOSURE_TIME_ABSOLUTE_CONTROL: 0x04, 136 | EXPOSURE_TIME_RELATIVE_CONTROL: 0x05, 137 | FOCUS_ABSOLUTE_CONTROL: 0x06, 138 | FOCUS_RELATIVE_CONTROL: 0x07, 139 | FOCUS_AUTO_CONTROL: 0x08, 140 | IRIS_ABSOLUTE_CONTROL: 0x09, 141 | IRIS_RELATIVE_CONTROL: 0x0A, 142 | ZOOM_ABSOLUTE_CONTROL: 0x0B, 143 | ZOOM_RELATIVE_CONTROL: 0x0C, 144 | PANTILT_ABSOLUTE_CONTROL: 0x0D, 145 | PANTILT_RELATIVE_CONTROL: 0x0E, 146 | ROLL_ABSOLUTE_CONTROL: 0x0F, 147 | ROLL_RELATIVE_CONTROL: 0x10, 148 | PRIVACY_CONTROL: 0x11, 149 | } 150 | 151 | const VC = { 152 | DESCRIPTOR_UNDEFINED: 0x00, 153 | HEADER: 0x01, 154 | INPUT_TERMINAL: 0x02, 155 | OUTPUT_TERMINAL: 0x03, 156 | SELECTOR_UNIT: 0x04, 157 | PROCESSING_UNIT: 0x05, 158 | EXTENSION_UNIT: 0x06, 159 | } 160 | 161 | const CC = { 162 | VIDEO: 0x0e, 163 | } 164 | 165 | const EP = { 166 | UNDEFINED: 0x00, 167 | GENERAL: 0x01, 168 | ENDPOINT: 0x02, 169 | INTERRUPT: 0x03, 170 | } 171 | 172 | const SC = { 173 | UNDEFINED: 0x00, 174 | VIDEOCONTROL: 0x01, 175 | VIDEOSTREAMING: 0x02, 176 | VIDEO_INTERFACE_COLLECTION: 0x03, 177 | } 178 | 179 | module.exports = { 180 | EP, 181 | SC, 182 | CC, 183 | VC, 184 | CT, 185 | CS, 186 | PU, 187 | VS, 188 | KEY, 189 | REQUEST, 190 | BM_REQUEST_TYPE, 191 | VS_DESCRIPTOR_SUBTYPE, 192 | FIELD_TYPE, 193 | } 194 | -------------------------------------------------------------------------------- /examples/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 34 | 35 | 36 | 37 | 38 | 39 |
40 | 41 |
42 |
43 | 199 | 200 | 201 | 202 | -------------------------------------------------------------------------------- /index.js: -------------------------------------------------------------------------------- 1 | const usb = require('usb') 2 | const { 3 | SC, 4 | CC, 5 | VC, 6 | CS, 7 | // VS, 8 | // VS_DESCRIPTOR_SUBTYPE, 9 | BM_REQUEST_TYPE, 10 | FIELD_TYPE, 11 | REQUEST, 12 | KEY, 13 | } = require('./lib/constants') 14 | const controls = require('./lib/controls') 15 | const EventEmitter = require('events').EventEmitter 16 | 17 | class UVCControl extends EventEmitter { 18 | 19 | constructor(options = {}) { 20 | super() 21 | this.options = options 22 | this.init() 23 | if (!this.device) throw Error('No device found, using options:', options) 24 | } 25 | 26 | init() { 27 | 28 | if (this.options.vid && this.options.pid && this.options.deviceAddress) { 29 | 30 | // find cam with vid / pid / deviceAddress 31 | this.device = usb.getDeviceList().filter((device) => { 32 | return isWebcam(device) && 33 | device.deviceDescriptor.idVendor === this.options.vid && 34 | device.deviceDescriptor.idProduct === this.options.pid && 35 | device.deviceAddress === this.options.deviceAddress 36 | })[0] 37 | 38 | } else if (this.options.vid && this.options.pid) { 39 | 40 | // find a camera that matches the vid / pid 41 | this.device = usb.getDeviceList().filter((device) => { 42 | return isWebcam(device) && 43 | device.deviceDescriptor.idVendor === this.options.vid && 44 | device.deviceDescriptor.idProduct === this.options.pid 45 | })[0] 46 | 47 | } else if (this.options.vid) { 48 | 49 | // find a camera that matches the vendor id 50 | this.device = usb.getDeviceList().filter((device) => { 51 | return isWebcam(device) && 52 | device.deviceDescriptor.idVendor === this.options.vid 53 | })[0] 54 | 55 | } else { 56 | 57 | // no options... use the first camera in the device list 58 | this.device = usb.getDeviceList().filter((device) => { 59 | return isWebcam(device) 60 | })[0] 61 | } 62 | 63 | if (this.device) { 64 | this.device.open() 65 | this.videoControlInterfaceNumber = detectVideoControlInterface(this.device) 66 | } 67 | 68 | const descriptors = getInterfaceDescriptors(this.device) 69 | this.ids = { 70 | processingUnit: descriptors.processingUnit.bUnitID, 71 | cameraInputTerminal: descriptors.cameraInputTerminal.bTerminalID, 72 | } 73 | 74 | this.supportedControls = descriptors.cameraInputTerminal.controls.concat(descriptors.processingUnit.controls) 75 | } 76 | 77 | getControlParams(id) { 78 | const control = controls[id] 79 | if (!control) { 80 | throw Error('UVC Control identifier not recognized: ' + id) 81 | } 82 | 83 | const controlType = { 84 | PU: 'processingUnit', 85 | CT: 'inputTerminal', 86 | // VS: 'videoStream', 87 | } [control.type] 88 | const unit = this.ids[controlType] 89 | // const unit = this.ids.processingUnit 90 | const params = { 91 | wValue: (control.selector << 8) | 0x00, 92 | wIndex: (unit << 8) | this.videoControlInterfaceNumber, 93 | wLength: control.wLength 94 | } 95 | return params 96 | } 97 | 98 | /** 99 | * Close the device 100 | */ 101 | close() { 102 | this.device.close() 103 | } 104 | 105 | /** 106 | * Get the value of a control 107 | * @param {string} controlName 108 | */ 109 | get(id) { 110 | const control = this.getControl(id) 111 | return new Promise((resolve, reject) => { 112 | const params = this.getControlParams(id) 113 | this.device.controlTransfer(BM_REQUEST_TYPE.GET, REQUEST.GET_CUR, params.wValue, params.wIndex, params.wLength, (error, buffer) => { 114 | if (error) return reject({ 115 | id, 116 | error 117 | }) 118 | const fields = {} 119 | control.fields.forEach(field => { 120 | // console.log(field.name, field.offset, field.size, buffer.byteLength) 121 | // sometimes the field doesn't take up the space it has 122 | const size = Math.min(field.size, buffer.byteLength) 123 | // sometimes the field isn't there...? 124 | if (field.offset === field.size) return 125 | fields[field.name] = buffer.readIntLE(field.offset, size) 126 | }) 127 | resolve(fields) 128 | }) 129 | }) 130 | } 131 | 132 | getInfo(id) { 133 | // check if control can actually make the request 134 | const control = this.getControl(id) 135 | if (control.requests.indexOf(REQUEST.GET_INFO) === -1) { 136 | throw Error(`GET_INFO request is not supported for ${id} on this device.`) 137 | } 138 | 139 | return new Promise((resolve, reject) => { 140 | const params = this.getControlParams(id) 141 | this.device.controlTransfer(BM_REQUEST_TYPE.GET, REQUEST.GET_INFO, params.wValue, params.wIndex, params.wLength, (error, buffer) => { 142 | if (error) return reject({ 143 | id, 144 | error 145 | }) 146 | const bm = bitmask(buffer.readIntLE(0, buffer.byteLength)) 147 | const info = { 148 | // D0 Supports GET value requests Capability 149 | get: Boolean(bm[0]), 150 | // D1 Supports SET value requests Capability 151 | set: Boolean(bm[1]), 152 | // D2 Disabled due to automatic mode (under device control) State 153 | disabled: Boolean(bm[2]), 154 | // D3 Autoupdate Control (see section 2.4.2.2 "Status Interrupt Endpoint") 155 | autoUpdate: Boolean(bm[3]), 156 | // D4 Asynchronous Control (see sections 2.4.2.2 "Status Interrupt Endpoint" and 2.4.4, “Control Transfer and Request Processing”) 157 | async: Boolean(bm[3]), 158 | } 159 | resolve(info) 160 | }) 161 | }) 162 | } 163 | 164 | getDefault(id) { 165 | // check if control can actually make the request 166 | const control = this.getControl(id) 167 | if (control.requests.indexOf(REQUEST.GET_DEF) === -1) { 168 | throw Error(`GET_DEF request is not supported for ${id} on this device.`) 169 | } 170 | 171 | return new Promise((resolve, reject) => { 172 | const params = this.getControlParams(id) 173 | this.device.controlTransfer(BM_REQUEST_TYPE.GET, REQUEST.GET_DEF, params.wValue, params.wIndex, params.wLength, (error, buffer) => { 174 | if (error) return reject({ 175 | id, 176 | error 177 | }) 178 | 179 | // parse based on fields offset/size 180 | const fieldDefaults = {} 181 | control.fields.forEach(field => { 182 | // NOTE min fixes out of bounds error, but this approach doesn't account for multiple fields... 183 | let int = buffer.readIntLE(field.offset, Math.min(buffer.byteLength, field.size)) 184 | let result = int 185 | if (field.type === FIELD_TYPE.BOOLEAN) { 186 | result = Boolean(int) 187 | } 188 | const results = { 189 | value: result, 190 | } 191 | try { 192 | // FIXME: what do we do with negative numbers in bitmaps?? 193 | // if (field.options && field.type !== 'Bitmap') { 194 | results.optionKey = Object.entries(field.options).filter(([key, val]) => { 195 | return val === result 196 | })[0][0] 197 | // } 198 | } catch (e) {} 199 | fieldDefaults[field.name] = results 200 | }) 201 | 202 | resolve(fieldDefaults) 203 | }) 204 | }) 205 | } 206 | 207 | getControl(id) { 208 | const control = controls[id] 209 | if (!control) throw Error(`No control named ${id}`) 210 | return control 211 | } 212 | 213 | /** 214 | * Set the value of a control 215 | * @param {string} controlId 216 | * @param {number} ...values 217 | */ 218 | set(id, ...values) { 219 | return new Promise((resolve, reject) => { 220 | const control = this.getControl(id) 221 | const params = this.getControlParams(id) 222 | const data = Buffer.alloc(params.wLength) 223 | control.fields.forEach((field, i) => { 224 | data.writeIntLE(values[i], field.offset, field.size) 225 | }) 226 | 227 | this.device.controlTransfer(BM_REQUEST_TYPE.SET, REQUEST.SET_CUR, params.wValue, params.wIndex, data, (err) => { 228 | if (err) reject(err) 229 | else resolve(values) 230 | }) 231 | }) 232 | } 233 | /** 234 | * Get the min and max range of a control 235 | * @param {string} controlName 236 | */ 237 | range(id) { 238 | const control = controls[id] 239 | if (control.requests.indexOf(REQUEST.GET_MIN) === -1) { 240 | throw Error('range request not supported for ', id) 241 | } 242 | 243 | return new Promise((resolve, reject) => { 244 | const params = this.getControlParams(id) 245 | const byteLength = 2 246 | // TODO support controls with multiple fields 247 | // TODO promise wrapper for controlTransfer so we can do parallel requests 248 | this.device.controlTransfer(BM_REQUEST_TYPE.GET, REQUEST.GET_MIN, params.wValue, params.wIndex, byteLength, (error, min) => { 249 | if (error) return reject(error) 250 | this.device.controlTransfer(BM_REQUEST_TYPE.GET, REQUEST.GET_MAX, params.wValue, params.wIndex, byteLength, (error, max) => { 251 | if (error) return reject(error) 252 | resolve({ 253 | min: min.readIntLE(0, byteLength), 254 | max: max.readIntLE(0, byteLength), 255 | }) 256 | }) 257 | }) 258 | }) 259 | } 260 | } 261 | 262 | /* 263 | Class level stuff 264 | */ 265 | 266 | UVCControl.controls = controls 267 | UVCControl.REQUEST = REQUEST 268 | 269 | /** 270 | * Discover uvc devices 271 | */ 272 | UVCControl.discover = () => { 273 | return new Promise((resolve, reject) => { 274 | var promises = usb.getDeviceList().map(UVCControl.validate) 275 | Promise.all(promises).then(results => { 276 | resolve(results.filter(w => w)) // rm nulls 277 | }).catch(err => reject(err)) 278 | }) 279 | } 280 | 281 | /** 282 | * Check if device is a uvc device 283 | * @param {object} device 284 | */ 285 | UVCControl.validate = (device) => { 286 | return new Promise((resolve, reject) => { 287 | 288 | if (device.deviceDescriptor.iProduct) { 289 | device.open() 290 | 291 | // http://www.usb.org/developers/defined_class/#BaseClass10h 292 | if (isWebcam(device)) { 293 | device.getStringDescriptor(device.deviceDescriptor.iProduct, (error, deviceName) => { 294 | if (error) return reject(error) 295 | device.close() 296 | device.name = deviceName 297 | resolve(device) 298 | }) 299 | } else resolve(false) 300 | } else resolve(false) 301 | }) 302 | } 303 | 304 | /** 305 | * Given a USB device, iterate through all of the exposed interfaces looking for the one for VideoControl. 306 | * @param {object} device 307 | * @return {object} interface 308 | */ 309 | function detectVideoControlInterface(device) { 310 | const { 311 | interfaces 312 | } = device 313 | for (let i = 0; i < interfaces.length; i++) { 314 | if (interfaces[i].descriptor.bInterfaceClass == CC.VIDEO && 315 | interfaces[i].descriptor.bInterfaceSubClass == SC.VIDEOCONTROL 316 | ) { 317 | return i 318 | } 319 | } 320 | } 321 | 322 | /** 323 | * Check the device descriptor and assert that it is a webcam 324 | * @param {object} device 325 | * @return {Boolean} 326 | */ 327 | function isWebcam(device) { 328 | return device.deviceDescriptor.bDeviceClass === 0xef && 329 | device.deviceDescriptor.bDeviceSubClass === 0x02 && 330 | device.deviceDescriptor.bDeviceProtocol === 0x01 331 | } 332 | 333 | function getInterfaceDescriptors(device) { 334 | // find the VC interface 335 | // VC Interface Descriptor is a concatenation of all the descriptors that are used to fully describe 336 | // the video function, i.e., all Unit Descriptors (UDs) and Terminal Descriptors (TDs) 337 | const vcInterface = device.interfaces.filter(interface => { 338 | const { 339 | descriptor 340 | } = interface 341 | return descriptor.bInterfaceClass === CC.VIDEO && 342 | descriptor.bInterfaceSubClass === SC.VIDEOCONTROL 343 | })[0] 344 | 345 | // parse the descriptors in the extra field 346 | let data = vcInterface.descriptor.extra.toJSON().data 347 | let descriptorArrays = [] 348 | while (data.length) { 349 | let bLength = data[0] 350 | let arr = data.splice(0, bLength) 351 | descriptorArrays.push(arr) 352 | } 353 | 354 | // Table 3-6 Camera Terminal Descriptor 355 | const cameraInputTerminalDescriptor = descriptorArrays.filter(arr => arr[1] === CS.INTERFACE && arr[2] === VC.INPUT_TERMINAL)[0] 356 | const cITDBuffer = Buffer.from(cameraInputTerminalDescriptor) 357 | let bControlSize = cITDBuffer.readIntLE(14, 1) 358 | let bmControls = bitmask(cITDBuffer.readIntLE(15, bControlSize)) 359 | const cameraInputTerminal = { 360 | bTerminalID: cITDBuffer.readIntLE(3, 1), 361 | wObjectiveFocalLengthMin: cITDBuffer.readIntLE(8, 2), 362 | wObjectiveFocalLengthMax: cITDBuffer.readIntLE(10, 2), 363 | wOcularFocalLength: cITDBuffer.readIntLE(12, 2), 364 | controls: [ 365 | KEY.scanning_mode, 366 | KEY.auto_exposure_mode, 367 | KEY.auto_exposure_priority, 368 | KEY.absolute_exposure_time, 369 | KEY.relative_exposure_time, 370 | KEY.absolute_focus, 371 | KEY.relative_focus, 372 | KEY.absolute_iris, 373 | KEY.relative_iris, 374 | KEY.absolute_zoom, 375 | KEY.relative_zoom, 376 | KEY.absolute_pan_tilt, 377 | KEY.relative_pan_tilt, 378 | KEY.absolute_roll, 379 | KEY.relative_roll, 380 | undefined, 381 | undefined, 382 | KEY.auto_focus, 383 | KEY.privacy, 384 | ].filter((name, i) => bmControls[i] && name) 385 | } 386 | 387 | // Table 3-8 Processing Unit Descriptor 388 | const processingUnitDescriptor = descriptorArrays.filter(arr => arr[1] === CS.INTERFACE && arr[2] === VC.PROCESSING_UNIT)[0] 389 | const pUDBuffer = Buffer.from(processingUnitDescriptor) 390 | bControlSize = pUDBuffer.readIntLE(7, 1) 391 | bmControls = bitmask(pUDBuffer.readIntLE(8, bControlSize)) 392 | const bmVideoStandards = bitmask(pUDBuffer.readIntLE(8 + bControlSize, 1)) 393 | const processingUnit = { 394 | bUnitID: pUDBuffer.readIntLE(3, 1), 395 | wMaxMultiplier: pUDBuffer.readIntLE(3, 1), 396 | controls: [ 397 | KEY.brightness, 398 | KEY.contrast, 399 | KEY.hue, 400 | KEY.saturation, 401 | KEY.sharpness, 402 | KEY.gamma, 403 | KEY.white_balance_temperature, 404 | KEY.white_balance_component, 405 | KEY.backlight_compensation, 406 | KEY.gain, 407 | KEY.power_line_frequency, 408 | KEY.auto_hue, 409 | KEY.auto_white_balance_temperature, 410 | KEY.auto_white_balance_component, 411 | KEY.digital_multiplier, 412 | KEY.digital_multiplier_limit, 413 | KEY.analog_video_standard, 414 | KEY.analog_lock_status, 415 | ].filter((name, i) => bmControls[i]), 416 | videoStandards: [ 417 | KEY.NONE, 418 | KEY.NTSC_525_60, 419 | KEY.PAL_625_50, 420 | KEY.SECAM_625_50, 421 | KEY.NTSC_625_50, 422 | KEY.PAL_525_60, 423 | ].filter((name, i) => bmVideoStandards[i]) 424 | } 425 | 426 | // console.log('cameraInputTerminal', cameraInputTerminal) 427 | // console.log('processingUnit', processingUnit) 428 | 429 | /* 430 | 3.9.2.1 Input Header Descriptor 431 | The Input Header descriptor is used for VS interfaces that contain an IN endpoint for streaming 432 | video data. It provides information on the number of different format descriptors that will follow 433 | it, as well as the total size of all class-specific descriptors in alternate setting zero of this interface. 434 | */ 435 | // const rawInputHeaderDescriptor = descriptorArrays.filter(arr => arr[1] === CS.INTERFACE && arr[2] === VS_DESCRIPTOR_SUBTYPE.INPUT_HEADER)[0] 436 | // const inputHeaderDescriptor = { 437 | // bEndpointAddress: rawInputHeaderDescriptor[6], 438 | // bTerminalLink: rawInputHeaderDescriptor[8], 439 | // bStillCaptureMethod: rawInputHeaderDescriptor[9], 440 | // } 441 | 442 | return { 443 | processingUnit, 444 | cameraInputTerminal, 445 | } 446 | } 447 | 448 | const bitmask = (int) => int.toString(2).split('').reverse().map(i => parseInt(i)) 449 | 450 | module.exports = UVCControl 451 | -------------------------------------------------------------------------------- /lib/controls.js: -------------------------------------------------------------------------------- 1 | // See USB Device Class Definition for Video Devices Revision 1.1 2 | // http://www.usb.org/developers/docs/devclass_docs/ 3 | 4 | const { 5 | FIELD_TYPE, 6 | REQUEST, 7 | PU, 8 | CT, 9 | VS, 10 | KEY, 11 | } = require('./constants') 12 | 13 | const CONTROLS = { 14 | 15 | // still_image_trigger: { 16 | // description: `This control notifies the device to begin sending still-image data over the relevant isochronous or bulk pipe. A dedicated still-image bulk pipe is only used for method 3 of still image capture. This control shall only be set while streaming is occurring, and the hardware shall reset it to the "Normal Operation" mode after the still image has been sent. This control is only required if the device supports method 2 or method 3 of still-image retrieval. See section 2.4.2.4 "Still Image Capture". `, 17 | // selector: VS.STILL_IMAGE_TRIGGER_CONTROL, 18 | // type: 'CT', 19 | // // type: 'VS', 20 | // wLength: 1, 21 | // requests: [ 22 | // REQUEST.SET_CUR, 23 | // REQUEST.GET_CUR, 24 | // REQUEST.GET_INFO, 25 | // ], 26 | // fields: [{ 27 | // name: 'bTrigger', 28 | // description: 'The setting for the Still Image Trigger Control', 29 | // offset: 0, 30 | // size: 1, 31 | // type: FIELD_TYPE.NUMBER, 32 | // options: { 33 | // NORMAL: 0, 34 | // TRANSMIT: 1, 35 | // TRANSMIT_BULK: 2, 36 | // ABORT: 3, 37 | // } 38 | // }] 39 | // }, 40 | // ============== 41 | // Input Terminal 42 | // ============== 43 | [KEY.auto_exposure_mode]: { 44 | description: `The Auto-Exposure Mode Control determines whether the device will provide automatic adjustment of the Exposure Time and Iris controls. Attempts to programmatically set the autoadjusted controls are then ignored. A GET_RES request issued to this control will return a bitmap of the modes supported by this control. A valid request to this control would have only one bit set (a single mode selected). This control must accept the GET_DEF request and return its default value.`, 45 | selector: CT.AE_MODE_CONTROL, 46 | type: 'PU', 47 | // type: 'CT', ?? 48 | wLength: 1, 49 | requests: [ 50 | REQUEST.SET_CUR, 51 | REQUEST.GET_CUR, 52 | REQUEST.GET_RES, 53 | REQUEST.GET_INFO, 54 | REQUEST.GET_DEF, 55 | ], 56 | fields: [{ 57 | name: 'bAutoExposureMode', 58 | description: 'The setting for the attribute of the addressed Auto-Exposure Mode Control', 59 | offset: 0, 60 | size: 1, 61 | type: FIELD_TYPE.BITMAP, 62 | options: { 63 | MANUAL: 0b00000001, 64 | AUTO: 0b00000010, 65 | PRIORITY_SHUTTER: 0b00000100, 66 | PRIORITY_APERTURE: 0b00001000, 67 | } 68 | }] 69 | }, 70 | [KEY.auto_exposure_priority]: { 71 | description: 'The Auto-Exposure Priority Control is used to specify constraints on the Exposure Time Control when the Auto-Exposure Mode Control is set to Auto Mode or Shutter Priority Mode. A value of zero indicates that the frame rate must remain constant. A value of 1 indicates that the frame rate may be dynamically varied by the device. The default value is zero (0).', 72 | selector: CT.AE_PRIORITY_CONTROL, 73 | // type: 'CT', 74 | type: 'PU', 75 | wLength: 1, 76 | requests: [ 77 | REQUEST.SET_CUR, 78 | REQUEST.GET_CUR, 79 | REQUEST.GET_INFO, 80 | ], 81 | fields: [{ 82 | name: 'bAutoExposurePriority', 83 | description: 'The setting for the attribute of the addressed AutoExposure Priority control.', 84 | type: FIELD_TYPE.NUMBER, 85 | offset: 0, 86 | size: 1, 87 | }] 88 | }, 89 | [KEY.absolute_exposure_time]: { 90 | description: 'The Exposure Time (Absolute) Control is used to specify the length of exposure. This value is expressed in 100µs units, where 1 is 1/10,000th of a second, 10,000 is 1 second, and 100,000 is 10 seconds. A value of zero (0) is undefined. Note that the manual exposure control is further limited by the frame interval, which always has higher precedence. If the frame interval is changed to a value below the current value of the Exposure Control, the Exposure Control value will automatically be changed. The default Exposure Control value will be the current frame interval until an explicit exposure value is chosen. This control will not accept SET requests when the Auto-Exposure Mode control is in Auto mode or Aperture Priority mode, and the control pipe shall indicate a stall in this case. This control must accept the GET_DEF request and return its default value.', 91 | selector: CT.EXPOSURE_TIME_ABSOLUTE_CONTROL, 92 | // type: 'CT', 93 | type: 'PU', 94 | wLength: 4, 95 | requests: [ 96 | REQUEST.GET_CUR, 97 | REQUEST.GET_MIN, 98 | REQUEST.GET_MAX, 99 | REQUEST.GET_RES, 100 | REQUEST.GET_INFO, 101 | REQUEST.GET_DEF, 102 | ], 103 | fields: [{ 104 | name: 'dwExposureTimeAbsolute', 105 | description: 'The setting for the attribute of the addressed Exposure Time (Absolute) Control. 0: Reserved, 1: 0.0001 sec, 100000: 10 sec', 106 | type: FIELD_TYPE.NUMBER, 107 | offset: 0, 108 | size: 4, 109 | }] 110 | }, 111 | [KEY.absolute_focus]: { 112 | description: 'The Focus (Absolute) Control is used to specify the distance to the optimally focused target. This value is expressed in millimeters. The default value is implementation-specific. This control must accept the GET_DEF request and return its default value.', 113 | selector: CT.FOCUS_ABSOLUTE_CONTROL, 114 | type: 'CT', 115 | wLength: 2, 116 | requests: [ 117 | REQUEST.GET_CUR, 118 | REQUEST.GET_MIN, 119 | REQUEST.GET_MAX, 120 | REQUEST.GET_RES, 121 | REQUEST.GET_INFO, 122 | REQUEST.GET_DEF, 123 | ], 124 | fields: [{ 125 | name: 'wFocusAbsolute', 126 | description: 'The setting for the attribute of the addressed Focus (Absolute) Control.', 127 | type: FIELD_TYPE.NUMBER, 128 | offset: 0, 129 | size: 2, 130 | }], 131 | }, 132 | [KEY.absolute_zoom]: { 133 | description: 'The Zoom (Absolute) Control is used to specify or determine the Objective lens focal length. This control is used in combination with the wObjectiveFocalLengthMin and wObjectiveFocalLengthMax fields in the Camera Terminal descriptor to describe and control the Objective lens focal length of the device(see section 2.4.2.5.1 "Optical Zoom"). The MIN and MAX values are sufficient to imply the resolution, so the RES value must always be 1. The MIN, MAX and default values are implementation dependent. This control must accept the GET_DEF request and return its default value.', 134 | selector: CT.ZOOM_ABSOLUTE_CONTROL, 135 | type: 'CT', 136 | wLength: 2, 137 | requests: [ 138 | REQUEST.GET_CUR, 139 | REQUEST.GET_MIN, 140 | REQUEST.GET_MAX, 141 | REQUEST.GET_RES, 142 | REQUEST.GET_INFO, 143 | REQUEST.GET_DEF, 144 | ], 145 | optional_requests: [ 146 | REQUEST.SET_CUR, 147 | ], 148 | fields: [{ 149 | name: 'wObjectiveFocalLength', 150 | description: 'The value of Zcur(see section 2.4.2.5.1 "Optical Zoom".)', 151 | type: FIELD_TYPE.NUMBER, 152 | offset: 0, 153 | size: 2, 154 | }], 155 | }, 156 | [KEY.absolute_pan_tilt]: { 157 | description: 'The PanTilt (Absolute) Control is used to specify the pan and tilt settings. The dwPanAbsolute is used to specify the pan setting in arc second units. 1 arc second is 1/3600 of a degree. Values range from –180*3600 arc second to +180*3600 arc second, or a subset thereof, with the default set to zero. Positive values are clockwise from the origin (the camera rotates clockwise when viewed from above), and negative values are counterclockwise from the origin. This control must accept the GET_DEF request and return its default value. The dwTiltAbsolute Control is used to specify the tilt setting in arc second units. 1 arc second is 1/3600 of a degree. Values range from –180*3600 arc second to +180*3600 arc second, or a subset thereof, with the default set to zero. Positive values point the imaging plane up, and negative values point the imaging plane down. This control must accept the GET_DEF request and return its default value.', 158 | selector: CT.PANTILT_ABSOLUTE_CONTROL, 159 | type: 'CT', 160 | wLength: 8, 161 | requests: [ 162 | REQUEST.GET_CUR, 163 | REQUEST.GET_MIN, 164 | REQUEST.GET_MAX, 165 | REQUEST.GET_RES, 166 | REQUEST.GET_INFO, 167 | REQUEST.GET_DEF, 168 | ], 169 | optional_requests: [ 170 | REQUEST.SET_CUR, 171 | ], 172 | fields: [{ 173 | name: 'dwPanAbsolute', 174 | description: 'The setting for the attribute of the addressed Pan (Absolute) Control.', 175 | type: FIELD_TYPE.NUMBER, // Signed Number 176 | offset: 0, 177 | size: 4, 178 | }, { 179 | name: 'dwTiltAbsolute', 180 | description: 'The setting for the attribute of the addressed Tilt (Absolute) Control.', 181 | type: FIELD_TYPE.NUMBER, // Signed Number 182 | offset: 4, 183 | size: 4, 184 | }], 185 | }, 186 | [KEY.auto_focus]: { 187 | description: 'The Focus, Auto Control setting determines whether the device will provide automatic adjustment of the Focus Absolute and/or Relative Controls. A value of 1 indicates that automatic adjustment is enabled. Attempts to programmatically set the related controls are then ignored. This control must accept the GET_DEF request and return its default value.', 188 | selector: CT.FOCUS_AUTO_CONTROL, 189 | type: 'CT', 190 | wLength: 1, 191 | requests: [ 192 | REQUEST.SET_CUR, 193 | REQUEST.GET_CUR, 194 | REQUEST.GET_INFO, 195 | REQUEST.GET_DEF, 196 | ], 197 | fields: [{ 198 | name: 'bFocusAuto', 199 | description: 'The setting for the attribute of the addressed Focus Auto control.', 200 | type: FIELD_TYPE.BOOLEAN, 201 | offset: 0, 202 | size: 1, 203 | }], 204 | }, 205 | 206 | [KEY.scanning_mode]: { 207 | description: 'The Scanning Mode Control setting is used to control the scanning mode of the camera sensor. A value of 0 indicates that the interlace mode is enabled, and a value of 1 indicates that the progressive or the non-interlace mode is enabled.', 208 | selector: CT.SCANNING_MODE_CONTROL, 209 | type: 'CT', 210 | wLength: 1, 211 | requests: [ 212 | REQUEST.SET_CUR, 213 | REQUEST.GET_CUR, 214 | REQUEST.GET_INFO, 215 | ], 216 | fields: [{ 217 | name: 'bScanningMode', 218 | description: 'The setting for the attribute of the addressed Scanning Mode Control', 219 | type: FIELD_TYPE.BOOLEAN, 220 | offset: 0, 221 | size: 1, 222 | options: { 223 | INTERLACED: 0, 224 | PROGRESSIVE: 1, 225 | } 226 | }], 227 | }, 228 | [KEY.relative_exposure_time]: { 229 | description: 'The Exposure Time (Relative) Control is used to specify the electronic shutter speed. This value is expressed in number of steps of exposure time that is incremented or decremented. A value of one (1) indicates that the exposure time is incremented one step further, and a value 0xFF indicates that the exposure time is decremented one step further. This step is implementation specific. A value of zero (0) indicates that the exposure time is set to the default value for implementation. The default values are implementation specific. This control will not accept SET requests when the Auto-Exposure Mode control is in Auto mode or Aperture Priority mode, and the control pipe shall indicate a stall in this case. If both Relative and Absolute Controls are supported, a SET_CUR to the Relative Control with a value other than 0x00 shall result in a Control Change interrupt for the Absolute Control (see section 2.4.2.2, “Status Interrupt Endpoint”).', 230 | selector: CT.EXPOSURE_TIME_RELATIVE_CONTROL, 231 | type: 'CT', 232 | wLength: 1, 233 | requests: [ 234 | REQUEST.SET_CUR, 235 | REQUEST.GET_CUR, 236 | REQUEST.GET_INFO, 237 | ], 238 | fields: [{ 239 | name: 'bExposureTimeRelative', 240 | description: 'The setting for the attribute of the addressed Exposure Time (Relative) Control', 241 | type: FIELD_TYPE.NUMBER, // Signed Number 242 | offset: 0, 243 | size: 1, 244 | options: { 245 | DEFAULT: 0, 246 | INCREASE: 1, 247 | DECREASE: 0xFF, 248 | } 249 | }], 250 | }, 251 | [KEY.relative_focus]: { 252 | description: 'The Focus (Relative) Control is used to move the focus lens group to specify the distance to the optimally focused target. The bFocusRelative field indicates whether the focus lens group is stopped or is moving for near or for infinity direction. A value of 1 indicates that the focus lens group is moved for near direction. A value of 0 indicates that the focus lens group is stopped. And a value of 0xFF indicates that the lens group is moved for infinity direction. The GET_MIN, GET_MAX, GET_RES and GET_DEF requests will return zero for this field. The bSpeed field indicates the speed of the lens group movement. A low number indicates a slow speed and a high number indicates a high speed. The GET_MIN, GET_MAX and GET_RES requests are used to retrieve the range and resolution for this field. The GET_DEF request is used to retrieve the default value for this field. If the control does not support speed control, it will return the value 1 in this field for all these requests. If both Relative and Absolute Controls are supported, a SET_CUR to the Relative Control with a value other than 0x00 shall result in a Control Change interrupt for the Absolute Control at the end of the movement (see section 2.4.2.2, “Status Interrupt Endpoint”). The end of movement can be due to physical device limits, or due to an explicit request by the host to stop the movement. If the end of movement is due to physical device limits (such as a limit in range of motion), a Control Change interrupt shall be generated for this Relative Control. If there is no limit in range of motion, a Control Change interrupt is not required.', 253 | selector: CT.FOCUS_RELATIVE_CONTROL, 254 | type: 'CT', 255 | wLength: 1, 256 | requests: [ 257 | REQUEST.SET_CUR, 258 | REQUEST.GET_CUR, 259 | REQUEST.GET_MIN, 260 | REQUEST.GET_MAX, 261 | REQUEST.GET_RES, 262 | REQUEST.GET_INFO, 263 | REQUEST.GET_DEF, 264 | ], 265 | fields: [{ 266 | name: 'bFocusRelative', 267 | description: 'The setting for the attribute of the addressed Focus (Relative) Control', 268 | type: FIELD_TYPE.NUMBER, // Signed Number 269 | offset: 0, 270 | size: 1, 271 | options: { 272 | STOP: 0, 273 | DIRECTION_NEAR: 1, 274 | DIRECTION_INFINITE: 0xFF, 275 | } 276 | }, { 277 | name: 'bSpeed', 278 | description: 'Speed for the control change', 279 | type: FIELD_TYPE.NUMBER, 280 | offset: 1, 281 | size: 1, 282 | }], 283 | }, 284 | [KEY.absolute_iris]: { 285 | description: `The Iris (Absolute) Control is used to specify the camera's aperture setting. This value is expressed in units of fstop * 100. The default value is implementation-specific. This control will not accept SET requests when the Auto-Exposure Mode control is in Auto mode or Shutter Priority mode, and the control pipe shall indicate a stall in this case. This control must accept the GET_DEF request and return its default value.`, 286 | selector: CT.IRIS_ABSOLUTE_CONTROL, 287 | type: 'CT', 288 | wLength: 2, 289 | requests: [ 290 | REQUEST.GET_CUR, 291 | REQUEST.GET_MIN, 292 | REQUEST.GET_MAX, 293 | REQUEST.GET_RES, 294 | REQUEST.GET_INFO, 295 | REQUEST.GET_DEF, 296 | ], 297 | optional_requests: [ 298 | REQUEST.SET_CUR, 299 | ], 300 | fields: [{ 301 | name: 'wIrisAbsolute', 302 | description: 'The setting for the attribute of the addressed Iris (Absolute) Control.', 303 | offset: 0, 304 | size: 2, 305 | type: FIELD_TYPE.NUMBER, 306 | }], 307 | }, 308 | [KEY.relative_iris]: { 309 | description: `The Iris (Relative) Control is used to specify the camera's aperture setting. This value is a signed integer and indicates the number of steps to open or close the iris. A value of 1 indicates that the iris is opened 1 step further. A value of 0xFF indicates that the iris is closed 1 step further. This step of iris is implementation specific. A value of zero (0) indicates that the iris is set to the default value for the implementation. The default value is implementation specific. This control will not accept SET requests when the Auto-Exposure Mode control is in Auto mode or Shutter Priority mode, and the control pipe shall indicate a stall in this case. If both Relative and Absolute Controls are supported, a SET_CUR to the Relative Control with a value other than 0x00 shall result in a Control Change interrupt for the Absolute Control (see section 2.4.2.2, “Status Interrupt Endpoint”). Table 4-18 Iris`, 310 | selector: CT.IRIS_RELATIVE_CONTROL, 311 | type: 'CT', 312 | wLength: 1, 313 | requests: [ 314 | REQUEST.SET_CUR, 315 | REQUEST.GET_CUR, 316 | REQUEST.GET_INFO, 317 | ], 318 | fields: [{ 319 | name: 'bIrisRelative', 320 | description: 'The setting for the attribute of the addressed Iris (Relative) Control', 321 | type: FIELD_TYPE.NUMBER, 322 | offset: 0, 323 | size: 1, 324 | options: { 325 | DEFAULT: 0, 326 | INCREASE: 1, 327 | DECREASE: 0xFF, 328 | } 329 | }], 330 | }, 331 | [KEY.relative_zoom]: { 332 | description: 'The Zoom (Relative) Control is used to specify the zoom focal length relatively as powered zoom. The bZoom field indicates whether the zoom lens group is stopped or the direction of the zoom lens. A value of 1 indicates that the zoom lens is moved towards the telephoto direction. A value of zero indicates that the zoom lens is stopped, and a value of 0xFF indicates that the zoom lens is moved towards the wide-angle direction. The GET_MIN, GET_MAX, GET_RES and GET_DEF requests will return zero for this field. The bDigitalZoom field specifies whether digital zoom is enabled or disabled. If the device only supports digital zoom, this field would be ignored. The GET_DEF request will return the default value for this field. The GET_MIN, GET_MAX and GET_RES requests will return zero for this field. The bSpeed field indicates the speed of the control change. A low number indicates a slow speed and a high number indicates a higher speed. The GET_MIN, GET_MAX and GET_RES requests are used to retrieve the range and resolution for this field. The GET_DEF request is used to retrieve the default value for this field. If the control does not support speed control, it will return the value 1 in this field for all these requests. If both Relative and Absolute Controls are supported, a SET_CUR to the Relative Control with a value other than 0x00 shall result in a Control Change interrupt for the Absolute Control at the end of the movement (see section 2.4.2.2, “Status Interrupt Endpoint”). The end of movement can be due to physical device limits, or due to an explicit request by the host to stop the movement. If the end of movement is due to physical device limits (such as a limit in range of motion), a Control Change interrupt shall be generated for this Relative Control.', 333 | selector: CT.ZOOM_RELATIVE_CONTROL, 334 | type: 'CT', 335 | wLength: 3, 336 | requests: [ 337 | REQUEST.SET_CUR, 338 | REQUEST.GET_CUR, 339 | REQUEST.GET_MIN, 340 | REQUEST.GET_MAX, 341 | REQUEST.GET_RES, 342 | REQUEST.GET_INFO, 343 | REQUEST.GET_DEF, 344 | ], 345 | fields: [{ 346 | name: 'bZoom', 347 | description: 'The setting for the attribute of the addressed Zoom Control', 348 | type: FIELD_TYPE.NUMBER, // Signed number 349 | offset: 0, 350 | size: 1, 351 | options: { 352 | STOP: 0, 353 | DIRECTION_TELEPHOTO: 1, 354 | DIRECTION_WIDE_ANGLE: 0xFF, 355 | } 356 | }, 357 | { 358 | name: 'bDigitalZoom', 359 | offset: 1, 360 | size: 1, 361 | type: FIELD_TYPE.BOOLEAN, 362 | options: { 363 | OFF: 0, 364 | ON: 1, 365 | } 366 | }, { 367 | name: 'bSpeed', 368 | description: 'Speed for the control change', 369 | type: FIELD_TYPE.NUMBER, 370 | offset: 2, 371 | size: 1, 372 | } 373 | ], 374 | }, 375 | [KEY.relative_pan_tilt]: { 376 | description: 'The PanTilt (Relative) Control is used to specify the pan and tilt direction to move. The bPanRelative field is used to specify the pan direction to move. A value of 0 indicates to stop the pan, a value of 1 indicates to start moving clockwise direction, and a value of 0xFF indicates to start moving counterclockwise direction. The GET_DEF, GET_MIN, GET_MAX and GET_RES requests will return zero for this field. The bPanSpeed field is used to specify the speed of the movement for the Pan direction. A low number indicates a slow speed and a high number indicates a higher speed. The GET_MIN, GET_MAX and GET_RES requests are used to retrieve the range and resolution for this field. The GET_DEF request is used to retrieve the default value for this field. If the control does not support speed control for the Pan control, it will return the value 1 in this field for all these requests. The bTiltRelative field is used to specify the tilt direction to move. A value of zero indicates to stop the tilt, a value of 1 indicates that the camera point the imaging plane up, and a value of 0xFF indicates that the camera point the imaging plane down. The GET_DEF, GET_MIN, GET_MAX and GET_RES requests will return zero for this field. The bTiltSpeed field is used to specify the speed of the movement for the Tilt direction. A low number indicates a slow speed and a high number indicates a higher speed. The GET_MIN, GET_MAX and GET_RES requests are used to retrieve the range and resolution for this field. The GET_DEF request is used to retrieve the default value for this field. If the control does not support speed control for the Tilt control, it will return the value 1 in this field for all these requests. If both Relative and Absolute Controls are supported, a SET_CUR to the Relative Control with a value other than 0x00 shall result in a Control Change interrupt for the Absolute Control at the end of the movement (see section 2.4.2.2, “Status Interrupt Endpoint”). The end of movement can be due to physical device limits, or due to an explicit request by the host to stop the movement. If the end of movement is due to physical device limits (such as a limit in range of motion), a Control Change interrupt shall be generated for this Relative Control. If there is no limit in range of motion, a Control Change interrupt is not required.', 377 | selector: CT.PANTILT_RELATIVE_CONTROL, 378 | type: 'CT', 379 | wLength: 4, 380 | requests: [ 381 | REQUEST.SET_CUR, 382 | REQUEST.GET_CUR, 383 | REQUEST.GET_MIN, 384 | REQUEST.GET_MAX, 385 | REQUEST.GET_RES, 386 | REQUEST.GET_INFO, 387 | REQUEST.GET_DEF, 388 | ], 389 | fields: [{ 390 | name: 'bPanRelative', 391 | description: 'The setting for the attribute of the addressed Pan(Relative) Control', 392 | type: FIELD_TYPE.NUMBER, // Signed Number 393 | offset: 0, 394 | size: 1, 395 | options: { 396 | STOP: 0, 397 | CLOCKWISE: 1, 398 | COUNTER_CLOCKWISE: 0xFF, 399 | } 400 | }, { 401 | name: 'bPanSpeed', 402 | description: 'Speed of the Pan movement', 403 | type: FIELD_TYPE.NUMBER, 404 | offset: 1, 405 | size: 1, 406 | }, { 407 | name: 'bTiltRelative', 408 | description: 'The setting for the attribute of the addressed Tilt(Relative) Control', 409 | offset: 2, 410 | size: 1, 411 | type: FIELD_TYPE.NUMBER, // Signed Number 412 | options: { 413 | STOP: 0, 414 | UP: 1, 415 | DOWN: 0xFF, 416 | } 417 | }, { 418 | name: 'bTiltSpeed', 419 | description: 'Speed for the Tilt movement', 420 | type: FIELD_TYPE.NUMBER, 421 | offset: 3, 422 | size: 1, 423 | }], 424 | }, 425 | [KEY.absolute_roll]: { 426 | description: 'The Roll (Absolute) Control is used to specify the roll setting in degrees. Values range from – 180 to +180, or a subset thereof, with the default being set to zero. Positive values cause a clockwise rotation of the camera along the image viewing axis, and negative values cause a counterclockwise rotation of the camera. This control must accept the GET_DEF request and return its default value.', 427 | selector: CT.ROLL_ABSOLUTE_CONTROL, 428 | type: 'CT', 429 | wLength: 2, 430 | requests: [ 431 | REQUEST.GET_CUR, 432 | REQUEST.GET_MIN, 433 | REQUEST.GET_MAX, 434 | REQUEST.GET_RES, 435 | REQUEST.GET_INFO, 436 | REQUEST.GET_DEF, 437 | ], 438 | optional_requests: [ 439 | REQUEST.SET_CUR, 440 | ], 441 | fields: [{ 442 | name: 'wRollAbsolute', 443 | description: 'The setting for the attribute of the addressed Roll (Absolute) Control.', 444 | type: FIELD_TYPE.NUMBER, // Signed Number 445 | offset: 0, 446 | size: 2, 447 | }], 448 | }, 449 | [KEY.relative_roll]: { 450 | description: 'The Roll (Relative) Control is used to specify the roll direction to move. The bRollRelative field is used to specify the roll direction to move. A value of 0 indicates to stop the roll, a value of 1 indicates to start moving in a clockwise rotation of the camera along the image viewing axis, and a value of 0xFF indicates to start moving in a counterclockwise direction. The GET_DEF, GET_MIN, GET_MAX and GET_RES requests will return zero for this field. The bSpeed is used to specify the speed of the roll movement. A low number indicates a slow speed and a high number indicates a higher speed. The GET_MIN, GET_MAX and GET_RES requests are used to retrieve the range and resolution for this field. The GET_DEF request is used to retrieve the default value for this field. If the control does not support speed control, it will return the value 1 in this field for all these requests. If both Relative and Absolute Controls are supported, a SET_CUR to the Relative Control with a value other than 0x00 shall result in a Control Change interrupt for the Absolute Control at the end of the movement (see section 2.4.2.2, “Status Interrupt Endpoint”). The end of movement can be due to physical device limits, or due to an explicit request by the host to stop the movement. If the end of movement is due to physical device limits (such as a limit in range of motion), a Control Change interrupt shall be generated for this Relative Control. If there is no limit in range of motion, a Control Change interrupt is not required.', 451 | selector: CT.ROLL_RELATIVE_CONTROL, 452 | type: 'CT', 453 | wLength: 2, 454 | requests: [ 455 | REQUEST.SET_CUR, 456 | REQUEST.GET_CUR, 457 | REQUEST.GET_MIN, 458 | REQUEST.GET_MAX, 459 | REQUEST.GET_RES, 460 | REQUEST.GET_INFO, 461 | REQUEST.GET_DEF, 462 | ], 463 | fields: [{ 464 | name: 'bRollRelative', 465 | description: 'The setting for the attribute of the addressed Roll (Relative) Control', 466 | type: FIELD_TYPE.NUMBER, // Signed Number 467 | offset: 0, 468 | size: 1, 469 | options: { 470 | STOP: 0, 471 | CLOCKWISE: 1, 472 | COUNTER_CLOCKWISE: 0xFF, 473 | } 474 | }, { 475 | name: 'bSpeed', 476 | description: 'Speed for the Roll movement', 477 | offset: 1, 478 | size: 1, 479 | type: FIELD_TYPE.NUMBER, 480 | }], 481 | }, 482 | [KEY.privacy]: { 483 | description: 'The Privacy Control setting is used to prevent video from being acquired by the camera sensor. A value of 0 indicates that the camera sensor is able to capture video images, and a value of 1 indicates that the camera sensor is prevented from capturing video images. This control shall be reported as an AutoUpdate control.', 484 | selector: CT.PRIVACY_CONTROL, 485 | type: 'CT', 486 | wLength: 1, 487 | requests: [ 488 | REQUEST.GET_CUR, 489 | REQUEST.GET_INFO, 490 | ], 491 | optional_requests: [ 492 | REQUEST.SET_CUR, 493 | ], 494 | fields: [{ 495 | name: 'bPrivacy', 496 | description: 'The setting for the attribute of the addressed Privacy Control', 497 | type: FIELD_TYPE.BOOLEAN, 498 | offset: 0, 499 | size: 1, 500 | options: { 501 | OPEN: 0, 502 | CLOSE: 1, 503 | } 504 | }], 505 | }, 506 | 507 | // =============== 508 | // Processing Unit 509 | // =============== 510 | [KEY.power_line_frequency]: { 511 | description: 'This control allows the host software to specify the local power line frequency, in order for the device to properly implement anti-flicker processing, if supported. The default is implementation-specific. This control must accept the GET_DEF request and return its default value.', 512 | selector: PU.POWER_LINE_FREQUENCY_CONTROL, 513 | type: 'PU', 514 | wLength: 1, 515 | requests: [ 516 | REQUEST.SET_CUR, 517 | REQUEST.GET_CUR, 518 | REQUEST.GET_INFO, 519 | REQUEST.GET_DEF, 520 | ], 521 | fields: [{ 522 | name: 'bPowerLineFrequency', 523 | description: 'The setting for the attribute of the addressed Power Line Frequency control.', 524 | type: FIELD_TYPE.NUMBER, 525 | offset: 0, 526 | size: 1, 527 | options: { 528 | DISABLED: 0, 529 | HZ_50: 1, 530 | HZ_60: 2, 531 | } 532 | }], 533 | }, 534 | [KEY.hue]: { 535 | description: 'This is used to specify the hue setting. The value of the hue setting is expressed in degrees multiplied by 100. The required range must be a subset of -18000 to 18000 (-180 to +180 degrees). The default value must be zero. This control must accept the GET_DEF request and return its default value.', 536 | selector: PU.HUE_CONTROL, 537 | type: 'PU', 538 | wLength: 2, 539 | requests: [ 540 | REQUEST.GET_CUR, 541 | REQUEST.GET_MIN, 542 | REQUEST.GET_MAX, 543 | REQUEST.GET_RES, 544 | REQUEST.GET_INFO, 545 | REQUEST.GET_DEF, 546 | ], 547 | optional_requests: [ 548 | REQUEST.SET_CUR, 549 | ], 550 | fields: [{ 551 | name: 'wHue', 552 | description: 'The setting for the attribute of the addressed Hue control.', 553 | type: FIELD_TYPE.NUMBER, // Signed Number 554 | offset: 0, 555 | size: 2, 556 | }], 557 | }, 558 | [KEY.white_balance_component]: { 559 | description: 'This is used to specify the white balance setting as Blue and Red values for video formats. This is offered as an alternative to the White Balance Temperature control. The supported range and default value for white balance components is implementation-dependent. The device shall interpret the controls as blue and red pairs. This control must accept the GET_DEF request and return its default value.', 560 | selector: PU.WHITE_BALANCE_COMPONENT_CONTROL, 561 | type: 'PU', 562 | wLength: 4, 563 | requests: [ 564 | REQUEST.GET_CUR, 565 | REQUEST.GET_MIN, 566 | REQUEST.GET_MAX, 567 | REQUEST.GET_RES, 568 | REQUEST.GET_INFO, 569 | REQUEST.GET_DEF, 570 | ], 571 | optional_requests: [ 572 | REQUEST.SET_CUR, 573 | ], 574 | fields: [{ 575 | name: 'wWhiteBalanceBlue', 576 | description: 'The setting for the blue component of the addressed White Balance Component control.', 577 | type: FIELD_TYPE.NUMBER, 578 | offset: 0, 579 | size: 2, 580 | }, { 581 | name: 'wWhiteBalanceRed', 582 | description: 'The setting for the red component of the addressed White Balance Component control.', 583 | type: FIELD_TYPE.NUMBER, 584 | offset: 1, 585 | size: 2, 586 | }], 587 | }, 588 | [KEY.auto_white_balance_component]: { 589 | description: 'The White Balance Component Auto Control setting determines whether the device will provide automatic adjustment of the related control. A value of 1 indicates that automatic adjustment is enabled. Attempts to programmatically set the related control are then ignored. This control must accept the GET_DEF request and return its default value.', 590 | selector: PU.WHITE_BALANCE_COMPONENT_AUTO_CONTROL, 591 | type: 'PU', 592 | wLength: 1, 593 | requests: [ 594 | REQUEST.SET_CUR, 595 | REQUEST.GET_CUR, 596 | REQUEST.GET_INFO, 597 | REQUEST.GET_DEF, 598 | ], 599 | fields: [{ 600 | name: 'bWhiteBalanceComponentAuto', 601 | description: 'The setting for the attribute of the addressed White Balance Component, Auto control.', 602 | type: FIELD_TYPE.NUMBER, 603 | offset: 0, 604 | size: 1, 605 | }], 606 | }, 607 | [KEY.digital_multiplier]: { 608 | description: 'This is used to specify the amount of Digital Zoom applied to the optical image. This is the position within the range of possible values of multiplier m, allowing the multiplier resolution to be described by the device implementation. The MIN and MAX values are sufficient to imply the resolution, so the RES value must always be 1. The MIN, MAX and default values are implementation dependent. If the Digital Multiplier Limit Control is supported, the MIN and MAX values shall match the MIN and MAX values of the Digital Multiplier Control. The Digital Multiplier Limit Control allows either the Device or the Host to establish a temporary upper limit for the Z′cur value, thus reducing dynamically the range of the Digital Multiplier Control. If Digital Multiplier Limit is used to decrease the Limit below the current Z′cur value, the Z′cur value will be adjusted to match the new limit and the Digital Multiplier Control shall send a Control Change Event to notify the host of the adjustment.', 609 | selector: PU.DIGITAL_MULTIPLIER_CONTROL, 610 | type: 'PU', 611 | wLength: 2, 612 | requests: [ 613 | REQUEST.SET_CUR, 614 | REQUEST.GET_CUR, 615 | REQUEST.GET_MIN, 616 | REQUEST.GET_MAX, 617 | REQUEST.GET_RES, 618 | REQUEST.GET_INFO, 619 | REQUEST.GET_DEF, 620 | ], 621 | fields: [{ 622 | name: 'wMultiplierStep', 623 | description: 'The value Z′cur (see section 2.4.2.5.2 "Digital Zoom".)', 624 | type: FIELD_TYPE.NUMBER, 625 | offset: 0, 626 | size: 2, 627 | }], 628 | }, 629 | [KEY.digital_multiplier_limit]: { 630 | description: 'This is used to specify an upper limit for the amount of Digital Zoom applied to the optical image. This is the maximum position within the range of possible values of multiplier m. The MIN and MAX values are sufficient to imply the resolution, so the RES value must always be 1. The MIN, MAX and default values are implementation dependent.', 631 | selector: PU.DIGITAL_MULTIPLIER_LIMIT_CONTROL, 632 | type: 'PU', 633 | wLength: 2, 634 | requests: [ 635 | REQUEST.SET_CUR, 636 | REQUEST.GET_CUR, 637 | REQUEST.GET_MIN, 638 | REQUEST.GET_MAX, 639 | REQUEST.GET_RES, 640 | REQUEST.GET_INFO, 641 | REQUEST.GET_DEF, 642 | ], 643 | fields: [{ 644 | name: 'wMultiplierLimit', 645 | description: 'A value specifying the upper bound for Z′cur (see section 2.4.2.5.2 "Digital Zoom".)', 646 | type: FIELD_TYPE.NUMBER, 647 | offset: 0, 648 | size: 2, 649 | }], 650 | }, 651 | [KEY.auto_hue]: { 652 | description: 'The Hue Auto Control setting determines whether the device will provide automatic adjustment of the related control. A value of 1 indicates that automatic adjustment is enabled. Attempts to programmatically set the related control are then ignored. This control must accept the GET_DEF request and return its default value.', 653 | selector: PU.HUE_AUTO_CONTROL, 654 | type: 'PU', 655 | wLength: 1, 656 | requests: [ 657 | REQUEST.SET_CUR, 658 | REQUEST.GET_CUR, 659 | REQUEST.GET_INFO, 660 | REQUEST.GET_DEF, 661 | ], 662 | fields: [{ 663 | name: 'bHueAuto', 664 | description: 'The setting for the attribute of the addressed Hue, Auto control.', 665 | type: FIELD_TYPE.NUMBER, 666 | offset: 0, 667 | size: 1, 668 | }], 669 | }, 670 | [KEY.analog_video_standard]: { 671 | description: 'This is used to report the current Video Standard of the stream captured by the Processing Unit. ', 672 | selector: PU.ANALOG_VIDEO_STANDARD_CONTROL, 673 | type: 'PU', 674 | wLength: 1, 675 | requests: [ 676 | REQUEST.GET_CUR, 677 | REQUEST.GET_INFO, 678 | ], 679 | fields: [{ 680 | name: 'bVideoStandard', 681 | description: 'The Analog Video Standard of the input video signal.', 682 | type: FIELD_TYPE.NUMBER, 683 | offset: 0, 684 | size: 1, 685 | options: { 686 | NONE: 0, 687 | NTSC_525_60: 1, 688 | PAL_625_50: 2, 689 | SECAM_625_50: 3, 690 | NTSC_625_50: 4, 691 | PAL_525_60: 5, 692 | } 693 | }], 694 | }, 695 | [KEY.analog_lock_status]: { 696 | description: 'This is used to report whether the video decoder has achieved horizontal lock of the analog input signal. If the decoder is locked, it is assumed that a valid video stream is being generated. This control is to be supported only for analog video decoder functionality.', 697 | selector: PU.ANALOG_LOCK_STATUS_CONTROL, 698 | type: 'PU', 699 | wLength: 1, 700 | requests: [ 701 | REQUEST.GET_CUR, 702 | REQUEST.GET_INFO, 703 | ], 704 | fields: [{ 705 | name: 'bStatus', 706 | description: 'Lock status', 707 | type: FIELD_TYPE.NUMBER, 708 | offset: 0, 709 | size: 1, 710 | options: { 711 | LOCKED: 0, 712 | UNLOCKED: 1, 713 | } 714 | }], 715 | }, 716 | [KEY.brightness]: { 717 | description: 'This is used to specify the brightness. This is a relative value where increasing values indicate increasing brightness. The MIN and MAX values are sufficient to imply the resolution, so the RES value must always be 1. The MIN, MAX and default values are implementation dependent. This control must accept the GET_DEF request and return its default value.', 718 | selector: PU.BRIGHTNESS_CONTROL, 719 | type: 'PU', 720 | wLength: 2, 721 | requests: [ 722 | REQUEST.SET_CUR, 723 | REQUEST.GET_CUR, 724 | REQUEST.GET_MIN, 725 | REQUEST.GET_MAX, 726 | REQUEST.GET_RES, 727 | REQUEST.GET_INFO, 728 | REQUEST.GET_DEF, 729 | ], 730 | fields: [{ 731 | name: 'wBrightness', 732 | description: 'The setting for the attribute of the addressed Brightness control.', 733 | type: FIELD_TYPE.NUMBER, // Signed Number 734 | offset: 0, 735 | size: 2, 736 | }], 737 | }, 738 | [KEY.contrast]: { 739 | description: 'This is used to specify the contrast value. This is a relative value where increasing values indicate increasing contrast. The MIN and MAX values are sufficient to imply the resolution, so the RES value must always be 1. The MIN, MAX and default values are implementation dependent. This control must accept the GET_DEF request and return its default value.', 740 | selector: PU.CONTRAST_CONTROL, 741 | type: 'PU', 742 | wLength: 2, 743 | requests: [ 744 | REQUEST.SET_CUR, 745 | REQUEST.GET_CUR, 746 | REQUEST.GET_MIN, 747 | REQUEST.GET_MAX, 748 | REQUEST.GET_RES, 749 | REQUEST.GET_INFO, 750 | REQUEST.GET_DEF, 751 | ], 752 | fields: [{ 753 | name: 'wContrast', 754 | description: 'The setting for the attribute of the addressed Contrast control.', 755 | type: FIELD_TYPE.NUMBER, 756 | offset: 0, 757 | size: 2, 758 | }], 759 | }, 760 | [KEY.gain]: { 761 | description: 'This is used to specify the gain setting. This is a relative value where increasing values indicate increasing gain. The MIN and MAX values are sufficient to imply the resolution, so the RES value must always be 1. The MIN, MAX and default values are implementation dependent. This control must accept the GET_DEF request and return its default value.', 762 | selector: PU.GAIN_CONTROL, 763 | type: 'PU', 764 | wLength: 2, 765 | requests: [ 766 | REQUEST.SET_CUR, 767 | REQUEST.GET_CUR, 768 | REQUEST.GET_MIN, 769 | REQUEST.GET_MAX, 770 | REQUEST.GET_RES, 771 | REQUEST.GET_INFO, 772 | REQUEST.GET_DEF, 773 | ], 774 | fields: [{ 775 | name: 'wGain', 776 | description: 'The setting for the attribute of the addressed Gain control.', 777 | type: FIELD_TYPE.NUMBER, 778 | offset: 0, 779 | size: 2, 780 | }], 781 | }, 782 | [KEY.saturation]: { 783 | description: 'This is used to specify the saturation setting. This is a relative value where increasing values indicate increasing saturation. A Saturation value of 0 indicates grayscale. The MIN and MAX values are sufficient to imply the resolution, so the RES value must always be 1. The MIN, MAX and default values are implementation-dependent. This control must accept the GET_DEF request and return its default value.', 784 | selector: PU.SATURATION_CONTROL, 785 | type: 'PU', 786 | wLength: 2, 787 | requests: [ 788 | REQUEST.SET_CUR, 789 | REQUEST.GET_CUR, 790 | REQUEST.GET_MIN, 791 | REQUEST.GET_MAX, 792 | REQUEST.GET_RES, 793 | REQUEST.GET_INFO, 794 | REQUEST.GET_DEF, 795 | ], 796 | fields: [{ 797 | name: 'wSaturation', 798 | description: 'The setting for the attribute of the addressed Saturation control.', 799 | type: FIELD_TYPE.NUMBER, 800 | offset: 0, 801 | size: 2, 802 | }], 803 | }, 804 | [KEY.sharpness]: { 805 | description: 'This is used to specify the sharpness setting. This is a relative value where increasing values indicate increasing sharpness, and the MIN value always implies "no sharpness processing", where the device will not process the video image to sharpen edges. The MIN and MAX values are sufficient to imply the resolution, so the RES value must always be 1. The MIN, MAX and default values are implementation-dependent. This control must accept the GET_DEF request and return its default value.', 806 | selector: PU.SHARPNESS_CONTROL, 807 | type: 'PU', 808 | wLength: 2, 809 | requests: [ 810 | REQUEST.SET_CUR, 811 | REQUEST.GET_CUR, 812 | REQUEST.GET_MIN, 813 | REQUEST.GET_MAX, 814 | REQUEST.GET_RES, 815 | REQUEST.GET_INFO, 816 | REQUEST.GET_DEF, 817 | ], 818 | fields: [{ 819 | name: 'wSharpness', 820 | description: 'The setting for the attribute of the addressed Sharpness control.', 821 | type: FIELD_TYPE.NUMBER, 822 | offset: 0, 823 | size: 2, 824 | }], 825 | }, 826 | [KEY.white_balance_temperature]: { 827 | description: 'This is used to specify the white balance setting as a color temperature in degrees Kelvin. This is offered as an alternative to the White Balance Component control. Minimum range should be 2800 (incandescent) to 6500 (daylight) for webcams and dual-mode cameras. The supported range and default value for white balance temperature is implementation-dependent. This control must accept the GET_DEF request and return its default value.', 828 | selector: PU.WHITE_BALANCE_TEMPERATURE_CONTROL, 829 | type: 'PU', 830 | wLength: 2, 831 | requests: [ 832 | REQUEST.GET_CUR, 833 | REQUEST.GET_MIN, 834 | REQUEST.GET_MAX, 835 | REQUEST.GET_RES, 836 | REQUEST.GET_INFO, 837 | REQUEST.GET_DEF, 838 | ], 839 | optional_requests: [ 840 | REQUEST.SET_CUR 841 | ], 842 | fields: [{ 843 | name: 'wWhiteBalanceTemperature', 844 | description: 'The setting for the attribute of the addressed White Balance Temperature control.', 845 | type: FIELD_TYPE.NUMBER, 846 | offset: 0, 847 | size: 2, 848 | }], 849 | }, 850 | [KEY.backlight_compensation]: { 851 | description: 'The Backlight Compensation Control is used to specify the backlight compensation. A value of zero indicates that the backlight compensation is disabled. A non-zero value indicates that the backlight compensation is enabled. The device may support a range of values, or simply a binary switch. If a range is supported, a low number indicates the least amount of backlightcompensation. The default value is implementation-specific, but enabling backlight compensation is recommended. This control must accept the GET_DEF request and return its default value.', 852 | selector: PU.BACKLIGHT_COMPENSATION_CONTROL, 853 | type: 'PU', 854 | wLength: 2, 855 | requests: [ 856 | REQUEST.SET_CUR, 857 | REQUEST.GET_CUR, 858 | REQUEST.GET_MIN, 859 | REQUEST.GET_MAX, 860 | REQUEST.GET_RES, 861 | REQUEST.GET_INFO, 862 | REQUEST.GET_DEF, 863 | ], 864 | fields: [{ 865 | name: 'wBacklightCompensation', 866 | description: 'The setting for the attribute of the addressed Backlight Compensation control.', 867 | type: FIELD_TYPE.NUMBER, 868 | offset: 0, 869 | size: 2, 870 | }], 871 | }, 872 | [KEY.gain]: { 873 | description: 'This is used to specify the gain setting. This is a relative value where increasing values indicate increasing gain. The MIN and MAX values are sufficient to imply the resolution, so the RES value must always be 1. The MIN, MAX and default values are implementation dependent. This control must accept the GET_DEF request and return its default value.', 874 | selector: PU.GAIN_CONTROL, 875 | type: 'PU', 876 | wLength: 2, 877 | requests: [ 878 | REQUEST.SET_CUR, 879 | REQUEST.GET_CUR, 880 | REQUEST.GET_MIN, 881 | REQUEST.GET_MAX, 882 | REQUEST.GET_RES, 883 | REQUEST.GET_INFO, 884 | REQUEST.GET_DEF, 885 | ], 886 | fields: [{ 887 | name: 'wGain', 888 | description: 'The setting for the attribute of the addressed Gain control.', 889 | type: FIELD_TYPE.NUMBER, 890 | offset: 0, 891 | size: 2, 892 | }], 893 | }, 894 | [KEY.auto_white_balance_temperature]: { 895 | description: 'The White Balance Temperature Auto Control setting determines whether the device will provide automatic adjustment of the related control. A value of 1 indicates that automatic adjustment is enabled. Attempts to programmatically set the related control are then ignored. This control must accept the GET_DEF request and return its default value.', 896 | selector: PU.WHITE_BALANCE_TEMPERATURE_AUTO_CONTROL, 897 | type: 'PU', 898 | wLength: 1, 899 | requests: [ 900 | REQUEST.SET_CUR, 901 | REQUEST.GET_CUR, 902 | REQUEST.GET_INFO, 903 | REQUEST.GET_DEF, 904 | ], 905 | fields: [{ 906 | name: 'bWhiteBalanceTemperatureAuto', 907 | description: 'The setting for the attribute of the addressed White Balance Temperature, Auto control.', 908 | type: FIELD_TYPE.BOOLEAN, 909 | offset: 0, 910 | size: 1, 911 | }], 912 | }, 913 | [KEY.gamma]: { 914 | description: 'This is used to specify the gamma setting. The value of the gamma setting is expressed in gamma multiplied by 100. The required range must be a subset of 1 to 500, and the default values are typically 100 (gamma = 1) or 220 (gamma = 2.2). This control must accept the GET_DEF request and return its default value', 915 | selector: PU.GAMMA_CONTROL, 916 | type: 'PU', 917 | wLength: 2, 918 | requests: [ 919 | REQUEST.SET_CUR, 920 | REQUEST.GET_CUR, 921 | REQUEST.GET_MIN, 922 | REQUEST.GET_MAX, 923 | REQUEST.GET_RES, 924 | REQUEST.GET_INFO, 925 | REQUEST.GET_DEF, 926 | ], 927 | fields: [{ 928 | name: 'wGamma', 929 | description: 'The setting for the attribute of the addressed Gamma control.', 930 | type: FIELD_TYPE.NUMBER, 931 | offset: 0, 932 | size: 2, 933 | }], 934 | }, 935 | } 936 | 937 | Object.entries(CONTROLS).forEach(([key, control]) => control.name = key) 938 | 939 | module.exports = CONTROLS 940 | --------------------------------------------------------------------------------