media: uvcvideo: Prepare deprecation of nodrop
Subsystems (2)
cover media: uvcvideo: Prepare deprecation of nodrop
We intend to deprecate the nodrop parameter in the future and adopt the default behaviour of the other media drivers: drop invalid packages.
Make the first step in the deprecation by changing the default value of the parameter and printing an error message when the value is changed.
---
Ricardo Ribalda (3):
media: uvcvideo: Swap default value for nodrop module param
media: uvcvideo: Allow changing noparam on the fly
media: uvcvideo: Announce the user our deprecation intentions
drivers/media/usb/uvc/uvc_driver.c | 23 ++++++++++++++++++++--- drivers/media/usb/uvc/uvc_queue.c | 6 ++---- drivers/media/usb/uvc/uvcvideo.h | 4 +--- 3 files changed, 23 insertions(+), 10 deletions(-)
---
base-commit: d216d9cb4dd854ef0a2ec1701f403facb298af51
change-id: 20241217-uvc-deprecate-fbd6228fa1e2
Best regards,
Signature · 1 line
Ricardo Ribalda <[email protected]>
PATCH 1/3 media: uvcvideo: Swap default value for nodrop module param
The module param nodrop defines what to do with frames that contain an
error: drop them or sending them to userspace.
The default seems to be to send them to userspace so they can decide what to do with the frame.
Change the default behaviour of uvcvideo to match the rest of the drivers and maybe get rid of the module parameter in the future.
--- drivers/media/usb/uvc/uvc_driver.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/media/usb/uvc/uvc_driver.c +1 -1
@@ -32,7 +32,7 @@unsigned int uvc_clock_param =CLOCK_MONOTONIC ;unsigned int uvc_hw_timestamps_param; -unsigned int uvc_no_drop_param; +unsigned int uvc_no_drop_param =1 ;static unsigned int uvc_quirks_param =-1 ;unsigned int uvc_dbg_param;unsigned int uvc_timeout_param =UVC_CTRL_STREAMING_TIMEOUT ;
Signature · 1 line
2.47.1.613.gc27f4b7a9f-goog
PATCH 2/3 media: uvcvideo: Allow changing noparam on the fly
In reply to Ricardo RibaldaRight now the parameter value is read during video_registration and cannot be changed afterwards, despite its permissions 0644, that makes the user believe that the value can be written.
The parameter only affects the beviour of uvc_queue_buffer_complete(), with only one check per buffer.
We can read the value directly from uvc_queue_buffer_complete() and therefore allowing changing it with sysfs on the fly.
--- drivers/media/usb/uvc/uvc_driver.c | 2 +- drivers/media/usb/uvc/uvc_queue.c | 6 ++---- drivers/media/usb/uvc/uvcvideo.h | 4 +--- 3 files changed, 4 insertions(+), 8 deletions(-)
drivers/media/usb/uvc/uvc_driver.c +1 -1
@@ -1995,7 +1995,7 @@ int uvc_register_video_device(struct uvc_device *dev,int ret;/* Initialize the video buffers queue. */ - ret =uvc_queue_init (queue, type, !uvc_no_drop_param); + ret =uvc_queue_init (queue, type);if (ret)return ret;
drivers/media/usb/uvc/uvc_queue.c +2 -4
@@ -208,8 +208,7 @@ static const struct vb2_ops uvc_meta_queue_qops = { .stop_streaming = uvc_stop_streaming, }; -int uvc_queue_init (struct uvc_video_queue *queue,enum v4l2_buf_type type, -int drop_corrupted) +int uvc_queue_init (struct uvc_video_queue *queue,enum v4l2_buf_type type) {int ret;
@@ -239,7 +238,6 @@ int uvc_queue_init(struct uvc_video_queue *queue, enum v4l2_buf_type type,mutex_init (&queue->mutex);spin_lock_init (&queue->irqlock);INIT_LIST_HEAD (&queue->irqqueue); - queue->flags = drop_corrupted ?UVC_QUEUE_DROP_CORRUPTED :0 ;return 0 ; }
@@ -472,7 +470,7 @@ static void uvc_queue_buffer_complete(struct kref *ref)struct vb2_buffer *vb = &buf->buf.vb2_buf;struct uvc_video_queue *queue =vb2_get_drv_priv (vb->vb2_queue); -if ((queue->flags &UVC_QUEUE_DROP_CORRUPTED ) && buf->error) { +if (buf->error && !uvc_no_drop_param) {uvc_queue_buffer_requeue (queue, buf);return ; }
drivers/media/usb/uvc/uvcvideo.h +1 -3
@@ -316,7 +316,6 @@ struct uvc_buffer { };#define UVC_QUEUE_DISCONNECTED (1 << 0) -#define UVC_QUEUE_DROP_CORRUPTED (1 << 1)struct uvc_video_queue {struct vb2_queue queue;
@@ -674,8 +673,7 @@ extern struct uvc_driver uvc_driver;struct uvc_entity *uvc_entity_by_id (struct uvc_device *dev,int id);/* Video buffers queue management. */ -int uvc_queue_init (struct uvc_video_queue *queue,enum v4l2_buf_type type, -int drop_corrupted); +int uvc_queue_init (struct uvc_video_queue *queue,enum v4l2_buf_type type);void uvc_queue_release (struct uvc_video_queue *queue);int uvc_request_buffers (struct uvc_video_queue *queue,struct v4l2_requestbuffers *rb);
Signature · 1 line
2.47.1.613.gc27f4b7a9f-goog
PATCH 3/3 media: uvcvideo: Announce the user our deprecation intentions
In reply to Ricardo RibaldaIf the user sets the nodrop parameter, print a deprecation warning once. Hopefully they will come to the mailing list if it is an ABI change.
Now that we have a callback, take this chance to parse the parameter as a boolean.
--- drivers/media/usb/uvc/uvc_driver.c | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-)
drivers/media/usb/uvc/uvc_driver.c +18 -1
@@ -2424,8 +2424,25 @@ module_param_call(clock, uvc_clock_param_set, uvc_clock_param_get,MODULE_PARM_DESC (clock,"Video buffers timestamp clock" );module_param_named (hwtimestamps, uvc_hw_timestamps_param, uint,0644 );MODULE_PARM_DESC (hwtimestamps,"Use hardware timestamps" ); -module_param_named (nodrop, uvc_no_drop_param, uint,0644 ); + +static int param_set_nodrop (const char *val,const struct kernel_param *kp) +{ +pr_warn_once ("uvcvideo: " +DEPRECATED +"nodrop parameter will be eventually removed.\n" ); +return param_set_bool (val, kp); +} + +static const struct kernel_param_ops param_ops_nodrop = { + .set = param_set_nodrop, + .get = param_get_uint, +}; + +param_check_uint (nodrop, &uvc_no_drop_param); +module_param_cb (nodrop, ¶m_ops_nodrop, &uvc_no_drop_param,0644 ); +__MODULE_PARM_TYPE (nodrop,"uint" );MODULE_PARM_DESC (nodrop,"Don't drop incomplete frames" ); +module_param_named (quirks, uvc_quirks_param, uint,0644 );MODULE_PARM_DESC (quirks,"Forced device quirks" );module_param_named (trace, uvc_dbg_param, uint,0644 );
Signature · 1 line
2.47.1.613.gc27f4b7a9f-goog
Hi Ricardo,
Thank you for working on this.
Quoted 2 lines · Ricardo Ribalda
We intend to deprecate the nodrop parameter in the future and adopt the default behaviour of the other media drivers: drop invalid packages.
Actually the default behaviour of other media drivers is:
"return buffers with an error to userspace with V4L2_BUF_FLAG_ERROR set in v4l2_buffer.flags".
It is not "drop invalid packages". The commit messages of patch 1/3 has some related unclear wording, please fix this.
Looking at this I actually have found what arguably is a bug in the UVC driver when nodrop is set, or at least something which we must change before making nodrop=1 the default.
Currently uvc_queue_buffer_complete() looks like this:
static void uvc_queue_buffer_complete(struct kref *ref)
{
struct uvc_buffer *buf = container_of(ref, struct uvc_buffer, ref);
struct vb2_buffer *vb = &buf->buf.vb2_buf;
struct uvc_video_queue *queue = vb2_get_drv_priv(vb->vb2_queue);
if ((queue->flags & UVC_QUEUE_DROP_CORRUPTED) && buf->error) {
uvc_queue_buffer_requeue(queue, buf);
return;
}
buf->state = buf->error ? UVC_BUF_STATE_ERROR : UVC_BUF_STATE_DONE;
vb2_set_plane_payload(&buf->buf.vb2_buf, 0, buf->bytesused);
vb2_buffer_done(&buf->buf.vb2_buf, VB2_BUF_STATE_DONE);
}Notice how the last line does not propagate buf->error to the videobuf2 code, so when nodrop=1 is set then buffers with errors are not only returned to userspace, they are returned to userspace without V4L2_BUF_FLAG_ERROR getting set in v4l2_buffer.flags .
The right thing to do in this case is to set V4L2_BUF_FLAG_ERROR IOW the last line of uvc_queue_buffer_complete() should be changed to:
vb2_buffer_done(&buf->buf.vb2_buf, buf->error ? VB2_BUF_STATE_ERROR : VB2_BUF_STATE_DONE);
And this should probably be the first patch in a v2 series for this.
Regards,
Hans