mirror of https://lore.kernel.org/lkml/
 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 v18 1/9] media: videobuf2: Update vb2_is_busy() logic
Date: Fri, 26 Jan 2024 12:01:33 +0100	[thread overview]
Message-ID: <20240126110141.135896-2-benjamin.gaignard@collabora.com> (raw)
In-Reply-To: <20240126110141.135896-1-benjamin.gaignard@collabora.com>

Do not rely on the number of allocated buffers to know if the
queue is busy but on flag set when at least buffer has been allocated
by REQBUFS or CREATE_BUFS ioctl.
The flag is reset when REQBUFS is called with count = 0 or close the
file handle.
This is needed because delete buffers feature will be able to remove
all the buffers from a queue while streaming so relying in the number
of allocated buffers in the queue won't be possible.

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

diff --git a/drivers/media/common/videobuf2/videobuf2-core.c b/drivers/media/common/videobuf2/videobuf2-core.c
index b6bf8f232f48..8aa6057df581 100644
--- a/drivers/media/common/videobuf2/videobuf2-core.c
+++ b/drivers/media/common/videobuf2/videobuf2-core.c
@@ -858,8 +858,10 @@ int vb2_core_reqbufs(struct vb2_queue *q, enum vb2_memory memory,
 		 * In case of REQBUFS(0) return immediately without calling
 		 * driver's queue_setup() callback and allocating resources.
 		 */
-		if (*count == 0)
+		if (*count == 0) {
+			q->is_busy = 0;
 			return 0;
+		}
 	}
 
 	/*
@@ -966,6 +968,7 @@ int vb2_core_reqbufs(struct vb2_queue *q, enum vb2_memory memory,
 	 */
 	*count = allocated_buffers;
 	q->waiting_for_buffers = !q->is_output;
+	q->is_busy = 1;
 
 	return 0;
 
@@ -1091,6 +1094,7 @@ int vb2_core_create_bufs(struct vb2_queue *q, enum vb2_memory memory,
 	 * to the userspace.
 	 */
 	*count = allocated_buffers;
+	q->is_busy = 1;
 
 	return 0;
 
diff --git a/include/media/videobuf2-core.h b/include/media/videobuf2-core.h
index 56719a26a46c..b317286a7b08 100644
--- a/include/media/videobuf2-core.h
+++ b/include/media/videobuf2-core.h
@@ -579,6 +579,7 @@ struct vb2_buf_ops {
  *		called since poll() needs to return %EPOLLERR in that situation.
  * @is_multiplanar: set if buffer type is multiplanar
  * @is_output:	set if buffer type is output
+ * @is_busy:	set if at least one buffer has been allocated at some time.
  * @copy_timestamp: set if vb2-core should set timestamps
  * @last_buffer_dequeued: used in poll() and DQBUF to immediately return if the
  *		last decoded buffer was already dequeued. Set for capture queues
@@ -644,6 +645,7 @@ struct vb2_queue {
 	unsigned int			waiting_in_dqbuf:1;
 	unsigned int			is_multiplanar:1;
 	unsigned int			is_output:1;
+	unsigned int			is_busy:1;
 	unsigned int			copy_timestamp:1;
 	unsigned int			last_buffer_dequeued:1;
 
@@ -1163,7 +1165,7 @@ static inline unsigned int vb2_get_num_buffers(struct vb2_queue *q)
  */
 static inline bool vb2_is_busy(struct vb2_queue *q)
 {
-	return vb2_get_num_buffers(q) > 0;
+	return !!q->is_busy;
 }
 
 /**
-- 
2.40.1


  reply	other threads:[~2024-01-26 11:01 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-01-26 11:01 [PATCH v18 0/9] Add DELETE_BUF ioctl Benjamin Gaignard
2024-01-26 11:01 ` Benjamin Gaignard [this message]
2024-02-05 13:59   ` [PATCH v18 1/9] media: videobuf2: Update vb2_is_busy() logic Hans Verkuil
2024-01-26 11:01 ` [PATCH v18 2/9] videobuf2: Add min_reqbufs_allocation field to vb2_queue structure Benjamin Gaignard
2024-01-26 11:01 ` [PATCH v18 3/9] media: test-drivers: Set REQBUFS minimum number of buffers Benjamin Gaignard
2024-01-26 11:01 ` [PATCH v18 4/9] media: core: Rework how create_buf index returned value is computed Benjamin Gaignard
2024-01-26 11:01 ` [PATCH v18 5/9] media: core: Add bitmap manage bufs array entries Benjamin Gaignard
2024-01-26 11:01 ` [PATCH v18 6/9] media: core: Free range of buffers Benjamin Gaignard
2024-02-05 14:15   ` Hans Verkuil
2024-01-26 11:01 ` [PATCH v18 7/9] media: v4l2: Add DELETE_BUFS ioctl Benjamin Gaignard
2024-02-05 14:28   ` Hans Verkuil
2024-01-26 11:01 ` [PATCH v18 8/9] media: v4l2: Add mem2mem helpers for " Benjamin Gaignard
2024-01-26 11:01 ` [PATCH v18 9/9] media: verisilicon: Support deleting buffers on capture queue 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=20240126110141.135896-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

all inboxes | Powered by JetHome®