joelpurra / uvcc

USB Video Class (UVC) device configurator. Used for webcams, camcorders, etcetera. Command line interface for automation.
https://joelpurra.com/projects/uvcc/
GNU General Public License v3.0
95 stars 5 forks source link

commands take a long time to finish after upgrade to v3.0.0 #16

Closed galak closed 3 years ago

galak commented 3 years ago

Just upgraded to v3.0.0 and when I do:

time uvcc --vendor 1133 --address 4 --product 2194 set auto_exposure_mode 1 --verbose

Parsed arguments: {
  "address": 4,
  "cmd": "set",
  "control": "auto_exposure_mode",
  "product": 2194,
  "values": [
    1
  ],
  "vendor": 1133,
  "verbose": true
}

real    0m8.852s
user    0m0.119s
sys 0m0.028s

This use to happen almost instantly:

device is:

kumar-macair:~ galak$ uvcc devices
[
  {
    "name": "HD Pro Webcam C920",
    "vendor": 1133,
    "product": 2194,
    "address": 4
  }
]
joelpurra commented 3 years ago

@galak: Ah, yes. I can confirm the issue. Running uvcc export shows the JSON output right way, but the program does not exit. Profiling confirms that uvcc export finishes in about 200 milliseconds, but not sure what takes so much time afterwards.

Attempted a minor fix related to improvements in uvcc v3.0.0 in https://github.com/joelpurra/node-uvc-control/commits/v2 but it didn't help. What did seem to help was to pin node-usb to the previous version v1.6.5. The most recent node-usb v1.7.0 is within the semantic versioning range and would be automatically installed by npm since its release 2021-04-10.

Before fix:

# joelpurra/node-uvc-control@958d949eb203b520966f50c377e15c529794ea6a with node-usb v1.7.0
# time uvcc export
0.14s user 0.01s system 1% cpu 8.908 total

After fix:

# joelpurra/node-uvc-control@8c5f5f41389bb6a8b4b243115ab92892d633cb55 with node-usb v1.6.5
# time uvcc export
0.11s user 0.01s system 67% cpu 0.180 total

The fix has been released on npm as uvcc v3.0.1.

@galak: can you confirm that the fix works?

kmalinich commented 3 years ago

I had this issue too! I was crawling all over the console logs and system logs, trying to find what was happening. I work from home and am on video meetings almost all day, and since my monitor faces a window I have to adjust the absolute_exposure_time and gain quite frequently.

I had downgraded uvcc one version at a time and still had the same issue (due to what you correctly pointed out about the semantic versioning range of usb)

But.. I'm pleased to report uvcc v3.0.1 fixes the issue! I'm so happy, I was tearing my hair out.

kdm-pc:~ $ uname -s -r -v -m -p -i -o
Darwin 20.3.0 Darwin Kernel Version 20.3.0: Thu Jan 21 00:07:06 PST 2021; root:xnu-7195.81.3~1/RELEASE_X86_64 x86_64 i386 iMac19,1 Darwin
kdm-pc:~ $ node -v
v16.0.0
kdm-pc:~ $ npm -v
7.11.2
kdm-pc:~ $ which uvcc
/usr/local/bin/uvcc
kdm-pc:~ $ jq .version /usr/local/lib/node_modules/uvcc/node_modules/usb/package.json
"1.6.5"
kdm-pc:~ $ time uvcc set absolute_exposure_time 156

 Real |  User | Systm | CPU%
0.112 | 0.087 | 0.027 | 101.21

Also - thanks for writing this application, I love it and it improves my day, every day. <3

joelpurra commented 3 years ago

@kmalinich: haha, I know the frustration of looking for a seemingly random issue very well ;) This time I got lucky noticing the node-usb version change! Happy that you enjoy using uvcc, thanks for the fix confirmation and encouraging words =)

Already reported the issue upstream.

galak commented 3 years ago

@galak: can you confirm that the fix works?

Can doubly confirm this fixes my issue.

joelpurra commented 2 years ago

Heads up: because it is no longer possible to install uvcc on the current Node.js v17 release (see #18), I upgraded to node-usb v1.8.0 (which still has long delays) and released uvcc v5.0.0.

npm install --global uvcc@latest

Don't upgrade if you don't want delays.

While the delays are inconvenient, I don't really want to maintain a support version of uvcc v4 which avoids the delay by not upgrading the node-usb dependency. If you choose to stay on Node.js v12, v14, v16 you can still use your installed uvcc v4.0.0 and avoid the delay. There's a big but: the way the forked node-uvc-control v2 (https://github.com/joelpurra/node-uvc-control/commits/v2) is installed (hint: it is not properly versioned since it's not "official") any new installation of even uvcc v4 may experience the 8 second delay (or worse, infinite delay).

The proper way forward is of course to fix node-usb; the maintainer is asking for help in fixing the issue, so please chip in if you can!