* [PATCH v2 0/6] Support getting default values from any control
@ 2015-10-29 10:10 Ricardo Ribalda Delgado
2015-10-29 10:10 ` [PATCH v2 1/6] videodev2.h: Extend struct v4l2_ext_controls Ricardo Ribalda Delgado
` (5 more replies)
0 siblings, 6 replies; 9+ messages in thread
From: Ricardo Ribalda Delgado @ 2015-10-29 10:10 UTC (permalink / raw)
To: Mauro Carvalho Chehab, Mike Isely, Laurent Pinchart,
Hans Verkuil, Steven Toth, Sakari Ailus, Vincent Palatin,
linux-media, linux-kernel
Cc: Ricardo Ribalda Delgado
Integer controls provide a way to get their default/initial value, but
any other control (p_u32, p_u8.....) provide no other way to get the
initial value than unloading the module and loading it back.
*What is the actual problem?
I have a custom control with WIDTH integer values. Every value
represents the calibrated FPN (fixed pattern noise) correction value for that
column
-Application A changes the FPN correction value
-Application B wants to restore the calibrated value but it cant :(
*What is the proposed solution?
(Kudos to Hans Verkuil!!!)
The key change is in struct v4l2_ext_controls where the __u32 ctrl_class field
is changed to:
union {
__u32 ctrl_class;
__u32 which;
};
And two new defines are added:
#define V4L2_CTRL_WHICH_CUR_VAL 0
#define V4L2_CTRL_WHICH_DEF_VAL 0x0f000000
The 'which' field tells you which controls are get/set/tried.
V4L2_CTRL_WHICH_CUR_VAL: the current value of the controls
V4L2_CTRL_WHICH_DEF_VAL: the default value of the controls
V4L2_CTRL_CLASS_*: the current value of the controls belonging to the specified class.
Note: this is deprecated usage and is only there for backwards compatibility.
Which is also why I don't think there is a need to add V4L2_CTRL_WHICH_
aliases for these defines.
I have posted a copy of my working tree to:
https://github.com/ribalda/linux/tree/which_def_v5
Changelog v2 (compared to Support getting default values from any control
Rebase to latest version
Remove saa7164-* patches (Hans already ported them to v4l2-ctrl)
Update doc dates
Suggested by Laurent Pinchart <laurent.pinchart@ideasonboard.com>:
Fixes for the uvc implementation (error in lock handling) (Thanks!)
Changelog v1 (compared to v5 of New ioct VIDIOC_G_DEF_EXT_CTRLS):
Suggested by Hans Verkuil <hverkuil@xs4all.nl>:
Replace ioctl implementation with a new union on the struct v4l2_ext_controls
THANKS!
Ricardo Ribalda Delgado (6):
videodev2.h: Extend struct v4l2_ext_controls
media/core: Replace ctrl_class with which
media/v4l2-core: struct struct v4l2_ext_controls param which
usb/uvc: Support for V4L2_CTRL_WHICH_DEF_VAL
media/usb/pvrusb2: Support for V4L2_CTRL_WHICH_DEF_VAL
Docbook: media: Document changes on struct v4l2_ext_controls
Documentation/DocBook/media/v4l/v4l2.xml | 10 ++++
.../DocBook/media/v4l/vidioc-g-ext-ctrls.xml | 28 +++++++++--
drivers/media/platform/s5p-mfc/s5p_mfc_dec.c | 2 +-
drivers/media/platform/s5p-mfc/s5p_mfc_enc.c | 2 +-
drivers/media/usb/pvrusb2/pvrusb2-v4l2.c | 16 ++++++-
drivers/media/usb/uvc/uvc_v4l2.c | 20 ++++++++
drivers/media/v4l2-core/v4l2-compat-ioctl32.c | 6 +--
drivers/media/v4l2-core/v4l2-ctrls.c | 54 ++++++++++++++++------
drivers/media/v4l2-core/v4l2-ioctl.c | 14 +++---
include/uapi/linux/videodev2.h | 12 ++++-
10 files changed, 131 insertions(+), 33 deletions(-)
--
2.6.1
^ permalink raw reply [flat|nested] 9+ messages in thread
* [PATCH v2 1/6] videodev2.h: Extend struct v4l2_ext_controls
2015-10-29 10:10 [PATCH v2 0/6] Support getting default values from any control Ricardo Ribalda Delgado
@ 2015-10-29 10:10 ` Ricardo Ribalda Delgado
2015-10-29 10:10 ` [PATCH v2 2/6] media/core: Replace ctrl_class with which Ricardo Ribalda Delgado
` (4 subsequent siblings)
5 siblings, 0 replies; 9+ messages in thread
From: Ricardo Ribalda Delgado @ 2015-10-29 10:10 UTC (permalink / raw)
To: Mauro Carvalho Chehab, Mike Isely, Laurent Pinchart,
Hans Verkuil, Steven Toth, Sakari Ailus, Vincent Palatin,
linux-media, linux-kernel
Cc: Ricardo Ribalda Delgado
So it can be used to get the default value of a control.
Without this change it is not possible to get get the
default value of array controls.
Signed-off-by: Ricardo Ribalda Delgado <ricardo.ribalda@gmail.com>
---
include/uapi/linux/videodev2.h | 7 ++++++-
1 file changed, 6 insertions(+), 1 deletion(-)
diff --git a/include/uapi/linux/videodev2.h b/include/uapi/linux/videodev2.h
index a0e87d16b726..4d88ee2d268e 100644
--- a/include/uapi/linux/videodev2.h
+++ b/include/uapi/linux/videodev2.h
@@ -1476,7 +1476,10 @@ struct v4l2_ext_control {
} __attribute__ ((packed));
struct v4l2_ext_controls {
- __u32 ctrl_class;
+ union {
+ __u32 ctrl_class;
+ __u32 which;
+ };
__u32 count;
__u32 error_idx;
__u32 reserved[2];
@@ -1487,6 +1490,8 @@ struct v4l2_ext_controls {
#define V4L2_CTRL_ID2CLASS(id) ((id) & 0x0fff0000UL)
#define V4L2_CTRL_DRIVER_PRIV(id) (((id) & 0xffff) >= 0x1000)
#define V4L2_CTRL_MAX_DIMS (4)
+#define V4L2_CTRL_WHICH_CUR_VAL 0
+#define V4L2_CTRL_WHICH_DEF_VAL 0x0f000000
enum v4l2_ctrl_type {
V4L2_CTRL_TYPE_INTEGER = 1,
--
2.6.1
^ permalink raw reply related [flat|nested] 9+ messages in thread
* [PATCH v2 2/6] media/core: Replace ctrl_class with which
2015-10-29 10:10 [PATCH v2 0/6] Support getting default values from any control Ricardo Ribalda Delgado
2015-10-29 10:10 ` [PATCH v2 1/6] videodev2.h: Extend struct v4l2_ext_controls Ricardo Ribalda Delgado
@ 2015-10-29 10:10 ` Ricardo Ribalda Delgado
2015-10-29 10:10 ` [PATCH v2 3/6] media/v4l2-core: struct struct v4l2_ext_controls param which Ricardo Ribalda Delgado
` (3 subsequent siblings)
5 siblings, 0 replies; 9+ messages in thread
From: Ricardo Ribalda Delgado @ 2015-10-29 10:10 UTC (permalink / raw)
To: Mauro Carvalho Chehab, Mike Isely, Laurent Pinchart,
Hans Verkuil, Steven Toth, Sakari Ailus, Vincent Palatin,
linux-media, linux-kernel
Cc: Ricardo Ribalda Delgado
Replace the obsolete field ctrl_class with "which".
Make sure it not used in future modules by commenting out the field with
ifndef __KERNEL_ .
The field cannot be simply removed because that would be change on the
kenel API to the userspace (and we don't like that).
Signed-off-by: Ricardo Ribalda Delgado <ricardo.ribalda@gmail.com>
---
.../DocBook/media/v4l/vidioc-g-ext-ctrls.xml | 6 +++---
drivers/media/platform/s5p-mfc/s5p_mfc_dec.c | 2 +-
drivers/media/platform/s5p-mfc/s5p_mfc_enc.c | 2 +-
drivers/media/v4l2-core/v4l2-compat-ioctl32.c | 6 +++---
drivers/media/v4l2-core/v4l2-ctrls.c | 24 +++++++++++-----------
drivers/media/v4l2-core/v4l2-ioctl.c | 14 ++++++-------
include/uapi/linux/videodev2.h | 5 +++++
7 files changed, 32 insertions(+), 27 deletions(-)
diff --git a/Documentation/DocBook/media/v4l/vidioc-g-ext-ctrls.xml b/Documentation/DocBook/media/v4l/vidioc-g-ext-ctrls.xml
index 842536aae8b4..47f9fee91442 100644
--- a/Documentation/DocBook/media/v4l/vidioc-g-ext-ctrls.xml
+++ b/Documentation/DocBook/media/v4l/vidioc-g-ext-ctrls.xml
@@ -61,7 +61,7 @@ must belong to the same control class.</para>
<para>Applications must always fill in the
<structfield>count</structfield>,
-<structfield>ctrl_class</structfield>,
+<structfield>which</structfield>,
<structfield>controls</structfield> and
<structfield>reserved</structfield> fields of &v4l2-ext-controls;, and
initialize the &v4l2-ext-control; array pointed to by the
@@ -109,7 +109,7 @@ the driver whether wrong values are automatically adjusted to a valid
value or if an error is returned.</para>
<para>When the <structfield>id</structfield> or
-<structfield>ctrl_class</structfield> is invalid drivers return an
+<structfield>which</structfield> is invalid drivers return an
&EINVAL;. When the value is out of bounds drivers can choose to take
the closest valid value or return an &ERANGE;, whatever seems more
appropriate. In the first case the new value is set in
@@ -390,7 +390,7 @@ These controls are described in <xref linkend="rf-tuner-controls" />.</entry>
<listitem>
<para>The &v4l2-ext-control; <structfield>id</structfield>
is invalid, the &v4l2-ext-controls;
-<structfield>ctrl_class</structfield> is invalid, or the &v4l2-ext-control;
+<structfield>which</structfield> is invalid, or the &v4l2-ext-control;
<structfield>value</structfield> was inappropriate (e.g. the given menu
index is not supported by the driver). This error code is
also returned by the <constant>VIDIOC_S_EXT_CTRLS</constant> and
diff --git a/drivers/media/platform/s5p-mfc/s5p_mfc_dec.c b/drivers/media/platform/s5p-mfc/s5p_mfc_dec.c
index 8c5060a7534f..1c4998c221a2 100644
--- a/drivers/media/platform/s5p-mfc/s5p_mfc_dec.c
+++ b/drivers/media/platform/s5p-mfc/s5p_mfc_dec.c
@@ -1119,7 +1119,7 @@ const struct v4l2_ioctl_ops *get_dec_v4l2_ioctl_ops(void)
return &s5p_mfc_dec_ioctl_ops;
}
-#define IS_MFC51_PRIV(x) ((V4L2_CTRL_ID2CLASS(x) == V4L2_CTRL_CLASS_MPEG) \
+#define IS_MFC51_PRIV(x) ((V4L2_CTRL_ID2WHICH(x) == V4L2_CTRL_CLASS_MPEG) \
&& V4L2_CTRL_DRIVER_PRIV(x))
int s5p_mfc_dec_ctrls_setup(struct s5p_mfc_ctx *ctx)
diff --git a/drivers/media/platform/s5p-mfc/s5p_mfc_enc.c b/drivers/media/platform/s5p-mfc/s5p_mfc_enc.c
index 5c678ec9c9f2..115b7dac1d4c 100644
--- a/drivers/media/platform/s5p-mfc/s5p_mfc_enc.c
+++ b/drivers/media/platform/s5p-mfc/s5p_mfc_enc.c
@@ -2067,7 +2067,7 @@ const struct v4l2_ioctl_ops *get_enc_v4l2_ioctl_ops(void)
return &s5p_mfc_enc_ioctl_ops;
}
-#define IS_MFC51_PRIV(x) ((V4L2_CTRL_ID2CLASS(x) == V4L2_CTRL_CLASS_MPEG) \
+#define IS_MFC51_PRIV(x) ((V4L2_CTRL_ID2WHICH(x) == V4L2_CTRL_CLASS_MPEG) \
&& V4L2_CTRL_DRIVER_PRIV(x))
int s5p_mfc_enc_ctrls_setup(struct s5p_mfc_ctx *ctx)
diff --git a/drivers/media/v4l2-core/v4l2-compat-ioctl32.c b/drivers/media/v4l2-core/v4l2-compat-ioctl32.c
index 327e83ac2469..8fd84a67478a 100644
--- a/drivers/media/v4l2-core/v4l2-compat-ioctl32.c
+++ b/drivers/media/v4l2-core/v4l2-compat-ioctl32.c
@@ -630,7 +630,7 @@ static inline int put_v4l2_input32(struct v4l2_input *kp, struct v4l2_input32 __
}
struct v4l2_ext_controls32 {
- __u32 ctrl_class;
+ __u32 which;
__u32 count;
__u32 error_idx;
__u32 reserved[2];
@@ -673,7 +673,7 @@ static int get_v4l2_ext_controls32(struct v4l2_ext_controls *kp, struct v4l2_ext
compat_caddr_t p;
if (!access_ok(VERIFY_READ, up, sizeof(struct v4l2_ext_controls32)) ||
- get_user(kp->ctrl_class, &up->ctrl_class) ||
+ get_user(kp->which, &up->which) ||
get_user(kp->count, &up->count) ||
get_user(kp->error_idx, &up->error_idx) ||
copy_from_user(kp->reserved, up->reserved,
@@ -723,7 +723,7 @@ static int put_v4l2_ext_controls32(struct v4l2_ext_controls *kp, struct v4l2_ext
compat_caddr_t p;
if (!access_ok(VERIFY_WRITE, up, sizeof(struct v4l2_ext_controls32)) ||
- put_user(kp->ctrl_class, &up->ctrl_class) ||
+ put_user(kp->which, &up->which) ||
put_user(kp->count, &up->count) ||
put_user(kp->error_idx, &up->error_idx) ||
copy_to_user(up->reserved, kp->reserved, sizeof(up->reserved)))
diff --git a/drivers/media/v4l2-core/v4l2-ctrls.c b/drivers/media/v4l2-core/v4l2-ctrls.c
index 4a1d9fdd14bb..cf8388407d68 100644
--- a/drivers/media/v4l2-core/v4l2-ctrls.c
+++ b/drivers/media/v4l2-core/v4l2-ctrls.c
@@ -1762,7 +1762,7 @@ static struct v4l2_ctrl_ref *find_private_ref(
list_for_each_entry(ref, &hdl->ctrl_refs, node) {
/* Search for private user controls that are compatible with
VIDIOC_G/S_CTRL. */
- if (V4L2_CTRL_ID2CLASS(ref->ctrl->id) == V4L2_CTRL_CLASS_USER &&
+ if (V4L2_CTRL_ID2WHICH(ref->ctrl->id) == V4L2_CTRL_CLASS_USER &&
V4L2_CTRL_DRIVER_PRIV(ref->ctrl->id)) {
if (!ref->ctrl->is_int)
continue;
@@ -1831,7 +1831,7 @@ static int handler_new_ref(struct v4l2_ctrl_handler *hdl,
struct v4l2_ctrl_ref *ref;
struct v4l2_ctrl_ref *new_ref;
u32 id = ctrl->id;
- u32 class_ctrl = V4L2_CTRL_ID2CLASS(id) | 1;
+ u32 class_ctrl = V4L2_CTRL_ID2WHICH(id) | 1;
int bucket = id % hdl->nr_of_buckets; /* which bucket to use */
/*
@@ -2253,9 +2253,9 @@ EXPORT_SYMBOL(v4l2_ctrl_add_handler);
bool v4l2_ctrl_radio_filter(const struct v4l2_ctrl *ctrl)
{
- if (V4L2_CTRL_ID2CLASS(ctrl->id) == V4L2_CTRL_CLASS_FM_TX)
+ if (V4L2_CTRL_ID2WHICH(ctrl->id) == V4L2_CTRL_CLASS_FM_TX)
return true;
- if (V4L2_CTRL_ID2CLASS(ctrl->id) == V4L2_CTRL_CLASS_FM_RX)
+ if (V4L2_CTRL_ID2WHICH(ctrl->id) == V4L2_CTRL_CLASS_FM_RX)
return true;
switch (ctrl->id) {
case V4L2_CID_AUDIO_MUTE:
@@ -2710,7 +2710,7 @@ static int prepare_ext_ctrls(struct v4l2_ctrl_handler *hdl,
cs->error_idx = i;
- if (cs->ctrl_class && V4L2_CTRL_ID2CLASS(id) != cs->ctrl_class)
+ if (cs->which && V4L2_CTRL_ID2WHICH(id) != cs->which)
return -EINVAL;
/* Old-style private controls are not allowed for
@@ -2787,11 +2787,11 @@ static int prepare_ext_ctrls(struct v4l2_ctrl_handler *hdl,
/* Handles the corner case where cs->count == 0. It checks whether the
specified control class exists. If that class ID is 0, then it checks
whether there are any controls at all. */
-static int class_check(struct v4l2_ctrl_handler *hdl, u32 ctrl_class)
+static int class_check(struct v4l2_ctrl_handler *hdl, u32 which)
{
- if (ctrl_class == 0)
+ if (!which)
return list_empty(&hdl->ctrl_refs) ? -EINVAL : 0;
- return find_ref_lock(hdl, ctrl_class | 1) ? 0 : -EINVAL;
+ return find_ref_lock(hdl, which | 1) ? 0 : -EINVAL;
}
@@ -2805,13 +2805,13 @@ int v4l2_g_ext_ctrls(struct v4l2_ctrl_handler *hdl, struct v4l2_ext_controls *cs
int i, j;
cs->error_idx = cs->count;
- cs->ctrl_class = V4L2_CTRL_ID2CLASS(cs->ctrl_class);
+ cs->which = V4L2_CTRL_ID2WHICH(cs->which);
if (hdl == NULL)
return -EINVAL;
if (cs->count == 0)
- return class_check(hdl, cs->ctrl_class);
+ return class_check(hdl, cs->which);
if (cs->count > ARRAY_SIZE(helper)) {
helpers = kmalloc_array(cs->count, sizeof(helper[0]),
@@ -3064,13 +3064,13 @@ static int try_set_ext_ctrls(struct v4l2_fh *fh, struct v4l2_ctrl_handler *hdl,
int ret;
cs->error_idx = cs->count;
- cs->ctrl_class = V4L2_CTRL_ID2CLASS(cs->ctrl_class);
+ cs->which = V4L2_CTRL_ID2WHICH(cs->which);
if (hdl == NULL)
return -EINVAL;
if (cs->count == 0)
- return class_check(hdl, cs->ctrl_class);
+ return class_check(hdl, cs->which);
if (cs->count > ARRAY_SIZE(helper)) {
helpers = kmalloc_array(cs->count, sizeof(helper[0]),
diff --git a/drivers/media/v4l2-core/v4l2-ioctl.c b/drivers/media/v4l2-core/v4l2-ioctl.c
index 7486af2c8ae4..8a018c6dd16a 100644
--- a/drivers/media/v4l2-core/v4l2-ioctl.c
+++ b/drivers/media/v4l2-core/v4l2-ioctl.c
@@ -565,8 +565,8 @@ static void v4l_print_ext_controls(const void *arg, bool write_only)
const struct v4l2_ext_controls *p = arg;
int i;
- pr_cont("class=0x%x, count=%d, error_idx=%d",
- p->ctrl_class, p->count, p->error_idx);
+ pr_cont("which=0x%x, count=%d, error_idx=%d",
+ p->which, p->count, p->error_idx);
for (i = 0; i < p->count; i++) {
if (!p->controls[i].size)
pr_cont(", id/val=0x%x/0x%x",
@@ -902,13 +902,13 @@ static int check_ext_ctrls(struct v4l2_ext_controls *c, int allow_priv)
Only when passed in through VIDIOC_G_CTRL and VIDIOC_S_CTRL
is it allowed for backwards compatibility.
*/
- if (!allow_priv && c->ctrl_class == V4L2_CID_PRIVATE_BASE)
+ if (!allow_priv && c->which == V4L2_CID_PRIVATE_BASE)
return 0;
- if (c->ctrl_class == 0)
+ if (!c->which)
return 1;
/* Check that all controls are from the same control class. */
for (i = 0; i < c->count; i++) {
- if (V4L2_CTRL_ID2CLASS(c->controls[i].id) != c->ctrl_class) {
+ if (V4L2_CTRL_ID2WHICH(c->controls[i].id) != c->which) {
c->error_idx = i;
return 0;
}
@@ -1969,7 +1969,7 @@ static int v4l_g_ctrl(const struct v4l2_ioctl_ops *ops,
if (ops->vidioc_g_ext_ctrls == NULL)
return -ENOTTY;
- ctrls.ctrl_class = V4L2_CTRL_ID2CLASS(p->id);
+ ctrls.which = V4L2_CTRL_ID2WHICH(p->id);
ctrls.count = 1;
ctrls.controls = &ctrl;
ctrl.id = p->id;
@@ -2003,7 +2003,7 @@ static int v4l_s_ctrl(const struct v4l2_ioctl_ops *ops,
if (ops->vidioc_s_ext_ctrls == NULL)
return -ENOTTY;
- ctrls.ctrl_class = V4L2_CTRL_ID2CLASS(p->id);
+ ctrls.which = V4L2_CTRL_ID2WHICH(p->id);
ctrls.count = 1;
ctrls.controls = &ctrl;
ctrl.id = p->id;
diff --git a/include/uapi/linux/videodev2.h b/include/uapi/linux/videodev2.h
index 4d88ee2d268e..bd2dc9431ac1 100644
--- a/include/uapi/linux/videodev2.h
+++ b/include/uapi/linux/videodev2.h
@@ -1477,7 +1477,9 @@ struct v4l2_ext_control {
struct v4l2_ext_controls {
union {
+#ifndef __KERNEL__
__u32 ctrl_class;
+#endif
__u32 which;
};
__u32 count;
@@ -1487,7 +1489,10 @@ struct v4l2_ext_controls {
};
#define V4L2_CTRL_ID_MASK (0x0fffffff)
+#ifndef __KERNEL__
#define V4L2_CTRL_ID2CLASS(id) ((id) & 0x0fff0000UL)
+#endif
+#define V4L2_CTRL_ID2WHICH(id) ((id) & 0x0fff0000UL)
#define V4L2_CTRL_DRIVER_PRIV(id) (((id) & 0xffff) >= 0x1000)
#define V4L2_CTRL_MAX_DIMS (4)
#define V4L2_CTRL_WHICH_CUR_VAL 0
--
2.6.1
^ permalink raw reply related [flat|nested] 9+ messages in thread
* [PATCH v2 3/6] media/v4l2-core: struct struct v4l2_ext_controls param which
2015-10-29 10:10 [PATCH v2 0/6] Support getting default values from any control Ricardo Ribalda Delgado
2015-10-29 10:10 ` [PATCH v2 1/6] videodev2.h: Extend struct v4l2_ext_controls Ricardo Ribalda Delgado
2015-10-29 10:10 ` [PATCH v2 2/6] media/core: Replace ctrl_class with which Ricardo Ribalda Delgado
@ 2015-10-29 10:10 ` Ricardo Ribalda Delgado
2015-10-29 10:10 ` [PATCH v2 4/6] usb/uvc: Support for V4L2_CTRL_WHICH_DEF_VAL Ricardo Ribalda Delgado
` (2 subsequent siblings)
5 siblings, 0 replies; 9+ messages in thread
From: Ricardo Ribalda Delgado @ 2015-10-29 10:10 UTC (permalink / raw)
To: Mauro Carvalho Chehab, Mike Isely, Laurent Pinchart,
Hans Verkuil, Steven Toth, Sakari Ailus, Vincent Palatin,
linux-media, linux-kernel
Cc: Ricardo Ribalda Delgado
Support for new field which on v4l2_ext_controls, used to get the
default value of one or more controls.
Signed-off-by: Ricardo Ribalda Delgado <ricardo.ribalda@gmail.com>
---
drivers/media/v4l2-core/v4l2-ctrls.c | 34 +++++++++++++++++++++++++++++-----
1 file changed, 29 insertions(+), 5 deletions(-)
diff --git a/drivers/media/v4l2-core/v4l2-ctrls.c b/drivers/media/v4l2-core/v4l2-ctrls.c
index cf8388407d68..5216a00b2b16 100644
--- a/drivers/media/v4l2-core/v4l2-ctrls.c
+++ b/drivers/media/v4l2-core/v4l2-ctrls.c
@@ -1491,6 +1491,17 @@ static int new_to_user(struct v4l2_ext_control *c,
return ptr_to_user(c, ctrl, ctrl->p_new);
}
+/* Helper function: copy the initial control value back to the caller */
+static int def_to_user(struct v4l2_ext_control *c, struct v4l2_ctrl *ctrl)
+{
+ int idx;
+
+ for (idx = 0; idx < ctrl->elems; idx++)
+ ctrl->type_ops->init(ctrl, idx, ctrl->p_new);
+
+ return ptr_to_user(c, ctrl, ctrl->p_new);
+}
+
/* Helper function: copy the caller-provider value to the given control value */
static int user_to_ptr(struct v4l2_ext_control *c,
struct v4l2_ctrl *ctrl,
@@ -2710,7 +2721,9 @@ static int prepare_ext_ctrls(struct v4l2_ctrl_handler *hdl,
cs->error_idx = i;
- if (cs->which && V4L2_CTRL_ID2WHICH(id) != cs->which)
+ if (cs->which &&
+ cs->which != V4L2_CTRL_WHICH_DEF_VAL &&
+ V4L2_CTRL_ID2WHICH(id) != cs->which)
return -EINVAL;
/* Old-style private controls are not allowed for
@@ -2789,7 +2802,7 @@ static int prepare_ext_ctrls(struct v4l2_ctrl_handler *hdl,
whether there are any controls at all. */
static int class_check(struct v4l2_ctrl_handler *hdl, u32 which)
{
- if (!which)
+ if (which == 0 || which == V4L2_CTRL_WHICH_DEF_VAL)
return list_empty(&hdl->ctrl_refs) ? -EINVAL : 0;
return find_ref_lock(hdl, which | 1) ? 0 : -EINVAL;
}
@@ -2803,6 +2816,9 @@ int v4l2_g_ext_ctrls(struct v4l2_ctrl_handler *hdl, struct v4l2_ext_controls *cs
struct v4l2_ctrl_helper *helpers = helper;
int ret;
int i, j;
+ bool def_value;
+
+ def_value = (cs->which == V4L2_CTRL_WHICH_DEF_VAL);
cs->error_idx = cs->count;
cs->which = V4L2_CTRL_ID2WHICH(cs->which);
@@ -2829,9 +2845,11 @@ int v4l2_g_ext_ctrls(struct v4l2_ctrl_handler *hdl, struct v4l2_ext_controls *cs
for (i = 0; !ret && i < cs->count; i++) {
int (*ctrl_to_user)(struct v4l2_ext_control *c,
- struct v4l2_ctrl *ctrl) = cur_to_user;
+ struct v4l2_ctrl *ctrl);
struct v4l2_ctrl *master;
+ ctrl_to_user = def_value ? def_to_user : cur_to_user;
+
if (helpers[i].mref == NULL)
continue;
@@ -2841,8 +2859,9 @@ int v4l2_g_ext_ctrls(struct v4l2_ctrl_handler *hdl, struct v4l2_ext_controls *cs
v4l2_ctrl_lock(master);
/* g_volatile_ctrl will update the new control values */
- if ((master->flags & V4L2_CTRL_FLAG_VOLATILE) ||
- (master->has_volatiles && !is_cur_manual(master))) {
+ if (!def_value &&
+ ((master->flags & V4L2_CTRL_FLAG_VOLATILE) ||
+ (master->has_volatiles && !is_cur_manual(master)))) {
for (j = 0; j < master->ncontrols; j++)
cur_to_new(master->cluster[j]);
ret = call_op(master, g_volatile_ctrl);
@@ -3064,6 +3083,11 @@ static int try_set_ext_ctrls(struct v4l2_fh *fh, struct v4l2_ctrl_handler *hdl,
int ret;
cs->error_idx = cs->count;
+
+ /* Default value cannot be changed */
+ if (cs->which == V4L2_CTRL_WHICH_DEF_VAL)
+ return -EINVAL;
+
cs->which = V4L2_CTRL_ID2WHICH(cs->which);
if (hdl == NULL)
--
2.6.1
^ permalink raw reply related [flat|nested] 9+ messages in thread
* [PATCH v2 4/6] usb/uvc: Support for V4L2_CTRL_WHICH_DEF_VAL
2015-10-29 10:10 [PATCH v2 0/6] Support getting default values from any control Ricardo Ribalda Delgado
` (2 preceding siblings ...)
2015-10-29 10:10 ` [PATCH v2 3/6] media/v4l2-core: struct struct v4l2_ext_controls param which Ricardo Ribalda Delgado
@ 2015-10-29 10:10 ` Ricardo Ribalda Delgado
2015-10-30 14:29 ` Laurent Pinchart
2015-10-29 10:10 ` [PATCH v2 5/6] media/usb/pvrusb2: " Ricardo Ribalda Delgado
2015-10-29 10:10 ` [PATCH v2 6/6] Docbook: media: Document changes on struct v4l2_ext_controls Ricardo Ribalda Delgado
5 siblings, 1 reply; 9+ messages in thread
From: Ricardo Ribalda Delgado @ 2015-10-29 10:10 UTC (permalink / raw)
To: Mauro Carvalho Chehab, Mike Isely, Laurent Pinchart,
Hans Verkuil, Steven Toth, Sakari Ailus, Vincent Palatin,
linux-media, linux-kernel
Cc: Ricardo Ribalda Delgado
This driver does not use the control infrastructure.
Add support for the new field which on structure
v4l2_ext_controls
Signed-off-by: Ricardo Ribalda Delgado <ricardo.ribalda@gmail.com>
---
drivers/media/usb/uvc/uvc_v4l2.c | 20 ++++++++++++++++++++
1 file changed, 20 insertions(+)
diff --git a/drivers/media/usb/uvc/uvc_v4l2.c b/drivers/media/usb/uvc/uvc_v4l2.c
index 2764f43607c1..d7723ce772b3 100644
--- a/drivers/media/usb/uvc/uvc_v4l2.c
+++ b/drivers/media/usb/uvc/uvc_v4l2.c
@@ -983,6 +983,22 @@ static int uvc_ioctl_g_ext_ctrls(struct file *file, void *fh,
unsigned int i;
int ret;
+ if (ctrls->which == V4L2_CTRL_WHICH_DEF_VAL) {
+ for (i = 0; i < ctrls->count; ++ctrl, ++i) {
+ struct v4l2_queryctrl qc = { .id = ctrl->id };
+
+ ret = uvc_query_v4l2_ctrl(chain, &qc);
+ if (ret < 0) {
+ ctrls->error_idx = i;
+ return ret;
+ }
+
+ ctrl->value = qc.default_value;
+ }
+
+ return 0;
+ }
+
ret = uvc_ctrl_begin(chain);
if (ret < 0)
return ret;
@@ -1010,6 +1026,10 @@ static int uvc_ioctl_s_try_ext_ctrls(struct uvc_fh *handle,
unsigned int i;
int ret;
+ /* Default value cannot be changed */
+ if (ctrls->which == V4L2_CTRL_WHICH_DEF_VAL)
+ return -EINVAL;
+
ret = uvc_ctrl_begin(chain);
if (ret < 0)
return ret;
--
2.6.1
^ permalink raw reply related [flat|nested] 9+ messages in thread
* [PATCH v2 5/6] media/usb/pvrusb2: Support for V4L2_CTRL_WHICH_DEF_VAL
2015-10-29 10:10 [PATCH v2 0/6] Support getting default values from any control Ricardo Ribalda Delgado
` (3 preceding siblings ...)
2015-10-29 10:10 ` [PATCH v2 4/6] usb/uvc: Support for V4L2_CTRL_WHICH_DEF_VAL Ricardo Ribalda Delgado
@ 2015-10-29 10:10 ` Ricardo Ribalda Delgado
2015-10-29 15:33 ` Mike Isely
2015-10-29 10:10 ` [PATCH v2 6/6] Docbook: media: Document changes on struct v4l2_ext_controls Ricardo Ribalda Delgado
5 siblings, 1 reply; 9+ messages in thread
From: Ricardo Ribalda Delgado @ 2015-10-29 10:10 UTC (permalink / raw)
To: Mauro Carvalho Chehab, Mike Isely, Laurent Pinchart,
Hans Verkuil, Steven Toth, Sakari Ailus, Vincent Palatin,
linux-media, linux-kernel
Cc: Ricardo Ribalda Delgado
This driver does not use the control infrastructure.
Add support for the new field which on structure
v4l2_ext_controls
Acked-by: Mike Isely <isely@pobox.com>
Signed-off-by: Ricardo Ribalda Delgado <ricardo.ribalda@gmail.com>
---
drivers/media/usb/pvrusb2/pvrusb2-v4l2.c | 16 ++++++++++++++--
1 file changed, 14 insertions(+), 2 deletions(-)
diff --git a/drivers/media/usb/pvrusb2/pvrusb2-v4l2.c b/drivers/media/usb/pvrusb2/pvrusb2-v4l2.c
index 1c5f85bf7ed4..81f788b7b242 100644
--- a/drivers/media/usb/pvrusb2/pvrusb2-v4l2.c
+++ b/drivers/media/usb/pvrusb2/pvrusb2-v4l2.c
@@ -628,6 +628,7 @@ static int pvr2_g_ext_ctrls(struct file *file, void *priv,
struct pvr2_v4l2_fh *fh = file->private_data;
struct pvr2_hdw *hdw = fh->channel.mc_head->hdw;
struct v4l2_ext_control *ctrl;
+ struct pvr2_ctrl *cptr;
unsigned int idx;
int val;
int ret;
@@ -635,8 +636,15 @@ static int pvr2_g_ext_ctrls(struct file *file, void *priv,
ret = 0;
for (idx = 0; idx < ctls->count; idx++) {
ctrl = ctls->controls + idx;
- ret = pvr2_ctrl_get_value(
- pvr2_hdw_get_ctrl_v4l(hdw, ctrl->id), &val);
+ cptr = pvr2_hdw_get_ctrl_v4l(hdw, ctrl->id);
+ if (cptr) {
+ if (ctls->which == V4L2_CTRL_WHICH_DEF_VAL)
+ pvr2_ctrl_get_def(cptr, &val);
+ else
+ ret = pvr2_ctrl_get_value(cptr, &val);
+ } else
+ ret = -EINVAL;
+
if (ret) {
ctls->error_idx = idx;
return ret;
@@ -658,6 +666,10 @@ static int pvr2_s_ext_ctrls(struct file *file, void *priv,
unsigned int idx;
int ret;
+ /* Default value cannot be changed */
+ if (ctls->which == V4L2_CTRL_WHICH_DEF_VAL)
+ return -EINVAL;
+
ret = 0;
for (idx = 0; idx < ctls->count; idx++) {
ctrl = ctls->controls + idx;
--
2.6.1
^ permalink raw reply related [flat|nested] 9+ messages in thread
* [PATCH v2 6/6] Docbook: media: Document changes on struct v4l2_ext_controls
2015-10-29 10:10 [PATCH v2 0/6] Support getting default values from any control Ricardo Ribalda Delgado
` (4 preceding siblings ...)
2015-10-29 10:10 ` [PATCH v2 5/6] media/usb/pvrusb2: " Ricardo Ribalda Delgado
@ 2015-10-29 10:10 ` Ricardo Ribalda Delgado
5 siblings, 0 replies; 9+ messages in thread
From: Ricardo Ribalda Delgado @ 2015-10-29 10:10 UTC (permalink / raw)
To: Mauro Carvalho Chehab, Mike Isely, Laurent Pinchart,
Hans Verkuil, Steven Toth, Sakari Ailus, Vincent Palatin,
linux-media, linux-kernel
Cc: Ricardo Ribalda Delgado
Vidioc-g-ext-ctrls can now be used to get the default value of the
controls.
Signed-off-by: Ricardo Ribalda Delgado <ricardo.ribalda@gmail.com>
---
Documentation/DocBook/media/v4l/v4l2.xml | 10 ++++++++++
.../DocBook/media/v4l/vidioc-g-ext-ctrls.xml | 22 ++++++++++++++++++++++
2 files changed, 32 insertions(+)
diff --git a/Documentation/DocBook/media/v4l/v4l2.xml b/Documentation/DocBook/media/v4l/v4l2.xml
index 7e61643358de..42e626d6c936 100644
--- a/Documentation/DocBook/media/v4l/v4l2.xml
+++ b/Documentation/DocBook/media/v4l/v4l2.xml
@@ -152,6 +152,16 @@ structs, ioctls) must be noted in more detail in the history chapter
(compat.xml), along with the possible impact on existing drivers and
applications. -->
<revision>
+ <revnumber>4.5</revnumber>
+ <date>2015-10-29</date>
+ <authorinitials>rr</authorinitials>
+ <revremark>Extend vidioc-g-ext-ctrls;. Replace ctrl_class with a new
+union with ctrl_class and which. Which is used to select the current value of
+the control or the default value.
+ </revremark>
+ </revision>
+
+ <revision>
<revnumber>4.4</revnumber>
<date>2015-05-26</date>
<authorinitials>ap</authorinitials>
diff --git a/Documentation/DocBook/media/v4l/vidioc-g-ext-ctrls.xml b/Documentation/DocBook/media/v4l/vidioc-g-ext-ctrls.xml
index 47f9fee91442..eb82f7e7d06b 100644
--- a/Documentation/DocBook/media/v4l/vidioc-g-ext-ctrls.xml
+++ b/Documentation/DocBook/media/v4l/vidioc-g-ext-ctrls.xml
@@ -223,7 +223,12 @@ Valid if <constant>V4L2_CTRL_FLAG_HAS_PAYLOAD</constant> is set for this control
<tgroup cols="3">
&cs-str;
<tbody valign="top">
+ <row>
+ <entry>union</entry>
+ <entry>(anonymous)</entry>
+ </row>
<row>
+ <entry></entry>
<entry>__u32</entry>
<entry><structfield>ctrl_class</structfield></entry>
<entry>The control class to which all controls belong, see
@@ -235,6 +240,23 @@ with a <structfield>count</structfield> of 0. If that succeeds, then the driver
supports this feature.</entry>
</row>
<row>
+ <entry></entry>
+ <entry>__u32</entry>
+ <entry><structfield>which</structfield></entry>
+ <entry><para>Which value of the control to get/set/try. <constant>V4L2_CTRL_WHICH_CUR_VAL</constant>
+will return the current value of the control and <constant>V4L2_CTRL_WHICH_DEF_VAL</constant> will
+return the default value of the control. Please note that you can only get the default value of the
+control, you cannot set or try it.</para>
+<para>For backwards compatibility you can also use a control class here (see
+<xref linkend="ctrl-class" />). In that case all controls have to belong to that
+control class. This usage is deprecated, instead just use <constant>V4L2_CTRL_WHICH_CUR_VAL</constant>.
+There are some very old drivers that do not yet support <constant>V4L2_CTRL_WHICH_CUR_VAL</constant>
+and that require a control class here. You can test for such drivers by setting ctrl_class to
+<constant>V4L2_CTRL_WHICH_CUR_VAL</constant> and calling VIDIOC_TRY_EXT_CTRLS with a count of 0.
+If that fails, then the driver does not support <constant>V4L2_CTRL_WHICH_CUR_VAL</constant>.</para>
+</entry>
+ </row>
+ <row>
<entry>__u32</entry>
<entry><structfield>count</structfield></entry>
<entry>The number of controls in the controls array. May
--
2.6.1
^ permalink raw reply related [flat|nested] 9+ messages in thread
* Re: [PATCH v2 5/6] media/usb/pvrusb2: Support for V4L2_CTRL_WHICH_DEF_VAL
2015-10-29 10:10 ` [PATCH v2 5/6] media/usb/pvrusb2: " Ricardo Ribalda Delgado
@ 2015-10-29 15:33 ` Mike Isely
0 siblings, 0 replies; 9+ messages in thread
From: Mike Isely @ 2015-10-29 15:33 UTC (permalink / raw)
To: Ricardo Ribalda Delgado
Cc: Mauro Carvalho Chehab, Laurent Pinchart, Hans Verkuil,
Steven Toth, Sakari Ailus, Vincent Palatin, linux-media,
Linux Kernel Mailing List, Mike Isely at pobox
Looks good to me (still), including now the change I had previously
suggested. For the record, the ack still applies. (I guess you can
consider this to be an ack of the ack...)
-Mike
On Thu, 29 Oct 2015, Ricardo Ribalda Delgado wrote:
> This driver does not use the control infrastructure.
> Add support for the new field which on structure
> v4l2_ext_controls
>
> Acked-by: Mike Isely <isely@pobox.com>
> Signed-off-by: Ricardo Ribalda Delgado <ricardo.ribalda@gmail.com>
> ---
> drivers/media/usb/pvrusb2/pvrusb2-v4l2.c | 16 ++++++++++++++--
> 1 file changed, 14 insertions(+), 2 deletions(-)
>
> diff --git a/drivers/media/usb/pvrusb2/pvrusb2-v4l2.c b/drivers/media/usb/pvrusb2/pvrusb2-v4l2.c
> index 1c5f85bf7ed4..81f788b7b242 100644
> --- a/drivers/media/usb/pvrusb2/pvrusb2-v4l2.c
> +++ b/drivers/media/usb/pvrusb2/pvrusb2-v4l2.c
> @@ -628,6 +628,7 @@ static int pvr2_g_ext_ctrls(struct file *file, void *priv,
> struct pvr2_v4l2_fh *fh = file->private_data;
> struct pvr2_hdw *hdw = fh->channel.mc_head->hdw;
> struct v4l2_ext_control *ctrl;
> + struct pvr2_ctrl *cptr;
> unsigned int idx;
> int val;
> int ret;
> @@ -635,8 +636,15 @@ static int pvr2_g_ext_ctrls(struct file *file, void *priv,
> ret = 0;
> for (idx = 0; idx < ctls->count; idx++) {
> ctrl = ctls->controls + idx;
> - ret = pvr2_ctrl_get_value(
> - pvr2_hdw_get_ctrl_v4l(hdw, ctrl->id), &val);
> + cptr = pvr2_hdw_get_ctrl_v4l(hdw, ctrl->id);
> + if (cptr) {
> + if (ctls->which == V4L2_CTRL_WHICH_DEF_VAL)
> + pvr2_ctrl_get_def(cptr, &val);
> + else
> + ret = pvr2_ctrl_get_value(cptr, &val);
> + } else
> + ret = -EINVAL;
> +
> if (ret) {
> ctls->error_idx = idx;
> return ret;
> @@ -658,6 +666,10 @@ static int pvr2_s_ext_ctrls(struct file *file, void *priv,
> unsigned int idx;
> int ret;
>
> + /* Default value cannot be changed */
> + if (ctls->which == V4L2_CTRL_WHICH_DEF_VAL)
> + return -EINVAL;
> +
> ret = 0;
> for (idx = 0; idx < ctls->count; idx++) {
> ctrl = ctls->controls + idx;
>
--
Mike Isely
isely @ isely (dot) net
PGP: 03 54 43 4D 75 E5 CC 92 71 16 01 E2 B5 F5 C1 E8
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: [PATCH v2 4/6] usb/uvc: Support for V4L2_CTRL_WHICH_DEF_VAL
2015-10-29 10:10 ` [PATCH v2 4/6] usb/uvc: Support for V4L2_CTRL_WHICH_DEF_VAL Ricardo Ribalda Delgado
@ 2015-10-30 14:29 ` Laurent Pinchart
0 siblings, 0 replies; 9+ messages in thread
From: Laurent Pinchart @ 2015-10-30 14:29 UTC (permalink / raw)
To: Ricardo Ribalda Delgado
Cc: Mauro Carvalho Chehab, Mike Isely, Hans Verkuil, Steven Toth,
Sakari Ailus, Vincent Palatin, linux-media, linux-kernel
Hi Ricardo,
Thank you for the patch.
On Thursday 29 October 2015 11:10:30 Ricardo Ribalda Delgado wrote:
> This driver does not use the control infrastructure.
> Add support for the new field which on structure
> v4l2_ext_controls
>
> Signed-off-by: Ricardo Ribalda Delgado <ricardo.ribalda@gmail.com>
Acked-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
> ---
> drivers/media/usb/uvc/uvc_v4l2.c | 20 ++++++++++++++++++++
> 1 file changed, 20 insertions(+)
>
> diff --git a/drivers/media/usb/uvc/uvc_v4l2.c
> b/drivers/media/usb/uvc/uvc_v4l2.c index 2764f43607c1..d7723ce772b3 100644
> --- a/drivers/media/usb/uvc/uvc_v4l2.c
> +++ b/drivers/media/usb/uvc/uvc_v4l2.c
> @@ -983,6 +983,22 @@ static int uvc_ioctl_g_ext_ctrls(struct file *file,
> void *fh, unsigned int i;
> int ret;
>
> + if (ctrls->which == V4L2_CTRL_WHICH_DEF_VAL) {
> + for (i = 0; i < ctrls->count; ++ctrl, ++i) {
> + struct v4l2_queryctrl qc = { .id = ctrl->id };
> +
> + ret = uvc_query_v4l2_ctrl(chain, &qc);
> + if (ret < 0) {
> + ctrls->error_idx = i;
> + return ret;
> + }
> +
> + ctrl->value = qc.default_value;
> + }
> +
> + return 0;
> + }
> +
> ret = uvc_ctrl_begin(chain);
> if (ret < 0)
> return ret;
> @@ -1010,6 +1026,10 @@ static int uvc_ioctl_s_try_ext_ctrls(struct uvc_fh
> *handle, unsigned int i;
> int ret;
>
> + /* Default value cannot be changed */
> + if (ctrls->which == V4L2_CTRL_WHICH_DEF_VAL)
> + return -EINVAL;
> +
> ret = uvc_ctrl_begin(chain);
> if (ret < 0)
> return ret;
--
Regards,
Laurent Pinchart
^ permalink raw reply [flat|nested] 9+ messages in thread
end of thread, other threads:[~2015-10-30 14:29 UTC | newest]
Thread overview: 9+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-10-29 10:10 [PATCH v2 0/6] Support getting default values from any control Ricardo Ribalda Delgado
2015-10-29 10:10 ` [PATCH v2 1/6] videodev2.h: Extend struct v4l2_ext_controls Ricardo Ribalda Delgado
2015-10-29 10:10 ` [PATCH v2 2/6] media/core: Replace ctrl_class with which Ricardo Ribalda Delgado
2015-10-29 10:10 ` [PATCH v2 3/6] media/v4l2-core: struct struct v4l2_ext_controls param which Ricardo Ribalda Delgado
2015-10-29 10:10 ` [PATCH v2 4/6] usb/uvc: Support for V4L2_CTRL_WHICH_DEF_VAL Ricardo Ribalda Delgado
2015-10-30 14:29 ` Laurent Pinchart
2015-10-29 10:10 ` [PATCH v2 5/6] media/usb/pvrusb2: " Ricardo Ribalda Delgado
2015-10-29 15:33 ` Mike Isely
2015-10-29 10:10 ` [PATCH v2 6/6] Docbook: media: Document changes on struct v4l2_ext_controls Ricardo Ribalda Delgado
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).