vidioc-g-ext-ctrls.xml 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427
  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>void *</entry>
  189. <entry><structfield>ptr</structfield></entry>
  190. <entry>A pointer to a compound type which can be an N-dimensional array and/or a
  191. compound type (the control's type is >= <constant>V4L2_CTRL_COMPOUND_TYPES</constant>).
  192. Valid if <constant>V4L2_CTRL_FLAG_HAS_PAYLOAD</constant> is set for this control.
  193. </entry>
  194. </row>
  195. </tbody>
  196. </tgroup>
  197. </table>
  198. <table pgwide="1" frame="none" id="v4l2-ext-controls">
  199. <title>struct <structname>v4l2_ext_controls</structname></title>
  200. <tgroup cols="3">
  201. &cs-str;
  202. <tbody valign="top">
  203. <row>
  204. <entry>__u32</entry>
  205. <entry><structfield>ctrl_class</structfield></entry>
  206. <entry>The control class to which all controls belong, see
  207. <xref linkend="ctrl-class" />. Drivers that use a kernel framework for handling
  208. controls will also accept a value of 0 here, meaning that the controls can
  209. belong to any control class. Whether drivers support this can be tested by setting
  210. <structfield>ctrl_class</structfield> to 0 and calling <constant>VIDIOC_TRY_EXT_CTRLS</constant>
  211. with a <structfield>count</structfield> of 0. If that succeeds, then the driver
  212. supports this feature.</entry>
  213. </row>
  214. <row>
  215. <entry>__u32</entry>
  216. <entry><structfield>count</structfield></entry>
  217. <entry>The number of controls in the controls array. May
  218. also be zero.</entry>
  219. </row>
  220. <row>
  221. <entry>__u32</entry>
  222. <entry><structfield>error_idx</structfield></entry>
  223. <entry><para>Set by the driver in case of an error. If the error is
  224. associated with a particular control, then <structfield>error_idx</structfield>
  225. is set to the index of that control. If the error is not related to a specific
  226. control, or the validation step failed (see below), then
  227. <structfield>error_idx</structfield> is set to <structfield>count</structfield>.
  228. The value is undefined if the ioctl returned 0 (success).</para>
  229. <para>Before controls are read from/written to hardware a validation step
  230. takes place: this checks if all controls in the list are valid controls,
  231. if no attempt is made to write to a read-only control or read from a write-only
  232. control, and any other up-front checks that can be done without accessing the
  233. hardware. The exact validations done during this step are driver dependent
  234. since some checks might require hardware access for some devices, thus making
  235. it impossible to do those checks up-front. However, drivers should make a
  236. best-effort to do as many up-front checks as possible.</para>
  237. <para>This check is done to avoid leaving the hardware in an inconsistent state due
  238. to easy-to-avoid problems. But it leads to another problem: the application needs to
  239. know whether an error came from the validation step (meaning that the hardware
  240. was not touched) or from an error during the actual reading from/writing to hardware.</para>
  241. <para>The, in hindsight quite poor, solution for that is to set <structfield>error_idx</structfield>
  242. to <structfield>count</structfield> if the validation failed. This has the
  243. unfortunate side-effect that it is not possible to see which control failed the
  244. validation. If the validation was successful and the error happened while
  245. accessing the hardware, then <structfield>error_idx</structfield> is less than
  246. <structfield>count</structfield> and only the controls up to
  247. <structfield>error_idx-1</structfield> were read or written correctly, and the
  248. state of the remaining controls is undefined.</para>
  249. <para>Since <constant>VIDIOC_TRY_EXT_CTRLS</constant> does not access hardware
  250. there is also no need to handle the validation step in this special way,
  251. so <structfield>error_idx</structfield> will just be set to the control that
  252. failed the validation step instead of to <structfield>count</structfield>.
  253. This means that if <constant>VIDIOC_S_EXT_CTRLS</constant> fails with
  254. <structfield>error_idx</structfield> set to <structfield>count</structfield>,
  255. then you can call <constant>VIDIOC_TRY_EXT_CTRLS</constant> to try to discover
  256. the actual control that failed the validation step. Unfortunately, there
  257. is no <constant>TRY</constant> equivalent for <constant>VIDIOC_G_EXT_CTRLS</constant>.
  258. </para></entry>
  259. </row>
  260. <row>
  261. <entry>__u32</entry>
  262. <entry><structfield>reserved</structfield>[2]</entry>
  263. <entry>Reserved for future extensions. Drivers and
  264. applications must set the array to zero.</entry>
  265. </row>
  266. <row>
  267. <entry>&v4l2-ext-control; *</entry>
  268. <entry><structfield>controls</structfield></entry>
  269. <entry>Pointer to an array of
  270. <structfield>count</structfield> v4l2_ext_control structures. Ignored
  271. if <structfield>count</structfield> equals zero.</entry>
  272. </row>
  273. </tbody>
  274. </tgroup>
  275. </table>
  276. <table pgwide="1" frame="none" id="ctrl-class">
  277. <title>Control classes</title>
  278. <tgroup cols="3">
  279. &cs-def;
  280. <tbody valign="top">
  281. <row>
  282. <entry><constant>V4L2_CTRL_CLASS_USER</constant></entry>
  283. <entry>0x980000</entry>
  284. <entry>The class containing user controls. These controls
  285. are described in <xref linkend="control" />. All controls that can be set
  286. using the &VIDIOC-S-CTRL; and &VIDIOC-G-CTRL; ioctl belong to this
  287. class.</entry>
  288. </row>
  289. <row>
  290. <entry><constant>V4L2_CTRL_CLASS_MPEG</constant></entry>
  291. <entry>0x990000</entry>
  292. <entry>The class containing MPEG compression controls.
  293. These controls are described in <xref
  294. linkend="mpeg-controls" />.</entry>
  295. </row>
  296. <row>
  297. <entry><constant>V4L2_CTRL_CLASS_CAMERA</constant></entry>
  298. <entry>0x9a0000</entry>
  299. <entry>The class containing camera controls.
  300. These controls are described in <xref
  301. linkend="camera-controls" />.</entry>
  302. </row>
  303. <row>
  304. <entry><constant>V4L2_CTRL_CLASS_FM_TX</constant></entry>
  305. <entry>0x9b0000</entry>
  306. <entry>The class containing FM Transmitter (FM TX) controls.
  307. These controls are described in <xref
  308. linkend="fm-tx-controls" />.</entry>
  309. </row>
  310. <row>
  311. <entry><constant>V4L2_CTRL_CLASS_FLASH</constant></entry>
  312. <entry>0x9c0000</entry>
  313. <entry>The class containing flash device controls.
  314. These controls are described in <xref
  315. linkend="flash-controls" />.</entry>
  316. </row>
  317. <row>
  318. <entry><constant>V4L2_CTRL_CLASS_JPEG</constant></entry>
  319. <entry>0x9d0000</entry>
  320. <entry>The class containing JPEG compression controls.
  321. These controls are described in <xref
  322. linkend="jpeg-controls" />.</entry>
  323. </row>
  324. <row>
  325. <entry><constant>V4L2_CTRL_CLASS_IMAGE_SOURCE</constant></entry>
  326. <entry>0x9e0000</entry> <entry>The class containing image
  327. source controls. These controls are described in <xref
  328. linkend="image-source-controls" />.</entry>
  329. </row>
  330. <row>
  331. <entry><constant>V4L2_CTRL_CLASS_IMAGE_PROC</constant></entry>
  332. <entry>0x9f0000</entry> <entry>The class containing image
  333. processing controls. These controls are described in <xref
  334. linkend="image-process-controls" />.</entry>
  335. </row>
  336. <row>
  337. <entry><constant>V4L2_CTRL_CLASS_FM_RX</constant></entry>
  338. <entry>0xa10000</entry>
  339. <entry>The class containing FM Receiver (FM RX) controls.
  340. These controls are described in <xref
  341. linkend="fm-rx-controls" />.</entry>
  342. </row>
  343. <row>
  344. <entry><constant>V4L2_CTRL_CLASS_RF_TUNER</constant></entry>
  345. <entry>0xa20000</entry>
  346. <entry>The class containing RF tuner controls.
  347. These controls are described in <xref linkend="rf-tuner-controls" />.</entry>
  348. </row>
  349. </tbody>
  350. </tgroup>
  351. </table>
  352. </refsect1>
  353. <refsect1>
  354. &return-value;
  355. <variablelist>
  356. <varlistentry>
  357. <term><errorcode>EINVAL</errorcode></term>
  358. <listitem>
  359. <para>The &v4l2-ext-control; <structfield>id</structfield>
  360. is invalid, the &v4l2-ext-controls;
  361. <structfield>ctrl_class</structfield> is invalid, or the &v4l2-ext-control;
  362. <structfield>value</structfield> was inappropriate (e.g. the given menu
  363. index is not supported by the driver). This error code is
  364. also returned by the <constant>VIDIOC_S_EXT_CTRLS</constant> and
  365. <constant>VIDIOC_TRY_EXT_CTRLS</constant> ioctls if two or more
  366. control values are in conflict.</para>
  367. </listitem>
  368. </varlistentry>
  369. <varlistentry>
  370. <term><errorcode>ERANGE</errorcode></term>
  371. <listitem>
  372. <para>The &v4l2-ext-control; <structfield>value</structfield>
  373. is out of bounds.</para>
  374. </listitem>
  375. </varlistentry>
  376. <varlistentry>
  377. <term><errorcode>EBUSY</errorcode></term>
  378. <listitem>
  379. <para>The control is temporarily not changeable, possibly
  380. because another applications took over control of the device function
  381. this control belongs to.</para>
  382. </listitem>
  383. </varlistentry>
  384. <varlistentry>
  385. <term><errorcode>ENOSPC</errorcode></term>
  386. <listitem>
  387. <para>The space reserved for the control's payload is insufficient.
  388. The field <structfield>size</structfield> is set to a value that is enough
  389. to store the payload and this error code is returned.</para>
  390. </listitem>
  391. </varlistentry>
  392. <varlistentry>
  393. <term><errorcode>EACCES</errorcode></term>
  394. <listitem>
  395. <para>Attempt to try or set a read-only control or to get a
  396. write-only control.</para>
  397. </listitem>
  398. </varlistentry>
  399. </variablelist>
  400. </refsect1>
  401. </refentry>