diff mbox series

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

Message ID 20210326095840.364424-13-ribalda@chromium.org
State New
Headers show
Series uvcvideo: Fix v4l2-compliance errors | expand

Commit Message

Ricardo Ribalda March 26, 2021, 9:58 a.m. UTC
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@xs4all.nl>
Reviewed-by: Hans Verkuil <hverkuil-cisco@xs4all.nl>
Signed-off-by: Ricardo Ribalda <ribalda@chromium.org>
---
 drivers/media/usb/uvc/uvc_video.c | 8 +++++---
 drivers/media/usb/uvc/uvcvideo.h  | 2 +-
 2 files changed, 6 insertions(+), 4 deletions(-)

Comments

Laurent Pinchart June 10, 2021, 4:48 p.m. UTC | #1
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@xs4all.nl>

> Reviewed-by: Hans Verkuil <hverkuil-cisco@xs4all.nl>

> Signed-off-by: Ricardo Ribalda <ribalda@chromium.org>

> ---

>  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@ideasonboard.com>


> +	    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
diff mbox series

Patch

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;
+	    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