From: Antonio Ospite <ao2@ao2.it>
To: linux-media@vger.kernel.org
Cc: Antonio Ospite <ao2@ao2.it>
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 [thread overview]
Message-ID: <20190103180102.12282-5-ao2@ao2.it> (raw)
In-Reply-To: <20190103180102.12282-1-ao2@ao2.it>
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 <ao2@ao2.it>
---
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<unsigned, std::vector<struct v4l2_ext_control> > class2ctrls_map;
typedef std::map<std::string, struct v4l2_query_ext_ctrl> 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);
}
}
--
2.20.1
next prev parent reply other threads:[~2019-01-03 18:41 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
2018-11-24 17:52 [v4l-utils] Add options to v4l2-ctrl to save/load settings to/from a file Antonio Ospite
2019-01-03 18:00 ` [RFC PATCH 0/5] v4l2-ctl: list controls values in a machine-readable format Antonio Ospite
2019-01-03 18:00 ` [RFC PATCH 1/5] v4l2-ctl: list controls with menus when OptAll is specified Antonio Ospite
2019-01-03 18:00 ` [RFC PATCH 2/5] v4l2-ctl: list once when both OptListCtrls and OptListCtrlsMenus are there Antonio Ospite
2019-01-03 18:01 ` [RFC PATCH 3/5] v4l2-ctl: use a dedicated function to print the control class name Antonio Ospite
2019-01-03 18:01 ` Antonio Ospite [this message]
2019-01-03 18:01 ` [RFC PATCH 5/5] v4l2-ctl: add an option to list controls in a machine-readable format Antonio Ospite
2019-01-07 10:18 ` Hans Verkuil
2019-01-09 21:15 ` Antonio Ospite
2019-01-10 12:05 ` Hans Verkuil
2019-01-07 10:21 ` [RFC PATCH 0/5] v4l2-ctl: list controls values " Hans Verkuil
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20190103180102.12282-5-ao2@ao2.it \
--to=ao2@ao2.it \
--cc=linux-media@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).