All of lore.kernel.org
 help / color / mirror / Atom feed
From: Guennadi Liakhovetski <g.liakhovetski@gmx.de>
To: Linux Media Mailing List <linux-media@vger.kernel.org>
Cc: Hans Verkuil <hverkuil@xs4all.nl>,
	Laurent Pinchart <laurent.pinchart@ideasonboard.com>,
	Pawel Osciak <pawel@osciak.com>,
	Sakari Ailus <sakari.ailus@maxwell.research.nokia.com>,
	Mauro Carvalho Chehab <mchehab@infradead.org>,
	Marek Szyprowski <m.szyprowski@samsung.com>
Subject: [PATCH 1/9 v6] V4L: add a new videobuf2 buffer state VB2_BUF_STATE_PREPARED
Date: Wed, 31 Aug 2011 20:02:40 +0200	[thread overview]
Message-ID: <1314813768-27752-2-git-send-email-g.liakhovetski@gmx.de> (raw)
In-Reply-To: <1314813768-27752-1-git-send-email-g.liakhovetski@gmx.de>

This patch prepares for a better separation of the buffer preparation
stage.

Signed-off-by: Guennadi Liakhovetski <g.liakhovetski@gmx.de>
Cc: Hans Verkuil <hverkuil@xs4all.nl>
Cc: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Cc: Marek Szyprowski <m.szyprowski@samsung.com>
Cc: Mauro Carvalho Chehab <mchehab@infradead.org>
Cc: Pawel Osciak <pawel@osciak.com>
Cc: Sakari Ailus <sakari.ailus@maxwell.research.nokia.com>
---

v6: as reported by Pawel: the VB2_BUF_STATE_PREPARED state has to actually be
    set

 drivers/media/video/videobuf2-core.c |   61 +++++++++++++++++++++------------
 include/media/videobuf2-core.h       |    2 +
 2 files changed, 41 insertions(+), 22 deletions(-)

diff --git a/drivers/media/video/videobuf2-core.c b/drivers/media/video/videobuf2-core.c
index 3015e60..4153da2 100644
--- a/drivers/media/video/videobuf2-core.c
+++ b/drivers/media/video/videobuf2-core.c
@@ -333,6 +333,7 @@ static int __fill_v4l2_buffer(struct vb2_buffer *vb, struct v4l2_buffer *b)
 		b->flags |= V4L2_BUF_FLAG_DONE;
 		break;
 	case VB2_BUF_STATE_DEQUEUED:
+	case VB2_BUF_STATE_PREPARED:
 		/* nothing */
 		break;
 	}
@@ -817,6 +818,33 @@ static void __enqueue_in_driver(struct vb2_buffer *vb)
 	q->ops->buf_queue(vb);
 }
 
+static int __buf_prepare(struct vb2_buffer *vb, struct v4l2_buffer *b)
+{
+	struct vb2_queue *q = vb->vb2_queue;
+	int ret;
+
+	switch (q->memory) {
+	case V4L2_MEMORY_MMAP:
+		ret = __qbuf_mmap(vb, b);
+		break;
+	case V4L2_MEMORY_USERPTR:
+		ret = __qbuf_userptr(vb, b);
+		break;
+	default:
+		WARN(1, "Invalid queue type\n");
+		ret = -EINVAL;
+	}
+
+	if (!ret)
+		ret = call_qop(q, buf_prepare, vb);
+	if (ret)
+		dprintk(1, "qbuf: buffer preparation failed: %d\n", ret);
+	else
+		vb->state = VB2_BUF_STATE_PREPARED;
+
+	return ret;
+}
+
 /**
  * vb2_qbuf() - Queue a buffer from userspace
  * @q:		videobuf2 queue
@@ -826,8 +854,8 @@ static void __enqueue_in_driver(struct vb2_buffer *vb)
  * Should be called from vidioc_qbuf ioctl handler of a driver.
  * This function:
  * 1) verifies the passed buffer,
- * 2) calls buf_prepare callback in the driver (if provided), in which
- *    driver-specific buffer initialization can be performed,
+ * 2) if necessary, calls buf_prepare callback in the driver (if provided), in
+ *    which driver-specific buffer initialization can be performed,
  * 3) if streaming is on, queues the buffer in driver by the means of buf_queue
  *    callback for processing.
  *
@@ -837,7 +865,7 @@ static void __enqueue_in_driver(struct vb2_buffer *vb)
 int vb2_qbuf(struct vb2_queue *q, struct v4l2_buffer *b)
 {
 	struct vb2_buffer *vb;
-	int ret = 0;
+	int ret;
 
 	if (q->fileio) {
 		dprintk(1, "qbuf: file io in progress\n");
@@ -866,29 +894,18 @@ int vb2_qbuf(struct vb2_queue *q, struct v4l2_buffer *b)
 		return -EINVAL;
 	}
 
-	if (vb->state != VB2_BUF_STATE_DEQUEUED) {
+	switch (vb->state) {
+	case VB2_BUF_STATE_DEQUEUED:
+		ret = __buf_prepare(vb, b);
+		if (ret)
+			return ret;
+	case VB2_BUF_STATE_PREPARED:
+		break;
+	default:
 		dprintk(1, "qbuf: buffer already in use\n");
 		return -EINVAL;
 	}
 
-	if (q->memory == V4L2_MEMORY_MMAP)
-		ret = __qbuf_mmap(vb, b);
-	else if (q->memory == V4L2_MEMORY_USERPTR)
-		ret = __qbuf_userptr(vb, b);
-	else {
-		WARN(1, "Invalid queue type\n");
-		return -EINVAL;
-	}
-
-	if (ret)
-		return ret;
-
-	ret = call_qop(q, buf_prepare, vb);
-	if (ret) {
-		dprintk(1, "qbuf: buffer preparation failed\n");
-		return ret;
-	}
-
 	/*
 	 * Add to the queued buffers list, a buffer will stay on it until
 	 * dequeued in dqbuf.
diff --git a/include/media/videobuf2-core.h b/include/media/videobuf2-core.h
index f87472a..65946c5 100644
--- a/include/media/videobuf2-core.h
+++ b/include/media/videobuf2-core.h
@@ -106,6 +106,7 @@ enum vb2_fileio_flags {
 /**
  * enum vb2_buffer_state - current video buffer state
  * @VB2_BUF_STATE_DEQUEUED:	buffer under userspace control
+ * @VB2_BUF_STATE_PREPARED:	buffer prepared in videobuf and by the driver
  * @VB2_BUF_STATE_QUEUED:	buffer queued in videobuf, but not in driver
  * @VB2_BUF_STATE_ACTIVE:	buffer queued in driver and possibly used
  *				in a hardware operation
@@ -117,6 +118,7 @@ enum vb2_fileio_flags {
  */
 enum vb2_buffer_state {
 	VB2_BUF_STATE_DEQUEUED,
+	VB2_BUF_STATE_PREPARED,
 	VB2_BUF_STATE_QUEUED,
 	VB2_BUF_STATE_ACTIVE,
 	VB2_BUF_STATE_DONE,
-- 
1.7.2.5


  reply	other threads:[~2011-08-31 18:02 UTC|newest]

Thread overview: 59+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-08-31 18:02 [PATCH 0/9 v6] new ioctl()s and soc-camera implementation Guennadi Liakhovetski
2011-08-31 18:02 ` Guennadi Liakhovetski [this message]
2011-08-31 18:02 ` [PATCH 2/9 v6] V4L: add two new ioctl()s for multi-size videobuffer management Guennadi Liakhovetski
2011-08-31 21:06   ` Sakari Ailus
2011-09-01  7:03     ` Guennadi Liakhovetski
2011-09-01  8:35       ` Laurent Pinchart
2011-09-01  8:53         ` Guennadi Liakhovetski
2011-09-01  8:42       ` Sakari Ailus
2011-09-01  9:24         ` Guennadi Liakhovetski
2011-09-01 10:19           ` Sakari Ailus
2011-09-01 10:51             ` Guennadi Liakhovetski
2011-09-01 11:06               ` Sakari Ailus
2011-09-01 13:35                 ` Laurent Pinchart
2011-09-01 13:45                   ` Guennadi Liakhovetski
2011-09-08  7:45         ` [PATCH 2/9 v7] " Guennadi Liakhovetski
2011-09-08  7:46           ` [PATCH 3/9 v7] V4L: document the new VIDIOC_CREATE_BUFS and VIDIOC_PREPARE_BUF ioctl()s Guennadi Liakhovetski
2011-09-09 13:24             ` Laurent Pinchart
2011-09-27 10:51             ` Hans Verkuil
2011-09-27 15:49               ` Guennadi Liakhovetski
2011-09-27 19:50                 ` Sakari Ailus
2011-09-28  7:34                 ` Hans Verkuil
2011-09-27 17:01               ` [PATCH 3/9 v8] " Guennadi Liakhovetski
2011-09-28 13:20                 ` [PATCH 3/9 v9] " Guennadi Liakhovetski
2011-09-28 14:58                   ` [PATCH 3/9 v10] " Guennadi Liakhovetski
2011-09-08  7:48           ` [PATCH] V4L: docbook documentation for struct v4l2_create_buffers Guennadi Liakhovetski
2011-09-08  8:10           ` [PATCH 1/1] v4l: Mark VIDIOC_PREPARE_BUFS and VIDIOC_CREATE_BUFS experimental Sakari Ailus
2011-09-27 10:34           ` [PATCH 2/9 v7] V4L: add two new ioctl()s for multi-size videobuffer management Hans Verkuil
2011-09-27 11:00             ` Guennadi Liakhovetski
2011-09-27 11:06               ` Hans Verkuil
2011-09-27 12:19                 ` Guennadi Liakhovetski
2011-09-27 13:40                   ` Hans Verkuil
2011-09-27 16:54                     ` [PATCH 2/9 v8] " Guennadi Liakhovetski
2011-09-28  8:06                       ` Hans Verkuil
2011-09-28  8:34                         ` Guennadi Liakhovetski
2011-09-28  8:48                           ` Guennadi Liakhovetski
2011-09-28  9:01                             ` Hans Verkuil
2011-09-28 13:19                       ` [PATCH 2/9 v9] " Guennadi Liakhovetski
2011-09-28 13:33                         ` Sakari Ailus
2011-09-28 14:59                           ` Guennadi Liakhovetski
2011-09-28 14:56                         ` [PATCH 2/9 v10] " Guennadi Liakhovetski
2011-09-28 20:15                           ` Sakari Ailus
2011-09-28 20:38                             ` Guennadi Liakhovetski
2011-09-29  6:59                               ` Sakari Ailus
2011-09-29  8:12                                 ` Guennadi Liakhovetski
2011-09-27 17:08             ` [PATCH 2/9 v7] " Laurent Pinchart
2011-09-28  8:09               ` Hans Verkuil
2011-08-31 18:02 ` [PATCH 3/9 v6] V4L: document the new VIDIOC_CREATE_BUFS and VIDIOC_PREPARE_BUF ioctl()s Guennadi Liakhovetski
2011-08-31 21:11   ` Sakari Ailus
2011-09-01  7:10     ` Guennadi Liakhovetski
2011-09-01 11:08       ` [PATCH 1/1] v4l: Add note on buffer locking to memory and DMA mapping to PREPARE_BUF Sakari Ailus
2011-09-28 20:20         ` Sakari Ailus
2011-09-28 20:31           ` Guennadi Liakhovetski
2011-11-03 12:13   ` [PATCH 3/9 v6] V4L: document the new VIDIOC_CREATE_BUFS and VIDIOC_PREPARE_BUF ioctl()s Mauro Carvalho Chehab
2011-08-31 18:02 ` [PATCH 4/9 v6] V4L: vb2: prepare to support multi-size buffers Guennadi Liakhovetski
2011-08-31 18:02 ` [PATCH 5/9 v6] V4L: vb2: add support for buffers of different sizes on a single queue Guennadi Liakhovetski
2011-08-31 18:02 ` [PATCH 6/9 v6] V4L: sh-mobile-ceu-camera: prepare to support multi-size buffers Guennadi Liakhovetski
2011-08-31 18:02 ` [PATCH 7/9 v6] dmaengine: ipu-idmac: add support for the DMA_PAUSE control Guennadi Liakhovetski
2011-08-31 18:02 ` [PATCH 8/9 v6] V4L: mx3-camera: prepare to support multi-size buffers Guennadi Liakhovetski
2011-08-31 18:02 ` [PATCH 9/9 v6] V4L: soc-camera: add 2 new ioctl() handlers Guennadi Liakhovetski

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1314813768-27752-2-git-send-email-g.liakhovetski@gmx.de \
    --to=g.liakhovetski@gmx.de \
    --cc=hverkuil@xs4all.nl \
    --cc=laurent.pinchart@ideasonboard.com \
    --cc=linux-media@vger.kernel.org \
    --cc=m.szyprowski@samsung.com \
    --cc=mchehab@infradead.org \
    --cc=pawel@osciak.com \
    --cc=sakari.ailus@maxwell.research.nokia.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.