From: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
To: linux-media@vger.kernel.org
Cc: Kieran Bingham <kieran.bingham@ideasonboard.com>
Subject: [PATCH yavta 5/7] Add support to reset device controls
Date: Wed, 20 Feb 2019 14:51:21 +0200 [thread overview]
Message-ID: <20190220125123.9410-6-laurent.pinchart@ideasonboard.com> (raw)
In-Reply-To: <20190220125123.9410-1-laurent.pinchart@ideasonboard.com>
From: Kieran Bingham <kieran.bingham@ideasonboard.com>
Provide a new option '--reset-controls' which will enumerate the
available controls on a device or sub-device, and re-initialise them to
defaults.
Signed-off-by: Kieran Bingham <kieran.bingham@ideasonboard.com>
Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
---
yavta.c | 62 ++++++++++++++++++++++++++++++++++++++++++++++++++++++---
1 file changed, 59 insertions(+), 3 deletions(-)
diff --git a/yavta.c b/yavta.c
index d1bfd380c03b..1490878c6f7e 100644
--- a/yavta.c
+++ b/yavta.c
@@ -527,7 +527,8 @@ static int query_control(struct device *dev, unsigned int id,
static int get_control(struct device *dev,
const struct v4l2_query_ext_ctrl *query,
- struct v4l2_ext_control *ctrl)
+ struct v4l2_ext_control *ctrl,
+ unsigned int which)
{
struct v4l2_ext_controls ctrls;
struct v4l2_control old;
@@ -536,7 +537,7 @@ static int get_control(struct device *dev,
memset(&ctrls, 0, sizeof(ctrls));
memset(ctrl, 0, sizeof(*ctrl));
- ctrls.ctrl_class = V4L2_CTRL_ID2CLASS(query->id);
+ ctrls.which = which;
ctrls.count = 1;
ctrls.controls = ctrl;
@@ -1295,7 +1296,7 @@ static int video_get_control(struct device *dev,
printf("current ");
- ret = get_control(dev, query, &ctrl);
+ ret = get_control(dev, query, &ctrl, V4L2_CTRL_WHICH_CUR_VAL);
if (ret < 0) {
printf("n/a\n");
printf("unable to get control 0x%8.8x: %s (%d).\n",
@@ -1478,6 +1479,51 @@ static void video_list_controls(struct device *dev)
printf("No control found.\n");
}
+static int video_reset_control(struct device *dev,
+ const struct v4l2_query_ext_ctrl *query)
+{
+ struct v4l2_ext_control ctrl = { .value = query->default_value, };
+ int ret;
+
+ if (query->flags & V4L2_CTRL_FLAG_DISABLED)
+ return 0;
+
+ if (query->type == V4L2_CTRL_TYPE_CTRL_CLASS)
+ return 0;
+
+ /*
+ * For controls with payloads the default value must be retrieved with
+ * a VIDIOC_G_EXT_CTRLS call. If the V4L2_CTRL_WHICH_DEF_VAL flag isn't
+ * supported by the kernel (it got introduced in v4.5, while controls
+ * with payloads were introduced in v3.17), there isn't much we can do,
+ * so skip resetting the control.
+ */
+ if (query->flags & V4L2_CTRL_FLAG_HAS_PAYLOAD) {
+ ret = get_control(dev, query, &ctrl, V4L2_CTRL_WHICH_DEF_VAL);
+ if (ret < 0)
+ return 0;
+ }
+
+ set_control(dev, query, &ctrl);
+
+ if (query->flags & V4L2_CTRL_FLAG_HAS_PAYLOAD)
+ free(ctrl.ptr);
+
+ return 1;
+}
+
+static void video_reset_controls(struct device *dev)
+{
+ int ret;
+
+ ret = video_for_each_control(dev, video_reset_control);
+ if (ret < 0)
+ return;
+
+ if (ret)
+ printf("%u control%s reset.\n", ret, ret > 1 ? "s" : "");
+}
+
static void video_enum_frame_intervals(struct device *dev, __u32 pixelformat,
unsigned int width, unsigned int height)
{
@@ -2099,6 +2145,7 @@ static void usage(const char *argv0)
printf(" --premultiplied Color components are premultiplied by alpha value\n");
printf(" --queue-late Queue buffers after streamon, not before\n");
printf(" --requeue-last Requeue the last buffers before streamoff\n");
+ printf(" --reset-controls Reset all available controls to their default value\n");
printf(" --timestamp-source Set timestamp source on output buffers [eof, soe]\n");
printf(" --skip n Skip the first n frames\n");
printf(" --sleep-forever Sleep forever after configuring the device\n");
@@ -2121,6 +2168,7 @@ static void usage(const char *argv0)
#define OPT_PREMULTIPLIED 269
#define OPT_QUEUE_LATE 270
#define OPT_DATA_PREFIX 271
+#define OPT_RESET_CONTROLS 272
static struct option opts[] = {
{"buffer-size", 1, 0, OPT_BUFFER_SIZE},
@@ -2149,6 +2197,7 @@ static struct option opts[] = {
{"queue-late", 0, 0, OPT_QUEUE_LATE},
{"get-control", 1, 0, 'r'},
{"requeue-last", 0, 0, OPT_REQUEUE_LAST},
+ {"reset-controls", 0, 0, OPT_RESET_CONTROLS},
{"realtime", 2, 0, 'R'},
{"size", 1, 0, 's'},
{"set-control", 1, 0, 'w'},
@@ -2176,6 +2225,7 @@ int main(int argc, char *argv[])
int do_enum_formats = 0, do_set_format = 0;
int do_enum_inputs = 0, do_set_input = 0;
int do_list_controls = 0, do_get_control = 0, do_set_control = 0;
+ int do_reset_controls = 0;
int do_sleep_forever = 0, do_requeue_last = 0;
int do_rt = 0, do_log_status = 0;
int no_query = 0, do_queue_late = 0;
@@ -2364,6 +2414,9 @@ int main(int argc, char *argv[])
case OPT_QUEUE_LATE:
do_queue_late = 1;
break;
+ case OPT_RESET_CONTROLS:
+ do_reset_controls = 1;
+ break;
case OPT_REQUEUE_LAST:
do_requeue_last = 1;
break;
@@ -2449,6 +2502,9 @@ int main(int argc, char *argv[])
if (do_list_controls)
video_list_controls(&dev);
+ if (do_reset_controls)
+ video_reset_controls(&dev);
+
if (do_enum_formats) {
printf("- Available formats:\n");
video_enum_formats(&dev, V4L2_BUF_TYPE_VIDEO_CAPTURE);
--
Regards,
Laurent Pinchart
next prev parent reply other threads:[~2019-02-20 12:51 UTC|newest]
Thread overview: 19+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-02-20 12:51 [PATCH yavta 0/7] Compound controls and controls reset support Laurent Pinchart
2019-02-20 12:51 ` [PATCH yavta 1/7] yavta: Refactor video_list_controls() Laurent Pinchart
2019-02-20 13:21 ` Sakari Ailus
2019-02-20 14:07 ` Laurent Pinchart
2019-02-20 14:13 ` Sakari Ailus
2019-02-20 12:51 ` [PATCH yavta 2/7] Implement VIDIOC_QUERY_EXT_CTRL support Laurent Pinchart
2019-02-20 12:51 ` [PATCH yavta 3/7] Implement compound control get support Laurent Pinchart
2019-02-20 14:06 ` Sakari Ailus
2019-02-20 14:55 ` Laurent Pinchart
2019-02-20 21:16 ` Sakari Ailus
2019-02-20 12:51 ` [PATCH yavta 4/7] Implement compound control set support Laurent Pinchart
2019-02-20 21:21 ` Sakari Ailus
2019-02-20 12:51 ` Laurent Pinchart [this message]
2019-02-20 12:51 ` [PATCH yavta 6/7] Support setting control from values stored in a file Laurent Pinchart
2019-02-20 21:26 ` Sakari Ailus
2019-02-22 11:47 ` Laurent Pinchart
2019-02-22 12:32 ` Sakari Ailus
2019-02-20 12:51 ` [PATCH yavta 7/7] Remove unneeded conditional compilation for old V4L2 API versions Laurent Pinchart
2019-02-20 21:33 ` [PATCH yavta 0/7] Compound controls and controls reset support Sakari Ailus
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=20190220125123.9410-6-laurent.pinchart@ideasonboard.com \
--to=laurent.pinchart@ideasonboard.com \
--cc=kieran.bingham@ideasonboard.com \
--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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.