From: Hans de Goede <hansg@kernel.org>
To: Ricardo Ribalda <ribalda@chromium.org>,
Laurent Pinchart <laurent.pinchart@ideasonboard.com>,
Mauro Carvalho Chehab <mchehab@kernel.org>,
Guennadi Liakhovetski <guennadi.liakhovetski@intel.com>,
Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Cc: linux-media@vger.kernel.org, linux-kernel@vger.kernel.org,
linux-usb@vger.kernel.org
Subject: Re: [PATCH v8 3/5] media: uvcvideo: Introduce dev->meta_formats
Date: Mon, 7 Jul 2025 22:55:41 +0200 [thread overview]
Message-ID: <5ae0db7f-6528-4eeb-8747-09be203e0089@kernel.org> (raw)
In-Reply-To: <20250707-uvc-meta-v8-3-ed17f8b1218b@chromium.org>
Hi,
On 7-Jul-25 8:34 PM, Ricardo Ribalda wrote:
> Right now, there driver supports devices with one or two metadata
> formats. Prepare it to support more than two metadata formats.
>
> This is achieved with the introduction of a new field `meta_formats`,
> that contains the array of metadata formats supported by the device, in
> the order expected by userspace.
>
> Suggested-by: Hans de Goede <hansg@kernel.org>
> Signed-off-by: Ricardo Ribalda <ribalda@chromium.org>
Thanks, patch looks good to me:
Reviewed-by: Hans de Goede <hansg@kernel.org>
Regards,
Hans
> ---
> drivers/media/usb/uvc/uvc_driver.c | 2 ++
> drivers/media/usb/uvc/uvc_metadata.c | 38 +++++++++++++++++++++++++++++-------
> drivers/media/usb/uvc/uvcvideo.h | 6 ++++++
> 3 files changed, 39 insertions(+), 7 deletions(-)
>
> diff --git a/drivers/media/usb/uvc/uvc_driver.c b/drivers/media/usb/uvc/uvc_driver.c
> index 62eb45435d8bec5c955720ecb46fb8936871e6cc..56ea20eeb7b9d5d92f3d837c15bdf11d536e9f2d 100644
> --- a/drivers/media/usb/uvc/uvc_driver.c
> +++ b/drivers/media/usb/uvc/uvc_driver.c
> @@ -2315,6 +2315,8 @@ static int uvc_probe(struct usb_interface *intf,
> goto error;
> }
>
> + uvc_meta_init(dev);
> +
> if (dev->quirks & UVC_QUIRK_NO_RESET_RESUME)
> udev->quirks &= ~USB_QUIRK_RESET_RESUME;
>
> diff --git a/drivers/media/usb/uvc/uvc_metadata.c b/drivers/media/usb/uvc/uvc_metadata.c
> index 82de7781f5b6b70c5ba16bcba9e0741231231904..4bcbc22f47e67c52baf6e133f240131ff3d32a03 100644
> --- a/drivers/media/usb/uvc/uvc_metadata.c
> +++ b/drivers/media/usb/uvc/uvc_metadata.c
> @@ -64,14 +64,20 @@ static int uvc_meta_v4l2_try_format(struct file *file, void *fh,
> struct uvc_device *dev = stream->dev;
> struct v4l2_meta_format *fmt = &format->fmt.meta;
> u32 fmeta = fmt->dataformat;
> + u32 i;
>
> if (format->type != vfh->vdev->queue->type)
> return -EINVAL;
>
> + for (i = 0; (fmeta != dev->meta_formats[i]) && dev->meta_formats[i];
> + i++)
> + ;
> + if (!dev->meta_formats[i])
> + fmeta = V4L2_META_FMT_UVC;
> +
> memset(fmt, 0, sizeof(*fmt));
>
> - fmt->dataformat = fmeta == dev->info->meta_format
> - ? fmeta : V4L2_META_FMT_UVC;
> + fmt->dataformat = fmeta;
> fmt->buffersize = UVC_METADATA_BUF_SIZE;
>
> return 0;
> @@ -112,17 +118,21 @@ static int uvc_meta_v4l2_enum_formats(struct file *file, void *fh,
> struct v4l2_fh *vfh = file->private_data;
> struct uvc_streaming *stream = video_get_drvdata(vfh->vdev);
> struct uvc_device *dev = stream->dev;
> - u32 index = fdesc->index;
> + u32 i;
> +
> + if (fdesc->type != vfh->vdev->queue->type)
> + return -EINVAL;
>
> - if (fdesc->type != vfh->vdev->queue->type ||
> - index > 1U || (index && !dev->info->meta_format))
> + for (i = 0; (i < fdesc->index) && dev->meta_formats[i]; i++)
> + ;
> + if (!dev->meta_formats[i])
> return -EINVAL;
>
> memset(fdesc, 0, sizeof(*fdesc));
>
> fdesc->type = vfh->vdev->queue->type;
> - fdesc->index = index;
> - fdesc->pixelformat = index ? dev->info->meta_format : V4L2_META_FMT_UVC;
> + fdesc->index = i;
> + fdesc->pixelformat = dev->meta_formats[i];
>
> return 0;
> }
> @@ -174,3 +184,17 @@ int uvc_meta_register(struct uvc_streaming *stream)
> V4L2_BUF_TYPE_META_CAPTURE,
> &uvc_meta_fops, &uvc_meta_ioctl_ops);
> }
> +
> +void uvc_meta_init(struct uvc_device *dev)
> +{
> + unsigned int i = 0;
> +
> + dev->meta_formats[i++] = V4L2_META_FMT_UVC;
> +
> + if (dev->info->meta_format &&
> + !WARN_ON(dev->info->meta_format == V4L2_META_FMT_UVC))
> + dev->meta_formats[i++] = dev->info->meta_format;
> +
> + /* IMPORTANT: for new meta-formats update UVC_MAX_META_DATA_FORMATS. */
> + dev->meta_formats[i++] = 0;
> +}
> diff --git a/drivers/media/usb/uvc/uvcvideo.h b/drivers/media/usb/uvc/uvcvideo.h
> index 11d6e3c2ebdfbabd7bbe5722f88ff85f406d9bb6..b3c094c6591e7a71fc00e1096bcf493a83f330ad 100644
> --- a/drivers/media/usb/uvc/uvcvideo.h
> +++ b/drivers/media/usb/uvc/uvcvideo.h
> @@ -572,6 +572,8 @@ struct uvc_status {
> };
> } __packed;
>
> +#define UVC_MAX_META_DATA_FORMATS 3
> +
> struct uvc_device {
> struct usb_device *udev;
> struct usb_interface *intf;
> @@ -582,6 +584,9 @@ struct uvc_device {
>
> const struct uvc_device_info *info;
>
> + /* Zero-ended list of meta formats */
> + u32 meta_formats[UVC_MAX_META_DATA_FORMATS + 1];
> +
> atomic_t nmappings;
>
> /* Video control interface */
> @@ -751,6 +756,7 @@ int uvc_query_ctrl(struct uvc_device *dev, u8 query, u8 unit,
> void uvc_video_clock_update(struct uvc_streaming *stream,
> struct vb2_v4l2_buffer *vbuf,
> struct uvc_buffer *buf);
> +void uvc_meta_init(struct uvc_device *dev);
> int uvc_meta_register(struct uvc_streaming *stream);
>
> int uvc_register_video_device(struct uvc_device *dev,
>
next prev parent reply other threads:[~2025-07-07 20:55 UTC|newest]
Thread overview: 21+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-07-07 18:34 [PATCH v8 0/5] media: uvcvideo: Introduce V4L2_META_FMT_UVC_MSXU_1_5 + other meta fixes Ricardo Ribalda
2025-07-07 18:34 ` [PATCH v8 1/5] media: uvcvideo: Do not mark valid metadata as invalid Ricardo Ribalda
2025-07-07 18:34 ` [PATCH v8 2/5] media: Documentation: Add note about UVCH length field Ricardo Ribalda
2025-07-07 18:34 ` [PATCH v8 3/5] media: uvcvideo: Introduce dev->meta_formats Ricardo Ribalda
2025-07-07 20:55 ` Hans de Goede [this message]
2025-07-07 18:34 ` [PATCH v8 4/5] media: uvcvideo: Introduce V4L2_META_FMT_UVC_MSXU_1_5 Ricardo Ribalda
2025-07-11 20:13 ` Laurent Pinchart
2025-07-14 7:44 ` Ricardo Ribalda
2025-07-14 14:59 ` Laurent Pinchart
2025-07-14 16:21 ` Ricardo Ribalda
2025-07-14 16:27 ` Laurent Pinchart
2025-07-14 16:42 ` Ricardo Ribalda
2025-07-14 17:07 ` Laurent Pinchart
2025-07-14 17:32 ` Ricardo Ribalda
2025-07-07 18:34 ` [PATCH v8 5/5] media: uvcvideo: Auto-set UVC_QUIRK_MSXU_META Ricardo Ribalda
2025-07-11 19:58 ` Laurent Pinchart
2025-07-14 7:46 ` Ricardo Ribalda
2025-07-14 8:06 ` Laurent Pinchart
2025-07-14 8:21 ` Ricardo Ribalda
2025-07-14 8:34 ` Laurent Pinchart
2025-07-07 21:00 ` [PATCH v8 0/5] media: uvcvideo: Introduce V4L2_META_FMT_UVC_MSXU_1_5 + other meta fixes Hans de Goede
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=5ae0db7f-6528-4eeb-8747-09be203e0089@kernel.org \
--to=hansg@kernel.org \
--cc=gregkh@linuxfoundation.org \
--cc=guennadi.liakhovetski@intel.com \
--cc=laurent.pinchart@ideasonboard.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-media@vger.kernel.org \
--cc=linux-usb@vger.kernel.org \
--cc=mchehab@kernel.org \
--cc=ribalda@chromium.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;
as well as URLs for NNTP newsgroup(s).