Linux-ARM-Kernel Archive on lore.kernel.org
 help / color / mirror / Atom feed
From: Siddharth Vadapalli <s-vadapalli@ti.com>
To: <mchehab@kernel.org>, <jai.luthra@linux.dev>,
	<nicolas.dufresne@collabora.com>, <detlev.casanova@collabora.com>,
	<hverkuil+cisco@kernel.org>, <sakari.ailus@linux.intel.com>,
	<richard.leitner@linux.dev>, <jackson.lee@chipsnmedia.com>
Cc: <linux-media@vger.kernel.org>,
	<linux-arm-kernel@lists.infradead.org>, <devarsht@ti.com>,
	<vigneshr@ti.com>, <srk@ti.com>, <s-vadapalli@ti.com>
Subject: [PATCH 1/3] media: v4l2: Add V4L2_EVENT_BUF_PROGRESS to report progress of capture
Date: Sun, 29 Nov 2026 18:58:15 +0530	[thread overview]
Message-ID: <20261129132825.4031308-2-s-vadapalli@ti.com> (raw)
In-Reply-To: <20261129132825.4031308-1-s-vadapalli@ti.com>

A capture buffer is only returned by VIDIOC_DQBUF once the whole frame
has been captured. For low latency pipelines that want to start processing
sub-frames (group of lines in a frame), there is currently no way to
identify how much of the capture buffer has been filled. This results in a
fixed latency overhead corresponding to the frame-rate because the
processing can only start after the entire frame has been captured.

Add V4L2_EVENT_BUF_PROGRESS, which reports the number of bytes from the
start of a buffer that have been written so far, thereby allowing
subscribers to determine the valid portion of the capture buffer and
start processing the valid sub-frame. When a buffer is completed
successfully, the last event for it is queued before the buffer is
returned by VIDIOC_DQBUF, so a subscriber can determine the end-of-frame
from that event alone.

The event payload has space reserved for future extensions. The bytesused
field is only defined for queues of a single-planar buffer type. This event
is generic and does not depend on the format.

Signed-off-by: Siddharth Vadapalli <s-vadapalli@ti.com>
---
 .../media/v4l/videodev2.h.rst.exceptions      |  1 +
 .../media/v4l/vidioc-dqevent.rst              | 74 +++++++++++++++++++
 include/uapi/linux/videodev2.h                | 18 +++++
 3 files changed, 93 insertions(+)

diff --git a/Documentation/userspace-api/media/v4l/videodev2.h.rst.exceptions b/Documentation/userspace-api/media/v4l/videodev2.h.rst.exceptions
index 6182b4e2d2ee..b02f5dd07cab 100644
--- a/Documentation/userspace-api/media/v4l/videodev2.h.rst.exceptions
+++ b/Documentation/userspace-api/media/v4l/videodev2.h.rst.exceptions
@@ -524,6 +524,7 @@ replace define V4L2_EVENT_CTRL event-type
 replace define V4L2_EVENT_FRAME_SYNC event-type
 replace define V4L2_EVENT_SOURCE_CHANGE event-type
 replace define V4L2_EVENT_MOTION_DET event-type
+replace define V4L2_EVENT_BUF_PROGRESS event-type
 replace define V4L2_EVENT_PRIVATE_START event-type
 
 replace define V4L2_EVENT_CTRL_CH_VALUE ctrl-changes-flags
diff --git a/Documentation/userspace-api/media/v4l/vidioc-dqevent.rst b/Documentation/userspace-api/media/v4l/vidioc-dqevent.rst
index 8db103760930..1421ccadab8e 100644
--- a/Documentation/userspace-api/media/v4l/vidioc-dqevent.rst
+++ b/Documentation/userspace-api/media/v4l/vidioc-dqevent.rst
@@ -64,6 +64,9 @@ call.
     * - struct :c:type:`v4l2_event_motion_det`
       - ``motion_det``
       - Event data for event V4L2_EVENT_MOTION_DET.
+    * - struct :c:type:`v4l2_event_buf_progress`
+      - ``buf_progress``
+      - Event data for event ``V4L2_EVENT_BUF_PROGRESS``.
     * - struct :c:type:`v4l2_event_src_change`
       - ``src_change``
       - Event data for event V4L2_EVENT_SOURCE_CHANGE.
@@ -182,6 +185,50 @@ call.
 	the regions changes. This event has a struct
 	:c:type:`v4l2_event_motion_det`
 	associated with it.
+    * - ``V4L2_EVENT_BUF_PROGRESS``
+      - 7
+      - Triggered while a capture buffer is being filled, to report how many
+	bytes from its start have already been written. This allows the
+	leading part of a frame to be processed before the buffer is ready
+	to be dequeued. This event has a struct
+	:c:type:`v4l2_event_buf_progress`
+	associated with it.
+
+	Events are only generated by drivers that support them, and only
+	while the ``V4L2_CID_BUF_PROGRESS_SIZE`` control is non-zero (see
+	:ref:`User Controls <control>`).
+
+	Within one buffer, the ``bytesused`` field only grows. When a buffer
+	is completed successfully, the last event for it, with ``bytesused``
+	equal to the ``bytesused`` of the buffer, is queued before the
+	buffer is returned by :ref:`VIDIOC_DQBUF <VIDIOC_QBUF>`. This last
+	event is always queued, even if fewer than
+	``V4L2_CID_BUF_PROGRESS_SIZE`` lines were written since the previous
+	event.
+
+	No last event is guaranteed for a buffer that is returned with the
+	``V4L2_BUF_FLAG_ERROR`` flag set, or for a buffer that is returned
+	because streaming was stopped with
+	:ref:`VIDIOC_STREAMOFF <VIDIOC_STREAMON>`. Events that were queued
+	for such a buffer have to be ignored. Applications must therefore
+	consider :ref:`VIDIOC_DQBUF <VIDIOC_QBUF>` as the authoritative
+	indication of the state of a buffer.
+
+	Events are dropped, oldest first, when the application does not
+	dequeue them in time. Lost events can be detected by a gap in the
+	``sequence`` field of struct :c:type:`v4l2_event`, which is not
+	related to the ``sequence`` field of struct
+	:c:type:`v4l2_event_buf_progress`. Applications must be prepared
+	for intermediate values of ``bytesused`` to be skipped.
+
+	The buffer remains owned by the driver until it is dequeued, and the
+	driver does not perform any cache maintenance on the part of the
+	buffer that was reported. An application that reads that part before
+	the buffer is dequeued must make sure that its mapping is coherent
+	with DMA, which is not the case for memory allocated with
+	``V4L2_MEMORY_FLAG_NON_COHERENT``. For buffers with memory type
+	``V4L2_MEMORY_DMABUF``, cache management is the responsibility of
+	the exporter of the buffer.
     * - ``V4L2_EVENT_PRIVATE_START``
       - 0x08000000
       - Base event number for driver-private events.
@@ -309,6 +356,33 @@ call.
 	automatically assigned to the default region 0.
 
 
+.. tabularcolumns:: |p{4.4cm}|p{4.4cm}|p{8.5cm}|
+
+.. c:type:: v4l2_event_buf_progress
+
+.. flat-table:: struct v4l2_event_buf_progress
+    :header-rows:  0
+    :stub-columns: 0
+    :widths:       1 1 2
+
+    * - __u32
+      - ``index``
+      - The index of the buffer that is being filled.
+    * - __u32
+      - ``sequence``
+      - The sequence number the buffer will be dequeued with.
+    * - __u32
+      - ``bytesused``
+      - The number of bytes from the start of the buffer that have been
+	written so far. This field is only defined for queues of a
+	single-planar buffer type. A driver that generates this event on a
+	multi-planar queue has to document the meaning of this field.
+    * - __u32
+      - ``reserved``\ [5]
+      - Reserved for future extensions. Drivers must set the array to
+	zero.
+
+
 .. tabularcolumns:: |p{6.6cm}|p{2.2cm}|p{8.5cm}|
 
 .. _ctrl-changes-flags:
diff --git a/include/uapi/linux/videodev2.h b/include/uapi/linux/videodev2.h
index 5373dba640fa..a019f481167e 100644
--- a/include/uapi/linux/videodev2.h
+++ b/include/uapi/linux/videodev2.h
@@ -2558,6 +2558,7 @@ struct v4l2_streamparm {
 #define V4L2_EVENT_FRAME_SYNC			4
 #define V4L2_EVENT_SOURCE_CHANGE		5
 #define V4L2_EVENT_MOTION_DET			6
+#define V4L2_EVENT_BUF_PROGRESS		7
 #define V4L2_EVENT_PRIVATE_START		0x08000000
 
 /* Payload for V4L2_EVENT_VSYNC */
@@ -2611,6 +2612,22 @@ struct v4l2_event_motion_det {
 	__u32 region_mask;
 };
 
+/**
+ * struct v4l2_event_buf_progress - buffer fill progress event
+ * @index:		index of the buffer that is being filled.
+ * @sequence:		sequence number the buffer will be dequeued with.
+ * @bytesused:		number of bytes from the start of the buffer that
+ *			have been written so far.
+ * @reserved:		reserved for future extensions, drivers must set
+ *			the array to zero.
+ */
+struct v4l2_event_buf_progress {
+	__u32 index;
+	__u32 sequence;
+	__u32 bytesused;
+	__u32 reserved[5];
+};
+
 struct v4l2_event {
 	__u32				type;
 	union {
@@ -2619,6 +2636,7 @@ struct v4l2_event {
 		struct v4l2_event_frame_sync	frame_sync;
 		struct v4l2_event_src_change	src_change;
 		struct v4l2_event_motion_det	motion_det;
+		struct v4l2_event_buf_progress	buf_progress;
 		__u8				data[64];
 	} u;
 	__u32				pending;
-- 
2.56.0



  reply	other threads:[~2026-11-29 13:29 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-29 13:28 [PATCH 0/3] media: Add V4L2_EVENT_BUF_PROGRESS and use it in j721e-csi2rx Siddharth Vadapalli
2026-11-29 13:28 ` Siddharth Vadapalli [this message]
2026-11-30 15:21   ` [PATCH 1/3] media: v4l2: Add V4L2_EVENT_BUF_PROGRESS to report progress of capture Nicolas Dufresne
2026-11-29 13:28 ` [PATCH 2/3] media: v4l2-ctrls: Add buffer progress controls for sub-frame functionality Siddharth Vadapalli
2026-11-29 13:28 ` [PATCH 3/3] media: ti: j721e-csi2rx: Generate capture-progress events for sub-frames Siddharth Vadapalli

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=20261129132825.4031308-2-s-vadapalli@ti.com \
    --to=s-vadapalli@ti.com \
    --cc=detlev.casanova@collabora.com \
    --cc=devarsht@ti.com \
    --cc=hverkuil+cisco@kernel.org \
    --cc=jackson.lee@chipsnmedia.com \
    --cc=jai.luthra@linux.dev \
    --cc=linux-arm-kernel@lists.infradead.org \
    --cc=linux-media@vger.kernel.org \
    --cc=mchehab@kernel.org \
    --cc=nicolas.dufresne@collabora.com \
    --cc=richard.leitner@linux.dev \
    --cc=sakari.ailus@linux.intel.com \
    --cc=srk@ti.com \
    --cc=vigneshr@ti.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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox