1 .. -*- coding: utf-8; mode: rst -*-
3 .. _VIDIOC_G_SELECTION:
5 ********************************************
6 ioctl VIDIOC_G_SELECTION, VIDIOC_S_SELECTION
7 ********************************************
9 *man VIDIOC_G_SELECTION(2)*
12 Get or set one of the selection rectangles
18 .. cpp:function:: int ioctl( int fd, int request, struct v4l2_selection *argp )
24 File descriptor returned by :ref:`open() <func-open>`.
27 VIDIOC_G_SELECTION, VIDIOC_S_SELECTION
35 The ioctls are used to query and configure selection rectangles.
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
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:
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
81 - ``V4L2_SEL_FLAG_GE`` - The driver is not allowed to shrink the
82 rectangle. The original rectangle must lay inside the adjusted one.
84 - ``V4L2_SEL_FLAG_LE`` - The driver is not allowed to enlarge the
85 rectangle. The adjusted rectangle must lay inside the original one.
87 - ``V4L2_SEL_FLAG_GE | V4L2_SEL_FLAG_LE`` - The driver must choose the
88 size exactly the same as in the requested rectangle.
90 Please refer to :ref:`sel-const-adjust`.
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
98 1. Satisfy constraints from struct
99 :ref:`v4l2_selection <v4l2-selection>` ``flags``.
101 2. Adjust width, height, left, and top to hardware limits and
104 3. Keep center of adjusted rectangle as close as possible to the
107 4. Keep width and height as close as possible to original ones.
109 5. Keep horizontal and vertical offset as close as possible to original
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
120 Selection targets and flags are documented in
121 :ref:`v4l2-selections-common`.
124 .. _sel-const-adjust:
126 .. figure:: vidioc-g-selection_files/constraints.*
127 :alt: constraints.png
130 Size adjustments with constraint flags.
132 Behaviour of rectangle adjustment for different constraint flags.
139 .. flat-table:: struct v4l2_selection
151 - Type of the buffer (from enum
152 :ref:`v4l2_buf_type <v4l2-buf-type>`).
160 - Used to select between
161 :ref:`cropping and composing rectangles <v4l2-selections-common>`.
169 - Flags controlling the selection rectangle adjustments, refer to
170 :ref:`selection flags <v4l2-selection-flags>`.
174 - struct :ref:`v4l2_rect <v4l2-rect>`
178 - The selection rectangle.
186 - Reserved fields for future use. Drivers and applications must zero
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.
199 Given buffer type ``type`` or the selection target ``target`` is not
200 supported, or the ``flags`` argument is not valid.
203 It is not possible to adjust struct :ref:`v4l2_rect <v4l2-rect>`
204 ``r`` rectangle to satisfy all constraints given in the ``flags``
208 It is not possible to apply change of the selection rectangle at the
209 moment. Usually because streaming is in progress.
212 .. ------------------------------------------------------------------------------
213 .. This file was automatically converted from DocBook-XML with the dbxml
214 .. library (https://github.com/return42/sphkerneldoc). The origin XML comes
215 .. from the linux kernel, refer to:
217 .. * https://github.com/torvalds/linux/tree/master/Documentation/DocBook
218 .. ------------------------------------------------------------------------------