1 .. -*- coding: utf-8; mode: rst -*-
3 .. _VIDIOC_G_SELECTION:
5 ********************************************
6 ioctl VIDIOC_G_SELECTION, VIDIOC_S_SELECTION
7 ********************************************
12 VIDIOC_G_SELECTION - VIDIOC_S_SELECTION - Get or set one of the selection rectangles
18 .. c:function:: int ioctl( int fd, VIDIOC_G_SELECTION, struct v4l2_selection *argp )
19 :name: VIDIOC_G_SELECTION
22 .. c:function:: int ioctl( int fd, VIDIOC_S_SELECTION, struct v4l2_selection *argp )
23 :name: VIDIOC_S_SELECTION
30 File descriptor returned by :ref:`open() <func-open>`.
33 VIDIOC_G_SELECTION, VIDIOC_S_SELECTION
41 The ioctls are used to query and configure selection rectangles.
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
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:
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
79 - ``V4L2_SEL_FLAG_GE`` - The driver is not allowed to shrink the
80 rectangle. The original rectangle must lay inside the adjusted one.
82 - ``V4L2_SEL_FLAG_LE`` - The driver is not allowed to enlarge the
83 rectangle. The adjusted rectangle must lay inside the original one.
85 - ``V4L2_SEL_FLAG_GE | V4L2_SEL_FLAG_LE`` - The driver must choose the
86 size exactly the same as in the requested rectangle.
88 Please refer to :ref:`sel-const-adjust`.
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
96 1. Satisfy constraints from struct
97 :c:type:`v4l2_selection` ``flags``.
99 2. Adjust width, height, left, and top to hardware limits and
102 3. Keep center of adjusted rectangle as close as possible to the
105 4. Keep width and height as close as possible to original ones.
107 5. Keep horizontal and vertical offset as close as possible to original
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
118 Selection targets and flags are documented in
119 :ref:`v4l2-selections-common`.
122 .. _sel-const-adjust:
124 .. kernel-figure:: constraints.svg
125 :alt: constraints.svg
128 Size adjustments with constraint flags.
130 Behaviour of rectangle adjustment for different constraint flags.
135 .. c:type:: v4l2_selection
137 .. tabularcolumns:: |p{4.4cm}|p{4.4cm}|p{8.7cm}|
139 .. flat-table:: struct v4l2_selection
146 - Type of the buffer (from enum
147 :c:type:`v4l2_buf_type`).
150 - Used to select between
151 :ref:`cropping and composing rectangles <v4l2-selections-common>`.
154 - Flags controlling the selection rectangle adjustments, refer to
155 :ref:`selection flags <v4l2-selection-flags>`.
156 * - struct :c:type:`v4l2_rect`
158 - The selection rectangle.
161 - Reserved fields for future use. Drivers and applications must zero
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).
172 Starting with kernel 4.13 both variations are allowed.
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.
183 Given buffer type ``type`` or the selection target ``target`` is not
184 supported, or the ``flags`` argument is not valid.
187 It is not possible to adjust struct :c:type:`v4l2_rect`
188 ``r`` rectangle to satisfy all constraints given in the ``flags``
192 Selection is not supported for this input or output.
195 It is not possible to apply change of the selection rectangle at the
196 moment. Usually because streaming is in progress.