media: v4l: Support line-based metadata capture
authorSakari Ailus <sakari.ailus@linux.intel.com>
Tue, 21 Feb 2023 17:37:29 +0000 (19:37 +0200)
committerHans Verkuil <hverkuil-cisco@xs4all.nl>
Mon, 29 Apr 2024 12:56:36 +0000 (14:56 +0200)
Many camera sensors, among other devices, transmit embedded data and image
data for each CSI-2 frame. This embedded data typically contains register
configuration of the sensor that has been used to capture the image data
of the same frame.

The embedded data is received by the CSI-2 receiver and has the same
properties as the image data, including that it is line based: it has
width, height and bytesperline (stride).

Add these fields to struct v4l2_meta_format and document them.

Also add V4L2_FMT_FLAG_META_LINE_BASED to tell a given format is
line-based i.e. these fields of struct v4l2_meta_format are valid for it.

Signed-off-by: Sakari Ailus <sakari.ailus@linux.intel.com>
Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Signed-off-by: Hans Verkuil <hverkuil-cisco@xs4all.nl>
Documentation/userspace-api/media/v4l/dev-meta.rst
Documentation/userspace-api/media/v4l/vidioc-enum-fmt.rst
Documentation/userspace-api/media/videodev2.h.rst.exceptions
drivers/media/v4l2-core/v4l2-ioctl.c
include/uapi/linux/videodev2.h

index 0e7e1ee1471a44c68e6280c2067f1990dee74868..5eee9ab60395e8885c33d522492863ae3e3d047a 100644 (file)
@@ -47,6 +47,12 @@ member of the ``fmt`` union as needed per the desired operation. Both drivers
 and applications must set the remainder of the :c:type:`v4l2_format` structure
 to 0.
 
+Devices that capture metadata by line have the struct v4l2_fmtdesc
+``V4L2_FMT_FLAG_META_LINE_BASED`` flag set for :c:func:`VIDIOC_ENUM_FMT`. Such
+devices can typically also :ref:`capture image data <capture>`. This primarily
+involves devices that receive the data from a different devices such as a camera
+sensor.
+
 .. c:type:: v4l2_meta_format
 
 .. tabularcolumns:: |p{1.4cm}|p{2.4cm}|p{13.5cm}|
@@ -65,3 +71,18 @@ to 0.
       - ``buffersize``
       - Maximum buffer size in bytes required for data. The value is set by the
         driver.
+    * - __u32
+      - ``width``
+      - Width of a line of metadata in Data Units. Valid when
+       :c:type`v4l2_fmtdesc` flag ``V4L2_FMT_FLAG_META_LINE_BASED`` is set,
+       otherwise zero. See :c:func:`VIDIOC_ENUM_FMT`.
+    * - __u32
+      - ``height``
+      - Number of rows of metadata. Valid when :c:type`v4l2_fmtdesc` flag
+       ``V4L2_FMT_FLAG_META_LINE_BASED`` is set, otherwise zero. See
+       :c:func:`VIDIOC_ENUM_FMT`.
+    * - __u32
+      - ``bytesperline``
+      - Offset in bytes between the beginning of two consecutive lines. Valid
+       when :c:type`v4l2_fmtdesc` flag ``V4L2_FMT_FLAG_META_LINE_BASED`` is
+       set, otherwise zero. See :c:func:`VIDIOC_ENUM_FMT`.
index 000c154b0f989dc11454bde77d5c1fdbc12f618e..3adb3d205531b48b58c462a46ad361124202c596 100644 (file)
@@ -227,6 +227,13 @@ the ``mbus_code`` field is handled differently:
        The application can ask to configure the quantization of the capture
        device when calling the :ref:`VIDIOC_S_FMT <VIDIOC_G_FMT>` ioctl with
        :ref:`V4L2_PIX_FMT_FLAG_SET_CSC <v4l2-pix-fmt-flag-set-csc>` set.
+    * - ``V4L2_FMT_FLAG_META_LINE_BASED``
+      - 0x0200
+      - The metadata format is line-based. In this case the ``width``,
+       ``height`` and ``bytesperline`` fields of :c:type:`v4l2_meta_format` are
+       valid. The buffer consists of ``height`` lines, each having ``width``
+       Data Units of data and the offset (in bytes) between the beginning of
+       each two consecutive lines is ``bytesperline``.
 
 Return Value
 ============
index 3e58aac4ef0b6e2e0ce1672515ccaff660377e90..bdc628e8c1d6943211940e55b67a587f44f931a6 100644 (file)
@@ -215,6 +215,7 @@ replace define V4L2_FMT_FLAG_CSC_XFER_FUNC fmtdesc-flags
 replace define V4L2_FMT_FLAG_CSC_YCBCR_ENC fmtdesc-flags
 replace define V4L2_FMT_FLAG_CSC_HSV_ENC fmtdesc-flags
 replace define V4L2_FMT_FLAG_CSC_QUANTIZATION fmtdesc-flags
+replace define V4L2_FMT_FLAG_META_LINE_BASED fmtdesc-flags
 
 # V4L2 timecode types
 replace define V4L2_TC_TYPE_24FPS timecode-type
index ae2dca7f2817e54e611257c224eaa3c93b1136cd..2cfc9106857aec82cd5b40f727530bedae2ef83f 100644 (file)
@@ -343,8 +343,9 @@ static void v4l_print_format(const void *arg, bool write_only)
        case V4L2_BUF_TYPE_META_OUTPUT:
                meta = &p->fmt.meta;
                pixelformat = meta->dataformat;
-               pr_cont(", dataformat=%p4cc, buffersize=%u\n",
-                       &pixelformat, meta->buffersize);
+               pr_cont(", dataformat=%p4cc, buffersize=%u, width=%u, height=%u, bytesperline=%u\n",
+                       &pixelformat, meta->buffersize, meta->width,
+                       meta->height, meta->bytesperline);
                break;
        }
 }
index 0f44b8486ea8a8dfeb1adf7e21f1bdcd33af1d90..647ce3419bd88460bd7d34df478cf105dffffa58 100644 (file)
@@ -877,6 +877,7 @@ struct v4l2_fmtdesc {
 #define V4L2_FMT_FLAG_CSC_YCBCR_ENC            0x0080
 #define V4L2_FMT_FLAG_CSC_HSV_ENC              V4L2_FMT_FLAG_CSC_YCBCR_ENC
 #define V4L2_FMT_FLAG_CSC_QUANTIZATION         0x0100
+#define V4L2_FMT_FLAG_META_LINE_BASED          0x0200
 
        /* Frame Size and frame rate enumeration */
 /*
@@ -2424,10 +2425,19 @@ struct v4l2_sdr_format {
  * struct v4l2_meta_format - metadata format definition
  * @dataformat:                little endian four character code (fourcc)
  * @buffersize:                maximum size in bytes required for data
+ * @width:             number of data units of data per line (valid for line
+ *                     based formats only, see format documentation)
+ * @height:            number of lines of data per buffer (valid for line based
+ *                     formats only)
+ * @bytesperline:      offset between the beginnings of two adjacent lines in
+ *                     bytes (valid for line based formats only)
  */
 struct v4l2_meta_format {
        __u32                           dataformat;
        __u32                           buffersize;
+       __u32                           width;
+       __u32                           height;
+       __u32                           bytesperline;
 } __attribute__ ((packed));
 
 /**