Re: [PATCH v9 12/22] media: uvcvideo: Increase the size of UVC_METADATA_BUF_SIZE

From: Laurent Pinchart
Date: Thu Jun 10 2021 - 12:48:59 EST


Hi Ricardo,

Thank you for the patch.

On Fri, Mar 26, 2021 at 10:58:30AM +0100, Ricardo Ribalda wrote:
> Hans has discovered that in his test device, for the H264 format
> bytesused goes up to about 570, for YUYV it will actually go up
> to a bit over 5000 bytes, and for MJPG up to about 2706 bytes.
>
> We should also, according to V4L2_META_FMT_UVC docs, drop headers when
> the buffer is full.
>
> Credit-to: Hans Verkuil <hverkuil@xxxxxxxxx>
> Reviewed-by: Hans Verkuil <hverkuil-cisco@xxxxxxxxx>
> Signed-off-by: Ricardo Ribalda <ribalda@xxxxxxxxxxxx>
> ---
> drivers/media/usb/uvc/uvc_video.c | 8 +++++---
> drivers/media/usb/uvc/uvcvideo.h | 2 +-
> 2 files changed, 6 insertions(+), 4 deletions(-)
>
> diff --git a/drivers/media/usb/uvc/uvc_video.c b/drivers/media/usb/uvc/uvc_video.c
> index 25fd8aa23529..ea2903dc3252 100644
> --- a/drivers/media/usb/uvc/uvc_video.c
> +++ b/drivers/media/usb/uvc/uvc_video.c
> @@ -1244,11 +1244,13 @@ static void uvc_video_decode_meta(struct uvc_streaming *stream,
> if (!meta_buf || length == 2)
> return;
>
> + /*
> + * According to V4L2_META_FMT_UVC docs, we should drop headers when
> + * the buffer is full.
> + */
> if (meta_buf->length - meta_buf->bytesused <
> - length + sizeof(meta->ns) + sizeof(meta->sof)) {
> - meta_buf->error = 1;

Shouldn't you still set meta_buf->error to 1, even if you drop headers ?
Otherwise the application can't tell if headers have been dropped.

With this fixed,

Reviewed-by: Laurent Pinchart <laurent.pinchart@xxxxxxxxxxxxxxxx>

> + length + sizeof(meta->ns) + sizeof(meta->sof))
> return;
> - }
>
> has_pts = mem[1] & UVC_STREAM_PTS;
> has_scr = mem[1] & UVC_STREAM_SCR;
> diff --git a/drivers/media/usb/uvc/uvcvideo.h b/drivers/media/usb/uvc/uvcvideo.h
> index b81d3f65e52e..a26bbec8d37b 100644
> --- a/drivers/media/usb/uvc/uvcvideo.h
> +++ b/drivers/media/usb/uvc/uvcvideo.h
> @@ -527,7 +527,7 @@ struct uvc_stats_stream {
> unsigned int max_sof; /* Maximum STC.SOF value */
> };
>
> -#define UVC_METADATA_BUF_SIZE 1024
> +#define UVC_METADATA_BUF_SIZE 10240
>
> /**
> * struct uvc_copy_op: Context structure to schedule asynchronous memcpy

--
Regards,

Laurent Pinchart