ioctl VIDIOC_G_EXT_CTRLS, VIDIOC_S_EXT_CTRLS, VIDIOC_TRY_EXT_CTRLS
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, VIDIOC_G_EXT_CTRLS, struct v4l2_ext_controls *argp)
int ioctl(int fd, VIDIOC_S_EXT_CTRLS, struct v4l2_ext_controls *argp)
int ioctl(int fd, VIDIOC_TRY_EXT_CTRLS, struct v4l2_ext_controls *argp)
Arguments #
-
fdFile descriptor returned by
open(). -
argpPointer to struct
v4l2_ext_controls.
Description #
These ioctls allow the caller to get or set multiple controls atomically. Control IDs are grouped into control classes (see ctrl-class) and all controls in the control array must belong to the same control class.
Applications must always fill in the count, which, 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 must also set the string field. Controls of compound types (V4L2_CTRL_FLAG_HAS_PAYLOAD is set) must set the ptr 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 memory to this new size and try again. For the string type it is possible that the same issue occurs again if the string has grown in the meantime. It is recommended to call ioctls VIDIOC_QUERYCTRL, VIDIOC_QUERY_EXT_CTRL and VIDIOC_QUERYMENU first and use maximum+1 as the new size value. It is guaranteed that that is sufficient memory.
N-dimensional arrays are set and retrieved row-by-row. You cannot set a partial array, all elements have to be set or retrieved. The total size is calculated as elems * elem_size. These values can be obtained by calling VIDIOC_QUERY_EXT_CTRL.
To change the value of a set of controls applications initialize the id, size, reserved2 and value/value64/string/ptr 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/value64/string/ptr 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 which 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. If the new control value is inappropriate (e.g. the given menu index is not supported by the menu control), then this will also result in an EINVAL error code error.
If request_fd is set to a not-yet-queued request file descriptor and which is set to V4L2_CTRL_WHICH_REQUEST_VAL, then the controls are not applied immediately when calling VIDIOC_S_EXT_CTRLS, but instead are applied by the driver for the buffer associated with the same request. If the device does not support requests, then EACCES will be returned. If requests are supported but an invalid request file descriptor is given, then EINVAL will be returned.
An attempt to call VIDIOC_S_EXT_CTRLS for a request that has already been queued will result in an EBUSY error.
If request_fd is specified and which is set to V4L2_CTRL_WHICH_REQUEST_VAL during a call to VIDIOC_G_EXT_CTRLS, then it will return the values of the controls at the time of request completion. If the request is not yet completed, then this will result in an EACCES error.
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.
v4l2_ext_control
|
__u32 |
|
Identifies the control, set by the application. |
|
__u32 |
|
The total size in bytes of the payload of this control. |
|
The |
||
|
__u32 |
|
Reserved for future extensions. Drivers and applications must set the array to zero. |
|
union { |
(anonymous) |
|
|
__s32 |
|
New value or current value. Valid if this control is not of type |
|
__s64 |
|
New value or current value. Valid if this control is of type |
|
char * |
|
A pointer to a string. Valid if this control is of type |
|
__u8 * |
|
A pointer to a matrix control of unsigned 8-bit values. Valid if this control is of type |
|
__u16 * |
|
A pointer to a matrix control of unsigned 16-bit values. Valid if this control is of type |
|
__u32 * |
|
A pointer to a matrix control of unsigned 32-bit values. Valid if this control is of type |
|
__s32 * |
|
A pointer to a matrix control of signed 32-bit values. Valid if this control is of type |
|
__s64 * |
|
A pointer to a matrix control of signed 64-bit values. Valid if this control is of type |
|
struct |
|
A pointer to a struct |
|
struct |
|
A pointer to a struct |
|
struct |
|
A pointer to a struct |
|
struct |
|
A pointer to a struct |
|
struct |
|
A pointer to a struct |
|
struct |
|
A pointer to a struct |
|
struct |
|
A pointer to a struct |
|
struct |
|
A pointer to a struct |
|
struct |
|
A pointer to a struct |
|
struct |
|
A pointer to a struct |
|
struct |
|
A pointer to a struct |
|
struct |
|
A pointer to a struct |
|
struct |
|
A pointer to a struct |
|
struct |
|
A pointer to a struct |
|
struct |
|
A pointer to a struct |
|
struct |
|
A pointer to a struct |
|
struct |
|
A pointer to a struct |
|
struct |
|
A pointer to a struct |
|
struct |
|
A pointer to a struct |
|
struct |
|
A pointer to a struct |
|
struct |
|
A pointer to a struct |
|
struct |
|
A pointer to a struct |
|
struct |
|
A pointer to a struct |
|
struct |
|
A pointer to a struct |
|
struct |
|
A pointer to a struct |
|
struct |
|
A pointer to a struct |
|
struct |
|
A pointer to a struct |
|
struct |
|
A pointer to a struct |
|
void * |
|
A pointer to a compound type which can be an N-dimensional array and/or a compound type (the control's type is >= |
|
} |
||
v4l2_ext_controls
|
union { |
(anonymous) |
|
|
__u32 |
|
Which value of the control to get/set/try. |
|
When using Whether a control supports querying the minimum and maximum values using For backwards compatibility you can also use a control class here (see ctrl-class). In that case all controls have to belong to that control class. This usage is deprecated, instead just use |
||
|
__u32 |
|
Deprecated name kept for backwards compatibility. Use |
|
} |
||
|
__u32 |
|
The number of controls in the controls array. May also be zero. |
|
__u32 |
|
Index of the failing control. Set by the driver in case of an error. |
|
If the error is associated with a particular control, then Before controls are read from/written to hardware a validation step takes place: this checks if all controls in the list are valid controls, if no attempt is made to write to a read-only control or read from a write-only control, and any other up-front checks that can be done without accessing the hardware. The exact validations done during this step are driver dependent since some checks might require hardware access for some devices, thus making it impossible to do those checks up-front. However, drivers should make a best-effort to do as many up-front checks as possible. This check is done to avoid leaving the hardware in an inconsistent state due to easy-to-avoid problems. But it leads to another problem: the application needs to know whether an error came from the validation step (meaning that the hardware was not touched) or from an error during the actual reading from/writing to hardware. The, in hindsight quite poor, solution for that is to set Since VIDIOC_TRY_EXT_CTRLS does not access hardware there is also no need to handle the validation step in this special way, so |
||
|
__s32 |
|
File descriptor of the request to be used by this operation. Only valid if |
|
__u32 |
|
Reserved for future extensions. Drivers and applications must set the array to zero. |
|
struct |
|
Pointer to an array of Ignored if |
|
|
0x980000 |
The class containing user controls. These controls are described in control. All controls that can be set using the VIDIOC_S_CTRL and VIDIOC_G_CTRL ioctl belong to this class. |
|
|
0x990000 |
The class containing stateful codec controls. These controls are described in Codec Control Reference. |
|
|
0x9a0000 |
The class containing camera controls. These controls are described in Camera Control Reference. |
|
|
0x9b0000 |
The class containing FM Transmitter (FM TX) controls. These controls are described in fm-tx-controls. |
|
|
0x9c0000 |
The class containing flash device controls. These controls are described in flash-controls. |
|
|
0x9d0000 |
The class containing JPEG compression controls. These controls are described in jpeg-controls. |
|
|
0x9e0000 |
The class containing image source controls. These controls are described in image-source-controls. |
|
|
0x9f0000 |
The class containing image processing controls. These controls are described in image-process-controls. |
|
|
0xa10000 |
The class containing FM Receiver (FM RX) controls. These controls are described in fm-rx-controls. |
|
|
0xa20000 |
The class containing RF tuner controls. These controls are described in rf-tuner-controls. |
|
|
0xa30000 |
The class containing motion or object detection controls. These controls are described in detect-controls. |
|
|
0xa40000 |
The class containing stateless codec controls. These controls are described in Stateless Codec Control Reference. |
|
|
0xa50000 |
The class containing colorimetry controls. These controls are described in colorimetry-controls. |
Return Value #
On success 0 is returned, on error -1 and the errno variable is set appropriately. The generic error codes are described at the Generic Error Codes chapter.
-
EINVAL
The struct
v4l2_ext_controlidis invalid, or the structv4l2_ext_controlswhichis invalid, or the structv4l2_ext_controlvaluewas inappropriate (e.g. the given menu index is not supported by the driver), or thewhichfield was set toV4L2_CTRL_WHICH_REQUEST_VALbut the givenrequest_fdwas invalid orV4L2_CTRL_WHICH_REQUEST_VALis not supported by the kernel. 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_controlvalueis 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, or (if the
whichfield was set toV4L2_CTRL_WHICH_REQUEST_VAL) the request was queued but not yet completed. -
ENOSPC
The space reserved for the control's payload is insufficient. The field
sizeis set to a value that is enough to store the payload and this error code is returned. -
EACCES
Attempt to try or set a read-only control, or to get a write-only control, or to get a control from a request that has not yet been completed.
Or the
whichfield was set toV4L2_CTRL_WHICH_REQUEST_VALbut the device does not support requests.Or if there is an attempt to set an inactive control and the driver is not capable of caching the new value until the control is active again.