Re: [PATCH v5 1/3] media: videodev2: Add flag to unconditionnaly enumerate pixels formats

From: Benjamin Gaignard
Date: Wed Jul 31 2024 - 03:00:58 EST



Le 30/07/2024 à 09:19, Hans Verkuil a écrit :
On 30/07/2024 09:08, Hans Verkuil wrote:
On 22/07/2024 17:05, Benjamin Gaignard wrote:
When the index field is ORed with V4L2_FMT_FLAG_ENUM_ALL the driver
will ignore any configuration and enumerate all the possible formats.
Drivers which do not support this flag yet always return an EINVAL
error code.

Signed-off-by: Benjamin Gaignard <benjamin.gaignard@xxxxxxxxxxxxx>
---
changes in version 5:
- Reset the proposal to follow Hans's advices
- Add new flag to be used with index field.

.../userspace-api/media/v4l/vidioc-enum-fmt.rst | 12 +++++++++++-
.../userspace-api/media/videodev2.h.rst.exceptions | 1 +
include/uapi/linux/videodev2.h | 3 +++
3 files changed, 15 insertions(+), 1 deletion(-)

diff --git a/Documentation/userspace-api/media/v4l/vidioc-enum-fmt.rst b/Documentation/userspace-api/media/v4l/vidioc-enum-fmt.rst
index 3adb3d205531..12e1e65e6a71 100644
--- a/Documentation/userspace-api/media/v4l/vidioc-enum-fmt.rst
+++ b/Documentation/userspace-api/media/v4l/vidioc-enum-fmt.rst
@@ -85,7 +85,11 @@ the ``mbus_code`` field is handled differently:
* - __u32
- ``index``
- Number of the format in the enumeration, set by the application.
- This is in no way related to the ``pixelformat`` field.
+ This is in no way related to the ``pixelformat`` field. When the
You need to start a new paragraph before 'When'. Otherwise you might read
that the 'When' sentence is somehow related to the previous sentence.

+ index is ORed with V4L2_FMT_FLAG_ENUM_ALL the driver will ignore
+ any configuration and enumerate all the possible formats. Drivers
I'd rephrase this a little bit:

the driver will enumerate all the possible formats, ignoring any limitations
from the current configuration.

And after that I would like to see an example of a use-case.
Should the flag be kept on return of VIDIOC_ENUM_FMT or should it be cleared?
For reference: VIDIOC_QUERYCTRL will clear the V4L2_CTRL_FLAG_NEXT_CTRL flag.

Regardless of what we pick, it should be documented.

I believe most of the flags are cleared in v4l2 so I will to do the same and
document it.


Regards,

Hans

+ which do not support this flag yet always return an ``EINVAL``
+ error code.
* - __u32
- ``type``
- Type of the data stream, set by the application. Only these types
@@ -234,6 +238,12 @@ the ``mbus_code`` field is handled differently:
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``.
+ * - ``V4L2_FMT_FLAG_ENUM_ALL``
I am not really happy with this name since the prefix is identical to that
of other V4L2_FMT_FLAG_ defines. How about: V4L2_FMTDESC_FLAG_ENUM_ALL?
Or V4L2_FMT_IDX_ENUM_ALL?

+ - 0x80000000
+ - When the applications ORs ``index`` with ``V4L2_FMT_FLAG_ENUM_ALL`` flag
+ the driver enumerates all the possible pixel formats without taking care
+ of any already set configuration. Drivers which do not support this flag
+ yet always return ``EINVAL``.
Return Value
============
diff --git a/Documentation/userspace-api/media/videodev2.h.rst.exceptions b/Documentation/userspace-api/media/videodev2.h.rst.exceptions
index bdc628e8c1d6..8dc10a500fc6 100644
--- a/Documentation/userspace-api/media/videodev2.h.rst.exceptions
+++ b/Documentation/userspace-api/media/videodev2.h.rst.exceptions
@@ -216,6 +216,7 @@ 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
+replace define V4L2_FMT_FLAG_ENUM_ALL fmtdesc-flags
# V4L2 timecode types
replace define V4L2_TC_TYPE_24FPS timecode-type
diff --git a/include/uapi/linux/videodev2.h b/include/uapi/linux/videodev2.h
index 4e91362da6da..3d11f91273a1 100644
--- a/include/uapi/linux/videodev2.h
+++ b/include/uapi/linux/videodev2.h
@@ -904,6 +904,9 @@ struct v4l2_fmtdesc {
#define V4L2_FMT_FLAG_CSC_QUANTIZATION 0x0100
#define V4L2_FMT_FLAG_META_LINE_BASED 0x0200
+/* Format description flag, to be ORed with the index */
+#define V4L2_FMT_FLAG_ENUM_ALL 0x80000000
+
/* Frame Size and frame rate enumeration */
/*
* F R A M E S I Z E E N U M E R A T I O N
Regards,

Hans