1059b1c5bSMauro Carvalho Chehab.. SPDX-License-Identifier: GFDL-1.1-no-invariants-or-later
2407e84cdSMauro Carvalho Chehab.. c:namespace:: V4L
354f38fcaSMauro Carvalho Chehab
454f38fcaSMauro Carvalho Chehab.. _VIDIOC_QUERYBUF:
554f38fcaSMauro Carvalho Chehab
654f38fcaSMauro Carvalho Chehab*********************
754f38fcaSMauro Carvalho Chehabioctl VIDIOC_QUERYBUF
854f38fcaSMauro Carvalho Chehab*********************
954f38fcaSMauro Carvalho Chehab
1054f38fcaSMauro Carvalho ChehabName
1154f38fcaSMauro Carvalho Chehab====
1254f38fcaSMauro Carvalho Chehab
1354f38fcaSMauro Carvalho ChehabVIDIOC_QUERYBUF - Query the status of a buffer
1454f38fcaSMauro Carvalho Chehab
1554f38fcaSMauro Carvalho ChehabSynopsis
1654f38fcaSMauro Carvalho Chehab========
1754f38fcaSMauro Carvalho Chehab
18407e84cdSMauro Carvalho Chehab.. c:macro:: VIDIOC_QUERYBUF
1954f38fcaSMauro Carvalho Chehab
20407e84cdSMauro Carvalho Chehab``int ioctl(int fd, VIDIOC_QUERYBUF, struct v4l2_buffer *argp)``
2154f38fcaSMauro Carvalho Chehab
2254f38fcaSMauro Carvalho ChehabArguments
2354f38fcaSMauro Carvalho Chehab=========
2454f38fcaSMauro Carvalho Chehab
2554f38fcaSMauro Carvalho Chehab``fd``
26407e84cdSMauro Carvalho Chehab    File descriptor returned by :c:func:`open()`.
2754f38fcaSMauro Carvalho Chehab
2854f38fcaSMauro Carvalho Chehab``argp``
2954f38fcaSMauro Carvalho Chehab    Pointer to struct :c:type:`v4l2_buffer`.
3054f38fcaSMauro Carvalho Chehab
3154f38fcaSMauro Carvalho ChehabDescription
3254f38fcaSMauro Carvalho Chehab===========
3354f38fcaSMauro Carvalho Chehab
3454f38fcaSMauro Carvalho ChehabThis ioctl is part of the :ref:`streaming <mmap>` I/O method. It can
3554f38fcaSMauro Carvalho Chehabbe used to query the status of a buffer at any time after buffers have
3654f38fcaSMauro Carvalho Chehabbeen allocated with the :ref:`VIDIOC_REQBUFS` ioctl.
3754f38fcaSMauro Carvalho Chehab
3854f38fcaSMauro Carvalho ChehabApplications set the ``type`` field of a struct
3954f38fcaSMauro Carvalho Chehab:c:type:`v4l2_buffer` to the same buffer type as was
4054f38fcaSMauro Carvalho Chehabpreviously used with struct :c:type:`v4l2_format` ``type``
4154f38fcaSMauro Carvalho Chehaband struct :c:type:`v4l2_requestbuffers` ``type``,
4254f38fcaSMauro Carvalho Chehaband the ``index`` field. Valid index numbers range from zero to the
4354f38fcaSMauro Carvalho Chehabnumber of buffers allocated with
4454f38fcaSMauro Carvalho Chehab:ref:`VIDIOC_REQBUFS` (struct
4554f38fcaSMauro Carvalho Chehab:c:type:`v4l2_requestbuffers` ``count``) minus
4654f38fcaSMauro Carvalho Chehabone. The ``reserved`` and ``reserved2`` fields must be set to 0. When
4754f38fcaSMauro Carvalho Chehabusing the :ref:`multi-planar API <planar-apis>`, the ``m.planes``
4854f38fcaSMauro Carvalho Chehabfield must contain a userspace pointer to an array of struct
4954f38fcaSMauro Carvalho Chehab:c:type:`v4l2_plane` and the ``length`` field has to be set
5054f38fcaSMauro Carvalho Chehabto the number of elements in that array. After calling
5154f38fcaSMauro Carvalho Chehab:ref:`VIDIOC_QUERYBUF` with a pointer to this structure drivers return an
5254f38fcaSMauro Carvalho Chehaberror code or fill the rest of the structure.
5354f38fcaSMauro Carvalho Chehab
5454f38fcaSMauro Carvalho ChehabIn the ``flags`` field the ``V4L2_BUF_FLAG_MAPPED``,
5554f38fcaSMauro Carvalho Chehab``V4L2_BUF_FLAG_PREPARED``, ``V4L2_BUF_FLAG_QUEUED`` and
5654f38fcaSMauro Carvalho Chehab``V4L2_BUF_FLAG_DONE`` flags will be valid. The ``memory`` field will be
5754f38fcaSMauro Carvalho Chehabset to the current I/O method. For the single-planar API, the
5854f38fcaSMauro Carvalho Chehab``m.offset`` contains the offset of the buffer from the start of the
5954f38fcaSMauro Carvalho Chehabdevice memory, the ``length`` field its size. For the multi-planar API,
6054f38fcaSMauro Carvalho Chehabfields ``m.mem_offset`` and ``length`` in the ``m.planes`` array
6154f38fcaSMauro Carvalho Chehabelements will be used instead and the ``length`` field of struct
6254f38fcaSMauro Carvalho Chehab:c:type:`v4l2_buffer` is set to the number of filled-in
6354f38fcaSMauro Carvalho Chehabarray elements. The driver may or may not set the remaining fields and
6454f38fcaSMauro Carvalho Chehabflags, they are meaningless in this context.
6554f38fcaSMauro Carvalho Chehab
6654f38fcaSMauro Carvalho ChehabThe struct :c:type:`v4l2_buffer` structure is specified in
6754f38fcaSMauro Carvalho Chehab:ref:`buffer`.
6854f38fcaSMauro Carvalho Chehab
6954f38fcaSMauro Carvalho ChehabReturn Value
7054f38fcaSMauro Carvalho Chehab============
7154f38fcaSMauro Carvalho Chehab
7254f38fcaSMauro Carvalho ChehabOn success 0 is returned, on error -1 and the ``errno`` variable is set
7354f38fcaSMauro Carvalho Chehabappropriately. The generic error codes are described at the
7454f38fcaSMauro Carvalho Chehab:ref:`Generic Error Codes <gen-errors>` chapter.
7554f38fcaSMauro Carvalho Chehab
7654f38fcaSMauro Carvalho ChehabEINVAL
7754f38fcaSMauro Carvalho Chehab    The buffer ``type`` is not supported, or the ``index`` is out of
7854f38fcaSMauro Carvalho Chehab    bounds.
79