lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Date:   Mon,  6 Feb 2023 12:33:08 +0800
From:   ayaka <ayaka@...lik.info>
To:     linux-media@...r.kernel.org
Cc:     randy.li@...aptics.com, Brian.Starkey@....com,
        boris.brezillon@...labora.com, frkoenig@...omium.org,
        hans.verkuil@...co.com, hiroh@...omium.org, hverkuil@...all.nl,
        kernel@...labora.com, laurent.pinchart@...asonboard.com,
        linux-kernel@...r.kernel.org, mchehab@...nel.org,
        narmstrong@...libre.com, nicolas@...fresne.ca, sakari.ailus@....fi,
        stanimir.varbanov@...aro.org, tfiga@...omium.org,
        Helen Koike <helen.koike@...labora.com>,
        Randy Li <ayaka@...lik.info>
Subject: [PATCH v7 9/9] media: vimc: Convert to v4l2_ext_pix_format

From: Helen Koike <helen.koike@...labora.com>

Simplify Multi/Single planer API handling by converting to v4l2_ext_pix_format.

Signed-off-by: Boris Brezillon <boris.brezillon@...labora.com>
Signed-off-by: Helen Koike <helen.koike@...labora.com>
Signed-off-by: Randy Li <ayaka@...lik.info>
---
Changes in v7:
- Refresh and rebase

Changes in v6:
- Update with new format and buffer structs

Changes in v4:
- Update with new format and buffer structs
- Rebased on top of media/master (post 5.8-rc1)

Changes in v3:
- Rebased on top of media/master (post 5.4-rc1)

Changes in v2:
- New patch
---
 .../media/test-drivers/vimc/vimc-capture.c    | 115 ++++++++++--------
 drivers/media/test-drivers/vimc/vimc-common.c |   6 +-
 drivers/media/test-drivers/vimc/vimc-common.h |   2 +-
 3 files changed, 68 insertions(+), 55 deletions(-)

diff --git a/drivers/media/test-drivers/vimc/vimc-capture.c b/drivers/media/test-drivers/vimc/vimc-capture.c
index 246d90d1f5ae..5429398bea8d 100644
--- a/drivers/media/test-drivers/vimc/vimc-capture.c
+++ b/drivers/media/test-drivers/vimc/vimc-capture.c
@@ -16,7 +16,7 @@
 struct vimc_capture_device {
 	struct vimc_ent_device ved;
 	struct video_device vdev;
-	struct v4l2_pix_format format;
+	struct v4l2_ext_pix_format format;
 	struct vb2_queue queue;
 	struct list_head buf_list;
 	/*
@@ -33,7 +33,8 @@ struct vimc_capture_device {
 	struct media_pad pad;
 };
 
-static const struct v4l2_pix_format fmt_default = {
+static const struct v4l2_ext_pix_format fmt_default = {
+	.type = V4L2_BUF_TYPE_VIDEO_CAPTURE,
 	.width = 640,
 	.height = 480,
 	.pixelformat = V4L2_PIX_FMT_RGB24,
@@ -53,7 +54,7 @@ struct vimc_capture_buffer {
 };
 
 static int vimc_capture_querycap(struct file *file, void *priv,
-			     struct v4l2_capability *cap)
+				 struct v4l2_capability *cap)
 {
 	strscpy(cap->driver, VIMC_PDEV_NAME, sizeof(cap->driver));
 	strscpy(cap->card, KBUILD_MODNAME, sizeof(cap->card));
@@ -64,28 +65,28 @@ static int vimc_capture_querycap(struct file *file, void *priv,
 }
 
 static void vimc_capture_get_format(struct vimc_ent_device *ved,
-				struct v4l2_pix_format *fmt)
+				    struct v4l2_ext_pix_format *fmt)
 {
-	struct vimc_capture_device *vcapture = container_of(ved, struct vimc_capture_device,
-						    ved);
+	struct vimc_capture_device *vcapture =
+	    container_of(ved, struct vimc_capture_device,
+			 ved);
 
 	*fmt = vcapture->format;
 }
 
 static int vimc_capture_g_fmt_vid_cap(struct file *file, void *priv,
-				  struct v4l2_format *f)
+				      struct v4l2_ext_pix_format *f)
 {
 	struct vimc_capture_device *vcapture = video_drvdata(file);
 
-	f->fmt.pix = vcapture->format;
+	*f = vcapture->format;
 
 	return 0;
 }
 
 static int vimc_capture_try_fmt_vid_cap(struct file *file, void *priv,
-				    struct v4l2_format *f)
+					struct v4l2_ext_pix_format *format)
 {
-	struct v4l2_pix_format *format = &f->fmt.pix;
 	const struct vimc_pix_map *vpix;
 
 	format->width = clamp_t(u32, format->width, VIMC_FRAME_MIN_WIDTH,
@@ -100,8 +101,10 @@ static int vimc_capture_try_fmt_vid_cap(struct file *file, void *priv,
 		vpix = vimc_pix_map_by_pixelformat(format->pixelformat);
 	}
 	/* TODO: Add support for custom bytesperline values */
-	format->bytesperline = format->width * vpix->bpp;
-	format->sizeimage = format->bytesperline * format->height;
+	memset(format->plane_fmt, 0, sizeof(format->plane_fmt));
+	format->plane_fmt[0].bytesperline = format->width * vpix->bpp;
+	format->plane_fmt[0].sizeimage = format->plane_fmt[0].bytesperline *
+	    format->height;
 
 	if (format->field == V4L2_FIELD_ANY)
 		format->field = fmt_default.field;
@@ -115,7 +118,7 @@ static int vimc_capture_try_fmt_vid_cap(struct file *file, void *priv,
 }
 
 static int vimc_capture_s_fmt_vid_cap(struct file *file, void *priv,
-				  struct v4l2_format *f)
+				      struct v4l2_ext_pix_format *f)
 {
 	struct vimc_capture_device *vcapture = video_drvdata(file);
 	int ret;
@@ -137,18 +140,16 @@ static int vimc_capture_s_fmt_vid_cap(struct file *file, void *priv,
 		vcapture->format.quantization, vcapture->format.xfer_func,
 		vcapture->format.ycbcr_enc,
 		/* new */
-		f->fmt.pix.width, f->fmt.pix.height,
-		f->fmt.pix.pixelformat,	f->fmt.pix.colorspace,
-		f->fmt.pix.quantization, f->fmt.pix.xfer_func,
-		f->fmt.pix.ycbcr_enc);
+		f->width, f->height, f->pixelformat, f->colorspace,
+		f->quantization, f->xfer_func, f->ycbcr_enc);
 
-	vcapture->format = f->fmt.pix;
+	vcapture->format = *f;
 
 	return 0;
 }
 
 static int vimc_capture_enum_fmt_vid_cap(struct file *file, void *priv,
-				     struct v4l2_fmtdesc *f)
+					 struct v4l2_fmtdesc *f)
 {
 	const struct vimc_pix_map *vpix;
 
@@ -170,7 +171,7 @@ static int vimc_capture_enum_fmt_vid_cap(struct file *file, void *priv,
 }
 
 static int vimc_capture_enum_framesizes(struct file *file, void *fh,
-				    struct v4l2_frmsizeenum *fsize)
+					struct v4l2_frmsizeenum *fsize)
 {
 	const struct vimc_pix_map *vpix;
 
@@ -206,9 +207,9 @@ static const struct v4l2_file_operations vimc_capture_fops = {
 static const struct v4l2_ioctl_ops vimc_capture_ioctl_ops = {
 	.vidioc_querycap = vimc_capture_querycap,
 
-	.vidioc_g_fmt_vid_cap = vimc_capture_g_fmt_vid_cap,
-	.vidioc_s_fmt_vid_cap = vimc_capture_s_fmt_vid_cap,
-	.vidioc_try_fmt_vid_cap = vimc_capture_try_fmt_vid_cap,
+	.vidioc_g_ext_pix_fmt_vid_cap = vimc_capture_g_fmt_vid_cap,
+	.vidioc_s_ext_pix_fmt_vid_cap = vimc_capture_s_fmt_vid_cap,
+	.vidioc_try_ext_pix_fmt_vid_cap = vimc_capture_try_fmt_vid_cap,
 	.vidioc_enum_fmt_vid_cap = vimc_capture_enum_fmt_vid_cap,
 	.vidioc_enum_framesizes = vimc_capture_enum_framesizes,
 
@@ -225,8 +226,9 @@ static const struct v4l2_ioctl_ops vimc_capture_ioctl_ops = {
 	.vidioc_streamoff = vb2_ioctl_streamoff,
 };
 
-static void vimc_capture_return_all_buffers(struct vimc_capture_device *vcapture,
-					enum vb2_buffer_state state)
+static void vimc_capture_return_all_buffers(struct vimc_capture_device
+					    *vcapture,
+					    enum vb2_buffer_state state)
 {
 	struct vimc_capture_buffer *vbuf, *node;
 
@@ -240,7 +242,8 @@ static void vimc_capture_return_all_buffers(struct vimc_capture_device *vcapture
 	spin_unlock(&vcapture->qlock);
 }
 
-static int vimc_capture_start_streaming(struct vb2_queue *vq, unsigned int count)
+static int vimc_capture_start_streaming(struct vb2_queue *vq,
+					unsigned int count)
 {
 	struct vimc_capture_device *vcapture = vb2_get_drv_priv(vq);
 	int ret;
@@ -248,7 +251,9 @@ static int vimc_capture_start_streaming(struct vb2_queue *vq, unsigned int count
 	vcapture->sequence = 0;
 
 	/* Start the media pipeline */
-	ret = video_device_pipeline_start(&vcapture->vdev, &vcapture->stream.pipe);
+	ret =
+	    video_device_pipeline_start(&vcapture->vdev,
+					&vcapture->stream.pipe);
 	if (ret) {
 		vimc_capture_return_all_buffers(vcapture, VB2_BUF_STATE_QUEUED);
 		return ret;
@@ -283,27 +288,31 @@ static void vimc_capture_stop_streaming(struct vb2_queue *vq)
 
 static void vimc_capture_buf_queue(struct vb2_buffer *vb2_buf)
 {
-	struct vimc_capture_device *vcapture = vb2_get_drv_priv(vb2_buf->vb2_queue);
+	struct vimc_capture_device *vcapture =
+	    vb2_get_drv_priv(vb2_buf->vb2_queue);
 	struct vimc_capture_buffer *buf = container_of(vb2_buf,
-						   struct vimc_capture_buffer,
-						   vb2.vb2_buf);
+						       struct
+						       vimc_capture_buffer,
+						       vb2.vb2_buf);
 
 	spin_lock(&vcapture->qlock);
 	list_add_tail(&buf->list, &vcapture->buf_list);
 	spin_unlock(&vcapture->qlock);
 }
 
-static int vimc_capture_queue_setup(struct vb2_queue *vq, unsigned int *nbuffers,
-				unsigned int *nplanes, unsigned int sizes[],
-				struct device *alloc_devs[])
+static int vimc_capture_queue_setup(struct vb2_queue *vq,
+				    unsigned int *nbuffers,
+				    unsigned int *nplanes, unsigned int sizes[],
+				    struct device *alloc_devs[])
 {
 	struct vimc_capture_device *vcapture = vb2_get_drv_priv(vq);
 
 	if (*nplanes)
-		return sizes[0] < vcapture->format.sizeimage ? -EINVAL : 0;
+		return sizes[0] <
+		    vcapture->format.plane_fmt[0].sizeimage ? -EINVAL : 0;
 	/* We don't support multiplanes for now */
 	*nplanes = 1;
-	sizes[0] = vcapture->format.sizeimage;
+	sizes[0] = vcapture->format.plane_fmt[0].sizeimage;
 
 	return 0;
 }
@@ -311,7 +320,7 @@ static int vimc_capture_queue_setup(struct vb2_queue *vq, unsigned int *nbuffers
 static int vimc_capture_buffer_prepare(struct vb2_buffer *vb)
 {
 	struct vimc_capture_device *vcapture = vb2_get_drv_priv(vb->vb2_queue);
-	unsigned long size = vcapture->format.sizeimage;
+	unsigned long size = vcapture->format.plane_fmt[0].sizeimage;
 
 	if (vb2_plane_size(vb, 0) < size) {
 		dev_err(vcapture->ved.dev, "%s: buffer too small (%lu < %lu)\n",
@@ -342,7 +351,7 @@ static const struct media_entity_operations vimc_capture_mops = {
 static void vimc_capture_release(struct vimc_ent_device *ved)
 {
 	struct vimc_capture_device *vcapture =
-		container_of(ved, struct vimc_capture_device, ved);
+	    container_of(ved, struct vimc_capture_device, ved);
 
 	media_entity_cleanup(vcapture->ved.ent);
 	kfree(vcapture);
@@ -351,16 +360,17 @@ static void vimc_capture_release(struct vimc_ent_device *ved)
 static void vimc_capture_unregister(struct vimc_ent_device *ved)
 {
 	struct vimc_capture_device *vcapture =
-		container_of(ved, struct vimc_capture_device, ved);
+	    container_of(ved, struct vimc_capture_device, ved);
 
 	vb2_video_unregister_device(&vcapture->vdev);
 }
 
 static void *vimc_capture_process_frame(struct vimc_ent_device *ved,
-				    const void *frame)
+					const void *frame)
 {
-	struct vimc_capture_device *vcapture = container_of(ved, struct vimc_capture_device,
-						    ved);
+	struct vimc_capture_device *vcapture =
+	    container_of(ved, struct vimc_capture_device,
+			 ved);
 	struct vimc_capture_buffer *vimc_buf;
 	void *vbuf;
 
@@ -386,11 +396,11 @@ static void *vimc_capture_process_frame(struct vimc_ent_device *ved,
 
 	vbuf = vb2_plane_vaddr(&vimc_buf->vb2.vb2_buf, 0);
 
-	memcpy(vbuf, frame, vcapture->format.sizeimage);
+	memcpy(vbuf, frame, vcapture->format.plane_fmt[0].sizeimage);
 
 	/* Set it as ready */
 	vb2_set_plane_payload(&vimc_buf->vb2.vb2_buf, 0,
-			      vcapture->format.sizeimage);
+			      vcapture->format.plane_fmt[0].sizeimage);
 	vb2_set_pixelformat(&vimc_buf->vb2.vb2_buf,
 			    vcapture->format.pixelformat);
 	vb2_buffer_done(&vimc_buf->vb2.vb2_buf, VB2_BUF_STATE_DONE);
@@ -398,7 +408,7 @@ static void *vimc_capture_process_frame(struct vimc_ent_device *ved,
 }
 
 static struct vimc_ent_device *vimc_capture_add(struct vimc_device *vimc,
-					    const char *vcfg_name)
+						const char *vcfg_name)
 {
 	struct v4l2_device *v4l2_dev = &vimc->v4l2_dev;
 	const struct vimc_pix_map *vpix;
@@ -416,8 +426,7 @@ static struct vimc_ent_device *vimc_capture_add(struct vimc_device *vimc,
 	vcapture->vdev.entity.name = vcfg_name;
 	vcapture->vdev.entity.function = MEDIA_ENT_F_IO_V4L;
 	vcapture->pad.flags = MEDIA_PAD_FL_SINK;
-	ret = media_entity_pads_init(&vcapture->vdev.entity,
-				     1, &vcapture->pad);
+	ret = media_entity_pads_init(&vcapture->vdev.entity, 1, &vcapture->pad);
 	if (ret)
 		goto err_free_vcapture;
 
@@ -434,7 +443,7 @@ static struct vimc_ent_device *vimc_capture_add(struct vimc_device *vimc,
 	q->buf_struct_size = sizeof(struct vimc_capture_buffer);
 	q->ops = &vimc_capture_qops;
 	q->mem_ops = vimc_allocator == VIMC_ALLOCATOR_DMA_CONTIG
-		   ? &vb2_dma_contig_memops : &vb2_vmalloc_memops;
+	    ? &vb2_dma_contig_memops : &vb2_vmalloc_memops;
 	q->timestamp_flags = V4L2_BUF_FLAG_TIMESTAMP_MONOTONIC;
 	q->min_buffers_needed = 2;
 	q->lock = &vcapture->lock;
@@ -454,9 +463,13 @@ static struct vimc_ent_device *vimc_capture_add(struct vimc_device *vimc,
 	/* Set default frame format */
 	vcapture->format = fmt_default;
 	vpix = vimc_pix_map_by_pixelformat(vcapture->format.pixelformat);
-	vcapture->format.bytesperline = vcapture->format.width * vpix->bpp;
-	vcapture->format.sizeimage = vcapture->format.bytesperline *
-				 vcapture->format.height;
+	memset(vcapture->format.plane_fmt, 0,
+	       sizeof(vcapture->format.plane_fmt));
+	vcapture->format.plane_fmt[0].bytesperline =
+	    vcapture->format.width * vpix->bpp;
+	vcapture->format.plane_fmt[0].sizeimage =
+	    vcapture->format.plane_fmt[0].bytesperline *
+	    vcapture->format.height;
 
 	/* Fill the vimc_ent_device struct */
 	vcapture->ved.ent = &vcapture->vdev.entity;
@@ -467,7 +480,7 @@ static struct vimc_ent_device *vimc_capture_add(struct vimc_device *vimc,
 	/* Initialize the video_device struct */
 	vdev = &vcapture->vdev;
 	vdev->device_caps = V4L2_CAP_VIDEO_CAPTURE | V4L2_CAP_STREAMING
-			  | V4L2_CAP_IO_MC;
+	    | V4L2_CAP_IO_MC;
 	vdev->entity.ops = &vimc_capture_mops;
 	vdev->release = video_device_release_empty;
 	vdev->fops = &vimc_capture_fops;
diff --git a/drivers/media/test-drivers/vimc/vimc-common.c b/drivers/media/test-drivers/vimc/vimc-common.c
index 7b27153c0728..8bbf80f2acb9 100644
--- a/drivers/media/test-drivers/vimc/vimc-common.c
+++ b/drivers/media/test-drivers/vimc/vimc-common.c
@@ -236,7 +236,7 @@ const struct vimc_pix_map *vimc_pix_map_by_pixelformat(u32 pixelformat)
 }
 
 static int vimc_get_pix_format(struct media_pad *pad,
-			       struct v4l2_pix_format *fmt)
+			       struct v4l2_ext_pix_format *fmt)
 {
 	if (is_media_entity_v4l2_subdev(pad->entity)) {
 		struct v4l2_subdev *sd =
@@ -252,7 +252,7 @@ static int vimc_get_pix_format(struct media_pad *pad,
 		if (ret)
 			return ret;
 
-		v4l2_fill_pix_format(fmt, &sd_fmt.format);
+		v4l2_fill_ext_pix_format_from_mbus(fmt, &sd_fmt.format);
 		pix_map = vimc_pix_map_by_code(sd_fmt.format.code);
 		fmt->pixelformat = pix_map->pixelformat;
 	} else if (is_media_entity_v4l2_video_device(pad->entity)) {
@@ -274,7 +274,7 @@ static int vimc_get_pix_format(struct media_pad *pad,
 
 int vimc_vdev_link_validate(struct media_link *link)
 {
-	struct v4l2_pix_format source_fmt, sink_fmt;
+	struct v4l2_ext_pix_format source_fmt, sink_fmt;
 	int ret;
 
 	ret = vimc_get_pix_format(link->source, &source_fmt);
diff --git a/drivers/media/test-drivers/vimc/vimc-common.h b/drivers/media/test-drivers/vimc/vimc-common.h
index 7641a101a728..f29429df10dd 100644
--- a/drivers/media/test-drivers/vimc/vimc-common.h
+++ b/drivers/media/test-drivers/vimc/vimc-common.h
@@ -111,7 +111,7 @@ struct vimc_ent_device {
 	void * (*process_frame)(struct vimc_ent_device *ved,
 				const void *frame);
 	void (*vdev_get_format)(struct vimc_ent_device *ved,
-			      struct v4l2_pix_format *fmt);
+				struct v4l2_ext_pix_format *fmt);
 };
 
 /**
-- 
2.17.1

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ