From patchwork Thu Jan 3 18:00:58 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Antonio Ospite X-Patchwork-Id: 10747693 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 13320746 for ; Thu, 3 Jan 2019 18:40:55 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 053DE28CF8 for ; Thu, 3 Jan 2019 18:40:55 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id ED06A28D05; Thu, 3 Jan 2019 18:40:54 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-8.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 9767A28CF8 for ; Thu, 3 Jan 2019 18:40:54 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1725988AbfACSkw (ORCPT ); Thu, 3 Jan 2019 13:40:52 -0500 Received: from mail.ao2.it ([92.243.12.208]:58429 "EHLO ao2.it" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725871AbfACSkw (ORCPT ); Thu, 3 Jan 2019 13:40:52 -0500 X-Greylist: delayed 2383 seconds by postgrey-1.27 at vger.kernel.org; Thu, 03 Jan 2019 13:40:51 EST DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=ao2.it; s=20180927; h=Content-Transfer-Encoding:MIME-Version:References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From; bh=ZimGhC4qxCEHzopW7Xfvqjl0RmpAcEZF+FCuV4ji0g0=; b=ZqEFO5A+vpaWIs6uu4dxrdl1vW1a3ZVxMfWYs7q1ne5sS5KVd9foyHuX7GnmuD1fFaEsswiWMh2/zaa9BgaDerLQKL1cNFwZZB3ZryBsR43903xKuyTi2PGTcpCKyzi3MoRzXxo3wV+USRz2EkkW0ZE0kpApTRYF+4EAyBamGDVab58NjYtZIWSSAVJn2+raxDtTNYfAv0NsC8BPpjPfUaNxdUHl294zvYsl77zIGVKTmClfjIfNGagqIjAx9l36SARNwpbXP4y84QAirtEDooyWClaTUakdlYAp44iFZGAXMkVKXR35EBdW6f2VxCZ+/D6BpS/LgE1h+rJL4Zxc8A==; Received: from localhost ([::1] helo=jcn) by ao2.it with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.84_2) (envelope-from ) id 1gf7Hp-0002wL-WB; Thu, 03 Jan 2019 19:00:06 +0100 Received: from ao2 by jcn with local (Exim 4.92-RC3) (envelope-from ) id 1gf7Io-0003Cy-NA; Thu, 03 Jan 2019 19:01:06 +0100 From: Antonio Ospite To: linux-media@vger.kernel.org Cc: Antonio Ospite Subject: [RFC PATCH 1/5] v4l2-ctl: list controls with menus when OptAll is specified Date: Thu, 3 Jan 2019 19:00:58 +0100 Message-Id: <20190103180102.12282-2-ao2@ao2.it> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190103180102.12282-1-ao2@ao2.it> References: <20181124185256.74dc969bdb8f7ab79cf03d5d@ao2.it> <20190103180102.12282-1-ao2@ao2.it> MIME-Version: 1.0 X-Face: z*RaLf`X<@C75u6Ig9}{oW$H;1_\2t5)({*|jhM/Vb;]yA5\I~93>J<_`<4)A{':UrE Sender: linux-media-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-media@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP When calling "v4l2-ctl --all" the user may expect the most comprehensive output, so also print the menus when listing controls. Signed-off-by: Antonio Ospite --- utils/v4l2-ctl/v4l2-ctl.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/utils/v4l2-ctl/v4l2-ctl.cpp b/utils/v4l2-ctl/v4l2-ctl.cpp index 8c52c7be..a65262f6 100644 --- a/utils/v4l2-ctl/v4l2-ctl.cpp +++ b/utils/v4l2-ctl/v4l2-ctl.cpp @@ -1255,7 +1255,7 @@ int main(int argc, char **argv) options[OptGetPriority] = 1; options[OptGetSelection] = 1; options[OptGetOutputSelection] = 1; - options[OptListCtrls] = 1; + options[OptListCtrlsMenus] = 1; options[OptSilent] = 1; } From patchwork Thu Jan 3 18:00:59 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Antonio Ospite X-Patchwork-Id: 10747697 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id DC8FB6C5 for ; Thu, 3 Jan 2019 18:40:58 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id D17FA28CF5 for ; Thu, 3 Jan 2019 18:40:58 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id C5FF828D04; Thu, 3 Jan 2019 18:40:58 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-8.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 7D31928CF5 for ; Thu, 3 Jan 2019 18:40:58 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726074AbfACSk5 (ORCPT ); Thu, 3 Jan 2019 13:40:57 -0500 Received: from mail.ao2.it ([92.243.12.208]:58431 "EHLO ao2.it" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725871AbfACSk5 (ORCPT ); Thu, 3 Jan 2019 13:40:57 -0500 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=ao2.it; s=20180927; h=Content-Transfer-Encoding:MIME-Version:References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From; bh=inL732P2ibVLjJvlYjE4QZS7vVZw5X1z6O6He+ahaoo=; b=IIrzbMTxXh6xbeRWQGxV1IJ5tafk9y3+3twXnrtXbP9ie2symCHwwocA2unbgsKuXX76BMyrzG/G8eiSjsczl+jef+/6NQMU6kpPWQO1DST2se4mI0mKSuK1eR2zG0wHM469jfNdFUyC4JYjveqYcbdRNODre79G3rPgXjD5aP0MYLjTjrlGrccJP0+kYUprYZ3AVmucJsUh5dZxXhI1lKv3K58gQ4vE3JxhM7ih7NXL4vNYjDpcA4p7EPLmSN4rc6qf9FRGgiu3LBrmcS4emIh68P2ELsWGd49/kZmdDgcIxCy6mCDpUBSRh57vHdjBYtRn5T9eQTWlg+cK6tRiww==; Received: from localhost ([::1] helo=jcn) by ao2.it with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.84_2) (envelope-from ) id 1gf7Hq-0002wM-39; Thu, 03 Jan 2019 19:00:06 +0100 Received: from ao2 by jcn with local (Exim 4.92-RC3) (envelope-from ) id 1gf7Io-0003D0-PU; Thu, 03 Jan 2019 19:01:06 +0100 From: Antonio Ospite To: linux-media@vger.kernel.org Cc: Antonio Ospite Subject: [RFC PATCH 2/5] v4l2-ctl: list once when both OptListCtrls and OptListCtrlsMenus are there Date: Thu, 3 Jan 2019 19:00:59 +0100 Message-Id: <20190103180102.12282-3-ao2@ao2.it> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190103180102.12282-1-ao2@ao2.it> References: <20181124185256.74dc969bdb8f7ab79cf03d5d@ao2.it> <20190103180102.12282-1-ao2@ao2.it> MIME-Version: 1.0 X-Face: z*RaLf`X<@C75u6Ig9}{oW$H;1_\2t5)({*|jhM/Vb;]yA5\I~93>J<_`<4)A{':UrE Sender: linux-media-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-media@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP When both --list-ctrls and --list-ctrls-menus are passed, controls are listed twice which is accurate but can be confusing. Treat --list-ctrls-menus as an option modifier when also --list-ctrls is passed, in order to have the controls listed only once. Signed-off-by: Antonio Ospite --- utils/v4l2-ctl/v4l2-ctl-common.cpp | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/utils/v4l2-ctl/v4l2-ctl-common.cpp b/utils/v4l2-ctl/v4l2-ctl-common.cpp index 8256cbd9..e2710335 100644 --- a/utils/v4l2-ctl/v4l2-ctl-common.cpp +++ b/utils/v4l2-ctl/v4l2-ctl-common.cpp @@ -1091,11 +1091,7 @@ void common_get(cv4l_fd &_fd) void common_list(cv4l_fd &fd) { - if (options[OptListCtrlsMenus]) { - list_controls(fd.g_fd(), 1); - } - - if (options[OptListCtrls]) { - list_controls(fd.g_fd(), 0); + if (options[OptListCtrls] || options[OptListCtrlsMenus]) { + list_controls(fd.g_fd(), options[OptListCtrlsMenus]); } } From patchwork Thu Jan 3 18:01:00 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Antonio Ospite X-Patchwork-Id: 10747703 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 19DC8746 for ; Thu, 3 Jan 2019 18:41:04 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 0EE1E28CF5 for ; Thu, 3 Jan 2019 18:41:04 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 0378028D04; Thu, 3 Jan 2019 18:41:04 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-8.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 9F5C528CF5 for ; Thu, 3 Jan 2019 18:41:03 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726080AbfACSlD (ORCPT ); Thu, 3 Jan 2019 13:41:03 -0500 Received: from mail.ao2.it ([92.243.12.208]:58434 "EHLO ao2.it" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725871AbfACSlC (ORCPT ); Thu, 3 Jan 2019 13:41:02 -0500 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=ao2.it; s=20180927; h=Content-Transfer-Encoding:MIME-Version:References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From; bh=FA1bQexyPoAn/vJg/TbwdBpgeZJJFuRc5mq1L8pu8EA=; b=q8xAfoYdwfHPXyVlYwihVxv5EDNj7v4T6skxhJyAMR967lemIXLbKMypFaYTFlF4rZlm0gGhrdERiiGp8rVQtanZnafZ/rk/+xsbPH9WxaFY/v+2vDOM1+7D3gB69Y4k9w2dah0OzAdpSCw/hFLRD1Igjkne1KWHovK+SWFRbGBszReSiTVjlUBBwvUDFJ3y6bWcgX4AQl6sqXEipNWEWhFA6fFJMaeb5tKaAON9hjmb8FEx7nZbMP1MTAolwOi9TnwKUrdsfx9+KNwniFZeM5pz1lchhwUH+95dEiBabDOHqsgtzm9YD5fmyoRBNCh69PT4438XoxcHwMcF2bnJpw==; Received: from localhost ([::1] helo=jcn) by ao2.it with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.84_2) (envelope-from ) id 1gf7Hq-0002wN-5q; Thu, 03 Jan 2019 19:00:06 +0100 Received: from ao2 by jcn with local (Exim 4.92-RC3) (envelope-from ) id 1gf7Io-0003D2-Re; Thu, 03 Jan 2019 19:01:06 +0100 From: Antonio Ospite To: linux-media@vger.kernel.org Cc: Antonio Ospite Subject: [RFC PATCH 3/5] v4l2-ctl: use a dedicated function to print the control class name Date: Thu, 3 Jan 2019 19:01:00 +0100 Message-Id: <20190103180102.12282-4-ao2@ao2.it> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190103180102.12282-1-ao2@ao2.it> References: <20181124185256.74dc969bdb8f7ab79cf03d5d@ao2.it> <20190103180102.12282-1-ao2@ao2.it> MIME-Version: 1.0 X-Face: z*RaLf`X<@C75u6Ig9}{oW$H;1_\2t5)({*|jhM/Vb;]yA5\I~93>J<_`<4)A{':UrE Sender: linux-media-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-media@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP All the details about the controls are printed in the dedicated function print_qctrl(), use a new dedicated function named print_class_name() to print the control class name as well, this is for symmetry but it is also in preparation for a change which aims to abstract how the controls are printed. Signed-off-by: Antonio Ospite --- utils/v4l2-ctl/v4l2-ctl-common.cpp | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/utils/v4l2-ctl/v4l2-ctl-common.cpp b/utils/v4l2-ctl/v4l2-ctl-common.cpp index e2710335..5d41d720 100644 --- a/utils/v4l2-ctl/v4l2-ctl-common.cpp +++ b/utils/v4l2-ctl/v4l2-ctl-common.cpp @@ -403,6 +403,11 @@ static void print_qctrl(int fd, struct v4l2_query_ext_ctrl *queryctrl, } } +static void print_class_name(const char *name) +{ + printf("\n%s\n\n", name); +} + static int print_control(int fd, struct v4l2_query_ext_ctrl &qctrl, int show_menus) { struct v4l2_control ctrl; @@ -415,7 +420,7 @@ static int print_control(int fd, struct v4l2_query_ext_ctrl &qctrl, int show_men if (qctrl.flags & V4L2_CTRL_FLAG_DISABLED) return 1; if (qctrl.type == V4L2_CTRL_TYPE_CTRL_CLASS) { - printf("\n%s\n\n", qctrl.name); + print_class_name(qctrl.name); return 1; } ext_ctrl.id = qctrl.id; From patchwork Thu Jan 3 18:01:01 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Antonio Ospite X-Patchwork-Id: 10747701 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id BF9DF746 for ; Thu, 3 Jan 2019 18:41:02 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id B3EE928CF5 for ; Thu, 3 Jan 2019 18:41:02 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id A87C428D04; Thu, 3 Jan 2019 18:41:02 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-8.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 3562828CF5 for ; Thu, 3 Jan 2019 18:41:02 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726087AbfACSlB (ORCPT ); Thu, 3 Jan 2019 13:41:01 -0500 Received: from mail.ao2.it ([92.243.12.208]:58433 "EHLO ao2.it" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725871AbfACSlB (ORCPT ); Thu, 3 Jan 2019 13:41:01 -0500 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=ao2.it; s=20180927; h=Content-Transfer-Encoding:MIME-Version:References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From; bh=hpryT/OzjHsFMb4eVdqf6EOcTMkFYwvsBlU8gQJByXA=; b=VTlpoFTvsxZpNzjq/8yJfu0FkvOe4D/TnzGQamp3SW7a5numSLDbouz/m0PVZbxIRCKGLp/c8PzvyuiSnTWEu5mQqKzGRjXX1pzNhpg0TaNNiPH9f9/zMMbrGDOOYsdwxJgLooy+fPZbE1riFCO9s9F7Yl83wYXHQltd5zUwtYX5CfVMnCD6WVh7oJLYJNjHlY3PMxCA70o/7uMzZt6j4EVGHTF0I7z6hxZ+ysIlSjvLtnmhkm66Cfs0SvtC65TonpZ/LIfkMP1Z6Ev2BEYtBRzFMo74/8zNGVg/qU+QUUpQnmLTJCF63CVqnN5oygc0VmBj6unR2oShhJL6nghTJw==; Received: from localhost ([::1] helo=jcn) by ao2.it with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.84_2) (envelope-from ) id 1gf7Hq-0002wO-7z; Thu, 03 Jan 2019 19:00:06 +0100 Received: from ao2 by jcn with local (Exim 4.92-RC3) (envelope-from ) id 1gf7Io-0003D4-Tm; Thu, 03 Jan 2019 19:01:06 +0100 From: Antonio Ospite To: linux-media@vger.kernel.org Cc: Antonio Ospite Subject: [RFC PATCH 4/5] v4l2-ctl: abstract the mechanism used to print the list of controls Date: Thu, 3 Jan 2019 19:01:01 +0100 Message-Id: <20190103180102.12282-5-ao2@ao2.it> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190103180102.12282-1-ao2@ao2.it> References: <20181124185256.74dc969bdb8f7ab79cf03d5d@ao2.it> <20190103180102.12282-1-ao2@ao2.it> MIME-Version: 1.0 X-Face: z*RaLf`X<@C75u6Ig9}{oW$H;1_\2t5)({*|jhM/Vb;]yA5\I~93>J<_`<4)A{':UrE Sender: linux-media-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-media@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Sometimes it may be useful to list the controls using a different output format than the current one used by --list-ctrls, for instance a new printing format could output a string which can be later fed to --set-ctrl. Add an abstraction mechanism to make it possible to add new output formats for controls. Signed-off-by: Antonio Ospite --- utils/v4l2-ctl/v4l2-ctl-common.cpp | 32 ++++++++++++++++++++---------- 1 file changed, 22 insertions(+), 10 deletions(-) diff --git a/utils/v4l2-ctl/v4l2-ctl-common.cpp b/utils/v4l2-ctl/v4l2-ctl-common.cpp index 5d41d720..7777b45c 100644 --- a/utils/v4l2-ctl/v4l2-ctl-common.cpp +++ b/utils/v4l2-ctl/v4l2-ctl-common.cpp @@ -30,6 +30,12 @@ struct ctrl_subset { unsigned size[V4L2_CTRL_MAX_DIMS]; }; +struct print_format { + void (*print_class_name)(const char *); + void (*print_qctrl)(int, struct v4l2_query_ext_ctrl *, struct v4l2_ext_control *, int); + int show_menus; +}; + typedef std::map > class2ctrls_map; typedef std::map ctrl_qmap; @@ -408,7 +414,7 @@ static void print_class_name(const char *name) printf("\n%s\n\n", name); } -static int print_control(int fd, struct v4l2_query_ext_ctrl &qctrl, int show_menus) +static int print_control(int fd, struct v4l2_query_ext_ctrl &qctrl, struct print_format *format) { struct v4l2_control ctrl; struct v4l2_ext_control ext_ctrl; @@ -420,17 +426,17 @@ static int print_control(int fd, struct v4l2_query_ext_ctrl &qctrl, int show_men if (qctrl.flags & V4L2_CTRL_FLAG_DISABLED) return 1; if (qctrl.type == V4L2_CTRL_TYPE_CTRL_CLASS) { - print_class_name(qctrl.name); + format->print_class_name(qctrl.name); return 1; } ext_ctrl.id = qctrl.id; if ((qctrl.flags & V4L2_CTRL_FLAG_WRITE_ONLY) || qctrl.type == V4L2_CTRL_TYPE_BUTTON) { - print_qctrl(fd, &qctrl, &ext_ctrl, show_menus); + format->print_qctrl(fd, &qctrl, &ext_ctrl, format->show_menus); return 1; } if (qctrl.type >= V4L2_CTRL_COMPOUND_TYPES) { - print_qctrl(fd, &qctrl, NULL, show_menus); + format->print_qctrl(fd, &qctrl, NULL, format->show_menus); return 1; } ctrls.which = V4L2_CTRL_ID2WHICH(qctrl.id); @@ -460,7 +466,7 @@ static int print_control(int fd, struct v4l2_query_ext_ctrl &qctrl, int show_men } ext_ctrl.value = ctrl.value; } - print_qctrl(fd, &qctrl, &ext_ctrl, show_menus); + format->print_qctrl(fd, &qctrl, &ext_ctrl, format->show_menus); if (qctrl.type == V4L2_CTRL_TYPE_STRING) free(ext_ctrl.string); return 1; @@ -512,7 +518,7 @@ static int query_ext_ctrl_ioctl(int fd, struct v4l2_query_ext_ctrl &qctrl) return rc; } -static void list_controls(int fd, int show_menus) +static void list_controls(int fd, struct print_format *format) { const unsigned next_fl = V4L2_CTRL_FLAG_NEXT_CTRL | V4L2_CTRL_FLAG_NEXT_COMPOUND; struct v4l2_query_ext_ctrl qctrl; @@ -521,7 +527,7 @@ static void list_controls(int fd, int show_menus) memset(&qctrl, 0, sizeof(qctrl)); qctrl.id = next_fl; while (query_ext_ctrl_ioctl(fd, qctrl) == 0) { - print_control(fd, qctrl, show_menus); + print_control(fd, qctrl, format); qctrl.id |= next_fl; } if (qctrl.id != next_fl) @@ -529,11 +535,11 @@ static void list_controls(int fd, int show_menus) for (id = V4L2_CID_USER_BASE; id < V4L2_CID_LASTP1; id++) { qctrl.id = id; if (query_ext_ctrl_ioctl(fd, qctrl) == 0) - print_control(fd, qctrl, show_menus); + print_control(fd, qctrl, format); } for (qctrl.id = V4L2_CID_PRIVATE_BASE; query_ext_ctrl_ioctl(fd, qctrl) == 0; qctrl.id++) { - print_control(fd, qctrl, show_menus); + print_control(fd, qctrl, format); } } @@ -1097,6 +1103,12 @@ void common_get(cv4l_fd &_fd) void common_list(cv4l_fd &fd) { if (options[OptListCtrls] || options[OptListCtrlsMenus]) { - list_controls(fd.g_fd(), options[OptListCtrlsMenus]); + struct print_format classic_format = { + .print_class_name = print_class_name, + .print_qctrl = print_qctrl, + .show_menus = options[OptListCtrlsMenus], + }; + + list_controls(fd.g_fd(), &classic_format); } } From patchwork Thu Jan 3 18:01:02 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Antonio Ospite X-Patchwork-Id: 10747695 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id E1CD1746 for ; Thu, 3 Jan 2019 18:40:57 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id D52E628CF5 for ; Thu, 3 Jan 2019 18:40:57 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id C735B28D04; Thu, 3 Jan 2019 18:40:57 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-8.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 3AA0E28CF5 for ; Thu, 3 Jan 2019 18:40:57 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726014AbfACSkz (ORCPT ); Thu, 3 Jan 2019 13:40:55 -0500 Received: from mail.ao2.it ([92.243.12.208]:58430 "EHLO ao2.it" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725871AbfACSkz (ORCPT ); Thu, 3 Jan 2019 13:40:55 -0500 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=ao2.it; s=20180927; h=Content-Transfer-Encoding:MIME-Version:References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From; bh=JFAfN0+7o1DcPPISxdQgm6nW9sVKi6SuEx+nthoJThM=; b=JqsdZyrHv3QzhuPK+TUVR8s69Qo5WPtoryv40qZxXO6NUj9mXJ9Z32XzNz/jEvnx3ybIIg9WIB7bQUc3Zosl9zxuieQuHl3pZ1V6FOLje9Sm3mFRPIULpgj0/WSKc68mXIJB7/8ugmxuWHClnArF1JurtvYa5CVnXbTGfbyt3VNyPxNuKrNSq89QUeHyqELz6bfGd93v5tpKvJ2vFTvdQ8Oy1uOV+6k1tmV1yZ/SDdvFpuIT/PLqOUJCR1zMR2Aup45Qvw7KouK4m+hApveXuidQiFS/WExzMCrGkFMYQ7/+xT/KGGRpPn8ae0FtVOMoL4u9UPv6eF/A7Tm74okWaw==; Received: from localhost ([::1] helo=jcn) by ao2.it with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.84_2) (envelope-from ) id 1gf7Hq-0002wS-Df; Thu, 03 Jan 2019 19:00:06 +0100 Received: from ao2 by jcn with local (Exim 4.92-RC3) (envelope-from ) id 1gf7Io-0003D7-W6; Thu, 03 Jan 2019 19:01:06 +0100 From: Antonio Ospite To: linux-media@vger.kernel.org Cc: Antonio Ospite Subject: [RFC PATCH 5/5] v4l2-ctl: add an option to list controls in a machine-readable format Date: Thu, 3 Jan 2019 19:01:02 +0100 Message-Id: <20190103180102.12282-6-ao2@ao2.it> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190103180102.12282-1-ao2@ao2.it> References: <20181124185256.74dc969bdb8f7ab79cf03d5d@ao2.it> <20190103180102.12282-1-ao2@ao2.it> MIME-Version: 1.0 X-Face: z*RaLf`X<@C75u6Ig9}{oW$H;1_\2t5)({*|jhM/Vb;]yA5\I~93>J<_`<4)A{':UrE Sender: linux-media-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-media@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Add a new option --list-ctrls-values to list the values of controls in a format which can be passed again to --set-ctrl. This can be useful to save and restore device settings: $ v4l2-ctl --list-ctrls-values >settings.txt 2>/dev/null $ v4l2-ctl --set-ctrl "$(cat settings.txt)" The new option has been tested with the vivid driver and it works well enough to be useful with a real driver as well. String controls are not supported for now, as they may not be parsed correctly by --set-ctrl if they contain a comma or a single quote. Signed-off-by: Antonio Ospite --- utils/v4l2-ctl/v4l2-ctl-common.cpp | 72 ++++++++++++++++++++++++++---- utils/v4l2-ctl/v4l2-ctl.1.in | 4 ++ utils/v4l2-ctl/v4l2-ctl.cpp | 1 + utils/v4l2-ctl/v4l2-ctl.h | 1 + 4 files changed, 69 insertions(+), 9 deletions(-) diff --git a/utils/v4l2-ctl/v4l2-ctl-common.cpp b/utils/v4l2-ctl/v4l2-ctl-common.cpp index 7777b45c..b4124608 100644 --- a/utils/v4l2-ctl/v4l2-ctl-common.cpp +++ b/utils/v4l2-ctl/v4l2-ctl-common.cpp @@ -93,6 +93,9 @@ void common_usage(void) " -l, --list-ctrls display all controls and their values [VIDIOC_QUERYCTRL]\n" " -L, --list-ctrls-menus\n" " display all controls and their menus [VIDIOC_QUERYMENU]\n" + " -m, --list-ctrls-values\n" + " display all controls and their values in a format compatible with\n" + " --set-ctrls (the 'm' stands for \"machine readable output\")\n" " -r, --subset [,,]+\n" " the subset of the N-dimensional array to get/set for control ,\n" " for every dimension an (, ) tuple is given.\n" @@ -409,6 +412,46 @@ static void print_qctrl(int fd, struct v4l2_query_ext_ctrl *queryctrl, } } +static void print_qctrl_values(int fd, struct v4l2_query_ext_ctrl *queryctrl, + struct v4l2_ext_control *ctrl, int show_menus) +{ + std::string s = name2var(queryctrl->name); + + if (queryctrl->nr_of_dims == 0) { + switch (queryctrl->type) { + case V4L2_CTRL_TYPE_INTEGER: + case V4L2_CTRL_TYPE_BOOLEAN: + case V4L2_CTRL_TYPE_MENU: + case V4L2_CTRL_TYPE_INTEGER_MENU: + printf("%s=%d,", s.c_str(), ctrl->value); + break; + case V4L2_CTRL_TYPE_BITMASK: + printf("%s=0x%08x,", s.c_str(), ctrl->value); + break; + case V4L2_CTRL_TYPE_INTEGER64: + printf("%s=%lld,", s.c_str(), ctrl->value64); + break; + case V4L2_CTRL_TYPE_STRING: + fprintf(stderr, "%s: string controls unsupported for now\n", queryctrl->name); + break; + default: + fprintf(stderr, "%s: unsupported payload type\n", queryctrl->name); + break; + } + } + + if (queryctrl->nr_of_dims) + fprintf(stderr, "%s: unsupported payload type (multi-dimensional)\n", queryctrl->name); + + if (queryctrl->flags) + fprintf(stderr, "%s: ignoring flags\n", queryctrl->name); + + if ((queryctrl->type == V4L2_CTRL_TYPE_MENU || + queryctrl->type == V4L2_CTRL_TYPE_INTEGER_MENU) && show_menus) { + fprintf(stderr, "%s: ignoring menus\n", queryctrl->name); + } +} + static void print_class_name(const char *name) { printf("\n%s\n\n", name); @@ -426,7 +469,8 @@ static int print_control(int fd, struct v4l2_query_ext_ctrl &qctrl, struct print if (qctrl.flags & V4L2_CTRL_FLAG_DISABLED) return 1; if (qctrl.type == V4L2_CTRL_TYPE_CTRL_CLASS) { - format->print_class_name(qctrl.name); + if (format->print_class_name) + format->print_class_name(qctrl.name); return 1; } ext_ctrl.id = qctrl.id; @@ -1102,13 +1146,23 @@ void common_get(cv4l_fd &_fd) void common_list(cv4l_fd &fd) { - if (options[OptListCtrls] || options[OptListCtrlsMenus]) { - struct print_format classic_format = { - .print_class_name = print_class_name, - .print_qctrl = print_qctrl, - .show_menus = options[OptListCtrlsMenus], - }; - - list_controls(fd.g_fd(), &classic_format); + if (options[OptListCtrls] || options[OptListCtrlsMenus] || options[OptListCtrlsValues]) { + if (options[OptListCtrlsValues]) { + struct print_format machine_format = { + .print_class_name = NULL, + .print_qctrl = print_qctrl_values, + .show_menus = 0, + }; + + list_controls(fd.g_fd(), &machine_format); + } else { + struct print_format classic_format = { + .print_class_name = print_class_name, + .print_qctrl = print_qctrl, + .show_menus = options[OptListCtrlsMenus], + }; + + list_controls(fd.g_fd(), &classic_format); + } } } diff --git a/utils/v4l2-ctl/v4l2-ctl.1.in b/utils/v4l2-ctl/v4l2-ctl.1.in index e60c2d49..98cc7b72 100644 --- a/utils/v4l2-ctl/v4l2-ctl.1.in +++ b/utils/v4l2-ctl/v4l2-ctl.1.in @@ -98,6 +98,10 @@ Display all controls and their values [VIDIOC_QUERYCTRL]. \fB-L\fR, \fB--list-ctrls-menus\fR Display all controls and their menus [VIDIOC_QUERYMENU]. .TP +\fB-m\fR, \fB--list-ctrls-values\fR +display all controls and their values in a format compatible with +--set-ctrls (the 'm' stands for "machine readable output") +.TP \fB-r\fR, \fB--subset\fR \fI\fR[,\fI\fR,\fI\fR]+ The subset of the N-dimensional array to get/set for control \fI\fR, for every dimension an (\fI\fR, \fI\fR) tuple is given. diff --git a/utils/v4l2-ctl/v4l2-ctl.cpp b/utils/v4l2-ctl/v4l2-ctl.cpp index a65262f6..647e1778 100644 --- a/utils/v4l2-ctl/v4l2-ctl.cpp +++ b/utils/v4l2-ctl/v4l2-ctl.cpp @@ -142,6 +142,7 @@ static struct option long_options[] = { {"info", no_argument, 0, OptGetDriverInfo}, {"list-ctrls", no_argument, 0, OptListCtrls}, {"list-ctrls-menus", no_argument, 0, OptListCtrlsMenus}, + {"list-ctrls-values", no_argument, 0, OptListCtrlsValues}, {"set-ctrl", required_argument, 0, OptSetCtrl}, {"get-ctrl", required_argument, 0, OptGetCtrl}, {"get-tuner", no_argument, 0, OptGetTuner}, diff --git a/utils/v4l2-ctl/v4l2-ctl.h b/utils/v4l2-ctl/v4l2-ctl.h index 5a52a0a4..e60a1ea1 100644 --- a/utils/v4l2-ctl/v4l2-ctl.h +++ b/utils/v4l2-ctl/v4l2-ctl.h @@ -65,6 +65,7 @@ enum Option { OptConcise = 'k', OptListCtrls = 'l', OptListCtrlsMenus = 'L', + OptListCtrlsValues = 'm', OptListOutputs = 'N', OptListInputs = 'n', OptGetOutput = 'O',