Skip to contentSkip to conversation

uvcvideo: Return sensible min and max values when querying a boolean control.

PATCH In review Laurent Pinchart 2 participants 6 messages Jul 17, 2008 – Jul 22, 2008 Media (V4L/DVB)

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 uvcvideo: Return sensible min and max values when querying a boolean control.

Although the V4L2 spec states that the minimum and maximum fields may not be valid for control types other than V4L2_CTRL_TYPE_INTEGER, it makes sense to set the bounds to 0 and 1 for boolean controls instead of returning uninitialized values.

---
 drivers/media/video/uvc/uvc_ctrl.c |   13 ++++++++++++-
 1 files changed, 12 insertions(+), 1 deletions(-)
(quoted diff) +0 -0

b/drivers/media/video/uvc/uvc_ctrl.c
index f0ee46d..0a446f0 100644

drivers/media/video/uvc/uvc_ctrl.c +12 -1
@@ -592,6 +592,7 @@ int uvc_query_v4l2_ctrl(struct uvc_video_device *video,
 	if (ctrl == NULL)
 		return -EINVAL;
 
+	memset(v4l2_ctrl, 0, sizeof *v4l2_ctrl);
 	v4l2_ctrl->id = mapping->id;
 	v4l2_ctrl->type = mapping->v4l2_type;
 	strncpy(v4l2_ctrl->name, mapping->name, sizeof v4l2_ctrl->name);
@@ -608,7 +609,8 @@ int uvc_query_v4l2_ctrl(struct uvc_video_device *video,
 		v4l2_ctrl->default_value = uvc_get_le_value(data, mapping);
 	}
 
-	if (mapping->v4l2_type == V4L2_CTRL_TYPE_MENU) {
+	switch (mapping->v4l2_type) {
+	case V4L2_CTRL_TYPE_MENU:
 		v4l2_ctrl->minimum = 0;
 		v4l2_ctrl->maximum = mapping->menu_count - 1;
 		v4l2_ctrl->step = 1;
@@ -622,6 +624,15 @@ int uvc_query_v4l2_ctrl(struct uvc_video_device *video,
 		}
 
 		return 0;
+
+	case V4L2_CTRL_TYPE_BOOLEAN:
+		v4l2_ctrl->minimum = 0;
+		v4l2_ctrl->maximum = 1;
+		v4l2_ctrl->step = 1;
+		return 0;
+
+	default:
+		break;
 	}
 
 	if (ctrl->info->flags & UVC_CONTROL_GET_MIN) {
Signature · 6 lines
1.5.4.5

--
video4linux-list mailing list
Unsubscribe mailto:[email protected]?subject=unsubscribe
https://www.redhat.com/mailman/listinfo/video4linux-list
#1 lore raw
Quoted 4 lines · On Thursday 17 July 2008 12:37:37 Laurent Pinchart wrote:

Although the V4L2 spec states that the minimum and maximum fields may not be valid for control types other than V4L2_CTRL_TYPE_INTEGER, it makes sense to set the bounds to 0 and 1 for boolean controls instead of returning uninitialized values.

Hi Laurent,

Are you aware of the control support functions in v4l2-common.c? In my opinion it would be a good idea if you would try to use those. In particular adding the control definitions for the standard camera controls to v4l2-common.c so that every driver that uses those will get the same control strings and data.

I also do not see any support for the V4L2_CID_CAMERA_CLASS control: it should return a description of the camera control class. It is used in e.g. v4l2-ctl --list-ctrls:

User Controls

                     brightness (int)  : min=0 max=255 step=1... 

where the string "User Controls" comes from the V4L2_CID_USER_CLASS.

I want to prevent having different driver present different control query results to the user, even though it's the same control.

Testing with v4l2-ctl is a good way to verify that it is all working as it should. Also qv4l2 is a useful tool to see if the controls use the correct GUI elements. Note that this currently only builds for qt3. Mauro made a patch to allow it to build for qt4, but I haven't gotten around to testing that (sorry Mauro).

Regards,

Hans

Quoted 34 lines
---
 drivers/media/video/uvc/uvc_ctrl.c |   13 ++++++++++++-
 1 files changed, 12 insertions(+), 1 deletions(-)
drivers/media/video/uvc/uvc_ctrl.c +5 -1
index f0ee46d..0a446f0 100644
@@ -592,6 +592,7 @@ int uvc_query_v4l2_ctrl(struct uvc_video_device
 *video, if (ctrl == NULL)
 		return -EINVAL;
 
+	memset(v4l2_ctrl, 0, sizeof *v4l2_ctrl);
 	v4l2_ctrl->id = mapping->id;
 	v4l2_ctrl->type = mapping->v4l2_type;
 	strncpy(v4l2_ctrl->name, mapping->name, sizeof v4l2_ctrl->name);
@@ -608,7 +609,8 @@ int uvc_query_v4l2_ctrl(struct uvc_video_device
 *video, v4l2_ctrl->default_value = uvc_get_le_value(data, mapping); }
 
-	if (mapping->v4l2_type == V4L2_CTRL_TYPE_MENU) {
+	switch (mapping->v4l2_type) {
+	case V4L2_CTRL_TYPE_MENU:
 		v4l2_ctrl->minimum = 0;
 		v4l2_ctrl->maximum = mapping->menu_count - 1;
 		v4l2_ctrl->step = 1;
@@ -622,6 +624,15 @@ int uvc_query_v4l2_ctrl(struct uvc_video_device
 *video, }
 
 		return 0;
+
+	case V4L2_CTRL_TYPE_BOOLEAN:

drivers/media/video/uvc/uvc_ctrl.c int uvc_query_v4l2_ctrl(struct uvc_video_device · line 638

Quoted 10 lines
drivers/media/video/uvc/uvc_ctrl.c +7 -0
+		v4l2_ctrl->minimum = 0;
+		v4l2_ctrl->maximum = 1;
+		v4l2_ctrl->step = 1;
+		return 0;
+
+	default:
+		break;
 	}
 
 	if (ctrl->info->flags & UVC_CONTROL_GET_MIN) {

--
video4linux-list mailing list
Unsubscribe mailto:[email protected]?subject=unsubscribe
https://www.redhat.com/mailman/listinfo/video4linux-list

#2 lore raw

Hi Hans,

Quoted 6 lines · Hans Verkuil
Quoted 4 lines · On Thursday 17 July 2008 12:37:37 Laurent Pinchart wrote:

Although the V4L2 spec states that the minimum and maximum fields may not be valid for control types other than V4L2_CTRL_TYPE_INTEGER, it makes sense to set the bounds to 0 and 1 for boolean controls instead of returning uninitialized values.

Quoted 7 lines

Hi Laurent,

Are you aware of the control support functions in v4l2-common.c? In my opinion it would be a good idea if you would try to use those. In particular adding the control definitions for the standard camera controls to v4l2-common.c so that every driver that uses those will get the same control strings and data.

I suppose you're referring to the v4l2_ctrl_* functions. I wasn't aware of them.

Some of them, such as v4l2_ctrl_get_menu() and v4l2_ctrl_query_fill(), are interesting to share control names across drivers, although they could make the kernel larger than necessary when only a single (or very few) V4L2 driver is compiled in.

Most of the other functions don't make much sense for the uvcvideo driver. For instance, the uvcvideo driver needs to associate private data with each menu item, so a static list of names isn't the best solution. Filling control information with standard minimum, maximum, step and default values is also not an option, as that information varies between UVC devices and is reported by the hardware directly.

Quoted 9 lines

I also do not see any support for the V4L2_CID_CAMERA_CLASS control: it should return a description of the camera control class. It is used in e.g. v4l2-ctl --list-ctrls:

User Controls

                     brightness (int)  : min=0 max=255 step=1...

where the string "User Controls" comes from the V4L2_CID_USER_CLASS.

What's the point of having a control that actually controls nothing ?

Quoted 2 lines

I want to prevent having different driver present different control query results to the user, even though it's the same control.

Names should be standard, but boundaries can vary between devices.

Quoted 5 lines

Testing with v4l2-ctl is a good way to verify that it is all working as it should. Also qv4l2 is a useful tool to see if the controls use the correct GUI elements. Note that this currently only builds for qt3. Mauro made a patch to allow it to build for qt4, but I haven't gotten around to testing that (sorry Mauro).

Thanks for the information, I'll try those applications.

Best regards,

Laurent Pinchart

--
video4linux-list mailing list
Unsubscribe mailto:[email protected]?subject=unsubscribe
https://www.redhat.com/mailman/listinfo/video4linux-list

#3 lore raw
Quoted 25 lines · On Friday 18 July 2008 23:11:17 Laurent Pinchart wrote:

Hi Hans,

Quoted 6 lines · Hans Verkuil
Quoted 4 lines · On Thursday 17 July 2008 12:37:37 Laurent Pinchart wrote:

Although the V4L2 spec states that the minimum and maximum fields may not be valid for control types other than V4L2_CTRL_TYPE_INTEGER, it makes sense to set the bounds to 0 and 1 for boolean controls instead of returning uninitialized values.

Quoted 7 lines

Hi Laurent,

Are you aware of the control support functions in v4l2-common.c? In my opinion it would be a good idea if you would try to use those. In particular adding the control definitions for the standard camera controls to v4l2-common.c so that every driver that uses those will get the same control strings and data.

I suppose you're referring to the v4l2_ctrl_* functions. I wasn't aware of them.

Some of them, such as v4l2_ctrl_get_menu() and v4l2_ctrl_query_fill(), are interesting to share control names across drivers, although they could make the kernel larger than necessary when only a single (or very few) V4L2 driver is compiled in.

Quoted 6 lines

Most of the other functions don't make much sense for the uvcvideo driver. For instance, the uvcvideo driver needs to associate private data with each menu item, so a static list of names isn't the best solution. Filling control information with standard minimum, maximum, step and default values is also not an option, as that information varies between UVC devices and is reported by the hardware directly.

I suspected as much, but see if there is some way to have a central place to keep the standard camera control descriptions. The reason for creating the functions in v4l2-common.c in the first place was to attempt to limit the wild variations in namings that were (are) in use.

Quoted 4 lines
Quoted 4 lines

I also do not see any support for the V4L2_CID_CAMERA_CLASS
control: it should return a description of the camera control class. It is used in e.g. v4l2-ctl --list-ctrls:

Quoted 8 lines
Quoted 6 lines

User Controls

                     brightness (int)  : min=0 max=255 step=1...

where the string "User Controls" comes from the
V4L2_CID_USER_CLASS.

What's the point of having a control that actually controls nothing ?

Try qv4l2: it's used as the caption for the control panels, or as the caption in v4l2-ctl --list-ctrls. It's a user interface element. The point it to let applications create control panel like GUIs. And for that they need to know how to group them and what to call those groups.

Quoted 4 lines
Quoted 2 lines

I want to prevent having different driver present different control query results to the user, even though it's the same control.

Names should be standard, but boundaries can vary between devices.

True, that's why v4l2_ctrl_query_fill was made: boundaries are passed to the function, but the description and type info is filled in for you.

Quoted 7 lines
Quoted 5 lines

Testing with v4l2-ctl is a good way to verify that it is all working as it should. Also qv4l2 is a useful tool to see if the controls use the correct GUI elements. Note that this currently only builds for qt3. Mauro made a patch to allow it to build for qt4, but I haven't gotten around to testing that (sorry Mauro).

Thanks for the information, I'll try those applications.

Regards,

Hans

--
video4linux-list mailing list
Unsubscribe mailto:[email protected]?subject=unsubscribe
https://www.redhat.com/mailman/listinfo/video4linux-list

#4 lore raw
Quoted 29 lines · Hans Verkuil
Quoted 21 lines · On Friday 18 July 2008 23:11:17 Laurent Pinchart wrote:
Quoted 11 lines · Hans Verkuil
Quoted 4 lines · On Thursday 17 July 2008 12:37:37 Laurent Pinchart wrote:

Although the V4L2 spec states that the minimum and maximum fields may not be valid for control types other than V4L2_CTRL_TYPE_INTEGER, it makes sense to set the bounds to 0 and 1 for boolean controls instead of returning uninitialized values.

Are you aware of the control support functions in v4l2-common.c? In my opinion it would be a good idea if you would try to use those. In particular adding the control definitions for the standard camera controls to v4l2-common.c so that every driver that uses those will get the same control strings and data.

I suppose you're referring to the v4l2_ctrl_* functions. I wasn't aware of them.

Some of them, such as v4l2_ctrl_get_menu() and v4l2_ctrl_query_fill(), are interesting to share control names across drivers, although they could make the kernel larger than necessary when only a single (or very few) V4L2 driver is compiled in.

Quoted 6 lines

Most of the other functions don't make much sense for the uvcvideo driver. For instance, the uvcvideo driver needs to associate private data with each menu item, so a static list of names isn't the best solution. Filling control information with standard minimum, maximum, step and default values is also not an option, as that information varies between UVC devices and is reported by the hardware directly.

Quoted 4 lines

I suspected as much, but see if there is some way to have a central place to keep the standard camera control descriptions. The reason for creating the functions in v4l2-common.c in the first place was to attempt to limit the wild variations in namings that were (are) in use.

What about creating a new function

const char *v4l2_ctrl_get_name(unsigned int id);

that would be used both by v4l2_ctrl_query_fill() and directly by drivers with 'advanced' needs such as uvcvideo ? This could serve as a central control names repository.

On a side note, I'm still not completely convinced that providing control names should be the responsibility of the kernel. A userspace library would do a better job at handling i18n.

Quoted 11 lines
Quoted 11 lines
Quoted 10 lines

I also do not see any support for the V4L2_CID_CAMERA_CLASS
control: it should return a description of the camera control class. It is used in e.g. v4l2-ctl --list-ctrls:

User Controls

                     brightness (int)  : min=0 max=255 step=1...

where the string "User Controls" comes from the
V4L2_CID_USER_CLASS.

Quoted 6 lines
Quoted 1 line

What's the point of having a control that actually controls nothing ?

Try qv4l2: it's used as the caption for the control panels, or as the caption in v4l2-ctl --list-ctrls. It's a user interface element. The point it to let applications create control panel like GUIs. And for that they need to know how to group them and what to call those groups.

Where can I get the latest version ? I'd prefer a tarball as I don't have mercurial installed.

Quoted 7 lines
Quoted 4 lines
Quoted 2 lines

I want to prevent having different driver present different control query results to the user, even though it's the same control.

Names should be standard, but boundaries can vary between devices.

True, that's why v4l2_ctrl_query_fill was made: boundaries are passed to the function, but the description and type info is filled in for you.

I was referring to v4l2_ctrl_query_fill_std().

Quoted 7 lines
Quoted 7 lines
Quoted 5 lines

Testing with v4l2-ctl is a good way to verify that it is all working as it should. Also qv4l2 is a useful tool to see if the controls use the correct GUI elements. Note that this currently only builds for qt3. Mauro made a patch to allow it to build for qt4, but I haven't gotten around to testing that (sorry Mauro).

Thanks for the information, I'll try those applications.

Best regards,

Laurent Pinchart

--
video4linux-list mailing list
Unsubscribe mailto:[email protected]?subject=unsubscribe
https://www.redhat.com/mailman/listinfo/video4linux-list

#5 lore raw
Quoted 40 lines · On Tuesday 22 July 2008 23:23:25 Laurent Pinchart wrote:
Quoted 33 lines · Hans Verkuil
Quoted 24 lines · On Friday 18 July 2008 23:11:17 Laurent Pinchart wrote:
Quoted 7 lines · Hans Verkuil
Quoted 5 lines · On Thursday 17 July 2008 12:37:37 Laurent Pinchart wrote:

Although the V4L2 spec states that the minimum and maximum fields may not be valid for control types other than V4L2_CTRL_TYPE_INTEGER, it makes sense to set the bounds to 0 and 1 for boolean controls instead of returning uninitialized values.

Quoted 6 lines

Are you aware of the control support functions in v4l2-common.c? In my opinion it would be a good idea if you would try to use those. In particular adding the control definitions for the standard camera controls to v4l2-common.c so that every driver that uses those will get the same control strings and data.

I suppose you're referring to the v4l2_ctrl_* functions. I wasn't aware of them.

Some of them, such as v4l2_ctrl_get_menu() and v4l2_ctrl_query_fill(), are interesting to share control names across drivers, although they could make the kernel larger than necessary when only a single (or very few) V4L2 driver is compiled in.

Quoted 7 lines

Most of the other functions don't make much sense for the uvcvideo driver. For instance, the uvcvideo driver needs to associate private data with each menu item, so a static list of names isn't the best solution. Filling control information with standard minimum, maximum, step and default values is also not an option, as that information varies between UVC devices and is reported by the hardware directly.

Quoted 5 lines

I suspected as much, but see if there is some way to have a central place to keep the standard camera control descriptions. The reason for creating the functions in v4l2-common.c in the first place was to attempt to limit the wild variations in namings that were (are) in use.

Quoted 7 lines

What about creating a new function

const char *v4l2_ctrl_get_name(unsigned int id);

that would be used both by v4l2_ctrl_query_fill() and directly by drivers with 'advanced' needs such as uvcvideo ? This could serve as a central control names repository.

Good idea.

Quoted 3 lines

On a side note, I'm still not completely convinced that providing control names should be the responsibility of the kernel. A userspace library would do a better job at handling i18n.

Yes and no. First of all we need this since that was the way the API was designed about 10 years ago. So we are stuck with it. Personally, I do not think it is such a bad idea to have a kernel provide some sort of a description. You can still use the control ID as a mapping in a library to do the translation as long as you refrain from using the V4L2_CID_PRIVATE_BASE controls since the same private control can have a different meaning in different drivers. If a new driver appears with new controls and there is no translation available, then you can still fall back on what the kernel provides.

Note that with the extended controls API you can make driver-specific controls without having to use V4L2_CID_PRIVATE_BASE. Much cleaner IMHO.

Quoted 15 lines
Quoted 15 lines
Quoted 14 lines
Quoted 11 lines

I also do not see any support for the V4L2_CID_CAMERA_CLASS
control: it should return a description of the camera control class. It is used in e.g. v4l2-ctl --list-ctrls:

User Controls

                     brightness (int)  : min=0 max=255

step=1...

where the string "User Controls" comes from the
V4L2_CID_USER_CLASS.

What's the point of having a control that actually controls nothing ?

Quoted 8 lines
Quoted 5 lines

Try qv4l2: it's used as the caption for the control panels, or as the caption in v4l2-ctl --list-ctrls. It's a user interface element. The point it to let applications create control panel like GUIs. And for that they need to know how to group them and what to call those groups.

Where can I get the latest version ? I'd prefer a tarball as I don't have mercurial installed.

Just in any hg tree, e.g.:

http://linuxtv.org/hg/v4l-dvb/archive/tip.tar.bz2

It's in the v4l2-apps directory (I think v4l2-apps should become a stand-alone tree, but that's another discussion).

Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 3 lines

I want to prevent having different driver present different control query results to the user, even though it's the same control.

Quoted 17 lines
Quoted 6 lines
Quoted 2 lines

Names should be standard, but boundaries can vary between devices.

True, that's why v4l2_ctrl_query_fill was made: boundaries are passed to the function, but the description and type info is filled in for you.

I was referring to v4l2_ctrl_query_fill_std().

Quoted 8 lines
Quoted 8 lines
Quoted 6 lines

Testing with v4l2-ctl is a good way to verify that it is all working as it should. Also qv4l2 is a useful tool to see if the controls use the correct GUI elements. Note that this currently only builds for qt3. Mauro made a patch to allow it to build for qt4, but I haven't gotten around to testing that (sorry Mauro).

Thanks for the information, I'll try those applications.

Regards,

Hans

--
video4linux-list mailing list
Unsubscribe mailto:[email protected]?subject=unsubscribe
https://www.redhat.com/mailman/listinfo/video4linux-list