linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Benjamin Gaignard <benjamin.gaignard@collabora.com>
To: hverkuil@xs4all.nl, mchehab@kernel.org
Cc: linux-kernel@vger.kernel.org, linux-media@vger.kernel.org,
	kernel@collabora.com,
	Benjamin Gaignard <benjamin.gaignard@collabora.com>
Subject: [PATCH v16 1/8] videobuf2: Add min_reqbufs_allocation field to vb2_queue structure
Date: Fri, 15 Dec 2023 10:08:06 +0100	[thread overview]
Message-ID: <20231215090813.15610-2-benjamin.gaignard@collabora.com> (raw)
In-Reply-To: <20231215090813.15610-1-benjamin.gaignard@collabora.com>

Add 'min_reqbufs_allocation' field in vb2_queue structure so drivers
can specificy the minimum number of buffers to allocate when calling
VIDIOC_REQBUFS.
If used this minimum should be higher than the minimum number of
queued buffers needed to start streaming.

Signed-off-by: Benjamin Gaignard <benjamin.gaignard@collabora.com>
---
 drivers/media/common/videobuf2/videobuf2-core.c | 10 ++++++++--
 include/media/videobuf2-core.h                  | 13 +++++++++++++
 2 files changed, 21 insertions(+), 2 deletions(-)

diff --git a/drivers/media/common/videobuf2/videobuf2-core.c b/drivers/media/common/videobuf2/videobuf2-core.c
index 41a832dd1426..a183edf11586 100644
--- a/drivers/media/common/videobuf2/videobuf2-core.c
+++ b/drivers/media/common/videobuf2/videobuf2-core.c
@@ -865,7 +865,7 @@ int vb2_core_reqbufs(struct vb2_queue *q, enum vb2_memory memory,
 	/*
 	 * Make sure the requested values and current defaults are sane.
 	 */
-	num_buffers = max_t(unsigned int, *count, q->min_queued_buffers);
+	num_buffers = max_t(unsigned int, *count, q->min_reqbufs_allocation);
 	num_buffers = min_t(unsigned int, num_buffers, q->max_num_buffers);
 	memset(q->alloc_devs, 0, sizeof(q->alloc_devs));
 	/*
@@ -917,7 +917,7 @@ int vb2_core_reqbufs(struct vb2_queue *q, enum vb2_memory memory,
 	 * There is no point in continuing if we can't allocate the minimum
 	 * number of buffers needed by this vb2_queue.
 	 */
-	if (allocated_buffers < q->min_queued_buffers)
+	if (allocated_buffers < q->min_reqbufs_allocation)
 		ret = -ENOMEM;
 
 	/*
@@ -2521,6 +2521,12 @@ int vb2_core_queue_init(struct vb2_queue *q)
 	if (WARN_ON(q->supports_requests && q->min_queued_buffers))
 		return -EINVAL;
 
+	q->min_reqbufs_allocation = max_t(unsigned int,
+					  q->min_reqbufs_allocation,
+					  q->min_queued_buffers + 1);
+	if (WARN_ON(q->min_reqbufs_allocation > q->max_num_buffers))
+		return -EINVAL;
+
 	INIT_LIST_HEAD(&q->queued_list);
 	INIT_LIST_HEAD(&q->done_list);
 	spin_lock_init(&q->done_lock);
diff --git a/include/media/videobuf2-core.h b/include/media/videobuf2-core.h
index 56719a26a46c..7b84b4e2e273 100644
--- a/include/media/videobuf2-core.h
+++ b/include/media/videobuf2-core.h
@@ -553,6 +553,18 @@ struct vb2_buf_ops {
  *		VIDIOC_REQBUFS will ensure at least @min_queued_buffers
  *		buffers will be allocated. Note that VIDIOC_CREATE_BUFS will not
  *		modify the requested buffer count.
+ * @min_reqbufs_allocation: the minimum number of buffers to be allocated when
+ *		calling VIDIOC_REQBUFS. Drivers can set this if there has to
+ *		be a certain number of buffers available for the hardware to
+ *		work effectively. If set, then @min_reqbufs_allocation must be
+ *		larger than @min_queued_buffers + 1.
+ *		This field is only used by VIDIOC_REQBUFS. This allows calling
+ *		that ioctl with a buffer count of 1 and it will be automatically
+ *		adjusted to a workable buffer count. VIDIOC_CREATE_BUFS will not
+ *		modify the requested buffer count.
+ *		If this field is > 3, then it is highly recommended that the
+ *		driver implements the V4L2_CID_MIN_BUFFERS_FOR_CAPTURE/OUTPUT
+ *		control.
  */
 /*
  * Private elements (won't appear at the uAPI book):
@@ -618,6 +630,7 @@ struct vb2_queue {
 	u32				timestamp_flags;
 	gfp_t				gfp_flags;
 	u32				min_queued_buffers;
+	u32				min_reqbufs_allocation;
 
 	struct device			*alloc_devs[VB2_MAX_PLANES];
 
-- 
2.40.1


  reply	other threads:[~2023-12-15  9:08 UTC|newest]

Thread overview: 28+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-12-15  9:08 [PATCH v16 0/8] Add DELETE_BUF ioctl Benjamin Gaignard
2023-12-15  9:08 ` Benjamin Gaignard [this message]
2024-01-15  9:16   ` [PATCH v16 1/8] videobuf2: Add min_reqbufs_allocation field to vb2_queue structure Hans Verkuil
2024-01-15 10:27   ` Hans Verkuil
2023-12-15  9:08 ` [PATCH v16 2/8] media: test-drivers: Set REQBUFS minimum number of buffers Benjamin Gaignard
2024-01-15 10:35   ` Hans Verkuil
2023-12-15  9:08 ` [PATCH v16 3/8] media: core: Rework how create_buf index returned value is computed Benjamin Gaignard
2024-01-15 11:00   ` Hans Verkuil
2024-01-15 11:40     ` Hans Verkuil
2024-01-15 12:11   ` Hans Verkuil
2024-01-15 14:52     ` Benjamin Gaignard
2024-01-15 15:17       ` Hans Verkuil
2024-01-15 16:04   ` Hans Verkuil
2023-12-15  9:08 ` [PATCH v16 4/8] media: core: Add bitmap manage bufs array entries Benjamin Gaignard
2024-01-15 12:21   ` Hans Verkuil
2024-01-15 14:51     ` Benjamin Gaignard
2024-01-15 15:14       ` Hans Verkuil
2023-12-15  9:08 ` [PATCH v16 5/8] media: core: Free range of buffers Benjamin Gaignard
2024-01-15 16:08   ` Hans Verkuil
2023-12-15  9:08 ` [PATCH v16 6/8] media: v4l2: Add DELETE_BUFS ioctl Benjamin Gaignard
2024-01-15 16:43   ` Hans Verkuil
2024-01-16  9:37     ` Benjamin Gaignard
2023-12-15  9:08 ` [PATCH v16 7/8] media: v4l2: Add mem2mem helpers for " Benjamin Gaignard
2024-01-15 16:50   ` Hans Verkuil
2024-01-16 10:42     ` Benjamin Gaignard
2023-12-15  9:08 ` [PATCH v16 8/8] media: test-drivers: Use helper " Benjamin Gaignard
2024-01-15 16:53   ` Hans Verkuil
2024-01-09  9:37 ` [PATCH v16 0/8] Add DELETE_BUF ioctl Benjamin Gaignard

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=20231215090813.15610-2-benjamin.gaignard@collabora.com \
    --to=benjamin.gaignard@collabora.com \
    --cc=hverkuil@xs4all.nl \
    --cc=kernel@collabora.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-media@vger.kernel.org \
    --cc=mchehab@kernel.org \
    /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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).