Skip to contentSkip to conversation

media: v4l2_ctrl: Add p_def to v4l2_ctrl_config

PATCH Superseded Ricardo Ribalda Delgado 2 participants 8 messages Nov 1, 2019 – Nov 4, 2019

Subsystems (2)

v3 of 4 Superseded Latest is v4 →

lore
Share & tools
lore
#0 lore raw

PATCH v3 1/5 media: v4l2_ctrl: Add p_def to v4l2_ctrl_config

This allows setting the default value on compound controls created via v4l2_ctrl_new_custom.

---
 drivers/media/v4l2-core/v4l2-ctrls.c | 2 +-
 include/media/v4l2-ctrls.h           | 2 ++
 2 files changed, 3 insertions(+), 1 deletion(-)
drivers/media/v4l2-core/v4l2-ctrls.c +1 -1
index b4caf2d4d076..73d99c3561ce 100644
@@ -2690,7 +2690,7 @@ struct v4l2_ctrl *v4l2_ctrl_new_custom(struct v4l2_ctrl_handler *hdl,
 			type, min, max,
 			is_menu ? cfg->menu_skip_mask : step, def,
 			cfg->dims, cfg->elem_size,
-			flags, qmenu, qmenu_int, ptr_null, priv);
+			flags, qmenu, qmenu_int, cfg->p_def, priv);
 	if (ctrl)
 		ctrl->is_private = cfg->is_private;
 	return ctrl;
include/media/v4l2-ctrls.h +2 -0
index e719d56fc024..78a97b10c89e 100644
@@ -382,6 +382,7 @@ struct v4l2_ctrl_handler {
  * @max:	The control's maximum value.
  * @step:	The control's step value for non-menu controls.
  * @def:	The control's default value.
+ * @p_def:	The control's default value for compound controls.
  * @dims:	The size of each dimension.
  * @elem_size:	The size in bytes of the control.
  * @flags:	The control's flags.
@@ -410,6 +411,7 @@ struct v4l2_ctrl_config {
 	s64 max;
 	u64 step;
 	s64 def;
+	union v4l2_ctrl_ptr p_def;
 	u32 dims[V4L2_CTRL_MAX_DIMS];
 	u32 elem_size;
 	u32 flags;
Signature · 1 line
2.24.0.rc1
#1 lore raw

PATCH v3 2/5 media: v4l2_ctrl: Add const pointer to ctrl_ptr

This pointer is used to point to data that is constant. Thanks to this we can avoid a lot of casting and we make more clear when the data is constant or variable.

---
 include/media/v4l2-ctrls.h | 2 ++
 1 file changed, 2 insertions(+)
include/media/v4l2-ctrls.h +2 -0
index 78a97b10c89e..7db9e719a583 100644
@@ -56,6 +56,7 @@ struct poll_table_struct;
  * @p_hevc_slice_params:	Pointer to an HEVC slice parameters structure.
  * @p_area:			Pointer to an area.
  * @p:				Pointer to a compound value.
+ * @p_const:			Pointer to a constant compound value.
  */
 union v4l2_ctrl_ptr {
 	s32 *p_s32;
@@ -78,6 +79,7 @@ union v4l2_ctrl_ptr {
 	struct v4l2_ctrl_hevc_slice_params *p_hevc_slice_params;
 	struct v4l2_area *p_area;
 	void *p;
+	const void *p_const;
 };
 
 /**
Signature · 1 line
2.24.0.rc1
#2 lore raw

Re: [PATCH v3 2/5] media: v4l2_ctrl: Add const pointer to ctrl_ptr

Hi Ricardo,

Quoted 24 lines · Ricardo Ribalda Delgado

This pointer is used to point to data that is constant. Thanks to this we can avoid a lot of casting and we make more clear when the data is constant or variable.

---
 include/media/v4l2-ctrls.h | 2 ++
 1 file changed, 2 insertions(+)
include/media/v4l2-ctrls.h +1 -0
index 78a97b10c89e..7db9e719a583 100644
@@ -56,6 +56,7 @@ struct poll_table_struct;
  * @p_hevc_slice_params:	Pointer to an HEVC slice parameters structure.
  * @p_area:			Pointer to an area.
  * @p:				Pointer to a compound value.
+ * @p_const:			Pointer to a constant compound value.
  */
 union v4l2_ctrl_ptr {
 	s32 *p_s32;

include/media/v4l2-ctrls.h union v4l2_ctrl_ptr { · line 85

Quoted 7 lines
include/media/v4l2-ctrls.h +1 -0
@@ -78,6 +79,7 @@ union v4l2_ctrl_ptr {
 	struct v4l2_ctrl_hevc_slice_params *p_hevc_slice_params;
 	struct v4l2_area *p_area;
 	void *p;
+	const void *p_const;
 };
 
 /**

This addition makes it possible to use const void pointers elsewhere in the control framework.

E.g. in std_equal you can use p_const in the memcmp at the end.

Can you go through the v4l2-ctrls.c source and replace .p by .p_const where it makes sense?

Obviously this would be a separate patch.

Regards,

Hans

#3 lore raw

PATCH v3 3/5 media: vivid: Add an area control

In reply to Ricardo Ribalda Delgado

This control represents a generic read/write area.

---
 drivers/media/platform/vivid/vivid-ctrls.c | 14 ++++++++++++++
 1 file changed, 14 insertions(+)
drivers/media/platform/vivid/vivid-ctrls.c +14 -0
index b250fc3764e2..fd35863798a7 100644
@@ -32,6 +32,7 @@
 #define VIVID_CID_U32_ARRAY		(VIVID_CID_CUSTOM_BASE + 8)
 #define VIVID_CID_U16_MATRIX		(VIVID_CID_CUSTOM_BASE + 9)
 #define VIVID_CID_U8_4D_ARRAY		(VIVID_CID_CUSTOM_BASE + 10)
+#define VIVID_CID_AREA			(VIVID_CID_CUSTOM_BASE + 11)
 
 #define VIVID_CID_VIVID_BASE		(0x00f00000 | 0xf000)
 #define VIVID_CID_VIVID_CLASS		(0x00f00000 | 1)
@@ -266,6 +267,18 @@ static const struct v4l2_ctrl_config vivid_ctrl_disconnect = {
 	.type = V4L2_CTRL_TYPE_BUTTON,
 };
 
+static const struct v4l2_area area = {
+	.width = 0xcafe,
+	.height = 0xb1b1d,
+};
+
+static const struct v4l2_ctrl_config vivid_ctrl_area = {
+	.ops = &vivid_user_gen_ctrl_ops,
+	.id = VIVID_CID_AREA,
+	.name = "Area",
+	.type = V4L2_CTRL_TYPE_AREA,
+	.p_def.p_const = &area,
+};
 
 /* Framebuffer Controls */
 
@@ -1574,6 +1587,7 @@ int vivid_create_controls(struct vivid_dev *dev, bool show_ccs_cap,
 	dev->string = v4l2_ctrl_new_custom(hdl_user_gen, &vivid_ctrl_string, NULL);
 	dev->bitmask = v4l2_ctrl_new_custom(hdl_user_gen, &vivid_ctrl_bitmask, NULL);
 	dev->int_menu = v4l2_ctrl_new_custom(hdl_user_gen, &vivid_ctrl_int_menu, NULL);
+	v4l2_ctrl_new_custom(hdl_user_gen, &vivid_ctrl_area, NULL);
 	v4l2_ctrl_new_custom(hdl_user_gen, &vivid_ctrl_u32_array, NULL);
 	v4l2_ctrl_new_custom(hdl_user_gen, &vivid_ctrl_u16_matrix, NULL);
 	v4l2_ctrl_new_custom(hdl_user_gen, &vivid_ctrl_u8_4d_array, NULL);
Signature · 1 line
2.24.0.rc1
#4 lore raw

Re: [PATCH v3 3/5] media: vivid: Add an area control

Quoted 21 lines · Ricardo Ribalda Delgado

This control represents a generic read/write area.

---
 drivers/media/platform/vivid/vivid-ctrls.c | 14 ++++++++++++++
 1 file changed, 14 insertions(+)
drivers/media/platform/vivid/vivid-ctrls.c +1 -0
index b250fc3764e2..fd35863798a7 100644
@@ -32,6 +32,7 @@
 #define VIVID_CID_U32_ARRAY		(VIVID_CID_CUSTOM_BASE + 8)
 #define VIVID_CID_U16_MATRIX		(VIVID_CID_CUSTOM_BASE + 9)
 #define VIVID_CID_U8_4D_ARRAY		(VIVID_CID_CUSTOM_BASE + 10)
+#define VIVID_CID_AREA			(VIVID_CID_CUSTOM_BASE + 11)
 
 #define VIVID_CID_VIVID_BASE		(0x00f00000 | 0xf000)
 #define VIVID_CID_VIVID_CLASS		(0x00f00000 | 1)

drivers/media/platform/vivid/vivid-ctrls.c static const struct v4l2_ctrl_config vivid_ctrl_disconnect = { · line 272

Quoted 6 lines
drivers/media/platform/vivid/vivid-ctrls.c +3 -0
@@ -266,6 +267,18 @@ static const struct v4l2_ctrl_config vivid_ctrl_disconnect = {
 	.type = V4L2_CTRL_TYPE_BUTTON,
 };
 
+static const struct v4l2_area area = {
+	.width = 0xcafe,
+	.height = 0xb1b1d,

I don't think there is any need for these weird values. Just set this to e.g. 1000x2000. Just as long as width and height are different.

Regards,

Hans

Quoted 21 lines
drivers/media/platform/vivid/vivid-ctrls.c +10 -0
+};
+
+static const struct v4l2_ctrl_config vivid_ctrl_area = {
+	.ops = &vivid_user_gen_ctrl_ops,
+	.id = VIVID_CID_AREA,
+	.name = "Area",
+	.type = V4L2_CTRL_TYPE_AREA,
+	.p_def.p_const = &area,
+};
 
 /* Framebuffer Controls */
 
@@ -1574,6 +1587,7 @@ int vivid_create_controls(struct vivid_dev *dev, bool show_ccs_cap,
 	dev->string = v4l2_ctrl_new_custom(hdl_user_gen, &vivid_ctrl_string, NULL);
 	dev->bitmask = v4l2_ctrl_new_custom(hdl_user_gen, &vivid_ctrl_bitmask, NULL);
 	dev->int_menu = v4l2_ctrl_new_custom(hdl_user_gen, &vivid_ctrl_int_menu, NULL);
+	v4l2_ctrl_new_custom(hdl_user_gen, &vivid_ctrl_area, NULL);
 	v4l2_ctrl_new_custom(hdl_user_gen, &vivid_ctrl_u32_array, NULL);
 	v4l2_ctrl_new_custom(hdl_user_gen, &vivid_ctrl_u16_matrix, NULL);
 	v4l2_ctrl_new_custom(hdl_user_gen, &vivid_ctrl_u8_4d_array, NULL);
#5 lore raw

Re: [PATCH v3 3/5] media: vivid: Add an area control

Hi hans

Quoted 26 lines · Hans Verkuil
Quoted 24 lines · Ricardo Ribalda Delgado

This control represents a generic read/write area.

---
 drivers/media/platform/vivid/vivid-ctrls.c | 14 ++++++++++++++
 1 file changed, 14 insertions(+)
drivers/media/platform/vivid/vivid-ctrls.c +1 -0
index b250fc3764e2..fd35863798a7 100644
@@ -32,6 +32,7 @@
 #define VIVID_CID_U32_ARRAY          (VIVID_CID_CUSTOM_BASE + 8)
 #define VIVID_CID_U16_MATRIX         (VIVID_CID_CUSTOM_BASE + 9)
 #define VIVID_CID_U8_4D_ARRAY                (VIVID_CID_CUSTOM_BASE + 10)
+#define VIVID_CID_AREA                       (VIVID_CID_CUSTOM_BASE + 11)
 
 #define VIVID_CID_VIVID_BASE         (0x00f00000 | 0xf000)
 #define VIVID_CID_VIVID_CLASS                (0x00f00000 | 1)
@@ -266,6 +267,18 @@ static const struct v4l2_ctrl_config vivid_ctrl_disconnect = {
      .type = V4L2_CTRL_TYPE_BUTTON,
 };
 
Quoted 8 lines

drivers/media/platform/vivid/vivid-ctrls.c static const struct v4l2_ctrl_config vivid_ctrl_disconnect = { · line 272

Quoted 3 lines
drivers/media/platform/vivid/vivid-ctrls.c +3 -0
+static const struct v4l2_area area = {
+     .width = 0xcafe,
+     .height = 0xb1b1d,

I don't think there is any need for these weird values. Just set this to e.g. 1000x2000. Just as long as width and height are different.

Regards,

Sure. I will change that.

I though anyone liked vivid cafe ;P

Quoted 25 lines

Hans

Quoted 21 lines
drivers/media/platform/vivid/vivid-ctrls.c +10 -0
+};
+
+static const struct v4l2_ctrl_config vivid_ctrl_area = {
+     .ops = &vivid_user_gen_ctrl_ops,
+     .id = VIVID_CID_AREA,
+     .name = "Area",
+     .type = V4L2_CTRL_TYPE_AREA,
+     .p_def.p_const = &area,
+};
 
 /* Framebuffer Controls */
 
@@ -1574,6 +1587,7 @@ int vivid_create_controls(struct vivid_dev *dev, bool show_ccs_cap,
      dev->string = v4l2_ctrl_new_custom(hdl_user_gen, &vivid_ctrl_string, NULL);
      dev->bitmask = v4l2_ctrl_new_custom(hdl_user_gen, &vivid_ctrl_bitmask, NULL);
      dev->int_menu = v4l2_ctrl_new_custom(hdl_user_gen, &vivid_ctrl_int_menu, NULL);
+     v4l2_ctrl_new_custom(hdl_user_gen, &vivid_ctrl_area, NULL);
      v4l2_ctrl_new_custom(hdl_user_gen, &vivid_ctrl_u32_array, NULL);
      v4l2_ctrl_new_custom(hdl_user_gen, &vivid_ctrl_u16_matrix, NULL);
      v4l2_ctrl_new_custom(hdl_user_gen, &vivid_ctrl_u8_4d_array, NULL);
#6 lore raw

PATCH v3 4/5 media: v4l2_core: Add p_area to struct v4l2_ext_control

In reply to Ricardo Ribalda Delgado

Allow accessing V4L2_CTRL_TYPE_AREA controls without any casting.

---
 include/uapi/linux/videodev2.h | 1 +
 1 file changed, 1 insertion(+)
include/uapi/linux/videodev2.h +1 -0
index f98bbcced8ff..04481c717fee 100644
@@ -1684,6 +1684,7 @@ struct v4l2_ext_control {
 		__u8 __user *p_u8;
 		__u16 __user *p_u16;
 		__u32 __user *p_u32;
+		struct v4l2_area __user *p_area;
 		void __user *ptr;
 	};
 } __attribute__ ((packed));
Signature · 1 line
2.24.0.rc1
#7 lore raw

PATCH v3 5/5 Documentation: v42l_core: v4l2_ext_control

In reply to Ricardo Ribalda Delgado

Describe p_area field from v4l2_ext_ctrl

---
 Documentation/media/uapi/v4l/vidioc-g-ext-ctrls.rst | 5 +++++
 1 file changed, 5 insertions(+)
Documentation/media/uapi/v4l/vidioc-g-ext-ctrls.rst +5 -0
index 13dc1a986249..271cac18afbb 100644
@@ -198,6 +198,11 @@ still cause this situation.
       - ``p_u32``
       - A pointer to a matrix control of unsigned 32-bit values. Valid if
 	this control is of type ``V4L2_CTRL_TYPE_U32``.
+    * -
+      - :c:type:`v4l2_area` *
+      - ``p_area``
+      - A pointer to a struct :c:type:`v4l2_area`. Valid if this control is
+        of type ``V4L2_CTRL_TYPE_AREA``.
     * -
       - void *
       - ``ptr``
Signature · 1 line
2.24.0.rc1