1*4882a593Smuzhiyun.. SPDX-License-Identifier: GFDL-1.1-no-invariants-or-later 2*4882a593Smuzhiyun.. c:namespace:: V4L 3*4882a593Smuzhiyun 4*4882a593Smuzhiyun.. _VIDIOC_G_SELECTION: 5*4882a593Smuzhiyun 6*4882a593Smuzhiyun******************************************** 7*4882a593Smuzhiyunioctl VIDIOC_G_SELECTION, VIDIOC_S_SELECTION 8*4882a593Smuzhiyun******************************************** 9*4882a593Smuzhiyun 10*4882a593SmuzhiyunName 11*4882a593Smuzhiyun==== 12*4882a593Smuzhiyun 13*4882a593SmuzhiyunVIDIOC_G_SELECTION - VIDIOC_S_SELECTION - Get or set one of the selection rectangles 14*4882a593Smuzhiyun 15*4882a593SmuzhiyunSynopsis 16*4882a593Smuzhiyun======== 17*4882a593Smuzhiyun 18*4882a593Smuzhiyun.. c:macro:: VIDIOC_G_SELECTION 19*4882a593Smuzhiyun 20*4882a593Smuzhiyun``int ioctl(int fd, VIDIOC_G_SELECTION, struct v4l2_selection *argp)`` 21*4882a593Smuzhiyun 22*4882a593Smuzhiyun.. c:macro:: VIDIOC_S_SELECTION 23*4882a593Smuzhiyun 24*4882a593Smuzhiyun``int ioctl(int fd, VIDIOC_S_SELECTION, struct v4l2_selection *argp)`` 25*4882a593Smuzhiyun 26*4882a593SmuzhiyunArguments 27*4882a593Smuzhiyun========= 28*4882a593Smuzhiyun 29*4882a593Smuzhiyun``fd`` 30*4882a593Smuzhiyun File descriptor returned by :c:func:`open()`. 31*4882a593Smuzhiyun 32*4882a593Smuzhiyun``argp`` 33*4882a593Smuzhiyun Pointer to struct :c:type:`v4l2_selection`. 34*4882a593Smuzhiyun 35*4882a593SmuzhiyunDescription 36*4882a593Smuzhiyun=========== 37*4882a593Smuzhiyun 38*4882a593SmuzhiyunThe ioctls are used to query and configure selection rectangles. 39*4882a593Smuzhiyun 40*4882a593SmuzhiyunTo query the cropping (composing) rectangle set struct 41*4882a593Smuzhiyun:c:type:`v4l2_selection` ``type`` field to the 42*4882a593Smuzhiyunrespective buffer type. The next step is setting the 43*4882a593Smuzhiyunvalue of struct :c:type:`v4l2_selection` ``target`` 44*4882a593Smuzhiyunfield to ``V4L2_SEL_TGT_CROP`` (``V4L2_SEL_TGT_COMPOSE``). Please refer 45*4882a593Smuzhiyunto table :ref:`v4l2-selections-common` or :ref:`selection-api` for 46*4882a593Smuzhiyunadditional targets. The ``flags`` and ``reserved`` fields of struct 47*4882a593Smuzhiyun:c:type:`v4l2_selection` are ignored and they must be 48*4882a593Smuzhiyunfilled with zeros. The driver fills the rest of the structure or returns 49*4882a593SmuzhiyunEINVAL error code if incorrect buffer type or target was used. If 50*4882a593Smuzhiyuncropping (composing) is not supported then the active rectangle is not 51*4882a593Smuzhiyunmutable and it is always equal to the bounds rectangle. Finally, the 52*4882a593Smuzhiyunstruct :c:type:`v4l2_rect` ``r`` rectangle is filled with 53*4882a593Smuzhiyunthe current cropping (composing) coordinates. The coordinates are 54*4882a593Smuzhiyunexpressed in driver-dependent units. The only exception are rectangles 55*4882a593Smuzhiyunfor images in raw formats, whose coordinates are always expressed in 56*4882a593Smuzhiyunpixels. 57*4882a593Smuzhiyun 58*4882a593SmuzhiyunTo change the cropping (composing) rectangle set the struct 59*4882a593Smuzhiyun:c:type:`v4l2_selection` ``type`` field to the 60*4882a593Smuzhiyunrespective buffer type. The next step is setting the 61*4882a593Smuzhiyunvalue of struct :c:type:`v4l2_selection` ``target`` to 62*4882a593Smuzhiyun``V4L2_SEL_TGT_CROP`` (``V4L2_SEL_TGT_COMPOSE``). Please refer to table 63*4882a593Smuzhiyun:ref:`v4l2-selections-common` or :ref:`selection-api` for additional 64*4882a593Smuzhiyuntargets. The struct :c:type:`v4l2_rect` ``r`` rectangle need 65*4882a593Smuzhiyunto be set to the desired active area. Field struct 66*4882a593Smuzhiyun:c:type:`v4l2_selection` ``reserved`` is ignored and 67*4882a593Smuzhiyunmust be filled with zeros. The driver may adjust coordinates of the 68*4882a593Smuzhiyunrequested rectangle. An application may introduce constraints to control 69*4882a593Smuzhiyunrounding behaviour. The struct :c:type:`v4l2_selection` 70*4882a593Smuzhiyun``flags`` field must be set to one of the following: 71*4882a593Smuzhiyun 72*4882a593Smuzhiyun- ``0`` - The driver can adjust the rectangle size freely and shall 73*4882a593Smuzhiyun choose a crop/compose rectangle as close as possible to the requested 74*4882a593Smuzhiyun one. 75*4882a593Smuzhiyun 76*4882a593Smuzhiyun- ``V4L2_SEL_FLAG_GE`` - The driver is not allowed to shrink the 77*4882a593Smuzhiyun rectangle. The original rectangle must lay inside the adjusted one. 78*4882a593Smuzhiyun 79*4882a593Smuzhiyun- ``V4L2_SEL_FLAG_LE`` - The driver is not allowed to enlarge the 80*4882a593Smuzhiyun rectangle. The adjusted rectangle must lay inside the original one. 81*4882a593Smuzhiyun 82*4882a593Smuzhiyun- ``V4L2_SEL_FLAG_GE | V4L2_SEL_FLAG_LE`` - The driver must choose the 83*4882a593Smuzhiyun size exactly the same as in the requested rectangle. 84*4882a593Smuzhiyun 85*4882a593SmuzhiyunPlease refer to :ref:`sel-const-adjust`. 86*4882a593Smuzhiyun 87*4882a593SmuzhiyunThe driver may have to adjusts the requested dimensions against hardware 88*4882a593Smuzhiyunlimits and other parts as the pipeline, i.e. the bounds given by the 89*4882a593Smuzhiyuncapture/output window or TV display. The closest possible values of 90*4882a593Smuzhiyunhorizontal and vertical offset and sizes are chosen according to 91*4882a593Smuzhiyunfollowing priority: 92*4882a593Smuzhiyun 93*4882a593Smuzhiyun1. Satisfy constraints from struct 94*4882a593Smuzhiyun :c:type:`v4l2_selection` ``flags``. 95*4882a593Smuzhiyun 96*4882a593Smuzhiyun2. Adjust width, height, left, and top to hardware limits and 97*4882a593Smuzhiyun alignments. 98*4882a593Smuzhiyun 99*4882a593Smuzhiyun3. Keep center of adjusted rectangle as close as possible to the 100*4882a593Smuzhiyun original one. 101*4882a593Smuzhiyun 102*4882a593Smuzhiyun4. Keep width and height as close as possible to original ones. 103*4882a593Smuzhiyun 104*4882a593Smuzhiyun5. Keep horizontal and vertical offset as close as possible to original 105*4882a593Smuzhiyun ones. 106*4882a593Smuzhiyun 107*4882a593SmuzhiyunOn success the struct :c:type:`v4l2_rect` ``r`` field 108*4882a593Smuzhiyuncontains the adjusted rectangle. When the parameters are unsuitable the 109*4882a593Smuzhiyunapplication may modify the cropping (composing) or image parameters and 110*4882a593Smuzhiyunrepeat the cycle until satisfactory parameters have been negotiated. If 111*4882a593Smuzhiyunconstraints flags have to be violated at then ``ERANGE`` is returned. The 112*4882a593Smuzhiyunerror indicates that *there exist no rectangle* that satisfies the 113*4882a593Smuzhiyunconstraints. 114*4882a593Smuzhiyun 115*4882a593SmuzhiyunSelection targets and flags are documented in 116*4882a593Smuzhiyun:ref:`v4l2-selections-common`. 117*4882a593Smuzhiyun 118*4882a593Smuzhiyun.. _sel-const-adjust: 119*4882a593Smuzhiyun 120*4882a593Smuzhiyun.. kernel-figure:: constraints.svg 121*4882a593Smuzhiyun :alt: constraints.svg 122*4882a593Smuzhiyun :align: center 123*4882a593Smuzhiyun 124*4882a593Smuzhiyun Size adjustments with constraint flags. 125*4882a593Smuzhiyun 126*4882a593Smuzhiyun Behaviour of rectangle adjustment for different constraint flags. 127*4882a593Smuzhiyun 128*4882a593Smuzhiyun 129*4882a593Smuzhiyun 130*4882a593Smuzhiyun.. c:type:: v4l2_selection 131*4882a593Smuzhiyun 132*4882a593Smuzhiyun.. tabularcolumns:: |p{4.4cm}|p{4.4cm}|p{8.7cm}| 133*4882a593Smuzhiyun 134*4882a593Smuzhiyun.. flat-table:: struct v4l2_selection 135*4882a593Smuzhiyun :header-rows: 0 136*4882a593Smuzhiyun :stub-columns: 0 137*4882a593Smuzhiyun :widths: 1 1 2 138*4882a593Smuzhiyun 139*4882a593Smuzhiyun * - __u32 140*4882a593Smuzhiyun - ``type`` 141*4882a593Smuzhiyun - Type of the buffer (from enum 142*4882a593Smuzhiyun :c:type:`v4l2_buf_type`). 143*4882a593Smuzhiyun * - __u32 144*4882a593Smuzhiyun - ``target`` 145*4882a593Smuzhiyun - Used to select between 146*4882a593Smuzhiyun :ref:`cropping and composing rectangles <v4l2-selections-common>`. 147*4882a593Smuzhiyun * - __u32 148*4882a593Smuzhiyun - ``flags`` 149*4882a593Smuzhiyun - Flags controlling the selection rectangle adjustments, refer to 150*4882a593Smuzhiyun :ref:`selection flags <v4l2-selection-flags>`. 151*4882a593Smuzhiyun * - struct :c:type:`v4l2_rect` 152*4882a593Smuzhiyun - ``r`` 153*4882a593Smuzhiyun - The selection rectangle. 154*4882a593Smuzhiyun * - __u32 155*4882a593Smuzhiyun - ``reserved[9]`` 156*4882a593Smuzhiyun - Reserved fields for future use. Drivers and applications must zero 157*4882a593Smuzhiyun this array. 158*4882a593Smuzhiyun 159*4882a593Smuzhiyun.. note:: 160*4882a593Smuzhiyun Unfortunately in the case of multiplanar buffer types 161*4882a593Smuzhiyun (``V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE`` and ``V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE``) 162*4882a593Smuzhiyun this API was messed up with regards to how the :c:type:`v4l2_selection` ``type`` field 163*4882a593Smuzhiyun should be filled in. Some drivers only accepted the ``_MPLANE`` buffer type while 164*4882a593Smuzhiyun other drivers only accepted a non-multiplanar buffer type (i.e. without the 165*4882a593Smuzhiyun ``_MPLANE`` at the end). 166*4882a593Smuzhiyun 167*4882a593Smuzhiyun Starting with kernel 4.13 both variations are allowed. 168*4882a593Smuzhiyun 169*4882a593SmuzhiyunReturn Value 170*4882a593Smuzhiyun============ 171*4882a593Smuzhiyun 172*4882a593SmuzhiyunOn success 0 is returned, on error -1 and the ``errno`` variable is set 173*4882a593Smuzhiyunappropriately. The generic error codes are described at the 174*4882a593Smuzhiyun:ref:`Generic Error Codes <gen-errors>` chapter. 175*4882a593Smuzhiyun 176*4882a593SmuzhiyunEINVAL 177*4882a593Smuzhiyun Given buffer type ``type`` or the selection target ``target`` is not 178*4882a593Smuzhiyun supported, or the ``flags`` argument is not valid. 179*4882a593Smuzhiyun 180*4882a593SmuzhiyunERANGE 181*4882a593Smuzhiyun It is not possible to adjust struct :c:type:`v4l2_rect` 182*4882a593Smuzhiyun ``r`` rectangle to satisfy all constraints given in the ``flags`` 183*4882a593Smuzhiyun argument. 184*4882a593Smuzhiyun 185*4882a593SmuzhiyunENODATA 186*4882a593Smuzhiyun Selection is not supported for this input or output. 187*4882a593Smuzhiyun 188*4882a593SmuzhiyunEBUSY 189*4882a593Smuzhiyun It is not possible to apply change of the selection rectangle at the 190*4882a593Smuzhiyun moment. Usually because streaming is in progress. 191