802 lines · plain
1.. SPDX-License-Identifier: GFDL-1.1-no-invariants-or-later2.. c:namespace:: V4L3 4.. _buffer:5 6*******7Buffers8*******9 10A buffer contains data exchanged by application and driver using one of11the Streaming I/O methods. In the multi-planar API, the data is held in12planes, while the buffer structure acts as a container for the planes.13Only pointers to buffers (planes) are exchanged, the data itself is not14copied. These pointers, together with meta-information like timestamps15or field parity, are stored in a struct :c:type:`v4l2_buffer`,16argument to the :ref:`VIDIOC_QUERYBUF`,17:ref:`VIDIOC_QBUF <VIDIOC_QBUF>` and18:ref:`VIDIOC_DQBUF <VIDIOC_QBUF>` ioctl. In the multi-planar API,19some plane-specific members of struct :c:type:`v4l2_buffer`,20such as pointers and sizes for each plane, are stored in21struct :c:type:`v4l2_plane` instead. In that case,22struct :c:type:`v4l2_buffer` contains an array of plane structures.23 24Dequeued video buffers come with timestamps. The driver decides at which25part of the frame and with which clock the timestamp is taken. Please26see flags in the masks ``V4L2_BUF_FLAG_TIMESTAMP_MASK`` and27``V4L2_BUF_FLAG_TSTAMP_SRC_MASK`` in :ref:`buffer-flags`. These flags28are always valid and constant across all buffers during the whole video29stream. Changes in these flags may take place as a side effect of30:ref:`VIDIOC_S_INPUT <VIDIOC_G_INPUT>` or31:ref:`VIDIOC_S_OUTPUT <VIDIOC_G_OUTPUT>` however. The32``V4L2_BUF_FLAG_TIMESTAMP_COPY`` timestamp type which is used by e.g. on33mem-to-mem devices is an exception to the rule: the timestamp source34flags are copied from the OUTPUT video buffer to the CAPTURE video35buffer.36 37Interactions between formats, controls and buffers38==================================================39 40V4L2 exposes parameters that influence the buffer size, or the way data is41laid out in the buffer. Those parameters are exposed through both formats and42controls. One example of such a control is the ``V4L2_CID_ROTATE`` control43that modifies the direction in which pixels are stored in the buffer, as well44as the buffer size when the selected format includes padding at the end of45lines.46 47The set of information needed to interpret the content of a buffer (e.g. the48pixel format, the line stride, the tiling orientation or the rotation) is49collectively referred to in the rest of this section as the buffer layout.50 51Controls that can modify the buffer layout shall set the52``V4L2_CTRL_FLAG_MODIFY_LAYOUT`` flag.53 54Modifying formats or controls that influence the buffer size or layout require55the stream to be stopped. Any attempt at such a modification while the stream56is active shall cause the ioctl setting the format or the control to return57the ``EBUSY`` error code. In that case drivers shall also set the58``V4L2_CTRL_FLAG_GRABBED`` flag when calling59:c:func:`VIDIOC_QUERYCTRL` or :c:func:`VIDIOC_QUERY_EXT_CTRL` for such a60control while the stream is active.61 62.. note::63 64 The :c:func:`VIDIOC_S_SELECTION` ioctl can, depending on the hardware (for65 instance if the device doesn't include a scaler), modify the format in66 addition to the selection rectangle. Similarly, the67 :c:func:`VIDIOC_S_INPUT`, :c:func:`VIDIOC_S_OUTPUT`, :c:func:`VIDIOC_S_STD`68 and :c:func:`VIDIOC_S_DV_TIMINGS` ioctls can also modify the format and69 selection rectangles. When those ioctls result in a buffer size or layout70 change, drivers shall handle that condition as they would handle it in the71 :c:func:`VIDIOC_S_FMT` ioctl in all cases described in this section.72 73Controls that only influence the buffer layout can be modified at any time74when the stream is stopped. As they don't influence the buffer size, no75special handling is needed to synchronize those controls with buffer76allocation and the ``V4L2_CTRL_FLAG_GRABBED`` flag is cleared once the77stream is stopped.78 79Formats and controls that influence the buffer size interact with buffer80allocation. The simplest way to handle this is for drivers to always require81buffers to be reallocated in order to change those formats or controls. In82that case, to perform such changes, userspace applications shall first stop83the video stream with the :c:func:`VIDIOC_STREAMOFF` ioctl if it is running84and free all buffers with the :c:func:`VIDIOC_REQBUFS` ioctl if they are85allocated. After freeing all buffers the ``V4L2_CTRL_FLAG_GRABBED`` flag86for controls is cleared. The format or controls can then be modified, and87buffers shall then be reallocated and the stream restarted. A typical ioctl88sequence is89 90 #. VIDIOC_STREAMOFF91 #. VIDIOC_REQBUFS(0)92 #. VIDIOC_S_EXT_CTRLS93 #. VIDIOC_S_FMT94 #. VIDIOC_REQBUFS(n)95 #. VIDIOC_QBUF96 #. VIDIOC_STREAMON97 98The second :c:func:`VIDIOC_REQBUFS` call will take the new format and control99value into account to compute the buffer size to allocate. Applications can100also retrieve the size by calling the :c:func:`VIDIOC_G_FMT` ioctl if needed.101 102.. note::103 104 The API doesn't mandate the above order for control (3.) and format (4.)105 changes. Format and controls can be set in a different order, or even106 interleaved, depending on the device and use case. For instance some107 controls might behave differently for different pixel formats, in which108 case the format might need to be set first.109 110When reallocation is required, any attempt to modify format or controls that111influences the buffer size while buffers are allocated shall cause the format112or control set ioctl to return the ``EBUSY`` error. Any attempt to queue a113buffer too small for the current format or controls shall cause the114:c:func:`VIDIOC_QBUF` ioctl to return a ``EINVAL`` error.115 116Buffer reallocation is an expensive operation. To avoid that cost, drivers can117(and are encouraged to) allow format or controls that influence the buffer118size to be changed with buffers allocated. In that case, a typical ioctl119sequence to modify format and controls is120 121 #. VIDIOC_STREAMOFF122 #. VIDIOC_S_EXT_CTRLS123 #. VIDIOC_S_FMT124 #. VIDIOC_QBUF125 #. VIDIOC_STREAMON126 127For this sequence to operate correctly, queued buffers need to be large enough128for the new format or controls. Drivers shall return a ``ENOSPC`` error in129response to format change (:c:func:`VIDIOC_S_FMT`) or control changes130(:c:func:`VIDIOC_S_CTRL` or :c:func:`VIDIOC_S_EXT_CTRLS`) if buffers too small131for the new format are currently queued. As a simplification, drivers are132allowed to return a ``EBUSY`` error from these ioctls if any buffer is133currently queued, without checking the queued buffers sizes.134 135Additionally, drivers shall return a ``EINVAL`` error from the136:c:func:`VIDIOC_QBUF` ioctl if the buffer being queued is too small for the137current format or controls. Together, these requirements ensure that queued138buffers will always be large enough for the configured format and controls.139 140Userspace applications can query the buffer size required for a given format141and controls by first setting the desired control values and then trying the142desired format. The :c:func:`VIDIOC_TRY_FMT` ioctl will return the required143buffer size.144 145 #. VIDIOC_S_EXT_CTRLS(x)146 #. VIDIOC_TRY_FMT()147 #. VIDIOC_S_EXT_CTRLS(y)148 #. VIDIOC_TRY_FMT()149 150The :c:func:`VIDIOC_CREATE_BUFS` ioctl can then be used to allocate buffers151based on the queried sizes (for instance by allocating a set of buffers large152enough for all the desired formats and controls, or by allocating separate set153of appropriately sized buffers for each use case).154 155.. c:type:: v4l2_buffer156 157struct v4l2_buffer158==================159 160.. tabularcolumns:: |p{2.9cm}|p{2.4cm}|p{12.0cm}|161 162.. cssclass:: longtable163 164.. flat-table:: struct v4l2_buffer165 :header-rows: 0166 :stub-columns: 0167 :widths: 1 2 10168 169 * - __u32170 - ``index``171 - Number of the buffer, set by the application except when calling172 :ref:`VIDIOC_DQBUF <VIDIOC_QBUF>`, then it is set by the173 driver. This field can range from zero to the number of buffers174 allocated with the :ref:`VIDIOC_REQBUFS` ioctl175 (struct :c:type:`v4l2_requestbuffers`176 ``count``), plus any buffers allocated with177 :ref:`VIDIOC_CREATE_BUFS` minus one.178 * - __u32179 - ``type``180 - Type of the buffer, same as struct181 :c:type:`v4l2_format` ``type`` or struct182 :c:type:`v4l2_requestbuffers` ``type``, set183 by the application. See :c:type:`v4l2_buf_type`184 * - __u32185 - ``bytesused``186 - The number of bytes occupied by the data in the buffer. It depends187 on the negotiated data format and may change with each buffer for188 compressed variable size data like JPEG images. Drivers must set189 this field when ``type`` refers to a capture stream, applications190 when it refers to an output stream. For multiplanar formats this field191 is ignored and the192 ``planes`` pointer is used instead.193 * - __u32194 - ``flags``195 - Flags set by the application or driver, see :ref:`buffer-flags`.196 * - __u32197 - ``field``198 - Indicates the field order of the image in the buffer, see199 :c:type:`v4l2_field`. This field is not used when the buffer200 contains VBI data. Drivers must set it when ``type`` refers to a201 capture stream, applications when it refers to an output stream.202 * - struct timeval203 - ``timestamp``204 - For capture streams this is time when the first data byte was205 captured, as returned by the :c:func:`clock_gettime()` function206 for the relevant clock id; see ``V4L2_BUF_FLAG_TIMESTAMP_*`` in207 :ref:`buffer-flags`. For output streams the driver stores the208 time at which the last data byte was actually sent out in the209 ``timestamp`` field. This permits applications to monitor the210 drift between the video and system clock. For output streams that211 use ``V4L2_BUF_FLAG_TIMESTAMP_COPY`` the application has to fill212 in the timestamp which will be copied by the driver to the capture213 stream.214 * - struct :c:type:`v4l2_timecode`215 - ``timecode``216 - When the ``V4L2_BUF_FLAG_TIMECODE`` flag is set in ``flags``, this217 structure contains a frame timecode. In218 :c:type:`V4L2_FIELD_ALTERNATE <v4l2_field>` mode the top and219 bottom field contain the same timecode. Timecodes are intended to220 help video editing and are typically recorded on video tapes, but221 also embedded in compressed formats like MPEG. This field is222 independent of the ``timestamp`` and ``sequence`` fields.223 * - __u32224 - ``sequence``225 - Set by the driver, counting the frames (not fields!) in sequence.226 This field is set for both input and output devices.227 * - :cspan:`2`228 229 In :c:type:`V4L2_FIELD_ALTERNATE <v4l2_field>` mode the top and230 bottom field have the same sequence number. The count starts at231 zero and includes dropped or repeated frames. A dropped frame was232 received by an input device but could not be stored due to lack of233 free buffer space. A repeated frame was displayed again by an234 output device because the application did not pass new data in235 time.236 237 .. note::238 239 This may count the frames received e.g. over USB, without240 taking into account the frames dropped by the remote hardware due241 to limited compression throughput or bus bandwidth. These devices242 identify by not enumerating any video standards, see243 :ref:`standard`.244 245 * - __u32246 - ``memory``247 - This field must be set by applications and/or drivers in248 accordance with the selected I/O method. See :c:type:`v4l2_memory`249 * - union {250 - ``m``251 * - __u32252 - ``offset``253 - For the single-planar API and when ``memory`` is254 ``V4L2_MEMORY_MMAP`` this is the offset of the buffer from the255 start of the device memory. The value is returned by the driver256 and apart of serving as parameter to the257 :c:func:`mmap()` function not useful for applications.258 See :ref:`mmap` for details259 * - unsigned long260 - ``userptr``261 - For the single-planar API and when ``memory`` is262 ``V4L2_MEMORY_USERPTR`` this is a pointer to the buffer (casted to263 unsigned long type) in virtual memory, set by the application. See264 :ref:`userp` for details.265 * - struct v4l2_plane266 - ``*planes``267 - When using the multi-planar API, contains a userspace pointer to268 an array of struct :c:type:`v4l2_plane`. The size of269 the array should be put in the ``length`` field of this270 struct :c:type:`v4l2_buffer` structure.271 * - int272 - ``fd``273 - For the single-plane API and when ``memory`` is274 ``V4L2_MEMORY_DMABUF`` this is the file descriptor associated with275 a DMABUF buffer.276 * - }277 -278 * - __u32279 - ``length``280 - Size of the buffer (not the payload) in bytes for the281 single-planar API. This is set by the driver based on the calls to282 :ref:`VIDIOC_REQBUFS` and/or283 :ref:`VIDIOC_CREATE_BUFS`. For the284 multi-planar API the application sets this to the number of285 elements in the ``planes`` array. The driver will fill in the286 actual number of valid elements in that array.287 * - __u32288 - ``reserved2``289 - A place holder for future extensions. Drivers and applications290 must set this to 0.291 * - __u32292 - ``request_fd``293 - The file descriptor of the request to queue the buffer to. If the flag294 ``V4L2_BUF_FLAG_REQUEST_FD`` is set, then the buffer will be295 queued to this request. If the flag is not set, then this field will296 be ignored.297 298 The ``V4L2_BUF_FLAG_REQUEST_FD`` flag and this field are only used by299 :ref:`ioctl VIDIOC_QBUF <VIDIOC_QBUF>` and ignored by other ioctls that300 take a :c:type:`v4l2_buffer` as argument.301 302 Applications should not set ``V4L2_BUF_FLAG_REQUEST_FD`` for any ioctls303 other than :ref:`VIDIOC_QBUF <VIDIOC_QBUF>`.304 305 If the device does not support requests, then ``EBADR`` will be returned.306 If requests are supported but an invalid request file descriptor is307 given, then ``EINVAL`` will be returned.308 309 310.. c:type:: v4l2_plane311 312struct v4l2_plane313=================314 315.. tabularcolumns:: |p{3.5cm}|p{3.5cm}|p{10.3cm}|316 317.. cssclass:: longtable318 319.. flat-table::320 :header-rows: 0321 :stub-columns: 0322 :widths: 1 1 2323 324 * - __u32325 - ``bytesused``326 - The number of bytes occupied by data in the plane (its payload).327 Drivers must set this field when ``type`` refers to a capture328 stream, applications when it refers to an output stream.329 330 .. note::331 332 Note that the actual image data starts at ``data_offset``333 which may not be 0.334 * - __u32335 - ``length``336 - Size in bytes of the plane (not its payload). This is set by the337 driver based on the calls to338 :ref:`VIDIOC_REQBUFS` and/or339 :ref:`VIDIOC_CREATE_BUFS`.340 * - union {341 - ``m``342 * - __u32343 - ``mem_offset``344 - When the memory type in the containing struct345 :c:type:`v4l2_buffer` is ``V4L2_MEMORY_MMAP``, this346 is the value that should be passed to :c:func:`mmap()`,347 similar to the ``offset`` field in struct348 :c:type:`v4l2_buffer`.349 * - unsigned long350 - ``userptr``351 - When the memory type in the containing struct352 :c:type:`v4l2_buffer` is ``V4L2_MEMORY_USERPTR``,353 this is a userspace pointer to the memory allocated for this plane354 by an application.355 * - int356 - ``fd``357 - When the memory type in the containing struct358 :c:type:`v4l2_buffer` is ``V4L2_MEMORY_DMABUF``,359 this is a file descriptor associated with a DMABUF buffer, similar360 to the ``fd`` field in struct :c:type:`v4l2_buffer`.361 * - }362 -363 * - __u32364 - ``data_offset``365 - Offset in bytes to video data in the plane. Drivers must set this366 field when ``type`` refers to a capture stream, applications when367 it refers to an output stream.368 369 .. note::370 371 That data_offset is included in ``bytesused``. So the372 size of the image in the plane is ``bytesused``-``data_offset``373 at offset ``data_offset`` from the start of the plane.374 * - __u32375 - ``reserved[11]``376 - Reserved for future use. Should be zeroed by drivers and377 applications.378 379 380.. c:type:: v4l2_buf_type381 382enum v4l2_buf_type383==================384 385.. cssclass:: longtable386 387.. tabularcolumns:: |p{7.8cm}|p{0.6cm}|p{8.9cm}|388 389.. flat-table::390 :header-rows: 0391 :stub-columns: 0392 :widths: 4 1 9393 394 * - ``V4L2_BUF_TYPE_VIDEO_CAPTURE``395 - 1396 - Buffer of a single-planar video capture stream, see397 :ref:`capture`.398 * - ``V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE``399 - 9400 - Buffer of a multi-planar video capture stream, see401 :ref:`capture`.402 * - ``V4L2_BUF_TYPE_VIDEO_OUTPUT``403 - 2404 - Buffer of a single-planar video output stream, see405 :ref:`output`.406 * - ``V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE``407 - 10408 - Buffer of a multi-planar video output stream, see :ref:`output`.409 * - ``V4L2_BUF_TYPE_VIDEO_OVERLAY``410 - 3411 - Buffer for video overlay, see :ref:`overlay`.412 * - ``V4L2_BUF_TYPE_VBI_CAPTURE``413 - 4414 - Buffer of a raw VBI capture stream, see :ref:`raw-vbi`.415 * - ``V4L2_BUF_TYPE_VBI_OUTPUT``416 - 5417 - Buffer of a raw VBI output stream, see :ref:`raw-vbi`.418 * - ``V4L2_BUF_TYPE_SLICED_VBI_CAPTURE``419 - 6420 - Buffer of a sliced VBI capture stream, see :ref:`sliced`.421 * - ``V4L2_BUF_TYPE_SLICED_VBI_OUTPUT``422 - 7423 - Buffer of a sliced VBI output stream, see :ref:`sliced`.424 * - ``V4L2_BUF_TYPE_VIDEO_OUTPUT_OVERLAY``425 - 8426 - Buffer for video output overlay (OSD), see :ref:`osd`.427 * - ``V4L2_BUF_TYPE_SDR_CAPTURE``428 - 11429 - Buffer for Software Defined Radio (SDR) capture stream, see430 :ref:`sdr`.431 * - ``V4L2_BUF_TYPE_SDR_OUTPUT``432 - 12433 - Buffer for Software Defined Radio (SDR) output stream, see434 :ref:`sdr`.435 * - ``V4L2_BUF_TYPE_META_CAPTURE``436 - 13437 - Buffer for metadata capture, see :ref:`metadata`.438 * - ``V4L2_BUF_TYPE_META_OUTPUT``439 - 14440 - Buffer for metadata output, see :ref:`metadata`.441 442 443.. _buffer-flags:444 445Buffer Flags446============447 448.. raw:: latex449 450 \footnotesize451 452.. tabularcolumns:: |p{6.5cm}|p{1.8cm}|p{9.0cm}|453 454.. cssclass:: longtable455 456.. flat-table::457 :header-rows: 0458 :stub-columns: 0459 :widths: 65 18 70460 461 * .. _`V4L2-BUF-FLAG-MAPPED`:462 463 - ``V4L2_BUF_FLAG_MAPPED``464 - 0x00000001465 - The buffer resides in device memory and has been mapped into the466 application's address space, see :ref:`mmap` for details.467 Drivers set or clear this flag when the468 :ref:`VIDIOC_QUERYBUF`,469 :ref:`VIDIOC_QBUF` or470 :ref:`VIDIOC_DQBUF <VIDIOC_QBUF>` ioctl is called. Set by the471 driver.472 * .. _`V4L2-BUF-FLAG-QUEUED`:473 474 - ``V4L2_BUF_FLAG_QUEUED``475 - 0x00000002476 - Internally drivers maintain two buffer queues, an incoming and477 outgoing queue. When this flag is set, the buffer is currently on478 the incoming queue. It automatically moves to the outgoing queue479 after the buffer has been filled (capture devices) or displayed480 (output devices). Drivers set or clear this flag when the481 ``VIDIOC_QUERYBUF`` ioctl is called. After (successful) calling482 the ``VIDIOC_QBUF``\ ioctl it is always set and after483 ``VIDIOC_DQBUF`` always cleared.484 * .. _`V4L2-BUF-FLAG-DONE`:485 486 - ``V4L2_BUF_FLAG_DONE``487 - 0x00000004488 - When this flag is set, the buffer is currently on the outgoing489 queue, ready to be dequeued from the driver. Drivers set or clear490 this flag when the ``VIDIOC_QUERYBUF`` ioctl is called. After491 calling the ``VIDIOC_QBUF`` or ``VIDIOC_DQBUF`` it is always492 cleared. Of course a buffer cannot be on both queues at the same493 time, the ``V4L2_BUF_FLAG_QUEUED`` and ``V4L2_BUF_FLAG_DONE`` flag494 are mutually exclusive. They can be both cleared however, then the495 buffer is in "dequeued" state, in the application domain so to496 say.497 * .. _`V4L2-BUF-FLAG-ERROR`:498 499 - ``V4L2_BUF_FLAG_ERROR``500 - 0x00000040501 - When this flag is set, the buffer has been dequeued successfully,502 although the data might have been corrupted. This is recoverable,503 streaming may continue as normal and the buffer may be reused504 normally. Drivers set this flag when the ``VIDIOC_DQBUF`` ioctl is505 called.506 * .. _`V4L2-BUF-FLAG-IN-REQUEST`:507 508 - ``V4L2_BUF_FLAG_IN_REQUEST``509 - 0x00000080510 - This buffer is part of a request that hasn't been queued yet.511 * .. _`V4L2-BUF-FLAG-KEYFRAME`:512 513 - ``V4L2_BUF_FLAG_KEYFRAME``514 - 0x00000008515 - Drivers set or clear this flag when calling the ``VIDIOC_DQBUF``516 ioctl. It may be set by video capture devices when the buffer517 contains a compressed image which is a key frame (or field), i. e.518 can be decompressed on its own. Also known as an I-frame.519 Applications can set this bit when ``type`` refers to an output520 stream.521 * .. _`V4L2-BUF-FLAG-PFRAME`:522 523 - ``V4L2_BUF_FLAG_PFRAME``524 - 0x00000010525 - Similar to ``V4L2_BUF_FLAG_KEYFRAME`` this flags predicted frames526 or fields which contain only differences to a previous key frame.527 Applications can set this bit when ``type`` refers to an output528 stream.529 * .. _`V4L2-BUF-FLAG-BFRAME`:530 531 - ``V4L2_BUF_FLAG_BFRAME``532 - 0x00000020533 - Similar to ``V4L2_BUF_FLAG_KEYFRAME`` this flags a bi-directional534 predicted frame or field which contains only the differences535 between the current frame and both the preceding and following key536 frames to specify its content. Applications can set this bit when537 ``type`` refers to an output stream.538 * .. _`V4L2-BUF-FLAG-TIMECODE`:539 540 - ``V4L2_BUF_FLAG_TIMECODE``541 - 0x00000100542 - The ``timecode`` field is valid. Drivers set or clear this flag543 when the ``VIDIOC_DQBUF`` ioctl is called. Applications can set544 this bit and the corresponding ``timecode`` structure when545 ``type`` refers to an output stream.546 * .. _`V4L2-BUF-FLAG-PREPARED`:547 548 - ``V4L2_BUF_FLAG_PREPARED``549 - 0x00000400550 - The buffer has been prepared for I/O and can be queued by the551 application. Drivers set or clear this flag when the552 :ref:`VIDIOC_QUERYBUF <VIDIOC_QUERYBUF>`,553 :ref:`VIDIOC_PREPARE_BUF <VIDIOC_QBUF>`,554 :ref:`VIDIOC_QBUF <VIDIOC_QBUF>` or555 :ref:`VIDIOC_DQBUF <VIDIOC_QBUF>` ioctl is called.556 * .. _`V4L2-BUF-FLAG-NO-CACHE-INVALIDATE`:557 558 - ``V4L2_BUF_FLAG_NO_CACHE_INVALIDATE``559 - 0x00000800560 - Caches do not have to be invalidated for this buffer. Typically561 applications shall use this flag if the data captured in the562 buffer is not going to be touched by the CPU, instead the buffer563 will, probably, be passed on to a DMA-capable hardware unit for564 further processing or output. This flag is ignored unless the565 queue is used for :ref:`memory mapping <mmap>` streaming I/O and566 reports :ref:`V4L2_BUF_CAP_SUPPORTS_MMAP_CACHE_HINTS567 <V4L2-BUF-CAP-SUPPORTS-MMAP-CACHE-HINTS>` capability.568 * .. _`V4L2-BUF-FLAG-NO-CACHE-CLEAN`:569 570 - ``V4L2_BUF_FLAG_NO_CACHE_CLEAN``571 - 0x00001000572 - Caches do not have to be cleaned for this buffer. Typically573 applications shall use this flag for output buffers if the data in574 this buffer has not been created by the CPU but by some575 DMA-capable unit, in which case caches have not been used. This flag576 is ignored unless the queue is used for :ref:`memory mapping <mmap>`577 streaming I/O and reports :ref:`V4L2_BUF_CAP_SUPPORTS_MMAP_CACHE_HINTS578 <V4L2-BUF-CAP-SUPPORTS-MMAP-CACHE-HINTS>` capability.579 * .. _`V4L2-BUF-FLAG-M2M-HOLD-CAPTURE-BUF`:580 581 - ``V4L2_BUF_FLAG_M2M_HOLD_CAPTURE_BUF``582 - 0x00000200583 - Only valid if struct :c:type:`v4l2_requestbuffers` flag ``V4L2_BUF_CAP_SUPPORTS_M2M_HOLD_CAPTURE_BUF`` is584 set. It is typically used with stateless decoders where multiple585 output buffers each decode to a slice of the decoded frame.586 Applications can set this flag when queueing the output buffer587 to prevent the driver from dequeueing the capture buffer after588 the output buffer has been decoded (i.e. the capture buffer is589 'held'). If the timestamp of this output buffer differs from that590 of the previous output buffer, then that indicates the start of a591 new frame and the previously held capture buffer is dequeued.592 * .. _`V4L2-BUF-FLAG-LAST`:593 594 - ``V4L2_BUF_FLAG_LAST``595 - 0x00100000596 - Last buffer produced by the hardware. mem2mem codec drivers set597 this flag on the capture queue for the last buffer when the598 :ref:`VIDIOC_QUERYBUF` or599 :ref:`VIDIOC_DQBUF <VIDIOC_QBUF>` ioctl is called. Due to600 hardware limitations, the last buffer may be empty. In this case601 the driver will set the ``bytesused`` field to 0, regardless of602 the format. Any subsequent call to the603 :ref:`VIDIOC_DQBUF <VIDIOC_QBUF>` ioctl will not block anymore,604 but return an ``EPIPE`` error code.605 * .. _`V4L2-BUF-FLAG-REQUEST-FD`:606 607 - ``V4L2_BUF_FLAG_REQUEST_FD``608 - 0x00800000609 - The ``request_fd`` field contains a valid file descriptor.610 * .. _`V4L2-BUF-FLAG-TIMESTAMP-MASK`:611 612 - ``V4L2_BUF_FLAG_TIMESTAMP_MASK``613 - 0x0000e000614 - Mask for timestamp types below. To test the timestamp type, mask615 out bits not belonging to timestamp type by performing a logical616 and operation with buffer flags and timestamp mask.617 * .. _`V4L2-BUF-FLAG-TIMESTAMP-UNKNOWN`:618 619 - ``V4L2_BUF_FLAG_TIMESTAMP_UNKNOWN``620 - 0x00000000621 - Unknown timestamp type. This type is used by drivers before Linux622 3.9 and may be either monotonic (see below) or realtime (wall623 clock). Monotonic clock has been favoured in embedded systems624 whereas most of the drivers use the realtime clock. Either kinds625 of timestamps are available in user space via626 :c:func:`clock_gettime` using clock IDs ``CLOCK_MONOTONIC``627 and ``CLOCK_REALTIME``, respectively.628 * .. _`V4L2-BUF-FLAG-TIMESTAMP-MONOTONIC`:629 630 - ``V4L2_BUF_FLAG_TIMESTAMP_MONOTONIC``631 - 0x00002000632 - The buffer timestamp has been taken from the ``CLOCK_MONOTONIC``633 clock. To access the same clock outside V4L2, use634 :c:func:`clock_gettime`.635 * .. _`V4L2-BUF-FLAG-TIMESTAMP-COPY`:636 637 - ``V4L2_BUF_FLAG_TIMESTAMP_COPY``638 - 0x00004000639 - The CAPTURE buffer timestamp has been taken from the corresponding640 OUTPUT buffer. This flag applies only to mem2mem devices.641 * .. _`V4L2-BUF-FLAG-TSTAMP-SRC-MASK`:642 643 - ``V4L2_BUF_FLAG_TSTAMP_SRC_MASK``644 - 0x00070000645 - Mask for timestamp sources below. The timestamp source defines the646 point of time the timestamp is taken in relation to the frame.647 Logical 'and' operation between the ``flags`` field and648 ``V4L2_BUF_FLAG_TSTAMP_SRC_MASK`` produces the value of the649 timestamp source. Applications must set the timestamp source when650 ``type`` refers to an output stream and651 ``V4L2_BUF_FLAG_TIMESTAMP_COPY`` is set.652 * .. _`V4L2-BUF-FLAG-TSTAMP-SRC-EOF`:653 654 - ``V4L2_BUF_FLAG_TSTAMP_SRC_EOF``655 - 0x00000000656 - End Of Frame. The buffer timestamp has been taken when the last657 pixel of the frame has been received or the last pixel of the658 frame has been transmitted. In practice, software generated659 timestamps will typically be read from the clock a small amount of660 time after the last pixel has been received or transmitten,661 depending on the system and other activity in it.662 * .. _`V4L2-BUF-FLAG-TSTAMP-SRC-SOE`:663 664 - ``V4L2_BUF_FLAG_TSTAMP_SRC_SOE``665 - 0x00010000666 - Start Of Exposure. The buffer timestamp has been taken when the667 exposure of the frame has begun. This is only valid for the668 ``V4L2_BUF_TYPE_VIDEO_CAPTURE`` buffer type.669 670.. raw:: latex671 672 \normalsize673 674enum v4l2_memory675================676 677.. tabularcolumns:: |p{5.0cm}|p{0.8cm}|p{11.5cm}|678 679.. flat-table::680 :header-rows: 0681 :stub-columns: 0682 :widths: 3 1 4683 684 * - ``V4L2_MEMORY_MMAP``685 - 1686 - The buffer is used for :ref:`memory mapping <mmap>` I/O.687 * - ``V4L2_MEMORY_USERPTR``688 - 2689 - The buffer is used for :ref:`user pointer <userp>` I/O.690 * - ``V4L2_MEMORY_OVERLAY``691 - 3692 - [to do]693 * - ``V4L2_MEMORY_DMABUF``694 - 4695 - The buffer is used for :ref:`DMA shared buffer <dmabuf>` I/O.696 697.. raw:: latex698 699 \normalsize700 701Timecodes702=========703 704The :c:type:`v4l2_buffer_timecode` structure is designed to hold a705:ref:`smpte12m` or similar timecode.706(struct :c:type:`timeval` timestamps are stored in the struct707:c:type:`v4l2_buffer` ``timestamp`` field.)708 709.. c:type:: v4l2_timecode710 711struct v4l2_timecode712--------------------713 714.. tabularcolumns:: |p{1.4cm}|p{2.8cm}|p{13.1cm}|715 716.. flat-table::717 :header-rows: 0718 :stub-columns: 0719 :widths: 1 1 2720 721 * - __u32722 - ``type``723 - Frame rate the timecodes are based on, see :ref:`timecode-type`.724 * - __u32725 - ``flags``726 - Timecode flags, see :ref:`timecode-flags`.727 * - __u8728 - ``frames``729 - Frame count, 0 ... 23/24/29/49/59, depending on the type of730 timecode.731 * - __u8732 - ``seconds``733 - Seconds count, 0 ... 59. This is a binary, not BCD number.734 * - __u8735 - ``minutes``736 - Minutes count, 0 ... 59. This is a binary, not BCD number.737 * - __u8738 - ``hours``739 - Hours count, 0 ... 29. This is a binary, not BCD number.740 * - __u8741 - ``userbits``\ [4]742 - The "user group" bits from the timecode.743 744 745.. _timecode-type:746 747Timecode Types748--------------749 750.. flat-table::751 :header-rows: 0752 :stub-columns: 0753 :widths: 3 1 4754 755 * - ``V4L2_TC_TYPE_24FPS``756 - 1757 - 24 frames per second, i. e. film.758 * - ``V4L2_TC_TYPE_25FPS``759 - 2760 - 25 frames per second, i. e. PAL or SECAM video.761 * - ``V4L2_TC_TYPE_30FPS``762 - 3763 - 30 frames per second, i. e. NTSC video.764 * - ``V4L2_TC_TYPE_50FPS``765 - 4766 -767 * - ``V4L2_TC_TYPE_60FPS``768 - 5769 -770 771 772.. _timecode-flags:773 774Timecode Flags775--------------776 777.. tabularcolumns:: |p{6.6cm}|p{1.4cm}|p{9.3cm}|778 779.. flat-table::780 :header-rows: 0781 :stub-columns: 0782 :widths: 3 1 4783 784 * - ``V4L2_TC_FLAG_DROPFRAME``785 - 0x0001786 - Indicates "drop frame" semantics for counting frames in 29.97 fps787 material. When set, frame numbers 0 and 1 at the start of each788 minute, except minutes 0, 10, 20, 30, 40, 50 are omitted from the789 count.790 * - ``V4L2_TC_FLAG_COLORFRAME``791 - 0x0002792 - The "color frame" flag.793 * - ``V4L2_TC_USERBITS_field``794 - 0x000C795 - Field mask for the "binary group flags".796 * - ``V4L2_TC_USERBITS_USERDEFINED``797 - 0x0000798 - Unspecified format.799 * - ``V4L2_TC_USERBITS_8BITCHARS``800 - 0x0008801 - 8-bit ISO characters.802