Skip to content

Commit 20d88ee

Browse files
Hans Verkuilmchehab
authored andcommitted
[media] v4l2-ctrls: prepare for array support
Add dims, nr_of_dims and elems fields to the core control structures in preparation for N-dimensional array support. Signed-off-by: Hans Verkuil <hans.verkuil@cisco.com> Signed-off-by: Mauro Carvalho Chehab <m.chehab@samsung.com>
1 parent 2a9ec37 commit 20d88ee

2 files changed

Lines changed: 32 additions & 9 deletions

File tree

‎drivers/media/v4l2-core/v4l2-ctrls.c‎

Lines changed: 24 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1759,18 +1759,27 @@ static struct v4l2_ctrl *v4l2_ctrl_new(struct v4l2_ctrl_handler *hdl,
17591759
const struct v4l2_ctrl_type_ops *type_ops,
17601760
u32 id, const char *name, enum v4l2_ctrl_type type,
17611761
s64 min, s64 max, u64 step, s64 def,
1762-
u32 elem_size,
1762+
const u32 dims[V4L2_CTRL_MAX_DIMS], u32 elem_size,
17631763
u32 flags, const char * const *qmenu,
17641764
const s64 *qmenu_int, void *priv)
17651765
{
17661766
struct v4l2_ctrl *ctrl;
17671767
unsigned sz_extra;
1768+
unsigned nr_of_dims = 0;
1769+
unsigned elems = 1;
17681770
void *data;
17691771
int err;
17701772

17711773
if (hdl->error)
17721774
return NULL;
17731775

1776+
while (dims && dims[nr_of_dims]) {
1777+
elems *= dims[nr_of_dims];
1778+
nr_of_dims++;
1779+
if (nr_of_dims == V4L2_CTRL_MAX_DIMS)
1780+
break;
1781+
}
1782+
17741783
if (type == V4L2_CTRL_TYPE_INTEGER64)
17751784
elem_size = sizeof(s64);
17761785
else if (type == V4L2_CTRL_TYPE_STRING)
@@ -1828,6 +1837,10 @@ static struct v4l2_ctrl *v4l2_ctrl_new(struct v4l2_ctrl_handler *hdl,
18281837
ctrl->is_string = type == V4L2_CTRL_TYPE_STRING;
18291838
ctrl->is_ptr = type >= V4L2_CTRL_COMPOUND_TYPES || ctrl->is_string;
18301839
ctrl->is_int = !ctrl->is_ptr && type != V4L2_CTRL_TYPE_INTEGER64;
1840+
ctrl->elems = elems;
1841+
ctrl->nr_of_dims = nr_of_dims;
1842+
if (nr_of_dims)
1843+
memcpy(ctrl->dims, dims, nr_of_dims * sizeof(dims[0]));
18311844
ctrl->elem_size = elem_size;
18321845
if (type == V4L2_CTRL_TYPE_MENU)
18331846
ctrl->qmenu = qmenu;
@@ -1892,8 +1905,8 @@ struct v4l2_ctrl *v4l2_ctrl_new_custom(struct v4l2_ctrl_handler *hdl,
18921905

18931906
ctrl = v4l2_ctrl_new(hdl, cfg->ops, cfg->type_ops, cfg->id, name,
18941907
type, min, max,
1895-
is_menu ? cfg->menu_skip_mask : step,
1896-
def, cfg->elem_size,
1908+
is_menu ? cfg->menu_skip_mask : step, def,
1909+
cfg->dims, cfg->elem_size,
18971910
flags, qmenu, qmenu_int, priv);
18981911
if (ctrl)
18991912
ctrl->is_private = cfg->is_private;
@@ -1918,7 +1931,7 @@ struct v4l2_ctrl *v4l2_ctrl_new_std(struct v4l2_ctrl_handler *hdl,
19181931
return NULL;
19191932
}
19201933
return v4l2_ctrl_new(hdl, ops, NULL, id, name, type,
1921-
min, max, step, def, 0,
1934+
min, max, step, def, NULL, 0,
19221935
flags, NULL, NULL, NULL);
19231936
}
19241937
EXPORT_SYMBOL(v4l2_ctrl_new_std);
@@ -1951,7 +1964,7 @@ struct v4l2_ctrl *v4l2_ctrl_new_std_menu(struct v4l2_ctrl_handler *hdl,
19511964
return NULL;
19521965
}
19531966
return v4l2_ctrl_new(hdl, ops, NULL, id, name, type,
1954-
0, max, mask, def, 0,
1967+
0, max, mask, def, NULL, 0,
19551968
flags, qmenu, qmenu_int, NULL);
19561969
}
19571970
EXPORT_SYMBOL(v4l2_ctrl_new_std_menu);
@@ -1983,8 +1996,8 @@ struct v4l2_ctrl *v4l2_ctrl_new_std_menu_items(struct v4l2_ctrl_handler *hdl,
19831996
return NULL;
19841997
}
19851998
return v4l2_ctrl_new(hdl, ops, NULL, id, name, type,
1986-
0, max, mask, def,
1987-
0, flags, qmenu, NULL, NULL);
1999+
0, max, mask, def, NULL, 0,
2000+
flags, qmenu, NULL, NULL);
19882001

19892002
}
19902003
EXPORT_SYMBOL(v4l2_ctrl_new_std_menu_items);
@@ -2008,7 +2021,7 @@ struct v4l2_ctrl *v4l2_ctrl_new_int_menu(struct v4l2_ctrl_handler *hdl,
20082021
return NULL;
20092022
}
20102023
return v4l2_ctrl_new(hdl, ops, NULL, id, name, type,
2011-
0, max, 0, def, 0,
2024+
0, max, 0, def, NULL, 0,
20122025
flags, NULL, qmenu_int, NULL);
20132026
}
20142027
EXPORT_SYMBOL(v4l2_ctrl_new_int_menu);
@@ -2354,7 +2367,9 @@ int v4l2_query_ext_ctrl(struct v4l2_ctrl_handler *hdl, struct v4l2_query_ext_ctr
23542367
if (ctrl->is_ptr)
23552368
qc->flags |= V4L2_CTRL_FLAG_HAS_PAYLOAD;
23562369
qc->elem_size = ctrl->elem_size;
2357-
qc->elems = 1;
2370+
qc->elems = ctrl->elems;
2371+
qc->nr_of_dims = ctrl->nr_of_dims;
2372+
memcpy(qc->dims, ctrl->dims, qc->nr_of_dims * sizeof(qc->dims[0]));
23582373
qc->minimum = ctrl->minimum;
23592374
qc->maximum = ctrl->maximum;
23602375
qc->default_value = ctrl->default_value;

‎include/media/v4l2-ctrls.h‎

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,10 @@ typedef void (*v4l2_ctrl_notify_fnc)(struct v4l2_ctrl *ctrl, void *priv);
129129
* @maximum: The control's maximum value.
130130
* @default_value: The control's default value.
131131
* @step: The control's step value for non-menu controls.
132+
* @elems: The number of elements in the N-dimensional array.
132133
* @elem_size: The size in bytes of the control.
134+
* @dims: The size of each dimension.
135+
* @nr_of_dims:The number of dimensions in @dims.
133136
* @menu_skip_mask: The control's skip mask for menu controls. This makes it
134137
* easy to skip menu items that are not valid. If bit X is set,
135138
* then menu item X is skipped. Of course, this only works for
@@ -176,7 +179,10 @@ struct v4l2_ctrl {
176179
const char *name;
177180
enum v4l2_ctrl_type type;
178181
s64 minimum, maximum, default_value;
182+
u32 elems;
179183
u32 elem_size;
184+
u32 dims[V4L2_CTRL_MAX_DIMS];
185+
u32 nr_of_dims;
180186
union {
181187
u64 step;
182188
u64 menu_skip_mask;
@@ -255,6 +261,7 @@ struct v4l2_ctrl_handler {
255261
* @max: The control's maximum value.
256262
* @step: The control's step value for non-menu controls.
257263
* @def: The control's default value.
264+
* @dims: The size of each dimension.
258265
* @elem_size: The size in bytes of the control.
259266
* @flags: The control's flags.
260267
* @menu_skip_mask: The control's skip mask for menu controls. This makes it
@@ -280,6 +287,7 @@ struct v4l2_ctrl_config {
280287
s64 max;
281288
u64 step;
282289
s64 def;
290+
u32 dims[V4L2_CTRL_MAX_DIMS];
283291
u32 elem_size;
284292
u32 flags;
285293
u64 menu_skip_mask;

0 commit comments

Comments
 (0)