This is an automatic generated email to let you know that the following patch 
were queued at the 
http://git.linuxtv.org/cgit.cgi/v4l-utils.git tree:

Subject: v4l2-ctl-vidcap: Add options to enumerate all pixel formats
Author:  Benjamin Gaignard <benjamin.gaign...@collabora.com>
Date:    Mon Aug 26 17:20:12 2024 +0000

Add 'all' option to the following test tools to use
V4L2_FMTDESC_FLAG_ENUM_ALL if supported by the driver:
- vidcap --list-formats(-ext) options
- meta --list-formats-meta option
- vidout -list-formats-out(-ext) options

Update functions prototype to provide an additional parameter.

Signed-off-by: Benjamin Gaignard <benjamin.gaign...@collabora.com>
Signed-off-by: Hans Verkuil <hverkuil-ci...@xs4all.nl>
[hverkuil: fix typo: specify -> specified]

 utils/common/cv4l-helpers.h         |  5 ++++-
 utils/v4l2-ctl/v4l2-ctl-meta.cpp    | 34 +++++++++++++++++++++++++---------
 utils/v4l2-ctl/v4l2-ctl-overlay.cpp |  2 +-
 utils/v4l2-ctl/v4l2-ctl-sdr.cpp     |  4 ++--
 utils/v4l2-ctl/v4l2-ctl-vidcap.cpp  | 26 ++++++++++++++++++--------
 utils/v4l2-ctl/v4l2-ctl-vidout.cpp  | 27 +++++++++++++++++++--------
 utils/v4l2-ctl/v4l2-ctl.cpp         | 16 ++++++++++------
 utils/v4l2-ctl/v4l2-ctl.h           |  4 ++--
 8 files changed, 81 insertions(+), 37 deletions(-)

---

http://git.linuxtv.org/cgit.cgi/v4l-utils.git/commit/?id=f8ece4bbbbd90d678a3ee8964f2888d4d98b001e
diff --git a/utils/common/cv4l-helpers.h b/utils/common/cv4l-helpers.h
index ec33da78b741..ab9c64b3bdb2 100644
--- a/utils/common/cv4l-helpers.h
+++ b/utils/common/cv4l-helpers.h
@@ -488,7 +488,7 @@ public:
                return cv4l_ioctl(VIDIOC_ENUM_DV_TIMINGS, &timings);
        }
 
-       int enum_fmt(v4l2_fmtdesc &fmt, bool init = false, int index = 0, 
unsigned type = 0, __u32 mbus_code = 0)
+       int enum_fmt(v4l2_fmtdesc &fmt, bool init = false, int index = 0, 
unsigned type = 0, __u32 mbus_code = 0, bool enum_all = false)
        {
                if (init) {
                        memset(&fmt, 0, sizeof(fmt));
@@ -498,6 +498,9 @@ public:
                } else {
                        fmt.index++;
                }
+               if (enum_all)
+                       fmt.index |= V4L2_FMTDESC_FLAG_ENUM_ALL;
+
                return cv4l_ioctl(VIDIOC_ENUM_FMT, &fmt);
        }
 
diff --git a/utils/v4l2-ctl/v4l2-ctl-meta.cpp b/utils/v4l2-ctl/v4l2-ctl-meta.cpp
index 6ad56845a46a..0d0ea660a86b 100644
--- a/utils/v4l2-ctl/v4l2-ctl-meta.cpp
+++ b/utils/v4l2-ctl/v4l2-ctl-meta.cpp
@@ -5,14 +5,19 @@
 static struct v4l2_format vfmt;        /* set_format/get_format */
 static unsigned mbus_code;
 static unsigned mbus_code_out;
+static bool enum_all;
+static bool enum_all_out;
 
 void meta_usage()
 {
        printf("\nMetadata Formats options:\n"
-              "  --list-formats-meta [<mbus_code>] display supported metadata 
capture formats.\n"
+              "  --list-formats-meta [<mbus_code>|all] display supported 
metadata capture formats.\n"
               "                     <mbus_code> is an optional media bus code, 
if the device has\n"
               "                     capability V4L2_CAP_IO_MC then only 
formats that support this\n"
-              "                     media bus code are listed 
[VIDIOC_ENUM_FMT]\n"
+              "                     media bus code are listed.\n"
+              "                     When 'all' is specified it enumerates all 
pixel formats if\n"
+              "                     V4L2_FMTDESC_FLAG_ENUM_ALL flag is 
supported by the driver.\n"
+              "                     [VIDIOC_ENUM_FMT]\n"
               "  --get-fmt-meta     query the metadata capture format 
[VIDIOC_G_FMT]\n"
               "  --set-fmt-meta <f> set the metadata capture format 
[VIDIOC_S_FMT]\n"
               "                     parameter is either the format index as 
reported by\n"
@@ -23,7 +28,10 @@ void meta_usage()
               "  --list-formats-meta-out [<mbus_code>] display supported 
metadata output formats.\n"
               "                     <mbus_code> is an optional media bus code, 
if the device has\n"
               "                     capability V4L2_CAP_IO_MC then only 
formats that support this\n"
-              "                     media bus code are listed 
[VIDIOC_ENUM_FMT]\n"
+              "                     media bus code are listed.\n"
+              "                     When 'all' is specified it enumerates all 
pixel formats if\n"
+              "                     V4L2_FMTDESC_FLAG_ENUM_ALL flag is 
supported by the driver.\n"
+              "                     [VIDIOC_ENUM_FMT]\n"
               "  --get-fmt-meta-out query the metadata output format 
[VIDIOC_G_FMT]\n"
               "  --set-fmt-meta-out <f> set the metadata output format 
[VIDIOC_S_FMT]\n"
               "                     parameter is either the format index as 
reported by\n"
@@ -52,12 +60,20 @@ void meta_cmd(int ch, char *optarg)
                }
                break;
        case OptListMetaFormats:
-               if (optarg)
-                       mbus_code = strtoul(optarg, nullptr, 0);
+               if (optarg) {
+                       if (strstr(optarg , "all"))
+                               enum_all = true;
+                       else
+                               mbus_code = strtoul(optarg, nullptr, 0);
+               }
                break;
        case OptListMetaOutFormats:
-               if (optarg)
-                       mbus_code_out = strtoul(optarg, nullptr, 0);
+               if (optarg) {
+                       if (strstr(optarg , "all"))
+                               enum_all_out = true;
+                       else
+                               mbus_code_out = strtoul(optarg, nullptr, 0);
+               }
                break;
        }
 }
@@ -121,12 +137,12 @@ void meta_list(cv4l_fd &fd)
 {
        if (options[OptListMetaFormats]) {
                printf("ioctl: VIDIOC_ENUM_FMT\n");
-               print_video_formats(fd, V4L2_BUF_TYPE_META_CAPTURE, mbus_code);
+               print_video_formats(fd, V4L2_BUF_TYPE_META_CAPTURE, mbus_code, 
enum_all);
        }
 
        if (options[OptListMetaOutFormats]) {
                printf("ioctl: VIDIOC_ENUM_FMT\n");
-               print_video_formats(fd, V4L2_BUF_TYPE_META_OUTPUT, 
mbus_code_out);
+               print_video_formats(fd, V4L2_BUF_TYPE_META_OUTPUT, 
mbus_code_out, enum_all_out);
        }
 }
 
diff --git a/utils/v4l2-ctl/v4l2-ctl-overlay.cpp 
b/utils/v4l2-ctl/v4l2-ctl-overlay.cpp
index 5493222dd76f..797b3f34f4dd 100644
--- a/utils/v4l2-ctl/v4l2-ctl-overlay.cpp
+++ b/utils/v4l2-ctl/v4l2-ctl-overlay.cpp
@@ -522,7 +522,7 @@ void overlay_list(cv4l_fd &fd)
 {
        if (options[OptListOverlayFormats]) {
                printf("ioctl: VIDIOC_ENUM_FMT\n");
-               print_video_formats(fd, V4L2_BUF_TYPE_VIDEO_OVERLAY, 0);
+               print_video_formats(fd, V4L2_BUF_TYPE_VIDEO_OVERLAY, 0, false);
        }
        if (options[OptFindFb])
                find_fb(fd.g_fd());
diff --git a/utils/v4l2-ctl/v4l2-ctl-sdr.cpp b/utils/v4l2-ctl/v4l2-ctl-sdr.cpp
index 4168eeb1b8b7..6f4a012a6fcd 100644
--- a/utils/v4l2-ctl/v4l2-ctl-sdr.cpp
+++ b/utils/v4l2-ctl/v4l2-ctl-sdr.cpp
@@ -122,10 +122,10 @@ void sdr_list(cv4l_fd &fd)
 {
        if (options[OptListSdrFormats]) {
                printf("ioctl: VIDIOC_ENUM_FMT\n");
-               print_video_formats(fd, V4L2_BUF_TYPE_SDR_CAPTURE, 0);
+               print_video_formats(fd, V4L2_BUF_TYPE_SDR_CAPTURE, 0, false);
        }
        if (options[OptListSdrOutFormats]) {
                printf("ioctl: VIDIOC_ENUM_FMT\n");
-               print_video_formats(fd, V4L2_BUF_TYPE_SDR_OUTPUT, 0);
+               print_video_formats(fd, V4L2_BUF_TYPE_SDR_OUTPUT, 0, false);
        }
 }
diff --git a/utils/v4l2-ctl/v4l2-ctl-vidcap.cpp 
b/utils/v4l2-ctl/v4l2-ctl-vidcap.cpp
index d593b3b4f8e4..498362217149 100644
--- a/utils/v4l2-ctl/v4l2-ctl-vidcap.cpp
+++ b/utils/v4l2-ctl/v4l2-ctl-vidcap.cpp
@@ -12,20 +12,26 @@ static __u32 ycbcr, quantization, xfer_func, colorspace;
 static __u32 bytesperline[VIDEO_MAX_PLANES];
 static __u32 sizeimage[VIDEO_MAX_PLANES];
 static unsigned mbus_code;
+static bool enum_all;
 
 void vidcap_usage()
 {
        printf("\nVideo Capture Formats options:\n"
-              "  --list-formats [<mbus_code>]\n"
+              "  --list-formats [<mbus_code>|all]\n"
               "                     display supported video formats. 
<mbus_code> is an optional\n"
               "                     media bus code, if the device has 
capability V4L2_CAP_IO_MC\n"
-              "                     then only formats that support this media 
bus code are listed\n"
+              "                     then only formats that support this media 
bus code are listed.\n"
+              "                     When 'all' is specified it enumerates all 
pixel formats if\n"
+              "                     V4L2_FMTDESC_FLAG_ENUM_ALL flag is 
supported by the driver.\n"
               "                     [VIDIOC_ENUM_FMT]\n"
-              "  --list-formats-ext [<mbus_code>]\n"
+              "  --list-formats-ext [<mbus_code>|all]\n"
               "                     display supported video formats including 
frame sizes and intervals\n"
               "                     <mbus_code> is an optional media bus code, 
if the device has\n"
               "                     capability V4L2_CAP_IO_MC then only 
formats that support this\n"
-              "                     media bus code are listed 
[VIDIOC_ENUM_FMT]\n"
+              "                     media bus code are listed.\n"
+              "                     When 'all' is specified it enumerates all 
pixel formats if\n"
+              "                     V4L2_FMTDESC_FLAG_ENUM_ALL flag is 
supported by the driver.\n"
+              "                     [VIDIOC_ENUM_FMT]\n"
               "  --list-framesizes <f>\n"
               "                     list supported framesizes for pixelformat 
<f>\n"
               "                     [VIDIOC_ENUM_FRAMESIZES]\n"
@@ -113,8 +119,12 @@ void vidcap_cmd(int ch, char *optarg)
                break;
        case OptListFormats:
        case OptListFormatsExt:
-               if (optarg)
-                       mbus_code = strtoul(optarg, nullptr, 0);
+               if (optarg) {
+                       if (strstr(optarg , "all"))
+                               enum_all = true;
+                       else
+                               mbus_code = strtoul(optarg, nullptr, 0);
+               }
                break;
        case OptListFrameSizes:
                be_pixfmt = strlen(optarg) == 7 && !memcmp(optarg + 4, "-BE", 
3);
@@ -331,12 +341,12 @@ void vidcap_list(cv4l_fd &fd)
 {
        if (options[OptListFormats]) {
                printf("ioctl: VIDIOC_ENUM_FMT\n");
-               print_video_formats(fd, vidcap_buftype, mbus_code);
+               print_video_formats(fd, vidcap_buftype, mbus_code, enum_all);
        }
 
        if (options[OptListFormatsExt]) {
                printf("ioctl: VIDIOC_ENUM_FMT\n");
-               print_video_formats_ext(fd, vidcap_buftype, mbus_code);
+               print_video_formats_ext(fd, vidcap_buftype, mbus_code, 
enum_all);
        }
 
        if (options[OptListFields]) {
diff --git a/utils/v4l2-ctl/v4l2-ctl-vidout.cpp 
b/utils/v4l2-ctl/v4l2-ctl-vidout.cpp
index 0d06f7478529..bbdbfc451614 100644
--- a/utils/v4l2-ctl/v4l2-ctl-vidout.cpp
+++ b/utils/v4l2-ctl/v4l2-ctl-vidout.cpp
@@ -5,18 +5,25 @@ static __u32 width, height, pixfmt, field, colorspace, 
xfer_func, ycbcr, quantiz
 static __u32 bytesperline[VIDEO_MAX_PLANES];
 static __u32 sizeimage[VIDEO_MAX_PLANES];
 static unsigned mbus_code_out;
+static bool enum_all;
 
 void vidout_usage()
 {
        printf("\nVideo Output Formats options:\n"
-              "  --list-formats-out [<mbus_code>] display supported video 
output formats.\n"
+              "  --list-formats-out [<mbus_code>|all] display supported video 
output formats.\n"
               "                     <mbus_code> is an optional media bus code, 
if the device has\n"
               "                     capability V4L2_CAP_IO_MC then only 
formats that support this\n"
-              "                     media bus code are listed 
[VIDIOC_ENUM_FMT]\n"
-              "  --list-formats-out-ext [<mbus_code>] display supported video 
output formats including\n"
+              "                     media bus code are listed.\n"
+              "                     When 'all' is specified it enumerates all 
pixel formats if\n"
+              "                     V4L2_FMTDESC_FLAG_ENUM_ALL flag is 
supported by the driver.\n"
+              "                     [VIDIOC_ENUM_FMT]\n"
+              "  --list-formats-out-ext [<mbus_code>|all] display supported 
video output formats including\n"
               "                     frame sizes and intervals. <mbus_code> is 
an optional media bus code,\n"
               "                     if the device has capability 
V4L2_CAP_IO_MC then only formats that\n"
-              "                     support this media bus code are listed 
[VIDIOC_ENUM_FMT]\n"
+              "                     support this media bus code are listed\n"
+              "                     When 'all' is specified it enumerates all 
pixel formats if\n"
+              "                     V4L2_FMTDESC_FLAG_ENUM_ALL flag is 
supported by the driver.\n"
+              "                     [VIDIOC_ENUM_FMT]\n"
               "  --list-fields-out  list supported fields for the current 
output format\n"
               "  -X, --get-fmt-video-out\n"
               "                     query the video output format 
[VIDIOC_G_FMT]\n"
@@ -93,8 +100,12 @@ void vidout_cmd(int ch, char *optarg)
                break;
        case OptListOutFormats:
        case OptListOutFormatsExt:
-               if (optarg)
-                       mbus_code_out = strtoul(optarg, nullptr, 0);
+               if (optarg) {
+                       if (strstr(optarg , "all"))
+                               enum_all = true;
+                       else
+                               mbus_code_out = strtoul(optarg, nullptr, 0);
+               }
                break;
        }
 }
@@ -226,12 +237,12 @@ void vidout_list(cv4l_fd &fd)
 {
        if (options[OptListOutFormats]) {
                printf("ioctl: VIDIOC_ENUM_FMT\n");
-               print_video_formats(fd, vidout_buftype, mbus_code_out);
+               print_video_formats(fd, vidout_buftype, mbus_code_out, 
enum_all);
        }
 
        if (options[OptListOutFormatsExt]) {
                printf("ioctl: VIDIOC_ENUM_FMT\n");
-               print_video_formats_ext(fd, vidout_buftype, mbus_code_out);
+               print_video_formats_ext(fd, vidout_buftype, mbus_code_out, 
enum_all);
        }
 
        if (options[OptListOutFields]) {
diff --git a/utils/v4l2-ctl/v4l2-ctl.cpp b/utils/v4l2-ctl/v4l2-ctl.cpp
index a64fa514b6e0..513ac8b728ff 100644
--- a/utils/v4l2-ctl/v4l2-ctl.cpp
+++ b/utils/v4l2-ctl/v4l2-ctl.cpp
@@ -602,7 +602,7 @@ void print_frmival(const struct v4l2_frmivalenum &frmival, 
const char *prefix)
        }
 }
 
-void print_video_formats(cv4l_fd &fd, __u32 type, unsigned int mbus_code)
+void print_video_formats(cv4l_fd &fd, __u32 type, unsigned int mbus_code, bool 
enum_all)
 {
        cv4l_disable_trace dt(fd);
        struct v4l2_fmtdesc fmt = {};
@@ -611,7 +611,7 @@ void print_video_formats(cv4l_fd &fd, __u32 type, unsigned 
int mbus_code)
                mbus_code = 0;
 
        printf("\tType: %s\n\n", buftype2s(type).c_str());
-       if (fd.enum_fmt(fmt, true, 0, type, mbus_code))
+       if (fd.enum_fmt(fmt, true, 0, type, mbus_code, enum_all))
                return;
        do {
                printf("\t[%d]: '%s' (%s", fmt.index, 
fcc2s(fmt.pixelformat).c_str(),
@@ -623,10 +623,10 @@ void print_video_formats(cv4l_fd &fd, __u32 type, 
unsigned int mbus_code)
                        printf(", %s", fmtdesc2s(fmt.flags, is_hsv).c_str());
                }
                printf(")\n");
-       } while (!fd.enum_fmt(fmt));
+       } while (!fd.enum_fmt(fmt, false, 0, type, mbus_code, enum_all));
 }
 
-void print_video_formats_ext(cv4l_fd &fd, __u32 type, unsigned int mbus_code)
+void print_video_formats_ext(cv4l_fd &fd, __u32 type, unsigned int mbus_code, 
bool enum_all)
 {
        cv4l_disable_trace dt(fd);
        struct v4l2_fmtdesc fmt = {};
@@ -637,7 +637,7 @@ void print_video_formats_ext(cv4l_fd &fd, __u32 type, 
unsigned int mbus_code)
                mbus_code = 0;
 
        printf("\tType: %s\n\n", buftype2s(type).c_str());
-       if (fd.enum_fmt(fmt, true, 0, type, mbus_code))
+       if (fd.enum_fmt(fmt, true, 0, type, mbus_code, enum_all))
                return;
        do {
                printf("\t[%d]: '%s' (%s", fmt.index, 
fcc2s(fmt.pixelformat).c_str(),
@@ -649,6 +649,10 @@ void print_video_formats_ext(cv4l_fd &fd, __u32 type, 
unsigned int mbus_code)
                        printf(", %s", fmtdesc2s(fmt.flags, is_hsv).c_str());
                }
                printf(")\n");
+
+               if (enum_all)
+                       continue;
+
                if (fd.enum_framesizes(frmsize, fmt.pixelformat))
                        continue;
                do {
@@ -664,7 +668,7 @@ void print_video_formats_ext(cv4l_fd &fd, __u32 type, 
unsigned int mbus_code)
                                print_frmival(frmival, "\t\t");
                        } while (!fd.enum_frameintervals(frmival));
                } while (!fd.enum_framesizes(frmsize));
-       } while (!fd.enum_fmt(fmt));
+       } while (!fd.enum_fmt(fmt,false, 0, type, mbus_code, enum_all));
 }
 
 int parse_subopt(char **subs, const char * const *subopts, char **value)
diff --git a/utils/v4l2-ctl/v4l2-ctl.h b/utils/v4l2-ctl/v4l2-ctl.h
index a1911e809a30..d8c25da5cda7 100644
--- a/utils/v4l2-ctl/v4l2-ctl.h
+++ b/utils/v4l2-ctl/v4l2-ctl.h
@@ -315,8 +315,8 @@ bool valid_pixel_format(int fd, __u32 pixelformat, bool 
output, bool mplane);
 void print_frmsize(const struct v4l2_frmsizeenum &frmsize, const char *prefix);
 void print_frmival(const struct v4l2_frmivalenum &frmival, const char *prefix);
 void printfmt(int fd, const struct v4l2_format &vfmt);
-void print_video_formats(cv4l_fd &fd, __u32 type, unsigned int mbus_code);
-void print_video_formats_ext(cv4l_fd &fd, __u32 type, unsigned int mbus_code);
+void print_video_formats(cv4l_fd &fd, __u32 type, unsigned int mbus_code, bool 
enum_all);
+void print_video_formats_ext(cv4l_fd &fd, __u32 type, unsigned int mbus_code, 
bool enum_all);
 
 static inline bool subscribe_event(cv4l_fd &fd, __u32 type)
 {

Reply via email to