162306a36Sopenharmony_ci.. SPDX-License-Identifier: GFDL-1.1-no-invariants-or-later
262306a36Sopenharmony_ci.. c:namespace:: V4L
362306a36Sopenharmony_ci
462306a36Sopenharmony_ci.. _buffer:
562306a36Sopenharmony_ci
662306a36Sopenharmony_ci*******
762306a36Sopenharmony_ciBuffers
862306a36Sopenharmony_ci*******
962306a36Sopenharmony_ci
1062306a36Sopenharmony_ciA buffer contains data exchanged by application and driver using one of
1162306a36Sopenharmony_cithe Streaming I/O methods. In the multi-planar API, the data is held in
1262306a36Sopenharmony_ciplanes, while the buffer structure acts as a container for the planes.
1362306a36Sopenharmony_ciOnly pointers to buffers (planes) are exchanged, the data itself is not
1462306a36Sopenharmony_cicopied. These pointers, together with meta-information like timestamps
1562306a36Sopenharmony_cior field parity, are stored in a struct :c:type:`v4l2_buffer`,
1662306a36Sopenharmony_ciargument to the :ref:`VIDIOC_QUERYBUF`,
1762306a36Sopenharmony_ci:ref:`VIDIOC_QBUF <VIDIOC_QBUF>` and
1862306a36Sopenharmony_ci:ref:`VIDIOC_DQBUF <VIDIOC_QBUF>` ioctl. In the multi-planar API,
1962306a36Sopenharmony_cisome plane-specific members of struct :c:type:`v4l2_buffer`,
2062306a36Sopenharmony_cisuch as pointers and sizes for each plane, are stored in
2162306a36Sopenharmony_cistruct :c:type:`v4l2_plane` instead. In that case,
2262306a36Sopenharmony_cistruct :c:type:`v4l2_buffer` contains an array of plane structures.
2362306a36Sopenharmony_ci
2462306a36Sopenharmony_ciDequeued video buffers come with timestamps. The driver decides at which
2562306a36Sopenharmony_cipart of the frame and with which clock the timestamp is taken. Please
2662306a36Sopenharmony_cisee flags in the masks ``V4L2_BUF_FLAG_TIMESTAMP_MASK`` and
2762306a36Sopenharmony_ci``V4L2_BUF_FLAG_TSTAMP_SRC_MASK`` in :ref:`buffer-flags`. These flags
2862306a36Sopenharmony_ciare always valid and constant across all buffers during the whole video
2962306a36Sopenharmony_cistream. Changes in these flags may take place as a side effect of
3062306a36Sopenharmony_ci:ref:`VIDIOC_S_INPUT <VIDIOC_G_INPUT>` or
3162306a36Sopenharmony_ci:ref:`VIDIOC_S_OUTPUT <VIDIOC_G_OUTPUT>` however. The
3262306a36Sopenharmony_ci``V4L2_BUF_FLAG_TIMESTAMP_COPY`` timestamp type which is used by e.g. on
3362306a36Sopenharmony_cimem-to-mem devices is an exception to the rule: the timestamp source
3462306a36Sopenharmony_ciflags are copied from the OUTPUT video buffer to the CAPTURE video
3562306a36Sopenharmony_cibuffer.
3662306a36Sopenharmony_ci
3762306a36Sopenharmony_ciInteractions between formats, controls and buffers
3862306a36Sopenharmony_ci==================================================
3962306a36Sopenharmony_ci
4062306a36Sopenharmony_ciV4L2 exposes parameters that influence the buffer size, or the way data is
4162306a36Sopenharmony_cilaid out in the buffer. Those parameters are exposed through both formats and
4262306a36Sopenharmony_cicontrols. One example of such a control is the ``V4L2_CID_ROTATE`` control
4362306a36Sopenharmony_cithat modifies the direction in which pixels are stored in the buffer, as well
4462306a36Sopenharmony_cias the buffer size when the selected format includes padding at the end of
4562306a36Sopenharmony_cilines.
4662306a36Sopenharmony_ci
4762306a36Sopenharmony_ciThe set of information needed to interpret the content of a buffer (e.g. the
4862306a36Sopenharmony_cipixel format, the line stride, the tiling orientation or the rotation) is
4962306a36Sopenharmony_cicollectively referred to in the rest of this section as the buffer layout.
5062306a36Sopenharmony_ci
5162306a36Sopenharmony_ciControls that can modify the buffer layout shall set the
5262306a36Sopenharmony_ci``V4L2_CTRL_FLAG_MODIFY_LAYOUT`` flag.
5362306a36Sopenharmony_ci
5462306a36Sopenharmony_ciModifying formats or controls that influence the buffer size or layout require
5562306a36Sopenharmony_cithe stream to be stopped. Any attempt at such a modification while the stream
5662306a36Sopenharmony_ciis active shall cause the ioctl setting the format or the control to return
5762306a36Sopenharmony_cithe ``EBUSY`` error code. In that case drivers shall also set the
5862306a36Sopenharmony_ci``V4L2_CTRL_FLAG_GRABBED`` flag when calling
5962306a36Sopenharmony_ci:c:func:`VIDIOC_QUERYCTRL` or :c:func:`VIDIOC_QUERY_EXT_CTRL` for such a
6062306a36Sopenharmony_cicontrol while the stream is active.
6162306a36Sopenharmony_ci
6262306a36Sopenharmony_ci.. note::
6362306a36Sopenharmony_ci
6462306a36Sopenharmony_ci   The :c:func:`VIDIOC_S_SELECTION` ioctl can, depending on the hardware (for
6562306a36Sopenharmony_ci   instance if the device doesn't include a scaler), modify the format in
6662306a36Sopenharmony_ci   addition to the selection rectangle. Similarly, the
6762306a36Sopenharmony_ci   :c:func:`VIDIOC_S_INPUT`, :c:func:`VIDIOC_S_OUTPUT`, :c:func:`VIDIOC_S_STD`
6862306a36Sopenharmony_ci   and :c:func:`VIDIOC_S_DV_TIMINGS` ioctls can also modify the format and
6962306a36Sopenharmony_ci   selection rectangles. When those ioctls result in a buffer size or layout
7062306a36Sopenharmony_ci   change, drivers shall handle that condition as they would handle it in the
7162306a36Sopenharmony_ci   :c:func:`VIDIOC_S_FMT` ioctl in all cases described in this section.
7262306a36Sopenharmony_ci
7362306a36Sopenharmony_ciControls that only influence the buffer layout can be modified at any time
7462306a36Sopenharmony_ciwhen the stream is stopped. As they don't influence the buffer size, no
7562306a36Sopenharmony_cispecial handling is needed to synchronize those controls with buffer
7662306a36Sopenharmony_ciallocation and the ``V4L2_CTRL_FLAG_GRABBED`` flag is cleared once the
7762306a36Sopenharmony_cistream is stopped.
7862306a36Sopenharmony_ci
7962306a36Sopenharmony_ciFormats and controls that influence the buffer size interact with buffer
8062306a36Sopenharmony_ciallocation. The simplest way to handle this is for drivers to always require
8162306a36Sopenharmony_cibuffers to be reallocated in order to change those formats or controls. In
8262306a36Sopenharmony_cithat case, to perform such changes, userspace applications shall first stop
8362306a36Sopenharmony_cithe video stream with the :c:func:`VIDIOC_STREAMOFF` ioctl if it is running
8462306a36Sopenharmony_ciand free all buffers with the :c:func:`VIDIOC_REQBUFS` ioctl if they are
8562306a36Sopenharmony_ciallocated. After freeing all buffers the ``V4L2_CTRL_FLAG_GRABBED`` flag
8662306a36Sopenharmony_cifor controls is cleared. The format or controls can then be modified, and
8762306a36Sopenharmony_cibuffers shall then be reallocated and the stream restarted. A typical ioctl
8862306a36Sopenharmony_cisequence is
8962306a36Sopenharmony_ci
9062306a36Sopenharmony_ci #. VIDIOC_STREAMOFF
9162306a36Sopenharmony_ci #. VIDIOC_REQBUFS(0)
9262306a36Sopenharmony_ci #. VIDIOC_S_EXT_CTRLS
9362306a36Sopenharmony_ci #. VIDIOC_S_FMT
9462306a36Sopenharmony_ci #. VIDIOC_REQBUFS(n)
9562306a36Sopenharmony_ci #. VIDIOC_QBUF
9662306a36Sopenharmony_ci #. VIDIOC_STREAMON
9762306a36Sopenharmony_ci
9862306a36Sopenharmony_ciThe second :c:func:`VIDIOC_REQBUFS` call will take the new format and control
9962306a36Sopenharmony_civalue into account to compute the buffer size to allocate. Applications can
10062306a36Sopenharmony_cialso retrieve the size by calling the :c:func:`VIDIOC_G_FMT` ioctl if needed.
10162306a36Sopenharmony_ci
10262306a36Sopenharmony_ci.. note::
10362306a36Sopenharmony_ci
10462306a36Sopenharmony_ci   The API doesn't mandate the above order for control (3.) and format (4.)
10562306a36Sopenharmony_ci   changes. Format and controls can be set in a different order, or even
10662306a36Sopenharmony_ci   interleaved, depending on the device and use case. For instance some
10762306a36Sopenharmony_ci   controls might behave differently for different pixel formats, in which
10862306a36Sopenharmony_ci   case the format might need to be set first.
10962306a36Sopenharmony_ci
11062306a36Sopenharmony_ciWhen reallocation is required, any attempt to modify format or controls that
11162306a36Sopenharmony_ciinfluences the buffer size while buffers are allocated shall cause the format
11262306a36Sopenharmony_cior control set ioctl to return the ``EBUSY`` error. Any attempt to queue a
11362306a36Sopenharmony_cibuffer too small for the current format or controls shall cause the
11462306a36Sopenharmony_ci:c:func:`VIDIOC_QBUF` ioctl to return a ``EINVAL`` error.
11562306a36Sopenharmony_ci
11662306a36Sopenharmony_ciBuffer reallocation is an expensive operation. To avoid that cost, drivers can
11762306a36Sopenharmony_ci(and are encouraged to) allow format or controls that influence the buffer
11862306a36Sopenharmony_cisize to be changed with buffers allocated. In that case, a typical ioctl
11962306a36Sopenharmony_cisequence to modify format and controls is
12062306a36Sopenharmony_ci
12162306a36Sopenharmony_ci #. VIDIOC_STREAMOFF
12262306a36Sopenharmony_ci #. VIDIOC_S_EXT_CTRLS
12362306a36Sopenharmony_ci #. VIDIOC_S_FMT
12462306a36Sopenharmony_ci #. VIDIOC_QBUF
12562306a36Sopenharmony_ci #. VIDIOC_STREAMON
12662306a36Sopenharmony_ci
12762306a36Sopenharmony_ciFor this sequence to operate correctly, queued buffers need to be large enough
12862306a36Sopenharmony_cifor the new format or controls. Drivers shall return a ``ENOSPC`` error in
12962306a36Sopenharmony_ciresponse to format change (:c:func:`VIDIOC_S_FMT`) or control changes
13062306a36Sopenharmony_ci(:c:func:`VIDIOC_S_CTRL` or :c:func:`VIDIOC_S_EXT_CTRLS`) if buffers too small
13162306a36Sopenharmony_cifor the new format are currently queued. As a simplification, drivers are
13262306a36Sopenharmony_ciallowed to return a ``EBUSY`` error from these ioctls if any buffer is
13362306a36Sopenharmony_cicurrently queued, without checking the queued buffers sizes.
13462306a36Sopenharmony_ci
13562306a36Sopenharmony_ciAdditionally, drivers shall return a ``EINVAL`` error from the
13662306a36Sopenharmony_ci:c:func:`VIDIOC_QBUF` ioctl if the buffer being queued is too small for the
13762306a36Sopenharmony_cicurrent format or controls. Together, these requirements ensure that queued
13862306a36Sopenharmony_cibuffers will always be large enough for the configured format and controls.
13962306a36Sopenharmony_ci
14062306a36Sopenharmony_ciUserspace applications can query the buffer size required for a given format
14162306a36Sopenharmony_ciand controls by first setting the desired control values and then trying the
14262306a36Sopenharmony_cidesired format. The :c:func:`VIDIOC_TRY_FMT` ioctl will return the required
14362306a36Sopenharmony_cibuffer size.
14462306a36Sopenharmony_ci
14562306a36Sopenharmony_ci #. VIDIOC_S_EXT_CTRLS(x)
14662306a36Sopenharmony_ci #. VIDIOC_TRY_FMT()
14762306a36Sopenharmony_ci #. VIDIOC_S_EXT_CTRLS(y)
14862306a36Sopenharmony_ci #. VIDIOC_TRY_FMT()
14962306a36Sopenharmony_ci
15062306a36Sopenharmony_ciThe :c:func:`VIDIOC_CREATE_BUFS` ioctl can then be used to allocate buffers
15162306a36Sopenharmony_cibased on the queried sizes (for instance by allocating a set of buffers large
15262306a36Sopenharmony_cienough for all the desired formats and controls, or by allocating separate set
15362306a36Sopenharmony_ciof appropriately sized buffers for each use case).
15462306a36Sopenharmony_ci
15562306a36Sopenharmony_ci.. c:type:: v4l2_buffer
15662306a36Sopenharmony_ci
15762306a36Sopenharmony_cistruct v4l2_buffer
15862306a36Sopenharmony_ci==================
15962306a36Sopenharmony_ci
16062306a36Sopenharmony_ci.. tabularcolumns:: |p{2.9cm}|p{2.4cm}|p{12.0cm}|
16162306a36Sopenharmony_ci
16262306a36Sopenharmony_ci.. cssclass:: longtable
16362306a36Sopenharmony_ci
16462306a36Sopenharmony_ci.. flat-table:: struct v4l2_buffer
16562306a36Sopenharmony_ci    :header-rows:  0
16662306a36Sopenharmony_ci    :stub-columns: 0
16762306a36Sopenharmony_ci    :widths:       1 2 10
16862306a36Sopenharmony_ci
16962306a36Sopenharmony_ci    * - __u32
17062306a36Sopenharmony_ci      - ``index``
17162306a36Sopenharmony_ci      - Number of the buffer, set by the application except when calling
17262306a36Sopenharmony_ci	:ref:`VIDIOC_DQBUF <VIDIOC_QBUF>`, then it is set by the
17362306a36Sopenharmony_ci	driver. This field can range from zero to the number of buffers
17462306a36Sopenharmony_ci	allocated with the :ref:`VIDIOC_REQBUFS` ioctl
17562306a36Sopenharmony_ci	(struct :c:type:`v4l2_requestbuffers`
17662306a36Sopenharmony_ci	``count``), plus any buffers allocated with
17762306a36Sopenharmony_ci	:ref:`VIDIOC_CREATE_BUFS` minus one.
17862306a36Sopenharmony_ci    * - __u32
17962306a36Sopenharmony_ci      - ``type``
18062306a36Sopenharmony_ci      - Type of the buffer, same as struct
18162306a36Sopenharmony_ci	:c:type:`v4l2_format` ``type`` or struct
18262306a36Sopenharmony_ci	:c:type:`v4l2_requestbuffers` ``type``, set
18362306a36Sopenharmony_ci	by the application. See :c:type:`v4l2_buf_type`
18462306a36Sopenharmony_ci    * - __u32
18562306a36Sopenharmony_ci      - ``bytesused``
18662306a36Sopenharmony_ci      - The number of bytes occupied by the data in the buffer. It depends
18762306a36Sopenharmony_ci	on the negotiated data format and may change with each buffer for
18862306a36Sopenharmony_ci	compressed variable size data like JPEG images. Drivers must set
18962306a36Sopenharmony_ci	this field when ``type`` refers to a capture stream, applications
19062306a36Sopenharmony_ci	when it refers to an output stream. For multiplanar formats this field
19162306a36Sopenharmony_ci        is ignored and the
19262306a36Sopenharmony_ci	``planes`` pointer is used instead.
19362306a36Sopenharmony_ci    * - __u32
19462306a36Sopenharmony_ci      - ``flags``
19562306a36Sopenharmony_ci      - Flags set by the application or driver, see :ref:`buffer-flags`.
19662306a36Sopenharmony_ci    * - __u32
19762306a36Sopenharmony_ci      - ``field``
19862306a36Sopenharmony_ci      - Indicates the field order of the image in the buffer, see
19962306a36Sopenharmony_ci	:c:type:`v4l2_field`. This field is not used when the buffer
20062306a36Sopenharmony_ci	contains VBI data. Drivers must set it when ``type`` refers to a
20162306a36Sopenharmony_ci	capture stream, applications when it refers to an output stream.
20262306a36Sopenharmony_ci    * - struct timeval
20362306a36Sopenharmony_ci      - ``timestamp``
20462306a36Sopenharmony_ci      - For capture streams this is time when the first data byte was
20562306a36Sopenharmony_ci	captured, as returned by the :c:func:`clock_gettime()` function
20662306a36Sopenharmony_ci	for the relevant clock id; see ``V4L2_BUF_FLAG_TIMESTAMP_*`` in
20762306a36Sopenharmony_ci	:ref:`buffer-flags`. For output streams the driver stores the
20862306a36Sopenharmony_ci	time at which the last data byte was actually sent out in the
20962306a36Sopenharmony_ci	``timestamp`` field. This permits applications to monitor the
21062306a36Sopenharmony_ci	drift between the video and system clock. For output streams that
21162306a36Sopenharmony_ci	use ``V4L2_BUF_FLAG_TIMESTAMP_COPY`` the application has to fill
21262306a36Sopenharmony_ci	in the timestamp which will be copied by the driver to the capture
21362306a36Sopenharmony_ci	stream.
21462306a36Sopenharmony_ci    * - struct :c:type:`v4l2_timecode`
21562306a36Sopenharmony_ci      - ``timecode``
21662306a36Sopenharmony_ci      - When the ``V4L2_BUF_FLAG_TIMECODE`` flag is set in ``flags``, this
21762306a36Sopenharmony_ci	structure contains a frame timecode. In
21862306a36Sopenharmony_ci	:c:type:`V4L2_FIELD_ALTERNATE <v4l2_field>` mode the top and
21962306a36Sopenharmony_ci	bottom field contain the same timecode. Timecodes are intended to
22062306a36Sopenharmony_ci	help video editing and are typically recorded on video tapes, but
22162306a36Sopenharmony_ci	also embedded in compressed formats like MPEG. This field is
22262306a36Sopenharmony_ci	independent of the ``timestamp`` and ``sequence`` fields.
22362306a36Sopenharmony_ci    * - __u32
22462306a36Sopenharmony_ci      - ``sequence``
22562306a36Sopenharmony_ci      - Set by the driver, counting the frames (not fields!) in sequence.
22662306a36Sopenharmony_ci	This field is set for both input and output devices.
22762306a36Sopenharmony_ci    * - :cspan:`2`
22862306a36Sopenharmony_ci
22962306a36Sopenharmony_ci	In :c:type:`V4L2_FIELD_ALTERNATE <v4l2_field>` mode the top and
23062306a36Sopenharmony_ci	bottom field have the same sequence number. The count starts at
23162306a36Sopenharmony_ci	zero and includes dropped or repeated frames. A dropped frame was
23262306a36Sopenharmony_ci	received by an input device but could not be stored due to lack of
23362306a36Sopenharmony_ci	free buffer space. A repeated frame was displayed again by an
23462306a36Sopenharmony_ci	output device because the application did not pass new data in
23562306a36Sopenharmony_ci	time.
23662306a36Sopenharmony_ci
23762306a36Sopenharmony_ci	.. note::
23862306a36Sopenharmony_ci
23962306a36Sopenharmony_ci	   This may count the frames received e.g. over USB, without
24062306a36Sopenharmony_ci	   taking into account the frames dropped by the remote hardware due
24162306a36Sopenharmony_ci	   to limited compression throughput or bus bandwidth. These devices
24262306a36Sopenharmony_ci	   identify by not enumerating any video standards, see
24362306a36Sopenharmony_ci	   :ref:`standard`.
24462306a36Sopenharmony_ci
24562306a36Sopenharmony_ci    * - __u32
24662306a36Sopenharmony_ci      - ``memory``
24762306a36Sopenharmony_ci      - This field must be set by applications and/or drivers in
24862306a36Sopenharmony_ci	accordance with the selected I/O method. See :c:type:`v4l2_memory`
24962306a36Sopenharmony_ci    * - union {
25062306a36Sopenharmony_ci      - ``m``
25162306a36Sopenharmony_ci    * - __u32
25262306a36Sopenharmony_ci      - ``offset``
25362306a36Sopenharmony_ci      - For the single-planar API and when ``memory`` is
25462306a36Sopenharmony_ci	``V4L2_MEMORY_MMAP`` this is the offset of the buffer from the
25562306a36Sopenharmony_ci	start of the device memory. The value is returned by the driver
25662306a36Sopenharmony_ci	and apart of serving as parameter to the
25762306a36Sopenharmony_ci	:c:func:`mmap()` function not useful for applications.
25862306a36Sopenharmony_ci	See :ref:`mmap` for details
25962306a36Sopenharmony_ci    * - unsigned long
26062306a36Sopenharmony_ci      - ``userptr``
26162306a36Sopenharmony_ci      - For the single-planar API and when ``memory`` is
26262306a36Sopenharmony_ci	``V4L2_MEMORY_USERPTR`` this is a pointer to the buffer (casted to
26362306a36Sopenharmony_ci	unsigned long type) in virtual memory, set by the application. See
26462306a36Sopenharmony_ci	:ref:`userp` for details.
26562306a36Sopenharmony_ci    * - struct v4l2_plane
26662306a36Sopenharmony_ci      - ``*planes``
26762306a36Sopenharmony_ci      - When using the multi-planar API, contains a userspace pointer to
26862306a36Sopenharmony_ci	an array of struct :c:type:`v4l2_plane`. The size of
26962306a36Sopenharmony_ci	the array should be put in the ``length`` field of this
27062306a36Sopenharmony_ci	struct :c:type:`v4l2_buffer` structure.
27162306a36Sopenharmony_ci    * - int
27262306a36Sopenharmony_ci      - ``fd``
27362306a36Sopenharmony_ci      - For the single-plane API and when ``memory`` is
27462306a36Sopenharmony_ci	``V4L2_MEMORY_DMABUF`` this is the file descriptor associated with
27562306a36Sopenharmony_ci	a DMABUF buffer.
27662306a36Sopenharmony_ci    * - }
27762306a36Sopenharmony_ci      -
27862306a36Sopenharmony_ci    * - __u32
27962306a36Sopenharmony_ci      - ``length``
28062306a36Sopenharmony_ci      - Size of the buffer (not the payload) in bytes for the
28162306a36Sopenharmony_ci	single-planar API. This is set by the driver based on the calls to
28262306a36Sopenharmony_ci	:ref:`VIDIOC_REQBUFS` and/or
28362306a36Sopenharmony_ci	:ref:`VIDIOC_CREATE_BUFS`. For the
28462306a36Sopenharmony_ci	multi-planar API the application sets this to the number of
28562306a36Sopenharmony_ci	elements in the ``planes`` array. The driver will fill in the
28662306a36Sopenharmony_ci	actual number of valid elements in that array.
28762306a36Sopenharmony_ci    * - __u32
28862306a36Sopenharmony_ci      - ``reserved2``
28962306a36Sopenharmony_ci      - A place holder for future extensions. Drivers and applications
29062306a36Sopenharmony_ci	must set this to 0.
29162306a36Sopenharmony_ci    * - __u32
29262306a36Sopenharmony_ci      - ``request_fd``
29362306a36Sopenharmony_ci      - The file descriptor of the request to queue the buffer to. If the flag
29462306a36Sopenharmony_ci        ``V4L2_BUF_FLAG_REQUEST_FD`` is set, then the buffer will be
29562306a36Sopenharmony_ci	queued to this request. If the flag is not set, then this field will
29662306a36Sopenharmony_ci	be ignored.
29762306a36Sopenharmony_ci
29862306a36Sopenharmony_ci	The ``V4L2_BUF_FLAG_REQUEST_FD`` flag and this field are only used by
29962306a36Sopenharmony_ci	:ref:`ioctl VIDIOC_QBUF <VIDIOC_QBUF>` and ignored by other ioctls that
30062306a36Sopenharmony_ci	take a :c:type:`v4l2_buffer` as argument.
30162306a36Sopenharmony_ci
30262306a36Sopenharmony_ci	Applications should not set ``V4L2_BUF_FLAG_REQUEST_FD`` for any ioctls
30362306a36Sopenharmony_ci	other than :ref:`VIDIOC_QBUF <VIDIOC_QBUF>`.
30462306a36Sopenharmony_ci
30562306a36Sopenharmony_ci	If the device does not support requests, then ``EBADR`` will be returned.
30662306a36Sopenharmony_ci	If requests are supported but an invalid request file descriptor is
30762306a36Sopenharmony_ci	given, then ``EINVAL`` will be returned.
30862306a36Sopenharmony_ci
30962306a36Sopenharmony_ci
31062306a36Sopenharmony_ci.. c:type:: v4l2_plane
31162306a36Sopenharmony_ci
31262306a36Sopenharmony_cistruct v4l2_plane
31362306a36Sopenharmony_ci=================
31462306a36Sopenharmony_ci
31562306a36Sopenharmony_ci.. tabularcolumns:: |p{3.5cm}|p{3.5cm}|p{10.3cm}|
31662306a36Sopenharmony_ci
31762306a36Sopenharmony_ci.. cssclass:: longtable
31862306a36Sopenharmony_ci
31962306a36Sopenharmony_ci.. flat-table::
32062306a36Sopenharmony_ci    :header-rows:  0
32162306a36Sopenharmony_ci    :stub-columns: 0
32262306a36Sopenharmony_ci    :widths:       1 1 2
32362306a36Sopenharmony_ci
32462306a36Sopenharmony_ci    * - __u32
32562306a36Sopenharmony_ci      - ``bytesused``
32662306a36Sopenharmony_ci      - The number of bytes occupied by data in the plane (its payload).
32762306a36Sopenharmony_ci	Drivers must set this field when ``type`` refers to a capture
32862306a36Sopenharmony_ci	stream, applications when it refers to an output stream.
32962306a36Sopenharmony_ci
33062306a36Sopenharmony_ci	.. note::
33162306a36Sopenharmony_ci
33262306a36Sopenharmony_ci	   Note that the actual image data starts at ``data_offset``
33362306a36Sopenharmony_ci	   which may not be 0.
33462306a36Sopenharmony_ci    * - __u32
33562306a36Sopenharmony_ci      - ``length``
33662306a36Sopenharmony_ci      - Size in bytes of the plane (not its payload). This is set by the
33762306a36Sopenharmony_ci	driver based on the calls to
33862306a36Sopenharmony_ci	:ref:`VIDIOC_REQBUFS` and/or
33962306a36Sopenharmony_ci	:ref:`VIDIOC_CREATE_BUFS`.
34062306a36Sopenharmony_ci    * - union {
34162306a36Sopenharmony_ci      - ``m``
34262306a36Sopenharmony_ci    * - __u32
34362306a36Sopenharmony_ci      - ``mem_offset``
34462306a36Sopenharmony_ci      - When the memory type in the containing struct
34562306a36Sopenharmony_ci	:c:type:`v4l2_buffer` is ``V4L2_MEMORY_MMAP``, this
34662306a36Sopenharmony_ci	is the value that should be passed to :c:func:`mmap()`,
34762306a36Sopenharmony_ci	similar to the ``offset`` field in struct
34862306a36Sopenharmony_ci	:c:type:`v4l2_buffer`.
34962306a36Sopenharmony_ci    * - unsigned long
35062306a36Sopenharmony_ci      - ``userptr``
35162306a36Sopenharmony_ci      - When the memory type in the containing struct
35262306a36Sopenharmony_ci	:c:type:`v4l2_buffer` is ``V4L2_MEMORY_USERPTR``,
35362306a36Sopenharmony_ci	this is a userspace pointer to the memory allocated for this plane
35462306a36Sopenharmony_ci	by an application.
35562306a36Sopenharmony_ci    * - int
35662306a36Sopenharmony_ci      - ``fd``
35762306a36Sopenharmony_ci      - When the memory type in the containing struct
35862306a36Sopenharmony_ci	:c:type:`v4l2_buffer` is ``V4L2_MEMORY_DMABUF``,
35962306a36Sopenharmony_ci	this is a file descriptor associated with a DMABUF buffer, similar
36062306a36Sopenharmony_ci	to the ``fd`` field in struct :c:type:`v4l2_buffer`.
36162306a36Sopenharmony_ci    * - }
36262306a36Sopenharmony_ci      -
36362306a36Sopenharmony_ci    * - __u32
36462306a36Sopenharmony_ci      - ``data_offset``
36562306a36Sopenharmony_ci      - Offset in bytes to video data in the plane. Drivers must set this
36662306a36Sopenharmony_ci	field when ``type`` refers to a capture stream, applications when
36762306a36Sopenharmony_ci	it refers to an output stream.
36862306a36Sopenharmony_ci
36962306a36Sopenharmony_ci	.. note::
37062306a36Sopenharmony_ci
37162306a36Sopenharmony_ci	   That data_offset is included  in ``bytesused``. So the
37262306a36Sopenharmony_ci	   size of the image in the plane is ``bytesused``-``data_offset``
37362306a36Sopenharmony_ci	   at offset ``data_offset`` from the start of the plane.
37462306a36Sopenharmony_ci    * - __u32
37562306a36Sopenharmony_ci      - ``reserved[11]``
37662306a36Sopenharmony_ci      - Reserved for future use. Should be zeroed by drivers and
37762306a36Sopenharmony_ci	applications.
37862306a36Sopenharmony_ci
37962306a36Sopenharmony_ci
38062306a36Sopenharmony_ci.. c:type:: v4l2_buf_type
38162306a36Sopenharmony_ci
38262306a36Sopenharmony_cienum v4l2_buf_type
38362306a36Sopenharmony_ci==================
38462306a36Sopenharmony_ci
38562306a36Sopenharmony_ci.. cssclass:: longtable
38662306a36Sopenharmony_ci
38762306a36Sopenharmony_ci.. tabularcolumns:: |p{7.8cm}|p{0.6cm}|p{8.9cm}|
38862306a36Sopenharmony_ci
38962306a36Sopenharmony_ci.. flat-table::
39062306a36Sopenharmony_ci    :header-rows:  0
39162306a36Sopenharmony_ci    :stub-columns: 0
39262306a36Sopenharmony_ci    :widths:       4 1 9
39362306a36Sopenharmony_ci
39462306a36Sopenharmony_ci    * - ``V4L2_BUF_TYPE_VIDEO_CAPTURE``
39562306a36Sopenharmony_ci      - 1
39662306a36Sopenharmony_ci      - Buffer of a single-planar video capture stream, see
39762306a36Sopenharmony_ci	:ref:`capture`.
39862306a36Sopenharmony_ci    * - ``V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE``
39962306a36Sopenharmony_ci      - 9
40062306a36Sopenharmony_ci      - Buffer of a multi-planar video capture stream, see
40162306a36Sopenharmony_ci	:ref:`capture`.
40262306a36Sopenharmony_ci    * - ``V4L2_BUF_TYPE_VIDEO_OUTPUT``
40362306a36Sopenharmony_ci      - 2
40462306a36Sopenharmony_ci      - Buffer of a single-planar video output stream, see
40562306a36Sopenharmony_ci	:ref:`output`.
40662306a36Sopenharmony_ci    * - ``V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE``
40762306a36Sopenharmony_ci      - 10
40862306a36Sopenharmony_ci      - Buffer of a multi-planar video output stream, see :ref:`output`.
40962306a36Sopenharmony_ci    * - ``V4L2_BUF_TYPE_VIDEO_OVERLAY``
41062306a36Sopenharmony_ci      - 3
41162306a36Sopenharmony_ci      - Buffer for video overlay, see :ref:`overlay`.
41262306a36Sopenharmony_ci    * - ``V4L2_BUF_TYPE_VBI_CAPTURE``
41362306a36Sopenharmony_ci      - 4
41462306a36Sopenharmony_ci      - Buffer of a raw VBI capture stream, see :ref:`raw-vbi`.
41562306a36Sopenharmony_ci    * - ``V4L2_BUF_TYPE_VBI_OUTPUT``
41662306a36Sopenharmony_ci      - 5
41762306a36Sopenharmony_ci      - Buffer of a raw VBI output stream, see :ref:`raw-vbi`.
41862306a36Sopenharmony_ci    * - ``V4L2_BUF_TYPE_SLICED_VBI_CAPTURE``
41962306a36Sopenharmony_ci      - 6
42062306a36Sopenharmony_ci      - Buffer of a sliced VBI capture stream, see :ref:`sliced`.
42162306a36Sopenharmony_ci    * - ``V4L2_BUF_TYPE_SLICED_VBI_OUTPUT``
42262306a36Sopenharmony_ci      - 7
42362306a36Sopenharmony_ci      - Buffer of a sliced VBI output stream, see :ref:`sliced`.
42462306a36Sopenharmony_ci    * - ``V4L2_BUF_TYPE_VIDEO_OUTPUT_OVERLAY``
42562306a36Sopenharmony_ci      - 8
42662306a36Sopenharmony_ci      - Buffer for video output overlay (OSD), see :ref:`osd`.
42762306a36Sopenharmony_ci    * - ``V4L2_BUF_TYPE_SDR_CAPTURE``
42862306a36Sopenharmony_ci      - 11
42962306a36Sopenharmony_ci      - Buffer for Software Defined Radio (SDR) capture stream, see
43062306a36Sopenharmony_ci	:ref:`sdr`.
43162306a36Sopenharmony_ci    * - ``V4L2_BUF_TYPE_SDR_OUTPUT``
43262306a36Sopenharmony_ci      - 12
43362306a36Sopenharmony_ci      - Buffer for Software Defined Radio (SDR) output stream, see
43462306a36Sopenharmony_ci	:ref:`sdr`.
43562306a36Sopenharmony_ci    * - ``V4L2_BUF_TYPE_META_CAPTURE``
43662306a36Sopenharmony_ci      - 13
43762306a36Sopenharmony_ci      - Buffer for metadata capture, see :ref:`metadata`.
43862306a36Sopenharmony_ci    * - ``V4L2_BUF_TYPE_META_OUTPUT``
43962306a36Sopenharmony_ci      - 14
44062306a36Sopenharmony_ci      - Buffer for metadata output, see :ref:`metadata`.
44162306a36Sopenharmony_ci
44262306a36Sopenharmony_ci
44362306a36Sopenharmony_ci.. _buffer-flags:
44462306a36Sopenharmony_ci
44562306a36Sopenharmony_ciBuffer Flags
44662306a36Sopenharmony_ci============
44762306a36Sopenharmony_ci
44862306a36Sopenharmony_ci.. raw:: latex
44962306a36Sopenharmony_ci
45062306a36Sopenharmony_ci    \footnotesize
45162306a36Sopenharmony_ci
45262306a36Sopenharmony_ci.. tabularcolumns:: |p{6.5cm}|p{1.8cm}|p{9.0cm}|
45362306a36Sopenharmony_ci
45462306a36Sopenharmony_ci.. cssclass:: longtable
45562306a36Sopenharmony_ci
45662306a36Sopenharmony_ci.. flat-table::
45762306a36Sopenharmony_ci    :header-rows:  0
45862306a36Sopenharmony_ci    :stub-columns: 0
45962306a36Sopenharmony_ci    :widths:       65 18 70
46062306a36Sopenharmony_ci
46162306a36Sopenharmony_ci    * .. _`V4L2-BUF-FLAG-MAPPED`:
46262306a36Sopenharmony_ci
46362306a36Sopenharmony_ci      - ``V4L2_BUF_FLAG_MAPPED``
46462306a36Sopenharmony_ci      - 0x00000001
46562306a36Sopenharmony_ci      - The buffer resides in device memory and has been mapped into the
46662306a36Sopenharmony_ci	application's address space, see :ref:`mmap` for details.
46762306a36Sopenharmony_ci	Drivers set or clear this flag when the
46862306a36Sopenharmony_ci	:ref:`VIDIOC_QUERYBUF`,
46962306a36Sopenharmony_ci	:ref:`VIDIOC_QBUF` or
47062306a36Sopenharmony_ci	:ref:`VIDIOC_DQBUF <VIDIOC_QBUF>` ioctl is called. Set by the
47162306a36Sopenharmony_ci	driver.
47262306a36Sopenharmony_ci    * .. _`V4L2-BUF-FLAG-QUEUED`:
47362306a36Sopenharmony_ci
47462306a36Sopenharmony_ci      - ``V4L2_BUF_FLAG_QUEUED``
47562306a36Sopenharmony_ci      - 0x00000002
47662306a36Sopenharmony_ci      - Internally drivers maintain two buffer queues, an incoming and
47762306a36Sopenharmony_ci	outgoing queue. When this flag is set, the buffer is currently on
47862306a36Sopenharmony_ci	the incoming queue. It automatically moves to the outgoing queue
47962306a36Sopenharmony_ci	after the buffer has been filled (capture devices) or displayed
48062306a36Sopenharmony_ci	(output devices). Drivers set or clear this flag when the
48162306a36Sopenharmony_ci	``VIDIOC_QUERYBUF`` ioctl is called. After (successful) calling
48262306a36Sopenharmony_ci	the ``VIDIOC_QBUF``\ ioctl it is always set and after
48362306a36Sopenharmony_ci	``VIDIOC_DQBUF`` always cleared.
48462306a36Sopenharmony_ci    * .. _`V4L2-BUF-FLAG-DONE`:
48562306a36Sopenharmony_ci
48662306a36Sopenharmony_ci      - ``V4L2_BUF_FLAG_DONE``
48762306a36Sopenharmony_ci      - 0x00000004
48862306a36Sopenharmony_ci      - When this flag is set, the buffer is currently on the outgoing
48962306a36Sopenharmony_ci	queue, ready to be dequeued from the driver. Drivers set or clear
49062306a36Sopenharmony_ci	this flag when the ``VIDIOC_QUERYBUF`` ioctl is called. After
49162306a36Sopenharmony_ci	calling the ``VIDIOC_QBUF`` or ``VIDIOC_DQBUF`` it is always
49262306a36Sopenharmony_ci	cleared. Of course a buffer cannot be on both queues at the same
49362306a36Sopenharmony_ci	time, the ``V4L2_BUF_FLAG_QUEUED`` and ``V4L2_BUF_FLAG_DONE`` flag
49462306a36Sopenharmony_ci	are mutually exclusive. They can be both cleared however, then the
49562306a36Sopenharmony_ci	buffer is in "dequeued" state, in the application domain so to
49662306a36Sopenharmony_ci	say.
49762306a36Sopenharmony_ci    * .. _`V4L2-BUF-FLAG-ERROR`:
49862306a36Sopenharmony_ci
49962306a36Sopenharmony_ci      - ``V4L2_BUF_FLAG_ERROR``
50062306a36Sopenharmony_ci      - 0x00000040
50162306a36Sopenharmony_ci      - When this flag is set, the buffer has been dequeued successfully,
50262306a36Sopenharmony_ci	although the data might have been corrupted. This is recoverable,
50362306a36Sopenharmony_ci	streaming may continue as normal and the buffer may be reused
50462306a36Sopenharmony_ci	normally. Drivers set this flag when the ``VIDIOC_DQBUF`` ioctl is
50562306a36Sopenharmony_ci	called.
50662306a36Sopenharmony_ci    * .. _`V4L2-BUF-FLAG-IN-REQUEST`:
50762306a36Sopenharmony_ci
50862306a36Sopenharmony_ci      - ``V4L2_BUF_FLAG_IN_REQUEST``
50962306a36Sopenharmony_ci      - 0x00000080
51062306a36Sopenharmony_ci      - This buffer is part of a request that hasn't been queued yet.
51162306a36Sopenharmony_ci    * .. _`V4L2-BUF-FLAG-KEYFRAME`:
51262306a36Sopenharmony_ci
51362306a36Sopenharmony_ci      - ``V4L2_BUF_FLAG_KEYFRAME``
51462306a36Sopenharmony_ci      - 0x00000008
51562306a36Sopenharmony_ci      - Drivers set or clear this flag when calling the ``VIDIOC_DQBUF``
51662306a36Sopenharmony_ci	ioctl. It may be set by video capture devices when the buffer
51762306a36Sopenharmony_ci	contains a compressed image which is a key frame (or field), i. e.
51862306a36Sopenharmony_ci	can be decompressed on its own. Also known as an I-frame.
51962306a36Sopenharmony_ci	Applications can set this bit when ``type`` refers to an output
52062306a36Sopenharmony_ci	stream.
52162306a36Sopenharmony_ci    * .. _`V4L2-BUF-FLAG-PFRAME`:
52262306a36Sopenharmony_ci
52362306a36Sopenharmony_ci      - ``V4L2_BUF_FLAG_PFRAME``
52462306a36Sopenharmony_ci      - 0x00000010
52562306a36Sopenharmony_ci      - Similar to ``V4L2_BUF_FLAG_KEYFRAME`` this flags predicted frames
52662306a36Sopenharmony_ci	or fields which contain only differences to a previous key frame.
52762306a36Sopenharmony_ci	Applications can set this bit when ``type`` refers to an output
52862306a36Sopenharmony_ci	stream.
52962306a36Sopenharmony_ci    * .. _`V4L2-BUF-FLAG-BFRAME`:
53062306a36Sopenharmony_ci
53162306a36Sopenharmony_ci      - ``V4L2_BUF_FLAG_BFRAME``
53262306a36Sopenharmony_ci      - 0x00000020
53362306a36Sopenharmony_ci      - Similar to ``V4L2_BUF_FLAG_KEYFRAME`` this flags a bi-directional
53462306a36Sopenharmony_ci	predicted frame or field which contains only the differences
53562306a36Sopenharmony_ci	between the current frame and both the preceding and following key
53662306a36Sopenharmony_ci	frames to specify its content. Applications can set this bit when
53762306a36Sopenharmony_ci	``type`` refers to an output stream.
53862306a36Sopenharmony_ci    * .. _`V4L2-BUF-FLAG-TIMECODE`:
53962306a36Sopenharmony_ci
54062306a36Sopenharmony_ci      - ``V4L2_BUF_FLAG_TIMECODE``
54162306a36Sopenharmony_ci      - 0x00000100
54262306a36Sopenharmony_ci      - The ``timecode`` field is valid. Drivers set or clear this flag
54362306a36Sopenharmony_ci	when the ``VIDIOC_DQBUF`` ioctl is called. Applications can set
54462306a36Sopenharmony_ci	this bit and the corresponding ``timecode`` structure when
54562306a36Sopenharmony_ci	``type`` refers to an output stream.
54662306a36Sopenharmony_ci    * .. _`V4L2-BUF-FLAG-PREPARED`:
54762306a36Sopenharmony_ci
54862306a36Sopenharmony_ci      - ``V4L2_BUF_FLAG_PREPARED``
54962306a36Sopenharmony_ci      - 0x00000400
55062306a36Sopenharmony_ci      - The buffer has been prepared for I/O and can be queued by the
55162306a36Sopenharmony_ci	application. Drivers set or clear this flag when the
55262306a36Sopenharmony_ci	:ref:`VIDIOC_QUERYBUF`,
55362306a36Sopenharmony_ci	:ref:`VIDIOC_PREPARE_BUF <VIDIOC_QBUF>`,
55462306a36Sopenharmony_ci	:ref:`VIDIOC_QBUF` or
55562306a36Sopenharmony_ci	:ref:`VIDIOC_DQBUF <VIDIOC_QBUF>` ioctl is called.
55662306a36Sopenharmony_ci    * .. _`V4L2-BUF-FLAG-NO-CACHE-INVALIDATE`:
55762306a36Sopenharmony_ci
55862306a36Sopenharmony_ci      - ``V4L2_BUF_FLAG_NO_CACHE_INVALIDATE``
55962306a36Sopenharmony_ci      - 0x00000800
56062306a36Sopenharmony_ci      - Caches do not have to be invalidated for this buffer. Typically
56162306a36Sopenharmony_ci	applications shall use this flag if the data captured in the
56262306a36Sopenharmony_ci	buffer is not going to be touched by the CPU, instead the buffer
56362306a36Sopenharmony_ci	will, probably, be passed on to a DMA-capable hardware unit for
56462306a36Sopenharmony_ci	further processing or output. This flag is ignored unless the
56562306a36Sopenharmony_ci	queue is used for :ref:`memory mapping <mmap>` streaming I/O and
56662306a36Sopenharmony_ci	reports :ref:`V4L2_BUF_CAP_SUPPORTS_MMAP_CACHE_HINTS
56762306a36Sopenharmony_ci	<V4L2-BUF-CAP-SUPPORTS-MMAP-CACHE-HINTS>` capability.
56862306a36Sopenharmony_ci    * .. _`V4L2-BUF-FLAG-NO-CACHE-CLEAN`:
56962306a36Sopenharmony_ci
57062306a36Sopenharmony_ci      - ``V4L2_BUF_FLAG_NO_CACHE_CLEAN``
57162306a36Sopenharmony_ci      - 0x00001000
57262306a36Sopenharmony_ci      - Caches do not have to be cleaned for this buffer. Typically
57362306a36Sopenharmony_ci	applications shall use this flag for output buffers if the data in
57462306a36Sopenharmony_ci	this buffer has not been created by the CPU but by some
57562306a36Sopenharmony_ci	DMA-capable unit, in which case caches have not been used. This flag
57662306a36Sopenharmony_ci	is ignored unless the queue is used for :ref:`memory mapping <mmap>`
57762306a36Sopenharmony_ci	streaming I/O and reports :ref:`V4L2_BUF_CAP_SUPPORTS_MMAP_CACHE_HINTS
57862306a36Sopenharmony_ci	<V4L2-BUF-CAP-SUPPORTS-MMAP-CACHE-HINTS>` capability.
57962306a36Sopenharmony_ci    * .. _`V4L2-BUF-FLAG-M2M-HOLD-CAPTURE-BUF`:
58062306a36Sopenharmony_ci
58162306a36Sopenharmony_ci      - ``V4L2_BUF_FLAG_M2M_HOLD_CAPTURE_BUF``
58262306a36Sopenharmony_ci      - 0x00000200
58362306a36Sopenharmony_ci      - Only valid if struct :c:type:`v4l2_requestbuffers` flag ``V4L2_BUF_CAP_SUPPORTS_M2M_HOLD_CAPTURE_BUF`` is
58462306a36Sopenharmony_ci	set. It is typically used with stateless decoders where multiple
58562306a36Sopenharmony_ci	output buffers each decode to a slice of the decoded frame.
58662306a36Sopenharmony_ci	Applications can set this flag when queueing the output buffer
58762306a36Sopenharmony_ci	to prevent the driver from dequeueing the capture buffer after
58862306a36Sopenharmony_ci	the output buffer has been decoded (i.e. the capture buffer is
58962306a36Sopenharmony_ci	'held'). If the timestamp of this output buffer differs from that
59062306a36Sopenharmony_ci	of the previous output buffer, then that indicates the start of a
59162306a36Sopenharmony_ci	new frame and the previously held capture buffer is dequeued.
59262306a36Sopenharmony_ci    * .. _`V4L2-BUF-FLAG-LAST`:
59362306a36Sopenharmony_ci
59462306a36Sopenharmony_ci      - ``V4L2_BUF_FLAG_LAST``
59562306a36Sopenharmony_ci      - 0x00100000
59662306a36Sopenharmony_ci      - Last buffer produced by the hardware. mem2mem codec drivers set
59762306a36Sopenharmony_ci	this flag on the capture queue for the last buffer when the
59862306a36Sopenharmony_ci	:ref:`VIDIOC_QUERYBUF` or
59962306a36Sopenharmony_ci	:ref:`VIDIOC_DQBUF <VIDIOC_QBUF>` ioctl is called. Due to
60062306a36Sopenharmony_ci	hardware limitations, the last buffer may be empty. In this case
60162306a36Sopenharmony_ci	the driver will set the ``bytesused`` field to 0, regardless of
60262306a36Sopenharmony_ci	the format. Any subsequent call to the
60362306a36Sopenharmony_ci	:ref:`VIDIOC_DQBUF <VIDIOC_QBUF>` ioctl will not block anymore,
60462306a36Sopenharmony_ci	but return an ``EPIPE`` error code.
60562306a36Sopenharmony_ci    * .. _`V4L2-BUF-FLAG-REQUEST-FD`:
60662306a36Sopenharmony_ci
60762306a36Sopenharmony_ci      - ``V4L2_BUF_FLAG_REQUEST_FD``
60862306a36Sopenharmony_ci      - 0x00800000
60962306a36Sopenharmony_ci      - The ``request_fd`` field contains a valid file descriptor.
61062306a36Sopenharmony_ci    * .. _`V4L2-BUF-FLAG-TIMESTAMP-MASK`:
61162306a36Sopenharmony_ci
61262306a36Sopenharmony_ci      - ``V4L2_BUF_FLAG_TIMESTAMP_MASK``
61362306a36Sopenharmony_ci      - 0x0000e000
61462306a36Sopenharmony_ci      - Mask for timestamp types below. To test the timestamp type, mask
61562306a36Sopenharmony_ci	out bits not belonging to timestamp type by performing a logical
61662306a36Sopenharmony_ci	and operation with buffer flags and timestamp mask.
61762306a36Sopenharmony_ci    * .. _`V4L2-BUF-FLAG-TIMESTAMP-UNKNOWN`:
61862306a36Sopenharmony_ci
61962306a36Sopenharmony_ci      - ``V4L2_BUF_FLAG_TIMESTAMP_UNKNOWN``
62062306a36Sopenharmony_ci      - 0x00000000
62162306a36Sopenharmony_ci      - Unknown timestamp type. This type is used by drivers before Linux
62262306a36Sopenharmony_ci	3.9 and may be either monotonic (see below) or realtime (wall
62362306a36Sopenharmony_ci	clock). Monotonic clock has been favoured in embedded systems
62462306a36Sopenharmony_ci	whereas most of the drivers use the realtime clock. Either kinds
62562306a36Sopenharmony_ci	of timestamps are available in user space via
62662306a36Sopenharmony_ci	:c:func:`clock_gettime` using clock IDs ``CLOCK_MONOTONIC``
62762306a36Sopenharmony_ci	and ``CLOCK_REALTIME``, respectively.
62862306a36Sopenharmony_ci    * .. _`V4L2-BUF-FLAG-TIMESTAMP-MONOTONIC`:
62962306a36Sopenharmony_ci
63062306a36Sopenharmony_ci      - ``V4L2_BUF_FLAG_TIMESTAMP_MONOTONIC``
63162306a36Sopenharmony_ci      - 0x00002000
63262306a36Sopenharmony_ci      - The buffer timestamp has been taken from the ``CLOCK_MONOTONIC``
63362306a36Sopenharmony_ci	clock. To access the same clock outside V4L2, use
63462306a36Sopenharmony_ci	:c:func:`clock_gettime`.
63562306a36Sopenharmony_ci    * .. _`V4L2-BUF-FLAG-TIMESTAMP-COPY`:
63662306a36Sopenharmony_ci
63762306a36Sopenharmony_ci      - ``V4L2_BUF_FLAG_TIMESTAMP_COPY``
63862306a36Sopenharmony_ci      - 0x00004000
63962306a36Sopenharmony_ci      - The CAPTURE buffer timestamp has been taken from the corresponding
64062306a36Sopenharmony_ci	OUTPUT buffer. This flag applies only to mem2mem devices.
64162306a36Sopenharmony_ci    * .. _`V4L2-BUF-FLAG-TSTAMP-SRC-MASK`:
64262306a36Sopenharmony_ci
64362306a36Sopenharmony_ci      - ``V4L2_BUF_FLAG_TSTAMP_SRC_MASK``
64462306a36Sopenharmony_ci      - 0x00070000
64562306a36Sopenharmony_ci      - Mask for timestamp sources below. The timestamp source defines the
64662306a36Sopenharmony_ci	point of time the timestamp is taken in relation to the frame.
64762306a36Sopenharmony_ci	Logical 'and' operation between the ``flags`` field and
64862306a36Sopenharmony_ci	``V4L2_BUF_FLAG_TSTAMP_SRC_MASK`` produces the value of the
64962306a36Sopenharmony_ci	timestamp source. Applications must set the timestamp source when
65062306a36Sopenharmony_ci	``type`` refers to an output stream and
65162306a36Sopenharmony_ci	``V4L2_BUF_FLAG_TIMESTAMP_COPY`` is set.
65262306a36Sopenharmony_ci    * .. _`V4L2-BUF-FLAG-TSTAMP-SRC-EOF`:
65362306a36Sopenharmony_ci
65462306a36Sopenharmony_ci      - ``V4L2_BUF_FLAG_TSTAMP_SRC_EOF``
65562306a36Sopenharmony_ci      - 0x00000000
65662306a36Sopenharmony_ci      - End Of Frame. The buffer timestamp has been taken when the last
65762306a36Sopenharmony_ci	pixel of the frame has been received or the last pixel of the
65862306a36Sopenharmony_ci	frame has been transmitted. In practice, software generated
65962306a36Sopenharmony_ci	timestamps will typically be read from the clock a small amount of
66062306a36Sopenharmony_ci	time after the last pixel has been received or transmitten,
66162306a36Sopenharmony_ci	depending on the system and other activity in it.
66262306a36Sopenharmony_ci    * .. _`V4L2-BUF-FLAG-TSTAMP-SRC-SOE`:
66362306a36Sopenharmony_ci
66462306a36Sopenharmony_ci      - ``V4L2_BUF_FLAG_TSTAMP_SRC_SOE``
66562306a36Sopenharmony_ci      - 0x00010000
66662306a36Sopenharmony_ci      - Start Of Exposure. The buffer timestamp has been taken when the
66762306a36Sopenharmony_ci	exposure of the frame has begun. This is only valid for the
66862306a36Sopenharmony_ci	``V4L2_BUF_TYPE_VIDEO_CAPTURE`` buffer type.
66962306a36Sopenharmony_ci
67062306a36Sopenharmony_ci.. raw:: latex
67162306a36Sopenharmony_ci
67262306a36Sopenharmony_ci    \normalsize
67362306a36Sopenharmony_ci
67462306a36Sopenharmony_cienum v4l2_memory
67562306a36Sopenharmony_ci================
67662306a36Sopenharmony_ci
67762306a36Sopenharmony_ci.. tabularcolumns:: |p{5.0cm}|p{0.8cm}|p{11.5cm}|
67862306a36Sopenharmony_ci
67962306a36Sopenharmony_ci.. flat-table::
68062306a36Sopenharmony_ci    :header-rows:  0
68162306a36Sopenharmony_ci    :stub-columns: 0
68262306a36Sopenharmony_ci    :widths:       3 1 4
68362306a36Sopenharmony_ci
68462306a36Sopenharmony_ci    * - ``V4L2_MEMORY_MMAP``
68562306a36Sopenharmony_ci      - 1
68662306a36Sopenharmony_ci      - The buffer is used for :ref:`memory mapping <mmap>` I/O.
68762306a36Sopenharmony_ci    * - ``V4L2_MEMORY_USERPTR``
68862306a36Sopenharmony_ci      - 2
68962306a36Sopenharmony_ci      - The buffer is used for :ref:`user pointer <userp>` I/O.
69062306a36Sopenharmony_ci    * - ``V4L2_MEMORY_OVERLAY``
69162306a36Sopenharmony_ci      - 3
69262306a36Sopenharmony_ci      - [to do]
69362306a36Sopenharmony_ci    * - ``V4L2_MEMORY_DMABUF``
69462306a36Sopenharmony_ci      - 4
69562306a36Sopenharmony_ci      - The buffer is used for :ref:`DMA shared buffer <dmabuf>` I/O.
69662306a36Sopenharmony_ci
69762306a36Sopenharmony_ci.. _memory-flags:
69862306a36Sopenharmony_ci
69962306a36Sopenharmony_ciMemory Consistency Flags
70062306a36Sopenharmony_ci------------------------
70162306a36Sopenharmony_ci
70262306a36Sopenharmony_ci.. raw:: latex
70362306a36Sopenharmony_ci
70462306a36Sopenharmony_ci    \small
70562306a36Sopenharmony_ci
70662306a36Sopenharmony_ci.. tabularcolumns:: |p{7.0cm}|p{2.1cm}|p{8.4cm}|
70762306a36Sopenharmony_ci
70862306a36Sopenharmony_ci.. cssclass:: longtable
70962306a36Sopenharmony_ci
71062306a36Sopenharmony_ci.. flat-table::
71162306a36Sopenharmony_ci    :header-rows:  0
71262306a36Sopenharmony_ci    :stub-columns: 0
71362306a36Sopenharmony_ci    :widths:       3 1 4
71462306a36Sopenharmony_ci
71562306a36Sopenharmony_ci    * .. _`V4L2-MEMORY-FLAG-NON-COHERENT`:
71662306a36Sopenharmony_ci
71762306a36Sopenharmony_ci      - ``V4L2_MEMORY_FLAG_NON_COHERENT``
71862306a36Sopenharmony_ci      - 0x00000001
71962306a36Sopenharmony_ci      - A buffer is allocated either in coherent (it will be automatically
72062306a36Sopenharmony_ci	coherent between the CPU and the bus) or non-coherent memory. The
72162306a36Sopenharmony_ci	latter can provide performance gains, for instance the CPU cache
72262306a36Sopenharmony_ci	sync/flush operations can be avoided if the buffer is accessed by the
72362306a36Sopenharmony_ci	corresponding device only and the CPU does not read/write to/from that
72462306a36Sopenharmony_ci	buffer. However, this requires extra care from the driver -- it must
72562306a36Sopenharmony_ci	guarantee memory consistency by issuing a cache flush/sync when
72662306a36Sopenharmony_ci	consistency is needed. If this flag is set V4L2 will attempt to
72762306a36Sopenharmony_ci	allocate the buffer in non-coherent memory. The flag takes effect
72862306a36Sopenharmony_ci	only if the buffer is used for :ref:`memory mapping <mmap>` I/O and the
72962306a36Sopenharmony_ci	queue reports the :ref:`V4L2_BUF_CAP_SUPPORTS_MMAP_CACHE_HINTS
73062306a36Sopenharmony_ci	<V4L2-BUF-CAP-SUPPORTS-MMAP-CACHE-HINTS>` capability.
73162306a36Sopenharmony_ci
73262306a36Sopenharmony_ci.. raw:: latex
73362306a36Sopenharmony_ci
73462306a36Sopenharmony_ci    \normalsize
73562306a36Sopenharmony_ci
73662306a36Sopenharmony_ciTimecodes
73762306a36Sopenharmony_ci=========
73862306a36Sopenharmony_ci
73962306a36Sopenharmony_ciThe :c:type:`v4l2_buffer_timecode` structure is designed to hold a
74062306a36Sopenharmony_ci:ref:`smpte12m` or similar timecode.
74162306a36Sopenharmony_ci(struct :c:type:`timeval` timestamps are stored in the struct
74262306a36Sopenharmony_ci:c:type:`v4l2_buffer` ``timestamp`` field.)
74362306a36Sopenharmony_ci
74462306a36Sopenharmony_ci.. c:type:: v4l2_timecode
74562306a36Sopenharmony_ci
74662306a36Sopenharmony_cistruct v4l2_timecode
74762306a36Sopenharmony_ci--------------------
74862306a36Sopenharmony_ci
74962306a36Sopenharmony_ci.. tabularcolumns:: |p{1.4cm}|p{2.8cm}|p{13.1cm}|
75062306a36Sopenharmony_ci
75162306a36Sopenharmony_ci.. flat-table::
75262306a36Sopenharmony_ci    :header-rows:  0
75362306a36Sopenharmony_ci    :stub-columns: 0
75462306a36Sopenharmony_ci    :widths:       1 1 2
75562306a36Sopenharmony_ci
75662306a36Sopenharmony_ci    * - __u32
75762306a36Sopenharmony_ci      - ``type``
75862306a36Sopenharmony_ci      - Frame rate the timecodes are based on, see :ref:`timecode-type`.
75962306a36Sopenharmony_ci    * - __u32
76062306a36Sopenharmony_ci      - ``flags``
76162306a36Sopenharmony_ci      - Timecode flags, see :ref:`timecode-flags`.
76262306a36Sopenharmony_ci    * - __u8
76362306a36Sopenharmony_ci      - ``frames``
76462306a36Sopenharmony_ci      - Frame count, 0 ... 23/24/29/49/59, depending on the type of
76562306a36Sopenharmony_ci	timecode.
76662306a36Sopenharmony_ci    * - __u8
76762306a36Sopenharmony_ci      - ``seconds``
76862306a36Sopenharmony_ci      - Seconds count, 0 ... 59. This is a binary, not BCD number.
76962306a36Sopenharmony_ci    * - __u8
77062306a36Sopenharmony_ci      - ``minutes``
77162306a36Sopenharmony_ci      - Minutes count, 0 ... 59. This is a binary, not BCD number.
77262306a36Sopenharmony_ci    * - __u8
77362306a36Sopenharmony_ci      - ``hours``
77462306a36Sopenharmony_ci      - Hours count, 0 ... 29. This is a binary, not BCD number.
77562306a36Sopenharmony_ci    * - __u8
77662306a36Sopenharmony_ci      - ``userbits``\ [4]
77762306a36Sopenharmony_ci      - The "user group" bits from the timecode.
77862306a36Sopenharmony_ci
77962306a36Sopenharmony_ci
78062306a36Sopenharmony_ci.. _timecode-type:
78162306a36Sopenharmony_ci
78262306a36Sopenharmony_ciTimecode Types
78362306a36Sopenharmony_ci--------------
78462306a36Sopenharmony_ci
78562306a36Sopenharmony_ci.. flat-table::
78662306a36Sopenharmony_ci    :header-rows:  0
78762306a36Sopenharmony_ci    :stub-columns: 0
78862306a36Sopenharmony_ci    :widths:       3 1 4
78962306a36Sopenharmony_ci
79062306a36Sopenharmony_ci    * - ``V4L2_TC_TYPE_24FPS``
79162306a36Sopenharmony_ci      - 1
79262306a36Sopenharmony_ci      - 24 frames per second, i. e. film.
79362306a36Sopenharmony_ci    * - ``V4L2_TC_TYPE_25FPS``
79462306a36Sopenharmony_ci      - 2
79562306a36Sopenharmony_ci      - 25 frames per second, i. e. PAL or SECAM video.
79662306a36Sopenharmony_ci    * - ``V4L2_TC_TYPE_30FPS``
79762306a36Sopenharmony_ci      - 3
79862306a36Sopenharmony_ci      - 30 frames per second, i. e. NTSC video.
79962306a36Sopenharmony_ci    * - ``V4L2_TC_TYPE_50FPS``
80062306a36Sopenharmony_ci      - 4
80162306a36Sopenharmony_ci      -
80262306a36Sopenharmony_ci    * - ``V4L2_TC_TYPE_60FPS``
80362306a36Sopenharmony_ci      - 5
80462306a36Sopenharmony_ci      -
80562306a36Sopenharmony_ci
80662306a36Sopenharmony_ci
80762306a36Sopenharmony_ci.. _timecode-flags:
80862306a36Sopenharmony_ci
80962306a36Sopenharmony_ciTimecode Flags
81062306a36Sopenharmony_ci--------------
81162306a36Sopenharmony_ci
81262306a36Sopenharmony_ci.. tabularcolumns:: |p{6.6cm}|p{1.4cm}|p{9.3cm}|
81362306a36Sopenharmony_ci
81462306a36Sopenharmony_ci.. flat-table::
81562306a36Sopenharmony_ci    :header-rows:  0
81662306a36Sopenharmony_ci    :stub-columns: 0
81762306a36Sopenharmony_ci    :widths:       3 1 4
81862306a36Sopenharmony_ci
81962306a36Sopenharmony_ci    * - ``V4L2_TC_FLAG_DROPFRAME``
82062306a36Sopenharmony_ci      - 0x0001
82162306a36Sopenharmony_ci      - Indicates "drop frame" semantics for counting frames in 29.97 fps
82262306a36Sopenharmony_ci	material. When set, frame numbers 0 and 1 at the start of each
82362306a36Sopenharmony_ci	minute, except minutes 0, 10, 20, 30, 40, 50 are omitted from the
82462306a36Sopenharmony_ci	count.
82562306a36Sopenharmony_ci    * - ``V4L2_TC_FLAG_COLORFRAME``
82662306a36Sopenharmony_ci      - 0x0002
82762306a36Sopenharmony_ci      - The "color frame" flag.
82862306a36Sopenharmony_ci    * - ``V4L2_TC_USERBITS_field``
82962306a36Sopenharmony_ci      - 0x000C
83062306a36Sopenharmony_ci      - Field mask for the "binary group flags".
83162306a36Sopenharmony_ci    * - ``V4L2_TC_USERBITS_USERDEFINED``
83262306a36Sopenharmony_ci      - 0x0000
83362306a36Sopenharmony_ci      - Unspecified format.
83462306a36Sopenharmony_ci    * - ``V4L2_TC_USERBITS_8BITCHARS``
83562306a36Sopenharmony_ci      - 0x0008
83662306a36Sopenharmony_ci      - 8-bit ISO characters.
837