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