From: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
To: Ricardo Ribalda <ribalda@chromium.org>
Cc: Hans de Goede <hansg@kernel.org>,
Mauro Carvalho Chehab <mchehab@kernel.org>,
Guennadi Liakhovetski <guennadi.liakhovetski@intel.com>,
linux-media@vger.kernel.org, linux-kernel@vger.kernel.org,
Yunke Cao <yunkec@google.com>
Subject: Re: [PATCH 3/3] media: uvcvideo: Allow userspace to increase the meta buffersize
Date: Wed, 18 Mar 2026 21:36:33 +0200 [thread overview]
Message-ID: <20260318193633.GA720831@killaraus.ideasonboard.com> (raw)
In-Reply-To: <CANiDSCu9DNoUX=D5Ywh6UxoswR=FF4S3BZYYJ_iqbizuQv43WQ@mail.gmail.com>
On Wed, Mar 18, 2026 at 08:29:58PM +0100, Ricardo Ribalda wrote:
> On Wed, 18 Mar 2026 at 20:22, Laurent Pinchart wrote:
> > On Mon, Mar 09, 2026 at 03:01:56PM +0000, Ricardo Ribalda wrote:
> > > Now we have the metadata size hardcoded to 10 KiB, this is a value that
> > > works fine for bulk cameras or frames with no extra metadata. But not
> > > for all usecases.
> > >
> > > We have seen some cameras that produce more metadata per frame. Eg:
> >
> > Can you tell what camera that is ?
>
> It is a pretty standard Sunplus camera. It should be producing frames
> at 30fps, but it had AutoFramerate based on exposure enabled and the
> real fps was 15.
> As a result of that there was twice of empty packages.
>
> If you are really curious I can try to dig the lsusb.
No, it's OK. I was wondering if it was anything special.
> > > Frame 1 captured (Bytes: 11154)
> > > Frame 2 captured (Bytes: 11616)
> > > Frame 3 captured (Bytes: 11374)
> > > Frame 4 captured (Bytes: 11132)
> > > Frame 5 captured (Bytes: 11594)
> > > Frame 6 captured (Bytes: 11352)
> > > Frame 7 captured (Bytes: 11110)
> > > Frame 8 captured (Bytes: 11572)
> > > Frame 9 captured (Bytes: 11308)
> > >
> > > When this happens, the driver (correctly) marks the metadata as ERROR.
> >
> > Is the maximum metadata size queryable through an XU on your devices ?
>
> There is no metadata in this device, just timing information.
>
> In MSXU there is a contol to set the size of the metadata. It is in
> kilobytes :S and pretty much every device I've seen implements it
> incorrectly.
Ah yes I remember you told me that. Lovely :-)
> > > This patch let userspace set bigger buffersize via S_FMT.
> > >
> > > Signed-off-by: Ricardo Ribalda <ribalda@chromium.org>
> > > ---
> > > drivers/media/usb/uvc/uvc_metadata.c | 9 +++++++--
> > > drivers/media/usb/uvc/uvc_queue.c | 2 +-
> > > drivers/media/usb/uvc/uvcvideo.h | 3 ++-
> > > 3 files changed, 10 insertions(+), 4 deletions(-)
> > >
> > > diff --git a/drivers/media/usb/uvc/uvc_metadata.c b/drivers/media/usb/uvc/uvc_metadata.c
> > > index 0a906ae3f971..9de8aba1229e 100644
> > > --- a/drivers/media/usb/uvc/uvc_metadata.c
> > > +++ b/drivers/media/usb/uvc/uvc_metadata.c
> > > @@ -50,7 +50,7 @@ static int uvc_meta_v4l2_get_format(struct file *file, void *priv,
> > > return -EINVAL;
> > >
> > > fmt->dataformat = stream->meta.format;
> > > - fmt->buffersize = UVC_METADATA_BUF_SIZE;
> > > + fmt->buffersize = stream->meta.buffersize;
> > >
> > > return 0;
> > > }
> > > @@ -63,6 +63,7 @@ static int uvc_meta_v4l2_try_format(struct file *file, void *priv,
> > > struct uvc_device *dev = stream->dev;
> > > struct v4l2_meta_format *fmt = &format->fmt.meta;
> > > u32 fmeta = V4L2_META_FMT_UVC;
> > > + u32 buffersize;
> > >
> > > if (format->type != vfh->vdev->queue->type)
> > > return -EINVAL;
> > > @@ -74,10 +75,12 @@ static int uvc_meta_v4l2_try_format(struct file *file, void *priv,
> > > }
> > > }
> > >
> > > + buffersize = max(UVC_METADATA_BUF_MIN_SIZE, fmt->buffersize);
> > > +
> > > memset(fmt, 0, sizeof(*fmt));
> > >
> > > fmt->dataformat = fmeta;
> > > - fmt->buffersize = UVC_METADATA_BUF_SIZE;
> > > + fmt->buffersize = buffersize;
> > >
> > > return 0;
> > > }
> > > @@ -103,6 +106,7 @@ static int uvc_meta_v4l2_set_format(struct file *file, void *priv,
> > > return -EBUSY;
> > >
> > > stream->meta.format = fmt->dataformat;
> > > + stream->meta.buffersize = fmt->buffersize;
> > >
> > > return 0;
> > > }
> > > @@ -229,6 +233,7 @@ int uvc_meta_register(struct uvc_streaming *stream)
> > > struct uvc_video_queue *queue = &stream->meta.queue;
> > >
> > > stream->meta.format = V4L2_META_FMT_UVC;
> > > + stream->meta.buffersize = UVC_METADATA_BUF_MIN_SIZE;
> > >
> > > return uvc_register_video_device(dev, stream, queue,
> > > V4L2_BUF_TYPE_META_CAPTURE,
> > > diff --git a/drivers/media/usb/uvc/uvc_queue.c b/drivers/media/usb/uvc/uvc_queue.c
> > > index 68ed2883edb2..89206f761006 100644
> > > --- a/drivers/media/usb/uvc/uvc_queue.c
> > > +++ b/drivers/media/usb/uvc/uvc_queue.c
> > > @@ -83,7 +83,7 @@ static int uvc_queue_setup(struct vb2_queue *vq,
> > >
> > > switch (vq->type) {
> > > case V4L2_BUF_TYPE_META_CAPTURE:
> > > - size = UVC_METADATA_BUF_SIZE;
> > > + size = stream->meta.buffersize;
> > > break;
> > >
> > > default:
> > > diff --git a/drivers/media/usb/uvc/uvcvideo.h b/drivers/media/usb/uvc/uvcvideo.h
> > > index 9b4849fda12f..5ba698d2a23d 100644
> > > --- a/drivers/media/usb/uvc/uvcvideo.h
> > > +++ b/drivers/media/usb/uvc/uvcvideo.h
> > > @@ -409,7 +409,7 @@ struct uvc_stats_stream {
> > > unsigned int max_sof; /* Maximum STC.SOF value */
> > > };
> > >
> > > -#define UVC_METADATA_BUF_SIZE 10240
> > > +#define UVC_METADATA_BUF_MIN_SIZE 10240
> >
> > I wondered if we should have a max limit to avoid letting userspace
> > starve system memory, but that can already be done through allocation of
> > arbitrarily large image buffers anyway. We need proper memory accounting
> > in V4L2.
> >
> > Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
> >
> > >
> > > /**
> > > * struct uvc_copy_op: Context structure to schedule asynchronous memcpy
> > > @@ -482,6 +482,7 @@ struct uvc_streaming {
> > > struct {
> > > struct uvc_video_queue queue;
> > > u32 format;
> > > + u32 buffersize;
> > > } meta;
> > >
> > > /* Context data used by the bulk completion handler. */
> > >
--
Regards,
Laurent Pinchart
next prev parent reply other threads:[~2026-03-18 19:36 UTC|newest]
Thread overview: 16+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-03-09 15:01 [PATCH 0/3] media: uvcvideo: Improvements for UVC metadata Ricardo Ribalda
2026-03-09 15:01 ` [PATCH 1/3] media: uvcvideo: Enable VB2_DMABUF for metadata stream Ricardo Ribalda
2026-03-16 11:47 ` Hans de Goede
2026-03-18 19:15 ` Laurent Pinchart
2026-03-09 15:01 ` [PATCH 2/3] media: uvcvideo: uvc_queue_to_stream(): Support meta queues Ricardo Ribalda
2026-03-16 11:49 ` Hans de Goede
2026-03-18 19:18 ` Laurent Pinchart
2026-03-09 15:01 ` [PATCH 3/3] media: uvcvideo: Allow userspace to increase the meta buffersize Ricardo Ribalda
2026-03-16 11:53 ` Hans de Goede
2026-03-18 19:22 ` Laurent Pinchart
2026-03-18 19:29 ` Ricardo Ribalda
2026-03-18 19:36 ` Laurent Pinchart [this message]
2026-03-16 12:05 ` [PATCH 0/3] media: uvcvideo: Improvements for UVC metadata Hans de Goede
2026-03-18 19:23 ` Laurent Pinchart
2026-03-18 20:22 ` [PATCH] media: uvcvideo: Add a stream backpointer in uvc_video_queue Ricardo Ribalda
2026-03-23 22:34 ` 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=20260318193633.GA720831@killaraus.ideasonboard.com \
--to=laurent.pinchart@ideasonboard.com \
--cc=guennadi.liakhovetski@intel.com \
--cc=hansg@kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-media@vger.kernel.org \
--cc=mchehab@kernel.org \
--cc=ribalda@chromium.org \
--cc=yunkec@google.com \
/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