参考地址:http://linuxtv.org/downloads/v4l-dvb-apis/vidioc-g-ctrl.html
Name
VIDIOC_G_CTRL, VIDIOC_S_CTRL — Get or set the value of a control
Synopsis
int ioctl( | int fd, |
int request, | |
struct v4l2_control*argp) ; |
Arguments
-
File descriptor returned by
open()
. -
VIDIOC_G_CTRL, VIDIOC_S_CTRL
-
fd
request
argp
Description
To get the current value of a control applications initialize theid
field of a structv4l2_control and call theVIDIOC_G_CTRL
ioctl with a pointer to this structure. To change the value of a control applications initialize theid
andvalue
fields of a structv4l2_control and call theVIDIOC_S_CTRL
ioctl.
要获取一个控制的值,程序需要先初始化控制id,然后调用命令VIDIOC_G_CTRL
。要改变一个控制的值,程序需要分别初始化结构体 v4l2_control 的id和value这两个域,再调用命令VIDIOC_S_CTRL
。
id 在include/linux/videodev2.h中定义
/* User-class control IDs defined by V4L2 */
#define V4L2_CID_MAX_CTRLS 1024
#define V4L2_CID_BASE (V4L2_CTRL_CLASS_USER | 0x900)
#define V4L2_CID_USER_BASE V4L2_CID_BASE
/* IDs reserved for driver specific controls */
#define V4L2_CID_PRIVATE_BASE 0x08000000
#define V4L2_CID_USER_CLASS (V4L2_CTRL_CLASS_USER | 1)
#define V4L2_CID_BRIGHTNESS (V4L2_CID_BASE+0)
#define V4L2_CID_CONTRAST (V4L2_CID_BASE+1)
#define V4L2_CID_SATURATION (V4L2_CID_BASE+2)
#define V4L2_CID_HUE (V4L2_CID_BASE+3)
#define V4L2_CID_AUDIO_VOLUME (V4L2_CID_BASE+5)
.................................
.................................
When the id
is invalid drivers return anEINVAL error code. When thevalue
is out of bounds drivers can choose to take the closest valid value or returnanERANGE error code, whatever seems more appropriate. However,VIDIOC_S_CTRL
is a write-only ioctl, it does not return the actual new value. If thevalue
is inappropriate for the control (e.g. if it refers to an unsupportedmenu index of a menu control), thenEINVAL error code is returned as well.
These ioctls work only with user controls. For other control classes the VIDIOC_G_EXT_CTRLS
, VIDIOC_S_EXT_CTRLS
orVIDIOC_TRY_EXT_CTRLS
must be used.
Table A.52. struct v4l2_control
__u32 | id | Identifies the control, set by the application. |
__s32 | value | New value or current value. |
Return Value
On success 0 is returned, on error-1 and theerrno
variable is set appropriately. The generic error codes are described at theGeneric Error Codes chapter.
-
EINVAL
-
The struct v4l2_control
id
is invalid or thevalue
is inappropriate for the given control (i.e. if a menu item is selected that is not supported by the driver according toVIDIOC_QUERYMENU
).
ERANGE
-
The struct v4l2_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.
EACCES
-
Attempt to set a read-only control or to get a write-only control.