1*4882a593Smuzhiyun.. SPDX-License-Identifier: GFDL-1.1-no-invariants-or-later 2*4882a593Smuzhiyun.. c:namespace:: V4L 3*4882a593Smuzhiyun 4*4882a593Smuzhiyun.. _VIDIOC_SUBDEV_G_CROP: 5*4882a593Smuzhiyun 6*4882a593Smuzhiyun************************************************ 7*4882a593Smuzhiyunioctl VIDIOC_SUBDEV_G_CROP, VIDIOC_SUBDEV_S_CROP 8*4882a593Smuzhiyun************************************************ 9*4882a593Smuzhiyun 10*4882a593SmuzhiyunName 11*4882a593Smuzhiyun==== 12*4882a593Smuzhiyun 13*4882a593SmuzhiyunVIDIOC_SUBDEV_G_CROP - VIDIOC_SUBDEV_S_CROP - Get or set the crop rectangle on a subdev pad 14*4882a593Smuzhiyun 15*4882a593SmuzhiyunSynopsis 16*4882a593Smuzhiyun======== 17*4882a593Smuzhiyun 18*4882a593Smuzhiyun.. c:macro:: VIDIOC_SUBDEV_G_CROP 19*4882a593Smuzhiyun 20*4882a593Smuzhiyun``int ioctl(int fd, VIDIOC_SUBDEV_G_CROP, struct v4l2_subdev_crop *argp)`` 21*4882a593Smuzhiyun 22*4882a593Smuzhiyun.. c:macro:: VIDIOC_SUBDEV_S_CROP 23*4882a593Smuzhiyun 24*4882a593Smuzhiyun``int ioctl(int fd, VIDIOC_SUBDEV_S_CROP, const struct v4l2_subdev_crop *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_subdev_crop`. 34*4882a593Smuzhiyun 35*4882a593SmuzhiyunDescription 36*4882a593Smuzhiyun=========== 37*4882a593Smuzhiyun 38*4882a593Smuzhiyun.. note:: 39*4882a593Smuzhiyun 40*4882a593Smuzhiyun This is an :ref:`obsolete` interface and may be removed 41*4882a593Smuzhiyun in the future. It is superseded by 42*4882a593Smuzhiyun :ref:`the selection API <VIDIOC_SUBDEV_G_SELECTION>`. 43*4882a593Smuzhiyun 44*4882a593SmuzhiyunTo retrieve the current crop rectangle applications set the ``pad`` 45*4882a593Smuzhiyunfield of a struct :c:type:`v4l2_subdev_crop` to the 46*4882a593Smuzhiyundesired pad number as reported by the media API and the ``which`` field 47*4882a593Smuzhiyunto ``V4L2_SUBDEV_FORMAT_ACTIVE``. They then call the 48*4882a593Smuzhiyun``VIDIOC_SUBDEV_G_CROP`` ioctl with a pointer to this structure. The 49*4882a593Smuzhiyundriver fills the members of the ``rect`` field or returns ``EINVAL`` error 50*4882a593Smuzhiyuncode if the input arguments are invalid, or if cropping is not supported 51*4882a593Smuzhiyunon the given pad. 52*4882a593Smuzhiyun 53*4882a593SmuzhiyunTo change the current crop rectangle applications set both the ``pad`` 54*4882a593Smuzhiyunand ``which`` fields and all members of the ``rect`` field. They then 55*4882a593Smuzhiyuncall the ``VIDIOC_SUBDEV_S_CROP`` ioctl with a pointer to this 56*4882a593Smuzhiyunstructure. The driver verifies the requested crop rectangle, adjusts it 57*4882a593Smuzhiyunbased on the hardware capabilities and configures the device. Upon 58*4882a593Smuzhiyunreturn the struct :c:type:`v4l2_subdev_crop` 59*4882a593Smuzhiyuncontains the current format as would be returned by a 60*4882a593Smuzhiyun``VIDIOC_SUBDEV_G_CROP`` call. 61*4882a593Smuzhiyun 62*4882a593SmuzhiyunApplications can query the device capabilities by setting the ``which`` 63*4882a593Smuzhiyunto ``V4L2_SUBDEV_FORMAT_TRY``. When set, 'try' crop rectangles are not 64*4882a593Smuzhiyunapplied to the device by the driver, but are mangled exactly as active 65*4882a593Smuzhiyuncrop rectangles and stored in the sub-device file handle. Two 66*4882a593Smuzhiyunapplications querying the same sub-device would thus not interact with 67*4882a593Smuzhiyuneach other. 68*4882a593Smuzhiyun 69*4882a593SmuzhiyunIf the subdev device node has been registered in read-only mode, calls to 70*4882a593Smuzhiyun``VIDIOC_SUBDEV_S_CROP`` are only valid if the ``which`` field is set to 71*4882a593Smuzhiyun``V4L2_SUBDEV_FORMAT_TRY``, otherwise an error is returned and the errno 72*4882a593Smuzhiyunvariable is set to ``-EPERM``. 73*4882a593Smuzhiyun 74*4882a593SmuzhiyunDrivers must not return an error solely because the requested crop 75*4882a593Smuzhiyunrectangle doesn't match the device capabilities. They must instead 76*4882a593Smuzhiyunmodify the rectangle to match what the hardware can provide. The 77*4882a593Smuzhiyunmodified format should be as close as possible to the original request. 78*4882a593Smuzhiyun 79*4882a593Smuzhiyun.. c:type:: v4l2_subdev_crop 80*4882a593Smuzhiyun 81*4882a593Smuzhiyun.. tabularcolumns:: |p{4.4cm}|p{4.4cm}|p{8.7cm}| 82*4882a593Smuzhiyun 83*4882a593Smuzhiyun.. flat-table:: struct v4l2_subdev_crop 84*4882a593Smuzhiyun :header-rows: 0 85*4882a593Smuzhiyun :stub-columns: 0 86*4882a593Smuzhiyun :widths: 1 1 2 87*4882a593Smuzhiyun 88*4882a593Smuzhiyun * - __u32 89*4882a593Smuzhiyun - ``pad`` 90*4882a593Smuzhiyun - Pad number as reported by the media framework. 91*4882a593Smuzhiyun * - __u32 92*4882a593Smuzhiyun - ``which`` 93*4882a593Smuzhiyun - Crop rectangle to get or set, from enum 94*4882a593Smuzhiyun :ref:`v4l2_subdev_format_whence <v4l2-subdev-format-whence>`. 95*4882a593Smuzhiyun * - struct :c:type:`v4l2_rect` 96*4882a593Smuzhiyun - ``rect`` 97*4882a593Smuzhiyun - Crop rectangle boundaries, in pixels. 98*4882a593Smuzhiyun * - __u32 99*4882a593Smuzhiyun - ``reserved``\ [8] 100*4882a593Smuzhiyun - Reserved for future extensions. Applications and drivers must set 101*4882a593Smuzhiyun the array to zero. 102*4882a593Smuzhiyun 103*4882a593SmuzhiyunReturn Value 104*4882a593Smuzhiyun============ 105*4882a593Smuzhiyun 106*4882a593SmuzhiyunOn success 0 is returned, on error -1 and the ``errno`` variable is set 107*4882a593Smuzhiyunappropriately. The generic error codes are described at the 108*4882a593Smuzhiyun:ref:`Generic Error Codes <gen-errors>` chapter. 109*4882a593Smuzhiyun 110*4882a593SmuzhiyunEBUSY 111*4882a593Smuzhiyun The crop rectangle can't be changed because the pad is currently 112*4882a593Smuzhiyun busy. This can be caused, for instance, by an active video stream on 113*4882a593Smuzhiyun the pad. The ioctl must not be retried without performing another 114*4882a593Smuzhiyun action to fix the problem first. Only returned by 115*4882a593Smuzhiyun ``VIDIOC_SUBDEV_S_CROP`` 116*4882a593Smuzhiyun 117*4882a593SmuzhiyunEINVAL 118*4882a593Smuzhiyun The struct :c:type:`v4l2_subdev_crop` ``pad`` 119*4882a593Smuzhiyun references a non-existing pad, the ``which`` field references a 120*4882a593Smuzhiyun non-existing format, or cropping is not supported on the given 121*4882a593Smuzhiyun subdev pad. 122*4882a593Smuzhiyun 123*4882a593SmuzhiyunEPERM 124*4882a593Smuzhiyun The ``VIDIOC_SUBDEV_S_CROP`` ioctl has been called on a read-only subdevice 125*4882a593Smuzhiyun and the ``which`` field is set to ``V4L2_SUBDEV_FORMAT_ACTIVE``. 126