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

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