xref: /OK3568_Linux_fs/kernel/Documentation/userspace-api/media/v4l/vidioc-querybuf.rst (revision 4882a59341e53eb6f0b4789bf948001014eff981)
1*4882a593Smuzhiyun.. SPDX-License-Identifier: GFDL-1.1-no-invariants-or-later
2*4882a593Smuzhiyun.. c:namespace:: V4L
3*4882a593Smuzhiyun
4*4882a593Smuzhiyun.. _VIDIOC_QUERYBUF:
5*4882a593Smuzhiyun
6*4882a593Smuzhiyun*********************
7*4882a593Smuzhiyunioctl VIDIOC_QUERYBUF
8*4882a593Smuzhiyun*********************
9*4882a593Smuzhiyun
10*4882a593SmuzhiyunName
11*4882a593Smuzhiyun====
12*4882a593Smuzhiyun
13*4882a593SmuzhiyunVIDIOC_QUERYBUF - Query the status of a buffer
14*4882a593Smuzhiyun
15*4882a593SmuzhiyunSynopsis
16*4882a593Smuzhiyun========
17*4882a593Smuzhiyun
18*4882a593Smuzhiyun.. c:macro:: VIDIOC_QUERYBUF
19*4882a593Smuzhiyun
20*4882a593Smuzhiyun``int ioctl(int fd, VIDIOC_QUERYBUF, struct v4l2_buffer *argp)``
21*4882a593Smuzhiyun
22*4882a593SmuzhiyunArguments
23*4882a593Smuzhiyun=========
24*4882a593Smuzhiyun
25*4882a593Smuzhiyun``fd``
26*4882a593Smuzhiyun    File descriptor returned by :c:func:`open()`.
27*4882a593Smuzhiyun
28*4882a593Smuzhiyun``argp``
29*4882a593Smuzhiyun    Pointer to struct :c:type:`v4l2_buffer`.
30*4882a593Smuzhiyun
31*4882a593SmuzhiyunDescription
32*4882a593Smuzhiyun===========
33*4882a593Smuzhiyun
34*4882a593SmuzhiyunThis ioctl is part of the :ref:`streaming <mmap>` I/O method. It can
35*4882a593Smuzhiyunbe used to query the status of a buffer at any time after buffers have
36*4882a593Smuzhiyunbeen allocated with the :ref:`VIDIOC_REQBUFS` ioctl.
37*4882a593Smuzhiyun
38*4882a593SmuzhiyunApplications set the ``type`` field of a struct
39*4882a593Smuzhiyun:c:type:`v4l2_buffer` to the same buffer type as was
40*4882a593Smuzhiyunpreviously used with struct :c:type:`v4l2_format` ``type``
41*4882a593Smuzhiyunand struct :c:type:`v4l2_requestbuffers` ``type``,
42*4882a593Smuzhiyunand the ``index`` field. Valid index numbers range from zero to the
43*4882a593Smuzhiyunnumber of buffers allocated with
44*4882a593Smuzhiyun:ref:`VIDIOC_REQBUFS` (struct
45*4882a593Smuzhiyun:c:type:`v4l2_requestbuffers` ``count``) minus
46*4882a593Smuzhiyunone. The ``reserved`` and ``reserved2`` fields must be set to 0. When
47*4882a593Smuzhiyunusing the :ref:`multi-planar API <planar-apis>`, the ``m.planes``
48*4882a593Smuzhiyunfield must contain a userspace pointer to an array of struct
49*4882a593Smuzhiyun:c:type:`v4l2_plane` and the ``length`` field has to be set
50*4882a593Smuzhiyunto the number of elements in that array. After calling
51*4882a593Smuzhiyun:ref:`VIDIOC_QUERYBUF` with a pointer to this structure drivers return an
52*4882a593Smuzhiyunerror code or fill the rest of the structure.
53*4882a593Smuzhiyun
54*4882a593SmuzhiyunIn the ``flags`` field the ``V4L2_BUF_FLAG_MAPPED``,
55*4882a593Smuzhiyun``V4L2_BUF_FLAG_PREPARED``, ``V4L2_BUF_FLAG_QUEUED`` and
56*4882a593Smuzhiyun``V4L2_BUF_FLAG_DONE`` flags will be valid. The ``memory`` field will be
57*4882a593Smuzhiyunset to the current I/O method. For the single-planar API, the
58*4882a593Smuzhiyun``m.offset`` contains the offset of the buffer from the start of the
59*4882a593Smuzhiyundevice memory, the ``length`` field its size. For the multi-planar API,
60*4882a593Smuzhiyunfields ``m.mem_offset`` and ``length`` in the ``m.planes`` array
61*4882a593Smuzhiyunelements will be used instead and the ``length`` field of struct
62*4882a593Smuzhiyun:c:type:`v4l2_buffer` is set to the number of filled-in
63*4882a593Smuzhiyunarray elements. The driver may or may not set the remaining fields and
64*4882a593Smuzhiyunflags, they are meaningless in this context.
65*4882a593Smuzhiyun
66*4882a593SmuzhiyunThe struct :c:type:`v4l2_buffer` structure is specified in
67*4882a593Smuzhiyun:ref:`buffer`.
68*4882a593Smuzhiyun
69*4882a593SmuzhiyunReturn Value
70*4882a593Smuzhiyun============
71*4882a593Smuzhiyun
72*4882a593SmuzhiyunOn success 0 is returned, on error -1 and the ``errno`` variable is set
73*4882a593Smuzhiyunappropriately. The generic error codes are described at the
74*4882a593Smuzhiyun:ref:`Generic Error Codes <gen-errors>` chapter.
75*4882a593Smuzhiyun
76*4882a593SmuzhiyunEINVAL
77*4882a593Smuzhiyun    The buffer ``type`` is not supported, or the ``index`` is out of
78*4882a593Smuzhiyun    bounds.
79