All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] media: uvcvideo: Ensure all probed info is returned to v4l2
@ 2020-04-24  5:36 Adam Goode
  2020-07-06 18:28 ` Adam Goode
  0 siblings, 1 reply; 2+ messages in thread
From: Adam Goode @ 2020-04-24  5:36 UTC (permalink / raw)
  To: Laurent Pinchart, Mauro Carvalho Chehab
  Cc: linux-media, linux-kernel, Adam Goode

bFrameIndex and bFormatIndex can be negotiated by the camera during
probing, resulting in the camera choosing a different format than
expected. v4l2 can already accommodate such changes, but the code was
not updating the proper fields.

Without such a change, v4l2 would potentially interpret the payload
incorrectly, causing corrupted output. This was happening on the
Elgato HD60 S+, which currently always renegotiates to format 1.

As an aside, the Elgato firmware is buggy and should not be renegotating,
but it is still a valid thing for the camera to do. Both macOS and Windows
will properly probe and read uncorrupted images from this camera.

With this change, both qv4l2 and chromium can now read uncorrupted video
from the Elgato HD60 S+.

Signed-off-by: Adam Goode <agoode@google.com>
---
 drivers/media/usb/uvc/uvc_v4l2.c | 26 ++++++++++++++++++++++++++
 1 file changed, 26 insertions(+)

diff --git a/drivers/media/usb/uvc/uvc_v4l2.c b/drivers/media/usb/uvc/uvc_v4l2.c
index 0335e69b70ab..7f14096cb44d 100644
--- a/drivers/media/usb/uvc/uvc_v4l2.c
+++ b/drivers/media/usb/uvc/uvc_v4l2.c
@@ -247,11 +247,37 @@ static int uvc_v4l2_try_format(struct uvc_streaming *stream,
 	if (ret < 0)
 		goto done;
 
+	/* After the probe, update fmt with the values returned from
+	 * negotiation with the device.
+	 */
+	for (i = 0; i < stream->nformats; ++i) {
+		if (probe->bFormatIndex == stream->format[i].index) {
+			format = &stream->format[i];
+			break;
+		}
+	}
+	if (i == stream->nformats) {
+		uvc_trace(UVC_TRACE_FORMAT, "Unknown bFormatIndex %u.\n",
+			  probe->bFormatIndex);
+		return -EINVAL;
+	}
+	for (i = 0; i < format->nframes; ++i) {
+		if (probe->bFrameIndex == format->frame[i].bFrameIndex) {
+			frame = &format->frame[i];
+			break;
+		}
+	}
+	if (i == format->nframes) {
+		uvc_trace(UVC_TRACE_FORMAT, "Unknown bFrameIndex %u.\n",
+			  probe->bFrameIndex);
+		return -EINVAL;
+	}
 	fmt->fmt.pix.width = frame->wWidth;
 	fmt->fmt.pix.height = frame->wHeight;
 	fmt->fmt.pix.field = V4L2_FIELD_NONE;
 	fmt->fmt.pix.bytesperline = uvc_v4l2_get_bytesperline(format, frame);
 	fmt->fmt.pix.sizeimage = probe->dwMaxVideoFrameSize;
+	fmt->fmt.pix.pixelformat = format->fcc;
 	fmt->fmt.pix.colorspace = format->colorspace;
 
 	if (uvc_format != NULL)
-- 
2.25.3


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

* Re: [PATCH] media: uvcvideo: Ensure all probed info is returned to v4l2
  2020-04-24  5:36 [PATCH] media: uvcvideo: Ensure all probed info is returned to v4l2 Adam Goode
@ 2020-07-06 18:28 ` Adam Goode
  0 siblings, 0 replies; 2+ messages in thread
From: Adam Goode @ 2020-07-06 18:28 UTC (permalink / raw)
  To: Laurent Pinchart, Mauro Carvalho Chehab; +Cc: linux-media, linux-kernel

On Fri, Apr 24, 2020 at 1:37 AM Adam Goode <agoode@google.com> wrote:
>
> bFrameIndex and bFormatIndex can be negotiated by the camera during
> probing, resulting in the camera choosing a different format than
> expected. v4l2 can already accommodate such changes, but the code was
> not updating the proper fields.
>
> Without such a change, v4l2 would potentially interpret the payload
> incorrectly, causing corrupted output. This was happening on the
> Elgato HD60 S+, which currently always renegotiates to format 1.
>
> As an aside, the Elgato firmware is buggy and should not be renegotating,
> but it is still a valid thing for the camera to do. Both macOS and Windows
> will properly probe and read uncorrupted images from this camera.
>
> With this change, both qv4l2 and chromium can now read uncorrupted video
> from the Elgato HD60 S+.
>
> Signed-off-by: Adam Goode <agoode@google.com>
> ---
>  drivers/media/usb/uvc/uvc_v4l2.c | 26 ++++++++++++++++++++++++++
>  1 file changed, 26 insertions(+)
>
> diff --git a/drivers/media/usb/uvc/uvc_v4l2.c b/drivers/media/usb/uvc/uvc_v4l2.c
> index 0335e69b70ab..7f14096cb44d 100644
> --- a/drivers/media/usb/uvc/uvc_v4l2.c
> +++ b/drivers/media/usb/uvc/uvc_v4l2.c
> @@ -247,11 +247,37 @@ static int uvc_v4l2_try_format(struct uvc_streaming *stream,
>         if (ret < 0)
>                 goto done;
>
> +       /* After the probe, update fmt with the values returned from
> +        * negotiation with the device.
> +        */
> +       for (i = 0; i < stream->nformats; ++i) {
> +               if (probe->bFormatIndex == stream->format[i].index) {
> +                       format = &stream->format[i];
> +                       break;
> +               }
> +       }
> +       if (i == stream->nformats) {
> +               uvc_trace(UVC_TRACE_FORMAT, "Unknown bFormatIndex %u.\n",
> +                         probe->bFormatIndex);
> +               return -EINVAL;
> +       }
> +       for (i = 0; i < format->nframes; ++i) {
> +               if (probe->bFrameIndex == format->frame[i].bFrameIndex) {
> +                       frame = &format->frame[i];
> +                       break;
> +               }
> +       }
> +       if (i == format->nframes) {
> +               uvc_trace(UVC_TRACE_FORMAT, "Unknown bFrameIndex %u.\n",
> +                         probe->bFrameIndex);
> +               return -EINVAL;
> +       }
>         fmt->fmt.pix.width = frame->wWidth;
>         fmt->fmt.pix.height = frame->wHeight;
>         fmt->fmt.pix.field = V4L2_FIELD_NONE;
>         fmt->fmt.pix.bytesperline = uvc_v4l2_get_bytesperline(format, frame);
>         fmt->fmt.pix.sizeimage = probe->dwMaxVideoFrameSize;
> +       fmt->fmt.pix.pixelformat = format->fcc;
>         fmt->fmt.pix.colorspace = format->colorspace;
>
>         if (uvc_format != NULL)
> --
> 2.25.3
>

Hi,

Could someone please take a look at this patch? Is there another
process I should follow to have this reviewed?


Thanks,

Adam

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

end of thread, other threads:[~2020-07-06 18:28 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-04-24  5:36 [PATCH] media: uvcvideo: Ensure all probed info is returned to v4l2 Adam Goode
2020-07-06 18:28 ` Adam Goode

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.