From bca24b4b5b2c18b844e8da80ac19819944f80a93 Mon Sep 17 00:00:00 2001 From: Daniel Scally Date: Tue, 22 Nov 2022 15:34:20 +0000 Subject: lib: uvc: Drop maxsize The maxsize field of struct uvc_device is probably unecessary even if it weren't currently fixed at 0. It's used to set dwMaxVideoFrameSize in addition to the sizeimage member of a struct v4l2_pix_fmt (multiplied in the latter instance by 1.5x). The documentary definitions for those two values are such that they should be identical though, so simply set dwMaxVideoFrameSize to width*height*2 (to maintain commonality with other UVC Video devices) and use that to set the sizeimage. Reviewed-by: Kieran Bingham Signed-off-by: Daniel Scally Signed-off-by: Kieran Bingham --- lib/uvc.c | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/lib/uvc.c b/lib/uvc.c index 975413a..a9d0e69 100644 --- a/lib/uvc.c +++ b/lib/uvc.c @@ -39,7 +39,6 @@ struct uvc_device unsigned int fcc; unsigned int width; unsigned int height; - unsigned int maxsize; }; struct uvc_device *uvc_open(const char *devname, struct uvc_stream *stream) @@ -112,12 +111,15 @@ uvc_fill_streaming_control(struct uvc_device *dev, ctrl->bFrameIndex = iframe ; ctrl->dwFrameInterval = ival; + /* + * The maximum size in bytes for a single frame depends on the format. + * This switch will need extending for any new formats that are added + * to ensure the buffer size calculations are done correctly. + */ switch (format->fcc) { case V4L2_PIX_FMT_YUYV: - ctrl->dwMaxVideoFrameSize = frame->width * frame->height * 2; - break; case V4L2_PIX_FMT_MJPEG: - ctrl->dwMaxVideoFrameSize = dev->maxsize; + ctrl->dwMaxVideoFrameSize = frame->width * frame->height * 2; break; } @@ -287,7 +289,7 @@ uvc_events_process_data(struct uvc_device *dev, pixfmt.pixelformat = format->fcc; pixfmt.field = V4L2_FIELD_NONE; if (format->fcc == V4L2_PIX_FMT_MJPEG) - pixfmt.sizeimage = dev->maxsize * 1.5; + pixfmt.sizeimage = target->dwMaxVideoFrameSize; uvc_stream_set_format(dev->stream, &pixfmt); @@ -373,8 +375,6 @@ void uvc_events_init(struct uvc_device *dev, struct events *events) void uvc_set_config(struct uvc_device *dev, struct uvc_function_config *fc) { - /* FIXME: The maximum size should be specified per format and frame. */ - dev->maxsize = 0; dev->fc = fc; } -- cgit v1.2.3