* [PATCH] media: uvcvideo: query pan/tilt position from the device on every read
@ 2026-07-25 21:23 Michael Jordan
2026-07-31 8:33 ` Ricardo Ribalda
0 siblings, 1 reply; 9+ messages in thread
From: Michael Jordan @ 2026-07-25 21:23 UTC (permalink / raw)
To: Laurent Pinchart, Hans de Goede, Mauro Carvalho Chehab
Cc: linux-media, linux-kernel, Michael Jordan
CT_PANTILT_ABSOLUTE_CONTROL reports the position of a mechanical actuator.
On a motorised PTZ camera that position keeps changing for as long as the
movement takes -- seconds -- and it can change with no host involvement at
all when the camera repositions itself. The driver caches the value and
serves VIDIOC_G_CTRL from that cache, so userspace cannot observe the
movement.
The cache is invalidated in only two places: uvc_ctrl_commit_entity(),
which clears it for auto-update controls when the driver commits a
SET_CUR, and uvc_ctrl_status_event(), on receipt of a Control Change
interrupt. Neither covers a move that is under way. The first G_CTRL after
a write does reach the device, but it then sets ctrl->loaded and every
subsequent read returns that one sample unchanged until the move ends.
An application polling the position sees a single value frozen for the
duration of the movement.
The Control Change interrupt does not fill the gap, because the mechanism
is event-shaped and the quantity is continuous. UVC 1.5 section 4.2.2.1.15
states that a SET_CUR to the Relative control "shall result in a Control
Change interrupt for the Absolute Control at the end of the movement".
Nothing is defined for the interval in between, and no reasonable firmware
would emit interrupts at frame rate for the length of a pan sweep. A fully
compliant device therefore leaves the cached value stale for the whole of
every move; this is a property of the control, not of any one vendor.
Add UVC_CTRL_FLAG_VOLATILE for controls whose value varies on its own, set
it on CT_PANTILT_ABSOLUTE_CONTROL, and query the device on every read of
such a control.
The live value is kept in a buffer of its own rather than in
UVC_CTRL_DATA_CURRENT, which continues to hold the value last commanded by
the host. That distinction matters because a single UVC control carries
both axes: the pan and tilt V4L2 controls map to 32-bit fields of one
8-byte control, so uvc_ctrl_set() performs a read-modify-write to preserve
the axis the caller is not writing. Were that path given a live reading, a
tilt write issued a few milliseconds after a pan command would rewrite pan
with the position the actuator had not yet left, cancelling the move in
progress. Keeping the buffers separate leaves the write path untouched.
Values staged by uvc_ctrl_set() but not yet committed take precedence over
a live read, so that reading a control back inside an uncommitted
transaction returns what the caller wrote.
Report V4L2_CTRL_FLAG_VOLATILE for such controls, so applications know the
value must not be cached and that the value read back need not match the
value last written. Since writes to a volatile control are documented to be
ignored unless V4L2_CTRL_FLAG_EXECUTE_ON_WRITE is also reported, and the
driver propagates every write of a writable control to the device, report
that flag alongside it when the control supports SET_CUR. This is the same
pairing the control framework uses for a manual gain control while autogain
is active.
Measured on an OBSBOT Tiny 2 (3564:fef8) with this patch applied, polling
VIDIOC_G_CTRL on V4L2_CID_PAN_ABSOLUTE while a 0 to 90 degree pan was in
flight (values in arc seconds, as reported):
t+109ms pan=0
t+284ms pan=18000
t+459ms pan=61200
t+811ms pan=129600
t+1161ms pan=198000
t+1513ms pan=280800
t+1690ms pan=324000 (physical arrival, steady thereafter)
Without the patch the same loop returns one unchanging value for the whole
sweep. A raw libusb GET_CUR trace taken with the driver detached shows the
same progression, confirming the driver now reports what the device was
always able to tell it.
The read-modify-write hazard described above was tested explicitly:
S_CTRL(pan=90 degrees) and S_CTRL(tilt=20 degrees) issued as separate
ioctls 18ms apart, with pan still reading 0 when the tilt write was
submitted, leaves both axes at their commanded targets (pan=324000,
tilt=72000). The pan movement is not cancelled.
The cost is one control transfer per read of an affected control. Polling
the control at 5 Hz concurrently with an active 30 fps capture on this
device showed no frame loss and no change in frame rate. On a device that
merely echoes back the last setpoint the extra transfer buys nothing, which
is why the flag is set on pan/tilt alone. Zoom, focus, roll and iris
absolute share the same character and may warrant the same treatment, but
are left alone here as they have not been tested.
Signed-off-by: Michael Jordan <jordan.mymail@gmail.com>
---
Notes:
Notes for reviewers; not intended for the commit log.
- UVC_CTRL_FLAG_VOLATILE is defined in include/uapi/linux/uvcvideo.h beside
the other UVC_CTRL_FLAG_* values, even though struct
uvc_xu_control_mapping has no flags member and userspace therefore cannot
set it. Keeping the whole flag namespace in one header seemed safer than
splitting it, since a later addition of bit 9 on the uapi side would
otherwise collide silently with a driver-private definition. I am happy
to move it to drivers/media/usb/uvc/uvcvideo.h if you would rather uapi
did not grow for a bit userspace cannot use.
- uvc_mapping_get_xctrl_compound() still reads UVC_CTRL_DATA_CURRENT and is
deliberately left alone. No compound control is flagged volatile, so
there is no bug today, but that is the second place this would need
wiring if the flag is ever applied to one.
- Only CT_PANTILT_ABSOLUTE_CONTROL is flagged here. Zoom, focus, roll and
iris absolute share the same character, a mechanical actuator whose
position lags its setpoint, and focus absolute under continuous autofocus
is arguably the more widespread case. I have not flagged them because
pan/tilt is what I can exercise on the hardware I have, and widening this
adds a control transfer per read across a great many devices. Glad to
extend it if you think the argument carries.
- Reading pan and tilt in one G_EXT_CTRLS call now issues one GET_CUR per
mapping, so the two values can come from instants roughly a millisecond
apart, where previously both decoded from a single cached sample. The
skew seemed inherent to polling a moving actuator and not worth a
per-ioctl generation scheme to share the transfer; flagging it in case
you weigh that differently.
- Testing: built and run on v7.2-rc4 (mainline); the posted patch is
rebased onto media.git next and compile-tested there. Hardware is an
OBSBOT Tiny 2 (3564:fef8). Verified that a live read tracks a physical
slew; that two single-axis writes issued ~20ms apart both reach their
targets, which is the read-modify-write regression the separate buffer
exists to avoid; that pan/tilt report V4L2_CTRL_FLAG_VOLATILE and
V4L2_CTRL_FLAG_EXECUTE_ON_WRITE while zoom reports neither; and that
polling position at 5 Hz during an active 30 fps capture costs no
frames. v4l2-compliance results are identical with and without the patch
on this device (45/47, the two failures being the camera reporting a
Power Line Frequency default outside its own min/max, present in both
runs). Also checked an integrated UVC 1.00 webcam (1bcf:28cc) with no
pan/tilt, to confirm ordinary devices are unaffected.
drivers/media/usb/uvc/uvc_ctrl.c | 57 +++++++++++++++++++++++++++++---
include/uapi/linux/uvcvideo.h | 2 ++
2 files changed, 55 insertions(+), 4 deletions(-)
diff --git a/drivers/media/usb/uvc/uvc_ctrl.c b/drivers/media/usb/uvc/uvc_ctrl.c
index 3ca108b83..c6e0c9958 100644
--- a/drivers/media/usb/uvc/uvc_ctrl.c
+++ b/drivers/media/usb/uvc/uvc_ctrl.c
@@ -30,7 +30,8 @@
#define UVC_CTRL_DATA_MAX 3
#define UVC_CTRL_DATA_RES 4
#define UVC_CTRL_DATA_DEF 5
-#define UVC_CTRL_DATA_LAST 6
+#define UVC_CTRL_DATA_LIVE 6
+#define UVC_CTRL_DATA_LAST 7
/* ------------------------------------------------------------------------
* Controls
@@ -302,7 +303,8 @@ static const struct uvc_control_info uvc_ctrls[] = {
.flags = UVC_CTRL_FLAG_SET_CUR
| UVC_CTRL_FLAG_GET_RANGE
| UVC_CTRL_FLAG_RESTORE
- | UVC_CTRL_FLAG_AUTO_UPDATE,
+ | UVC_CTRL_FLAG_AUTO_UPDATE
+ | UVC_CTRL_FLAG_VOLATILE,
},
{
.entity = UVC_GUID_UVC_CAMERA,
@@ -1499,22 +1501,58 @@ static int __uvc_ctrl_load_cur(struct uvc_video_chain *chain,
return ret;
}
+/*
+ * Query the device for the current value of a volatile control, storing it in
+ * a buffer of its own. UVC_CTRL_DATA_CURRENT is deliberately left alone: it
+ * holds the value last commanded by the host, which is what the
+ * read-modify-write path in uvc_ctrl_set() must use to preserve the fields of
+ * a multi-field control that the caller is not writing.
+ */
+static int __uvc_ctrl_load_live(struct uvc_video_chain *chain,
+ struct uvc_control *ctrl)
+{
+ u8 *data = uvc_ctrl_data(ctrl, UVC_CTRL_DATA_LIVE);
+
+ if (ctrl->entity->get_cur)
+ return ctrl->entity->get_cur(chain->dev, ctrl->entity,
+ ctrl->info.selector, data,
+ ctrl->info.size);
+
+ return uvc_query_ctrl(chain->dev, UVC_GET_CUR, ctrl->entity->id,
+ chain->dev->intfnum, ctrl->info.selector, data,
+ ctrl->info.size);
+}
+
static int __uvc_ctrl_get(struct uvc_video_chain *chain,
struct uvc_control *ctrl,
struct uvc_control_mapping *mapping,
s32 *value)
{
+ int id = UVC_CTRL_DATA_CURRENT;
int ret;
if ((ctrl->info.flags & UVC_CTRL_FLAG_GET_CUR) == 0)
return -EACCES;
- ret = __uvc_ctrl_load_cur(chain, ctrl);
+ /*
+ * A volatile control tracks a quantity that varies without host
+ * intervention, so the cache cannot be trusted and the device is
+ * queried on every read. Values staged by uvc_ctrl_set() but not yet
+ * committed take precedence, so that reading back a control inside an
+ * uncommitted transaction returns what the caller just wrote.
+ */
+ if ((ctrl->info.flags & UVC_CTRL_FLAG_VOLATILE) && !ctrl->dirty) {
+ ret = __uvc_ctrl_load_live(chain, ctrl);
+ id = UVC_CTRL_DATA_LIVE;
+ } else {
+ ret = __uvc_ctrl_load_cur(chain, ctrl);
+ }
+
if (ret < 0)
return ret;
*value = uvc_mapping_get_s32(mapping, UVC_GET_CUR,
- uvc_ctrl_data(ctrl, UVC_CTRL_DATA_CURRENT));
+ uvc_ctrl_data(ctrl, id));
return 0;
}
@@ -1840,6 +1878,17 @@ static int __uvc_query_v4l2_ctrl(struct uvc_video_chain *chain,
if ((ctrl->info.flags & UVC_CTRL_FLAG_GET_MAX) &&
(ctrl->info.flags & UVC_CTRL_FLAG_GET_MIN))
v4l2_ctrl->flags |= V4L2_CTRL_FLAG_HAS_WHICH_MIN_MAX;
+ if (ctrl->info.flags & UVC_CTRL_FLAG_VOLATILE) {
+ v4l2_ctrl->flags |= V4L2_CTRL_FLAG_VOLATILE;
+ /*
+ * Writes to a volatile control are documented to be ignored
+ * unless EXECUTE_ON_WRITE is also reported. The driver
+ * propagates every write of a writable control to the device,
+ * so report the flag accordingly.
+ */
+ if (ctrl->info.flags & UVC_CTRL_FLAG_SET_CUR)
+ v4l2_ctrl->flags |= V4L2_CTRL_FLAG_EXECUTE_ON_WRITE;
+ }
if (mapping->master_id)
__uvc_find_control(ctrl->entity, mapping->master_id,
diff --git a/include/uapi/linux/uvcvideo.h b/include/uapi/linux/uvcvideo.h
index cbe15bca9..b22fee8af 100644
--- a/include/uapi/linux/uvcvideo.h
+++ b/include/uapi/linux/uvcvideo.h
@@ -31,6 +31,8 @@
#define UVC_CTRL_FLAG_AUTO_UPDATE (1 << 7)
/* Control supports asynchronous reporting */
#define UVC_CTRL_FLAG_ASYNCHRONOUS (1 << 8)
+/* Control tracks a value that varies on its own; never serve it from cache. */
+#define UVC_CTRL_FLAG_VOLATILE (1 << 9)
#define UVC_CTRL_FLAG_GET_RANGE \
(UVC_CTRL_FLAG_GET_CUR | UVC_CTRL_FLAG_GET_MIN | \
base-commit: a52e6f7923c17a672135b485ffd96fbd72f46267
--
2.43.0
^ permalink raw reply [flat|nested] 9+ messages in thread* Re: [PATCH] media: uvcvideo: query pan/tilt position from the device on every read 2026-07-25 21:23 [PATCH] media: uvcvideo: query pan/tilt position from the device on every read Michael Jordan @ 2026-07-31 8:33 ` Ricardo Ribalda 2026-07-31 15:15 ` Michael Jordan 0 siblings, 1 reply; 9+ messages in thread From: Ricardo Ribalda @ 2026-07-31 8:33 UTC (permalink / raw) To: Michael Jordan Cc: Laurent Pinchart, Hans de Goede, Mauro Carvalho Chehab, linux-media, linux-kernel Dear Michael Jordan (I always wanted to start an email like that :P) Thanks for your patch On Sat, 25 Jul 2026 at 23:23, Michael Jordan <jordan.mymail@gmail.com> wrote: > > CT_PANTILT_ABSOLUTE_CONTROL reports the position of a mechanical actuator. > On a motorised PTZ camera that position keeps changing for as long as the > movement takes -- seconds -- and it can change with no host involvement at > all when the camera repositions itself. The driver caches the value and > serves VIDIOC_G_CTRL from that cache, so userspace cannot observe the > movement. I am not against the idea proposed by this patch, but I would like to understand your use case a bit better. Do you want to know where the camera is because: - You want to do something continuously with that info (e.g., tagging frames with the live position)? - Or because you just want to know when the camera has actually finished moving? If it is the latter, you could use V4L2 control events. That should work perfectly for signalling the end of a move: https://www.kernel.org/doc/html/v4.9/media/kapi/v4l2-event.html You also mentioned that the camera can reposition itself. Do you mean that the camera could be tracking something and decide to move on its own? We do not currently support that well, but we should. The problem is that autonomous movement actually breaks the separate-buffer logic proposed in your patch. Let's think of a camera with PAN and TILT: - We set PAN and TILT to (100, 100). (And UVC_CTRL_DATA_CURRENT is set to those values). - The camera arrives at (100, 100). - The camera moves on its own to (200, 200) to track a subject. - You want to change the TILT and only the TILT, so you send a command to set it to 300. - Because your patch uses UVC_CTRL_DATA_CURRENT for the read-modify-write path, the control will send (100, 300). That will unintentionally move both axes, yanking the PAN back to 100 and fighting the camera's autonomous tracking. What I think we should do instead is manage the cache validity based on who "owns" the control. For ASYNCHRONOUS controls that have an active handle (i.e., a user-commanded move that has not completed), we mark them as "loaded". But when they are owned/updated by the device autonomously, we never mark them as loaded. This specific logic still doesn't support polling the live mid-flight position of a user-commanded move, but maybe V4L2 events can cover your actual use case? Let me know what you think. Here is some horrible pseudo-code for inspiration, which has not been tested and does not even compile, just to hopefully explain better what I meant in the text. diff --git a/drivers/media/usb/uvc/uvc_ctrl.c b/drivers/media/usb/uvc/uvc_ctrl.c index 3ca108b83f1d..9ba16fc506ef 100644 --- a/drivers/media/usb/uvc/uvc_ctrl.c +++ b/drivers/media/usb/uvc/uvc_ctrl.c @@ -1494,7 +1494,8 @@ static int __uvc_ctrl_load_cur(struct uvc_video_chain *chain, if (ret < 0) return ret; - ctrl->loaded = 1; + if (!FLAG_AUTO_UPDATE) + ctrl->loaded = 1; return ret; } @@ -2427,7 +2428,8 @@ static int uvc_ctrl_commit_entity(struct uvc_device *dev, * explicitly set by the user. */ if (ctrl->info.flags & UVC_CTRL_FLAG_AUTO_UPDATE || - !(ctrl->info.flags & UVC_CTRL_FLAG_GET_CUR)) + !(ctrl->info.flags & UVC_CTRL_FLAG_GET_CUR) && + phandle_not_set) // data is_not_flying ctrl->loaded = 0; if (!ctrl->dirty) > > The cache is invalidated in only two places: uvc_ctrl_commit_entity(), > which clears it for auto-update controls when the driver commits a > SET_CUR, and uvc_ctrl_status_event(), on receipt of a Control Change > interrupt. Neither covers a move that is under way. The first G_CTRL after > a write does reach the device, but it then sets ctrl->loaded and every > subsequent read returns that one sample unchanged until the move ends. > An application polling the position sees a single value frozen for the > duration of the movement. > > The Control Change interrupt does not fill the gap, because the mechanism > is event-shaped and the quantity is continuous. UVC 1.5 section 4.2.2.1.15 > states that a SET_CUR to the Relative control "shall result in a Control > Change interrupt for the Absolute Control at the end of the movement". > Nothing is defined for the interval in between, and no reasonable firmware > would emit interrupts at frame rate for the length of a pan sweep. A fully > compliant device therefore leaves the cached value stale for the whole of > every move; this is a property of the control, not of any one vendor. > > Add UVC_CTRL_FLAG_VOLATILE for controls whose value varies on its own, set > it on CT_PANTILT_ABSOLUTE_CONTROL, and query the device on every read of > such a control. > > The live value is kept in a buffer of its own rather than in > UVC_CTRL_DATA_CURRENT, which continues to hold the value last commanded by > the host. That distinction matters because a single UVC control carries > both axes: the pan and tilt V4L2 controls map to 32-bit fields of one > 8-byte control, so uvc_ctrl_set() performs a read-modify-write to preserve > the axis the caller is not writing. Were that path given a live reading, a > tilt write issued a few milliseconds after a pan command would rewrite pan > with the position the actuator had not yet left, cancelling the move in > progress. Keeping the buffers separate leaves the write path untouched. > > Values staged by uvc_ctrl_set() but not yet committed take precedence over > a live read, so that reading a control back inside an uncommitted > transaction returns what the caller wrote. > > Report V4L2_CTRL_FLAG_VOLATILE for such controls, so applications know the > value must not be cached and that the value read back need not match the > value last written. Since writes to a volatile control are documented to be > ignored unless V4L2_CTRL_FLAG_EXECUTE_ON_WRITE is also reported, and the > driver propagates every write of a writable control to the device, report > that flag alongside it when the control supports SET_CUR. This is the same > pairing the control framework uses for a manual gain control while autogain > is active. > > Measured on an OBSBOT Tiny 2 (3564:fef8) with this patch applied, polling > VIDIOC_G_CTRL on V4L2_CID_PAN_ABSOLUTE while a 0 to 90 degree pan was in > flight (values in arc seconds, as reported): > > t+109ms pan=0 > t+284ms pan=18000 > t+459ms pan=61200 > t+811ms pan=129600 > t+1161ms pan=198000 > t+1513ms pan=280800 > t+1690ms pan=324000 (physical arrival, steady thereafter) > > Without the patch the same loop returns one unchanging value for the whole > sweep. A raw libusb GET_CUR trace taken with the driver detached shows the > same progression, confirming the driver now reports what the device was > always able to tell it. > > The read-modify-write hazard described above was tested explicitly: > S_CTRL(pan=90 degrees) and S_CTRL(tilt=20 degrees) issued as separate > ioctls 18ms apart, with pan still reading 0 when the tilt write was > submitted, leaves both axes at their commanded targets (pan=324000, > tilt=72000). The pan movement is not cancelled. > > The cost is one control transfer per read of an affected control. Polling > the control at 5 Hz concurrently with an active 30 fps capture on this > device showed no frame loss and no change in frame rate. On a device that > merely echoes back the last setpoint the extra transfer buys nothing, which > is why the flag is set on pan/tilt alone. Zoom, focus, roll and iris > absolute share the same character and may warrant the same treatment, but > are left alone here as they have not been tested. > > Signed-off-by: Michael Jordan <jordan.mymail@gmail.com> > --- > > Notes: > Notes for reviewers; not intended for the commit log. > > - UVC_CTRL_FLAG_VOLATILE is defined in include/uapi/linux/uvcvideo.h beside > the other UVC_CTRL_FLAG_* values, even though struct > uvc_xu_control_mapping has no flags member and userspace therefore cannot > set it. Keeping the whole flag namespace in one header seemed safer than > splitting it, since a later addition of bit 9 on the uapi side would > otherwise collide silently with a driver-private definition. I am happy > to move it to drivers/media/usb/uvc/uvcvideo.h if you would rather uapi > did not grow for a bit userspace cannot use. > > - uvc_mapping_get_xctrl_compound() still reads UVC_CTRL_DATA_CURRENT and is > deliberately left alone. No compound control is flagged volatile, so > there is no bug today, but that is the second place this would need > wiring if the flag is ever applied to one. > > - Only CT_PANTILT_ABSOLUTE_CONTROL is flagged here. Zoom, focus, roll and > iris absolute share the same character, a mechanical actuator whose > position lags its setpoint, and focus absolute under continuous autofocus > is arguably the more widespread case. I have not flagged them because > pan/tilt is what I can exercise on the hardware I have, and widening this > adds a control transfer per read across a great many devices. Glad to > extend it if you think the argument carries. > > - Reading pan and tilt in one G_EXT_CTRLS call now issues one GET_CUR per > mapping, so the two values can come from instants roughly a millisecond > apart, where previously both decoded from a single cached sample. The > skew seemed inherent to polling a moving actuator and not worth a > per-ioctl generation scheme to share the transfer; flagging it in case > you weigh that differently. > > - Testing: built and run on v7.2-rc4 (mainline); the posted patch is > rebased onto media.git next and compile-tested there. Hardware is an > OBSBOT Tiny 2 (3564:fef8). Verified that a live read tracks a physical > slew; that two single-axis writes issued ~20ms apart both reach their > targets, which is the read-modify-write regression the separate buffer > exists to avoid; that pan/tilt report V4L2_CTRL_FLAG_VOLATILE and > V4L2_CTRL_FLAG_EXECUTE_ON_WRITE while zoom reports neither; and that > polling position at 5 Hz during an active 30 fps capture costs no > frames. v4l2-compliance results are identical with and without the patch > on this device (45/47, the two failures being the camera reporting a > Power Line Frequency default outside its own min/max, present in both > runs). Also checked an integrated UVC 1.00 webcam (1bcf:28cc) with no > pan/tilt, to confirm ordinary devices are unaffected. > > drivers/media/usb/uvc/uvc_ctrl.c | 57 +++++++++++++++++++++++++++++--- > include/uapi/linux/uvcvideo.h | 2 ++ > 2 files changed, 55 insertions(+), 4 deletions(-) > > diff --git a/drivers/media/usb/uvc/uvc_ctrl.c b/drivers/media/usb/uvc/uvc_ctrl.c > index 3ca108b83..c6e0c9958 100644 > --- a/drivers/media/usb/uvc/uvc_ctrl.c > +++ b/drivers/media/usb/uvc/uvc_ctrl.c > @@ -30,7 +30,8 @@ > #define UVC_CTRL_DATA_MAX 3 > #define UVC_CTRL_DATA_RES 4 > #define UVC_CTRL_DATA_DEF 5 > -#define UVC_CTRL_DATA_LAST 6 > +#define UVC_CTRL_DATA_LIVE 6 > +#define UVC_CTRL_DATA_LAST 7 > > /* ------------------------------------------------------------------------ > * Controls > @@ -302,7 +303,8 @@ static const struct uvc_control_info uvc_ctrls[] = { > .flags = UVC_CTRL_FLAG_SET_CUR > | UVC_CTRL_FLAG_GET_RANGE > | UVC_CTRL_FLAG_RESTORE > - | UVC_CTRL_FLAG_AUTO_UPDATE, > + | UVC_CTRL_FLAG_AUTO_UPDATE > + | UVC_CTRL_FLAG_VOLATILE, > }, > { > .entity = UVC_GUID_UVC_CAMERA, > @@ -1499,22 +1501,58 @@ static int __uvc_ctrl_load_cur(struct uvc_video_chain *chain, > return ret; > } > > +/* > + * Query the device for the current value of a volatile control, storing it in > + * a buffer of its own. UVC_CTRL_DATA_CURRENT is deliberately left alone: it > + * holds the value last commanded by the host, which is what the > + * read-modify-write path in uvc_ctrl_set() must use to preserve the fields of > + * a multi-field control that the caller is not writing. > + */ > +static int __uvc_ctrl_load_live(struct uvc_video_chain *chain, > + struct uvc_control *ctrl) > +{ > + u8 *data = uvc_ctrl_data(ctrl, UVC_CTRL_DATA_LIVE); > + > + if (ctrl->entity->get_cur) > + return ctrl->entity->get_cur(chain->dev, ctrl->entity, > + ctrl->info.selector, data, > + ctrl->info.size); > + > + return uvc_query_ctrl(chain->dev, UVC_GET_CUR, ctrl->entity->id, > + chain->dev->intfnum, ctrl->info.selector, data, > + ctrl->info.size); > +} > + > static int __uvc_ctrl_get(struct uvc_video_chain *chain, > struct uvc_control *ctrl, > struct uvc_control_mapping *mapping, > s32 *value) > { > + int id = UVC_CTRL_DATA_CURRENT; > int ret; > > if ((ctrl->info.flags & UVC_CTRL_FLAG_GET_CUR) == 0) > return -EACCES; > > - ret = __uvc_ctrl_load_cur(chain, ctrl); > + /* > + * A volatile control tracks a quantity that varies without host > + * intervention, so the cache cannot be trusted and the device is > + * queried on every read. Values staged by uvc_ctrl_set() but not yet > + * committed take precedence, so that reading back a control inside an > + * uncommitted transaction returns what the caller just wrote. > + */ > + if ((ctrl->info.flags & UVC_CTRL_FLAG_VOLATILE) && !ctrl->dirty) { > + ret = __uvc_ctrl_load_live(chain, ctrl); > + id = UVC_CTRL_DATA_LIVE; > + } else { > + ret = __uvc_ctrl_load_cur(chain, ctrl); > + } > + > if (ret < 0) > return ret; > > *value = uvc_mapping_get_s32(mapping, UVC_GET_CUR, > - uvc_ctrl_data(ctrl, UVC_CTRL_DATA_CURRENT)); > + uvc_ctrl_data(ctrl, id)); > > return 0; > } > @@ -1840,6 +1878,17 @@ static int __uvc_query_v4l2_ctrl(struct uvc_video_chain *chain, > if ((ctrl->info.flags & UVC_CTRL_FLAG_GET_MAX) && > (ctrl->info.flags & UVC_CTRL_FLAG_GET_MIN)) > v4l2_ctrl->flags |= V4L2_CTRL_FLAG_HAS_WHICH_MIN_MAX; > + if (ctrl->info.flags & UVC_CTRL_FLAG_VOLATILE) { > + v4l2_ctrl->flags |= V4L2_CTRL_FLAG_VOLATILE; > + /* > + * Writes to a volatile control are documented to be ignored > + * unless EXECUTE_ON_WRITE is also reported. The driver > + * propagates every write of a writable control to the device, > + * so report the flag accordingly. > + */ > + if (ctrl->info.flags & UVC_CTRL_FLAG_SET_CUR) > + v4l2_ctrl->flags |= V4L2_CTRL_FLAG_EXECUTE_ON_WRITE; > + } > > if (mapping->master_id) > __uvc_find_control(ctrl->entity, mapping->master_id, > diff --git a/include/uapi/linux/uvcvideo.h b/include/uapi/linux/uvcvideo.h > index cbe15bca9..b22fee8af 100644 > --- a/include/uapi/linux/uvcvideo.h > +++ b/include/uapi/linux/uvcvideo.h > @@ -31,6 +31,8 @@ > #define UVC_CTRL_FLAG_AUTO_UPDATE (1 << 7) > /* Control supports asynchronous reporting */ > #define UVC_CTRL_FLAG_ASYNCHRONOUS (1 << 8) > +/* Control tracks a value that varies on its own; never serve it from cache. */ > +#define UVC_CTRL_FLAG_VOLATILE (1 << 9) > > #define UVC_CTRL_FLAG_GET_RANGE \ > (UVC_CTRL_FLAG_GET_CUR | UVC_CTRL_FLAG_GET_MIN | \ > > base-commit: a52e6f7923c17a672135b485ffd96fbd72f46267 > -- > 2.43.0 > > -- Ricardo Ribalda ^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: [PATCH] media: uvcvideo: query pan/tilt position from the device on every read 2026-07-31 8:33 ` Ricardo Ribalda @ 2026-07-31 15:15 ` Michael Jordan 2026-07-31 17:14 ` Ricardo Ribalda 0 siblings, 1 reply; 9+ messages in thread From: Michael Jordan @ 2026-07-31 15:15 UTC (permalink / raw) To: Ricardo Ribalda Cc: laurent.pinchart, hansg, mchehab, linux-media, linux-kernel Hi Ricardo, On Fri, 31 Jul 2026 10:33:02 +0200, Ricardo Ribalda <ribalda@chromium.org> wrote: > Dear Michael Jordan > > (I always wanted to start an email like that :P) Happy to have been able to help with that. > I am not against the idea proposed by this patch, but I would like to > understand your use case a bit better. Do you want to know where the > camera is because: > - You want to do something continuously with that info (e.g., tagging > frames with the live position)? > - Or because you just want to know when the camera has actually > finished moving? The former. The application computes framing adjustments from the current pose -- "move 10 degrees left of wherever you are now" needs to know where "now" is -- and shows live position while the gimbal moves. A single end-of-move notification would not be enough even for the commanded-move case, and it does not exist at all for the autonomous one, which brings me to: > You also mentioned that the camera can reposition itself. Do you mean > that the camera could be tracking something and decide to move on its > own? Yes, exactly that. This camera (and similar PTZ conference cameras) has on-device AI tracking: once enabled, the gimbal follows a person continuously, for minutes at a time, with no host involvement at all. While tracking is active the position is a continuously varying quantity with no SET_CUR in flight and no "end of movement" to report. That is the case that made me give up on every event-shaped mechanism: > If it is the latter, you could use V4L2 control events. That should > work perfectly for signalling the end of a move: Three separate things go wrong, in increasing order of stubbornness: - uvcvideo's device-originated control events come from exactly one place, uvc_ctrl_status_event(), fed by the Control Change interrupt, and the spec only promises that interrupt "at the end of the movement" (4.2.2.1.15). So even a perfect device yields one event per move, not a trajectory. - This device never emits the interrupt at all. GET_INFO on CT_PANTILT_ABSOLUTE_CONTROL returns 0x03 -- neither D3 (Autoupdate) nor D4 (Asynchronous) -- so the event path has nothing to deliver. (Arguably a firmware defect per 2.4.4, but it looks systemic: the value is identical across every CT control on this device, so the firmware is not computing it per control.) - Under autonomous tracking there is no end of movement, so even compliant firmware would have nothing to hook the event to. > - Because your patch uses UVC_CTRL_DATA_CURRENT for the > read-modify-write path, the control will send (100, 300). That will > unintentionally move both axes, yanking the PAN back to 100 and > fighting the camera's autonomous tracking. The behaviour is real, but the patch does not introduce it: the write path is byte-identical before and after. What the RMW merges against today is decided by the device's GET_INFO bits, and both outcomes you are weighing already ship: - On a device whose GET_INFO clears AUTO_UPDATE (this one), ctrl->loaded stays set after the commit, so the tilt write merges against the cached setpoint and sends (100, 300) -- your scenario, reproduced exactly, on an unpatched kernel. - On a device that reports Autoupdate, uvc_ctrl_commit_entity() clears ctrl->loaded, so the tilt write does a fresh GET_CUR and merges against live data, sending (200, 300) -- kind to the tracker, but this is the variant that cancels a move the *user* commanded: issue two single-axis writes a few tens of milliseconds apart, and the second merges against a live reading in which the first axis has barely left its old position, and commits it right back. I have measured that second failure on real hardware (this camera keeps AUTO_UPDATE when probed while asleep, since it does not answer GET_INFO in that state -- its own small horror story): S_CTRL(pan), then S_CTRL(tilt) ~20ms later, and pan is yanked back to where it started. Same hardware with AUTO_UPDATE cleared, both axes reach their targets. Both merge sources are in the tree today; the patch adds neither and removes neither. If anything the patch improves your scenario slightly on Autoupdate devices: reads no longer set ctrl->loaded, so the write path can no longer merge against a stale sample frozen in the cache by an earlier G_CTRL. > What I think we should do instead is manage the cache validity based > on who "owns" the control. For ASYNCHRONOUS controls that have an > active handle (i.e., a user-commanded move that has not completed), we > mark them as "loaded". But when they are owned/updated by the device > autonomously, we never mark them as loaded. I think ownership is the right frame -- for the write path. Which merge source is correct genuinely depends on who owns the control: while a user move is in flight, the setpoint (live data cancels the move); while the device owns it, live data (the setpoint fights the tracker). That is a real pre-existing problem, your scenario is a good demonstration of one horn of it, and I would be glad to help fix it. But I do not think it can replace this patch, for the reason you already identified: > This specific logic still doesn't support polling the live mid-flight > position of a user-commanded move, but maybe V4L2 events can cover > your actual use case? Right -- and the mid-flight (or mid-tracking) position is the entire use case. However the write path picks its merge source, G_CTRL still has to report the actual position, which is what this patch does without touching the merge at all. The two compose: an ownership- based write path plus a live read path leaves nothing stale anywhere. Two practical notes on the pseudo-code: > - ctrl->loaded = 1; > + if (!FLAG_AUTO_UPDATE) > + ctrl->loaded = 1; __uvc_ctrl_load_cur() fills UVC_CTRL_DATA_CURRENT, which is the RMW source, so with this hunk every load puts live data where the write path merges -- the user-move cancellation above, now unconditional on every Autoupdate device. Keeping the live value in a buffer of its own is precisely how the patch avoids creating that. Separately, anything keyed on AUTO_UPDATE or ASYNCHRONOUS will not trigger on this device, since GET_INFO reports neither -- one reason the patch uses a static table flag that uvc_ctrl_get_flags() does not rewrite. The ownership logic would also need a completion signal for "the move has finished", and the only candidate is the Control Change interrupt this firmware never sends. Happy to respin if you would like any of this argued in the commit message itself -- the autonomous-tracking use case in particular is probably worth stating there rather than in a reply. Thanks again for the review. Best regards, Michael Jordan ^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: [PATCH] media: uvcvideo: query pan/tilt position from the device on every read 2026-07-31 15:15 ` Michael Jordan @ 2026-07-31 17:14 ` Ricardo Ribalda 2026-08-01 5:00 ` Michael Jordan 2026-08-14 23:33 ` Michael Jordan 0 siblings, 2 replies; 9+ messages in thread From: Ricardo Ribalda @ 2026-07-31 17:14 UTC (permalink / raw) To: Michael Jordan, Hans Verkuil Cc: laurent.pinchart, hansg, mchehab, linux-media, linux-kernel Hi Michael On Fri, 31 Jul 2026 at 17:15, Michael Jordan <jordan.mymail@gmail.com> wrote: > > Hi Ricardo, > > On Fri, 31 Jul 2026 10:33:02 +0200, Ricardo Ribalda <ribalda@chromium.org> wrote: > > Dear Michael Jordan > > > > (I always wanted to start an email like that :P) > > Happy to have been able to help with that. > > > I am not against the idea proposed by this patch, but I would like to > > understand your use case a bit better. Do you want to know where the > > camera is because: > > - You want to do something continuously with that info (e.g., tagging > > frames with the live position)? > > - Or because you just want to know when the camera has actually > > finished moving? > > The former. The application computes framing adjustments from the > current pose -- "move 10 degrees left of wherever you are now" needs > to know where "now" is -- and shows live position while the gimbal > moves. A single end-of-move notification would not be enough even for > the commanded-move case, and it does not exist at all for the > autonomous one, which brings me to: How accurate does the mapping frame/position need to be? You do not know how big the camera pipeline is. Maybe you are processing frame NOW-4 when you read position NOW > > > You also mentioned that the camera can reposition itself. Do you mean > > that the camera could be tracking something and decide to move on its > > own? > > Yes, exactly that. This camera (and similar PTZ conference cameras) > has on-device AI tracking: once enabled, the gimbal follows a person > continuously, for minutes at a time, with no host involvement at all. > While tracking is active the position is a continuously varying > quantity with no SET_CUR in flight and no "end of movement" to > report. That is the case that made me give up on every event-shaped > mechanism: > > > If it is the latter, you could use V4L2 control events. That should > > work perfectly for signalling the end of a move: > > Three separate things go wrong, in increasing order of stubbornness: > > - uvcvideo's device-originated control events come from exactly one > place, uvc_ctrl_status_event(), fed by the Control Change > interrupt, and the spec only promises that interrupt "at the end of > the movement" (4.2.2.1.15). So even a perfect device yields one > event per move, not a trajectory. And we rely on that interrupt to know when the device is done and we can go to sleep. > > - This device never emits the interrupt at all. GET_INFO on > CT_PANTILT_ABSOLUTE_CONTROL returns 0x03 -- neither D3 (Autoupdate) > nor D4 (Asynchronous) -- so the event path has nothing to deliver. > (Arguably a firmware defect per 2.4.4, but it looks systemic: the > value is identical across every CT control on this device, so the > firmware is not computing it per control.) If the device is not setting the Asynchronous I think we have bigger problems to deal with. Without the async, the device will go to sleep as soon as you set the control (if you are not streaming). You definitely have to ping the vendor to make sure they fix their firmware. > > - Under autonomous tracking there is no end of movement, so even > compliant firmware would have nothing to hook the event to. If AUTO_UPDATE is present you would get fresh data when you poll the control. > > > - Because your patch uses UVC_CTRL_DATA_CURRENT for the > > read-modify-write path, the control will send (100, 300). That will > > unintentionally move both axes, yanking the PAN back to 100 and > > fighting the camera's autonomous tracking. > > The behaviour is real, but the patch does not introduce it: the write > path is byte-identical before and after. What the RMW merges against > today is decided by the device's GET_INFO bits, and both outcomes you > are weighing already ship: > > - On a device whose GET_INFO clears AUTO_UPDATE (this one), > ctrl->loaded stays set after the commit, so the tilt write merges > against the cached setpoint and sends (100, 300) -- your scenario, > reproduced exactly, on an unpatched kernel. > > - On a device that reports Autoupdate, uvc_ctrl_commit_entity() > clears ctrl->loaded, so the tilt write does a fresh GET_CUR and > merges against live data, sending (200, 300) -- kind to the > tracker, but this is the variant that cancels a move the *user* > commanded: issue two single-axis writes a few tens of milliseconds > apart, and the second merges against a live reading in which the > first axis has barely left its old position, and commits it right > back. unrelated note: if you need to set the two axis at the set time, you can use V4L.VIDIOC_S_EXT_CTRLS https://www.kernel.org/doc/html/latest/userspace-api/media/v4l/vidioc-g-ext-ctrls.html#c.V4L.VIDIOC_S_EXT_CTRLS (You probably are aware of it, just want to make sure that you know it exists). In fact you could use that today to avoid part of the kernel issue. Always send pan and tilt when you are tracking the movement. > > I have measured that second failure on real hardware (this camera > keeps AUTO_UPDATE when probed while asleep, since it does not answer > GET_INFO in that state -- its own small horror story): S_CTRL(pan), > then S_CTRL(tilt) ~20ms later, and pan is yanked back to where it > started. Same hardware with AUTO_UPDATE cleared, both axes reach > their targets. Both merge sources are in the tree today; the patch > adds neither and removes neither. > > If anything the patch improves your scenario slightly on Autoupdate > devices: reads no longer set ctrl->loaded, so the write path can no > longer merge against a stale sample frozen in the cache by an > earlier G_CTRL. > > > What I think we should do instead is manage the cache validity based > > on who "owns" the control. For ASYNCHRONOUS controls that have an > > active handle (i.e., a user-commanded move that has not completed), we > > mark them as "loaded". But when they are owned/updated by the device > > autonomously, we never mark them as loaded. > > I think ownership is the right frame -- for the write path. Which > merge source is correct genuinely depends on who owns the control: > while a user move is in flight, the setpoint (live data cancels the > move); while the device owns it, live data (the setpoint fights the > tracker). That is a real pre-existing problem, your scenario is a > good demonstration of one horn of it, and I would be glad to help fix > it. But I do not think it can replace this patch, for the reason you > already identified: > > > This specific logic still doesn't support polling the live mid-flight > > position of a user-commanded move, but maybe V4L2 events can cover > > your actual use case? > > Right -- and the mid-flight (or mid-tracking) position is the entire > use case. However the write path picks its merge source, G_CTRL still > has to report the actual position, which is what this patch does > without touching the merge at all. The two compose: an ownership- > based write path plus a live read path leaves nothing stale anywhere. > > Two practical notes on the pseudo-code: > > > - ctrl->loaded = 1; > > + if (!FLAG_AUTO_UPDATE) > > + ctrl->loaded = 1; > > __uvc_ctrl_load_cur() fills UVC_CTRL_DATA_CURRENT, which is the RMW > source, so with this hunk every load puts live data where the write > path merges -- the user-move cancellation above, now unconditional on > every Autoupdate device. Keeping the live value in a buffer of its > own is precisely how the patch avoids creating that. Separately, > anything keyed on AUTO_UPDATE or ASYNCHRONOUS will not trigger on > this device, since GET_INFO reports neither -- one reason the patch > uses a static table flag that uvc_ctrl_get_flags() does not rewrite. > The ownership logic would also need a completion signal for "the move > has finished", and the only candidate is the Control Change interrupt > this firmware never sends. > > Happy to respin if you would like any of this argued in the commit > message itself -- the autonomous-tracking use case in particular is > probably worth stating there rather than in a reply. Let's wait a bit for Laurent or HansG (or even Hans Verkuil) to comment. There are different problems here: 1) Your firmware is broken. We need to fix the general case assuming compliant cameras. (We can introduce a quirk later, for your device) 2) We want different behaviour based on what is happening: - The camera is tracking an object autonomously: - Get the live values for pan and tilt and use them as reference when we change pan or tilt - The camera is finalising a movement required by the user - Use the pair of pain/tilt provived by the user as reference when we change pan or tilt. note: A firmware that sets the AUTO_UPDATE flag could be used by a userspace that is aware of who owns the control. I am very curious what HansV thinks. Regards PS: I am planning to be OOO next week so my replies will be slower. > > Thanks again for the review. > > Best regards, > Michael Jordan -- Ricardo Ribalda ^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: [PATCH] media: uvcvideo: query pan/tilt position from the device on every read 2026-07-31 17:14 ` Ricardo Ribalda @ 2026-08-01 5:00 ` Michael Jordan [not found] ` <CAMdm4Cz-oREZfk2-_eQ16umQawWF+c9vA_AV4tBuHHvsbP0vqw@mail.gmail.com> 2026-08-14 23:33 ` Michael Jordan 1 sibling, 1 reply; 9+ messages in thread From: Michael Jordan @ 2026-08-01 5:00 UTC (permalink / raw) To: Ricardo Ribalda, Hans Verkuil Cc: laurent.pinchart, hansg, mchehab, linux-media, linux-kernel Hi Ricardo, On Fri, 31 Jul 2026 19:14:51 +0200, Ricardo Ribalda <ribalda@chromium.org> wrote: > How accurate does the mapping frame/position need to be? > > You do not know how big the camera pipeline is. Maybe you are > processing frame NOW-4 when you read position NOW Not accurate at all, and I should have been clearer earlier: I picked "the former" for the continuous part of your question, not for the frame-tagging example. Nothing in my use case correlates a position with a particular frame. The position is an input to a control loop ("where am I, so I can ask for ten degrees left of here") and a number on a UI, and the gimbal's own time constants are hundreds of milliseconds per move, so a few frames of pipeline skew is far below anything that matters. If someone did want frame-accurate pose, I agree a G_CTRL read would be the wrong instrument entirely -- that is a per-frame metadata problem, and this patch would not be the right vehicle for it. > unrelated note: if you need to set the two axis at the set time, you > can use V4L.VIDIOC_S_EXT_CTRLS > [...] > In fact you could use that today to avoid part of the kernel issue. > Always send pan and tilt when you are tracking the movement. Thanks -- and you are right that this sidesteps the merge problem completely, which I had not appreciated. Both mappings land in UVC_CTRL_DATA_CURRENT before the single commit, so whatever __uvc_ctrl_load_cur() put there is fully overwritten and it no longer matters which source the RMW pulled from. I will switch my userspace to always send both axes. It does not touch the read side, but it makes the write side a non-issue for me in the meantime. > If AUTO_UPDATE is present you would get fresh data when you poll the > control. One clarification for the record, since it bears on what you are asking HansV to weigh: that holds via the interrupt rather than via the poll. uvc_ctrl_status_event() clears ctrl->loaded, so a poll after a notification does re-read the device -- but polls between notifications still return the cache, because __uvc_ctrl_load_cur() returns early on ctrl->loaded and nothing else clears it outside a commit. So on a compliant autoupdate device the update rate is the device's signalling rate, and for pan/tilt 4.2.2.1.15 only promises that signal at the end of the movement. Good enough for "it stopped, here is where"; not for sampling a trajectory. I mention it only so the comparison is accurate, not to relitigate -- your framing of the two problems matches how I see them. > You definitely have to ping the vendor to make sure they fix their > firmware. Agreed, and I will. I am not counting on a timeline. > Let's wait a bit for Laurent or HansG (or even Hans Verkuil) to > comment. Sounds good -- no rush at all from my side, and I am happy to respin against whatever shape you all land on. Enjoy the time off. Best regards, Michael Jordan ^ permalink raw reply [flat|nested] 9+ messages in thread
[parent not found: <CAMdm4Cz-oREZfk2-_eQ16umQawWF+c9vA_AV4tBuHHvsbP0vqw@mail.gmail.com>]
* Re: Re: [PATCH] media: uvcvideo: query pan/tilt position from the device on every read [not found] ` <CAMdm4Cz-oREZfk2-_eQ16umQawWF+c9vA_AV4tBuHHvsbP0vqw@mail.gmail.com> @ 2026-08-18 11:30 ` Ricardo Ribalda 2026-08-21 9:03 ` Michael Jordan 0 siblings, 1 reply; 9+ messages in thread From: Ricardo Ribalda @ 2026-08-18 11:30 UTC (permalink / raw) To: Michael Jordan Cc: hverkuil+cisco, laurent.pinchart, hansg, mchehab, linux-media, linux-kernel Hi Michael On Sat, 15 Aug 2026 at 01:11, Michael Jordan <jordan.mymail@gmail.com> wrote: > > Hi Ricardo, > > On Fri, 31 Jul 2026 19:14:51 +0200, Ricardo Ribalda <ribalda@chromium.org> wrote: > > You definitely have to ping the vendor to make sure they fix their firmware. > > Done -- I wrote to OBSBOT on 4 August covering the GET_INFO stub along > with two other compliance defects I found on the device (a control > default outside the control's own min/max, and PanTilt-Relative > returning a constant). No response so far. I will report back if that > changes. > > One thing I should have made explicit earlier, since it bears on > whether this patch is the right general-case fix rather than a quirk > for one broken camera: correcting that firmware would not make the > position observable. > > The driver clears the control cache in exactly two places -- > uvc_ctrl_status_event() on a Control Change interrupt, and > uvc_ctrl_commit_entity() after a SET_CUR commit for auto-update > controls -- and __uvc_ctrl_load_cur() re-arms it after each read. So on > a fully compliant device a host-commanded move yields two samples, both > endpoints: the first G_CTRL after the commit reaches the device, but it > runs microseconds after the command, when the actuator has not yet > moved, and every later poll returns that value frozen until the > end-of-movement interrupt. Under autonomous tracking there is no commit > and no defined interrupt, so nothing invalidates the cache at all. I believe that if AUTO_UPDATE would be properly initialized, then, the values will always be fresh when you run G_CTRL o G_EXT_CTRLS from userspace: G_EXT_CTRLS uvc_ioctl_g_ext_ctls() uvc_ctrl_rollback() uvc_ctrl_commit() uvc_ctrl_commit_entity() ctrl->loaded=0 So all the values captured with G_EXT_CTRL() will show fresh data. > > So the limit is the caching model rather than the device. That is the > case I would want the patch judged on, and it applies to correct > firmware too. > > Worth flagging one side effect if OBSBOT does fix GET_INFO: with > AUTO_UPDATE reported, uvc_ctrl_commit_entity() would begin clearing > ctrl->loaded on this camera, so single-axis writes issued tens of > milliseconds apart would start merging against live data and cancelling > each other -- the second failure mode I measured. It would move the > device from one horn of the read-modify-write question to the other, > which is the pre-existing problem you identified and which this patch > deliberately does not touch. > > No action needed from my side while we wait for Laurent, HansG or > HansV. I am still happy to respin with the autonomous-tracking case > argued in the commit message rather than in this thread, if that would > help whoever picks it up. Until they reply maybe you want to: - rename uvc_ctrl_fixup_xu_info to uvc_ctrl_fixup_flags - modify uvc_ctrl_get_flags so it calls uvc_ctrl_fixup_flags - add your device information to uvc_ctrl_fixup_flags and then modify your userspace code, so you allways do S_EXT_CTRLS() with the information of both axis. I believe that should cover your usecase. > > Best regards, > Michael Jordan > > On Sat, Aug 01, 2026 01:00 AM, Michael Jordan <jordan.mymail@gmail.com> wrote: >> >> Hi Ricardo, >> >> On Fri, 31 Jul 2026 19:14:51 +0200, Ricardo Ribalda <ribalda@chromium.org> wrote: >> > How accurate does the mapping frame/position need to be? >> > >> > You do not know how big the camera pipeline is. Maybe you are >> > processing frame NOW-4 when you read position NOW >> >> Not accurate at all, and I should have been clearer earlier: I picked >> "the former" for the continuous part of your question, not for the >> frame-tagging example. Nothing in my use case correlates a position >> with a particular frame. The position is an input to a control loop >> ("where am I, so I can ask for ten degrees left of here") and a number >> on a UI, and the gimbal's own time constants are hundreds of >> milliseconds per move, so a few frames of pipeline skew is far below >> anything that matters. >> >> If someone did want frame-accurate pose, I agree a G_CTRL read would be >> the wrong instrument entirely -- that is a per-frame metadata problem, >> and this patch would not be the right vehicle for it. >> >> > unrelated note: if you need to set the two axis at the set time, you >> > can use V4L.VIDIOC_S_EXT_CTRLS >> > [...] >> > In fact you could use that today to avoid part of the kernel issue. >> > Always send pan and tilt when you are tracking the movement. >> >> Thanks -- and you are right that this sidesteps the merge problem >> completely, which I had not appreciated. Both mappings land in >> UVC_CTRL_DATA_CURRENT before the single commit, so whatever >> __uvc_ctrl_load_cur() put there is fully overwritten and it no longer >> matters which source the RMW pulled from. I will switch my userspace to >> always send both axes. It does not touch the read side, but it makes >> the write side a non-issue for me in the meantime. >> >> > If AUTO_UPDATE is present you would get fresh data when you poll the >> > control. >> >> One clarification for the record, since it bears on what you are asking >> HansV to weigh: that holds via the interrupt rather than via the poll. >> uvc_ctrl_status_event() clears ctrl->loaded, so a poll after a >> notification does re-read the device -- but polls between notifications >> still return the cache, because __uvc_ctrl_load_cur() returns early on >> ctrl->loaded and nothing else clears it outside a commit. So on a >> compliant autoupdate device the update rate is the device's signalling >> rate, and for pan/tilt 4.2.2.1.15 only promises that signal at the end >> of the movement. Good enough for "it stopped, here is where"; not for >> sampling a trajectory. I mention it only so the comparison is accurate, >> not to relitigate -- your framing of the two problems matches how I see >> them. >> >> > You definitely have to ping the vendor to make sure they fix their >> > firmware. >> >> Agreed, and I will. I am not counting on a timeline. >> >> > Let's wait a bit for Laurent or HansG (or even Hans Verkuil) to >> > comment. >> >> Sounds good -- no rush at all from my side, and I am happy to respin >> against whatever shape you all land on. Enjoy the time off. >> >> Best regards, >> Michael Jordan -- Ricardo Ribalda ^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: [PATCH] media: uvcvideo: query pan/tilt position from the device on every read 2026-08-18 11:30 ` Ricardo Ribalda @ 2026-08-21 9:03 ` Michael Jordan 2026-08-27 7:30 ` Ricardo Ribalda 0 siblings, 1 reply; 9+ messages in thread From: Michael Jordan @ 2026-08-21 9:03 UTC (permalink / raw) To: linux-media, Ricardo Ribalda Cc: hverkuil+cisco, laurent.pinchart, hansg, mchehab, linux-kernel Hi Ricardo, On Tue, 18 Aug 2026 13:30:57 +0200, Ricardo Ribalda <ribalda@chromium.org> wrote: > I believe that if AUTO_UPDATE would be properly initialized, then, the > values will always be fresh when you run G_CTRL o G_EXT_CTRLS from > userspace: > > G_EXT_CTRLS > uvc_ioctl_g_ext_ctls() > uvc_ctrl_rollback() > uvc_ctrl_commit() > uvc_ctrl_commit_entity() > ctrl->loaded=0 You are right, and this corrects what I wrote on 14 August. The rollback at the end of every G_EXT_CTRLS runs uvc_ctrl_commit_entity(), which clears ->loaded for an AUTO_UPDATE control at the top of the loop, before the dirty/rollback checks, so the following read re-queries the device. I had only counted the Control Change interrupt and the SET_CUR commit as cache-invalidation points and missed that the read path invalidates its own cache. So on this device, once AUTO_UPDATE is restored, polling G_EXT_CTRLS returns fresh data with no volatile flag involved. My claim that "correcting the firmware would not make the position observable" was wrong. > Until they reply maybe you want to: > - rename uvc_ctrl_fixup_xu_info to uvc_ctrl_fixup_flags > - modify uvc_ctrl_get_flags so it calls uvc_ctrl_fixup_flags > - add your device information to uvc_ctrl_fixup_flags I did this and tested it on the hardware. For the record, the device's GET_INFO for CT_PANTILT_ABSOLUTE (entity 1, selector 0x0d) returns 0x03 -- GET|SET, no AUTOUPDATE bit -- so uvc_ctrl_get_flags() masks off the UVC_CTRL_FLAG_AUTO_UPDATE that the static uvc_ctrls[] entry sets for this control. Calling the fixup from uvc_ctrl_get_flags() unconditionally (so it also runs when GET_INFO succeeds) and adding { USB_DEVICE(0x3564, 0xfef8), 1, UVC_CT_PANTILT_ABSOLUTE_CONTROL, UVC_CTRL_FLAG_SET_CUR | UVC_CTRL_FLAG_GET_RANGE | UVC_CTRL_FLAG_RESTORE | UVC_CTRL_FLAG_AUTO_UPDATE } restores it. One detail worth noting: the existing fixup does info->flags = fixups[i].flags, a full replace rather than a masked OR, so a standard-control entry has to spell out the whole flag set, not just the missing bit. With that in place I verified on an OBSBOT Tiny 2 (3564:fef8) that polling G_EXT_CTRLS tracks a physical slew on both axes, including motion the host never commanded (moving the gimbal by hand), while a stock module returns the stale value indefinitely for the same reads. So your suggestion covers my use case, and I am going to carry the quirk rather than the volatile change. I have also switched my userspace to always send both axes in one S_EXT_CTRLS, as you suggested. Both mappings land in UVC_CTRL_DATA_CURRENT before the single commit, so whatever the read-modify-write loaded is fully overwritten and the merge source stops mattering -- the write side is a non-issue now regardless of the flags. Given the rollback point, the general-case argument for the volatile patch is weaker than I framed it: for the ioctl polling path a device with correct (or fixed-up) flags does not need it. The only things it still does that the quirk does not are to advertise V4L2_CTRL_FLAG_VOLATILE to userspace and to keep the write-side RMW reading from a separate buffer, and with always-send-both-axes I need neither. So I will not push the volatile patch further unless you or Hans think the userspace-visible VOLATILE flag is worth having on its own. If it is useful I am happy to send the fixup as a proper patch with a Suggested-by: you, or to leave it to you if you would rather fold it in. Thanks for the review and the pointer -- both were right. Best regards, Michael Jordan ^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: [PATCH] media: uvcvideo: query pan/tilt position from the device on every read 2026-08-21 9:03 ` Michael Jordan @ 2026-08-27 7:30 ` Ricardo Ribalda 0 siblings, 0 replies; 9+ messages in thread From: Ricardo Ribalda @ 2026-08-27 7:30 UTC (permalink / raw) To: Michael Jordan Cc: linux-media, hverkuil+cisco, laurent.pinchart, hansg, mchehab, linux-kernel Hi Michael On Fri, 21 Aug 2026 at 11:03, Michael Jordan <jordan.mymail@gmail.com> wrote: > > Hi Ricardo, > > On Tue, 18 Aug 2026 13:30:57 +0200, Ricardo Ribalda <ribalda@chromium.org> wrote: > > I believe that if AUTO_UPDATE would be properly initialized, then, the > > values will always be fresh when you run G_CTRL o G_EXT_CTRLS from > > userspace: > > > > G_EXT_CTRLS > > uvc_ioctl_g_ext_ctls() > > uvc_ctrl_rollback() > > uvc_ctrl_commit() > > uvc_ctrl_commit_entity() > > ctrl->loaded=0 > > You are right, and this corrects what I wrote on 14 August. The rollback > at the end of every G_EXT_CTRLS runs uvc_ctrl_commit_entity(), which > clears ->loaded for an AUTO_UPDATE control at the top of the loop, before > the dirty/rollback checks, so the following read re-queries the device. I > had only counted the Control Change interrupt and the SET_CUR commit as > cache-invalidation points and missed that the read path invalidates its > own cache. So on this device, once AUTO_UPDATE is restored, polling > G_EXT_CTRLS returns fresh data with no volatile flag involved. My claim > that "correcting the firmware would not make the position observable" was > wrong. > > > Until they reply maybe you want to: > > - rename uvc_ctrl_fixup_xu_info to uvc_ctrl_fixup_flags > > - modify uvc_ctrl_get_flags so it calls uvc_ctrl_fixup_flags > > - add your device information to uvc_ctrl_fixup_flags > > I did this and tested it on the hardware. For the record, the device's > GET_INFO for CT_PANTILT_ABSOLUTE (entity 1, selector 0x0d) returns 0x03 -- > GET|SET, no AUTOUPDATE bit -- so uvc_ctrl_get_flags() masks off the > UVC_CTRL_FLAG_AUTO_UPDATE that the static uvc_ctrls[] entry sets for this > control. Calling the fixup from uvc_ctrl_get_flags() unconditionally (so it > also runs when GET_INFO succeeds) and adding > > { USB_DEVICE(0x3564, 0xfef8), 1, UVC_CT_PANTILT_ABSOLUTE_CONTROL, > UVC_CTRL_FLAG_SET_CUR | UVC_CTRL_FLAG_GET_RANGE | > UVC_CTRL_FLAG_RESTORE | UVC_CTRL_FLAG_AUTO_UPDATE } > > restores it. One detail worth noting: the existing fixup does > info->flags = fixups[i].flags, a full replace rather than a masked OR, so > a standard-control entry has to spell out the whole flag set, not just the > missing bit. > > With that in place I verified on an OBSBOT Tiny 2 (3564:fef8) that polling > G_EXT_CTRLS tracks a physical slew on both axes, including motion the host > never commanded (moving the gimbal by hand), while a stock module returns > the stale value indefinitely for the same reads. So your suggestion covers > my use case, and I am going to carry the quirk rather than the volatile > change. > > I have also switched my userspace to always send both axes in one > S_EXT_CTRLS, as you suggested. Both mappings land in UVC_CTRL_DATA_CURRENT > before the single commit, so whatever the read-modify-write loaded is fully > overwritten and the merge source stops mattering -- the write side is a > non-issue now regardless of the flags. > > Given the rollback point, the general-case argument for the volatile patch > is weaker than I framed it: for the ioctl polling path a device with > correct (or fixed-up) flags does not need it. The only things it still does > that the quirk does not are to advertise V4L2_CTRL_FLAG_VOLATILE to > userspace and to keep the write-side RMW reading from a separate buffer, > and with always-send-both-axes I need neither. So I will not push the > volatile patch further unless you or Hans think the userspace-visible > VOLATILE flag is worth having on its own. > > If it is useful I am happy to send the fixup as a proper patch with a > Suggested-by: you, or to leave it to you if you would rather fold it in. > Thanks for the review and the pointer -- both were right. Happy to hear that it works for you! A proper patchset would be awesome. I do not think we have to wait for Hans(es) to start reviewing it. How does this sound?: 1) A patch to add V4L2_CTRL_FLAG_VOLATILE for all the UVC_CTRL_FLAG_AUTO_UPDATE controls ( I think that is missing) 2) A patch to rename uvc_ctrl_fixup_xu_info to uvc_ctrl_fixup_flags and modify uvc_ctrl_get_flags so it calls it. 3) A patch to add the quirk for your device. In the commit message, please include the lsusb -v output of your device and mention that you pinged the vendor to fix their firmware. The Suggested-by tag would be great :) Regards! > > Best regards, > Michael Jordan -- Ricardo Ribalda ^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: [PATCH] media: uvcvideo: query pan/tilt position from the device on every read 2026-07-31 17:14 ` Ricardo Ribalda 2026-08-01 5:00 ` Michael Jordan @ 2026-08-14 23:33 ` Michael Jordan 1 sibling, 0 replies; 9+ messages in thread From: Michael Jordan @ 2026-08-14 23:33 UTC (permalink / raw) To: Ricardo Ribalda, Hans Verkuil Cc: Michael Jordan, laurent.pinchart, hansg, mchehab, linux-media, linux-kernel Hi Ricardo, On Fri, 31 Jul 2026 19:14:51 +0200, Ricardo Ribalda <ribalda@chromium.org> wrote: > You definitely have to ping the vendor to make sure they fix their firmware. Done -- I wrote to OBSBOT on 4 August covering the GET_INFO stub along with two other compliance defects I found on the device (a control default outside the control's own min/max, and PanTilt-Relative returning a constant). No response so far. I will report back if that changes. One thing I should have made explicit earlier, since it bears on whether this patch is the right general-case fix rather than a quirk for one broken camera: correcting that firmware would not make the position observable. The driver clears the control cache in exactly two places -- uvc_ctrl_status_event() on a Control Change interrupt, and uvc_ctrl_commit_entity() after a SET_CUR commit for auto-update controls -- and __uvc_ctrl_load_cur() re-arms it after each read. So on a fully compliant device a host-commanded move yields two samples, both endpoints: the first G_CTRL after the commit reaches the device, but it runs microseconds after the command, when the actuator has not yet moved, and every later poll returns that value frozen until the end-of-movement interrupt. Under autonomous tracking there is no commit and no defined interrupt, so nothing invalidates the cache at all. So the limit is the caching model rather than the device. That is the case I would want the patch judged on, and it applies to correct firmware too. Worth flagging one side effect if OBSBOT does fix GET_INFO: with AUTO_UPDATE reported, uvc_ctrl_commit_entity() would begin clearing ctrl->loaded on this camera, so single-axis writes issued tens of milliseconds apart would start merging against live data and cancelling each other -- the second failure mode I measured. It would move the device from one horn of the read-modify-write question to the other, which is the pre-existing problem you identified and which this patch deliberately does not touch. No action needed from my side while we wait for Laurent, HansG or HansV. I am still happy to respin with the autonomous-tracking case argued in the commit message rather than in this thread, if that would help whoever picks it up. Best regards, Michael Jordan ^ permalink raw reply [flat|nested] 9+ messages in thread
end of thread, other threads:[~2026-08-27 7:31 UTC | newest]
Thread overview: 9+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-07-25 21:23 [PATCH] media: uvcvideo: query pan/tilt position from the device on every read Michael Jordan
2026-07-31 8:33 ` Ricardo Ribalda
2026-07-31 15:15 ` Michael Jordan
2026-07-31 17:14 ` Ricardo Ribalda
2026-08-01 5:00 ` Michael Jordan
[not found] ` <CAMdm4Cz-oREZfk2-_eQ16umQawWF+c9vA_AV4tBuHHvsbP0vqw@mail.gmail.com>
2026-08-18 11:30 ` Ricardo Ribalda
2026-08-21 9:03 ` Michael Jordan
2026-08-27 7:30 ` Ricardo Ribalda
2026-08-14 23:33 ` Michael Jordan
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®