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