Re: [PATCH v3] media: v4l2-ctrl: add a helper function to modify the menu
Hi Prabhakar, Thanks for the patch. On Tuesday 11 September 2012 19:53:38 Prabhakar Lad wrote: From: Lad, Prabhakar prabhakar@ti.com Add a helper function to modify the menu, max and default value to set. Signed-off-by: Lad, Prabhakar prabhakar@ti.com Signed-off-by: Manjunath Hadli manjunath.ha...@ti.com Cc: Hans Verkuil hans.verk...@cisco.com Cc: Sakari Ailus sakari.ai...@iki.fi Cc: Sylwester Nawrocki s.nawro...@samsung.com Cc: Laurent Pinchart laurent.pinch...@ideasonboard.com Cc: Mauro Carvalho Chehab mche...@infradead.org Cc: Hans de Goede hdego...@redhat.com Cc: Kyungmin Park kyungmin.p...@samsung.com Cc: Guennadi Liakhovetski g.liakhovet...@gmx.de Cc: Rob Landley r...@landley.net --- Changes for v3: 1: Fixed style/grammer issues as pointed by Hans. Thanks Hans for providing the description. Changes for v2: 1: Fixed review comments from Hans, to have return type as void, add WARN_ON() for fail conditions, allow this fucntion to modify the menu of custom controls. Documentation/video4linux/v4l2-controls.txt | 29 drivers/media/v4l2-core/v4l2-ctrls.c| 17 +++ include/media/v4l2-ctrls.h | 11 ++ 3 files changed, 57 insertions(+), 0 deletions(-) diff --git a/Documentation/video4linux/v4l2-controls.txt b/Documentation/video4linux/v4l2-controls.txt index 43da22b..01d0a82 100644 --- a/Documentation/video4linux/v4l2-controls.txt +++ b/Documentation/video4linux/v4l2-controls.txt @@ -367,6 +367,35 @@ it to 0 means that all menu items are supported. You set this mask either through the v4l2_ctrl_config struct for a custom control, or by calling v4l2_ctrl_new_std_menu(). +There are situations where menu items may be device specific. In such cases the +framework provides a helper function to change the menu: + +void v4l2_ctrl_modify_menu(struct v4l2_ctrl *ctrl, const char * const *qmenu, + s32 max, u32 menu_skip_mask, s32 def); Sorry if this is a stupid question, but wouldn't it be better to add a function to create a custom menu instead of modifying it afterwards ? + +A good example is the test pattern control for capture/display/sensors devices +that have the capability to generate test patterns. These test patterns are +hardware specific, so the contents of the menu will vary from device to device. + +This helper function is used to modify the menu, max, mask and the default +value of the control. + +Example: + + static const char * const test_pattern[] = { + Disabled, + Vertical Bars, + Solid Black, + Solid White, + NULL, + }; + struct v4l2_ctrl *test_pattern_ctrl = + v4l2_ctrl_new_std_menu(foo-ctrl_handler, foo_ctrl_ops, + V4L2_CID_TEST_PATTERN, V4L2_TEST_PATTERN_DISABLED, 0, + V4L2_TEST_PATTERN_DISABLED); + + v4l2_ctrl_modify_menu(test_pattern_ctrl, test_pattern, 3, 0, + V4L2_TEST_PATTERN_DISABLED); Custom Controls === -- Regards, Laurent Pinchart -- To unsubscribe from this list: send the line unsubscribe linux-media in the body of a message to majord...@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html
Re: [PATCH v3] media: v4l2-ctrl: add a helper function to modify the menu
Hi Laurent, Thanks for the review. On Thursday 13 September 2012 06:45 AM, Laurent Pinchart wrote: Hi Prabhakar, Thanks for the patch. On Tuesday 11 September 2012 19:53:38 Prabhakar Lad wrote: From: Lad, Prabhakar prabhakar@ti.com Add a helper function to modify the menu, max and default value to set. Signed-off-by: Lad, Prabhakar prabhakar@ti.com Signed-off-by: Manjunath Hadli manjunath.ha...@ti.com Cc: Hans Verkuil hans.verk...@cisco.com Cc: Sakari Ailus sakari.ai...@iki.fi Cc: Sylwester Nawrocki s.nawro...@samsung.com Cc: Laurent Pinchart laurent.pinch...@ideasonboard.com Cc: Mauro Carvalho Chehab mche...@infradead.org Cc: Hans de Goede hdego...@redhat.com Cc: Kyungmin Park kyungmin.p...@samsung.com Cc: Guennadi Liakhovetski g.liakhovet...@gmx.de Cc: Rob Landley r...@landley.net --- Changes for v3: 1: Fixed style/grammer issues as pointed by Hans. Thanks Hans for providing the description. Changes for v2: 1: Fixed review comments from Hans, to have return type as void, add WARN_ON() for fail conditions, allow this fucntion to modify the menu of custom controls. Documentation/video4linux/v4l2-controls.txt | 29 drivers/media/v4l2-core/v4l2-ctrls.c| 17 +++ include/media/v4l2-ctrls.h | 11 ++ 3 files changed, 57 insertions(+), 0 deletions(-) diff --git a/Documentation/video4linux/v4l2-controls.txt b/Documentation/video4linux/v4l2-controls.txt index 43da22b..01d0a82 100644 --- a/Documentation/video4linux/v4l2-controls.txt +++ b/Documentation/video4linux/v4l2-controls.txt @@ -367,6 +367,35 @@ it to 0 means that all menu items are supported. You set this mask either through the v4l2_ctrl_config struct for a custom control, or by calling v4l2_ctrl_new_std_menu(). +There are situations where menu items may be device specific. In such cases the +framework provides a helper function to change the menu: + +void v4l2_ctrl_modify_menu(struct v4l2_ctrl *ctrl, const char * const *qmenu, +s32 max, u32 menu_skip_mask, s32 def); Sorry if this is a stupid question, but wouldn't it be better to add a function to create a custom menu instead of modifying it afterwards ? Create a custom menu? eventually everything boils down to modifying the menu itself. Regards, --Prabhakar Lad + +A good example is the test pattern control for capture/display/sensors devices +that have the capability to generate test patterns. These test patterns are +hardware specific, so the contents of the menu will vary from device to device. + +This helper function is used to modify the menu, max, mask and the default +value of the control. + +Example: + +static const char * const test_pattern[] = { +Disabled, +Vertical Bars, +Solid Black, +Solid White, +NULL, +}; +struct v4l2_ctrl *test_pattern_ctrl = +v4l2_ctrl_new_std_menu(foo-ctrl_handler, foo_ctrl_ops, +V4L2_CID_TEST_PATTERN, V4L2_TEST_PATTERN_DISABLED, 0, +V4L2_TEST_PATTERN_DISABLED); + +v4l2_ctrl_modify_menu(test_pattern_ctrl, test_pattern, 3, 0, +V4L2_TEST_PATTERN_DISABLED); Custom Controls === -- To unsubscribe from this list: send the line unsubscribe linux-media in the body of a message to majord...@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html
Re: [PATCH v3] media: v4l2-ctrl: add a helper function to modify the menu
On Thu 13 September 2012 13:43:36 Prabhakar Lad wrote: Hi Laurent, Thanks for the review. On Thursday 13 September 2012 06:45 AM, Laurent Pinchart wrote: Hi Prabhakar, Thanks for the patch. On Tuesday 11 September 2012 19:53:38 Prabhakar Lad wrote: From: Lad, Prabhakar prabhakar@ti.com Add a helper function to modify the menu, max and default value to set. Signed-off-by: Lad, Prabhakar prabhakar@ti.com Signed-off-by: Manjunath Hadli manjunath.ha...@ti.com Cc: Hans Verkuil hans.verk...@cisco.com Cc: Sakari Ailus sakari.ai...@iki.fi Cc: Sylwester Nawrocki s.nawro...@samsung.com Cc: Laurent Pinchart laurent.pinch...@ideasonboard.com Cc: Mauro Carvalho Chehab mche...@infradead.org Cc: Hans de Goede hdego...@redhat.com Cc: Kyungmin Park kyungmin.p...@samsung.com Cc: Guennadi Liakhovetski g.liakhovet...@gmx.de Cc: Rob Landley r...@landley.net --- Changes for v3: 1: Fixed style/grammer issues as pointed by Hans. Thanks Hans for providing the description. Changes for v2: 1: Fixed review comments from Hans, to have return type as void, add WARN_ON() for fail conditions, allow this fucntion to modify the menu of custom controls. Documentation/video4linux/v4l2-controls.txt | 29 drivers/media/v4l2-core/v4l2-ctrls.c| 17 +++ include/media/v4l2-ctrls.h | 11 ++ 3 files changed, 57 insertions(+), 0 deletions(-) diff --git a/Documentation/video4linux/v4l2-controls.txt b/Documentation/video4linux/v4l2-controls.txt index 43da22b..01d0a82 100644 --- a/Documentation/video4linux/v4l2-controls.txt +++ b/Documentation/video4linux/v4l2-controls.txt @@ -367,6 +367,35 @@ it to 0 means that all menu items are supported. You set this mask either through the v4l2_ctrl_config struct for a custom control, or by calling v4l2_ctrl_new_std_menu(). +There are situations where menu items may be device specific. In such cases the +framework provides a helper function to change the menu: + +void v4l2_ctrl_modify_menu(struct v4l2_ctrl *ctrl, const char * const *qmenu, + s32 max, u32 menu_skip_mask, s32 def); Sorry if this is a stupid question, but wouldn't it be better to add a function to create a custom menu instead of modifying it afterwards ? Create a custom menu? eventually everything boils down to modifying the menu itself. Laurent, the reason we went for modifying a standard control is that that ensures that the control name and type is all standardized. The only thing that can be changed later is the menu contents. Regards, Hans Regards, --Prabhakar Lad + +A good example is the test pattern control for capture/display/sensors devices +that have the capability to generate test patterns. These test patterns are +hardware specific, so the contents of the menu will vary from device to device. + +This helper function is used to modify the menu, max, mask and the default +value of the control. + +Example: + + static const char * const test_pattern[] = { + Disabled, + Vertical Bars, + Solid Black, + Solid White, + NULL, + }; + struct v4l2_ctrl *test_pattern_ctrl = + v4l2_ctrl_new_std_menu(foo-ctrl_handler, foo_ctrl_ops, + V4L2_CID_TEST_PATTERN, V4L2_TEST_PATTERN_DISABLED, 0, + V4L2_TEST_PATTERN_DISABLED); + + v4l2_ctrl_modify_menu(test_pattern_ctrl, test_pattern, 3, 0, + V4L2_TEST_PATTERN_DISABLED); Custom Controls === -- To unsubscribe from this list: send the line unsubscribe linux-media in the body of a message to majord...@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html
[PATCH v3] media: v4l2-ctrl: add a helper function to modify the menu
From: Lad, Prabhakar prabhakar@ti.com Add a helper function to modify the menu, max and default value to set. Signed-off-by: Lad, Prabhakar prabhakar@ti.com Signed-off-by: Manjunath Hadli manjunath.ha...@ti.com Cc: Hans Verkuil hans.verk...@cisco.com Cc: Sakari Ailus sakari.ai...@iki.fi Cc: Sylwester Nawrocki s.nawro...@samsung.com Cc: Laurent Pinchart laurent.pinch...@ideasonboard.com Cc: Mauro Carvalho Chehab mche...@infradead.org Cc: Hans de Goede hdego...@redhat.com Cc: Kyungmin Park kyungmin.p...@samsung.com Cc: Guennadi Liakhovetski g.liakhovet...@gmx.de Cc: Rob Landley r...@landley.net --- Changes for v3: 1: Fixed style/grammer issues as pointed by Hans. Thanks Hans for providing the description. Changes for v2: 1: Fixed review comments from Hans, to have return type as void, add WARN_ON() for fail conditions, allow this fucntion to modify the menu of custom controls. Documentation/video4linux/v4l2-controls.txt | 29 +++ drivers/media/v4l2-core/v4l2-ctrls.c| 17 +++ include/media/v4l2-ctrls.h | 11 ++ 3 files changed, 57 insertions(+), 0 deletions(-) diff --git a/Documentation/video4linux/v4l2-controls.txt b/Documentation/video4linux/v4l2-controls.txt index 43da22b..01d0a82 100644 --- a/Documentation/video4linux/v4l2-controls.txt +++ b/Documentation/video4linux/v4l2-controls.txt @@ -367,6 +367,35 @@ it to 0 means that all menu items are supported. You set this mask either through the v4l2_ctrl_config struct for a custom control, or by calling v4l2_ctrl_new_std_menu(). +There are situations where menu items may be device specific. In such cases the +framework provides a helper function to change the menu: + +void v4l2_ctrl_modify_menu(struct v4l2_ctrl *ctrl, const char * const *qmenu, + s32 max, u32 menu_skip_mask, s32 def); + +A good example is the test pattern control for capture/display/sensors devices +that have the capability to generate test patterns. These test patterns are +hardware specific, so the contents of the menu will vary from device to device. + +This helper function is used to modify the menu, max, mask and the default +value of the control. + +Example: + + static const char * const test_pattern[] = { + Disabled, + Vertical Bars, + Solid Black, + Solid White, + NULL, + }; + struct v4l2_ctrl *test_pattern_ctrl = + v4l2_ctrl_new_std_menu(foo-ctrl_handler, foo_ctrl_ops, + V4L2_CID_TEST_PATTERN, V4L2_TEST_PATTERN_DISABLED, 0, + V4L2_TEST_PATTERN_DISABLED); + + v4l2_ctrl_modify_menu(test_pattern_ctrl, test_pattern, 3, 0, + V4L2_TEST_PATTERN_DISABLED); Custom Controls === diff --git a/drivers/media/v4l2-core/v4l2-ctrls.c b/drivers/media/v4l2-core/v4l2-ctrls.c index d731422..d89b460 100644 --- a/drivers/media/v4l2-core/v4l2-ctrls.c +++ b/drivers/media/v4l2-core/v4l2-ctrls.c @@ -2666,3 +2666,20 @@ unsigned int v4l2_ctrl_poll(struct file *file, struct poll_table_struct *wait) return 0; } EXPORT_SYMBOL(v4l2_ctrl_poll); + +/* Helper function for modifying the menu */ +void v4l2_ctrl_modify_menu(struct v4l2_ctrl *ctrl, const char * const *qmenu, + s32 max, u32 menu_skip_mask, s32 def) +{ + if (WARN_ON(ctrl-type != V4L2_CTRL_TYPE_MENU || qmenu == NULL)) + return; + + if (WARN_ON(def 0 || def max)) + return; + + ctrl-qmenu = qmenu; + ctrl-maximum = max; + ctrl-menu_skip_mask = menu_skip_mask; + ctrl-cur.val = ctrl-val = ctrl-default_value = def; +} +EXPORT_SYMBOL(v4l2_ctrl_modify_menu); diff --git a/include/media/v4l2-ctrls.h b/include/media/v4l2-ctrls.h index 776605f..5303489 100644 --- a/include/media/v4l2-ctrls.h +++ b/include/media/v4l2-ctrls.h @@ -488,6 +488,17 @@ static inline void v4l2_ctrl_unlock(struct v4l2_ctrl *ctrl) mutex_unlock(ctrl-handler-lock); } +/** + * v4l2_ctrl_modify_menu() - This function is used to modify the menu. + * @ctrl: The control whose menu should be modified. + * @qmenu: The new menu. + * @max: Maximum value of the control. + * @menu_skip_mask:The control's skip mask for menu controls. + * @def: The default value for control to be set. + */ +void v4l2_ctrl_modify_menu(struct v4l2_ctrl *ctrl, const char * const *qmenu, + s32 max, u32 menu_skip_mask, s32 def); + /** v4l2_ctrl_g_ctrl() - Helper function to get the control's value from within a driver. * @ctrl: The control. * -- 1.7.0.4 -- To unsubscribe from this list: send the line unsubscribe linux-media in the body of a message to majord...@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html
Re: [PATCH v3] media: v4l2-ctrl: add a helper function to modify the menu
On Tue 11 September 2012 16:23:38 Prabhakar Lad wrote: From: Lad, Prabhakar prabhakar@ti.com Add a helper function to modify the menu, max and default value to set. Signed-off-by: Lad, Prabhakar prabhakar@ti.com Signed-off-by: Manjunath Hadli manjunath.ha...@ti.com Cc: Hans Verkuil hans.verk...@cisco.com Cc: Sakari Ailus sakari.ai...@iki.fi Cc: Sylwester Nawrocki s.nawro...@samsung.com Cc: Laurent Pinchart laurent.pinch...@ideasonboard.com Cc: Mauro Carvalho Chehab mche...@infradead.org Cc: Hans de Goede hdego...@redhat.com Cc: Kyungmin Park kyungmin.p...@samsung.com Cc: Guennadi Liakhovetski g.liakhovet...@gmx.de Cc: Rob Landley r...@landley.net Thanks! Reviewed-by: Hans Verkuil hans.verk...@cisco.com Regards, Hans --- Changes for v3: 1: Fixed style/grammer issues as pointed by Hans. Thanks Hans for providing the description. Changes for v2: 1: Fixed review comments from Hans, to have return type as void, add WARN_ON() for fail conditions, allow this fucntion to modify the menu of custom controls. Documentation/video4linux/v4l2-controls.txt | 29 +++ drivers/media/v4l2-core/v4l2-ctrls.c| 17 +++ include/media/v4l2-ctrls.h | 11 ++ 3 files changed, 57 insertions(+), 0 deletions(-) diff --git a/Documentation/video4linux/v4l2-controls.txt b/Documentation/video4linux/v4l2-controls.txt index 43da22b..01d0a82 100644 --- a/Documentation/video4linux/v4l2-controls.txt +++ b/Documentation/video4linux/v4l2-controls.txt @@ -367,6 +367,35 @@ it to 0 means that all menu items are supported. You set this mask either through the v4l2_ctrl_config struct for a custom control, or by calling v4l2_ctrl_new_std_menu(). +There are situations where menu items may be device specific. In such cases the +framework provides a helper function to change the menu: + +void v4l2_ctrl_modify_menu(struct v4l2_ctrl *ctrl, const char * const *qmenu, + s32 max, u32 menu_skip_mask, s32 def); + +A good example is the test pattern control for capture/display/sensors devices +that have the capability to generate test patterns. These test patterns are +hardware specific, so the contents of the menu will vary from device to device. + +This helper function is used to modify the menu, max, mask and the default +value of the control. + +Example: + + static const char * const test_pattern[] = { + Disabled, + Vertical Bars, + Solid Black, + Solid White, + NULL, + }; + struct v4l2_ctrl *test_pattern_ctrl = + v4l2_ctrl_new_std_menu(foo-ctrl_handler, foo_ctrl_ops, + V4L2_CID_TEST_PATTERN, V4L2_TEST_PATTERN_DISABLED, 0, + V4L2_TEST_PATTERN_DISABLED); + + v4l2_ctrl_modify_menu(test_pattern_ctrl, test_pattern, 3, 0, + V4L2_TEST_PATTERN_DISABLED); Custom Controls === diff --git a/drivers/media/v4l2-core/v4l2-ctrls.c b/drivers/media/v4l2-core/v4l2-ctrls.c index d731422..d89b460 100644 --- a/drivers/media/v4l2-core/v4l2-ctrls.c +++ b/drivers/media/v4l2-core/v4l2-ctrls.c @@ -2666,3 +2666,20 @@ unsigned int v4l2_ctrl_poll(struct file *file, struct poll_table_struct *wait) return 0; } EXPORT_SYMBOL(v4l2_ctrl_poll); + +/* Helper function for modifying the menu */ +void v4l2_ctrl_modify_menu(struct v4l2_ctrl *ctrl, const char * const *qmenu, +s32 max, u32 menu_skip_mask, s32 def) +{ + if (WARN_ON(ctrl-type != V4L2_CTRL_TYPE_MENU || qmenu == NULL)) + return; + + if (WARN_ON(def 0 || def max)) + return; + + ctrl-qmenu = qmenu; + ctrl-maximum = max; + ctrl-menu_skip_mask = menu_skip_mask; + ctrl-cur.val = ctrl-val = ctrl-default_value = def; +} +EXPORT_SYMBOL(v4l2_ctrl_modify_menu); diff --git a/include/media/v4l2-ctrls.h b/include/media/v4l2-ctrls.h index 776605f..5303489 100644 --- a/include/media/v4l2-ctrls.h +++ b/include/media/v4l2-ctrls.h @@ -488,6 +488,17 @@ static inline void v4l2_ctrl_unlock(struct v4l2_ctrl *ctrl) mutex_unlock(ctrl-handler-lock); } +/** + * v4l2_ctrl_modify_menu() - This function is used to modify the menu. + * @ctrl:The control whose menu should be modified. + * @qmenu: The new menu. + * @max: Maximum value of the control. + * @menu_skip_mask: The control's skip mask for menu controls. + * @def: The default value for control to be set. + */ +void v4l2_ctrl_modify_menu(struct v4l2_ctrl *ctrl, const char * const *qmenu, +s32 max, u32 menu_skip_mask, s32 def); + /** v4l2_ctrl_g_ctrl() - Helper function to get the control's value from within a driver. * @ctrl: The control. * -- To unsubscribe from this list: send the line unsubscribe linux-media in the body of a message to