ioctl VIDIOC_QUERYCTRL, VIDIOC_QUERYMENU
&manvol;

# VIDIOC_QUERYCTRL

# VIDIOC_QUERYMENU

Enumerate controls and menu control items

    	int ioctl
    	int fd
    	int request
    	struct v4l2_queryctrl *argp

    	int ioctl
    	int fd
    	int request
    	struct v4l2_querymenu *argp

## Arguments

`fd`

  &fd;

`request`

  VIDIOC_QUERYCTRL, VIDIOC_QUERYMENU

`argp`

## Description

To query the attributes of a control applications set the id field of a &v4l2-queryctrl; and call the `VIDIOC_QUERYCTRL` ioctl with a pointer to this structure. The driver fills the rest of the structure or returns an &EINVAL; when the id is invalid.

It is possible to enumerate controls by calling `VIDIOC_QUERYCTRL` with successive id values starting from `V4L2_CID_BASE` up to and exclusive `V4L2_CID_BASE_LASTP1`. Drivers may return EINVAL if a control in this range is not supported. Further applications can enumerate private controls, which are not defined in this specification, by starting at `V4L2_CID_PRIVATE_BASE` and incrementing id until the driver returns EINVAL.

In both cases, when the driver sets the `V4L2_CTRL_FLAG_DISABLED` flag in the flags field this control is permanently disabled and should be ignored by the application. `V4L2_CTRL_FLAG_DISABLED` was intended for two purposes: Drivers can skip predefined controls not supported by the hardware (although returning EINVAL would do as well), or disable predefined and private controls after hardware detection without the trouble of reordering control arrays and indices (EINVAL cannot be used to skip private controls because it would prematurely end the enumeration).

When the application ORs id with `V4L2_CTRL_FLAG_NEXT_CTRL` the driver returns the next supported control, or EINVAL if there is none. Drivers which do not support this flag yet always return EINVAL.

Additional information is required for menu controls: the names of the menu items. To query them applications set the id and index fields of &v4l2-querymenu; and call the `VIDIOC_QUERYMENU` ioctl with a pointer to this structure. The driver fills the rest of the structure or returns an &EINVAL; when the id or index is invalid. Menu items are enumerated by calling `VIDIOC_QUERYMENU` with successive index values from &v4l2-queryctrl; minimum to maximum, inclusive. Note that it is possible for `VIDIOC_QUERYMENU` to return an &EINVAL; for some indices between minimum and maximum. In that case that particular menu item is not supported by this driver. Also note that the minimum value is not necessarily 0.

See also the examples in .

### struct v4l2_queryctrl

&cs-str;
__u32 | id | Identifies the control, set by the application. See for predefined IDs. When the ID is ORed with V4L2_CTRL_FLAG_NEXT_CTRL the driver clears the flag and returns the first control with a higher ID. Drivers which do not support this flag yet always return an &EINVAL;.
&v4l2-ctrl-type; | type | Type of control, see .
__u8 | name[32] | Name of the control, a NUL-terminated ASCII string. This information is intended for the user.

__s32

minimum

Minimum value, inclusive. This field gives a lower bound for `V4L2_CTRL_TYPE_INTEGER` controls and the lowest valid index for `V4L2_CTRL_TYPE_MENU` controls. For `V4L2_CTRL_TYPE_STRING` controls the minimum value gives the minimum length of the string. This length does not include the terminating zero. It may not be valid for any other type of control, including `V4L2_CTRL_TYPE_INTEGER64` controls. Note that this is a signed value.

__s32

maximum

Maximum value, inclusive. This field gives an upper bound for `V4L2_CTRL_TYPE_INTEGER` controls and the highest valid index for `V4L2_CTRL_TYPE_MENU` controls. For `V4L2_CTRL_TYPE_STRING` controls the maximum value gives the maximum length of the string. This length does not include the terminating zero. It may not be valid for any other type of control, including `V4L2_CTRL_TYPE_INTEGER64` controls. Note that this is a signed value.

__s32

step

This field gives a step size for `V4L2_CTRL_TYPE_INTEGER` controls. For `V4L2_CTRL_TYPE_STRING` controls this field refers to the string length that has to be a multiple of this step size. It may not be valid for any other type of control, including `V4L2_CTRL_TYPE_INTEGER64` controls.

Generally drivers should not scale hardware control values. It may be necessary for example when the name or id imply a particular unit and the hardware actually accepts only multiples of said unit. If so, drivers must take care values are properly rounded when scaling, such that errors will not accumulate on repeated read-write cycles.

This field gives the smallest change of an integer control actually affecting hardware. Often the information is needed when the user can change controls by keyboard or GUI buttons, rather than a slider. When for example a hardware register accepts values 0-511 and the driver reports 0-65535, step should be 128.

Note that although signed, the step value is supposed to be always positive.

__s32 | default_value | The default value of a `V4L2_CTRL_TYPE_INTEGER`, `_BOOLEAN` or `_MENU` control. Not valid for other types of controls. Drivers reset controls only when the driver is loaded, not later, in particular not when the func-open; is called.
__u32 | flags | Control flags, see .
__u32 | reserved[2] | Reserved for future extensions. Drivers must set the array to zero.

### struct v4l2_querymenu

&cs-str;
__u32 | id | Identifies the control, set by the application from the respective &v4l2-queryctrl; id.
__u32 | index | Index of the menu item, starting at zero, set by the application.
__u8 | name[32] | Name of the menu item, a NUL-terminated ASCII string. This information is intended for the user.
__u32 | reserved | Reserved for future extensions. Drivers must set the array to zero.

### enum v4l2_ctrl_type

Type | minimum | step | maximum | Description
--- | --- | --- | --- | ---
`V4L2_CTRL_TYPE_INTEGER` | any | any | any | An integer-valued control ranging from minimum to maximum inclusive. The step value indicates the increment between values which are actually different on the hardware.
`V4L2_CTRL_TYPE_BOOLEAN` | 0 | 1 | 1 | A boolean-valued control. Zero corresponds to "disabled", and one means "enabled".
`V4L2_CTRL_TYPE_MENU` | ≥ 0 | 1 | N-1 | The control has a menu of N choices. The names of the menu items can be enumerated with the `VIDIOC_QUERYMENU` ioctl.
`V4L2_CTRL_TYPE_BUTTON` | 0 | 0 | 0 | A control which performs an action when set. Drivers must ignore the value passed with `VIDIOC_S_CTRL` and return an &EINVAL; on a `VIDIOC_G_CTRL` attempt.
`V4L2_CTRL_TYPE_INTEGER64` | n/a | n/a | n/a | A 64-bit integer valued control. Minimum, maximum and step size cannot be queried.

`V4L2_CTRL_TYPE_STRING`

≥ 0

≥ 1

≥ 0

The minimum and maximum string lengths. The step size means that the string must be (minimum + N * step) characters long for N ≥ 0. These lengths do not include the terminating zero, so in order to pass a string of length 8 to &VIDIOC-S-EXT-CTRLS; you need to set the size field of &v4l2-ext-control; to 9. For &VIDIOC-G-EXT-CTRLS; you can set the size field to maximum + 1. Which character encoding is used will depend on the string control itself and should be part of the control documentation.

`V4L2_CTRL_TYPE_CTRL_CLASS` | n/a | n/a | n/a | This is not a control. When `VIDIOC_QUERYCTRL` is called with a control ID equal to a control class code (see ) + 1, the ioctl returns the name of the control class and this control type. Older drivers which do not support this feature return an &EINVAL;.

### Control Flags

&cs-def;
`V4L2_CTRL_FLAG_DISABLED` | 0x0001 | This control is permanently disabled and should be ignored by the application. Any attempt to change the control will result in an &EINVAL;.
`V4L2_CTRL_FLAG_GRABBED` | 0x0002 | This control is temporarily unchangeable, for example because another application took over control of the respective resource. Such controls may be displayed specially in a user interface. Attempts to change the control may result in an &EBUSY;.
`V4L2_CTRL_FLAG_READ_ONLY` | 0x0004 | This control is permanently readable only. Any attempt to change the control will result in an &EINVAL;.
`V4L2_CTRL_FLAG_UPDATE` | 0x0008 | A hint that changing this control may affect the value of other controls within the same control class. Applications should update their user interface accordingly.
`V4L2_CTRL_FLAG_INACTIVE` | 0x0010 | This control is not applicable to the current configuration and should be displayed accordingly in a user interface. For example the flag may be set on a MPEG audio level 2 bitrate control when MPEG audio encoding level 1 was selected with another control.
`V4L2_CTRL_FLAG_SLIDER` | 0x0020 | A hint that this control is best represented as a slider-like element in a user interface.
`V4L2_CTRL_FLAG_WRITE_ONLY` | 0x0040 | This control is permanently writable only. Any attempt to read the control will result in an &EACCES; error code. This flag is typically present for relative controls or action controls where writing a value will cause the device to carry out a given action (&eg; motor control) but no meaningful value can be returned.

&return-value;

EINVAL

  The &v4l2-queryctrl; id is invalid. The &v4l2-querymenu; id is invalid or index is out of range (less than minimum or greater than maximum) or this particular menu item is not supported by the driver.

EACCES

  An attempt was made to read a write-only control.