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-sdr: simplify command handling
Author:  Hans Verkuil <[email protected]>
Date:    Sat Aug 22 16:18:50 2026 +0200

SDR format handling can be simplified, making the code easier to
understand.

Signed-off-by: Hans Verkuil <[email protected]>
Assisted-by: Claude-Code:claude-opus-5

 utils/v4l2-ctl/v4l2-ctl-sdr.cpp | 88 +++++++++++++++++------------------------
 1 file changed, 36 insertions(+), 52 deletions(-)

---

http://git.linuxtv.org/cgit.cgi/v4l-utils.git/commit/?id=1586d94c1efe98bb4dd9299a7c7a02ad26449a41
diff --git a/utils/v4l2-ctl/v4l2-ctl-sdr.cpp b/utils/v4l2-ctl/v4l2-ctl-sdr.cpp
index 4703d5e88af6..35e7885e188e 100644
--- a/utils/v4l2-ctl/v4l2-ctl-sdr.cpp
+++ b/utils/v4l2-ctl/v4l2-ctl-sdr.cpp
@@ -47,75 +47,59 @@ void sdr_cmd(int ch, char *optarg)
        }
 }
 
-void sdr_set(cv4l_fd &_fd)
+static void __sdr_set(cv4l_fd &_fd, bool set, bool _try, __u32 type)
 {
+       struct v4l2_format in_vfmt;
        int fd = _fd.g_fd();
        int ret;
 
-       if (options[OptSetSdrFormat] || options[OptTrySdrFormat]) {
-               struct v4l2_format in_vfmt;
-
-               in_vfmt.type = V4L2_BUF_TYPE_SDR_CAPTURE;
-               in_vfmt.fmt.sdr.pixelformat = vfmt.fmt.sdr.pixelformat;
+       if (!set && !_try)
+               return;
 
-               if (in_vfmt.fmt.sdr.pixelformat < 256) {
-                       struct v4l2_fmtdesc fmt = {};
+       in_vfmt.type = type;
+       in_vfmt.fmt.sdr.pixelformat = vfmt.fmt.sdr.pixelformat;
 
-                       fmt.index = in_vfmt.fmt.sdr.pixelformat;
-                       fmt.type = V4L2_BUF_TYPE_SDR_CAPTURE;
+       if (in_vfmt.fmt.sdr.pixelformat < 256) {
+               struct v4l2_fmtdesc fmt = {};
 
-                       if (doioctl(fd, VIDIOC_ENUM_FMT, &fmt))
-                               fmt.pixelformat = 0;
+               fmt.index = in_vfmt.fmt.sdr.pixelformat;
+               fmt.type = in_vfmt.type;
 
-                       in_vfmt.fmt.sdr.pixelformat = fmt.pixelformat;
-               }
+               if (doioctl(fd, VIDIOC_ENUM_FMT, &fmt))
+                       fmt.pixelformat = 0;
 
-               if (options[OptSetSdrFormat])
-                       ret = doioctl(fd, VIDIOC_S_FMT, &in_vfmt);
-               else
-                       ret = doioctl(fd, VIDIOC_TRY_FMT, &in_vfmt);
-               if (ret == 0 && (verbose || options[OptTrySdrFormat]))
-                       printfmt(fd, in_vfmt);
+               in_vfmt.fmt.sdr.pixelformat = fmt.pixelformat;
        }
-       if (options[OptSetSdrOutFormat] || options[OptTrySdrOutFormat]) {
-               struct v4l2_format in_vfmt;
-
-               in_vfmt.type = V4L2_BUF_TYPE_SDR_OUTPUT;
-               in_vfmt.fmt.sdr.pixelformat = vfmt.fmt.sdr.pixelformat;
 
-               if (in_vfmt.fmt.sdr.pixelformat < 256) {
-                       struct v4l2_fmtdesc fmt = {};
-
-                       fmt.index = in_vfmt.fmt.sdr.pixelformat;
-                       fmt.type = V4L2_BUF_TYPE_SDR_OUTPUT;
-
-                       if (doioctl(fd, VIDIOC_ENUM_FMT, &fmt))
-                               fmt.pixelformat = 0;
+       if (set)
+               ret = doioctl(fd, VIDIOC_S_FMT, &in_vfmt);
+       else
+               ret = doioctl(fd, VIDIOC_TRY_FMT, &in_vfmt);
+       if (ret == 0 && (verbose || _try))
+               printfmt(fd, in_vfmt);
+}
 
-                       in_vfmt.fmt.sdr.pixelformat = fmt.pixelformat;
-               }
+void sdr_set(cv4l_fd &_fd)
+{
+       __sdr_set(_fd, options[OptSetSdrFormat], options[OptTrySdrFormat],
+                 V4L2_BUF_TYPE_SDR_CAPTURE);
+       __sdr_set(_fd, options[OptSetSdrOutFormat],
+                 options[OptTrySdrOutFormat], V4L2_BUF_TYPE_SDR_OUTPUT);
+}
 
-               if (options[OptSetSdrOutFormat])
-                       ret = doioctl(fd, VIDIOC_S_FMT, &in_vfmt);
-               else
-                       ret = doioctl(fd, VIDIOC_TRY_FMT, &in_vfmt);
-               if (ret == 0 && (verbose || options[OptTrySdrOutFormat]))
-                       printfmt(fd, in_vfmt);
-       }
+static void __sdr_get(cv4l_fd &fd, __u32 type)
+{
+       vfmt.type = type;
+       if (doioctl(fd.g_fd(), VIDIOC_G_FMT, &vfmt) == 0)
+               printfmt(fd.g_fd(), vfmt);
 }
 
 void sdr_get(cv4l_fd &fd)
 {
-       if (options[OptGetSdrFormat]) {
-               vfmt.type = V4L2_BUF_TYPE_SDR_CAPTURE;
-               if (doioctl(fd.g_fd(), VIDIOC_G_FMT, &vfmt) == 0)
-                       printfmt(fd.g_fd(), vfmt);
-       }
-       if (options[OptGetSdrOutFormat]) {
-               vfmt.type = V4L2_BUF_TYPE_SDR_OUTPUT;
-               if (doioctl(fd.g_fd(), VIDIOC_G_FMT, &vfmt) == 0)
-                       printfmt(fd.g_fd(), vfmt);
-       }
+       if (options[OptGetSdrFormat])
+               __sdr_get(fd, V4L2_BUF_TYPE_SDR_CAPTURE);
+       if (options[OptGetSdrOutFormat])
+               __sdr_get(fd, V4L2_BUF_TYPE_SDR_OUTPUT);
 }
 
 void sdr_list(cv4l_fd &fd)
_______________________________________________
linuxtv-commits mailing list -- [email protected]
To unsubscribe send an email to [email protected]

Reply via email to