* [PATCH v7 1/3] media: videodev2: Add flag to unconditionally enumerate pixel formats
[not found] <20240826172407.140538-1-benjamin.gaignard@collabora.com>
@ 2024-08-26 17:24 ` Benjamin Gaignard
2024-10-11 13:29 ` Hans Verkuil
2024-08-26 17:24 ` [PATCH v7 3/3] media: verisilicon: Use V4L2_FMTDESC_FLAG_ENUM_ALL flag Benjamin Gaignard
2024-08-26 17:24 ` [PATCH v7 2/3] media: test-drivers: " Benjamin Gaignard
2 siblings, 1 reply; 5+ messages in thread
From: Benjamin Gaignard @ 2024-08-26 17:24 UTC (permalink / raw)
To: mchehab, ezequiel, hverkuil-cisco
Cc: linux-media, linux-kernel, linux-rockchip, kernel, Benjamin Gaignard
When the index is ORed with V4L2_FMTDESC_FLAG_ENUM_ALL the
driver clears the flag and enumerate all the possible formats,
ignoring any limitations from the current configuration.
Drivers which do not support this flag yet always return an EINVAL.
Signed-off-by: Benjamin Gaignard <benjamin.gaignard@collabora.com>
---
change in version 7:
- Rework documentation about which drivers should use the flag
.../media/v4l/vidioc-enum-fmt.rst | 18 +++++++++++++++++-
.../media/videodev2.h.rst.exceptions | 1 +
include/uapi/linux/videodev2.h | 3 +++
3 files changed, 21 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..e39c87bcbfc3 100644
--- a/Documentation/userspace-api/media/v4l/vidioc-enum-fmt.rst
+++ b/Documentation/userspace-api/media/v4l/vidioc-enum-fmt.rst
@@ -85,7 +85,17 @@ 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 index is ORed with ``V4L2_FMTDESC_FLAG_ENUM_ALL`` the
+ driver clears the flag and enumerates all the possible formats,
+ ignoring any limitations from the current configuration. Drivers
+ which do not support this flag always return an ``EINVAL``
+ error code.
+ Formats enumerated when using ``V4L2_FMTDESC_FLAG_ENUM_ALL`` flag
+ shouldn't be used when calling :c:func:`VIDIOC_ENUM_FRAMESIZES`
+ or :c:func:`VIDIOC_ENUM_FRAMEINTERVALS`.
+ ``V4L2_FMTDESC_FLAG_ENUM_ALL`` should only be used by drivers that
+ can return different format list depending on this flag.
* - __u32
- ``type``
- Type of the data stream, set by the application. Only these types
@@ -234,6 +244,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_FMTDESC_FLAG_ENUM_ALL``
+ - 0x80000000
+ - When the applications ORs ``index`` with ``V4L2_FMTDESC_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,
+ 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..0a9ea9686c24 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_FMTDESC_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..421a30cb0c51 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_FMTDESC_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
--
2.43.0
^ permalink raw reply [flat|nested] 5+ messages in thread
* [PATCH v7 2/3] media: test-drivers: Use V4L2_FMTDESC_FLAG_ENUM_ALL flag
[not found] <20240826172407.140538-1-benjamin.gaignard@collabora.com>
2024-08-26 17:24 ` [PATCH v7 1/3] media: videodev2: Add flag to unconditionally enumerate pixel formats Benjamin Gaignard
2024-08-26 17:24 ` [PATCH v7 3/3] media: verisilicon: Use V4L2_FMTDESC_FLAG_ENUM_ALL flag Benjamin Gaignard
@ 2024-08-26 17:24 ` Benjamin Gaignard
2 siblings, 0 replies; 5+ messages in thread
From: Benjamin Gaignard @ 2024-08-26 17:24 UTC (permalink / raw)
To: mchehab, ezequiel, hverkuil-cisco
Cc: linux-media, linux-kernel, linux-rockchip, kernel, Benjamin Gaignard
Since the V4L2_FMTDESC_FLAG_ENUM_ALL flag mostly targets stateless
decoder pixel-format enumeration, update visl test driver to use it.
When V4L2_FMTDESC_FLAG_ENUM_ALL flag is set let the driver returns
one more pixel format.
Signed-off-by: Benjamin Gaignard <benjamin.gaignard@collabora.com>
---
drivers/media/test-drivers/visl/visl-video.c | 20 ++++++++++++++++++--
1 file changed, 18 insertions(+), 2 deletions(-)
diff --git a/drivers/media/test-drivers/visl/visl-video.c b/drivers/media/test-drivers/visl/visl-video.c
index f8d970319764..677a8564de03 100644
--- a/drivers/media/test-drivers/visl/visl-video.c
+++ b/drivers/media/test-drivers/visl/visl-video.c
@@ -136,6 +136,12 @@ static const u32 visl_decoded_fmts[] = {
V4L2_PIX_FMT_YUV420,
};
+static const u32 visl_extended_decoded_fmts[] = {
+ V4L2_PIX_FMT_NV12,
+ V4L2_PIX_FMT_YUV420,
+ V4L2_PIX_FMT_P010,
+};
+
const struct visl_coded_format_desc visl_coded_fmts[] = {
{
.pixelformat = V4L2_PIX_FMT_FWHT_STATELESS,
@@ -341,11 +347,21 @@ static int visl_enum_fmt_vid_cap(struct file *file, void *priv,
struct v4l2_fmtdesc *f)
{
struct visl_ctx *ctx = visl_file_to_ctx(file);
+ u32 index = f->index & ~V4L2_FMTDESC_FLAG_ENUM_ALL;
+ int max_fmts = ctx->coded_format_desc->num_decoded_fmts;
+ const u32 *decoded_fmts = ctx->coded_format_desc->decoded_fmts;
+
+ if (f->index & V4L2_FMTDESC_FLAG_ENUM_ALL) {
+ max_fmts = ARRAY_SIZE(visl_extended_decoded_fmts);
+ decoded_fmts = visl_extended_decoded_fmts;
+ }
+
+ f->index = index;
- if (f->index >= ctx->coded_format_desc->num_decoded_fmts)
+ if (index >= max_fmts)
return -EINVAL;
- f->pixelformat = ctx->coded_format_desc->decoded_fmts[f->index];
+ f->pixelformat = decoded_fmts[index];
return 0;
}
--
2.43.0
^ permalink raw reply [flat|nested] 5+ messages in thread
* [PATCH v7 3/3] media: verisilicon: Use V4L2_FMTDESC_FLAG_ENUM_ALL flag
[not found] <20240826172407.140538-1-benjamin.gaignard@collabora.com>
2024-08-26 17:24 ` [PATCH v7 1/3] media: videodev2: Add flag to unconditionally enumerate pixel formats Benjamin Gaignard
@ 2024-08-26 17:24 ` Benjamin Gaignard
2024-08-26 17:24 ` [PATCH v7 2/3] media: test-drivers: " Benjamin Gaignard
2 siblings, 0 replies; 5+ messages in thread
From: Benjamin Gaignard @ 2024-08-26 17:24 UTC (permalink / raw)
To: mchehab, ezequiel, hverkuil-cisco
Cc: linux-media, linux-kernel, linux-rockchip, kernel, Benjamin Gaignard
By adding support for the V4L2_FMTDESC_FLAG_ENUM_ALL flag into the driver
we allow userspace applications to discover all possible
pixel formats of the hardware block. This way userspace can decide
which decoder to use given the supported pixel formats.
Signed-off-by: Benjamin Gaignard <benjamin.gaignard@collabora.com>
---
.../media/platform/verisilicon/hantro_v4l2.c | 18 +++++++++++++-----
1 file changed, 13 insertions(+), 5 deletions(-)
diff --git a/drivers/media/platform/verisilicon/hantro_v4l2.c b/drivers/media/platform/verisilicon/hantro_v4l2.c
index df6f2536263b..f416c5b36dd0 100644
--- a/drivers/media/platform/verisilicon/hantro_v4l2.c
+++ b/drivers/media/platform/verisilicon/hantro_v4l2.c
@@ -201,7 +201,15 @@ static int vidioc_enum_fmt(struct file *file, void *priv,
struct hantro_ctx *ctx = fh_to_ctx(priv);
const struct hantro_fmt *fmt, *formats;
unsigned int num_fmts, i, j = 0;
- bool skip_mode_none;
+ bool skip_mode_none, enum_all_formats;
+ u32 index = f->index & ~V4L2_FMTDESC_FLAG_ENUM_ALL;
+
+ /*
+ * If the V4L2_FMTDESC_FLAG_ENUM_ALL flag is set, we want to enumerate all
+ * hardware supported pixel formats
+ */
+ enum_all_formats = !!(f->index & V4L2_FMTDESC_FLAG_ENUM_ALL);
+ f->index = index;
/*
* When dealing with an encoder:
@@ -222,9 +230,9 @@ static int vidioc_enum_fmt(struct file *file, void *priv,
if (skip_mode_none == mode_none)
continue;
- if (!hantro_check_depth_match(fmt, ctx->bit_depth))
+ if (!hantro_check_depth_match(fmt, ctx->bit_depth) && !enum_all_formats)
continue;
- if (j == f->index) {
+ if (j == index) {
f->pixelformat = fmt->fourcc;
return 0;
}
@@ -242,9 +250,9 @@ static int vidioc_enum_fmt(struct file *file, void *priv,
for (i = 0; i < num_fmts; i++) {
fmt = &formats[i];
- if (!hantro_check_depth_match(fmt, ctx->bit_depth))
+ if (!hantro_check_depth_match(fmt, ctx->bit_depth) && !enum_all_formats)
continue;
- if (j == f->index) {
+ if (j == index) {
f->pixelformat = fmt->fourcc;
return 0;
}
--
2.43.0
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH v7 1/3] media: videodev2: Add flag to unconditionally enumerate pixel formats
2024-08-26 17:24 ` [PATCH v7 1/3] media: videodev2: Add flag to unconditionally enumerate pixel formats Benjamin Gaignard
@ 2024-10-11 13:29 ` Hans Verkuil
2024-10-14 7:07 ` Benjamin Gaignard
0 siblings, 1 reply; 5+ messages in thread
From: Hans Verkuil @ 2024-10-11 13:29 UTC (permalink / raw)
To: Benjamin Gaignard, mchehab, ezequiel
Cc: linux-media, linux-kernel, linux-rockchip, kernel
Hi Benjamin,
On 26/08/2024 19:24, Benjamin Gaignard wrote:
> When the index is ORed with V4L2_FMTDESC_FLAG_ENUM_ALL the
> driver clears the flag and enumerate all the possible formats,
> ignoring any limitations from the current configuration.
> Drivers which do not support this flag yet always return an EINVAL.
>
> Signed-off-by: Benjamin Gaignard <benjamin.gaignard@collabora.com>
> ---
> change in version 7:
> - Rework documentation about which drivers should use the flag
>
> .../media/v4l/vidioc-enum-fmt.rst | 18 +++++++++++++++++-
> .../media/videodev2.h.rst.exceptions | 1 +
> include/uapi/linux/videodev2.h | 3 +++
> 3 files changed, 21 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..e39c87bcbfc3 100644
> --- a/Documentation/userspace-api/media/v4l/vidioc-enum-fmt.rst
> +++ b/Documentation/userspace-api/media/v4l/vidioc-enum-fmt.rst
> @@ -85,7 +85,17 @@ 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 index is ORed with ``V4L2_FMTDESC_FLAG_ENUM_ALL`` the
> + driver clears the flag and enumerates all the possible formats,
> + ignoring any limitations from the current configuration. Drivers
> + which do not support this flag always return an ``EINVAL``
> + error code.
I would like to add: " without clearing this flag."
> + Formats enumerated when using ``V4L2_FMTDESC_FLAG_ENUM_ALL`` flag
> + shouldn't be used when calling :c:func:`VIDIOC_ENUM_FRAMESIZES`
> + or :c:func:`VIDIOC_ENUM_FRAMEINTERVALS`.
> + ``V4L2_FMTDESC_FLAG_ENUM_ALL`` should only be used by drivers that
> + can return different format list depending on this flag.
> * - __u32
> - ``type``
> - Type of the data stream, set by the application. Only these types
> @@ -234,6 +244,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_FMTDESC_FLAG_ENUM_ALL``
> + - 0x80000000
> + - When the applications ORs ``index`` with ``V4L2_FMTDESC_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,
> + always return ``EINVAL``.
Ditto.
If you agree, then I can make that change myself, no need to post a new version.
Regards,
Hans
>
> Return Value
> ============
> diff --git a/Documentation/userspace-api/media/videodev2.h.rst.exceptions b/Documentation/userspace-api/media/videodev2.h.rst.exceptions
> index bdc628e8c1d6..0a9ea9686c24 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_FMTDESC_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..421a30cb0c51 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_FMTDESC_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
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH v7 1/3] media: videodev2: Add flag to unconditionally enumerate pixel formats
2024-10-11 13:29 ` Hans Verkuil
@ 2024-10-14 7:07 ` Benjamin Gaignard
0 siblings, 0 replies; 5+ messages in thread
From: Benjamin Gaignard @ 2024-10-14 7:07 UTC (permalink / raw)
To: Hans Verkuil, mchehab, ezequiel
Cc: linux-media, linux-kernel, linux-rockchip, kernel
Le 11/10/2024 à 15:29, Hans Verkuil a écrit :
> Hi Benjamin,
>
> On 26/08/2024 19:24, Benjamin Gaignard wrote:
>> When the index is ORed with V4L2_FMTDESC_FLAG_ENUM_ALL the
>> driver clears the flag and enumerate all the possible formats,
>> ignoring any limitations from the current configuration.
>> Drivers which do not support this flag yet always return an EINVAL.
>>
>> Signed-off-by: Benjamin Gaignard <benjamin.gaignard@collabora.com>
>> ---
>> change in version 7:
>> - Rework documentation about which drivers should use the flag
>>
>> .../media/v4l/vidioc-enum-fmt.rst | 18 +++++++++++++++++-
>> .../media/videodev2.h.rst.exceptions | 1 +
>> include/uapi/linux/videodev2.h | 3 +++
>> 3 files changed, 21 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..e39c87bcbfc3 100644
>> --- a/Documentation/userspace-api/media/v4l/vidioc-enum-fmt.rst
>> +++ b/Documentation/userspace-api/media/v4l/vidioc-enum-fmt.rst
>> @@ -85,7 +85,17 @@ 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 index is ORed with ``V4L2_FMTDESC_FLAG_ENUM_ALL`` the
>> + driver clears the flag and enumerates all the possible formats,
>> + ignoring any limitations from the current configuration. Drivers
>> + which do not support this flag always return an ``EINVAL``
>> + error code.
> I would like to add: " without clearing this flag."
>
>> + Formats enumerated when using ``V4L2_FMTDESC_FLAG_ENUM_ALL`` flag
>> + shouldn't be used when calling :c:func:`VIDIOC_ENUM_FRAMESIZES`
>> + or :c:func:`VIDIOC_ENUM_FRAMEINTERVALS`.
>> + ``V4L2_FMTDESC_FLAG_ENUM_ALL`` should only be used by drivers that
>> + can return different format list depending on this flag.
>> * - __u32
>> - ``type``
>> - Type of the data stream, set by the application. Only these types
>> @@ -234,6 +244,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_FMTDESC_FLAG_ENUM_ALL``
>> + - 0x80000000
>> + - When the applications ORs ``index`` with ``V4L2_FMTDESC_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,
>> + always return ``EINVAL``.
> Ditto.
>
> If you agree, then I can make that change myself, no need to post a new version.
Of I agree :-)
Thanks a lot.
Benjamin
>
> Regards,
>
> Hans
>
>>
>> Return Value
>> ============
>> diff --git a/Documentation/userspace-api/media/videodev2.h.rst.exceptions b/Documentation/userspace-api/media/videodev2.h.rst.exceptions
>> index bdc628e8c1d6..0a9ea9686c24 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_FMTDESC_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..421a30cb0c51 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_FMTDESC_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
>
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2024-10-14 7:07 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
[not found] <20240826172407.140538-1-benjamin.gaignard@collabora.com>
2024-08-26 17:24 ` [PATCH v7 1/3] media: videodev2: Add flag to unconditionally enumerate pixel formats Benjamin Gaignard
2024-10-11 13:29 ` Hans Verkuil
2024-10-14 7:07 ` Benjamin Gaignard
2024-08-26 17:24 ` [PATCH v7 3/3] media: verisilicon: Use V4L2_FMTDESC_FLAG_ENUM_ALL flag Benjamin Gaignard
2024-08-26 17:24 ` [PATCH v7 2/3] media: test-drivers: " Benjamin Gaignard
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®