media: uvcvideo: add quirks for per-device stream error handling
Subsystems (3)
PATCH 1/2 media: uvcvideo: add quirks for per-device stream error handling
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.
--- 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(-)
drivers/media/usb/uvc/uvcvideo.h +2 -0
@@ -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
drivers/media/usb/uvc/uvc_video.c +2 -1
@@ -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) {
drivers/media/usb/uvc/uvc_queue.c +2 -1
@@ -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
PATCH 2/2 media: uvcvideo: add device entry for Logitech C920 (046d:08e5)
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).
--- drivers/media/usb/uvc/uvc_driver.c | 12 ++++++++++++ 1 file changed, 12 insertions(+)
drivers/media/usb/uvc/uvc_driver.c +12 -0
@@ -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
kernel test robot
build botRe: [PATCH 2/2] media: uvcvideo: add device entry for Logitech C920 (046d:08e5)
kernel test robot noticed the following build errors:
Hi Pol,
kernel test robot noticed the following build errors:
[auto build test ERROR on linuxtv-media-pending/master]
[also build test ERROR on media-tree/master sailus-media-tree/master linus/master v7.2-rc7 next-20260721] [cannot apply to sailus-media-tree/streams]
[If your patch is applied to the wrong git tree, kindly drop us a note.
And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch#_base_tree_information]
url: https://github.com/intel-lab-lkp/linux/commits/Pol-Fern-ndez-Fern-ndez/media-uvcvideo-add-device-entry-for-Logitech-C920-046d-08e5/20260814-213320 base: https://git.linuxtv.org/media-ci/media-pending.git master patch link: https://lore.kernel.org/r/20260629163805.37879-2-fernandezfernandezpol%40gmail.com patch subject: [PATCH 2/2] media: uvcvideo: add device entry for Logitech C920 (046d:08e5) config: x86_64-rhel-9.4-bpf (https://download.01.org/0day-ci/archive/20260816/[email protected]/config) compiler: gcc-14 (Debian 14.2.0-19) 14.2.0 reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20260816/[email protected]/reproduce)
If you fix the issue in a separate patch/commit (i.e. not just a new version of the same patch/commit), kindly add following tags
| Reported-by: kernel test robot <[email protected]>
| Closes: https://lore.kernel.org/oe-kbuild-all/[email protected]/
All errors (new ones prefixed by >>):
drivers/media/usb/uvc/uvc_queue.c: In function 'uvc_queue_buffer_complete':
>> drivers/media/usb/uvc/uvc_queue.c:360:14: error: implicit declaration of function 'uvc_queue_to_stream'; did you mean 'uvc_queue_streaming'? [-Wimplicit-function-declaration]
360 | (uvc_queue_to_stream(queue)->dev->quirks & UVC_QUIRK_DROP_STREAM_ERR))) {
| ^~~~~~~~~~~~~~~~~~~
| uvc_queue_streaming
>> drivers/media/usb/uvc/uvc_queue.c:360:40: error: invalid type argument of '->' (have 'int')
360 | (uvc_queue_to_stream(queue)->dev->quirks & UVC_QUIRK_DROP_STREAM_ERR))) {
| ^~vim +360 drivers/media/usb/uvc/uvc_queue.c
352
353 static void uvc_queue_buffer_complete(struct kref *ref)
354 {
355 struct uvc_buffer *buf = container_of(ref, struct uvc_buffer, ref);
356 struct vb2_buffer *vb = &buf->buf.vb2_buf;
357 struct uvc_video_queue *queue = vb2_get_drv_priv(vb->vb2_queue);
358
359 if (buf->error && (!uvc_no_drop_param ||
> 360 (uvc_queue_to_stream(queue)->dev->quirks & UVC_QUIRK_DROP_STREAM_ERR))) { 361 uvc_queue_buffer_requeue(queue, buf);
362 return;
363 }
364
365 buf->state = buf->error ? UVC_BUF_STATE_ERROR : UVC_BUF_STATE_DONE;
366 vb2_set_plane_payload(&buf->buf.vb2_buf, 0, buf->bytesused);
367 vb2_buffer_done(&buf->buf.vb2_buf, buf->error ? VB2_BUF_STATE_ERROR :
368 VB2_BUF_STATE_DONE);
369 }
370
--
0-DAY CI Kernel Test Service
https://github.com/intel/lkp-tests/wiki
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!
Quoted 75 lines · Pol Fernández Fernández
The
UVC_STREAM_ERRbit in the payload header signals that the device could not deliver a frame correctly. By default, uvcvideo delivers these frames to userspace withV4L2_BUF_FLAG_ERRORwhenuvc_no_drop_paramis 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_ERRto force-drop frames flagged withUVC_STREAM_ERRfor specific devices, regardless of theuvc_no_drop_parammodule parameter. This ensures applications never receive truncated frames from devices known to setUVC_STREAM_ERRon genuine encoding errors. The existinguvc_queue_to_stream()helper is used to reach the device quirks from withinuvc_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 toUVC_STREAM_ERRevents. AddUVC_QUIRK_NO_FORCE_QUALITYto preserve the camera's default quality value during probe negotiation.Signed-off-by Pol Fernández Fernández <[email protected]>--- 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(-)drivers/media/usb/uvc/uvcvideo.h +2
-0@@ -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 0x00000001drivers/media/usb/uvc/uvc_video.c +2
-1@@ -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) {drivers/media/usb/uvc/uvc_queue.c +2
-2@@ -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
Signature · 1 line
Ricardo Ribalda
A message that is not in the archive (sent off-list or not yet received): CAD0bCtmJ88fC3zXhU5nDxugagjNMmY=FS7sO40x3OsAe41L+qg@mail.gmail.com
Hi Pol
Quoted 6 lines · Pol Fernández Fernández
Hi Ricardo,
Thank you for the feedback.
The original detection was in MATLAB, and the same corruption is reproducible in guvcview. However, the issue is not application-specific: I've confirmed the same corruption on a second machine running Ubuntu 24 with a stock kernel. It does not reproduce on two Windows 11 machines with the same C920, and does not reproduce with other UVC cameras on the same Linux system (tested with a Logitech BRIO 100 and an HP 950 4K Pro). Capturing in YUYV on the same system produces zero corruption, confirming the problem is specific to the MJPEG encoder path. This points to a specific interaction between this device's firmware and the Linux uvcvideo driver.
I just sent a patch to guvcview to fix handling the invalid frames:
https://sourceforge.net/p/guvcview/discussion/general/thread/4af26b96c8/
I hope they carry it soon.
You need to ping your MATLAB support so they fix their code.
Have you tried with the nodrop parameter?
Quoted 6 lines
The patch series addresses two separate contributing factors:
Regarding
UVC_QUIRK_NO_FORCE_QUALITY: uvcvideo unconditionally overrides wCompQuality withGET_MAX(61 for this device) during probe negotiation, discarding the camera'sGET_CURvalue of 0, which this firmware uses to indicate adaptive encoding mode. The Windows UVC driver does not perform this override, and the camera works correctly there. Forcing maximum quality increases encoder pressure and raises the frequency ofUVC_STREAM_ERRevents. This is a driver-side behavior that contributes to the problem independently of what any application does.Regarding
UVC_QUIRK_DROP_STREAM_ERR: uvc_no_drop_param=0 would address the symptom, but it applies globally to all UVC cameras on the system. A per-device quirk limits the behavior change strictly to the device with the confirmed firmware bug.
I do not think there is a firmware bug. It is flagging the invalid frames properly; userspace is processing invalid frames.
Quoted 100 lines
Best regards!
Pol Fernández FernándezQuoted 95 lines · Ricardo Ribalda
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_prodto 0Something like:
rmmod uvcvideo
modprobe uvcvideo nodrop=0Regards!
Quoted 73 lines · Pol Fernández Fernández
The
UVC_STREAM_ERRbit in the payload header signals that the device could not deliver a frame correctly. By default, uvcvideo delivers these frames to userspace withV4L2_BUF_FLAG_ERRORwhenuvc_no_drop_paramis 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_ERRto force-drop frames flagged withUVC_STREAM_ERRfor specific devices, regardless of theuvc_no_drop_parammodule parameter. This ensures applications never receive truncated frames from devices known to setUVC_STREAM_ERRon genuine encoding errors. The existinguvc_queue_to_stream()helper is used to reach the device quirks from withinuvc_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 toUVC_STREAM_ERRevents. AddUVC_QUIRK_NO_FORCE_QUALITYto preserve the camera's default quality value during probe negotiation.Signed-off-by Pol Fernández Fernández <[email protected]>--- 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(-)drivers/media/usb/uvc/uvcvideo.h +2
-0@@ -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 0x00000001drivers/media/usb/uvc/uvc_video.c +2
-1@@ -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) {drivers/media/usb/uvc/uvc_queue.c +2
-2@@ -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 ; } --Quoted 2 lines
2.43.0
--
Ricardo Ribalda
Signature · 1 line
Ricardo Ribalda
Laurent Pinchart
maintainerQuoted 8 lines · Pol Fernández Fernández
The
UVC_STREAM_ERRbit in the payload header signals that the device could not deliver a frame correctly. By default, uvcvideo delivers these frames to userspace withV4L2_BUF_FLAG_ERRORwhenuvc_no_drop_paramis 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.
Quoted 4 lines
Add
UVC_QUIRK_DROP_STREAM_ERRto force-drop frames flagged withUVC_STREAM_ERRfor specific devices, regardless of theuvc_no_drop_parammodule parameter. This ensures applications never receive truncated frames from devices known to setUVC_STREAM_ERRon 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.
Quoted 8 lines
The existing
uvc_queue_to_stream()helper is used to reach the device quirks from withinuvc_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 ?
Quoted 5 lines
this override increases encoding pressure and can contribute to
UVC_STREAM_ERRevents. AddUVC_QUIRK_NO_FORCE_QUALITYto preserve the camera's default quality value during probe negotiation.Signed-off-by Pol Fernández Fernández <[email protected]>
Please split this patch in two as it addresses two different issues.
Quoted 47 lines
--- 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(-)drivers/media/usb/uvc/uvcvideo.h +2
-0@@ -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 0x00000001drivers/media/usb/uvc/uvc_video.c +2
-1@@ -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) {drivers/media/usb/uvc/uvc_queue.c +2
-1@@ -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 ; }
Signature · 3 lines
Regards, Laurent Pinchart