pupil icon indicating copy to clipboard operation
pupil copied to clipboard

Eye window crashes when mistakenly selecting my webcam as source

Open pfaion opened this issue 4 years ago • 5 comments

I enabled Manual Camera Selection and miss-clicked on my webcam instead of the Pupil cam. As a result the eye window crashed beyond recovery and only restarting Capture solved the issue.

See log
2020-05-15 10:09:33,313 - eye1 - [DEBUG] uvc: Found device that mached uid:'1:5'
2020-05-15 10:09:33,423 - eye1 - [DEBUG] plugin: Plugin <video_capture.uvc_backend.UVC_Source object at 0x7f1b2af2b790> of base class Base_Source will be replaced by UVC_Source.
2020-05-15 10:09:33,430 - eye1 - [DEBUG] uvc: Stream stopped
2020-05-15 10:09:33,464 - eye1 - [DEBUG] uvc: Stream closed
2020-05-15 10:09:33,464 - eye1 - [DEBUG] uvc: Stream stop.
2020-05-15 10:09:33,525 - eye1 - [DEBUG] uvc: UVC device closed.
2020-05-15 10:09:33,526 - eye1 - [DEBUG] plugin: Unloaded Plugin: <video_capture.uvc_backend.UVC_Source object at 0x7f1b2af2b790>
2020-05-15 10:09:33,575 - eye1 - [DEBUG] uvc: Found device that mached uid:'1:5'
2020-05-15 10:09:33,658 - eye1 - [DEBUG] uvc: Device '1:5' opended.
2020-05-15 10:09:33,658 - eye1 - [DEBUG] uvc: avaible video modes: [{'size': (960, 544), 'rates': [29, 25, 23, 14]}, {'size': (1024, 576), 'rates': [29, 25, 23, 14]}, {'size': (960, 720), 'rates': [29, 25, 23, 14]}, {'size': (1280, 720), 'rates': [29, 25, 23, 14]}]
2020-05-15 10:09:33,658 - eye1 - [DEBUG] uvc: Adding "Auto Exposure Mode" control.
2020-05-15 10:09:33,666 - eye1 - [DEBUG] uvc: Adding "Absolute Exposure Time" control.
2020-05-15 10:09:33,679 - eye1 - [DEBUG] uvc: Adding "Backlight Compensation" control.
2020-05-15 10:09:33,693 - eye1 - [DEBUG] uvc: Adding "Brightness" control.
2020-05-15 10:09:33,708 - eye1 - [DEBUG] uvc: Adding "Contrast" control.
2020-05-15 10:09:33,723 - eye1 - [DEBUG] uvc: Adding "Power Line frequency" control.
2020-05-15 10:09:33,731 - eye1 - [DEBUG] uvc: Adding "Hue" control.
2020-05-15 10:09:33,746 - eye1 - [DEBUG] uvc: Adding "Saturation" control.
2020-05-15 10:09:33,761 - eye1 - [DEBUG] uvc: Adding "Sharpness" control.
2020-05-15 10:09:33,776 - eye1 - [DEBUG] uvc: Adding "Gamma" control.
2020-05-15 10:09:33,791 - eye1 - [DEBUG] uvc: Adding "White Balance temperature" control.
2020-05-15 10:09:33,807 - eye1 - [DEBUG] uvc: Adding "White Balance temperature,Auto" control.
2020-05-15 10:09:33,813 - eye1 - [INFO] video_capture.uvc_backend: Hardware timestamps not supported for FaceTime HD Camera (Built-in). Using software timestamps.
2020-05-15 10:09:33,813 - eye1 - [WARNING] video_capture.uvc_backend: [192, 192] resolution capture mode not available. Selected (960, 544).
2020-05-15 10:09:33,823 - eye1 - [INFO] camera_models: No user calibration found for camera FaceTime HD Camera (Built-in) at resolution (960, 544)
2020-05-15 10:09:33,823 - eye1 - [INFO] camera_models: No pre-recorded calibration available
2020-05-15 10:09:33,823 - eye1 - [WARNING] camera_models: Loading dummy calibration
2020-05-15 10:09:33,823 - eye1 - [WARNING] video_capture.uvc_backend: 120fps capture mode not available at ((960, 544)) on 'FaceTime HD Camera (Built-in)'. Selected 29fps. 
2020-05-15 10:09:33,823 - eye1 - [DEBUG] uvc: Setting mode: 960,544,29
2020-05-15 10:09:33,832 - eye1 - [DEBUG] video_capture.uvc_backend: No UVC setting "Auto Exposure Mode" found from settings.
2020-05-15 10:09:33,832 - eye1 - [DEBUG] video_capture.uvc_backend: No UVC setting "Absolute Exposure Time" found from settings.
2020-05-15 10:09:33,832 - eye1 - [DEBUG] video_capture.uvc_backend: No UVC setting "Backlight Compensation" found from settings.
2020-05-15 10:09:33,833 - eye1 - [DEBUG] video_capture.uvc_backend: No UVC setting "Brightness" found from settings.
2020-05-15 10:09:33,833 - eye1 - [DEBUG] video_capture.uvc_backend: No UVC setting "Contrast" found from settings.
2020-05-15 10:09:33,833 - eye1 - [DEBUG] video_capture.uvc_backend: No UVC setting "Power Line frequency" found from settings.
2020-05-15 10:09:33,833 - eye1 - [DEBUG] video_capture.uvc_backend: No UVC setting "Hue" found from settings.
2020-05-15 10:09:33,833 - eye1 - [DEBUG] video_capture.uvc_backend: No UVC setting "Saturation" found from settings.
2020-05-15 10:09:33,833 - eye1 - [DEBUG] video_capture.uvc_backend: No UVC setting "Sharpness" found from settings.
2020-05-15 10:09:33,833 - eye1 - [DEBUG] video_capture.uvc_backend: No UVC setting "Gamma" found from settings.
2020-05-15 10:09:33,833 - eye1 - [DEBUG] video_capture.uvc_backend: No UVC setting "White Balance temperature" found from settings.
2020-05-15 10:09:33,833 - eye1 - [DEBUG] video_capture.uvc_backend: No UVC setting "White Balance temperature,Auto" found from settings.
2020-05-15 10:09:34,079 - eye1 - [ERROR] launchables.eye: Process Eye1 crashed with trace:
Traceback (most recent call last):
  File "pyglui/ui_elements.pxi", line 390, in pyglui.ui.Selector._on_change
ValueError: 3 is not in list

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/home/patrick/work/pupil/pupil_src/launchables/eye.py", line 533, in eye
    notification.get("args", {}),
  File "/home/patrick/work/pupil/pupil_src/shared_modules/plugin.py", line 386, in add
    plugin_instance.init_ui()
  File "/home/patrick/work/pupil/pupil_src/shared_modules/video_capture/base_backend.py", line 104, in init_ui
    self.update_menu()
  File "/home/patrick/work/pupil/pupil_src/shared_modules/video_capture/base_backend.py", line 202, in update_menu
    source_settings = self.ui_elements()
  File "/home/patrick/work/pupil/pupil_src/shared_modules/video_capture/uvc_backend.py", line 812, in ui_elements
    "value", control, label=ctl_name, selection=selection, labels=labels
  File "pyglui/ui_elements.pxi", line 375, in pyglui.ui.Selector.__cinit__
  File "pyglui/ui.pyx", line 332, in pyglui.ui.Synced_Value.__init__
  File "pyglui/ui.pyx", line 367, in pyglui.ui.Synced_Value.sync
  File "pyglui/ui_elements.pxi", line 396, in pyglui.ui.Selector._on_change
ValueError: Synced value '3' is not part of selection.

The error happens when drawing the UI for the UVC control Power Line frequency with: https://github.com/pupil-labs/pupil/blob/b3dda8cba54b2eff9503faa66e126bfce3c7b952/pupil_src/shared_modules/video_capture/uvc_backend.py#L808-L813

The debugger shows:

selection == [0, 1, 2]
labels == ['Disabled', '50Hz', '60Hz']
control.value == 3

which obviously does not work. Not sure if this a bug in pyuvc?

pfaion avatar May 15 '20 08:05 pfaion

pyuvc only defines these three values. It is an implementation of this spec. See Table 4-31 on page 95. My guess is that your webcam uses a newer UVC standard that is not supported by pyuvc.

papr avatar Jul 13 '20 09:07 papr

Indeed it seems we implemented UVC 1.1 from 2005. In 2012 they released UVC 1.5, which includes 3: 'Auto'. Weirdly there seem to be no versions 1.2 to 1.4. See this document, ctrl-f for Table 4-35

I feel like this might be something we should check against?

pfaion avatar Jul 20 '20 06:07 pfaion

I had a quick look and it seems the USB specification includes an InterfaceProtocol for all its interface classes (which UVC is an instance of).

Specifically, UVC 1.1 only has one valid value for this: PC_PROTOCOL_UNDEFINED, see the UVC 1.1 spec. image

UVC 1.5 additionally adds PC_PROTOCOL_15 as value, which seems to indicate that the device communicates over the UVC 1.5 spec. We would have to validate that. See the UVC 1.5 spec. image

We can probably filter for the non-1.5 version in our custom libuvc fork: https://github.com/pupil-labs/libuvc/blob/master/src/device.c#L640-L643

	/* Video, Streaming */
	if (if_desc->bInterfaceClass == 14 && if_desc->bInterfaceSubClass == 2) {
	  got_interface = 1;
	}

There is already some other filtering happening on the libusb_interface_descriptor struct, which contains the uint8_t bInterfaceProtocol member. I can give this a try at some point.

pfaion avatar Jul 24 '20 11:07 pfaion

The question is, if we want to limit our libuvc fork to UVC 1.1 devices, or whether we want to expose this setting to the outside. The second option would require a change to pyuvc and Pupil as well in order to make it work.

pfaion avatar Jul 24 '20 11:07 pfaion

I suggest adding support for that attribute in libuvc, and only accepting UVC 1.1 devices in pyuvc as it does not support later protocol versions. This way we do not need to adjust Pupil.

papr avatar Jul 27 '20 12:07 papr