Based on kernel version 4.7.2. Page generated on 2016-08-22 22:45 EST.
1 <refentry id="vidioc-g-ext-ctrls"> 2 <refmeta> 3 <refentrytitle>ioctl VIDIOC_G_EXT_CTRLS, VIDIOC_S_EXT_CTRLS, 4 VIDIOC_TRY_EXT_CTRLS</refentrytitle> 5 &manvol; 6 </refmeta> 7 8 <refnamediv> 9 <refname>VIDIOC_G_EXT_CTRLS</refname> 10 <refname>VIDIOC_S_EXT_CTRLS</refname> 11 <refname>VIDIOC_TRY_EXT_CTRLS</refname> 12 <refpurpose>Get or set the value of several controls, try control 13 values</refpurpose> 14 </refnamediv> 15 16 <refsynopsisdiv> 17 <funcsynopsis> 18 <funcprototype> 19 <funcdef>int <function>ioctl</function></funcdef> 20 <paramdef>int <parameter>fd</parameter></paramdef> 21 <paramdef>int <parameter>request</parameter></paramdef> 22 <paramdef>struct v4l2_ext_controls 23 *<parameter>argp</parameter></paramdef> 24 </funcprototype> 25 </funcsynopsis> 26 </refsynopsisdiv> 27 28 <refsect1> 29 <title>Arguments</title> 30 31 <variablelist> 32 <varlistentry> 33 <term><parameter>fd</parameter></term> 34 <listitem> 35 <para>&fd;</para> 36 </listitem> 37 </varlistentry> 38 <varlistentry> 39 <term><parameter>request</parameter></term> 40 <listitem> 41 <para>VIDIOC_G_EXT_CTRLS, VIDIOC_S_EXT_CTRLS, 42 VIDIOC_TRY_EXT_CTRLS</para> 43 </listitem> 44 </varlistentry> 45 <varlistentry> 46 <term><parameter>argp</parameter></term> 47 <listitem> 48 <para></para> 49 </listitem> 50 </varlistentry> 51 </variablelist> 52 </refsect1> 53 54 <refsect1> 55 <title>Description</title> 56 57 <para>These ioctls allow the caller to get or set multiple 58 controls atomically. Control IDs are grouped into control classes (see 59 <xref linkend="ctrl-class" />) and all controls in the control array 60 must belong to the same control class.</para> 61 62 <para>Applications must always fill in the 63 <structfield>count</structfield>, 64 <structfield>which</structfield>, 65 <structfield>controls</structfield> and 66 <structfield>reserved</structfield> fields of &v4l2-ext-controls;, and 67 initialize the &v4l2-ext-control; array pointed to by the 68 <structfield>controls</structfield> fields.</para> 69 70 <para>To get the current value of a set of controls applications 71 initialize the <structfield>id</structfield>, 72 <structfield>size</structfield> and <structfield>reserved2</structfield> fields 73 of each &v4l2-ext-control; and call the 74 <constant>VIDIOC_G_EXT_CTRLS</constant> ioctl. String controls controls 75 must also set the <structfield>string</structfield> field. Controls 76 of compound types (<constant>V4L2_CTRL_FLAG_HAS_PAYLOAD</constant> is set) 77 must set the <structfield>ptr</structfield> field.</para> 78 79 <para>If the <structfield>size</structfield> is too small to 80 receive the control result (only relevant for pointer-type controls 81 like strings), then the driver will set <structfield>size</structfield> 82 to a valid value and return an &ENOSPC;. You should re-allocate the 83 memory to this new size and try again. For the string type it is possible that 84 the same issue occurs again if the string has grown in the meantime. It is 85 recommended to call &VIDIOC-QUERYCTRL; first and use 86 <structfield>maximum</structfield>+1 as the new <structfield>size</structfield> 87 value. It is guaranteed that that is sufficient memory. 88 </para> 89 90 <para>N-dimensional arrays are set and retrieved row-by-row. You cannot set a partial 91 array, all elements have to be set or retrieved. The total size is calculated 92 as <structfield>elems</structfield> * <structfield>elem_size</structfield>. 93 These values can be obtained by calling &VIDIOC-QUERY-EXT-CTRL;.</para> 94 95 <para>To change the value of a set of controls applications 96 initialize the <structfield>id</structfield>, <structfield>size</structfield>, 97 <structfield>reserved2</structfield> and 98 <structfield>value/value64/string/ptr</structfield> fields of each &v4l2-ext-control; and 99 call the <constant>VIDIOC_S_EXT_CTRLS</constant> ioctl. The controls 100 will only be set if <emphasis>all</emphasis> control values are 101 valid.</para> 102 103 <para>To check if a set of controls have correct values applications 104 initialize the <structfield>id</structfield>, <structfield>size</structfield>, 105 <structfield>reserved2</structfield> and 106 <structfield>value/value64/string/ptr</structfield> fields of each &v4l2-ext-control; and 107 call the <constant>VIDIOC_TRY_EXT_CTRLS</constant> ioctl. It is up to 108 the driver whether wrong values are automatically adjusted to a valid 109 value or if an error is returned.</para> 110 111 <para>When the <structfield>id</structfield> or 112 <structfield>which</structfield> is invalid drivers return an 113 &EINVAL;. When the value is out of bounds drivers can choose to take 114 the closest valid value or return an &ERANGE;, whatever seems more 115 appropriate. In the first case the new value is set in 116 &v4l2-ext-control;. If the new control value is inappropriate (e.g. the 117 given menu index is not supported by the menu control), then this will 118 also result in an &EINVAL; error.</para> 119 120 <para>The driver will only set/get these controls if all control 121 values are correct. This prevents the situation where only some of the 122 controls were set/get. Only low-level errors (⪚ a failed i2c 123 command) can still cause this situation.</para> 124 125 <table pgwide="1" frame="none" id="v4l2-ext-control"> 126 <title>struct <structname>v4l2_ext_control</structname></title> 127 <tgroup cols="4"> 128 &cs-ustr; 129 <tbody valign="top"> 130 <row> 131 <entry>__u32</entry> 132 <entry><structfield>id</structfield></entry> 133 <entry></entry> 134 <entry>Identifies the control, set by the 135 application.</entry> 136 </row> 137 <row> 138 <entry>__u32</entry> 139 <entry><structfield>size</structfield></entry> 140 <entry></entry> 141 <entry>The total size in bytes of the payload of this 142 control. This is normally 0, but for pointer controls this should be 143 set to the size of the memory containing the payload, or that will 144 receive the payload. If <constant>VIDIOC_G_EXT_CTRLS</constant> finds 145 that this value is less than is required to store 146 the payload result, then it is set to a value large enough to store the 147 payload result and ENOSPC is returned. Note that for string controls 148 this <structfield>size</structfield> field should not be confused with the length of the string. 149 This field refers to the size of the memory that contains the string. 150 The actual <emphasis>length</emphasis> of the string may well be much smaller. 151 </entry> 152 </row> 153 <row> 154 <entry>__u32</entry> 155 <entry><structfield>reserved2</structfield>[1]</entry> 156 <entry></entry> 157 <entry>Reserved for future extensions. Drivers and 158 applications must set the array to zero.</entry> 159 </row> 160 <row> 161 <entry>union</entry> 162 <entry>(anonymous)</entry> 163 </row> 164 <row> 165 <entry></entry> 166 <entry>__s32</entry> 167 <entry><structfield>value</structfield></entry> 168 <entry>New value or current value. Valid if this control is not of 169 type <constant>V4L2_CTRL_TYPE_INTEGER64</constant> and 170 <constant>V4L2_CTRL_FLAG_HAS_PAYLOAD</constant> is not set.</entry> 171 </row> 172 <row> 173 <entry></entry> 174 <entry>__s64</entry> 175 <entry><structfield>value64</structfield></entry> 176 <entry>New value or current value. Valid if this control is of 177 type <constant>V4L2_CTRL_TYPE_INTEGER64</constant> and 178 <constant>V4L2_CTRL_FLAG_HAS_PAYLOAD</constant> is not set.</entry> 179 </row> 180 <row> 181 <entry></entry> 182 <entry>char *</entry> 183 <entry><structfield>string</structfield></entry> 184 <entry>A pointer to a string. Valid if this control is of 185 type <constant>V4L2_CTRL_TYPE_STRING</constant>.</entry> 186 </row> 187 <row> 188 <entry></entry> 189 <entry>__u8 *</entry> 190 <entry><structfield>p_u8</structfield></entry> 191 <entry>A pointer to a matrix control of unsigned 8-bit values. 192 Valid if this control is of type <constant>V4L2_CTRL_TYPE_U8</constant>.</entry> 193 </row> 194 <row> 195 <entry></entry> 196 <entry>__u16 *</entry> 197 <entry><structfield>p_u16</structfield></entry> 198 <entry>A pointer to a matrix control of unsigned 16-bit values. 199 Valid if this control is of type <constant>V4L2_CTRL_TYPE_U16</constant>.</entry> 200 </row> 201 <row> 202 <entry></entry> 203 <entry>__u32 *</entry> 204 <entry><structfield>p_u32</structfield></entry> 205 <entry>A pointer to a matrix control of unsigned 32-bit values. 206 Valid if this control is of type <constant>V4L2_CTRL_TYPE_U32</constant>.</entry> 207 </row> 208 <row> 209 <entry></entry> 210 <entry>void *</entry> 211 <entry><structfield>ptr</structfield></entry> 212 <entry>A pointer to a compound type which can be an N-dimensional array and/or a 213 compound type (the control's type is >= <constant>V4L2_CTRL_COMPOUND_TYPES</constant>). 214 Valid if <constant>V4L2_CTRL_FLAG_HAS_PAYLOAD</constant> is set for this control. 215 </entry> 216 </row> 217 </tbody> 218 </tgroup> 219 </table> 220 221 <table pgwide="1" frame="none" id="v4l2-ext-controls"> 222 <title>struct <structname>v4l2_ext_controls</structname></title> 223 <tgroup cols="3"> 224 &cs-str; 225 <tbody valign="top"> 226 <row> 227 <entry>union</entry> 228 <entry>(anonymous)</entry> 229 </row> 230 <row> 231 <entry></entry> 232 <entry>__u32</entry> 233 <entry><structfield>ctrl_class</structfield></entry> 234 <entry>The control class to which all controls belong, see 235 <xref linkend="ctrl-class" />. Drivers that use a kernel framework for handling 236 controls will also accept a value of 0 here, meaning that the controls can 237 belong to any control class. Whether drivers support this can be tested by setting 238 <structfield>ctrl_class</structfield> to 0 and calling <constant>VIDIOC_TRY_EXT_CTRLS</constant> 239 with a <structfield>count</structfield> of 0. If that succeeds, then the driver 240 supports this feature.</entry> 241 </row> 242 <row> 243 <entry></entry> 244 <entry>__u32</entry> 245 <entry><structfield>which</structfield></entry> 246 <entry><para>Which value of the control to get/set/try. <constant>V4L2_CTRL_WHICH_CUR_VAL</constant> 247 will return the current value of the control and <constant>V4L2_CTRL_WHICH_DEF_VAL</constant> will 248 return the default value of the control. Please note that you can only get the default value of the 249 control, you cannot set or try it.</para> 250 <para>For backwards compatibility you can also use a control class here (see 251 <xref linkend="ctrl-class" />). In that case all controls have to belong to that 252 control class. This usage is deprecated, instead just use <constant>V4L2_CTRL_WHICH_CUR_VAL</constant>. 253 There are some very old drivers that do not yet support <constant>V4L2_CTRL_WHICH_CUR_VAL</constant> 254 and that require a control class here. You can test for such drivers by setting ctrl_class to 255 <constant>V4L2_CTRL_WHICH_CUR_VAL</constant> and calling VIDIOC_TRY_EXT_CTRLS with a count of 0. 256 If that fails, then the driver does not support <constant>V4L2_CTRL_WHICH_CUR_VAL</constant>.</para> 257 </entry> 258 </row> 259 <row> 260 <entry>__u32</entry> 261 <entry><structfield>count</structfield></entry> 262 <entry>The number of controls in the controls array. May 263 also be zero.</entry> 264 </row> 265 <row> 266 <entry>__u32</entry> 267 <entry><structfield>error_idx</structfield></entry> 268 <entry><para>Set by the driver in case of an error. If the error is 269 associated with a particular control, then <structfield>error_idx</structfield> 270 is set to the index of that control. If the error is not related to a specific 271 control, or the validation step failed (see below), then 272 <structfield>error_idx</structfield> is set to <structfield>count</structfield>. 273 The value is undefined if the ioctl returned 0 (success).</para> 274 275 <para>Before controls are read from/written to hardware a validation step 276 takes place: this checks if all controls in the list are valid controls, 277 if no attempt is made to write to a read-only control or read from a write-only 278 control, and any other up-front checks that can be done without accessing the 279 hardware. The exact validations done during this step are driver dependent 280 since some checks might require hardware access for some devices, thus making 281 it impossible to do those checks up-front. However, drivers should make a 282 best-effort to do as many up-front checks as possible.</para> 283 284 <para>This check is done to avoid leaving the hardware in an inconsistent state due 285 to easy-to-avoid problems. But it leads to another problem: the application needs to 286 know whether an error came from the validation step (meaning that the hardware 287 was not touched) or from an error during the actual reading from/writing to hardware.</para> 288 289 <para>The, in hindsight quite poor, solution for that is to set <structfield>error_idx</structfield> 290 to <structfield>count</structfield> if the validation failed. This has the 291 unfortunate side-effect that it is not possible to see which control failed the 292 validation. If the validation was successful and the error happened while 293 accessing the hardware, then <structfield>error_idx</structfield> is less than 294 <structfield>count</structfield> and only the controls up to 295 <structfield>error_idx-1</structfield> were read or written correctly, and the 296 state of the remaining controls is undefined.</para> 297 298 <para>Since <constant>VIDIOC_TRY_EXT_CTRLS</constant> does not access hardware 299 there is also no need to handle the validation step in this special way, 300 so <structfield>error_idx</structfield> will just be set to the control that 301 failed the validation step instead of to <structfield>count</structfield>. 302 This means that if <constant>VIDIOC_S_EXT_CTRLS</constant> fails with 303 <structfield>error_idx</structfield> set to <structfield>count</structfield>, 304 then you can call <constant>VIDIOC_TRY_EXT_CTRLS</constant> to try to discover 305 the actual control that failed the validation step. Unfortunately, there 306 is no <constant>TRY</constant> equivalent for <constant>VIDIOC_G_EXT_CTRLS</constant>. 307 </para></entry> 308 </row> 309 <row> 310 <entry>__u32</entry> 311 <entry><structfield>reserved</structfield>[2]</entry> 312 <entry>Reserved for future extensions. Drivers and 313 applications must set the array to zero.</entry> 314 </row> 315 <row> 316 <entry>&v4l2-ext-control; *</entry> 317 <entry><structfield>controls</structfield></entry> 318 <entry>Pointer to an array of 319 <structfield>count</structfield> v4l2_ext_control structures. Ignored 320 if <structfield>count</structfield> equals zero.</entry> 321 </row> 322 </tbody> 323 </tgroup> 324 </table> 325 326 <table pgwide="1" frame="none" id="ctrl-class"> 327 <title>Control classes</title> 328 <tgroup cols="3"> 329 &cs-def; 330 <tbody valign="top"> 331 <row> 332 <entry><constant>V4L2_CTRL_CLASS_USER</constant></entry> 333 <entry>0x980000</entry> 334 <entry>The class containing user controls. These controls 335 are described in <xref linkend="control" />. All controls that can be set 336 using the &VIDIOC-S-CTRL; and &VIDIOC-G-CTRL; ioctl belong to this 337 class.</entry> 338 </row> 339 <row> 340 <entry><constant>V4L2_CTRL_CLASS_MPEG</constant></entry> 341 <entry>0x990000</entry> 342 <entry>The class containing MPEG compression controls. 343 These controls are described in <xref 344 linkend="mpeg-controls" />.</entry> 345 </row> 346 <row> 347 <entry><constant>V4L2_CTRL_CLASS_CAMERA</constant></entry> 348 <entry>0x9a0000</entry> 349 <entry>The class containing camera controls. 350 These controls are described in <xref 351 linkend="camera-controls" />.</entry> 352 </row> 353 <row> 354 <entry><constant>V4L2_CTRL_CLASS_FM_TX</constant></entry> 355 <entry>0x9b0000</entry> 356 <entry>The class containing FM Transmitter (FM TX) controls. 357 These controls are described in <xref 358 linkend="fm-tx-controls" />.</entry> 359 </row> 360 <row> 361 <entry><constant>V4L2_CTRL_CLASS_FLASH</constant></entry> 362 <entry>0x9c0000</entry> 363 <entry>The class containing flash device controls. 364 These controls are described in <xref 365 linkend="flash-controls" />.</entry> 366 </row> 367 <row> 368 <entry><constant>V4L2_CTRL_CLASS_JPEG</constant></entry> 369 <entry>0x9d0000</entry> 370 <entry>The class containing JPEG compression controls. 371 These controls are described in <xref 372 linkend="jpeg-controls" />.</entry> 373 </row> 374 <row> 375 <entry><constant>V4L2_CTRL_CLASS_IMAGE_SOURCE</constant></entry> 376 <entry>0x9e0000</entry> <entry>The class containing image 377 source controls. These controls are described in <xref 378 linkend="image-source-controls" />.</entry> 379 </row> 380 <row> 381 <entry><constant>V4L2_CTRL_CLASS_IMAGE_PROC</constant></entry> 382 <entry>0x9f0000</entry> <entry>The class containing image 383 processing controls. These controls are described in <xref 384 linkend="image-process-controls" />.</entry> 385 </row> 386 387 <row> 388 <entry><constant>V4L2_CTRL_CLASS_FM_RX</constant></entry> 389 <entry>0xa10000</entry> 390 <entry>The class containing FM Receiver (FM RX) controls. 391 These controls are described in <xref 392 linkend="fm-rx-controls" />.</entry> 393 </row> 394 <row> 395 <entry><constant>V4L2_CTRL_CLASS_RF_TUNER</constant></entry> 396 <entry>0xa20000</entry> 397 <entry>The class containing RF tuner controls. 398 These controls are described in <xref linkend="rf-tuner-controls" />.</entry> 399 </row> 400 </tbody> 401 </tgroup> 402 </table> 403 404 </refsect1> 405 406 <refsect1> 407 &return-value; 408 409 <variablelist> 410 <varlistentry> 411 <term><errorcode>EINVAL</errorcode></term> 412 <listitem> 413 <para>The &v4l2-ext-control; <structfield>id</structfield> 414 is invalid, the &v4l2-ext-controls; 415 <structfield>which</structfield> is invalid, or the &v4l2-ext-control; 416 <structfield>value</structfield> was inappropriate (e.g. the given menu 417 index is not supported by the driver). This error code is 418 also returned by the <constant>VIDIOC_S_EXT_CTRLS</constant> and 419 <constant>VIDIOC_TRY_EXT_CTRLS</constant> ioctls if two or more 420 control values are in conflict.</para> 421 </listitem> 422 </varlistentry> 423 <varlistentry> 424 <term><errorcode>ERANGE</errorcode></term> 425 <listitem> 426 <para>The &v4l2-ext-control; <structfield>value</structfield> 427 is out of bounds.</para> 428 </listitem> 429 </varlistentry> 430 <varlistentry> 431 <term><errorcode>EBUSY</errorcode></term> 432 <listitem> 433 <para>The control is temporarily not changeable, possibly 434 because another applications took over control of the device function 435 this control belongs to.</para> 436 </listitem> 437 </varlistentry> 438 <varlistentry> 439 <term><errorcode>ENOSPC</errorcode></term> 440 <listitem> 441 <para>The space reserved for the control's payload is insufficient. 442 The field <structfield>size</structfield> is set to a value that is enough 443 to store the payload and this error code is returned.</para> 444 </listitem> 445 </varlistentry> 446 <varlistentry> 447 <term><errorcode>EACCES</errorcode></term> 448 <listitem> 449 <para>Attempt to try or set a read-only control or to get a 450 write-only control.</para> 451 </listitem> 452 </varlistentry> 453 </variablelist> 454 </refsect1> 455 </refentry>