This is an automated email from the ASF dual-hosted git repository. acassis pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/nuttx.git
commit 13c52e6d5c2c058d1958e65ddb2512f6cc329dc0 Author: yaojingwei <[email protected]> AuthorDate: Fri Nov 14 16:59:45 2025 +0800 v4l2_cap: support set buffer size by s_fmt command Some encoded streams need a buffer size chosen by the user. Keep the sizeimage passed to VIDIOC_S_FMT and VIDIOC_TRY_FMT, return it from VIDIOC_G_FMT, and use it as the buffer size of a JPEG stream when it is not 0. Uncompressed formats keep the size computed from the frame geometry, so a small sizeimage cannot make their buffers smaller than one frame. Signed-off-by: yaojingwei <[email protected]> --- drivers/video/v4l2_cap.c | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/drivers/video/v4l2_cap.c b/drivers/video/v4l2_cap.c index abc159ac790..ff0bf92abd4 100644 --- a/drivers/video/v4l2_cap.c +++ b/drivers/video/v4l2_cap.c @@ -84,6 +84,7 @@ struct video_format_s uint16_t width; uint16_t height; uint32_t pixelformat; + uint32_t sizeimage; }; typedef struct video_format_s video_format_t; @@ -1341,6 +1342,11 @@ static size_t get_bufsize(FAR video_format_t *vf) uint32_t height = vf->height; size_t ret = width * height; + if (vf->sizeimage > 0 && vf->pixelformat == V4L2_PIX_FMT_JPEG) + { + return vf->sizeimage; + } + switch (vf->pixelformat) { case V4L2_PIX_FMT_NV12: @@ -2494,6 +2500,7 @@ static int capture_g_fmt(FAR struct file *filep, fmt->fmt.pix.width = type_inf->fmt[CAPTURE_FMT_MAIN].width; fmt->fmt.pix.height = type_inf->fmt[CAPTURE_FMT_MAIN].height; fmt->fmt.pix.pixelformat = type_inf->fmt[CAPTURE_FMT_MAIN].pixelformat; + fmt->fmt.pix.sizeimage = type_inf->fmt[CAPTURE_FMT_MAIN].sizeimage; return OK; } @@ -2540,6 +2547,7 @@ static int capture_s_fmt(FAR struct file *filep, type_inf->fmt[CAPTURE_FMT_SUB].width = fmt->fmt.pix.width; type_inf->fmt[CAPTURE_FMT_SUB].height = fmt->fmt.pix.height; + type_inf->fmt[CAPTURE_FMT_SUB].sizeimage = fmt->fmt.pix.sizeimage; type_inf->fmt[CAPTURE_FMT_SUB].pixelformat = fmt->fmt.pix.pixelformat == V4L2_PIX_FMT_SUBIMG_UYVY ? V4L2_PIX_FMT_UYVY : V4L2_PIX_FMT_RGB565; @@ -2549,6 +2557,7 @@ static int capture_s_fmt(FAR struct file *filep, default: type_inf->fmt[CAPTURE_FMT_MAIN].width = fmt->fmt.pix.width; type_inf->fmt[CAPTURE_FMT_MAIN].height = fmt->fmt.pix.height; + type_inf->fmt[CAPTURE_FMT_MAIN].sizeimage = fmt->fmt.pix.sizeimage; type_inf->fmt[CAPTURE_FMT_MAIN].pixelformat = fmt->fmt.pix.pixelformat; type_inf->nr_fmt = 1; @@ -2602,6 +2611,7 @@ static int capture_try_fmt(FAR struct file *filep, sizeof(video_format_t)); vf[CAPTURE_FMT_SUB].width = fmt->fmt.pix.width; vf[CAPTURE_FMT_SUB].height = fmt->fmt.pix.height; + vf[CAPTURE_FMT_SUB].sizeimage = fmt->fmt.pix.sizeimage; vf[CAPTURE_FMT_SUB].pixelformat = fmt->fmt.pix.pixelformat == V4L2_PIX_FMT_SUBIMG_UYVY ? V4L2_PIX_FMT_UYVY : V4L2_PIX_FMT_RGB565; @@ -2618,6 +2628,7 @@ static int capture_try_fmt(FAR struct file *filep, vf[CAPTURE_FMT_MAIN].width = fmt->fmt.pix.width; vf[CAPTURE_FMT_MAIN].height = fmt->fmt.pix.height; vf[CAPTURE_FMT_MAIN].pixelformat = fmt->fmt.pix.pixelformat; + vf[CAPTURE_FMT_MAIN].sizeimage = fmt->fmt.pix.sizeimage; break; default:
