On Thu, Nov 12, 2026 at 04:46:47PM +0100, Kirill A. Korinsky wrote:
> On Thu, 12 Nov 2026 02:19:14 +0100,
> Kyle Markley <[email protected]> wrote:
> >
> > Hello,
> >
> > For several years I've had a problem that my webcam would work only very
> > intermittently in chromium.?? With the patience to run several
> > experiments and $2.99 of GPT-6.1 Terra, I have what seems to be a robust
> > fix.
> >
> > >Synopsis:?? ?? uvideo queries unsupported boolean control ranges,
> > breaking capture
> > >Category:?? ?? kernel
> > >Environment:
> > ?? System?? ?? ?? : OpenBSD 8.0
> > ?? Details?? ?? ??: OpenBSD 8.0-stable (GENERIC.MP) #6: Wed Nov 11 12:31:55
> > PST 2026
> > ?? Architecture: OpenBSD.amd64
> > ?? Machine?? ?? ??: amd64
> >
> > >Description:
> > ?? Chromium usually fails to start video capture from this USB camera.
> > ?? getUserMedia reports NotReadableError. Chromium logs show that
> > ?? VIDIOC_S_FMT fails with EINVAL, and the kernel reports:
> >
> > ?? uvideo0: could not SET probe request: STALLED
> >
> > ?? The camera works with ffplay, including YUYV at 640x480 and MJPEG
> > ?? ??at 1280x720. Instrumentation showed that uvideo_queryctrl() sends
> > ?? GET_MIN for the automatic white-balance boolean control. The camera
> > ?? stalls that request. Chromium disables automatic white balance during
> > ?? startup, queries its default, and then attempts to restore it. With
> > ?? the unmodified driver, the query fails; subsequent stream negotiation
> > ?? can fail with a stalled probe request. The exact reason the camera
> > ?? then stalls the probe is not established.
> >
> > >How-To-Repeat:
> >
> > ?? On the affected hardware with an unmodified OpenBSD 8.0-stable
> > ?? kernel, open a page in Chromium that calls
> > ?? navigator.mediaDevices.getUserMedia({video: true, audio: false}).
> > ?? Grant camera access. The request usually fails with
> > ?? NotReadableError; the failure is intermittent.
> >
> > ?? As an isolation experiment, rejecting the automatic white-balance
> > ?? query before it reached the camera allowed Chromium capture to work,
> > ?? but hid the control and could leave automatic white balance disabled.
> >
> > >Fix:
> >
> > ?? For V4L2 boolean controls, report minimum 0, maximum 1 and step 1
> > ?? without issuing USB GET_MIN, GET_MAX or GET_RES requests. Continue
> > ?? to obtain the device default with GET_DEF, preserving control
> > ?? operation and error handling. Non-boolean controls are unchanged.
> >
> > ?? With this change, the camera's GET_DEF succeeded, Chromium restored
> > ?? automatic white balance to 1, and 640x480 capture started
> > ?? successfully.
> >
>
> Kyle, thanks for suggested diff.
>
> It reads like the right direction.
>
> But I'd like to use that opportunity to rework a bit the code around.
>
> Does this diff work for you?
Your enhanced diff to simplify the duplicated code looks good to me.
I also did a quick regression test with one of my cams.
ok mglocker@
> Index: sys/dev/usb/uvideo.c
> ===================================================================
> RCS file: /home/cvs/src/sys/dev/usb/uvideo.c,v
> diff -u -p -r1.267 uvideo.c
> --- sys/dev/usb/uvideo.c 19 Oct 2026 18:33:50 -0000 1.267
> +++ sys/dev/usb/uvideo.c 12 Nov 2026 15:12:55 -0000
> @@ -4167,7 +4167,13 @@ int
> uvideo_queryctrl(void *v, struct v4l2_queryctrl *qctrl)
> {
> struct uvideo_softc *sc = v;
> - int i, ret = 0;
> + int32_t *values[] = {
> + &qctrl->minimum,
> + &qctrl->maximum,
> + &qctrl->step,
> + &qctrl->default_value
> + };
> + int i, j, ret = 0;
> usbd_status error;
> uint8_t *ctrl_data;
> uint16_t ctrl_len;
> @@ -4194,89 +4200,37 @@ uvideo_queryctrl(void *v, struct v4l2_qu
> /* set description name */
> strlcpy(qctrl->name, uvideo_ctrls[i].name, sizeof(qctrl->name));
>
> - /* set minimum */
> - error = uvideo_vc_get_ctrl(sc, ctrl_data, GET_MIN,
> - sc->sc_desc_vc_pu_cur->bUnitID,
> - uvideo_ctrls[i].ctrl_selector, uvideo_ctrls[i].ctrl_len);
> - if (error != USBD_NORMAL_COMPLETION) {
> - ret = EINVAL;
> - goto out;
> - }
> - switch (ctrl_len) {
> - case 1:
> - qctrl->minimum = uvideo_ctrls[i].sig ?
> - *(int8_t *)ctrl_data :
> - *ctrl_data;
> - break;
> - case 2:
> - qctrl->minimum = uvideo_ctrls[i].sig ?
> - (int16_t)UGETW(ctrl_data) :
> - UGETW(ctrl_data);
> - break;
> - }
> -
> - /* set maximum */
> - error = uvideo_vc_get_ctrl(sc, ctrl_data, GET_MAX,
> - sc->sc_desc_vc_pu_cur->bUnitID,
> - uvideo_ctrls[i].ctrl_selector, uvideo_ctrls[i].ctrl_len);
> - if (error != USBD_NORMAL_COMPLETION) {
> - ret = EINVAL;
> - goto out;
> - }
> - switch(ctrl_len) {
> - case 1:
> - qctrl->maximum = uvideo_ctrls[i].sig ?
> - *(int8_t *)ctrl_data :
> - *ctrl_data;
> - break;
> - case 2:
> - qctrl->maximum = uvideo_ctrls[i].sig ?
> - (int16_t)UGETW(ctrl_data) :
> - UGETW(ctrl_data);
> - break;
> - }
> -
> - /* set resolution */
> - error = uvideo_vc_get_ctrl(sc, ctrl_data, GET_RES,
> - sc->sc_desc_vc_pu_cur->bUnitID,
> - uvideo_ctrls[i].ctrl_selector, uvideo_ctrls[i].ctrl_len);
> - if (error != USBD_NORMAL_COMPLETION) {
> - ret = EINVAL;
> - goto out;
> - }
> - switch(ctrl_len) {
> - case 1:
> - qctrl->step = uvideo_ctrls[i].sig ?
> - *(int8_t *)ctrl_data:
> - *ctrl_data;
> - break;
> - case 2:
> - qctrl->step = uvideo_ctrls[i].sig ?
> - (int16_t)UGETW(ctrl_data) :
> - UGETW(ctrl_data);
> - break;
> - }
> -
> - /* set default */
> - error = uvideo_vc_get_ctrl(sc, ctrl_data, GET_DEF,
> - sc->sc_desc_vc_pu_cur->bUnitID,
> - uvideo_ctrls[i].ctrl_selector, uvideo_ctrls[i].ctrl_len);
> - if (error != USBD_NORMAL_COMPLETION) {
> - ret = EINVAL;
> - goto out;
> - }
> - switch(ctrl_len) {
> - case 1:
> - qctrl->default_value = uvideo_ctrls[i].sig ?
> - *(int8_t *)ctrl_data :
> - *ctrl_data;
> - break;
> - case 2:
> - qctrl->default_value = uvideo_ctrls[i].sig ?
> - (int16_t)UGETW(ctrl_data) :
> - UGETW(ctrl_data);
> - break;
> - }
> + for (j = 0; j < nitems(uvideo_ctrls[i].query); j++) {
> + if (uvideo_ctrls[i].query[j].request == 0) {
> + *values[j] = uvideo_ctrls[i].query[j].value;
> + continue;
> + }
> +
> + error = uvideo_vc_get_ctrl(sc, ctrl_data,
> + uvideo_ctrls[i].query[j].request,
> + sc->sc_desc_vc_pu_cur->bUnitID,
> + uvideo_ctrls[i].ctrl_selector, ctrl_len);
> + if (error != USBD_NORMAL_COMPLETION) {
> + ret = EINVAL;
> + goto out;
> + }
> + switch (ctrl_len) {
> + case 1:
> + *values[j] = uvideo_ctrls[i].sig ?
> + *(int8_t *)ctrl_data :
> + *ctrl_data;
> + break;
> + case 2:
> + *values[j] = uvideo_ctrls[i].sig ?
> + (int16_t)UGETW(ctrl_data) :
> + UGETW(ctrl_data);
> + break;
> + }
> + }
> +
> + if (uvideo_ctrls[i].ctrl_selector == PU_POWER_LINE_FREQUENCY_CONTROL &&
> + UGETW(sc->sc_desc_vc_header.fix->bcdUVC) >= 0x0150)
> + qctrl->maximum = 3;
>
> /* set flags */
> qctrl->flags = 0;
> @@ -4335,7 +4289,7 @@ uvideo_g_ctrl(void *v, struct v4l2_contr
> out:
> free(ctrl_data, M_USBDEV, ctrl_len);
>
> - return (0);
> + return (ret);
> }
>
> int
> Index: sys/dev/usb/uvideo.h
> ===================================================================
> RCS file: /home/cvs/src/sys/dev/usb/uvideo.h,v
> diff -u -p -r1.71 uvideo.h
> --- sys/dev/usb/uvideo.h 6 Sep 2025 13:45:41 -0000 1.71
> +++ sys/dev/usb/uvideo.h 12 Nov 2026 15:12:55 -0000
> @@ -688,6 +688,19 @@ struct uvideo_res {
> int fidx;
> };
>
> +struct uvideo_ctrl_query {
> + uint8_t request;
> + int32_t value;
> +};
> +
> +#define UVIDEO_CTRL_RANGE \
> + { { GET_MIN, 0 }, { GET_MAX, 0 }, \
> + { GET_RES, 0 }, { GET_DEF, 0 } }
> +#define UVIDEO_CTRL_AUTO \
> + { { 0, 0 }, { 0, 1 }, { 0, 1 }, { GET_DEF, 0 } }
> +#define UVIDEO_CTRL_POWER_LINE \
> + { { 0, 0 }, { 0, 2 }, { 0, 1 }, { GET_DEF, 0 } }
> +
> struct uvideo_controls {
> int cid;
> int type;
> @@ -696,6 +709,7 @@ struct uvideo_controls {
> uint16_t ctrl_selector;
> uint16_t ctrl_len;
> int sig;
> + struct uvideo_ctrl_query query[4]; /* min, max, step, default */
> } uvideo_ctrls[] = {
> /*
> * Processing Unit Controls
> @@ -707,7 +721,8 @@ struct uvideo_controls {
> 0,
> PU_BRIGHTNESS_CONTROL,
> 2,
> - 1
> + 1,
> + UVIDEO_CTRL_RANGE
> },
> {
> V4L2_CID_CONTRAST,
> @@ -716,7 +731,8 @@ struct uvideo_controls {
> 1,
> PU_CONTRAST_CONTROL,
> 2,
> - 0
> + 0,
> + UVIDEO_CTRL_RANGE
> },
> {
> V4L2_CID_HUE,
> @@ -725,7 +741,8 @@ struct uvideo_controls {
> 2,
> PU_HUE_CONTROL,
> 2,
> - 1
> + 1,
> + UVIDEO_CTRL_RANGE
> },
> {
> V4L2_CID_SATURATION,
> @@ -734,7 +751,8 @@ struct uvideo_controls {
> 3,
> PU_SATURATION_CONTROL,
> 2,
> - 0
> + 0,
> + UVIDEO_CTRL_RANGE
> },
> {
> V4L2_CID_SHARPNESS,
> @@ -743,7 +761,8 @@ struct uvideo_controls {
> 4,
> PU_SHARPNESS_CONTROL,
> 2,
> - 0
> + 0,
> + UVIDEO_CTRL_RANGE
> },
> {
> V4L2_CID_GAMMA,
> @@ -752,7 +771,8 @@ struct uvideo_controls {
> 5,
> PU_GAMMA_CONTROL,
> 2,
> - 0
> + 0,
> + UVIDEO_CTRL_RANGE
> },
> {
> V4L2_CID_WHITE_BALANCE_TEMPERATURE,
> @@ -761,7 +781,8 @@ struct uvideo_controls {
> 6,
> PU_WHITE_BALANCE_TEMPERATURE_CONTROL,
> 2,
> - 0
> + 0,
> + UVIDEO_CTRL_RANGE
> },
> #if 0
> /* XXX Two V4L2 ids mapping one UVC control */
> @@ -782,7 +803,8 @@ struct uvideo_controls {
> 8,
> PU_BACKLIGHT_COMPENSATION_CONTROL,
> 2,
> - 0
> + 0,
> + UVIDEO_CTRL_RANGE
> },
> {
> V4L2_CID_GAIN,
> @@ -791,7 +813,8 @@ struct uvideo_controls {
> 9,
> PU_GAIN_CONTROL,
> 2,
> - 0
> + 0,
> + UVIDEO_CTRL_RANGE
> },
> {
> V4L2_CID_POWER_LINE_FREQUENCY,
> @@ -799,8 +822,9 @@ struct uvideo_controls {
> "Power Line Frequency",
> 10,
> PU_POWER_LINE_FREQUENCY_CONTROL,
> - 2,
> - 0
> + 1,
> + 0,
> + UVIDEO_CTRL_POWER_LINE
> },
> {
> V4L2_CID_HUE_AUTO,
> @@ -809,7 +833,8 @@ struct uvideo_controls {
> 11,
> PU_HUE_AUTO_CONTROL,
> 1,
> - 0
> + 0,
> + UVIDEO_CTRL_AUTO
> },
> {
> V4L2_CID_AUTO_WHITE_BALANCE,
> @@ -818,7 +843,8 @@ struct uvideo_controls {
> 12,
> PU_WHITE_BALANCE_TEMPERATURE_AUTO_CONTROL,
> 1,
> - 0
> + 0,
> + UVIDEO_CTRL_AUTO
> },
> {
> V4L2_CID_AUTO_WHITE_BALANCE,
> @@ -827,7 +853,8 @@ struct uvideo_controls {
> 13,
> PU_WHITE_BALANCE_COMPONENT_AUTO_CONTROL,
> 1,
> - 0
> + 0,
> + UVIDEO_CTRL_AUTO
> },
> #if 0
> /* XXX No V4L2 CID for these controls? */
> @@ -868,5 +895,5 @@ struct uvideo_controls {
> 0
> },
> #endif
> - { 0, 0, "", 0, 0, 0, 0 }
> + { 0, 0, "", 0, 0, 0, 0, { { 0, 0 } } }
> };
>
>
> --
> wbr, Kirill
>