V4L2命令之 User Controls

来源:互联网 发布:商标域名查询 编辑:程序博客网 时间:2024/05/22 03:40

http://linuxtv.org/downloads/v4l-dvb-apis/control.html


User Controls

Devices typically have a number of user-settable controls such asbrightness, saturation and so on, which would be presented to the user on a graphical user interface. But, different devices will have different controls available, and further more, the range of possible values, and the default value will vary from device to device. The control ioctls provide the information and a mechanism to create a nice user interface for these controls that will work correctly with any device.

All controls are accessed using an ID value. V4L2 defines several IDs for specific purposes. Drivers can also implement their own custom controls usingV4L2_CID_PRIVATE_BASEand higher values. The pre-defined control IDs have the prefixV4L2_CID_ , and are listed inTable 1.1, “Control IDs”. The ID is used when querying the attributes of a control, and when getting or setting the current value.

Generally applications should present controls to the user without assumptions假想 about their purpose. Each control comes with a name string the user is supposed to understand. When the purpose is non-intuitive不直观 the driver writer should provide a user manual, a user interface plug-in插件 or a driver specific panel application. Predefined IDs were introduced to change a few controls programmatically方式, for example to mute静音 a device during a channel switch.

Drivers may enumerate different controls after switching the current video input or output, tuner or modulator, or audio inputor output. Different in the sense of other bounds, another default and current value, step size or other menu items. A control with a certain custom ID can also change name and type.[9] Control values are stored globally, they do not change when switching except to stay within the reported bounds. They also do not change e. g. when the device is opened or closed, when the tuner radio frequency is changed or generally never without application request. Since V4L2 specifies no event mechanism, panel applications intended to cooperate with other panel applications (be they built into a larger application, as a TV viewer) may need to regularly poll control values to update their user interface.[10]

All controls use machine endianness.

Table 1.1. Control IDs

IDTypeDescriptionV4L2_CID_BASE
First predefined ID, equal toV4L2_CID_BRIGHTNESS.V4L2_CID_USER_BASE
Synonym ofV4L2_CID_BASE.V4L2_CID_BRIGHTNESSintegerPicture brightness, or more precisely, the black level.V4L2_CID_CONTRASTintegerPicture contrast对比度 or luma亮度 gain.V4L2_CID_SATURATIONintegerPicture color saturation饱和度 or chroma透明度 gain.V4L2_CID_HUEintegerHue色调 or color balance.V4L2_CID_AUDIO_VOLUMEintegerOverall audio volume. Note some drivers also provide an OSS or ALSA mixer interface.V4L2_CID_AUDIO_BALANCEintegerAudio stereo立体 balance. Minimum corresponds to all the way left, maximum to right.V4L2_CID_AUDIO_BASSintegerAudio bass低音 adjustment.V4L2_CID_AUDIO_TREBLEintegerAudio treble高音 adjustment.V4L2_CID_AUDIO_MUTEbooleanMute静音 audio, i. e. set the volume to zero, however without affectingV4L2_CID_AUDIO_VOLUME. LikeALSA drivers, V4L2 drivers must mute at load time to avoid excessive过多的 noise. Actually the entire device should be reset to a low power consumption state.V4L2_CID_AUDIO_LOUDNESSbooleanLoudness mode (bass boost).V4L2_CID_BLACK_LEVELintegerAnother name for brightness (not a synonym of V4L2_CID_BRIGHTNESS). This control is deprecated弃用 and should not be used in new drivers and applications.V4L2_CID_AUTO_WHITE_BALANCEbooleanAutomatic white balance (cameras).V4L2_CID_DO_WHITE_BALANCEbuttonThis is an action control. When set (the value is ignored), the device will do a white balance and then hold the current setting. Contrast this with the boolean V4L2_CID_AUTO_WHITE_BALANCE, which, when activated, keeps adjusting the white balance.V4L2_CID_RED_BALANCEintegerRed chroma色度 balance.V4L2_CID_BLUE_BALANCEintegerBlue chroma balance.V4L2_CID_GAMMAintegerGamma伽马 adjust.V4L2_CID_WHITENESSintegerWhiteness for grey-scale devices. This is a synonym同名 forV4L2_CID_GAMMA. This control is deprecated and should not be used in new drivers and applications.V4L2_CID_EXPOSUREintegerExposure曝光 (cameras). [Unit?]V4L2_CID_AUTOGAINbooleanAutomatic gain/exposure control.V4L2_CID_GAINintegerGain control.V4L2_CID_HFLIPbooleanMirror the picture horizontally.V4L2_CID_VFLIPbooleanMirror the picture vertically.V4L2_CID_POWER_LINE_FREQUENCYenumEnables a power line frequency filter to avoid flicker闪光. Possible values forenum v4l2_power_line_frequency are:V4L2_CID_POWER_LINE_FREQUENCY_DISABLED (0),V4L2_CID_POWER_LINE_FREQUENCY_50HZ (1),V4L2_CID_POWER_LINE_FREQUENCY_60HZ (2) andV4L2_CID_POWER_LINE_FREQUENCY_AUTO (3).V4L2_CID_HUE_AUTObooleanEnables automatic hue色彩 control by the device. The effect of settingV4L2_CID_HUE while automatic hue control is enabled is undefined, drivers should ignore such request.V4L2_CID_WHITE_BALANCE_TEMPERATUREintegerThis control specifies the white balance settings as a color temperature in Kelvin开尔文. A driver should have a minimum of 2800 (incandescent) to 6500 (daylight). For more information about color temperature see Wikipedia.V4L2_CID_SHARPNESSintegerAdjusts the sharpness锐度 filters in a camera. The minimum value disables the filters, higher values give a sharper picture.V4L2_CID_BACKLIGHT_COMPENSATIONintegerAdjusts the backlight compensation补偿 in a camera. The minimum value disables backlight compensation.V4L2_CID_CHROMA_AGCbooleanChroma色度 automatic gain control.V4L2_CID_CHROMA_GAINintegerAdjusts the Chroma gain control (for use when chroma AGC is disabled).V4L2_CID_COLOR_KILLERbooleanEnable the color killer (i. e. force a black & white image in case of a weak video signal).V4L2_CID_COLORFXenumSelects a color effect. The following values are defined:

V4L2_COLORFX_NONE Color effect is disabled.V4L2_COLORFX_ANTIQUE An aging (old photo) effect.V4L2_COLORFX_ART_FREEZE Frost color effect.V4L2_COLORFX_AQUA Water color, cool tone.V4L2_COLORFX_BW Black and white.V4L2_COLORFX_EMBOSS Emboss, the highlights and shadows replace light/dark boundaries and low contrast areas are set to a gray background.V4L2_COLORFX_GRASS_GREEN Grass green.V4L2_COLORFX_NEGATIVE Negative.V4L2_COLORFX_SEPIA Sepia tone.V4L2_COLORFX_SKETCH Sketch.V4L2_COLORFX_SKIN_WHITEN Skin whiten.V4L2_COLORFX_SKY_BLUE Sky blue.V4L2_COLORFX_SOLARIZATION Solarization, the image is partially reversed in tone, only color values above or below a certain threshold are inverted.V4L2_COLORFX_SILHOUETTE Silhouette (outline).V4L2_COLORFX_VIVID Vivid colors.V4L2_COLORFX_SET_CBCR The Cb and Cr chroma components are replaced by fixed coefficients determined byV4L2_CID_COLORFX_CBCR control.V4L2_CID_COLORFX_CBCRintegerDetermines the Cb and Cr coefficients系数 forV4L2_COLORFX_SET_CBCR color effect. Bits [7:0] of the supplied 32 bit value are interpreted as Cr component, bits [15:8] as Cb component and bits [31:16] must be zero.V4L2_CID_AUTOBRIGHTNESSbooleanEnable Automatic Brightness.V4L2_CID_ROTATEintegerRotates旋转 the image by specified angle. Common angles are 90, 270 and 180. Rotating the image to 90 and 270 will reverse the height and width of the display window. It is necessary to set the new height and width of the picture using the VIDIOC_S_FMT ioctl according to the rotation angle selected.V4L2_CID_BG_COLORintegerSets the background color on the current output device. Background color needs to be specified in the RGB24 format. The supplied 32 bit value is interpreted as bits 0-7 Red color information, bits 8-15 Green color information, bits 16-23 Blue color information and bits 24-31 must be zero.V4L2_CID_ILLUMINATORS_1V4L2_CID_ILLUMINATORS_2booleanSwitch on or off the illuminator 1 or 2 of the device(usually a microscope).V4L2_CID_MIN_BUFFERS_FOR_CAPTUREintegerThis is a read-only control that can be read by the application and used as a hint提示 to determine the number of CAPTURE buffers to pass to REQBUFS.The value is the minimum number of CAPTURE buffers that is necessary for hardware to work.V4L2_CID_MIN_BUFFERS_FOR_OUTPUTintegerThis is a read-only control that can be read by the application and used as a hint to determine the number of OUTPUT buffers to pass to REQBUFS.The value is the minimum number of OUTPUT buffers that is necessary for hardware to work.V4L2_CID_ALPHA_COMPONENTintegerSets the alpha color component on the capture device or on the capture buffer queue of a mem-to-mem device. When a mem-to-mem device produces frame format that includes an alpha component (e.g. packed RGB image formats) and the alpha value is not defined by the mem-to-mem input data this control lets you select the alpha component value of all pixels. It is applicable to any pixel format that contains an alpha component.V4L2_CID_LASTP1
End of the predefined control IDs (currentlyV4L2_CID_ALPHA_COMPONENT + 1).V4L2_CID_PRIVATE_BASE
ID of the first custom (driver specific) control.Applications depending on particular custom controls should check thedriver name and version, seethe section called “Querying Capabilities”.

Applications can enumerate the available controls with theVIDIOC_QUERYCTRL and VIDIOC_QUERYMENU ioctls, get and set a control value with theVIDIOC_G_CTRL andVIDIOC_S_CTRL ioctls.Drivers must implementVIDIOC_QUERYCTRL,VIDIOC_G_CTRL and VIDIOC_S_CTRL when the device has one or more controls,VIDIOC_QUERYMENU when it has one or more menu type controls.

Example 1.8. Enumerating all controls

struct v4l2_queryctrl queryctrl;struct v4l2_querymenu querymenu;static voidenumerate_menu (void){printf ("  Menu items:\n");memset (&querymenu, 0, sizeof (querymenu));querymenu.id = queryctrl.id;for (querymenu.index = queryctrl.minimum;     querymenu.index <= queryctrl.maximum;      querymenu.index++) {if (0 == ioctl (fd, VIDIOC_QUERYMENU, &querymenu)) {printf ("  %s\n", querymenu.name);}}}memset (&queryctrl, 0, sizeof (queryctrl));for (queryctrl.id = V4L2_CID_BASE;     queryctrl.id < V4L2_CID_LASTP1;     queryctrl.id++) {if (0 == ioctl (fd, VIDIOC_QUERYCTRL, &queryctrl)) {if (queryctrl.flags & V4L2_CTRL_FLAG_DISABLED) //该命令已被禁止,无效命令continue;printf ("Control %s\n", queryctrl.name);if (queryctrl.type == V4L2_CTRL_TYPE_MENU) //如果命令式菜单型的则调用枚举菜单的子函数enumerate_menu ();} else {if (errno == EINVAL)continue;perror ("VIDIOC_QUERYCTRL");exit (EXIT_FAILURE);}}for (queryctrl.id = V4L2_CID_PRIVATE_BASE;;     queryctrl.id++) {if (0 == ioctl (fd, VIDIOC_QUERYCTRL, &queryctrl)) {if (queryctrl.flags & V4L2_CTRL_FLAG_DISABLED)continue;printf ("Control %s\n", queryctrl.name);if (queryctrl.type == V4L2_CTRL_TYPE_MENU)enumerate_menu ();} else {if (errno == EINVAL)break;perror ("VIDIOC_QUERYCTRL");exit (EXIT_FAILURE);}}

Example 1.9. Changing controls

struct v4l2_queryctrl queryctrl;struct v4l2_control control;memset (&queryctrl, 0, sizeof (queryctrl));queryctrl.id = V4L2_CID_BRIGHTNESS;if (-1 == ioctl (fd, VIDIOC_QUERYCTRL, &queryctrl)) {if (errno != EINVAL) {perror ("VIDIOC_QUERYCTRL");exit (EXIT_FAILURE);} else {printf ("V4L2_CID_BRIGHTNESS is not supported\n");}} else if (queryctrl.flags & V4L2_CTRL_FLAG_DISABLED) {printf ("V4L2_CID_BRIGHTNESS is not supported\n");} else {memset (&control, 0, sizeof (control));control.id = V4L2_CID_BRIGHTNESS;control.value = queryctrl.default_value;if (-1 == ioctl (fd, VIDIOC_S_CTRL, &control)) {perror ("VIDIOC_S_CTRL");exit (EXIT_FAILURE);}}memset (&control, 0, sizeof (control));control.id = V4L2_CID_CONTRAST;if (0 == ioctl (fd, VIDIOC_G_CTRL, &control)) {control.value += 1;/* The driver may clamp the value or return ERANGE, ignored here */if (-1 == ioctl (fd, VIDIOC_S_CTRL, &control)    && errno != ERANGE) {perror ("VIDIOC_S_CTRL");exit (EXIT_FAILURE);}/* Ignore if V4L2_CID_CONTRAST is unsupported */} else if (errno != EINVAL) {perror ("VIDIOC_G_CTRL");exit (EXIT_FAILURE);}control.id = V4L2_CID_AUDIO_MUTE;control.value = TRUE; /* silence *//* Errors ignored */ioctl (fd, VIDIOC_S_CTRL, &control);



[9]It will be more convenient for applications if driversmake use of the V4L2_CTRL_FLAG_DISABLED flag, butthat was never required.

[10]Applications could call an ioctl to request events.After another process calledVIDIOC_S_CTRL or another ioctl changingshared properties theselect() function would indicatereadability until any ioctl (querying the properties) iscalled.

原创粉丝点击