Bug 252327 - multimedia/v4l-utils: v4l2-ctl can't determine the device type
Summary: multimedia/v4l-utils: v4l2-ctl can't determine the device type
Status: Closed FIXED
Alias: None
Product: Ports & Packages
Classification: Unclassified
Component: Individual Port(s) (show other bugs)
Version: Latest
Hardware: Any Any
: --- Affects Some People
Assignee: freebsd-multimedia (Nobody)
Depends on:
Reported: 2021-01-01 14:14 UTC by Trenton Schulz
Modified: 2021-04-21 16:33 UTC (History)
3 users (show)

See Also:
bugzilla: maintainer-feedback? (multimedia)

Patch submitted upstream (1.76 KB, patch)
2021-04-04 14:08 UTC, Trenton Schulz
no flags Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Trenton Schulz 2021-01-01 14:14:47 UTC
v4l2-ctl allows you to set options on a web camera. For example, changing the power line frequency to 50 Hz to get rid of flicker with lights in Europe.

Unfortunately, it seems that v4l2-ctl can't determine the device type. Running it with any sort of webcam produces the following:

v4l2-ctl -L
Unable to detect what device /dev/video0 is, exiting.

Looking at the source code it seems that mi_media_detect_type() in media-info.cpp is using the Linux sysfs and uevent to get information about the device type. This information doesn't exist on FreeBSD (at least not in that form).

If one hardcodes(!) the type to MEDIA_TYPE_VIDEO, the information does show up:

./v4l2-ctl -L
                     brightness 0x00980900 (int)    : min=0 max=255 step=1 default=128 value=128
                       contrast 0x00980901 (int)    : min=0 max=255 step=1 default=128 value=128
                     saturation 0x00980902 (int)    : min=0 max=255 step=1 default=128 value=128
 white_balance_temperature_auto 0x0098090c (bool)   : default=1 value=1
                           gain 0x00980913 (int)    : min=0 max=255 step=1 default=0 value=136
           power_line_frequency 0x00980918 (menu)   : min=0 max=2 default=2 value=1
                                0: Disabled
                                1: 50 Hz
                                2: 60 Hz
      white_balance_temperature 0x0098091a (int)    : min=2000 max=6500 step=1 default=4000 value=3385 flags=inactive
                      sharpness 0x0098091b (int)    : min=0 max=255 step=1 default=128 value=128
         backlight_compensation 0x0098091c (int)    : min=0 max=1 step=1 default=0 value=0
                  exposure_auto 0x009a0901 (menu)   : min=0 max=3 default=3 value=3
                                1: Manual Mode
                                3: Aperture Priority Mode
              exposure_absolute 0x009a0902 (int)    : min=3 max=2047 step=1 default=250 value=299 flags=inactive
         exposure_auto_priority 0x009a0903 (bool)   : default=0 value=1
                   pan_absolute 0x009a0908 (int)    : min=-36000 max=36000 step=3600 default=0 value=0
                  tilt_absolute 0x009a0909 (int)    : min=-36000 max=36000 step=3600 default=0 value=0
                 focus_absolute 0x009a090a (int)    : min=0 max=250 step=5 default=0 value=50 flags=inactive
                     focus_auto 0x009a090c (bool)   : default=1 value=1
                  zoom_absolute 0x009a090d (int)    : min=100 max=500 step=1 default=100 value=100

Naturally, hard coding this value is not a permanent solution, but it does show that things work afterwards. There are still issues in setting values (getsubopt returns differently), but the first step is to get the items to recognize correctly.
Comment 1 Hans Petter Selasky freebsd_committer 2021-01-01 14:17:17 UTC
If you want to work on this, feel free to make a proper patch on top of:



Currently, the code only compiles and I did not test all the utilities when doing the porting:

Comment 2 Trenton Schulz 2021-01-03 15:14:49 UTC
Thanks for the info. I can try and take a look. How would I get this information from the driver? It seems that usbconfig can provide some of that information, but if there are some manpages or headers that I could look at, that would help.
Comment 3 Hans Petter Selasky freebsd_committer 2021-01-03 18:49:34 UTC
I'm not sure. Maybe a command line parameter, or some magic based on the device name is required.

There are many IOCTLs supported by these devices, and maybe just trial and error will work too.
Comment 4 Trenton Schulz 2021-04-02 13:38:53 UTC
I finally had a little time to look at this and created a pull request here:


This seems to get what I want, but if there are better ways to do things. I am happy to discuss (here or in the pull request).
Comment 5 Trenton Schulz 2021-04-04 14:08:47 UTC
Created attachment 223802 [details]
Patch submitted upstream

Including the patch here in case others want to use it.
Comment 6 Trenton Schulz 2021-04-21 16:33:20 UTC
Fixed by commit 3a28080660e54a820fd7eedfae8ec768945d223c