Re: [PATCH 1/2] media: uvcvideo: add quirks for per-device stream error handling
From: Ricardo Ribalda
Date: Mon Jun 29 2026 - 12:57:04 EST
Hi Pol
What application are you using to fetch frames? It should not process
frames with the error flag.
If you cannot fix your application, why don't you set the parameter no_prod to 0
Something like:
rmmod uvcvideo
modprobe uvcvideo nodrop=0
Regards!
On Mon, 29 Jun 2026 at 18:38, Pol Fernández Fernández
<fernandezfernandezpol@xxxxxxxxx> wrote:
>
> The UVC_STREAM_ERR bit in the payload header signals that the device
> could not deliver a frame correctly. By default, uvcvideo delivers
> these frames to userspace with V4L2_BUF_FLAG_ERROR when uvc_no_drop_param
> is set (the default). Applications that rely on strict JPEG decoders
> (e.g. libjpeg) will display gray bands for the incomplete portion of
> the image, since libjpeg fills undecodable MCU rows with a neutral gray
> when the EOI marker is missing.
>
> Add UVC_QUIRK_DROP_STREAM_ERR to force-drop frames flagged with
> UVC_STREAM_ERR for specific devices, regardless of the uvc_no_drop_param
> module parameter. This ensures applications never receive truncated frames
> from devices known to set UVC_STREAM_ERR on genuine encoding errors.
> The existing uvc_queue_to_stream() helper is used to reach the device
> quirks from within uvc_queue_buffer_complete().
>
> Additionally, uvcvideo unconditionally overrides the camera's probed
> wCompQuality with the maximum value returned by GET_MAX. For devices
> whose firmware treats wCompQuality=0 as an adaptive encoding mode (where
> the encoder adjusts quality dynamically to fit within the available USB
> bandwidth), this override increases encoding pressure and can contribute
> to UVC_STREAM_ERR events. Add UVC_QUIRK_NO_FORCE_QUALITY to preserve
> the camera's default quality value during probe negotiation.
>
> Signed-off-by: Pol Fernández Fernández <fernandezfernandezpol@xxxxxxxxx>
> ---
> drivers/media/usb/uvc/uvc_queue.c | 3 ++-
> drivers/media/usb/uvc/uvc_video.c | 3 ++-
> drivers/media/usb/uvc/uvcvideo.h | 2 ++
> 3 files changed, 6 insertions(+), 2 deletions(-)
>
> diff --git a/drivers/media/usb/uvc/uvcvideo.h b/drivers/media/usb/uvc/uvcvideo.h
> index XXXXXXX..XXXXXXX 100644
> --- a/drivers/media/usb/uvc/uvcvideo.h
> +++ b/drivers/media/usb/uvc/uvcvideo.h
> @@ -81,6 +81,8 @@
> #define UVC_QUIRK_INVALID_DEVICE_SOF 0x00010000
> #define UVC_QUIRK_MJPEG_NO_EOF 0x00020000
> #define UVC_QUIRK_MSXU_META 0x00040000
> +#define UVC_QUIRK_DROP_STREAM_ERR 0x00080000
> +#define UVC_QUIRK_NO_FORCE_QUALITY 0x00100000
>
> /* Format flags */
> #define UVC_FMT_FLAG_COMPRESSED 0x00000001
> diff --git a/drivers/media/usb/uvc/uvc_video.c b/drivers/media/usb/uvc/uvc_video.c
> index XXXXXXX..XXXXXXX 100644
> --- a/drivers/media/usb/uvc/uvc_video.c
> +++ b/drivers/media/usb/uvc/uvc_video.c
> @@ -451,7 +451,8 @@ int uvc_probe_video(struct uvc_streaming *stream,
> if (ret < 0)
> goto done;
>
> - probe->wCompQuality = probe_max.wCompQuality;
> + if (!(stream->dev->quirks & UVC_QUIRK_NO_FORCE_QUALITY))
> + probe->wCompQuality = probe_max.wCompQuality;
> }
>
> for (i = 0; i < 2; ++i) {
> diff --git a/drivers/media/usb/uvc/uvc_queue.c b/drivers/media/usb/uvc/uvc_queue.c
> index XXXXXXX..XXXXXXX 100644
> --- a/drivers/media/usb/uvc/uvc_queue.c
> +++ b/drivers/media/usb/uvc/uvc_queue.c
> @@ -357,7 +357,8 @@ 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 (buf->error && !uvc_no_drop_param) {
> + if (buf->error && (!uvc_no_drop_param ||
> + (uvc_queue_to_stream(queue)->dev->quirks & UVC_QUIRK_DROP_STREAM_ERR))) {
> uvc_queue_buffer_requeue(queue, buf);
> return;
> }
> --
> 2.43.0
>
--
Ricardo Ribalda