diff --git a/src/v4l2.c b/src/v4l2.c index 5267072..d881cbe 100644 --- a/src/v4l2.c +++ b/src/v4l2.c @@ -447,12 +447,42 @@ static int v4l2_ioctl_controls(int video_fd, int request_fd, unsigned long ioc, rc = ioctl(video_fd, ioc, &controls); if (rc < 0 && errno == EINVAL && ioc == VIDIOC_S_EXT_CTRLS) { - request_log("S_EXT_CTRLS EINVAL: num_controls=%u error_idx=%u\n", + int saved_errno = errno; + request_log("S_EXT_CTRLS EINVAL: num_controls=%u error_idx=%u (count = obfuscated)\n", num_controls, controls.error_idx); for (unsigned int i = 0; i < num_controls; i++) { request_log(" ctrl[%u]: id=0x%08x size=%u\n", i, control_array[i].id, control_array[i].size); } + /* + * Retry with VIDIOC_TRY_EXT_CTRLS — kernel comment in + * v4l2-ctrls-api.c:222-224 says TRY_EXT_CTRLS "never modifies + * controls [so] error_idx is just set to whatever control has + * an invalid value." Unlike S_EXT_CTRLS which deliberately + * obfuscates by setting error_idx = count. + */ + struct v4l2_ext_controls try_controls; + memset(&try_controls, 0, sizeof(try_controls)); + try_controls.controls = control_array; + try_controls.count = num_controls; + if (request_fd >= 0) { + try_controls.which = V4L2_CTRL_WHICH_REQUEST_VAL; + try_controls.request_fd = request_fd; + } + int try_rc = ioctl(video_fd, VIDIOC_TRY_EXT_CTRLS, &try_controls); + if (try_rc < 0) { + request_log(" TRY_EXT_CTRLS retry: errno=%d (%s) error_idx=%u\n", + errno, strerror(errno), try_controls.error_idx); + if (try_controls.error_idx < num_controls) { + request_log(" --> failing control is ctrl[%u]: id=0x%08x size=%u\n", + try_controls.error_idx, + control_array[try_controls.error_idx].id, + control_array[try_controls.error_idx].size); + } + } else { + request_log(" TRY_EXT_CTRLS retry: passed (S vs TRY semantics differ — likely cluster commit)\n"); + } + errno = saved_errno; } return rc; }