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