Linux USB
 help / color / mirror / Atom feed
* [PATCH 1/2] media: uvcvideo: add quirks for per-device stream error handling
@ 2026-06-29 16:38 Pol Fernández Fernández
  2026-06-29 16:38 ` [PATCH 2/2] media: uvcvideo: add device entry for Logitech C920 (046d:08e5) Pol Fernández Fernández
                   ` (2 more replies)
  0 siblings, 3 replies; 4+ messages in thread
From: Pol Fernández Fernández @ 2026-06-29 16:38 UTC (permalink / raw)
  To: linux-media
  Cc: laurent.pinchart, linux-usb, linux-kernel,
	Pol Fernández Fernández

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@gmail.com>
---
 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

^ permalink raw reply	[flat|nested] 4+ messages in thread

* [PATCH 2/2] media: uvcvideo: add device entry for Logitech C920 (046d:08e5)
  2026-06-29 16:38 [PATCH 1/2] media: uvcvideo: add quirks for per-device stream error handling Pol Fernández Fernández
@ 2026-06-29 16:38 ` Pol Fernández Fernández
  2026-06-29 16:55 ` [PATCH 1/2] media: uvcvideo: add quirks for per-device stream error handling Ricardo Ribalda
  2026-06-29 18:23 ` Laurent Pinchart
  2 siblings, 0 replies; 4+ messages in thread
From: Pol Fernández Fernández @ 2026-06-29 16:38 UTC (permalink / raw)
  To: linux-media
  Cc: laurent.pinchart, linux-usb, linux-kernel,
	Pol Fernández Fernández

The Logitech HD Pro Webcam C920 variant with USB ID 046d:08e5 is not
present in the device ID table and is matched only by the generic UVC
catch-all entry, receiving no device-specific quirks.

This device intermittently sends MJPEG frames at 1920x1080/30fps
without the EOI (0xFF 0xD9) End of Image marker, correctly signaling
the incomplete frame via UVC_STREAM_ERR in the UVC payload header.
Applications using strict JPEG decoders (libjpeg) display the corrupted
portion as a gray band covering the remainder of the frame. The issue
does not occur on Windows.

Two contributing factors were identified:

1. The C920 (08e5) operates at the USB 2.0 High Speed isochronous
   ceiling (wMaxPacketSize = 3x1024 = 3072 bytes, altsetting 11).
   The camera firmware has an intermittent bug where it occasionally
   fails to finalize a JPEG frame and signals this correctly via
   UVC_STREAM_ERR. No USB-level isochronous packet failures were
   observed (iso_frame_desc.status was always 0).

2. uvcvideo forces wCompQuality to the maximum value returned by
   GET_MAX during probe negotiation (61 for this device, on a
   firmware-specific scale). The camera's default value from GET_CUR
   is 0, which this firmware uses to indicate adaptive encoding mode.
   Forcing maximum quality increases encoder pressure and raises the
   frequency of UVC_STREAM_ERR events.

Add a device table entry with:
- UVC_QUIRK_RESTORE_CTRLS_ON_INIT and UVC_QUIRK_INVALID_DEVICE_SOF,
  consistent with the existing entry for the related 046d:082d variant
  of the same camera family.
- UVC_QUIRK_NO_FORCE_QUALITY to preserve wCompQuality=0 (adaptive
  mode) during probe negotiation rather than overriding it with the
  maximum value.
- UVC_QUIRK_DROP_STREAM_ERR to ensure frames flagged with
  UVC_STREAM_ERR are silently dropped rather than delivered to
  userspace as truncated JPEG data.

Tested on Linux 7.0.0 at 1920x1080 MJPEG 30fps. With this fix, 0
truncated frames were observed in 300-frame capture sequences
(previously 1-2% of frames were affected).

Signed-off-by: Pol Fernández Fernández <fernandezfernandezpol@gmail.com>
---
 drivers/media/usb/uvc/uvc_driver.c | 12 ++++++++++++
 1 file changed, 12 insertions(+)

diff --git a/drivers/media/usb/uvc/uvc_driver.c b/drivers/media/usb/uvc/uvc_driver.c
index XXXXXXX..XXXXXXX 100644
--- a/drivers/media/usb/uvc/uvc_driver.c
+++ b/drivers/media/usb/uvc/uvc_driver.c
@@ -2729,6 +2729,18 @@
 	  .bInterfaceSubClass	= 1,
 	  .bInterfaceProtocol	= 0,
 	  .driver_info		= UVC_INFO_QUIRK(UVC_QUIRK_NO_RESET_RESUME) },
+	/* Logitech HD Pro Webcam C920 (variant 08e5) */
+	{ .match_flags		= USB_DEVICE_ID_MATCH_DEVICE
+				| USB_DEVICE_ID_MATCH_INT_INFO,
+	  .idVendor		= 0x046d,
+	  .idProduct		= 0x08e5,
+	  .bInterfaceClass	= USB_CLASS_VIDEO,
+	  .bInterfaceSubClass	= 1,
+	  .bInterfaceProtocol	= 0,
+	  .driver_info		= UVC_INFO_QUIRK(UVC_QUIRK_RESTORE_CTRLS_ON_INIT
+					       | UVC_QUIRK_INVALID_DEVICE_SOF
+					       | UVC_QUIRK_NO_FORCE_QUALITY
+					       | UVC_QUIRK_DROP_STREAM_ERR) },
 	/* Chicony CNF7129 (Asus EEE 100HE) */
 	{ .match_flags		= USB_DEVICE_ID_MATCH_DEVICE
 				| USB_DEVICE_ID_MATCH_INT_INFO,
--
2.43.0

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH 1/2] media: uvcvideo: add quirks for per-device stream error handling
  2026-06-29 16:38 [PATCH 1/2] media: uvcvideo: add quirks for per-device stream error handling Pol Fernández Fernández
  2026-06-29 16:38 ` [PATCH 2/2] media: uvcvideo: add device entry for Logitech C920 (046d:08e5) Pol Fernández Fernández
@ 2026-06-29 16:55 ` Ricardo Ribalda
  2026-06-29 18:23 ` Laurent Pinchart
  2 siblings, 0 replies; 4+ messages in thread
From: Ricardo Ribalda @ 2026-06-29 16:55 UTC (permalink / raw)
  To: Pol Fernández Fernández
  Cc: linux-media, laurent.pinchart, linux-usb, linux-kernel

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@gmail.com> 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@gmail.com>
> ---
>  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

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH 1/2] media: uvcvideo: add quirks for per-device stream error handling
  2026-06-29 16:38 [PATCH 1/2] media: uvcvideo: add quirks for per-device stream error handling Pol Fernández Fernández
  2026-06-29 16:38 ` [PATCH 2/2] media: uvcvideo: add device entry for Logitech C920 (046d:08e5) Pol Fernández Fernández
  2026-06-29 16:55 ` [PATCH 1/2] media: uvcvideo: add quirks for per-device stream error handling Ricardo Ribalda
@ 2026-06-29 18:23 ` Laurent Pinchart
  2 siblings, 0 replies; 4+ messages in thread
From: Laurent Pinchart @ 2026-06-29 18:23 UTC (permalink / raw)
  To: Pol Fernández Fernández; +Cc: linux-media, linux-usb, linux-kernel

On Mon, Jun 29, 2026 at 06:38:02PM +0200, Pol Fernández Fernández 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.

That completely defeats the point of uvc_no_drop_param. The issue should
be fixed in userspace, where you should ignore frames with the error
flag set if desired.

> 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),

The UVC 1.1 specification documents the range wCompQuality values as

"Values for this property range from 0 to 10000 (0 indicates the lowest
quality, 10000 the highest)."

While the UVC 1.5 specification documents it as

"Values for this property range from 1 to 10000 (1 indicates the lowest
quality, 10000 the highest)."

There is no mention of 0 being allowed as a magic value. Where did you
find information about the adaptive encoding mode ?

> 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@gmail.com>

Please split this patch in two as it addresses two different issues.

> ---
>  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;
>  	}

-- 
Regards,

Laurent Pinchart

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2026-06-29 18:23 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-06-29 16:38 [PATCH 1/2] media: uvcvideo: add quirks for per-device stream error handling Pol Fernández Fernández
2026-06-29 16:38 ` [PATCH 2/2] media: uvcvideo: add device entry for Logitech C920 (046d:08e5) Pol Fernández Fernández
2026-06-29 16:55 ` [PATCH 1/2] media: uvcvideo: add quirks for per-device stream error handling Ricardo Ribalda
2026-06-29 18:23 ` Laurent Pinchart

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox