Skip to contentSkip to conversation

Add tests compliance tests about V4L2_FMTDESC_FLAG_ENUM_ALL flag usage

PATCH Superseded Benjamin Gaignard 2 participants 4 messages Jul 31, 2024 – Aug 7, 2024 Media (V4L/DVB)

v3 of 4 Superseded Latest is v4 →

lore
Share & tools
lore
#0 lore raw

v3 cover Add tests compliance tests about V4L2_FMTDESC_FLAG_ENUM_ALL flag usage

V4L2_FMTDESC_FLAG_ENUM_ALL flag goal is to enumerate all possible pixel format while ignoring the current configuration. The series add tests for v4l2-compliance and v4l2-ctl tools.

v4l2-compliance will check is the flag is supported by drivers and verify if the enumerated list is an upperset of VIDIO_ENUM_FMT called without the flag.

Add 'all' supoption to vidcap --list-formats(-ext) options to use V4L2_FMTDESC_FLAG_ENUM_ALL if supported by the driver.

As example, Verisilicon driver support the flag usage and give these results:
./v4l2-ctl --list-formats -d 1
ioctl: VIDIOC_ENUM_FMT

	Type: Video Capture Multiplanar

	[0]: 'VT12' (Y/UV 4:2:0 (4x4 Linear))
	[1]: 'NV12' (Y/UV 4:2:0)

./v4l2-ctl --list-formats all -d 1
ioctl: VIDIOC_ENUM_FMT

	Type: Video Capture Multiplanar

	[0]: 'VT12' (Y/UV 4:2:0 (4x4 Linear))
	[1]: 'T010' (10-bit Y/UV 4:2:0 (4x4 Linear))
	[2]: 'NV12' (Y/UV 4:2:0)
	[3]: 'P010' (10-bit Y/UV 4:2:0)

so userspace can discover that it support 10-bit formats on capture queue.

Benjamin Gaignard (2):
v4l2-compliance: Add test for V4L2_FMTDESC_FLAG_ENUM_ALL flag
v4l2-ctl-vidcap: Add option to enumerate all pixel formats

 include/linux/videodev2.h                   |  3 ++
 utils/common/cv4l-helpers.h                 |  5 ++-
 utils/v4l2-compliance/v4l2-test-formats.cpp | 35 +++++++++++++++++++++
 utils/v4l2-ctl/v4l2-ctl-meta.cpp            |  4 +--
 utils/v4l2-ctl/v4l2-ctl-overlay.cpp         |  2 +-
 utils/v4l2-ctl/v4l2-ctl-sdr.cpp             |  4 +--
 utils/v4l2-ctl/v4l2-ctl-vidcap.cpp          | 25 +++++++++++----
 utils/v4l2-ctl/v4l2-ctl-vidout.cpp          |  4 +--
 utils/v4l2-ctl/v4l2-ctl.cpp                 | 16 ++++++----
 utils/v4l2-ctl/v4l2-ctl.h                   |  4 +--
 10 files changed, 80 insertions(+), 22 deletions(-)
Signature · 1 line
2.43.0
#1 lore raw

PATCH v3 1/2 v4l2-compliance: Add test for V4L2_FMTDESC_FLAG_ENUM_ALL flag

If V4L2_FMTDESC_FLAG_ENUM_ALL flag is supported, test if all pixel formats list with VIDIOC_ENUM_FMT without the flag been set is a subset of the list created with the flag.
Also Test that the flag is cleared of calling VIDIOC_ENUM_FMT.

---
changes in version 3:
- Fix the remarks done by Hans

 include/linux/videodev2.h                   |  3 ++
 utils/v4l2-compliance/v4l2-test-formats.cpp | 35 +++++++++++++++++++++
 2 files changed, 38 insertions(+)
include/linux/videodev2.h +3 -0
index f18a40d4..c166bb35 100644
@@ -864,6 +864,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
utils/v4l2-compliance/v4l2-test-formats.cpp +35 -0
index fc16ad39..bac28cba 100644
@@ -224,6 +224,7 @@ static int testEnumFrameSizes(struct node *node, __u32 pixfmt)
 static int testEnumFormatsType(struct node *node, unsigned type)
 {
 	pixfmt_map &map = node->buftype_pixfmts[type];
+	pixfmt_map enum_all;
 	struct v4l2_fmtdesc fmtdesc;
 	unsigned f = 0;
 	int ret;
@@ -318,6 +319,40 @@ static int testEnumFormatsType(struct node *node, unsigned type)
 		map[fmtdesc.pixelformat] = fmtdesc.flags;
 	}
 	info("found %d formats for buftype %d\n", f, type);
+
+	/* Test V4L2_FMTDESC_FLAG_ENUM_ALL if supported */
+	f = 0;
+	for (;;) {
+		memset(&fmtdesc, 0xff, sizeof(fmtdesc));
+		fmtdesc.type = type;
+		fmtdesc.index = f | V4L2_FMTDESC_FLAG_ENUM_ALL;
+		fmtdesc.mbus_code = 0;
+
+		ret = doioctl(node, VIDIOC_ENUM_FMT, &fmtdesc);
+		if (f == 0 && ret == EINVAL)
+			return 0;
+		if (ret == EINVAL)
+			break;
+		if (ret)
+			return fail("expected EINVAL, but got %d when enumerating buftype %d\n", ret, type);
+		if (fmtdesc.index != f)
+			return fail("V4L2_FMTDESC_FLAG_ENUM_ALL hasn't been cleared from fmtdesc.index 0x%x f 0x%x\n", fmtdesc.index, f);
+		f++;
+		if (type == V4L2_BUF_TYPE_PRIVATE)
+			continue;
+		assert(type <= V4L2_BUF_TYPE_LAST);
+		if (enum_all.find(fmtdesc.pixelformat) != enum_all.end())
+			return fail("duplicate format %08x (%s)\n",
+				    fmtdesc.pixelformat, fcc2s(fmtdesc.pixelformat).c_str());
+		enum_all[fmtdesc.pixelformat] = fmtdesc.flags;
+	}
+	info("found %d formats for buftype %d (with V4L2_FMTDESC_FLAG_ENUM_ALL)\n", f, type);
+
+	/* if V4L2_FMTDESC_FLAG_ENUM_ALL is supported, verify that the list is a subset of VIDIOC_ENUM_FMT list */
+	for (auto it = map.begin(); it != map.end(); it++)
+		if (enum_all.find(it->first) == enum_all.end())
+			return fail("V4L2_FMTDESC_FLAG_ENUM_ALL failed to enumerate format %08x (%s)\n", it->first, fcc2s(it->first).c_str());
+
 	return 0;
 }
 
Signature · 1 line
2.43.0
#2 lore raw

PATCH v3 2/2 v4l2-ctl-vidcap: Add option to enumerate all pixel formats

In reply to Benjamin Gaignard

Add 'all' option to vidcap --list-formats(-ext) option to use V4L2_FMTDESC_FLAG_ENUM_ALL if supported by the driver. Update functions prototype to provide an additional parameter.

---
changes in version 3:
- Add 'all' suboption to --list-formats(-ext) options

 utils/common/cv4l-helpers.h         |  5 ++++-
 utils/v4l2-ctl/v4l2-ctl-meta.cpp    |  4 ++--
 utils/v4l2-ctl/v4l2-ctl-overlay.cpp |  2 +-
 utils/v4l2-ctl/v4l2-ctl-sdr.cpp     |  4 ++--
 utils/v4l2-ctl/v4l2-ctl-vidcap.cpp  | 25 +++++++++++++++++++------
 utils/v4l2-ctl/v4l2-ctl-vidout.cpp  |  4 ++--
 utils/v4l2-ctl/v4l2-ctl.cpp         | 16 ++++++++++------
 utils/v4l2-ctl/v4l2-ctl.h           |  4 ++--
 8 files changed, 42 insertions(+), 22 deletions(-)
utils/common/cv4l-helpers.h +4 -1
index ec33da78..ab9c64b3 100644
@@ -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);
 	}
 
utils/v4l2-ctl/v4l2-ctl-meta.cpp +2 -2
index 6ad56845..a7faf600 100644
@@ -121,12 +121,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, false);
 	}
 
 	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, false);
 	}
 }
 
utils/v4l2-ctl/v4l2-ctl-overlay.cpp +1 -1
index 5493222d..797b3f34 100644
@@ -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());
utils/v4l2-ctl/v4l2-ctl-sdr.cpp +2 -2
index 4168eeb1..6f4a012a 100644
@@ -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);
 	}
 }
utils/v4l2-ctl/v4l2-ctl-vidcap.cpp +19 -6
index d593b3b4..63d2b1c7 100644
@@ -12,20 +12,25 @@ 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"
 	       "		     [VIDIOC_ENUM_FMT]\n"
-	       "  --list-formats-ext [<mbus_code>]\n"
+	       "		     when 'all' is specify it enumerates all pixel formats if\n"
+	       "		     V4L2_FMTDESC_FLAG_ENUM_ALL flag is supported by the driver\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"
+	       "		     when 'all' is specify it enumerates all pixel formats if\n"
+	       "		     V4L2_FMTDESC_FLAG_ENUM_ALL flag is supported by the driver\n"
 	       "  --list-framesizes <f>\n"
 	       "                     list supported framesizes for pixelformat <f>\n"
 	       "                     [VIDIOC_ENUM_FRAMESIZES]\n"
@@ -113,8 +118,16 @@ void vidcap_cmd(int ch, char *optarg)
 		break;
 	case OptListFormats:
 	case OptListFormatsExt:
-		if (optarg)
-			mbus_code = strtoul(optarg, nullptr, 0);
+		if (optarg) {
+			char *all;
+			unsigned code = strtoul(optarg, nullptr, 0);
+			if (!errno)
+				mbus_code = code;
+
+			all = strstr(optarg , "all");
+			if (all)
+				enum_all = true;
+		}
 		break;
 	case OptListFrameSizes:
 		be_pixfmt = strlen(optarg) == 7 && !memcmp(optarg + 4, "-BE", 3);
@@ -331,12 +344,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]) {
utils/v4l2-ctl/v4l2-ctl-vidout.cpp +2 -2
index 0d06f747..59acddcc 100644
@@ -226,12 +226,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, false);
 	}
 
 	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, false);
 	}
 
 	if (options[OptListOutFields]) {
utils/v4l2-ctl/v4l2-ctl.cpp +10 -6
index a64fa514..513ac8b7 100644
@@ -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)
utils/v4l2-ctl/v4l2-ctl.h +2 -2
index a1911e80..d8c25da5 100644
@@ -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)
 {
Signature · 1 line
2.43.0
#3 lore raw

Re: [PATCH v3 2/2] v4l2-ctl-vidcap: Add option to enumerate all pixel formats

Quoted 96 lines · Benjamin Gaignard

Add 'all' option to vidcap --list-formats(-ext) option to use V4L2_FMTDESC_FLAG_ENUM_ALL if supported by the driver. Update functions prototype to provide an additional parameter.

---
changes in version 3:
- Add 'all' suboption to --list-formats(-ext) options

 utils/common/cv4l-helpers.h         |  5 ++++-
 utils/v4l2-ctl/v4l2-ctl-meta.cpp    |  4 ++--
 utils/v4l2-ctl/v4l2-ctl-overlay.cpp |  2 +-
 utils/v4l2-ctl/v4l2-ctl-sdr.cpp     |  4 ++--
 utils/v4l2-ctl/v4l2-ctl-vidcap.cpp  | 25 +++++++++++++++++++------
 utils/v4l2-ctl/v4l2-ctl-vidout.cpp  |  4 ++--
 utils/v4l2-ctl/v4l2-ctl.cpp         | 16 ++++++++++------
 utils/v4l2-ctl/v4l2-ctl.h           |  4 ++--
 8 files changed, 42 insertions(+), 22 deletions(-)
utils/common/cv4l-helpers.h +4 -1
index ec33da78..ab9c64b3 100644
@@ -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);
 	}
 
utils/v4l2-ctl/v4l2-ctl-meta.cpp +2 -2
index 6ad56845..a7faf600 100644
@@ -121,12 +121,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, false);
 	}
 
 	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, false);
 	}
 }
 
utils/v4l2-ctl/v4l2-ctl-overlay.cpp +1 -1
index 5493222d..797b3f34 100644
@@ -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());
utils/v4l2-ctl/v4l2-ctl-sdr.cpp +2 -2
index 4168eeb1..6f4a012a 100644
@@ -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);
 	}
 }
utils/v4l2-ctl/v4l2-ctl-vidcap.cpp +0 -0
index d593b3b4..63d2b1c7 100644

utils/v4l2-ctl/v4l2-ctl-vidcap.cpp static __u32 ycbcr, quantization, xfer_func, colorspace; · line 20

Quoted 10 lines
utils/v4l2-ctl/v4l2-ctl-vidcap.cpp +2 -1
@@ -12,20 +12,25 @@ 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"

I think this should be: [<mbus_code>|all]
since combining the two makes no sense.

utils/v4l2-ctl/v4l2-ctl-vidcap.cpp static __u32 ycbcr, quantization, xfer_func, colorspace; · line 26

Quoted 7 lines
utils/v4l2-ctl/v4l2-ctl-vidcap.cpp +2 -1
 	       "		     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"
 	       "		     [VIDIOC_ENUM_FMT]\n"
-	       "  --list-formats-ext [<mbus_code>]\n"
+	       "		     when 'all' is specify it enumerates all pixel formats if\n"
+	       "		     V4L2_FMTDESC_FLAG_ENUM_ALL flag is supported by the driver\n"

This two lines should go before the "[VIDIOC_ENUM_FMT]" line.

utils/v4l2-ctl/v4l2-ctl-vidcap.cpp static __u32 ycbcr, quantization, xfer_func, colorspace; · line 33

Quoted 7 lines
utils/v4l2-ctl/v4l2-ctl-vidcap.cpp +3 -0
+	       "  --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"
+	       "		     when 'all' is specify it enumerates all pixel formats if\n"
+	       "		     V4L2_FMTDESC_FLAG_ENUM_ALL flag is supported by the driver\n"

Ditto. I.e., the help text ends with [VIDIOC_ENUM_FMT] instead of that being in the middle.

utils/v4l2-ctl/v4l2-ctl-vidcap.cpp void vidcap_cmd(int ch, char *optarg) · line 122

Quoted 11 lines
utils/v4l2-ctl/v4l2-ctl-vidcap.cpp +2 -2
 	       "  --list-framesizes <f>\n"
 	       "                     list supported framesizes for pixelformat <f>\n"
 	       "                     [VIDIOC_ENUM_FRAMESIZES]\n"
@@ -113,8 +118,16 @@ void vidcap_cmd(int ch, char *optarg)
 		break;
 	case OptListFormats:
 	case OptListFormatsExt:
-		if (optarg)
-			mbus_code = strtoul(optarg, nullptr, 0);
+		if (optarg) {
+			char *all;

You need to set errno to 0 first, since (according to man strtoul):
"This function does not modify errno on success."

utils/v4l2-ctl/v4l2-ctl-vidcap.cpp void vidcap_cmd(int ch, char *optarg) · line 129

Quoted 7 lines
utils/v4l2-ctl/v4l2-ctl-vidcap.cpp +7 -0
+			unsigned code = strtoul(optarg, nullptr, 0);
+			if (!errno)
+				mbus_code = code;
+
+			all = strstr(optarg , "all");
+			if (all)
+				enum_all = true;

I think this can be written as:

			if (strstr(optarg , "all"))
				enum_all = true;
			else
				mbus_code = strtoul(optarg, nullptr, 0);

Much simpler. This assumes that 'all' and mbus_code are mutually exclusive, which IMHO they are.

Quoted 26 lines
utils/v4l2-ctl/v4l2-ctl-vidcap.cpp +3 -2
+		}
 		break;
 	case OptListFrameSizes:
 		be_pixfmt = strlen(optarg) == 7 && !memcmp(optarg + 4, "-BE", 3);
@@ -331,12 +344,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]) {
utils/v4l2-ctl/v4l2-ctl-vidout.cpp +0 -0
index 0d06f747..59acddcc 100644
@@ -226,12 +226,12 @@ void vidout_list(cv4l_fd &fd)
 {
 	if (options[OptListOutFormats]) {

utils/v4l2-ctl/v4l2-ctl-vidout.cpp void vidout_list(cv4l_fd &fd) · line 235

Quoted 10 lines
utils/v4l2-ctl/v4l2-ctl-vidout.cpp +2 -2
 		printf("ioctl: VIDIOC_ENUM_FMT\n");
-		print_video_formats(fd, vidout_buftype, mbus_code_out);
+		print_video_formats(fd, vidout_buftype, mbus_code_out, false);
 	}
 
 	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, false);
 	}

v4l2-ctl-vidout definitely should support the new flag as well. And I think v4l2-ctl-meta.cpp as well.

All of those support the mbus_code as well, so it makes sense to add the new flag there too.

I can't imagine it being needed for vbi or sdr formats, so it's OK that we don't support it for those types.

Regards,

Hans

Quoted 81 lines
utils/v4l2-ctl/v4l2-ctl-vidout.cpp +0 -0
 	if (options[OptListOutFields]) {
utils/v4l2-ctl/v4l2-ctl.cpp +10 -6
index a64fa514..513ac8b7 100644
@@ -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)
utils/v4l2-ctl/v4l2-ctl.h +2 -2
index a1911e80..d8c25da5 100644
@@ -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)
 {