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 .. cpp:function:: int ioctl( int fd, int request, struct v4l2_selection *argp )
25 File descriptor returned by :ref:`open() <func-open>`.
28 VIDIOC_G_SELECTION, VIDIOC_S_SELECTION
36 The ioctls are used to query and configure selection rectangles.
38 To query the cropping (composing) rectangle set struct
39 :ref:`v4l2_selection <v4l2-selection>` ``type`` field to the
40 respective 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
45 value of struct :ref:`v4l2_selection <v4l2-selection>` ``target``
46 field to ``V4L2_SEL_TGT_CROP`` (``V4L2_SEL_TGT_COMPOSE``). Please refer
47 to table :ref:`v4l2-selections-common` or :ref:`selection-api` for
48 additional targets. The ``flags`` and ``reserved`` fields of struct
49 :ref:`v4l2_selection <v4l2-selection>` are ignored and they must be
50 filled with zeros. The driver fills the rest of the structure or returns
51 EINVAL error code if incorrect buffer type or target was used. If
52 cropping (composing) is not supported then the active rectangle is not
53 mutable and it is always equal to the bounds rectangle. Finally, the
54 struct :ref:`v4l2_rect <v4l2-rect>` ``r`` rectangle is filled with
55 the current cropping (composing) coordinates. The coordinates are
56 expressed in driver-dependent units. The only exception are rectangles
57 for images in raw formats, whose coordinates are always expressed in
60 To change the cropping (composing) rectangle set the struct
61 :ref:`v4l2_selection <v4l2-selection>` ``type`` field to the
62 respective 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
67 value 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
70 targets. The struct :ref:`v4l2_rect <v4l2-rect>` ``r`` rectangle need
71 to be set to the desired active area. Field struct
72 :ref:`v4l2_selection <v4l2-selection>` ``reserved`` is ignored and
73 must be filled with zeros. The driver may adjust coordinates of the
74 requested rectangle. An application may introduce constraints to control
75 rounding behaviour. The struct :ref:`v4l2_selection <v4l2-selection>`
76 ``flags`` field must be set to one of the following:
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
82 - ``V4L2_SEL_FLAG_GE`` - The driver is not allowed to shrink the
83 rectangle. The original rectangle must lay inside the adjusted one.
85 - ``V4L2_SEL_FLAG_LE`` - The driver is not allowed to enlarge the
86 rectangle. The adjusted rectangle must lay inside the original one.
88 - ``V4L2_SEL_FLAG_GE | V4L2_SEL_FLAG_LE`` - The driver must choose the
89 size exactly the same as in the requested rectangle.
91 Please refer to :ref:`sel-const-adjust`.
93 The driver may have to adjusts the requested dimensions against hardware
94 limits and other parts as the pipeline, i.e. the bounds given by the
95 capture/output window or TV display. The closest possible values of
96 horizontal and vertical offset and sizes are chosen according to
99 1. Satisfy constraints from struct
100 :ref:`v4l2_selection <v4l2-selection>` ``flags``.
102 2. Adjust width, height, left, and top to hardware limits and
105 3. Keep center of adjusted rectangle as close as possible to the
108 4. Keep width and height as close as possible to original ones.
110 5. Keep horizontal and vertical offset as close as possible to original
113 On success the struct :ref:`v4l2_rect <v4l2-rect>` ``r`` field
114 contains the adjusted rectangle. When the parameters are unsuitable the
115 application may modify the cropping (composing) or image parameters and
116 repeat the cycle until satisfactory parameters have been negotiated. If
117 constraints flags have to be violated at then ``ERANGE`` is returned. The
118 error indicates that *there exist no rectangle* that satisfies the
121 Selection targets and flags are documented in
122 :ref:`v4l2-selections-common`.
125 .. _sel-const-adjust:
127 .. figure:: vidioc-g-selection_files/constraints.*
128 :alt: constraints.png
131 Size adjustments with constraint flags.
133 Behaviour of rectangle adjustment for different constraint flags.
140 .. flat-table:: struct v4l2_selection
152 - Type of the buffer (from enum
153 :ref:`v4l2_buf_type <v4l2-buf-type>`).
161 - Used to select between
162 :ref:`cropping and composing rectangles <v4l2-selections-common>`.
170 - Flags controlling the selection rectangle adjustments, refer to
171 :ref:`selection flags <v4l2-selection-flags>`.
175 - struct :ref:`v4l2_rect <v4l2-rect>`
179 - The selection rectangle.
187 - 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.