media: videobuf2: Introduce vb2_find_buffer()
authorEzequiel Garcia <ezequiel@collabora.com>
Mon, 11 Jul 2022 21:11:34 +0000 (22:11 +0100)
committerMauro Carvalho Chehab <mchehab@kernel.org>
Sun, 17 Jul 2022 10:10:11 +0000 (11:10 +0100)
All users of vb2_find_timestamp() combine it with vb2_get_buffer()
to retrieve a videobuf2 buffer, given a u64 timestamp.

Introduce an API for this use-case. Users will be converted to the new
API as follow-up commits.

Signed-off-by: Ezequiel Garcia <ezequiel@collabora.com>
Acked-by: Tomasz Figa <tfiga@chromium.org>
Reviewed-by: Philipp Zabel <p.zabel@pengutronix.de>
Signed-off-by: Hans Verkuil <hverkuil-cisco@xs4all.nl>
Signed-off-by: Mauro Carvalho Chehab <mchehab@kernel.org>
drivers/media/common/videobuf2/videobuf2-v4l2.c
include/media/videobuf2-v4l2.h

index 075d24ebf44c3a8c521356f5ea05d19bb6449260..f26cb8586bd4e15c1534696aa26f9b2f8caf7669 100644 (file)
@@ -638,6 +638,18 @@ int vb2_find_timestamp(const struct vb2_queue *q, u64 timestamp,
 }
 EXPORT_SYMBOL_GPL(vb2_find_timestamp);
 
+struct vb2_buffer *vb2_find_buffer(struct vb2_queue *q, u64 timestamp)
+{
+       unsigned int i;
+
+       for (i = 0; i < q->num_buffers; i++)
+               if (q->bufs[i]->copied_timestamp &&
+                   q->bufs[i]->timestamp == timestamp)
+                       return vb2_get_buffer(q, i);
+       return NULL;
+}
+EXPORT_SYMBOL_GPL(vb2_find_buffer);
+
 /*
  * vb2_querybuf() - query video buffer information
  * @q:         videobuf queue
index d818d97076953efb3e55f53444dad9d08b7b9439..76e405c0b00307ae3c19268078882c30c6caf629 100644 (file)
@@ -78,6 +78,16 @@ struct vb2_v4l2_buffer {
 int vb2_find_timestamp(const struct vb2_queue *q, u64 timestamp,
                       unsigned int start_idx);
 
+/**
+ * vb2_find_buffer() - Find a buffer with given timestamp
+ *
+ * @q:         pointer to &struct vb2_queue with videobuf2 queue.
+ * @timestamp: the timestamp to find.
+ *
+ * Returns the buffer with the given @timestamp, or NULL if not found.
+ */
+struct vb2_buffer *vb2_find_buffer(struct vb2_queue *q, u64 timestamp);
+
 int vb2_querybuf(struct vb2_queue *q, struct v4l2_buffer *b);
 
 /**