From patchwork Fri Aug 28 15:17:18 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dafna Hirschfeld X-Patchwork-Id: 11743175 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 7297413B6 for ; Fri, 28 Aug 2020 15:17:39 +0000 (UTC) Received: from merlin.infradead.org (merlin.infradead.org [205.233.59.134]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 3EF6B20757 for ; Fri, 28 Aug 2020 15:17:39 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=lists.infradead.org header.i=@lists.infradead.org header.b="3F9kEMe6" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 3EF6B20757 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=collabora.com Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=linux-rockchip-bounces+patchwork-linux-rockchip=patchwork.kernel.org@lists.infradead.org DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=merlin.20170209; h=Sender:Content-Transfer-Encoding: Content-Type:MIME-Version:Cc:List-Subscribe:List-Help:List-Post:List-Archive: List-Unsubscribe:List-Id:Message-Id:Date:Subject:To:From:Reply-To:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:In-Reply-To:References:List-Owner; bh=JRbhlXcVQIVcw+Sm3OHfPclAZbzwNkSfYtuhEOcjMqQ=; b=3F9kEMe6fURYxjY4KsEy0VrInD p5yUrNDyTrWV2ZGaOQf73GjDCeDlfAZ9+gL8wPckRriGWvoi3JfX3uMtyi83ePRZ4LQL4ezraS0ls 4K+8zoyV9ojKz/LxX50mQAOVo6VfDIDH58nymSV8m/dM6doT2jpGOZL/z8/SrMED1onMKgPkIh+Ar b13uY/JSFJ3QKd1TFfbjH384nA1Kg3vyGANMlgDNiOxsVmf+FH4qv8+PtUAGNiVsPMcrsblIOmlU1 /Rg4orVCwU/zi1nucwM107e+zfw9kShw8Uho87mIXRMXykxhO93F/g3Tv64O++gpf0rGMJEq/nDTH 9iOsB0aA==; Received: from localhost ([::1] helo=merlin.infradead.org) by merlin.infradead.org with esmtp (Exim 4.92.3 #3 (Red Hat Linux)) id 1kBg8A-0001G1-Fd; Fri, 28 Aug 2020 15:17:30 +0000 Received: from bhuna.collabora.co.uk ([2a00:1098:0:82:1000:25:2eeb:e3e3]) by merlin.infradead.org with esmtps (Exim 4.92.3 #3 (Red Hat Linux)) id 1kBg87-0001FL-Ge for linux-rockchip@lists.infradead.org; Fri, 28 Aug 2020 15:17:28 +0000 Received: from [127.0.0.1] (localhost [127.0.0.1]) (Authenticated sender: dafna) with ESMTPSA id 5CBC429A124 From: Dafna Hirschfeld To: linux-media@vger.kernel.org Subject: [PATCH v3] utils: v4l2-ctl: support V4L2_CAP_IO_MC in v4l2-ctl '--list-formats-*' commands Date: Fri, 28 Aug 2020 17:17:18 +0200 Message-Id: <20200828151718.17996-1-dafna.hirschfeld@collabora.com> X-Mailer: git-send-email 2.17.1 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20200828_111727_787255_CC64F2FE X-CRM114-Status: GOOD ( 16.93 ) X-Spam-Score: -0.0 (/) X-Spam-Report: SpamAssassin version 3.4.4 on merlin.infradead.org summary: Content analysis details: (-0.0 points) pts rule name description ---- ---------------------- -------------------------------------------------- -0.0 SPF_HELO_PASS SPF: HELO matches SPF record -0.0 SPF_PASS SPF: sender matches SPF record 0.0 UNPARSEABLE_RELAY Informational: message has unparseable relay lines X-BeenThere: linux-rockchip@lists.infradead.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Upstream kernel work for Rockchip platforms List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: mchehab@kernel.org, dafna.hirschfeld@collabora.com, dafna3@gmail.com, tfiga@chromium.org, hverkuil@xs4all.nl, linux-rockchip@lists.infradead.org, helen.koike@collabora.com, laurent.pinchart@ideasonboard.com, sakari.ailus@linux.intel.com, kernel@collabora.com, ezequiel@collabora.com MIME-Version: 1.0 Sender: "Linux-rockchip" Errors-To: linux-rockchip-bounces+patchwork-linux-rockchip=patchwork.kernel.org@lists.infradead.org Add optional arg to 'v4l2-ctl --list-formats-*' commands for capture, metadata and output devices. If is given and the device has capability V4L2_CAP_IO_MC then list only the formats that matches the mbus code. The mbus_code is ignored for devices that don't use it or don't have the V4L2_CAP_IO_MC capability. Signed-off-by: Dafna Hirschfeld --- changes since v2: - using different global vars for different metadata buffer types and changing var name to media_code_out for output dev - space after 'if' - replace 's/if the driver has capability/if the device has capability/' changes since v1: code refactor due to comments from Hans utils/common/cv4l-helpers.h | 3 ++- utils/v4l2-ctl/v4l2-ctl-meta.cpp | 24 ++++++++++++++++++++---- utils/v4l2-ctl/v4l2-ctl-overlay.cpp | 2 +- utils/v4l2-ctl/v4l2-ctl-sdr.cpp | 4 ++-- utils/v4l2-ctl/v4l2-ctl-vidcap.cpp | 23 ++++++++++++++++++----- utils/v4l2-ctl/v4l2-ctl-vidout.cpp | 22 ++++++++++++++++------ utils/v4l2-ctl/v4l2-ctl.cpp | 26 ++++++++++++++++---------- utils/v4l2-ctl/v4l2-ctl.h | 4 ++-- 8 files changed, 77 insertions(+), 31 deletions(-) diff --git a/utils/common/cv4l-helpers.h b/utils/common/cv4l-helpers.h index 6295054a..3cee372b 100644 --- a/utils/common/cv4l-helpers.h +++ b/utils/common/cv4l-helpers.h @@ -483,12 +483,13 @@ public: return cv4l_ioctl(VIDIOC_ENUM_DV_TIMINGS, &timings); } - int enum_fmt(v4l2_fmtdesc &fmt, bool init = false, int index = 0, unsigned type = 0) + int enum_fmt(v4l2_fmtdesc &fmt, bool init = false, int index = 0, unsigned type = 0, __u32 mbus_code = 0) { if (init) { memset(&fmt, 0, sizeof(fmt)); fmt.type = type ? type : g_type(); fmt.index = index; + fmt.mbus_code = mbus_code; } else { fmt.index++; } diff --git a/utils/v4l2-ctl/v4l2-ctl-meta.cpp b/utils/v4l2-ctl/v4l2-ctl-meta.cpp index b4c7bb89..a4f1d534 100644 --- a/utils/v4l2-ctl/v4l2-ctl-meta.cpp +++ b/utils/v4l2-ctl/v4l2-ctl-meta.cpp @@ -18,11 +18,16 @@ #include "v4l2-ctl.h" static struct v4l2_format vfmt; /* set_format/get_format */ +static unsigned mbus_code; +static unsigned mbus_code_out; void meta_usage() { printf("\nMetadata Formats options:\n" - " --list-formats-meta display supported metadata capture formats [VIDIOC_ENUM_FMT]\n" + " --list-formats-meta [] display supported metadata capture formats.\n" + " 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" " --get-fmt-meta query the metadata capture format [VIDIOC_G_FMT]\n" " --set-fmt-meta set the metadata capture format [VIDIOC_S_FMT]\n" " parameter is either the format index as reported by\n" @@ -30,7 +35,10 @@ void meta_usage() " --try-fmt-meta try the metadata capture format [VIDIOC_TRY_FMT]\n" " parameter is either the format index as reported by\n" " --list-formats-meta, or the fourcc value as a string\n" - " --list-formats-meta-out display supported metadata output formats [VIDIOC_ENUM_FMT]\n" + " --list-formats-meta-out [] display supported metadata output formats.\n" + " 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" " --get-fmt-meta-out query the metadata output format [VIDIOC_G_FMT]\n" " --set-fmt-meta-out set the metadata output format [VIDIOC_S_FMT]\n" " parameter is either the format index as reported by\n" @@ -58,6 +66,14 @@ void meta_cmd(int ch, char *optarg) vfmt.fmt.meta.dataformat = strtol(optarg, 0L, 0); } break; + case OptListMetaFormats: + if (optarg) + mbus_code = strtoul(optarg, 0L, 0); + break; + case OptListMetaOutFormats: + if (optarg) + mbus_code_out = strtoul(optarg, 0L, 0); + break; } } @@ -120,12 +136,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); + print_video_formats(fd, V4L2_BUF_TYPE_META_CAPTURE, mbus_code); } if (options[OptListMetaOutFormats]) { printf("ioctl: VIDIOC_ENUM_FMT\n"); - print_video_formats(fd, V4L2_BUF_TYPE_META_OUTPUT); + print_video_formats(fd, V4L2_BUF_TYPE_META_OUTPUT, mbus_code_out); } } diff --git a/utils/v4l2-ctl/v4l2-ctl-overlay.cpp b/utils/v4l2-ctl/v4l2-ctl-overlay.cpp index 7809a6db..75681332 100644 --- a/utils/v4l2-ctl/v4l2-ctl-overlay.cpp +++ b/utils/v4l2-ctl/v4l2-ctl-overlay.cpp @@ -539,7 +539,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); + print_video_formats(fd, V4L2_BUF_TYPE_VIDEO_OVERLAY, 0); } 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 7a36341a..5b724696 100644 --- a/utils/v4l2-ctl/v4l2-ctl-sdr.cpp +++ b/utils/v4l2-ctl/v4l2-ctl-sdr.cpp @@ -139,10 +139,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); + print_video_formats(fd, V4L2_BUF_TYPE_SDR_CAPTURE, 0); } if (options[OptListSdrOutFormats]) { printf("ioctl: VIDIOC_ENUM_FMT\n"); - print_video_formats(fd, V4L2_BUF_TYPE_SDR_OUTPUT); + print_video_formats(fd, V4L2_BUF_TYPE_SDR_OUTPUT, 0); } } diff --git a/utils/v4l2-ctl/v4l2-ctl-vidcap.cpp b/utils/v4l2-ctl/v4l2-ctl-vidcap.cpp index 5abab5e7..3d0f27db 100644 --- a/utils/v4l2-ctl/v4l2-ctl-vidcap.cpp +++ b/utils/v4l2-ctl/v4l2-ctl-vidcap.cpp @@ -23,13 +23,21 @@ static unsigned set_fmts; static __u32 width, height, pixfmt, field, flags; static __u32 bytesperline[VIDEO_MAX_PLANES]; static __u32 sizeimage[VIDEO_MAX_PLANES]; +static unsigned mbus_code; void vidcap_usage() { printf("\nVideo Capture Formats options:\n" - " --list-formats display supported video formats [VIDIOC_ENUM_FMT]\n" - " --list-formats-ext display supported video formats including frame sizes\n" - " and intervals\n" + " --list-formats []\n" + " display supported video formats. 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 []\n" + " display supported video formats including frame sizes and intervals\n" + " 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-framesizes \n" " list supported framesizes for pixelformat \n" " [VIDIOC_ENUM_FRAMESIZES]\n" @@ -117,6 +125,11 @@ void vidcap_cmd(int ch, char *optarg) std::exit(EXIT_FAILURE); } break; + case OptListFormats: + case OptListFormatsExt: + if (optarg) + mbus_code = strtoul(optarg, 0L, 0); + break; case OptListFrameSizes: be_pixfmt = strlen(optarg) == 7 && !memcmp(optarg + 4, "-BE", 3); if (be_pixfmt || strlen(optarg) == 4) { @@ -298,12 +311,12 @@ void vidcap_list(cv4l_fd &fd) { if (options[OptListFormats]) { printf("ioctl: VIDIOC_ENUM_FMT\n"); - print_video_formats(fd, vidcap_buftype); + print_video_formats(fd, vidcap_buftype, mbus_code); } if (options[OptListFormatsExt]) { printf("ioctl: VIDIOC_ENUM_FMT\n"); - print_video_formats_ext(fd, vidcap_buftype); + print_video_formats_ext(fd, vidcap_buftype, mbus_code); } if (options[OptListFields]) { diff --git a/utils/v4l2-ctl/v4l2-ctl-vidout.cpp b/utils/v4l2-ctl/v4l2-ctl-vidout.cpp index 5f433a17..5362e155 100644 --- a/utils/v4l2-ctl/v4l2-ctl-vidout.cpp +++ b/utils/v4l2-ctl/v4l2-ctl-vidout.cpp @@ -21,14 +21,19 @@ static unsigned set_fmts_out; static __u32 width, height, pixfmt, field, colorspace, xfer_func, ycbcr, quantization, flags; static __u32 bytesperline[VIDEO_MAX_PLANES]; static __u32 sizeimage[VIDEO_MAX_PLANES]; +static unsigned mbus_code_out; void vidout_usage() { printf("\nVideo Output Formats options:\n" - " --list-formats-out display supported video output formats [VIDIOC_ENUM_FMT]\n" - " --list-formats-out-ext\n" - " display supported video output formats including frame sizes\n" - " and intervals\n" + " --list-formats-out [] display supported video output formats.\n" + " 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 [] display supported video output formats including\n" + " frame sizes and intervals. 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" " --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" @@ -103,6 +108,11 @@ void vidout_cmd(int ch, char *optarg) std::exit(EXIT_FAILURE); } break; + case OptListOutFormats: + case OptListOutFormatsExt: + if (optarg) + mbus_code_out = strtoul(optarg, 0L, 0); + break; } } @@ -233,12 +243,12 @@ void vidout_list(cv4l_fd &fd) { if (options[OptListOutFormats]) { printf("ioctl: VIDIOC_ENUM_FMT\n"); - print_video_formats(fd, vidout_buftype); + print_video_formats(fd, vidout_buftype, mbus_code_out); } if (options[OptListOutFormatsExt]) { printf("ioctl: VIDIOC_ENUM_FMT\n"); - print_video_formats_ext(fd, vidout_buftype); + print_video_formats_ext(fd, vidout_buftype, mbus_code_out); } if (options[OptListOutFields]) { diff --git a/utils/v4l2-ctl/v4l2-ctl.cpp b/utils/v4l2-ctl/v4l2-ctl.cpp index a31b29f8..c01ee883 100644 --- a/utils/v4l2-ctl/v4l2-ctl.cpp +++ b/utils/v4l2-ctl/v4l2-ctl.cpp @@ -114,18 +114,18 @@ static struct option long_options[] = { {"get-freq", no_argument, 0, OptGetFreq}, {"set-freq", required_argument, 0, OptSetFreq}, {"list-standards", no_argument, 0, OptListStandards}, - {"list-formats", no_argument, 0, OptListFormats}, - {"list-formats-ext", no_argument, 0, OptListFormatsExt}, + {"list-formats", optional_argument, 0, OptListFormats}, + {"list-formats-ext", optional_argument, 0, OptListFormatsExt}, {"list-fields", no_argument, 0, OptListFields}, {"list-framesizes", required_argument, 0, OptListFrameSizes}, {"list-frameintervals", required_argument, 0, OptListFrameIntervals}, {"list-formats-overlay", no_argument, 0, OptListOverlayFormats}, {"list-formats-sdr", no_argument, 0, OptListSdrFormats}, {"list-formats-sdr-out", no_argument, 0, OptListSdrOutFormats}, - {"list-formats-out", no_argument, 0, OptListOutFormats}, - {"list-formats-out-ext", no_argument, 0, OptListOutFormatsExt}, - {"list-formats-meta", no_argument, 0, OptListMetaFormats}, - {"list-formats-meta-out", no_argument, 0, OptListMetaOutFormats}, + {"list-formats-out", optional_argument, 0, OptListOutFormats}, + {"list-formats-out-ext", optional_argument, 0, OptListOutFormatsExt}, + {"list-formats-meta", optional_argument, 0, OptListMetaFormats}, + {"list-formats-meta-out", optional_argument, 0, OptListMetaOutFormats}, {"list-subdev-mbus-codes", optional_argument, 0, OptListSubDevMBusCodes}, {"list-subdev-framesizes", required_argument, 0, OptListSubDevFrameSizes}, {"list-subdev-frameintervals", required_argument, 0, OptListSubDevFrameIntervals}, @@ -612,13 +612,16 @@ void print_frmival(const struct v4l2_frmivalenum &frmival, const char *prefix) } } -void print_video_formats(cv4l_fd &fd, __u32 type) +void print_video_formats(cv4l_fd &fd, __u32 type, unsigned int mbus_code) { cv4l_disable_trace dt(fd); struct v4l2_fmtdesc fmt = {}; + if (mbus_code && !(capabilities & V4L2_CAP_IO_MC)) + mbus_code = 0; + printf("\tType: %s\n\n", buftype2s(type).c_str()); - if (fd.enum_fmt(fmt, true, 0, type)) + if (fd.enum_fmt(fmt, true, 0, type, mbus_code)) return; do { printf("\t[%d]: '%s' (%s", fmt.index, fcc2s(fmt.pixelformat).c_str(), @@ -629,15 +632,18 @@ void print_video_formats(cv4l_fd &fd, __u32 type) } while (!fd.enum_fmt(fmt)); } -void print_video_formats_ext(cv4l_fd &fd, __u32 type) +void print_video_formats_ext(cv4l_fd &fd, __u32 type, unsigned int mbus_code) { cv4l_disable_trace dt(fd); struct v4l2_fmtdesc fmt = {}; struct v4l2_frmsizeenum frmsize; struct v4l2_frmivalenum frmival; + if (mbus_code && !(capabilities & V4L2_CAP_IO_MC)) + mbus_code = 0; + printf("\tType: %s\n\n", buftype2s(type).c_str()); - if (fd.enum_fmt(fmt, true, 0, type)) + if (fd.enum_fmt(fmt, true, 0, type, mbus_code)) return; do { printf("\t[%d]: '%s' (%s", fmt.index, fcc2s(fmt.pixelformat).c_str(), diff --git a/utils/v4l2-ctl/v4l2-ctl.h b/utils/v4l2-ctl/v4l2-ctl.h index 4acb4d51..e906dc73 100644 --- a/utils/v4l2-ctl/v4l2-ctl.h +++ b/utils/v4l2-ctl/v4l2-ctl.h @@ -321,8 +321,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); -void print_video_formats_ext(cv4l_fd &fd, __u32 type); +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); static inline bool subscribe_event(cv4l_fd &fd, __u32 type) {