buffer.rst 29 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803
  1. .. SPDX-License-Identifier: GFDL-1.1-no-invariants-or-later
  2. .. c:namespace:: V4L
  3. .. _buffer:
  4. *******
  5. Buffers
  6. *******
  7. A buffer contains data exchanged by application and driver using one of
  8. the Streaming I/O methods. In the multi-planar API, the data is held in
  9. planes, while the buffer structure acts as a container for the planes.
  10. Only pointers to buffers (planes) are exchanged, the data itself is not
  11. copied. These pointers, together with meta-information like timestamps
  12. or field parity, are stored in a struct :c:type:`v4l2_buffer`,
  13. argument to the :ref:`VIDIOC_QUERYBUF`,
  14. :ref:`VIDIOC_QBUF <VIDIOC_QBUF>` and
  15. :ref:`VIDIOC_DQBUF <VIDIOC_QBUF>` ioctl. In the multi-planar API,
  16. some plane-specific members of struct :c:type:`v4l2_buffer`,
  17. such as pointers and sizes for each plane, are stored in
  18. struct :c:type:`v4l2_plane` instead. In that case,
  19. struct :c:type:`v4l2_buffer` contains an array of plane structures.
  20. Dequeued video buffers come with timestamps. The driver decides at which
  21. part of the frame and with which clock the timestamp is taken. Please
  22. see flags in the masks ``V4L2_BUF_FLAG_TIMESTAMP_MASK`` and
  23. ``V4L2_BUF_FLAG_TSTAMP_SRC_MASK`` in :ref:`buffer-flags`. These flags
  24. are always valid and constant across all buffers during the whole video
  25. stream. Changes in these flags may take place as a side effect of
  26. :ref:`VIDIOC_S_INPUT <VIDIOC_G_INPUT>` or
  27. :ref:`VIDIOC_S_OUTPUT <VIDIOC_G_OUTPUT>` however. The
  28. ``V4L2_BUF_FLAG_TIMESTAMP_COPY`` timestamp type which is used by e.g. on
  29. mem-to-mem devices is an exception to the rule: the timestamp source
  30. flags are copied from the OUTPUT video buffer to the CAPTURE video
  31. buffer.
  32. Interactions between formats, controls and buffers
  33. ==================================================
  34. V4L2 exposes parameters that influence the buffer size, or the way data is
  35. laid out in the buffer. Those parameters are exposed through both formats and
  36. controls. One example of such a control is the ``V4L2_CID_ROTATE`` control
  37. that modifies the direction in which pixels are stored in the buffer, as well
  38. as the buffer size when the selected format includes padding at the end of
  39. lines.
  40. The set of information needed to interpret the content of a buffer (e.g. the
  41. pixel format, the line stride, the tiling orientation or the rotation) is
  42. collectively referred to in the rest of this section as the buffer layout.
  43. Controls that can modify the buffer layout shall set the
  44. ``V4L2_CTRL_FLAG_MODIFY_LAYOUT`` flag.
  45. Modifying formats or controls that influence the buffer size or layout require
  46. the stream to be stopped. Any attempt at such a modification while the stream
  47. is active shall cause the ioctl setting the format or the control to return
  48. the ``EBUSY`` error code. In that case drivers shall also set the
  49. ``V4L2_CTRL_FLAG_GRABBED`` flag when calling
  50. :c:func:`VIDIOC_QUERYCTRL` or :c:func:`VIDIOC_QUERY_EXT_CTRL` for such a
  51. control while the stream is active.
  52. .. note::
  53. The :c:func:`VIDIOC_S_SELECTION` ioctl can, depending on the hardware (for
  54. instance if the device doesn't include a scaler), modify the format in
  55. addition to the selection rectangle. Similarly, the
  56. :c:func:`VIDIOC_S_INPUT`, :c:func:`VIDIOC_S_OUTPUT`, :c:func:`VIDIOC_S_STD`
  57. and :c:func:`VIDIOC_S_DV_TIMINGS` ioctls can also modify the format and
  58. selection rectangles. When those ioctls result in a buffer size or layout
  59. change, drivers shall handle that condition as they would handle it in the
  60. :c:func:`VIDIOC_S_FMT` ioctl in all cases described in this section.
  61. Controls that only influence the buffer layout can be modified at any time
  62. when the stream is stopped. As they don't influence the buffer size, no
  63. special handling is needed to synchronize those controls with buffer
  64. allocation and the ``V4L2_CTRL_FLAG_GRABBED`` flag is cleared once the
  65. stream is stopped.
  66. Formats and controls that influence the buffer size interact with buffer
  67. allocation. The simplest way to handle this is for drivers to always require
  68. buffers to be reallocated in order to change those formats or controls. In
  69. that case, to perform such changes, userspace applications shall first stop
  70. the video stream with the :c:func:`VIDIOC_STREAMOFF` ioctl if it is running
  71. and free all buffers with the :c:func:`VIDIOC_REQBUFS` ioctl if they are
  72. allocated. After freeing all buffers the ``V4L2_CTRL_FLAG_GRABBED`` flag
  73. for controls is cleared. The format or controls can then be modified, and
  74. buffers shall then be reallocated and the stream restarted. A typical ioctl
  75. sequence is
  76. #. VIDIOC_STREAMOFF
  77. #. VIDIOC_REQBUFS(0)
  78. #. VIDIOC_S_EXT_CTRLS
  79. #. VIDIOC_S_FMT
  80. #. VIDIOC_REQBUFS(n)
  81. #. VIDIOC_QBUF
  82. #. VIDIOC_STREAMON
  83. The second :c:func:`VIDIOC_REQBUFS` call will take the new format and control
  84. value into account to compute the buffer size to allocate. Applications can
  85. also retrieve the size by calling the :c:func:`VIDIOC_G_FMT` ioctl if needed.
  86. .. note::
  87. The API doesn't mandate the above order for control (3.) and format (4.)
  88. changes. Format and controls can be set in a different order, or even
  89. interleaved, depending on the device and use case. For instance some
  90. controls might behave differently for different pixel formats, in which
  91. case the format might need to be set first.
  92. When reallocation is required, any attempt to modify format or controls that
  93. influences the buffer size while buffers are allocated shall cause the format
  94. or control set ioctl to return the ``EBUSY`` error. Any attempt to queue a
  95. buffer too small for the current format or controls shall cause the
  96. :c:func:`VIDIOC_QBUF` ioctl to return a ``EINVAL`` error.
  97. Buffer reallocation is an expensive operation. To avoid that cost, drivers can
  98. (and are encouraged to) allow format or controls that influence the buffer
  99. size to be changed with buffers allocated. In that case, a typical ioctl
  100. sequence to modify format and controls is
  101. #. VIDIOC_STREAMOFF
  102. #. VIDIOC_S_EXT_CTRLS
  103. #. VIDIOC_S_FMT
  104. #. VIDIOC_QBUF
  105. #. VIDIOC_STREAMON
  106. For this sequence to operate correctly, queued buffers need to be large enough
  107. for the new format or controls. Drivers shall return a ``ENOSPC`` error in
  108. response to format change (:c:func:`VIDIOC_S_FMT`) or control changes
  109. (:c:func:`VIDIOC_S_CTRL` or :c:func:`VIDIOC_S_EXT_CTRLS`) if buffers too small
  110. for the new format are currently queued. As a simplification, drivers are
  111. allowed to return a ``EBUSY`` error from these ioctls if any buffer is
  112. currently queued, without checking the queued buffers sizes.
  113. Additionally, drivers shall return a ``EINVAL`` error from the
  114. :c:func:`VIDIOC_QBUF` ioctl if the buffer being queued is too small for the
  115. current format or controls. Together, these requirements ensure that queued
  116. buffers will always be large enough for the configured format and controls.
  117. Userspace applications can query the buffer size required for a given format
  118. and controls by first setting the desired control values and then trying the
  119. desired format. The :c:func:`VIDIOC_TRY_FMT` ioctl will return the required
  120. buffer size.
  121. #. VIDIOC_S_EXT_CTRLS(x)
  122. #. VIDIOC_TRY_FMT()
  123. #. VIDIOC_S_EXT_CTRLS(y)
  124. #. VIDIOC_TRY_FMT()
  125. The :c:func:`VIDIOC_CREATE_BUFS` ioctl can then be used to allocate buffers
  126. based on the queried sizes (for instance by allocating a set of buffers large
  127. enough for all the desired formats and controls, or by allocating separate set
  128. of appropriately sized buffers for each use case).
  129. .. c:type:: v4l2_buffer
  130. struct v4l2_buffer
  131. ==================
  132. .. tabularcolumns:: |p{2.9cm}|p{2.4cm}|p{12.0cm}|
  133. .. cssclass:: longtable
  134. .. flat-table:: struct v4l2_buffer
  135. :header-rows: 0
  136. :stub-columns: 0
  137. :widths: 1 2 10
  138. * - __u32
  139. - ``index``
  140. - Number of the buffer, set by the application except when calling
  141. :ref:`VIDIOC_DQBUF <VIDIOC_QBUF>`, then it is set by the
  142. driver. This field can range from zero to the number of buffers
  143. allocated with the :ref:`VIDIOC_REQBUFS` ioctl
  144. (struct :c:type:`v4l2_requestbuffers`
  145. ``count``), plus any buffers allocated with
  146. :ref:`VIDIOC_CREATE_BUFS` minus one.
  147. * - __u32
  148. - ``type``
  149. - Type of the buffer, same as struct
  150. :c:type:`v4l2_format` ``type`` or struct
  151. :c:type:`v4l2_requestbuffers` ``type``, set
  152. by the application. See :c:type:`v4l2_buf_type`
  153. * - __u32
  154. - ``bytesused``
  155. - The number of bytes occupied by the data in the buffer. It depends
  156. on the negotiated data format and may change with each buffer for
  157. compressed variable size data like JPEG images. Drivers must set
  158. this field when ``type`` refers to a capture stream, applications
  159. when it refers to an output stream. For multiplanar formats this field
  160. is ignored and the
  161. ``planes`` pointer is used instead.
  162. * - __u32
  163. - ``flags``
  164. - Flags set by the application or driver, see :ref:`buffer-flags`.
  165. * - __u32
  166. - ``field``
  167. - Indicates the field order of the image in the buffer, see
  168. :c:type:`v4l2_field`. This field is not used when the buffer
  169. contains VBI data. Drivers must set it when ``type`` refers to a
  170. capture stream, applications when it refers to an output stream.
  171. * - struct timeval
  172. - ``timestamp``
  173. - For capture streams this is time when the first data byte was
  174. captured, as returned by the :c:func:`clock_gettime()` function
  175. for the relevant clock id; see ``V4L2_BUF_FLAG_TIMESTAMP_*`` in
  176. :ref:`buffer-flags`. For output streams the driver stores the
  177. time at which the last data byte was actually sent out in the
  178. ``timestamp`` field. This permits applications to monitor the
  179. drift between the video and system clock. For output streams that
  180. use ``V4L2_BUF_FLAG_TIMESTAMP_COPY`` the application has to fill
  181. in the timestamp which will be copied by the driver to the capture
  182. stream.
  183. * - struct :c:type:`v4l2_timecode`
  184. - ``timecode``
  185. - When the ``V4L2_BUF_FLAG_TIMECODE`` flag is set in ``flags``, this
  186. structure contains a frame timecode. In
  187. :c:type:`V4L2_FIELD_ALTERNATE <v4l2_field>` mode the top and
  188. bottom field contain the same timecode. Timecodes are intended to
  189. help video editing and are typically recorded on video tapes, but
  190. also embedded in compressed formats like MPEG. This field is
  191. independent of the ``timestamp`` and ``sequence`` fields.
  192. * - __u32
  193. - ``sequence``
  194. - Set by the driver, counting the frames (not fields!) in sequence.
  195. This field is set for both input and output devices.
  196. * - :cspan:`2`
  197. In :c:type:`V4L2_FIELD_ALTERNATE <v4l2_field>` mode the top and
  198. bottom field have the same sequence number. The count starts at
  199. zero and includes dropped or repeated frames. A dropped frame was
  200. received by an input device but could not be stored due to lack of
  201. free buffer space. A repeated frame was displayed again by an
  202. output device because the application did not pass new data in
  203. time.
  204. .. note::
  205. This may count the frames received e.g. over USB, without
  206. taking into account the frames dropped by the remote hardware due
  207. to limited compression throughput or bus bandwidth. These devices
  208. identify by not enumerating any video standards, see
  209. :ref:`standard`.
  210. * - __u32
  211. - ``memory``
  212. - This field must be set by applications and/or drivers in
  213. accordance with the selected I/O method. See :c:type:`v4l2_memory`
  214. * - union {
  215. - ``m``
  216. * - __u32
  217. - ``offset``
  218. - For the single-planar API and when ``memory`` is
  219. ``V4L2_MEMORY_MMAP`` this is the offset of the buffer from the
  220. start of the device memory. The value is returned by the driver
  221. and apart of serving as parameter to the
  222. :c:func:`mmap()` function not useful for applications.
  223. See :ref:`mmap` for details
  224. * - unsigned long
  225. - ``userptr``
  226. - For the single-planar API and when ``memory`` is
  227. ``V4L2_MEMORY_USERPTR`` this is a pointer to the buffer (casted to
  228. unsigned long type) in virtual memory, set by the application. See
  229. :ref:`userp` for details.
  230. * - struct v4l2_plane
  231. - ``*planes``
  232. - When using the multi-planar API, contains a userspace pointer to
  233. an array of struct :c:type:`v4l2_plane`. The size of
  234. the array should be put in the ``length`` field of this
  235. struct :c:type:`v4l2_buffer` structure.
  236. * - int
  237. - ``fd``
  238. - For the single-plane API and when ``memory`` is
  239. ``V4L2_MEMORY_DMABUF`` this is the file descriptor associated with
  240. a DMABUF buffer.
  241. * - }
  242. -
  243. * - __u32
  244. - ``length``
  245. - Size of the buffer (not the payload) in bytes for the
  246. single-planar API. This is set by the driver based on the calls to
  247. :ref:`VIDIOC_REQBUFS` and/or
  248. :ref:`VIDIOC_CREATE_BUFS`. For the
  249. multi-planar API the application sets this to the number of
  250. elements in the ``planes`` array. The driver will fill in the
  251. actual number of valid elements in that array.
  252. * - __u32
  253. - ``reserved2``
  254. - A place holder for future extensions. Drivers and applications
  255. must set this to 0.
  256. * - __u32
  257. - ``request_fd``
  258. - The file descriptor of the request to queue the buffer to. If the flag
  259. ``V4L2_BUF_FLAG_REQUEST_FD`` is set, then the buffer will be
  260. queued to this request. If the flag is not set, then this field will
  261. be ignored.
  262. The ``V4L2_BUF_FLAG_REQUEST_FD`` flag and this field are only used by
  263. :ref:`ioctl VIDIOC_QBUF <VIDIOC_QBUF>` and ignored by other ioctls that
  264. take a :c:type:`v4l2_buffer` as argument.
  265. Applications should not set ``V4L2_BUF_FLAG_REQUEST_FD`` for any ioctls
  266. other than :ref:`VIDIOC_QBUF <VIDIOC_QBUF>`.
  267. If the device does not support requests, then ``EBADR`` will be returned.
  268. If requests are supported but an invalid request file descriptor is
  269. given, then ``EINVAL`` will be returned.
  270. .. c:type:: v4l2_plane
  271. struct v4l2_plane
  272. =================
  273. .. tabularcolumns:: |p{3.5cm}|p{3.5cm}|p{10.3cm}|
  274. .. cssclass:: longtable
  275. .. flat-table::
  276. :header-rows: 0
  277. :stub-columns: 0
  278. :widths: 1 1 2
  279. * - __u32
  280. - ``bytesused``
  281. - The number of bytes occupied by data in the plane (its payload).
  282. Drivers must set this field when ``type`` refers to a capture
  283. stream, applications when it refers to an output stream.
  284. .. note::
  285. Note that the actual image data starts at ``data_offset``
  286. which may not be 0.
  287. * - __u32
  288. - ``length``
  289. - Size in bytes of the plane (not its payload). This is set by the
  290. driver based on the calls to
  291. :ref:`VIDIOC_REQBUFS` and/or
  292. :ref:`VIDIOC_CREATE_BUFS`.
  293. * - union {
  294. - ``m``
  295. * - __u32
  296. - ``mem_offset``
  297. - When the memory type in the containing struct
  298. :c:type:`v4l2_buffer` is ``V4L2_MEMORY_MMAP``, this
  299. is the value that should be passed to :c:func:`mmap()`,
  300. similar to the ``offset`` field in struct
  301. :c:type:`v4l2_buffer`.
  302. * - unsigned long
  303. - ``userptr``
  304. - When the memory type in the containing struct
  305. :c:type:`v4l2_buffer` is ``V4L2_MEMORY_USERPTR``,
  306. this is a userspace pointer to the memory allocated for this plane
  307. by an application.
  308. * - int
  309. - ``fd``
  310. - When the memory type in the containing struct
  311. :c:type:`v4l2_buffer` is ``V4L2_MEMORY_DMABUF``,
  312. this is a file descriptor associated with a DMABUF buffer, similar
  313. to the ``fd`` field in struct :c:type:`v4l2_buffer`.
  314. * - }
  315. -
  316. * - __u32
  317. - ``data_offset``
  318. - Offset in bytes to video data in the plane. Drivers must set this
  319. field when ``type`` refers to a capture stream, applications when
  320. it refers to an output stream.
  321. .. note::
  322. That data_offset is included in ``bytesused``. So the
  323. size of the image in the plane is ``bytesused``-``data_offset``
  324. at offset ``data_offset`` from the start of the plane.
  325. * - __u32
  326. - ``reserved[11]``
  327. - Reserved for future use. Should be zeroed by drivers and
  328. applications.
  329. .. c:type:: v4l2_buf_type
  330. enum v4l2_buf_type
  331. ==================
  332. .. cssclass:: longtable
  333. .. tabularcolumns:: |p{7.8cm}|p{0.6cm}|p{8.9cm}|
  334. .. flat-table::
  335. :header-rows: 0
  336. :stub-columns: 0
  337. :widths: 4 1 9
  338. * - ``V4L2_BUF_TYPE_VIDEO_CAPTURE``
  339. - 1
  340. - Buffer of a single-planar video capture stream, see
  341. :ref:`capture`.
  342. * - ``V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE``
  343. - 9
  344. - Buffer of a multi-planar video capture stream, see
  345. :ref:`capture`.
  346. * - ``V4L2_BUF_TYPE_VIDEO_OUTPUT``
  347. - 2
  348. - Buffer of a single-planar video output stream, see
  349. :ref:`output`.
  350. * - ``V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE``
  351. - 10
  352. - Buffer of a multi-planar video output stream, see :ref:`output`.
  353. * - ``V4L2_BUF_TYPE_VIDEO_OVERLAY``
  354. - 3
  355. - Buffer for video overlay, see :ref:`overlay`.
  356. * - ``V4L2_BUF_TYPE_VBI_CAPTURE``
  357. - 4
  358. - Buffer of a raw VBI capture stream, see :ref:`raw-vbi`.
  359. * - ``V4L2_BUF_TYPE_VBI_OUTPUT``
  360. - 5
  361. - Buffer of a raw VBI output stream, see :ref:`raw-vbi`.
  362. * - ``V4L2_BUF_TYPE_SLICED_VBI_CAPTURE``
  363. - 6
  364. - Buffer of a sliced VBI capture stream, see :ref:`sliced`.
  365. * - ``V4L2_BUF_TYPE_SLICED_VBI_OUTPUT``
  366. - 7
  367. - Buffer of a sliced VBI output stream, see :ref:`sliced`.
  368. * - ``V4L2_BUF_TYPE_VIDEO_OUTPUT_OVERLAY``
  369. - 8
  370. - Buffer for video output overlay (OSD), see :ref:`osd`.
  371. * - ``V4L2_BUF_TYPE_SDR_CAPTURE``
  372. - 11
  373. - Buffer for Software Defined Radio (SDR) capture stream, see
  374. :ref:`sdr`.
  375. * - ``V4L2_BUF_TYPE_SDR_OUTPUT``
  376. - 12
  377. - Buffer for Software Defined Radio (SDR) output stream, see
  378. :ref:`sdr`.
  379. * - ``V4L2_BUF_TYPE_META_CAPTURE``
  380. - 13
  381. - Buffer for metadata capture, see :ref:`metadata`.
  382. * - ``V4L2_BUF_TYPE_META_OUTPUT``
  383. - 14
  384. - Buffer for metadata output, see :ref:`metadata`.
  385. .. _buffer-flags:
  386. Buffer Flags
  387. ============
  388. .. raw:: latex
  389. \footnotesize
  390. .. tabularcolumns:: |p{6.5cm}|p{1.8cm}|p{9.0cm}|
  391. .. cssclass:: longtable
  392. .. flat-table::
  393. :header-rows: 0
  394. :stub-columns: 0
  395. :widths: 65 18 70
  396. * .. _`V4L2-BUF-FLAG-MAPPED`:
  397. - ``V4L2_BUF_FLAG_MAPPED``
  398. - 0x00000001
  399. - The buffer resides in device memory and has been mapped into the
  400. application's address space, see :ref:`mmap` for details.
  401. Drivers set or clear this flag when the
  402. :ref:`VIDIOC_QUERYBUF`,
  403. :ref:`VIDIOC_QBUF` or
  404. :ref:`VIDIOC_DQBUF <VIDIOC_QBUF>` ioctl is called. Set by the
  405. driver.
  406. * .. _`V4L2-BUF-FLAG-QUEUED`:
  407. - ``V4L2_BUF_FLAG_QUEUED``
  408. - 0x00000002
  409. - Internally drivers maintain two buffer queues, an incoming and
  410. outgoing queue. When this flag is set, the buffer is currently on
  411. the incoming queue. It automatically moves to the outgoing queue
  412. after the buffer has been filled (capture devices) or displayed
  413. (output devices). Drivers set or clear this flag when the
  414. ``VIDIOC_QUERYBUF`` ioctl is called. After (successful) calling
  415. the ``VIDIOC_QBUF``\ ioctl it is always set and after
  416. ``VIDIOC_DQBUF`` always cleared.
  417. * .. _`V4L2-BUF-FLAG-DONE`:
  418. - ``V4L2_BUF_FLAG_DONE``
  419. - 0x00000004
  420. - When this flag is set, the buffer is currently on the outgoing
  421. queue, ready to be dequeued from the driver. Drivers set or clear
  422. this flag when the ``VIDIOC_QUERYBUF`` ioctl is called. After
  423. calling the ``VIDIOC_QBUF`` or ``VIDIOC_DQBUF`` it is always
  424. cleared. Of course a buffer cannot be on both queues at the same
  425. time, the ``V4L2_BUF_FLAG_QUEUED`` and ``V4L2_BUF_FLAG_DONE`` flag
  426. are mutually exclusive. They can be both cleared however, then the
  427. buffer is in "dequeued" state, in the application domain so to
  428. say.
  429. * .. _`V4L2-BUF-FLAG-ERROR`:
  430. - ``V4L2_BUF_FLAG_ERROR``
  431. - 0x00000040
  432. - When this flag is set, the buffer has been dequeued successfully,
  433. although the data might have been corrupted. This is recoverable,
  434. streaming may continue as normal and the buffer may be reused
  435. normally. Drivers set this flag when the ``VIDIOC_DQBUF`` ioctl is
  436. called.
  437. * .. _`V4L2-BUF-FLAG-IN-REQUEST`:
  438. - ``V4L2_BUF_FLAG_IN_REQUEST``
  439. - 0x00000080
  440. - This buffer is part of a request that hasn't been queued yet.
  441. * .. _`V4L2-BUF-FLAG-KEYFRAME`:
  442. - ``V4L2_BUF_FLAG_KEYFRAME``
  443. - 0x00000008
  444. - Drivers set or clear this flag when calling the ``VIDIOC_DQBUF``
  445. ioctl. It may be set by video capture devices when the buffer
  446. contains a compressed image which is a key frame (or field), i. e.
  447. can be decompressed on its own. Also known as an I-frame.
  448. Applications can set this bit when ``type`` refers to an output
  449. stream.
  450. * .. _`V4L2-BUF-FLAG-PFRAME`:
  451. - ``V4L2_BUF_FLAG_PFRAME``
  452. - 0x00000010
  453. - Similar to ``V4L2_BUF_FLAG_KEYFRAME`` this flags predicted frames
  454. or fields which contain only differences to a previous key frame.
  455. Applications can set this bit when ``type`` refers to an output
  456. stream.
  457. * .. _`V4L2-BUF-FLAG-BFRAME`:
  458. - ``V4L2_BUF_FLAG_BFRAME``
  459. - 0x00000020
  460. - Similar to ``V4L2_BUF_FLAG_KEYFRAME`` this flags a bi-directional
  461. predicted frame or field which contains only the differences
  462. between the current frame and both the preceding and following key
  463. frames to specify its content. Applications can set this bit when
  464. ``type`` refers to an output stream.
  465. * .. _`V4L2-BUF-FLAG-TIMECODE`:
  466. - ``V4L2_BUF_FLAG_TIMECODE``
  467. - 0x00000100
  468. - The ``timecode`` field is valid. Drivers set or clear this flag
  469. when the ``VIDIOC_DQBUF`` ioctl is called. Applications can set
  470. this bit and the corresponding ``timecode`` structure when
  471. ``type`` refers to an output stream.
  472. * .. _`V4L2-BUF-FLAG-PREPARED`:
  473. - ``V4L2_BUF_FLAG_PREPARED``
  474. - 0x00000400
  475. - The buffer has been prepared for I/O and can be queued by the
  476. application. Drivers set or clear this flag when the
  477. :ref:`VIDIOC_QUERYBUF <VIDIOC_QUERYBUF>`,
  478. :ref:`VIDIOC_PREPARE_BUF <VIDIOC_QBUF>`,
  479. :ref:`VIDIOC_QBUF <VIDIOC_QBUF>` or
  480. :ref:`VIDIOC_DQBUF <VIDIOC_QBUF>` ioctl is called.
  481. * .. _`V4L2-BUF-FLAG-NO-CACHE-INVALIDATE`:
  482. - ``V4L2_BUF_FLAG_NO_CACHE_INVALIDATE``
  483. - 0x00000800
  484. - Caches do not have to be invalidated for this buffer. Typically
  485. applications shall use this flag if the data captured in the
  486. buffer is not going to be touched by the CPU, instead the buffer
  487. will, probably, be passed on to a DMA-capable hardware unit for
  488. further processing or output. This flag is ignored unless the
  489. queue is used for :ref:`memory mapping <mmap>` streaming I/O and
  490. reports :ref:`V4L2_BUF_CAP_SUPPORTS_MMAP_CACHE_HINTS
  491. <V4L2-BUF-CAP-SUPPORTS-MMAP-CACHE-HINTS>` capability.
  492. * .. _`V4L2-BUF-FLAG-NO-CACHE-CLEAN`:
  493. - ``V4L2_BUF_FLAG_NO_CACHE_CLEAN``
  494. - 0x00001000
  495. - Caches do not have to be cleaned for this buffer. Typically
  496. applications shall use this flag for output buffers if the data in
  497. this buffer has not been created by the CPU but by some
  498. DMA-capable unit, in which case caches have not been used. This flag
  499. is ignored unless the queue is used for :ref:`memory mapping <mmap>`
  500. streaming I/O and reports :ref:`V4L2_BUF_CAP_SUPPORTS_MMAP_CACHE_HINTS
  501. <V4L2-BUF-CAP-SUPPORTS-MMAP-CACHE-HINTS>` capability.
  502. * .. _`V4L2-BUF-FLAG-M2M-HOLD-CAPTURE-BUF`:
  503. - ``V4L2_BUF_FLAG_M2M_HOLD_CAPTURE_BUF``
  504. - 0x00000200
  505. - Only valid if struct :c:type:`v4l2_requestbuffers` flag ``V4L2_BUF_CAP_SUPPORTS_M2M_HOLD_CAPTURE_BUF`` is
  506. set. It is typically used with stateless decoders where multiple
  507. output buffers each decode to a slice of the decoded frame.
  508. Applications can set this flag when queueing the output buffer
  509. to prevent the driver from dequeueing the capture buffer after
  510. the output buffer has been decoded (i.e. the capture buffer is
  511. 'held'). If the timestamp of this output buffer differs from that
  512. of the previous output buffer, then that indicates the start of a
  513. new frame and the previously held capture buffer is dequeued.
  514. * .. _`V4L2-BUF-FLAG-LAST`:
  515. - ``V4L2_BUF_FLAG_LAST``
  516. - 0x00100000
  517. - Last buffer produced by the hardware. mem2mem codec drivers set
  518. this flag on the capture queue for the last buffer when the
  519. :ref:`VIDIOC_QUERYBUF` or
  520. :ref:`VIDIOC_DQBUF <VIDIOC_QBUF>` ioctl is called. Due to
  521. hardware limitations, the last buffer may be empty. In this case
  522. the driver will set the ``bytesused`` field to 0, regardless of
  523. the format. Any subsequent call to the
  524. :ref:`VIDIOC_DQBUF <VIDIOC_QBUF>` ioctl will not block anymore,
  525. but return an ``EPIPE`` error code.
  526. * .. _`V4L2-BUF-FLAG-REQUEST-FD`:
  527. - ``V4L2_BUF_FLAG_REQUEST_FD``
  528. - 0x00800000
  529. - The ``request_fd`` field contains a valid file descriptor.
  530. * .. _`V4L2-BUF-FLAG-TIMESTAMP-MASK`:
  531. - ``V4L2_BUF_FLAG_TIMESTAMP_MASK``
  532. - 0x0000e000
  533. - Mask for timestamp types below. To test the timestamp type, mask
  534. out bits not belonging to timestamp type by performing a logical
  535. and operation with buffer flags and timestamp mask.
  536. * .. _`V4L2-BUF-FLAG-TIMESTAMP-UNKNOWN`:
  537. - ``V4L2_BUF_FLAG_TIMESTAMP_UNKNOWN``
  538. - 0x00000000
  539. - Unknown timestamp type. This type is used by drivers before Linux
  540. 3.9 and may be either monotonic (see below) or realtime (wall
  541. clock). Monotonic clock has been favoured in embedded systems
  542. whereas most of the drivers use the realtime clock. Either kinds
  543. of timestamps are available in user space via
  544. :c:func:`clock_gettime` using clock IDs ``CLOCK_MONOTONIC``
  545. and ``CLOCK_REALTIME``, respectively.
  546. * .. _`V4L2-BUF-FLAG-TIMESTAMP-MONOTONIC`:
  547. - ``V4L2_BUF_FLAG_TIMESTAMP_MONOTONIC``
  548. - 0x00002000
  549. - The buffer timestamp has been taken from the ``CLOCK_MONOTONIC``
  550. clock. To access the same clock outside V4L2, use
  551. :c:func:`clock_gettime`.
  552. * .. _`V4L2-BUF-FLAG-TIMESTAMP-COPY`:
  553. - ``V4L2_BUF_FLAG_TIMESTAMP_COPY``
  554. - 0x00004000
  555. - The CAPTURE buffer timestamp has been taken from the corresponding
  556. OUTPUT buffer. This flag applies only to mem2mem devices.
  557. * .. _`V4L2-BUF-FLAG-TSTAMP-SRC-MASK`:
  558. - ``V4L2_BUF_FLAG_TSTAMP_SRC_MASK``
  559. - 0x00070000
  560. - Mask for timestamp sources below. The timestamp source defines the
  561. point of time the timestamp is taken in relation to the frame.
  562. Logical 'and' operation between the ``flags`` field and
  563. ``V4L2_BUF_FLAG_TSTAMP_SRC_MASK`` produces the value of the
  564. timestamp source. Applications must set the timestamp source when
  565. ``type`` refers to an output stream and
  566. ``V4L2_BUF_FLAG_TIMESTAMP_COPY`` is set.
  567. * .. _`V4L2-BUF-FLAG-TSTAMP-SRC-EOF`:
  568. - ``V4L2_BUF_FLAG_TSTAMP_SRC_EOF``
  569. - 0x00000000
  570. - End Of Frame. The buffer timestamp has been taken when the last
  571. pixel of the frame has been received or the last pixel of the
  572. frame has been transmitted. In practice, software generated
  573. timestamps will typically be read from the clock a small amount of
  574. time after the last pixel has been received or transmitten,
  575. depending on the system and other activity in it.
  576. * .. _`V4L2-BUF-FLAG-TSTAMP-SRC-SOE`:
  577. - ``V4L2_BUF_FLAG_TSTAMP_SRC_SOE``
  578. - 0x00010000
  579. - Start Of Exposure. The buffer timestamp has been taken when the
  580. exposure of the frame has begun. This is only valid for the
  581. ``V4L2_BUF_TYPE_VIDEO_CAPTURE`` buffer type.
  582. .. c:enum:: v4l2_memory
  583. .. raw:: latex
  584. \normalsize
  585. enum v4l2_memory
  586. ================
  587. .. tabularcolumns:: |p{5.0cm}|p{0.8cm}|p{11.5cm}|
  588. .. flat-table::
  589. :header-rows: 0
  590. :stub-columns: 0
  591. :widths: 3 1 4
  592. * - ``V4L2_MEMORY_MMAP``
  593. - 1
  594. - The buffer is used for :ref:`memory mapping <mmap>` I/O.
  595. * - ``V4L2_MEMORY_USERPTR``
  596. - 2
  597. - The buffer is used for :ref:`user pointer <userp>` I/O.
  598. * - ``V4L2_MEMORY_OVERLAY``
  599. - 3
  600. - [to do]
  601. * - ``V4L2_MEMORY_DMABUF``
  602. - 4
  603. - The buffer is used for :ref:`DMA shared buffer <dmabuf>` I/O.
  604. .. raw:: latex
  605. \normalsize
  606. Timecodes
  607. =========
  608. The :c:type:`v4l2_buffer_timecode` structure is designed to hold a
  609. :ref:`smpte12m` or similar timecode.
  610. (struct :c:type:`timeval` timestamps are stored in the struct
  611. :c:type:`v4l2_buffer` ``timestamp`` field.)
  612. .. c:type:: v4l2_timecode
  613. struct v4l2_timecode
  614. --------------------
  615. .. tabularcolumns:: |p{1.4cm}|p{2.8cm}|p{13.1cm}|
  616. .. flat-table::
  617. :header-rows: 0
  618. :stub-columns: 0
  619. :widths: 1 1 2
  620. * - __u32
  621. - ``type``
  622. - Frame rate the timecodes are based on, see :ref:`timecode-type`.
  623. * - __u32
  624. - ``flags``
  625. - Timecode flags, see :ref:`timecode-flags`.
  626. * - __u8
  627. - ``frames``
  628. - Frame count, 0 ... 23/24/29/49/59, depending on the type of
  629. timecode.
  630. * - __u8
  631. - ``seconds``
  632. - Seconds count, 0 ... 59. This is a binary, not BCD number.
  633. * - __u8
  634. - ``minutes``
  635. - Minutes count, 0 ... 59. This is a binary, not BCD number.
  636. * - __u8
  637. - ``hours``
  638. - Hours count, 0 ... 29. This is a binary, not BCD number.
  639. * - __u8
  640. - ``userbits``\ [4]
  641. - The "user group" bits from the timecode.
  642. .. _timecode-type:
  643. Timecode Types
  644. --------------
  645. .. flat-table::
  646. :header-rows: 0
  647. :stub-columns: 0
  648. :widths: 3 1 4
  649. * - ``V4L2_TC_TYPE_24FPS``
  650. - 1
  651. - 24 frames per second, i. e. film.
  652. * - ``V4L2_TC_TYPE_25FPS``
  653. - 2
  654. - 25 frames per second, i. e. PAL or SECAM video.
  655. * - ``V4L2_TC_TYPE_30FPS``
  656. - 3
  657. - 30 frames per second, i. e. NTSC video.
  658. * - ``V4L2_TC_TYPE_50FPS``
  659. - 4
  660. -
  661. * - ``V4L2_TC_TYPE_60FPS``
  662. - 5
  663. -
  664. .. _timecode-flags:
  665. Timecode Flags
  666. --------------
  667. .. tabularcolumns:: |p{6.6cm}|p{1.4cm}|p{9.3cm}|
  668. .. flat-table::
  669. :header-rows: 0
  670. :stub-columns: 0
  671. :widths: 3 1 4
  672. * - ``V4L2_TC_FLAG_DROPFRAME``
  673. - 0x0001
  674. - Indicates "drop frame" semantics for counting frames in 29.97 fps
  675. material. When set, frame numbers 0 and 1 at the start of each
  676. minute, except minutes 0, 10, 20, 30, 40, 50 are omitted from the
  677. count.
  678. * - ``V4L2_TC_FLAG_COLORFRAME``
  679. - 0x0002
  680. - The "color frame" flag.
  681. * - ``V4L2_TC_USERBITS_field``
  682. - 0x000C
  683. - Field mask for the "binary group flags".
  684. * - ``V4L2_TC_USERBITS_USERDEFINED``
  685. - 0x0000
  686. - Unspecified format.
  687. * - ``V4L2_TC_USERBITS_8BITCHARS``
  688. - 0x0008
  689. - 8-bit ISO characters.