162306a36Sopenharmony_ci.. SPDX-License-Identifier: GFDL-1.1-no-invariants-or-later
262306a36Sopenharmony_ci.. c:namespace:: V4L
362306a36Sopenharmony_ci
462306a36Sopenharmony_ci.. _VIDIOC_SUBDEV_G_CROP:
562306a36Sopenharmony_ci
662306a36Sopenharmony_ci************************************************
762306a36Sopenharmony_ciioctl VIDIOC_SUBDEV_G_CROP, VIDIOC_SUBDEV_S_CROP
862306a36Sopenharmony_ci************************************************
962306a36Sopenharmony_ci
1062306a36Sopenharmony_ciName
1162306a36Sopenharmony_ci====
1262306a36Sopenharmony_ci
1362306a36Sopenharmony_ciVIDIOC_SUBDEV_G_CROP - VIDIOC_SUBDEV_S_CROP - Get or set the crop rectangle on a subdev pad
1462306a36Sopenharmony_ci
1562306a36Sopenharmony_ciSynopsis
1662306a36Sopenharmony_ci========
1762306a36Sopenharmony_ci
1862306a36Sopenharmony_ci.. c:macro:: VIDIOC_SUBDEV_G_CROP
1962306a36Sopenharmony_ci
2062306a36Sopenharmony_ci``int ioctl(int fd, VIDIOC_SUBDEV_G_CROP, struct v4l2_subdev_crop *argp)``
2162306a36Sopenharmony_ci
2262306a36Sopenharmony_ci.. c:macro:: VIDIOC_SUBDEV_S_CROP
2362306a36Sopenharmony_ci
2462306a36Sopenharmony_ci``int ioctl(int fd, VIDIOC_SUBDEV_S_CROP, const struct v4l2_subdev_crop *argp)``
2562306a36Sopenharmony_ci
2662306a36Sopenharmony_ciArguments
2762306a36Sopenharmony_ci=========
2862306a36Sopenharmony_ci
2962306a36Sopenharmony_ci``fd``
3062306a36Sopenharmony_ci    File descriptor returned by :c:func:`open()`.
3162306a36Sopenharmony_ci
3262306a36Sopenharmony_ci``argp``
3362306a36Sopenharmony_ci    Pointer to struct :c:type:`v4l2_subdev_crop`.
3462306a36Sopenharmony_ci
3562306a36Sopenharmony_ciDescription
3662306a36Sopenharmony_ci===========
3762306a36Sopenharmony_ci
3862306a36Sopenharmony_ci.. note::
3962306a36Sopenharmony_ci
4062306a36Sopenharmony_ci    This is an :ref:`obsolete` interface and may be removed
4162306a36Sopenharmony_ci    in the future. It is superseded by
4262306a36Sopenharmony_ci    :ref:`the selection API <VIDIOC_SUBDEV_G_SELECTION>`.
4362306a36Sopenharmony_ci
4462306a36Sopenharmony_ciTo retrieve the current crop rectangle applications set the ``pad``
4562306a36Sopenharmony_cifield of a struct :c:type:`v4l2_subdev_crop` to the
4662306a36Sopenharmony_cidesired pad number as reported by the media API and the ``which`` field
4762306a36Sopenharmony_cito ``V4L2_SUBDEV_FORMAT_ACTIVE``. They then call the
4862306a36Sopenharmony_ci``VIDIOC_SUBDEV_G_CROP`` ioctl with a pointer to this structure. The
4962306a36Sopenharmony_cidriver fills the members of the ``rect`` field or returns ``EINVAL`` error
5062306a36Sopenharmony_cicode if the input arguments are invalid, or if cropping is not supported
5162306a36Sopenharmony_cion the given pad.
5262306a36Sopenharmony_ci
5362306a36Sopenharmony_ciTo change the current crop rectangle applications set both the ``pad``
5462306a36Sopenharmony_ciand ``which`` fields and all members of the ``rect`` field. They then
5562306a36Sopenharmony_cicall the ``VIDIOC_SUBDEV_S_CROP`` ioctl with a pointer to this
5662306a36Sopenharmony_cistructure. The driver verifies the requested crop rectangle, adjusts it
5762306a36Sopenharmony_cibased on the hardware capabilities and configures the device. Upon
5862306a36Sopenharmony_cireturn the struct :c:type:`v4l2_subdev_crop`
5962306a36Sopenharmony_cicontains the current format as would be returned by a
6062306a36Sopenharmony_ci``VIDIOC_SUBDEV_G_CROP`` call.
6162306a36Sopenharmony_ci
6262306a36Sopenharmony_ciApplications can query the device capabilities by setting the ``which``
6362306a36Sopenharmony_cito ``V4L2_SUBDEV_FORMAT_TRY``. When set, 'try' crop rectangles are not
6462306a36Sopenharmony_ciapplied to the device by the driver, but are mangled exactly as active
6562306a36Sopenharmony_cicrop rectangles and stored in the sub-device file handle. Two
6662306a36Sopenharmony_ciapplications querying the same sub-device would thus not interact with
6762306a36Sopenharmony_cieach other.
6862306a36Sopenharmony_ci
6962306a36Sopenharmony_ciIf the subdev device node has been registered in read-only mode, calls to
7062306a36Sopenharmony_ci``VIDIOC_SUBDEV_S_CROP`` are only valid if the ``which`` field is set to
7162306a36Sopenharmony_ci``V4L2_SUBDEV_FORMAT_TRY``, otherwise an error is returned and the errno
7262306a36Sopenharmony_civariable is set to ``-EPERM``.
7362306a36Sopenharmony_ci
7462306a36Sopenharmony_ciDrivers must not return an error solely because the requested crop
7562306a36Sopenharmony_cirectangle doesn't match the device capabilities. They must instead
7662306a36Sopenharmony_cimodify the rectangle to match what the hardware can provide. The
7762306a36Sopenharmony_cimodified format should be as close as possible to the original request.
7862306a36Sopenharmony_ci
7962306a36Sopenharmony_ci.. c:type:: v4l2_subdev_crop
8062306a36Sopenharmony_ci
8162306a36Sopenharmony_ci.. tabularcolumns:: |p{4.4cm}|p{4.4cm}|p{8.5cm}|
8262306a36Sopenharmony_ci
8362306a36Sopenharmony_ci.. flat-table:: struct v4l2_subdev_crop
8462306a36Sopenharmony_ci    :header-rows:  0
8562306a36Sopenharmony_ci    :stub-columns: 0
8662306a36Sopenharmony_ci    :widths:       1 1 2
8762306a36Sopenharmony_ci
8862306a36Sopenharmony_ci    * - __u32
8962306a36Sopenharmony_ci      - ``pad``
9062306a36Sopenharmony_ci      - Pad number as reported by the media framework.
9162306a36Sopenharmony_ci    * - __u32
9262306a36Sopenharmony_ci      - ``which``
9362306a36Sopenharmony_ci      - Crop rectangle to get or set, from enum
9462306a36Sopenharmony_ci	:ref:`v4l2_subdev_format_whence <v4l2-subdev-format-whence>`.
9562306a36Sopenharmony_ci    * - struct :c:type:`v4l2_rect`
9662306a36Sopenharmony_ci      - ``rect``
9762306a36Sopenharmony_ci      - Crop rectangle boundaries, in pixels.
9862306a36Sopenharmony_ci    * - __u32
9962306a36Sopenharmony_ci      - ``stream``
10062306a36Sopenharmony_ci      - Stream identifier.
10162306a36Sopenharmony_ci    * - __u32
10262306a36Sopenharmony_ci      - ``reserved``\ [7]
10362306a36Sopenharmony_ci      - Reserved for future extensions. Applications and drivers must set
10462306a36Sopenharmony_ci	the array to zero.
10562306a36Sopenharmony_ci
10662306a36Sopenharmony_ciReturn Value
10762306a36Sopenharmony_ci============
10862306a36Sopenharmony_ci
10962306a36Sopenharmony_ciOn success 0 is returned, on error -1 and the ``errno`` variable is set
11062306a36Sopenharmony_ciappropriately. The generic error codes are described at the
11162306a36Sopenharmony_ci:ref:`Generic Error Codes <gen-errors>` chapter.
11262306a36Sopenharmony_ci
11362306a36Sopenharmony_ciEBUSY
11462306a36Sopenharmony_ci    The crop rectangle can't be changed because the pad is currently
11562306a36Sopenharmony_ci    busy. This can be caused, for instance, by an active video stream on
11662306a36Sopenharmony_ci    the pad. The ioctl must not be retried without performing another
11762306a36Sopenharmony_ci    action to fix the problem first. Only returned by
11862306a36Sopenharmony_ci    ``VIDIOC_SUBDEV_S_CROP``
11962306a36Sopenharmony_ci
12062306a36Sopenharmony_ciEINVAL
12162306a36Sopenharmony_ci    The struct :c:type:`v4l2_subdev_crop` ``pad``
12262306a36Sopenharmony_ci    references a non-existing pad, the ``which`` field references a
12362306a36Sopenharmony_ci    non-existing format, or cropping is not supported on the given
12462306a36Sopenharmony_ci    subdev pad.
12562306a36Sopenharmony_ci
12662306a36Sopenharmony_ciEPERM
12762306a36Sopenharmony_ci    The ``VIDIOC_SUBDEV_S_CROP`` ioctl has been called on a read-only subdevice
12862306a36Sopenharmony_ci    and the ``which`` field is set to ``V4L2_SUBDEV_FORMAT_ACTIVE``.
129