1 .. -*- coding: utf-8; mode: rst -*-
9 A buffer contains data exchanged by application and driver using one of
10 the Streaming I/O methods. In the multi-planar API, the data is held in
11 planes, while the buffer structure acts as a container for the planes.
12 Only pointers to buffers (planes) are exchanged, the data itself is not
13 copied. These pointers, together with meta-information like timestamps
14 or field parity, are stored in a struct :c:type:`v4l2_buffer`,
15 argument to the :ref:`VIDIOC_QUERYBUF`,
16 :ref:`VIDIOC_QBUF` and
17 :ref:`VIDIOC_DQBUF <VIDIOC_QBUF>` ioctl. In the multi-planar API,
18 some plane-specific members of struct :c:type:`v4l2_buffer`,
19 such as pointers and sizes for each plane, are stored in struct
20 struct :c:type:`v4l2_plane` instead. In that case, struct
21 struct :c:type:`v4l2_buffer` contains an array of plane structures.
23 Dequeued video buffers come with timestamps. The driver decides at which
24 part of the frame and with which clock the timestamp is taken. Please
25 see flags in the masks ``V4L2_BUF_FLAG_TIMESTAMP_MASK`` and
26 ``V4L2_BUF_FLAG_TSTAMP_SRC_MASK`` in :ref:`buffer-flags`. These flags
27 are always valid and constant across all buffers during the whole video
28 stream. Changes in these flags may take place as a side effect of
29 :ref:`VIDIOC_S_INPUT <VIDIOC_G_INPUT>` or
30 :ref:`VIDIOC_S_OUTPUT <VIDIOC_G_OUTPUT>` however. The
31 ``V4L2_BUF_FLAG_TIMESTAMP_COPY`` timestamp type which is used by e.g. on
32 mem-to-mem devices is an exception to the rule: the timestamp source
33 flags are copied from the OUTPUT video buffer to the CAPTURE video
37 .. c:type:: v4l2_buffer
42 .. tabularcolumns:: |p{2.8cm}|p{2.5cm}|p{1.3cm}|p{10.5cm}|
44 .. cssclass:: longtable
46 .. flat-table:: struct v4l2_buffer
59 - Number of the buffer, set by the application except when calling
60 :ref:`VIDIOC_DQBUF <VIDIOC_QBUF>`, then it is set by the
61 driver. This field can range from zero to the number of buffers
62 allocated with the :ref:`VIDIOC_REQBUFS` ioctl
63 (struct :c:type:`v4l2_requestbuffers`
64 ``count``), plus any buffers allocated with
65 :ref:`VIDIOC_CREATE_BUFS` minus one.
74 - Type of the buffer, same as struct
75 :c:type:`v4l2_format` ``type`` or struct
76 :c:type:`v4l2_requestbuffers` ``type``, set
77 by the application. See :ref:`v4l2-buf-type`
86 - The number of bytes occupied by the data in the buffer. It depends
87 on the negotiated data format and may change with each buffer for
88 compressed variable size data like JPEG images. Drivers must set
89 this field when ``type`` refers to a capture stream, applications
90 when it refers to an output stream. If the application sets this
91 to 0 for an output stream, then ``bytesused`` will be set to the
92 size of the buffer (see the ``length`` field of this struct) by
93 the driver. For multiplanar formats this field is ignored and the
94 ``planes`` pointer is used instead.
103 - Flags set by the application or driver, see :ref:`buffer-flags`.
112 - Indicates the field order of the image in the buffer, see
113 :ref:`v4l2-field`. This field is not used when the buffer
114 contains VBI data. Drivers must set it when ``type`` refers to a
115 capture stream, applications when it refers to an output stream.
124 - For capture streams this is time when the first data byte was
125 captured, as returned by the :c:func:`clock_gettime()` function
126 for the relevant clock id; see ``V4L2_BUF_FLAG_TIMESTAMP_*`` in
127 :ref:`buffer-flags`. For output streams the driver stores the
128 time at which the last data byte was actually sent out in the
129 ``timestamp`` field. This permits applications to monitor the
130 drift between the video and system clock. For output streams that
131 use ``V4L2_BUF_FLAG_TIMESTAMP_COPY`` the application has to fill
132 in the timestamp which will be copied by the driver to the capture
137 - struct :c:type:`v4l2_timecode`
142 - When ``type`` is ``V4L2_BUF_TYPE_VIDEO_CAPTURE`` and the
143 ``V4L2_BUF_FLAG_TIMECODE`` flag is set in ``flags``, this
144 structure contains a frame timecode. In
145 :ref:`V4L2_FIELD_ALTERNATE <v4l2-field>` mode the top and
146 bottom field contain the same timecode. Timecodes are intended to
147 help video editing and are typically recorded on video tapes, but
148 also embedded in compressed formats like MPEG. This field is
149 independent of the ``timestamp`` and ``sequence`` fields.
158 - Set by the driver, counting the frames (not fields!) in sequence.
159 This field is set for both input and output devices.
165 In :ref:`V4L2_FIELD_ALTERNATE <v4l2-field>` mode the top and
166 bottom field have the same sequence number. The count starts at
167 zero and includes dropped or repeated frames. A dropped frame was
168 received by an input device but could not be stored due to lack of
169 free buffer space. A repeated frame was displayed again by an
170 output device because the application did not pass new data in
175 This may count the frames received e.g. over USB, without
176 taking into account the frames dropped by the remote hardware due
177 to limited compression throughput or bus bandwidth. These devices
178 identify by not enumerating any video standards, see
189 - This field must be set by applications and/or drivers in
190 accordance with the selected I/O method. See :ref:`v4l2-memory`
205 - For the single-planar API and when ``memory`` is
206 ``V4L2_MEMORY_MMAP`` this is the offset of the buffer from the
207 start of the device memory. The value is returned by the driver
208 and apart of serving as parameter to the
209 :ref:`mmap() <func-mmap>` function not useful for applications.
210 See :ref:`mmap` for details
219 - For the single-planar API and when ``memory`` is
220 ``V4L2_MEMORY_USERPTR`` this is a pointer to the buffer (casted to
221 unsigned long type) in virtual memory, set by the application. See
222 :ref:`userp` for details.
231 - When using the multi-planar API, contains a userspace pointer to
232 an array of struct :c:type:`v4l2_plane`. The size of
233 the array should be put in the ``length`` field of this
234 struct :c:type:`v4l2_buffer` structure.
243 - For the single-plane API and when ``memory`` is
244 ``V4L2_MEMORY_DMABUF`` this is the file descriptor associated with
254 - Size of the buffer (not the payload) in bytes for the
255 single-planar API. This is set by the driver based on the calls to
256 :ref:`VIDIOC_REQBUFS` and/or
257 :ref:`VIDIOC_CREATE_BUFS`. For the
258 multi-planar API the application sets this to the number of
259 elements in the ``planes`` array. The driver will fill in the
260 actual number of valid elements in that array.
269 - A place holder for future extensions. Drivers and applications
279 - A place holder for future extensions. Drivers and applications
284 .. c:type:: v4l2_plane
289 .. tabularcolumns:: |p{3.5cm}|p{3.5cm}|p{3.5cm}|p{7.0cm}|
291 .. cssclass:: longtable
306 - The number of bytes occupied by data in the plane (its payload).
307 Drivers must set this field when ``type`` refers to a capture
308 stream, applications when it refers to an output stream. If the
309 application sets this to 0 for an output stream, then
310 ``bytesused`` will be set to the size of the plane (see the
311 ``length`` field of this struct) by the driver.
315 Note that the actual image data starts at ``data_offset``
325 - Size in bytes of the plane (not its payload). This is set by the
326 driver based on the calls to
327 :ref:`VIDIOC_REQBUFS` and/or
328 :ref:`VIDIOC_CREATE_BUFS`.
346 - When the memory type in the containing struct
347 :c:type:`v4l2_buffer` is ``V4L2_MEMORY_MMAP``, this
348 is the value that should be passed to :ref:`mmap() <func-mmap>`,
349 similar to the ``offset`` field in struct
350 :c:type:`v4l2_buffer`.
359 - When the memory type in the containing struct
360 :c:type:`v4l2_buffer` is ``V4L2_MEMORY_USERPTR``,
361 this is a userspace pointer to the memory allocated for this plane
371 - When the memory type in the containing struct
372 :c:type:`v4l2_buffer` is ``V4L2_MEMORY_DMABUF``,
373 this is a file descriptor associated with a DMABUF buffer, similar
374 to the ``fd`` field in struct :c:type:`v4l2_buffer`.
383 - Offset in bytes to video data in the plane. Drivers must set this
384 field when ``type`` refers to a capture stream, applications when
385 it refers to an output stream.
389 That data_offset is included in ``bytesused``. So the
390 size of the image in the plane is ``bytesused``-``data_offset``
391 at offset ``data_offset`` from the start of the plane.
400 - Reserved for future use. Should be zeroed by drivers and
410 .. cssclass:: longtable
412 .. tabularcolumns:: |p{7.2cm}|p{0.6cm}|p{9.7cm}|
422 - ``V4L2_BUF_TYPE_VIDEO_CAPTURE``
426 - Buffer of a single-planar video capture stream, see
431 - ``V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE``
435 - Buffer of a multi-planar video capture stream, see
440 - ``V4L2_BUF_TYPE_VIDEO_OUTPUT``
444 - Buffer of a single-planar video output stream, see
449 - ``V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE``
453 - Buffer of a multi-planar video output stream, see :ref:`output`.
457 - ``V4L2_BUF_TYPE_VIDEO_OVERLAY``
461 - Buffer for video overlay, see :ref:`overlay`.
465 - ``V4L2_BUF_TYPE_VBI_CAPTURE``
469 - Buffer of a raw VBI capture stream, see :ref:`raw-vbi`.
473 - ``V4L2_BUF_TYPE_VBI_OUTPUT``
477 - Buffer of a raw VBI output stream, see :ref:`raw-vbi`.
481 - ``V4L2_BUF_TYPE_SLICED_VBI_CAPTURE``
485 - Buffer of a sliced VBI capture stream, see :ref:`sliced`.
489 - ``V4L2_BUF_TYPE_SLICED_VBI_OUTPUT``
493 - Buffer of a sliced VBI output stream, see :ref:`sliced`.
497 - ``V4L2_BUF_TYPE_VIDEO_OUTPUT_OVERLAY``
501 - Buffer for video output overlay (OSD), see :ref:`osd`.
505 - ``V4L2_BUF_TYPE_SDR_CAPTURE``
509 - Buffer for Software Defined Radio (SDR) capture stream, see
514 - ``V4L2_BUF_TYPE_SDR_OUTPUT``
518 - Buffer for Software Defined Radio (SDR) output stream, see
528 .. tabularcolumns:: |p{7.0cm}|p{2.2cm}|p{8.3cm}|
530 .. cssclass:: longtable
538 - .. _`V4L2-BUF-FLAG-MAPPED`:
540 - ``V4L2_BUF_FLAG_MAPPED``
544 - The buffer resides in device memory and has been mapped into the
545 application's address space, see :ref:`mmap` for details.
546 Drivers set or clear this flag when the
547 :ref:`VIDIOC_QUERYBUF`,
548 :ref:`VIDIOC_QBUF` or
549 :ref:`VIDIOC_DQBUF <VIDIOC_QBUF>` ioctl is called. Set by the
552 - .. _`V4L2-BUF-FLAG-QUEUED`:
554 - ``V4L2_BUF_FLAG_QUEUED``
558 - Internally drivers maintain two buffer queues, an incoming and
559 outgoing queue. When this flag is set, the buffer is currently on
560 the incoming queue. It automatically moves to the outgoing queue
561 after the buffer has been filled (capture devices) or displayed
562 (output devices). Drivers set or clear this flag when the
563 ``VIDIOC_QUERYBUF`` ioctl is called. After (successful) calling
564 the ``VIDIOC_QBUF``\ ioctl it is always set and after
565 ``VIDIOC_DQBUF`` always cleared.
567 - .. _`V4L2-BUF-FLAG-DONE`:
569 - ``V4L2_BUF_FLAG_DONE``
573 - When this flag is set, the buffer is currently on the outgoing
574 queue, ready to be dequeued from the driver. Drivers set or clear
575 this flag when the ``VIDIOC_QUERYBUF`` ioctl is called. After
576 calling the ``VIDIOC_QBUF`` or ``VIDIOC_DQBUF`` it is always
577 cleared. Of course a buffer cannot be on both queues at the same
578 time, the ``V4L2_BUF_FLAG_QUEUED`` and ``V4L2_BUF_FLAG_DONE`` flag
579 are mutually exclusive. They can be both cleared however, then the
580 buffer is in "dequeued" state, in the application domain so to
583 - .. _`V4L2-BUF-FLAG-ERROR`:
585 - ``V4L2_BUF_FLAG_ERROR``
589 - When this flag is set, the buffer has been dequeued successfully,
590 although the data might have been corrupted. This is recoverable,
591 streaming may continue as normal and the buffer may be reused
592 normally. Drivers set this flag when the ``VIDIOC_DQBUF`` ioctl is
595 - .. _`V4L2-BUF-FLAG-KEYFRAME`:
597 - ``V4L2_BUF_FLAG_KEYFRAME``
601 - Drivers set or clear this flag when calling the ``VIDIOC_DQBUF``
602 ioctl. It may be set by video capture devices when the buffer
603 contains a compressed image which is a key frame (or field), i. e.
604 can be decompressed on its own. Also known as an I-frame.
605 Applications can set this bit when ``type`` refers to an output
608 - .. _`V4L2-BUF-FLAG-PFRAME`:
610 - ``V4L2_BUF_FLAG_PFRAME``
614 - Similar to ``V4L2_BUF_FLAG_KEYFRAME`` this flags predicted frames
615 or fields which contain only differences to a previous key frame.
616 Applications can set this bit when ``type`` refers to an output
619 - .. _`V4L2-BUF-FLAG-BFRAME`:
621 - ``V4L2_BUF_FLAG_BFRAME``
625 - Similar to ``V4L2_BUF_FLAG_KEYFRAME`` this flags a bi-directional
626 predicted frame or field which contains only the differences
627 between the current frame and both the preceding and following key
628 frames to specify its content. Applications can set this bit when
629 ``type`` refers to an output stream.
631 - .. _`V4L2-BUF-FLAG-TIMECODE`:
633 - ``V4L2_BUF_FLAG_TIMECODE``
637 - The ``timecode`` field is valid. Drivers set or clear this flag
638 when the ``VIDIOC_DQBUF`` ioctl is called. Applications can set
639 this bit and the corresponding ``timecode`` structure when
640 ``type`` refers to an output stream.
642 - .. _`V4L2-BUF-FLAG-PREPARED`:
644 - ``V4L2_BUF_FLAG_PREPARED``
648 - The buffer has been prepared for I/O and can be queued by the
649 application. Drivers set or clear this flag when the
650 :ref:`VIDIOC_QUERYBUF`,
651 :ref:`VIDIOC_PREPARE_BUF <VIDIOC_QBUF>`,
652 :ref:`VIDIOC_QBUF` or
653 :ref:`VIDIOC_DQBUF <VIDIOC_QBUF>` ioctl is called.
655 - .. _`V4L2-BUF-FLAG-NO-CACHE-INVALIDATE`:
657 - ``V4L2_BUF_FLAG_NO_CACHE_INVALIDATE``
661 - Caches do not have to be invalidated for this buffer. Typically
662 applications shall use this flag if the data captured in the
663 buffer is not going to be touched by the CPU, instead the buffer
664 will, probably, be passed on to a DMA-capable hardware unit for
665 further processing or output.
667 - .. _`V4L2-BUF-FLAG-NO-CACHE-CLEAN`:
669 - ``V4L2_BUF_FLAG_NO_CACHE_CLEAN``
673 - Caches do not have to be cleaned for this buffer. Typically
674 applications shall use this flag for output buffers if the data in
675 this buffer has not been created by the CPU but by some
676 DMA-capable unit, in which case caches have not been used.
678 - .. _`V4L2-BUF-FLAG-LAST`:
680 - ``V4L2_BUF_FLAG_LAST``
684 - Last buffer produced by the hardware. mem2mem codec drivers set
685 this flag on the capture queue for the last buffer when the
686 :ref:`VIDIOC_QUERYBUF` or
687 :ref:`VIDIOC_DQBUF <VIDIOC_QBUF>` ioctl is called. Due to
688 hardware limitations, the last buffer may be empty. In this case
689 the driver will set the ``bytesused`` field to 0, regardless of
690 the format. Any Any subsequent call to the
691 :ref:`VIDIOC_DQBUF <VIDIOC_QBUF>` ioctl will not block anymore,
692 but return an ``EPIPE`` error code.
694 - .. _`V4L2-BUF-FLAG-TIMESTAMP-MASK`:
696 - ``V4L2_BUF_FLAG_TIMESTAMP_MASK``
700 - Mask for timestamp types below. To test the timestamp type, mask
701 out bits not belonging to timestamp type by performing a logical
702 and operation with buffer flags and timestamp mask.
704 - .. _`V4L2-BUF-FLAG-TIMESTAMP-UNKNOWN`:
706 - ``V4L2_BUF_FLAG_TIMESTAMP_UNKNOWN``
710 - Unknown timestamp type. This type is used by drivers before Linux
711 3.9 and may be either monotonic (see below) or realtime (wall
712 clock). Monotonic clock has been favoured in embedded systems
713 whereas most of the drivers use the realtime clock. Either kinds
714 of timestamps are available in user space via
715 :c:func:`clock_gettime` using clock IDs ``CLOCK_MONOTONIC``
716 and ``CLOCK_REALTIME``, respectively.
718 - .. _`V4L2-BUF-FLAG-TIMESTAMP-MONOTONIC`:
720 - ``V4L2_BUF_FLAG_TIMESTAMP_MONOTONIC``
724 - The buffer timestamp has been taken from the ``CLOCK_MONOTONIC``
725 clock. To access the same clock outside V4L2, use
726 :c:func:`clock_gettime`.
728 - .. _`V4L2-BUF-FLAG-TIMESTAMP-COPY`:
730 - ``V4L2_BUF_FLAG_TIMESTAMP_COPY``
734 - The CAPTURE buffer timestamp has been taken from the corresponding
735 OUTPUT buffer. This flag applies only to mem2mem devices.
737 - .. _`V4L2-BUF-FLAG-TSTAMP-SRC-MASK`:
739 - ``V4L2_BUF_FLAG_TSTAMP_SRC_MASK``
743 - Mask for timestamp sources below. The timestamp source defines the
744 point of time the timestamp is taken in relation to the frame.
745 Logical 'and' operation between the ``flags`` field and
746 ``V4L2_BUF_FLAG_TSTAMP_SRC_MASK`` produces the value of the
747 timestamp source. Applications must set the timestamp source when
748 ``type`` refers to an output stream and
749 ``V4L2_BUF_FLAG_TIMESTAMP_COPY`` is set.
751 - .. _`V4L2-BUF-FLAG-TSTAMP-SRC-EOF`:
753 - ``V4L2_BUF_FLAG_TSTAMP_SRC_EOF``
757 - End Of Frame. The buffer timestamp has been taken when the last
758 pixel of the frame has been received or the last pixel of the
759 frame has been transmitted. In practice, software generated
760 timestamps will typically be read from the clock a small amount of
761 time after the last pixel has been received or transmitten,
762 depending on the system and other activity in it.
764 - .. _`V4L2-BUF-FLAG-TSTAMP-SRC-SOE`:
766 - ``V4L2_BUF_FLAG_TSTAMP_SRC_SOE``
770 - Start Of Exposure. The buffer timestamp has been taken when the
771 exposure of the frame has begun. This is only valid for the
772 ``V4L2_BUF_TYPE_VIDEO_CAPTURE`` buffer type.
781 .. tabularcolumns:: |p{6.6cm}|p{2.2cm}|p{8.7cm}|
791 - ``V4L2_MEMORY_MMAP``
795 - The buffer is used for :ref:`memory mapping <mmap>` I/O.
799 - ``V4L2_MEMORY_USERPTR``
803 - The buffer is used for :ref:`user pointer <userp>` I/O.
807 - ``V4L2_MEMORY_OVERLAY``
815 - ``V4L2_MEMORY_DMABUF``
819 - The buffer is used for :ref:`DMA shared buffer <dmabuf>` I/O.
826 The struct :c:type:`v4l2_timecode` structure is designed to hold a
827 :ref:`smpte12m` or similar timecode. (struct
828 struct :c:type:`timeval` timestamps are stored in struct
829 :c:type:`v4l2_buffer` field ``timestamp``.)
832 .. c:type:: v4l2_timecode
837 .. tabularcolumns:: |p{4.4cm}|p{4.4cm}|p{8.7cm}|
851 - Frame rate the timecodes are based on, see :ref:`timecode-type`.
859 - Timecode flags, see :ref:`timecode-flags`.
867 - Frame count, 0 ... 23/24/29/49/59, depending on the type of
876 - Seconds count, 0 ... 59. This is a binary, not BCD number.
884 - Minutes count, 0 ... 59. This is a binary, not BCD number.
892 - Hours count, 0 ... 29. This is a binary, not BCD number.
900 - The "user group" bits from the timecode.
909 .. tabularcolumns:: |p{6.6cm}|p{2.2cm}|p{8.7cm}|
919 - ``V4L2_TC_TYPE_24FPS``
923 - 24 frames per second, i. e. film.
927 - ``V4L2_TC_TYPE_25FPS``
931 - 25 frames per second, i. e. PAL or SECAM video.
935 - ``V4L2_TC_TYPE_30FPS``
939 - 30 frames per second, i. e. NTSC video.
943 - ``V4L2_TC_TYPE_50FPS``
951 - ``V4L2_TC_TYPE_60FPS``
964 .. tabularcolumns:: |p{6.6cm}|p{1.4cm}|p{9.5cm}|
974 - ``V4L2_TC_FLAG_DROPFRAME``
978 - Indicates "drop frame" semantics for counting frames in 29.97 fps
979 material. When set, frame numbers 0 and 1 at the start of each
980 minute, except minutes 0, 10, 20, 30, 40, 50 are omitted from the
985 - ``V4L2_TC_FLAG_COLORFRAME``
989 - The "color frame" flag.
993 - ``V4L2_TC_USERBITS_field``
997 - Field mask for the "binary group flags".
1001 - ``V4L2_TC_USERBITS_USERDEFINED``
1005 - Unspecified format.
1009 - ``V4L2_TC_USERBITS_8BITCHARS``
1013 - 8-bit ISO characters.