Hi Ricardo,

As per our irc discussion, here is a proposal how I think it can be done.
The core problem is that for compound types we want to provide a default
value that can be used in std_init_compound() without having to provide
our own type ops. The new v4l2_ctrl_new_std_compound would pass a const
pointer to the struct with the default value, and std_init_compound
should use that if p_def != NULL.

I think this is beneficial for the various codec compound types as well.

Implementing this in v4l2-ctrls.c is left as an exercise for the reader
(i.e., you!).



Signed-off-by: Hans Verkuil <hverkuil-ci...@xs4all.nl>
diff --git a/include/media/v4l2-ctrls.h b/include/media/v4l2-ctrls.h
index 570ff4b0205a..7fdbf3abe49b 100644
--- a/include/media/v4l2-ctrls.h
+++ b/include/media/v4l2-ctrls.h
@@ -254,6 +254,7 @@ struct v4l2_ctrl {
                s32 val;
        } cur;

+       const union v4l2_ctrl_ptr p_def;
        union v4l2_ctrl_ptr p_new;
        union v4l2_ctrl_ptr p_cur;
@@ -667,6 +668,27 @@ struct v4l2_ctrl *v4l2_ctrl_new_int_menu(struct 
v4l2_ctrl_handler *hdl,
                                         u32 id, u8 max, u8 def,
                                         const s64 *qmenu_int);

+ * v4l2_ctrl_new_std_compound() - Allocate and initialize a new standard V4L2
+ *     compound control.
+ *
+ * @hdl:       The control handler.
+ * @ops:       The control ops.
+ * @id:                The control ID.
+ * @min:       The control's minimum value.
+ * @max:       The control's maximum value.
+ * @step:      The control's step value
+ * @p_def:     The control's default value.
+ *
+ * If the &v4l2_ctrl struct could not be allocated, or the control
+ * ID is not known, then NULL is returned and @hdl->error is set to the
+ * appropriate error code (if it wasn't set already).
+ */
+struct v4l2_ctrl *v4l2_ctrl_new_std_compound(struct v4l2_ctrl_handler *hdl,
+                                            const struct v4l2_ctrl_ops *ops,
+                                            u32 id, s64 min, s64 max, u64 step,
+                                            const union v4l2_ctrl_ptr p_def);
  * typedef v4l2_ctrl_filter - Typedef to define the filter function to be
  *     used when adding a control handler.

Reply via email to