Linux USB
 help / color / mirror / Atom feed
From: "Pol Fernández Fernández" <fernandezfernandezpol@gmail.com>
To: linux-media@vger.kernel.org
Cc: laurent.pinchart@ideasonboard.com, linux-usb@vger.kernel.org,
	linux-kernel@vger.kernel.org,
	"Pol Fernández Fernández" <fernandezfernandezpol@gmail.com>
Subject: [PATCH 1/2] media: uvcvideo: add quirks for per-device stream error handling
Date: Mon, 29 Jun 2026 18:38:02 +0200	[thread overview]
Message-ID: <20260629163805.37879-1-fernandezfernandezpol@gmail.com> (raw)

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

             reply	other threads:[~2026-06-29 16:38 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-06-29 16:38 Pol Fernández Fernández [this message]
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

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20260629163805.37879-1-fernandezfernandezpol@gmail.com \
    --to=fernandezfernandezpol@gmail.com \
    --cc=laurent.pinchart@ideasonboard.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-media@vger.kernel.org \
    --cc=linux-usb@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox