xref: /linux/Documentation/userspace-api/media/v4l/vidioc-subdev-g-selection.rst (revision fea13a6935c79896a53a8ede32b0b6f6bce5042c)
1059b1c5bSMauro Carvalho Chehab.. SPDX-License-Identifier: GFDL-1.1-no-invariants-or-later
2407e84cdSMauro Carvalho Chehab.. c:namespace:: V4L
354f38fcaSMauro Carvalho Chehab
454f38fcaSMauro Carvalho Chehab.. _VIDIOC_SUBDEV_G_SELECTION:
554f38fcaSMauro Carvalho Chehab
654f38fcaSMauro Carvalho Chehab**********************************************************
754f38fcaSMauro Carvalho Chehabioctl VIDIOC_SUBDEV_G_SELECTION, VIDIOC_SUBDEV_S_SELECTION
854f38fcaSMauro Carvalho Chehab**********************************************************
954f38fcaSMauro Carvalho Chehab
1054f38fcaSMauro Carvalho ChehabName
1154f38fcaSMauro Carvalho Chehab====
1254f38fcaSMauro Carvalho Chehab
1354f38fcaSMauro Carvalho ChehabVIDIOC_SUBDEV_G_SELECTION - VIDIOC_SUBDEV_S_SELECTION - Get or set selection rectangles on a subdev pad
1454f38fcaSMauro Carvalho Chehab
1554f38fcaSMauro Carvalho ChehabSynopsis
1654f38fcaSMauro Carvalho Chehab========
1754f38fcaSMauro Carvalho Chehab
18407e84cdSMauro Carvalho Chehab.. c:macro:: VIDIOC_SUBDEV_G_SELECTION
1954f38fcaSMauro Carvalho Chehab
20407e84cdSMauro Carvalho Chehab``int ioctl(int fd, VIDIOC_SUBDEV_G_SELECTION, struct v4l2_subdev_selection *argp)``
2154f38fcaSMauro Carvalho Chehab
22407e84cdSMauro Carvalho Chehab.. c:macro:: VIDIOC_SUBDEV_S_SELECTION
23407e84cdSMauro Carvalho Chehab
24407e84cdSMauro Carvalho Chehab``int ioctl(int fd, VIDIOC_SUBDEV_S_SELECTION, struct v4l2_subdev_selection *argp)``
2554f38fcaSMauro Carvalho Chehab
2654f38fcaSMauro Carvalho ChehabArguments
2754f38fcaSMauro Carvalho Chehab=========
2854f38fcaSMauro Carvalho Chehab
2954f38fcaSMauro Carvalho Chehab``fd``
30407e84cdSMauro Carvalho Chehab    File descriptor returned by :c:func:`open()`.
3154f38fcaSMauro Carvalho Chehab
3254f38fcaSMauro Carvalho Chehab``argp``
3354f38fcaSMauro Carvalho Chehab    Pointer to struct :c:type:`v4l2_subdev_selection`.
3454f38fcaSMauro Carvalho Chehab
3554f38fcaSMauro Carvalho ChehabDescription
3654f38fcaSMauro Carvalho Chehab===========
3754f38fcaSMauro Carvalho Chehab
3854f38fcaSMauro Carvalho ChehabThe selections are used to configure various image processing
3954f38fcaSMauro Carvalho Chehabfunctionality performed by the subdevs which affect the image size. This
4054f38fcaSMauro Carvalho Chehabcurrently includes cropping, scaling and composition.
4154f38fcaSMauro Carvalho Chehab
4254f38fcaSMauro Carvalho ChehabThe selection API replaces
4354f38fcaSMauro Carvalho Chehab:ref:`the old subdev crop API <VIDIOC_SUBDEV_G_CROP>`. All the
4454f38fcaSMauro Carvalho Chehabfunction of the crop API, and more, are supported by the selections API.
4554f38fcaSMauro Carvalho Chehab
4654f38fcaSMauro Carvalho ChehabSee :ref:`subdev` for more information on how each selection target
4754f38fcaSMauro Carvalho Chehabaffects the image processing pipeline inside the subdevice.
4854f38fcaSMauro Carvalho Chehab
493fb0ee8bSJacopo MondiIf the subdev device node has been registered in read-only mode, calls to
503fb0ee8bSJacopo Mondi``VIDIOC_SUBDEV_S_SELECTION`` are only valid if the ``which`` field is set to
513fb0ee8bSJacopo Mondi``V4L2_SUBDEV_FORMAT_TRY``, otherwise an error is returned and the errno
523fb0ee8bSJacopo Mondivariable is set to ``-EPERM``.
5354f38fcaSMauro Carvalho Chehab
5454f38fcaSMauro Carvalho ChehabTypes of selection targets
5554f38fcaSMauro Carvalho Chehab--------------------------
5654f38fcaSMauro Carvalho Chehab
5754f38fcaSMauro Carvalho ChehabThere are two types of selection targets: actual and bounds. The actual
5854f38fcaSMauro Carvalho Chehabtargets are the targets which configure the hardware. The BOUNDS target
5954f38fcaSMauro Carvalho Chehabwill return a rectangle that contain all possible actual rectangles.
6054f38fcaSMauro Carvalho Chehab
6154f38fcaSMauro Carvalho ChehabDiscovering supported features
6254f38fcaSMauro Carvalho Chehab------------------------------
6354f38fcaSMauro Carvalho Chehab
6454f38fcaSMauro Carvalho ChehabTo discover which targets are supported, the user can perform
6554f38fcaSMauro Carvalho Chehab``VIDIOC_SUBDEV_G_SELECTION`` on them. Any unsupported target will
6654f38fcaSMauro Carvalho Chehabreturn ``EINVAL``.
6754f38fcaSMauro Carvalho Chehab
6854f38fcaSMauro Carvalho ChehabSelection targets and flags are documented in
6954f38fcaSMauro Carvalho Chehab:ref:`v4l2-selections-common`.
7054f38fcaSMauro Carvalho Chehab
7154f38fcaSMauro Carvalho Chehab.. c:type:: v4l2_subdev_selection
7254f38fcaSMauro Carvalho Chehab
73*fea13a69SMauro Carvalho Chehab.. tabularcolumns:: |p{4.4cm}|p{4.4cm}|p{8.5cm}|
7454f38fcaSMauro Carvalho Chehab
7554f38fcaSMauro Carvalho Chehab.. flat-table:: struct v4l2_subdev_selection
7654f38fcaSMauro Carvalho Chehab    :header-rows:  0
7754f38fcaSMauro Carvalho Chehab    :stub-columns: 0
7854f38fcaSMauro Carvalho Chehab    :widths:       1 1 2
7954f38fcaSMauro Carvalho Chehab
8054f38fcaSMauro Carvalho Chehab    * - __u32
8154f38fcaSMauro Carvalho Chehab      - ``which``
8254f38fcaSMauro Carvalho Chehab      - Active or try selection, from enum
8354f38fcaSMauro Carvalho Chehab	:ref:`v4l2_subdev_format_whence <v4l2-subdev-format-whence>`.
8454f38fcaSMauro Carvalho Chehab    * - __u32
8554f38fcaSMauro Carvalho Chehab      - ``pad``
8654f38fcaSMauro Carvalho Chehab      - Pad number as reported by the media framework.
8754f38fcaSMauro Carvalho Chehab    * - __u32
8854f38fcaSMauro Carvalho Chehab      - ``target``
8954f38fcaSMauro Carvalho Chehab      - Target selection rectangle. See :ref:`v4l2-selections-common`.
9054f38fcaSMauro Carvalho Chehab    * - __u32
9154f38fcaSMauro Carvalho Chehab      - ``flags``
9254f38fcaSMauro Carvalho Chehab      - Flags. See :ref:`v4l2-selection-flags`.
9354f38fcaSMauro Carvalho Chehab    * - struct :c:type:`v4l2_rect`
9454f38fcaSMauro Carvalho Chehab      - ``r``
9554f38fcaSMauro Carvalho Chehab      - Selection rectangle, in pixels.
9654f38fcaSMauro Carvalho Chehab    * - __u32
9754f38fcaSMauro Carvalho Chehab      - ``reserved``\ [8]
9854f38fcaSMauro Carvalho Chehab      - Reserved for future extensions. Applications and drivers must set
9954f38fcaSMauro Carvalho Chehab	the array to zero.
10054f38fcaSMauro Carvalho Chehab
10154f38fcaSMauro Carvalho ChehabReturn Value
10254f38fcaSMauro Carvalho Chehab============
10354f38fcaSMauro Carvalho Chehab
10454f38fcaSMauro Carvalho ChehabOn success 0 is returned, on error -1 and the ``errno`` variable is set
10554f38fcaSMauro Carvalho Chehabappropriately. The generic error codes are described at the
10654f38fcaSMauro Carvalho Chehab:ref:`Generic Error Codes <gen-errors>` chapter.
10754f38fcaSMauro Carvalho Chehab
10854f38fcaSMauro Carvalho ChehabEBUSY
10954f38fcaSMauro Carvalho Chehab    The selection rectangle can't be changed because the pad is
11054f38fcaSMauro Carvalho Chehab    currently busy. This can be caused, for instance, by an active video
11154f38fcaSMauro Carvalho Chehab    stream on the pad. The ioctl must not be retried without performing
11254f38fcaSMauro Carvalho Chehab    another action to fix the problem first. Only returned by
11354f38fcaSMauro Carvalho Chehab    ``VIDIOC_SUBDEV_S_SELECTION``
11454f38fcaSMauro Carvalho Chehab
11554f38fcaSMauro Carvalho ChehabEINVAL
11654f38fcaSMauro Carvalho Chehab    The struct :c:type:`v4l2_subdev_selection`
11754f38fcaSMauro Carvalho Chehab    ``pad`` references a non-existing pad, the ``which`` field
11854f38fcaSMauro Carvalho Chehab    references a non-existing format, or the selection target is not
11954f38fcaSMauro Carvalho Chehab    supported on the given subdev pad.
1203fb0ee8bSJacopo Mondi
1213fb0ee8bSJacopo MondiEPERM
1223fb0ee8bSJacopo Mondi    The ``VIDIOC_SUBDEV_S_SELECTION`` ioctl has been called on a read-only
1233fb0ee8bSJacopo Mondi    subdevice and the ``which`` field is set to ``V4L2_SUBDEV_FORMAT_ACTIVE``.
124