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_CROP: |
Markus Heiser | 5377d91 | 2016-06-30 15:18:56 +0200 | [diff] [blame] | 4 | |
| 5 | ********************************** |
| 6 | ioctl VIDIOC_G_CROP, VIDIOC_S_CROP |
| 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_CROP - VIDIOC_S_CROP - Get or set the current cropping rectangle |
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_CROP, struct v4l2_crop *argp ) |
| 19 | :name: VIDIOC_G_CROP |
Markus Heiser | 5377d91 | 2016-06-30 15:18:56 +0200 | [diff] [blame] | 20 | |
Mauro Carvalho Chehab | 41d8046 | 2016-08-19 16:53:38 -0300 | [diff] [blame] | 21 | .. c:function:: int ioctl( int fd, VIDIOC_S_CROP, const struct v4l2_crop *argp ) |
| 22 | :name: VIDIOC_S_CROP |
Markus Heiser | 5377d91 | 2016-06-30 15:18:56 +0200 | [diff] [blame] | 23 | |
Mauro Carvalho Chehab | 586027c | 2016-07-05 07:58:48 -0300 | [diff] [blame] | 24 | |
Mauro Carvalho Chehab | 15e7d61 | 2016-07-05 15:14:35 -0300 | [diff] [blame] | 25 | Arguments |
Markus Heiser | 5377d91 | 2016-06-30 15:18:56 +0200 | [diff] [blame] | 26 | ========= |
| 27 | |
| 28 | ``fd`` |
| 29 | File descriptor returned by :ref:`open() <func-open>`. |
| 30 | |
Markus Heiser | 5377d91 | 2016-06-30 15:18:56 +0200 | [diff] [blame] | 31 | ``argp`` |
| 32 | |
| 33 | |
Mauro Carvalho Chehab | 15e7d61 | 2016-07-05 15:14:35 -0300 | [diff] [blame] | 34 | Description |
Markus Heiser | 5377d91 | 2016-06-30 15:18:56 +0200 | [diff] [blame] | 35 | =========== |
| 36 | |
| 37 | To query the cropping rectangle size and position applications set the |
Mauro Carvalho Chehab | e8be7e9 | 2016-08-29 17:37:59 -0300 | [diff] [blame^] | 38 | ``type`` field of a :c:type:`struct v4l2_crop <v4l2_crop>` structure to the |
Mauro Carvalho Chehab | 4e03cb7 | 2016-07-03 10:02:29 -0300 | [diff] [blame] | 39 | respective buffer (stream) type and call the :ref:`VIDIOC_G_CROP <VIDIOC_G_CROP>` ioctl |
Markus Heiser | 5377d91 | 2016-06-30 15:18:56 +0200 | [diff] [blame] | 40 | with a pointer to this structure. The driver fills the rest of the |
Mauro Carvalho Chehab | cdb4af0 | 2016-07-03 11:53:09 -0300 | [diff] [blame] | 41 | structure or returns the ``EINVAL`` error code if cropping is not supported. |
Markus Heiser | 5377d91 | 2016-06-30 15:18:56 +0200 | [diff] [blame] | 42 | |
| 43 | To change the cropping rectangle applications initialize the ``type`` |
Mauro Carvalho Chehab | e8be7e9 | 2016-08-29 17:37:59 -0300 | [diff] [blame^] | 44 | and struct :c:type:`v4l2_rect` substructure named ``c`` of a |
Mauro Carvalho Chehab | 2212ff2 | 2016-07-01 14:33:56 -0300 | [diff] [blame] | 45 | v4l2_crop structure and call the :ref:`VIDIOC_S_CROP <VIDIOC_G_CROP>` ioctl with a pointer |
Markus Heiser | 5377d91 | 2016-06-30 15:18:56 +0200 | [diff] [blame] | 46 | to this structure. |
| 47 | |
| 48 | Do not use the multiplanar buffer types. Use |
| 49 | ``V4L2_BUF_TYPE_VIDEO_CAPTURE`` instead of |
| 50 | ``V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE`` and use |
| 51 | ``V4L2_BUF_TYPE_VIDEO_OUTPUT`` instead of |
| 52 | ``V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE``. |
| 53 | |
| 54 | The driver first adjusts the requested dimensions against hardware |
| 55 | limits, i. e. the bounds given by the capture/output window, and it |
| 56 | rounds to the closest possible values of horizontal and vertical offset, |
| 57 | width and height. In particular the driver must round the vertical |
| 58 | offset of the cropping rectangle to frame lines modulo two, such that |
| 59 | the field order cannot be confused. |
| 60 | |
| 61 | Second the driver adjusts the image size (the opposite rectangle of the |
| 62 | scaling process, source or target depending on the data direction) to |
| 63 | the closest size possible while maintaining the current horizontal and |
| 64 | vertical scaling factor. |
| 65 | |
| 66 | Finally the driver programs the hardware with the actual cropping and |
Mauro Carvalho Chehab | 2212ff2 | 2016-07-01 14:33:56 -0300 | [diff] [blame] | 67 | image parameters. :ref:`VIDIOC_S_CROP <VIDIOC_G_CROP>` is a write-only ioctl, it does not |
Markus Heiser | 5377d91 | 2016-06-30 15:18:56 +0200 | [diff] [blame] | 68 | return the actual parameters. To query them applications must call |
Mauro Carvalho Chehab | 4e03cb7 | 2016-07-03 10:02:29 -0300 | [diff] [blame] | 69 | :ref:`VIDIOC_G_CROP <VIDIOC_G_CROP>` and :ref:`VIDIOC_G_FMT`. When the |
Markus Heiser | 5377d91 | 2016-06-30 15:18:56 +0200 | [diff] [blame] | 70 | parameters are unsuitable the application may modify the cropping or |
| 71 | image parameters and repeat the cycle until satisfactory parameters have |
| 72 | been negotiated. |
| 73 | |
| 74 | When cropping is not supported then no parameters are changed and |
Mauro Carvalho Chehab | cdb4af0 | 2016-07-03 11:53:09 -0300 | [diff] [blame] | 75 | :ref:`VIDIOC_S_CROP <VIDIOC_G_CROP>` returns the ``EINVAL`` error code. |
Markus Heiser | 5377d91 | 2016-06-30 15:18:56 +0200 | [diff] [blame] | 76 | |
| 77 | |
Mauro Carvalho Chehab | e8be7e9 | 2016-08-29 17:37:59 -0300 | [diff] [blame^] | 78 | .. c:type:: v4l2_crop |
Markus Heiser | 5377d91 | 2016-06-30 15:18:56 +0200 | [diff] [blame] | 79 | |
Mauro Carvalho Chehab | 5bd4bb7 | 2016-08-17 08:14:19 -0300 | [diff] [blame] | 80 | .. tabularcolumns:: |p{4.4cm}|p{4.4cm}|p{8.7cm}| |
| 81 | |
Markus Heiser | 5377d91 | 2016-06-30 15:18:56 +0200 | [diff] [blame] | 82 | .. flat-table:: struct v4l2_crop |
| 83 | :header-rows: 0 |
| 84 | :stub-columns: 0 |
| 85 | :widths: 1 1 2 |
| 86 | |
| 87 | |
| 88 | - .. row 1 |
| 89 | |
| 90 | - __u32 |
| 91 | |
| 92 | - ``type`` |
| 93 | |
| 94 | - Type of the data stream, set by the application. Only these types |
Mauro Carvalho Chehab | 0579e6e | 2016-07-04 16:25:48 -0300 | [diff] [blame] | 95 | are valid here: ``V4L2_BUF_TYPE_VIDEO_CAPTURE``, |
| 96 | ``V4L2_BUF_TYPE_VIDEO_OUTPUT`` and |
| 97 | ``V4L2_BUF_TYPE_VIDEO_OVERLAY``. See :ref:`v4l2-buf-type`. |
Markus Heiser | 5377d91 | 2016-06-30 15:18:56 +0200 | [diff] [blame] | 98 | |
| 99 | - .. row 2 |
| 100 | |
Mauro Carvalho Chehab | e8be7e9 | 2016-08-29 17:37:59 -0300 | [diff] [blame^] | 101 | - struct :c:type:`v4l2_rect` |
Markus Heiser | 5377d91 | 2016-06-30 15:18:56 +0200 | [diff] [blame] | 102 | |
| 103 | - ``c`` |
| 104 | |
| 105 | - Cropping rectangle. The same co-ordinate system as for struct |
Mauro Carvalho Chehab | e8be7e9 | 2016-08-29 17:37:59 -0300 | [diff] [blame^] | 106 | :c:type:`v4l2_cropcap` ``bounds`` is used. |
Markus Heiser | 5377d91 | 2016-06-30 15:18:56 +0200 | [diff] [blame] | 107 | |
| 108 | |
Mauro Carvalho Chehab | 15e7d61 | 2016-07-05 15:14:35 -0300 | [diff] [blame] | 109 | Return Value |
Markus Heiser | 5377d91 | 2016-06-30 15:18:56 +0200 | [diff] [blame] | 110 | ============ |
| 111 | |
| 112 | On success 0 is returned, on error -1 and the ``errno`` variable is set |
| 113 | appropriately. The generic error codes are described at the |
| 114 | :ref:`Generic Error Codes <gen-errors>` chapter. |
Hans Verkuil | 3f8d56b | 2016-07-20 09:39:42 -0300 | [diff] [blame] | 115 | |
| 116 | ENODATA |
| 117 | Cropping is not supported for this input or output. |