[PATCH 1/3] media: v4l2: Add V4L2_EVENT_BUF_PROGRESS to report progress of capture

Siddharth Vadapalli s-vadapalli at ti.com
Sun Nov 29 05:28:15 PST 2026


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 at 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




More information about the linux-arm-kernel mailing list