]> git.kernelconcepts.de Git - karo-tx-linux.git/blob - Documentation/media/uapi/v4l/vidioc-g-selection.rst
Merge tag 'renesas-fixes4-for-v4.13' of https://git.kernel.org/pub/scm/linux/kernel...
[karo-tx-linux.git] / Documentation / media / uapi / v4l / vidioc-g-selection.rst
1 .. -*- coding: utf-8; mode: rst -*-
2
3 .. _VIDIOC_G_SELECTION:
4
5 ********************************************
6 ioctl VIDIOC_G_SELECTION, VIDIOC_S_SELECTION
7 ********************************************
8
9 Name
10 ====
11
12 VIDIOC_G_SELECTION - VIDIOC_S_SELECTION - Get or set one of the selection rectangles
13
14
15 Synopsis
16 ========
17
18 .. c:function:: int ioctl( int fd, VIDIOC_G_SELECTION, struct v4l2_selection *argp )
19     :name: VIDIOC_G_SELECTION
20
21
22 .. c:function:: int ioctl( int fd, VIDIOC_S_SELECTION, struct v4l2_selection *argp )
23     :name: VIDIOC_S_SELECTION
24
25
26 Arguments
27 =========
28
29 ``fd``
30     File descriptor returned by :ref:`open() <func-open>`.
31
32 ``request``
33     VIDIOC_G_SELECTION, VIDIOC_S_SELECTION
34
35 ``argp``
36
37
38 Description
39 ===========
40
41 The ioctls are used to query and configure selection rectangles.
42
43 To query the cropping (composing) rectangle set struct
44 :c:type:`v4l2_selection` ``type`` field to the
45 respective buffer type. The next step is setting the
46 value of struct :c:type:`v4l2_selection` ``target``
47 field to ``V4L2_SEL_TGT_CROP`` (``V4L2_SEL_TGT_COMPOSE``). Please refer
48 to table :ref:`v4l2-selections-common` or :ref:`selection-api` for
49 additional targets. The ``flags`` and ``reserved`` fields of struct
50 :c:type:`v4l2_selection` are ignored and they must be
51 filled with zeros. The driver fills the rest of the structure or returns
52 EINVAL error code if incorrect buffer type or target was used. If
53 cropping (composing) is not supported then the active rectangle is not
54 mutable and it is always equal to the bounds rectangle. Finally, the
55 struct :c:type:`v4l2_rect` ``r`` rectangle is filled with
56 the current cropping (composing) coordinates. The coordinates are
57 expressed in driver-dependent units. The only exception are rectangles
58 for images in raw formats, whose coordinates are always expressed in
59 pixels.
60
61 To change the cropping (composing) rectangle set the struct
62 :c:type:`v4l2_selection` ``type`` field to the
63 respective buffer type. The next step is setting the
64 value of struct :c:type:`v4l2_selection` ``target`` to
65 ``V4L2_SEL_TGT_CROP`` (``V4L2_SEL_TGT_COMPOSE``). Please refer to table
66 :ref:`v4l2-selections-common` or :ref:`selection-api` for additional
67 targets. The struct :c:type:`v4l2_rect` ``r`` rectangle need
68 to be set to the desired active area. Field struct
69 :c:type:`v4l2_selection` ``reserved`` is ignored and
70 must be filled with zeros. The driver may adjust coordinates of the
71 requested rectangle. An application may introduce constraints to control
72 rounding behaviour. The struct :c:type:`v4l2_selection`
73 ``flags`` field must be set to one of the following:
74
75 -  ``0`` - The driver can adjust the rectangle size freely and shall
76    choose a crop/compose rectangle as close as possible to the requested
77    one.
78
79 -  ``V4L2_SEL_FLAG_GE`` - The driver is not allowed to shrink the
80    rectangle. The original rectangle must lay inside the adjusted one.
81
82 -  ``V4L2_SEL_FLAG_LE`` - The driver is not allowed to enlarge the
83    rectangle. The adjusted rectangle must lay inside the original one.
84
85 -  ``V4L2_SEL_FLAG_GE | V4L2_SEL_FLAG_LE`` - The driver must choose the
86    size exactly the same as in the requested rectangle.
87
88 Please refer to :ref:`sel-const-adjust`.
89
90 The driver may have to adjusts the requested dimensions against hardware
91 limits and other parts as the pipeline, i.e. the bounds given by the
92 capture/output window or TV display. The closest possible values of
93 horizontal and vertical offset and sizes are chosen according to
94 following priority:
95
96 1. Satisfy constraints from struct
97    :c:type:`v4l2_selection` ``flags``.
98
99 2. Adjust width, height, left, and top to hardware limits and
100    alignments.
101
102 3. Keep center of adjusted rectangle as close as possible to the
103    original one.
104
105 4. Keep width and height as close as possible to original ones.
106
107 5. Keep horizontal and vertical offset as close as possible to original
108    ones.
109
110 On success the struct :c:type:`v4l2_rect` ``r`` field
111 contains the adjusted rectangle. When the parameters are unsuitable the
112 application may modify the cropping (composing) or image parameters and
113 repeat the cycle until satisfactory parameters have been negotiated. If
114 constraints flags have to be violated at then ``ERANGE`` is returned. The
115 error indicates that *there exist no rectangle* that satisfies the
116 constraints.
117
118 Selection targets and flags are documented in
119 :ref:`v4l2-selections-common`.
120
121
122 .. _sel-const-adjust:
123
124 .. kernel-figure::  constraints.svg
125     :alt:    constraints.svg
126     :align:  center
127
128     Size adjustments with constraint flags.
129
130     Behaviour of rectangle adjustment for different constraint flags.
131
132
133
134
135 .. c:type:: v4l2_selection
136
137 .. tabularcolumns:: |p{4.4cm}|p{4.4cm}|p{8.7cm}|
138
139 .. flat-table:: struct v4l2_selection
140     :header-rows:  0
141     :stub-columns: 0
142     :widths:       1 1 2
143
144     * - __u32
145       - ``type``
146       - Type of the buffer (from enum
147         :c:type:`v4l2_buf_type`).
148     * - __u32
149       - ``target``
150       - Used to select between
151         :ref:`cropping and composing rectangles <v4l2-selections-common>`.
152     * - __u32
153       - ``flags``
154       - Flags controlling the selection rectangle adjustments, refer to
155         :ref:`selection flags <v4l2-selection-flags>`.
156     * - struct :c:type:`v4l2_rect`
157       - ``r``
158       - The selection rectangle.
159     * - __u32
160       - ``reserved[9]``
161       - Reserved fields for future use. Drivers and applications must zero
162         this array.
163
164 .. note::
165    Unfortunately in the case of multiplanar buffer types
166    (``V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE`` and ``V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE``)
167    this API was messed up with regards to how the :c:type:`v4l2_selection` ``type`` field
168    should be filled in. Some drivers only accepted the ``_MPLANE`` buffer type while
169    other drivers only accepted a non-multiplanar buffer type (i.e. without the
170    ``_MPLANE`` at the end).
171
172    Starting with kernel 4.13 both variations are allowed.
173
174
175 Return Value
176 ============
177
178 On success 0 is returned, on error -1 and the ``errno`` variable is set
179 appropriately. The generic error codes are described at the
180 :ref:`Generic Error Codes <gen-errors>` chapter.
181
182 EINVAL
183     Given buffer type ``type`` or the selection target ``target`` is not
184     supported, or the ``flags`` argument is not valid.
185
186 ERANGE
187     It is not possible to adjust struct :c:type:`v4l2_rect`
188     ``r`` rectangle to satisfy all constraints given in the ``flags``
189     argument.
190
191 ENODATA
192     Selection is not supported for this input or output.
193
194 EBUSY
195     It is not possible to apply change of the selection rectangle at the
196     moment. Usually because streaming is in progress.