vidioc-g-ext-ctrls.xml 17 KB

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