Name

VIDIOC_G_EXT_CTRLS, VIDIOC_S_EXT_CTRLS, VIDIOC_TRY_EXT_CTRLS — Get or set the value of several controls, try control values

Synopsis

int ioctl(int  fd,
 int  request,
 struct v4l2_ext_controls * argp);

Arguments

fd

File descriptor returned by open().

request

VIDIOC_G_EXT_CTRLS, VIDIOC_S_EXT_CTRLS, VIDIOC_TRY_EXT_CTRLS

argp

Description

These ioctls allow the caller to get or set multiple controls atomically. Control IDs are grouped into control classes (see Table 80, “Control classes”) and all controls in the control array must belong to the same control class.

Applications must always fill in the count, ctrl_class, controls and reserved fields of struct v4l2_ext_controls, and initialize the struct v4l2_ext_control array pointed to by the controls fields.

To get the current value of a set of controls applications initialize the id, size and reserved2 fields of each struct v4l2_ext_control and call the VIDIOC_G_EXT_CTRLS ioctl. String controls controls must also set the string field.

If the size is too small to receive the control result (only relevant for pointer-type controls like strings), then the driver will set size to a valid value and return an ENOSPC error code. You should re-allocate the string memory to this new size and try again. It is possible that the same issue occurs again if the string has grown in the meantime. It is recommended to call VIDIOC_QUERYCTRL first and use maximum+1 as the new size value. It is guaranteed that that is sufficient memory.

To change the value of a set of controls applications initialize the id, size, reserved2 and value/string fields of each struct v4l2_ext_control and call the VIDIOC_S_EXT_CTRLS ioctl. The controls will only be set if all control values are valid.

To check if a set of controls have correct values applications initialize the id, size, reserved2 and value/string fields of each struct v4l2_ext_control and call the VIDIOC_TRY_EXT_CTRLS ioctl. It is up to the driver whether wrong values are automatically adjusted to a valid value or if an error is returned.

When the id or ctrl_class is invalid drivers return an EINVAL error code. When the value is out of bounds drivers can choose to take the closest valid value or return an ERANGE error code, whatever seems more appropriate. In the first case the new value is set in struct v4l2_ext_control.

The driver will only set/get these controls if all control values are correct. This prevents the situation where only some of the controls were set/get. Only low-level errors (e. g. a failed i2c command) can still cause this situation.

Table 78. struct v4l2_ext_control

__u32id Identifies the control, set by the application.
__u32size The total size in bytes of the payload of this control. This is normally 0, but for pointer controls this should be set to the size of the memory containing the payload, or that will receive the payload. If VIDIOC_G_EXT_CTRLS finds that this value is less than is required to store the payload result, then it is set to a value large enough to store the payload result and ENOSPC is returned. Note that for string controls this size field should not be confused with the length of the string. This field refers to the size of the memory that contains the string. The actual length of the string may well be much smaller.
__u32reserved2[1] Reserved for future extensions. Drivers and applications must set the array to zero.
union(anonymous)  
 __s32valueNew value or current value.
 __s64value64New value or current value.
 char *stringA pointer to a string.

Table 79. struct v4l2_ext_controls

__u32ctrl_classThe control class to which all controls belong, see Table 80, “Control classes”.
__u32countThe number of controls in the controls array. May also be zero.
__u32error_idxSet by the driver in case of an error. It is the index of the control causing the error or equal to 'count' when the error is not associated with a particular control. Undefined when the ioctl returns 0 (success).
__u32reserved[2]Reserved for future extensions. Drivers and applications must set the array to zero.
struct v4l2_ext_control *controlsPointer to an array of count v4l2_ext_control structures. Ignored if count equals zero.

Table 80. Control classes

V4L2_CTRL_CLASS_USER0x980000The class containing user controls. These controls are described in Section 1.8, “User Controls”. All controls that can be set using the VIDIOC_S_CTRL and VIDIOC_G_CTRL ioctl belong to this class.
V4L2_CTRL_CLASS_MPEG0x990000The class containing MPEG compression controls. These controls are described in Section 1.9.5, “MPEG Control Reference”.
V4L2_CTRL_CLASS_CAMERA0x9a0000The class containing camera controls. These controls are described in Section 1.9.6, “Camera Control Reference”.
V4L2_CTRL_CLASS_FM_TX0x9b0000The class containing FM Transmitter (FM TX) controls. These controls are described in Section 1.9.7, “FM Transmitter Control Reference”.

Return Value

On success 0 is returned, on error -1 and the errno variable is set appropriately:

EINVAL

The struct v4l2_ext_control id is invalid or the struct v4l2_ext_controls ctrl_class is invalid. This error code is also returned by the VIDIOC_S_EXT_CTRLS and VIDIOC_TRY_EXT_CTRLS ioctls if two or more control values are in conflict.

ERANGE

The struct v4l2_ext_control value is out of bounds.

EBUSY

The control is temporarily not changeable, possibly because another applications took over control of the device function this control belongs to.

ENOSPC

The space reserved for the control's payload is insufficient. The field size is set to a value that is enough to store the payload and this error code is returned.