vidioc-queryctrl.rst 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535
  1. .. -*- coding: utf-8; mode: rst -*-
  2. .. _VIDIOC_QUERYCTRL:
  3. *******************************************************************
  4. ioctls VIDIOC_QUERYCTRL, VIDIOC_QUERY_EXT_CTRL and VIDIOC_QUERYMENU
  5. *******************************************************************
  6. Name
  7. ====
  8. VIDIOC_QUERYCTRL - VIDIOC_QUERY_EXT_CTRL - VIDIOC_QUERYMENU - Enumerate controls and menu control items
  9. Synopsis
  10. ========
  11. .. c:function:: int ioctl( int fd, int VIDIOC_QUERYCTRL, struct v4l2_queryctrl *argp )
  12. :name: VIDIOC_QUERYCTRL
  13. .. c:function:: int ioctl( int fd, VIDIOC_QUERY_EXT_CTRL, struct v4l2_query_ext_ctrl *argp )
  14. :name: VIDIOC_QUERY_EXT_CTRL
  15. .. c:function:: int ioctl( int fd, VIDIOC_QUERYMENU, struct v4l2_querymenu *argp )
  16. :name: VIDIOC_QUERYMENU
  17. Arguments
  18. =========
  19. ``fd``
  20. File descriptor returned by :ref:`open() <func-open>`.
  21. ``argp``
  22. Description
  23. ===========
  24. To query the attributes of a control applications set the ``id`` field
  25. of a struct :ref:`v4l2_queryctrl <v4l2-queryctrl>` and call the
  26. ``VIDIOC_QUERYCTRL`` ioctl with a pointer to this structure. The driver
  27. fills the rest of the structure or returns an ``EINVAL`` error code when the
  28. ``id`` is invalid.
  29. It is possible to enumerate controls by calling ``VIDIOC_QUERYCTRL``
  30. with successive ``id`` values starting from ``V4L2_CID_BASE`` up to and
  31. exclusive ``V4L2_CID_LASTP1``. Drivers may return ``EINVAL`` if a control in
  32. this range is not supported. Further applications can enumerate private
  33. controls, which are not defined in this specification, by starting at
  34. ``V4L2_CID_PRIVATE_BASE`` and incrementing ``id`` until the driver
  35. returns ``EINVAL``.
  36. In both cases, when the driver sets the ``V4L2_CTRL_FLAG_DISABLED`` flag
  37. in the ``flags`` field this control is permanently disabled and should
  38. be ignored by the application. [#f1]_
  39. When the application ORs ``id`` with ``V4L2_CTRL_FLAG_NEXT_CTRL`` the
  40. driver returns the next supported non-compound control, or ``EINVAL`` if
  41. there is none. In addition, the ``V4L2_CTRL_FLAG_NEXT_COMPOUND`` flag
  42. can be specified to enumerate all compound controls (i.e. controls with
  43. type ≥ ``V4L2_CTRL_COMPOUND_TYPES`` and/or array control, in other words
  44. controls that contain more than one value). Specify both
  45. ``V4L2_CTRL_FLAG_NEXT_CTRL`` and ``V4L2_CTRL_FLAG_NEXT_COMPOUND`` in
  46. order to enumerate all controls, compound or not. Drivers which do not
  47. support these flags yet always return ``EINVAL``.
  48. The ``VIDIOC_QUERY_EXT_CTRL`` ioctl was introduced in order to better
  49. support controls that can use compound types, and to expose additional
  50. control information that cannot be returned in struct
  51. :ref:`v4l2_queryctrl <v4l2-queryctrl>` since that structure is full.
  52. ``VIDIOC_QUERY_EXT_CTRL`` is used in the same way as
  53. ``VIDIOC_QUERYCTRL``, except that the ``reserved`` array must be zeroed
  54. as well.
  55. Additional information is required for menu controls: the names of the
  56. menu items. To query them applications set the ``id`` and ``index``
  57. fields of struct :ref:`v4l2_querymenu <v4l2-querymenu>` and call the
  58. ``VIDIOC_QUERYMENU`` ioctl with a pointer to this structure. The driver
  59. fills the rest of the structure or returns an ``EINVAL`` error code when the
  60. ``id`` or ``index`` is invalid. Menu items are enumerated by calling
  61. ``VIDIOC_QUERYMENU`` with successive ``index`` values from struct
  62. :ref:`v4l2_queryctrl <v4l2-queryctrl>` ``minimum`` to ``maximum``,
  63. inclusive.
  64. .. note::
  65. It is possible for ``VIDIOC_QUERYMENU`` to return
  66. an ``EINVAL`` error code for some indices between ``minimum`` and
  67. ``maximum``. In that case that particular menu item is not supported by
  68. this driver. Also note that the ``minimum`` value is not necessarily 0.
  69. See also the examples in :ref:`control`.
  70. .. tabularcolumns:: |p{1.2cm}|p{3.6cm}|p{12.7cm}|
  71. .. _v4l2-queryctrl:
  72. .. cssclass:: longtable
  73. .. flat-table:: struct v4l2_queryctrl
  74. :header-rows: 0
  75. :stub-columns: 0
  76. :widths: 1 1 2
  77. * - __u32
  78. - ``id``
  79. - Identifies the control, set by the application. See
  80. :ref:`control-id` for predefined IDs. When the ID is ORed with
  81. V4L2_CTRL_FLAG_NEXT_CTRL the driver clears the flag and
  82. returns the first control with a higher ID. Drivers which do not
  83. support this flag yet always return an ``EINVAL`` error code.
  84. * - __u32
  85. - ``type``
  86. - Type of control, see :c:type:`v4l2_ctrl_type`.
  87. * - __u8
  88. - ``name``\ [32]
  89. - Name of the control, a NUL-terminated ASCII string. This
  90. information is intended for the user.
  91. * - __s32
  92. - ``minimum``
  93. - Minimum value, inclusive. This field gives a lower bound for the
  94. control. See enum :c:type:`v4l2_ctrl_type` how
  95. the minimum value is to be used for each possible control type.
  96. Note that this a signed 32-bit value.
  97. * - __s32
  98. - ``maximum``
  99. - Maximum value, inclusive. This field gives an upper bound for the
  100. control. See enum :c:type:`v4l2_ctrl_type` how
  101. the maximum value is to be used for each possible control type.
  102. Note that this a signed 32-bit value.
  103. * - __s32
  104. - ``step``
  105. - This field gives a step size for the control. See enum
  106. :c:type:`v4l2_ctrl_type` how the step value is
  107. to be used for each possible control type. Note that this an
  108. unsigned 32-bit value.
  109. Generally drivers should not scale hardware control values. It may
  110. be necessary for example when the ``name`` or ``id`` imply a
  111. particular unit and the hardware actually accepts only multiples
  112. of said unit. If so, drivers must take care values are properly
  113. rounded when scaling, such that errors will not accumulate on
  114. repeated read-write cycles.
  115. This field gives the smallest change of an integer control
  116. actually affecting hardware. Often the information is needed when
  117. the user can change controls by keyboard or GUI buttons, rather
  118. than a slider. When for example a hardware register accepts values
  119. 0-511 and the driver reports 0-65535, step should be 128.
  120. Note that although signed, the step value is supposed to be always
  121. positive.
  122. * - __s32
  123. - ``default_value``
  124. - The default value of a ``V4L2_CTRL_TYPE_INTEGER``, ``_BOOLEAN``,
  125. ``_BITMASK``, ``_MENU`` or ``_INTEGER_MENU`` control. Not valid
  126. for other types of controls.
  127. .. note::
  128. Drivers reset controls to their default value only when
  129. the driver is first loaded, never afterwards.
  130. * - __u32
  131. - ``flags``
  132. - Control flags, see :ref:`control-flags`.
  133. * - __u32
  134. - ``reserved``\ [2]
  135. - Reserved for future extensions. Drivers must set the array to
  136. zero.
  137. .. tabularcolumns:: |p{1.2cm}|p{5.0cm}|p{11.3cm}|
  138. .. _v4l2-query-ext-ctrl:
  139. .. cssclass:: longtable
  140. .. flat-table:: struct v4l2_query_ext_ctrl
  141. :header-rows: 0
  142. :stub-columns: 0
  143. :widths: 1 1 2
  144. * - __u32
  145. - ``id``
  146. - Identifies the control, set by the application. See
  147. :ref:`control-id` for predefined IDs. When the ID is ORed with
  148. ``V4L2_CTRL_FLAG_NEXT_CTRL`` the driver clears the flag and
  149. returns the first non-compound control with a higher ID. When the
  150. ID is ORed with ``V4L2_CTRL_FLAG_NEXT_COMPOUND`` the driver clears
  151. the flag and returns the first compound control with a higher ID.
  152. Set both to get the first control (compound or not) with a higher
  153. ID.
  154. * - __u32
  155. - ``type``
  156. - Type of control, see :c:type:`v4l2_ctrl_type`.
  157. * - char
  158. - ``name``\ [32]
  159. - Name of the control, a NUL-terminated ASCII string. This
  160. information is intended for the user.
  161. * - __s64
  162. - ``minimum``
  163. - Minimum value, inclusive. This field gives a lower bound for the
  164. control. See enum :c:type:`v4l2_ctrl_type` how
  165. the minimum value is to be used for each possible control type.
  166. Note that this a signed 64-bit value.
  167. * - __s64
  168. - ``maximum``
  169. - Maximum value, inclusive. This field gives an upper bound for the
  170. control. See enum :c:type:`v4l2_ctrl_type` how
  171. the maximum value is to be used for each possible control type.
  172. Note that this a signed 64-bit value.
  173. * - __u64
  174. - ``step``
  175. - This field gives a step size for the control. See enum
  176. :c:type:`v4l2_ctrl_type` how the step value is
  177. to be used for each possible control type. Note that this an
  178. unsigned 64-bit value.
  179. Generally drivers should not scale hardware control values. It may
  180. be necessary for example when the ``name`` or ``id`` imply a
  181. particular unit and the hardware actually accepts only multiples
  182. of said unit. If so, drivers must take care values are properly
  183. rounded when scaling, such that errors will not accumulate on
  184. repeated read-write cycles.
  185. This field gives the smallest change of an integer control
  186. actually affecting hardware. Often the information is needed when
  187. the user can change controls by keyboard or GUI buttons, rather
  188. than a slider. When for example a hardware register accepts values
  189. 0-511 and the driver reports 0-65535, step should be 128.
  190. * - __s64
  191. - ``default_value``
  192. - The default value of a ``V4L2_CTRL_TYPE_INTEGER``, ``_INTEGER64``,
  193. ``_BOOLEAN``, ``_BITMASK``, ``_MENU``, ``_INTEGER_MENU``, ``_U8``
  194. or ``_U16`` control. Not valid for other types of controls.
  195. .. note::
  196. Drivers reset controls to their default value only when
  197. the driver is first loaded, never afterwards.
  198. * - __u32
  199. - ``flags``
  200. - Control flags, see :ref:`control-flags`.
  201. * - __u32
  202. - ``elem_size``
  203. - The size in bytes of a single element of the array. Given a char
  204. pointer ``p`` to a 3-dimensional array you can find the position
  205. of cell ``(z, y, x)`` as follows:
  206. ``p + ((z * dims[1] + y) * dims[0] + x) * elem_size``.
  207. ``elem_size`` is always valid, also when the control isn't an
  208. array. For string controls ``elem_size`` is equal to
  209. ``maximum + 1``.
  210. * - __u32
  211. - ``elems``
  212. - The number of elements in the N-dimensional array. If this control
  213. is not an array, then ``elems`` is 1. The ``elems`` field can
  214. never be 0.
  215. * - __u32
  216. - ``nr_of_dims``
  217. - The number of dimension in the N-dimensional array. If this
  218. control is not an array, then this field is 0.
  219. * - __u32
  220. - ``dims[V4L2_CTRL_MAX_DIMS]``
  221. - The size of each dimension. The first ``nr_of_dims`` elements of
  222. this array must be non-zero, all remaining elements must be zero.
  223. * - __u32
  224. - ``reserved``\ [32]
  225. - Reserved for future extensions. Applications and drivers must set
  226. the array to zero.
  227. .. tabularcolumns:: |p{1.2cm}|p{0.6cm}|p{1.6cm}|p{13.5cm}|
  228. .. _v4l2-querymenu:
  229. .. flat-table:: struct v4l2_querymenu
  230. :header-rows: 0
  231. :stub-columns: 0
  232. :widths: 1 1 2 1
  233. * - __u32
  234. -
  235. - ``id``
  236. - Identifies the control, set by the application from the respective
  237. struct :ref:`v4l2_queryctrl <v4l2-queryctrl>` ``id``.
  238. * - __u32
  239. -
  240. - ``index``
  241. - Index of the menu item, starting at zero, set by the application.
  242. * - union
  243. -
  244. -
  245. -
  246. * -
  247. - __u8
  248. - ``name``\ [32]
  249. - Name of the menu item, a NUL-terminated ASCII string. This
  250. information is intended for the user. This field is valid for
  251. ``V4L2_CTRL_FLAG_MENU`` type controls.
  252. * -
  253. - __s64
  254. - ``value``
  255. - Value of the integer menu item. This field is valid for
  256. ``V4L2_CTRL_FLAG_INTEGER_MENU`` type controls.
  257. * - __u32
  258. -
  259. - ``reserved``
  260. - Reserved for future extensions. Drivers must set the array to
  261. zero.
  262. .. tabularcolumns:: |p{5.8cm}|p{1.4cm}|p{1.0cm}|p{1.4cm}|p{6.9cm}|
  263. .. c:type:: v4l2_ctrl_type
  264. .. cssclass:: longtable
  265. .. flat-table:: enum v4l2_ctrl_type
  266. :header-rows: 1
  267. :stub-columns: 0
  268. :widths: 30 5 5 5 55
  269. * - Type
  270. - ``minimum``
  271. - ``step``
  272. - ``maximum``
  273. - Description
  274. * - ``V4L2_CTRL_TYPE_INTEGER``
  275. - any
  276. - any
  277. - any
  278. - An integer-valued control ranging from minimum to maximum
  279. inclusive. The step value indicates the increment between values.
  280. * - ``V4L2_CTRL_TYPE_BOOLEAN``
  281. - 0
  282. - 1
  283. - 1
  284. - A boolean-valued control. Zero corresponds to "disabled", and one
  285. means "enabled".
  286. * - ``V4L2_CTRL_TYPE_MENU``
  287. - ≥ 0
  288. - 1
  289. - N-1
  290. - The control has a menu of N choices. The names of the menu items
  291. can be enumerated with the ``VIDIOC_QUERYMENU`` ioctl.
  292. * - ``V4L2_CTRL_TYPE_INTEGER_MENU``
  293. - ≥ 0
  294. - 1
  295. - N-1
  296. - The control has a menu of N choices. The values of the menu items
  297. can be enumerated with the ``VIDIOC_QUERYMENU`` ioctl. This is
  298. similar to ``V4L2_CTRL_TYPE_MENU`` except that instead of strings,
  299. the menu items are signed 64-bit integers.
  300. * - ``V4L2_CTRL_TYPE_BITMASK``
  301. - 0
  302. - n/a
  303. - any
  304. - A bitmask field. The maximum value is the set of bits that can be
  305. used, all other bits are to be 0. The maximum value is interpreted
  306. as a __u32, allowing the use of bit 31 in the bitmask.
  307. * - ``V4L2_CTRL_TYPE_BUTTON``
  308. - 0
  309. - 0
  310. - 0
  311. - A control which performs an action when set. Drivers must ignore
  312. the value passed with ``VIDIOC_S_CTRL`` and return an ``EINVAL`` error
  313. code on a ``VIDIOC_G_CTRL`` attempt.
  314. * - ``V4L2_CTRL_TYPE_INTEGER64``
  315. - any
  316. - any
  317. - any
  318. - A 64-bit integer valued control. Minimum, maximum and step size
  319. cannot be queried using ``VIDIOC_QUERYCTRL``. Only
  320. ``VIDIOC_QUERY_EXT_CTRL`` can retrieve the 64-bit min/max/step
  321. values, they should be interpreted as n/a when using
  322. ``VIDIOC_QUERYCTRL``.
  323. * - ``V4L2_CTRL_TYPE_STRING``
  324. - ≥ 0
  325. - ≥ 1
  326. - ≥ 0
  327. - The minimum and maximum string lengths. The step size means that
  328. the string must be (minimum + N * step) characters long for N ≥ 0.
  329. These lengths do not include the terminating zero, so in order to
  330. pass a string of length 8 to
  331. :ref:`VIDIOC_S_EXT_CTRLS <VIDIOC_G_EXT_CTRLS>` you need to
  332. set the ``size`` field of struct
  333. :c:type:`v4l2_ext_control` to 9. For
  334. :ref:`VIDIOC_G_EXT_CTRLS <VIDIOC_G_EXT_CTRLS>` you can set
  335. the ``size`` field to ``maximum`` + 1. Which character encoding is
  336. used will depend on the string control itself and should be part
  337. of the control documentation.
  338. * - ``V4L2_CTRL_TYPE_CTRL_CLASS``
  339. - n/a
  340. - n/a
  341. - n/a
  342. - This is not a control. When ``VIDIOC_QUERYCTRL`` is called with a
  343. control ID equal to a control class code (see :ref:`ctrl-class`)
  344. + 1, the ioctl returns the name of the control class and this
  345. control type. Older drivers which do not support this feature
  346. return an ``EINVAL`` error code.
  347. * - ``V4L2_CTRL_TYPE_U8``
  348. - any
  349. - any
  350. - any
  351. - An unsigned 8-bit valued control ranging from minimum to maximum
  352. inclusive. The step value indicates the increment between values.
  353. * - ``V4L2_CTRL_TYPE_U16``
  354. - any
  355. - any
  356. - any
  357. - An unsigned 16-bit valued control ranging from minimum to maximum
  358. inclusive. The step value indicates the increment between values.
  359. * - ``V4L2_CTRL_TYPE_U32``
  360. - any
  361. - any
  362. - any
  363. - An unsigned 32-bit valued control ranging from minimum to maximum
  364. inclusive. The step value indicates the increment between values.
  365. .. tabularcolumns:: |p{6.6cm}|p{2.2cm}|p{8.7cm}|
  366. .. _control-flags:
  367. .. cssclass:: longtable
  368. .. flat-table:: Control Flags
  369. :header-rows: 0
  370. :stub-columns: 0
  371. :widths: 3 1 4
  372. * - ``V4L2_CTRL_FLAG_DISABLED``
  373. - 0x0001
  374. - This control is permanently disabled and should be ignored by the
  375. application. Any attempt to change the control will result in an
  376. ``EINVAL`` error code.
  377. * - ``V4L2_CTRL_FLAG_GRABBED``
  378. - 0x0002
  379. - This control is temporarily unchangeable, for example because
  380. another application took over control of the respective resource.
  381. Such controls may be displayed specially in a user interface.
  382. Attempts to change the control may result in an ``EBUSY`` error code.
  383. * - ``V4L2_CTRL_FLAG_READ_ONLY``
  384. - 0x0004
  385. - This control is permanently readable only. Any attempt to change
  386. the control will result in an ``EINVAL`` error code.
  387. * - ``V4L2_CTRL_FLAG_UPDATE``
  388. - 0x0008
  389. - A hint that changing this control may affect the value of other
  390. controls within the same control class. Applications should update
  391. their user interface accordingly.
  392. * - ``V4L2_CTRL_FLAG_INACTIVE``
  393. - 0x0010
  394. - This control is not applicable to the current configuration and
  395. should be displayed accordingly in a user interface. For example
  396. the flag may be set on a MPEG audio level 2 bitrate control when
  397. MPEG audio encoding level 1 was selected with another control.
  398. * - ``V4L2_CTRL_FLAG_SLIDER``
  399. - 0x0020
  400. - A hint that this control is best represented as a slider-like
  401. element in a user interface.
  402. * - ``V4L2_CTRL_FLAG_WRITE_ONLY``
  403. - 0x0040
  404. - This control is permanently writable only. Any attempt to read the
  405. control will result in an ``EACCES`` error code error code. This flag
  406. is typically present for relative controls or action controls
  407. where writing a value will cause the device to carry out a given
  408. action (e. g. motor control) but no meaningful value can be
  409. returned.
  410. * - ``V4L2_CTRL_FLAG_VOLATILE``
  411. - 0x0080
  412. - This control is volatile, which means that the value of the
  413. control changes continuously. A typical example would be the
  414. current gain value if the device is in auto-gain mode. In such a
  415. case the hardware calculates the gain value based on the lighting
  416. conditions which can change over time.
  417. .. note::
  418. Setting a new value for a volatile control will be ignored
  419. unless
  420. :ref:`V4L2_CTRL_FLAG_EXECUTE_ON_WRITE <FLAG_EXECUTE_ON_WRITE>`
  421. is also set.
  422. Setting a new value for a volatile control will *never* trigger a
  423. :ref:`V4L2_EVENT_CTRL_CH_VALUE <ctrl-changes-flags>` event.
  424. * - ``V4L2_CTRL_FLAG_HAS_PAYLOAD``
  425. - 0x0100
  426. - This control has a pointer type, so its value has to be accessed
  427. using one of the pointer fields of struct
  428. :c:type:`v4l2_ext_control`. This flag is set
  429. for controls that are an array, string, or have a compound type.
  430. In all cases you have to set a pointer to memory containing the
  431. payload of the control.
  432. * .. _FLAG_EXECUTE_ON_WRITE:
  433. - ``V4L2_CTRL_FLAG_EXECUTE_ON_WRITE``
  434. - 0x0200
  435. - The value provided to the control will be propagated to the driver
  436. even if it remains constant. This is required when the control
  437. represents an action on the hardware. For example: clearing an
  438. error flag or triggering the flash. All the controls of the type
  439. ``V4L2_CTRL_TYPE_BUTTON`` have this flag set.
  440. Return Value
  441. ============
  442. On success 0 is returned, on error -1 and the ``errno`` variable is set
  443. appropriately. The generic error codes are described at the
  444. :ref:`Generic Error Codes <gen-errors>` chapter.
  445. EINVAL
  446. The struct :ref:`v4l2_queryctrl <v4l2-queryctrl>` ``id`` is
  447. invalid. The struct :ref:`v4l2_querymenu <v4l2-querymenu>` ``id``
  448. is invalid or ``index`` is out of range (less than ``minimum`` or
  449. greater than ``maximum``) or this particular menu item is not
  450. supported by the driver.
  451. EACCES
  452. An attempt was made to read a write-only control.
  453. .. [#f1]
  454. ``V4L2_CTRL_FLAG_DISABLED`` was intended for two purposes: Drivers
  455. can skip predefined controls not supported by the hardware (although
  456. returning ``EINVAL`` would do as well), or disable predefined and private
  457. controls after hardware detection without the trouble of reordering
  458. control arrays and indices (``EINVAL`` cannot be used to skip private
  459. controls because it would prematurely end the enumeration).