18c2ecf20Sopenharmony_ci.. SPDX-License-Identifier: GFDL-1.1-no-invariants-or-later 28c2ecf20Sopenharmony_ci.. c:namespace:: V4L 38c2ecf20Sopenharmony_ci 48c2ecf20Sopenharmony_ci.. _VIDIOC_G_SELECTION: 58c2ecf20Sopenharmony_ci 68c2ecf20Sopenharmony_ci******************************************** 78c2ecf20Sopenharmony_ciioctl VIDIOC_G_SELECTION, VIDIOC_S_SELECTION 88c2ecf20Sopenharmony_ci******************************************** 98c2ecf20Sopenharmony_ci 108c2ecf20Sopenharmony_ciName 118c2ecf20Sopenharmony_ci==== 128c2ecf20Sopenharmony_ci 138c2ecf20Sopenharmony_ciVIDIOC_G_SELECTION - VIDIOC_S_SELECTION - Get or set one of the selection rectangles 148c2ecf20Sopenharmony_ci 158c2ecf20Sopenharmony_ciSynopsis 168c2ecf20Sopenharmony_ci======== 178c2ecf20Sopenharmony_ci 188c2ecf20Sopenharmony_ci.. c:macro:: VIDIOC_G_SELECTION 198c2ecf20Sopenharmony_ci 208c2ecf20Sopenharmony_ci``int ioctl(int fd, VIDIOC_G_SELECTION, struct v4l2_selection *argp)`` 218c2ecf20Sopenharmony_ci 228c2ecf20Sopenharmony_ci.. c:macro:: VIDIOC_S_SELECTION 238c2ecf20Sopenharmony_ci 248c2ecf20Sopenharmony_ci``int ioctl(int fd, VIDIOC_S_SELECTION, struct v4l2_selection *argp)`` 258c2ecf20Sopenharmony_ci 268c2ecf20Sopenharmony_ciArguments 278c2ecf20Sopenharmony_ci========= 288c2ecf20Sopenharmony_ci 298c2ecf20Sopenharmony_ci``fd`` 308c2ecf20Sopenharmony_ci File descriptor returned by :c:func:`open()`. 318c2ecf20Sopenharmony_ci 328c2ecf20Sopenharmony_ci``argp`` 338c2ecf20Sopenharmony_ci Pointer to struct :c:type:`v4l2_selection`. 348c2ecf20Sopenharmony_ci 358c2ecf20Sopenharmony_ciDescription 368c2ecf20Sopenharmony_ci=========== 378c2ecf20Sopenharmony_ci 388c2ecf20Sopenharmony_ciThe ioctls are used to query and configure selection rectangles. 398c2ecf20Sopenharmony_ci 408c2ecf20Sopenharmony_ciTo query the cropping (composing) rectangle set struct 418c2ecf20Sopenharmony_ci:c:type:`v4l2_selection` ``type`` field to the 428c2ecf20Sopenharmony_cirespective buffer type. The next step is setting the 438c2ecf20Sopenharmony_civalue of struct :c:type:`v4l2_selection` ``target`` 448c2ecf20Sopenharmony_cifield to ``V4L2_SEL_TGT_CROP`` (``V4L2_SEL_TGT_COMPOSE``). Please refer 458c2ecf20Sopenharmony_cito table :ref:`v4l2-selections-common` or :ref:`selection-api` for 468c2ecf20Sopenharmony_ciadditional targets. The ``flags`` and ``reserved`` fields of struct 478c2ecf20Sopenharmony_ci:c:type:`v4l2_selection` are ignored and they must be 488c2ecf20Sopenharmony_cifilled with zeros. The driver fills the rest of the structure or returns 498c2ecf20Sopenharmony_ciEINVAL error code if incorrect buffer type or target was used. If 508c2ecf20Sopenharmony_cicropping (composing) is not supported then the active rectangle is not 518c2ecf20Sopenharmony_cimutable and it is always equal to the bounds rectangle. Finally, the 528c2ecf20Sopenharmony_cistruct :c:type:`v4l2_rect` ``r`` rectangle is filled with 538c2ecf20Sopenharmony_cithe current cropping (composing) coordinates. The coordinates are 548c2ecf20Sopenharmony_ciexpressed in driver-dependent units. The only exception are rectangles 558c2ecf20Sopenharmony_cifor images in raw formats, whose coordinates are always expressed in 568c2ecf20Sopenharmony_cipixels. 578c2ecf20Sopenharmony_ci 588c2ecf20Sopenharmony_ciTo change the cropping (composing) rectangle set the struct 598c2ecf20Sopenharmony_ci:c:type:`v4l2_selection` ``type`` field to the 608c2ecf20Sopenharmony_cirespective buffer type. The next step is setting the 618c2ecf20Sopenharmony_civalue of struct :c:type:`v4l2_selection` ``target`` to 628c2ecf20Sopenharmony_ci``V4L2_SEL_TGT_CROP`` (``V4L2_SEL_TGT_COMPOSE``). Please refer to table 638c2ecf20Sopenharmony_ci:ref:`v4l2-selections-common` or :ref:`selection-api` for additional 648c2ecf20Sopenharmony_citargets. The struct :c:type:`v4l2_rect` ``r`` rectangle need 658c2ecf20Sopenharmony_cito be set to the desired active area. Field struct 668c2ecf20Sopenharmony_ci:c:type:`v4l2_selection` ``reserved`` is ignored and 678c2ecf20Sopenharmony_cimust be filled with zeros. The driver may adjust coordinates of the 688c2ecf20Sopenharmony_cirequested rectangle. An application may introduce constraints to control 698c2ecf20Sopenharmony_cirounding behaviour. The struct :c:type:`v4l2_selection` 708c2ecf20Sopenharmony_ci``flags`` field must be set to one of the following: 718c2ecf20Sopenharmony_ci 728c2ecf20Sopenharmony_ci- ``0`` - The driver can adjust the rectangle size freely and shall 738c2ecf20Sopenharmony_ci choose a crop/compose rectangle as close as possible to the requested 748c2ecf20Sopenharmony_ci one. 758c2ecf20Sopenharmony_ci 768c2ecf20Sopenharmony_ci- ``V4L2_SEL_FLAG_GE`` - The driver is not allowed to shrink the 778c2ecf20Sopenharmony_ci rectangle. The original rectangle must lay inside the adjusted one. 788c2ecf20Sopenharmony_ci 798c2ecf20Sopenharmony_ci- ``V4L2_SEL_FLAG_LE`` - The driver is not allowed to enlarge the 808c2ecf20Sopenharmony_ci rectangle. The adjusted rectangle must lay inside the original one. 818c2ecf20Sopenharmony_ci 828c2ecf20Sopenharmony_ci- ``V4L2_SEL_FLAG_GE | V4L2_SEL_FLAG_LE`` - The driver must choose the 838c2ecf20Sopenharmony_ci size exactly the same as in the requested rectangle. 848c2ecf20Sopenharmony_ci 858c2ecf20Sopenharmony_ciPlease refer to :ref:`sel-const-adjust`. 868c2ecf20Sopenharmony_ci 878c2ecf20Sopenharmony_ciThe driver may have to adjusts the requested dimensions against hardware 888c2ecf20Sopenharmony_cilimits and other parts as the pipeline, i.e. the bounds given by the 898c2ecf20Sopenharmony_cicapture/output window or TV display. The closest possible values of 908c2ecf20Sopenharmony_cihorizontal and vertical offset and sizes are chosen according to 918c2ecf20Sopenharmony_cifollowing priority: 928c2ecf20Sopenharmony_ci 938c2ecf20Sopenharmony_ci1. Satisfy constraints from struct 948c2ecf20Sopenharmony_ci :c:type:`v4l2_selection` ``flags``. 958c2ecf20Sopenharmony_ci 968c2ecf20Sopenharmony_ci2. Adjust width, height, left, and top to hardware limits and 978c2ecf20Sopenharmony_ci alignments. 988c2ecf20Sopenharmony_ci 998c2ecf20Sopenharmony_ci3. Keep center of adjusted rectangle as close as possible to the 1008c2ecf20Sopenharmony_ci original one. 1018c2ecf20Sopenharmony_ci 1028c2ecf20Sopenharmony_ci4. Keep width and height as close as possible to original ones. 1038c2ecf20Sopenharmony_ci 1048c2ecf20Sopenharmony_ci5. Keep horizontal and vertical offset as close as possible to original 1058c2ecf20Sopenharmony_ci ones. 1068c2ecf20Sopenharmony_ci 1078c2ecf20Sopenharmony_ciOn success the struct :c:type:`v4l2_rect` ``r`` field 1088c2ecf20Sopenharmony_cicontains the adjusted rectangle. When the parameters are unsuitable the 1098c2ecf20Sopenharmony_ciapplication may modify the cropping (composing) or image parameters and 1108c2ecf20Sopenharmony_cirepeat the cycle until satisfactory parameters have been negotiated. If 1118c2ecf20Sopenharmony_ciconstraints flags have to be violated at then ``ERANGE`` is returned. The 1128c2ecf20Sopenharmony_cierror indicates that *there exist no rectangle* that satisfies the 1138c2ecf20Sopenharmony_ciconstraints. 1148c2ecf20Sopenharmony_ci 1158c2ecf20Sopenharmony_ciSelection targets and flags are documented in 1168c2ecf20Sopenharmony_ci:ref:`v4l2-selections-common`. 1178c2ecf20Sopenharmony_ci 1188c2ecf20Sopenharmony_ci.. _sel-const-adjust: 1198c2ecf20Sopenharmony_ci 1208c2ecf20Sopenharmony_ci.. kernel-figure:: constraints.svg 1218c2ecf20Sopenharmony_ci :alt: constraints.svg 1228c2ecf20Sopenharmony_ci :align: center 1238c2ecf20Sopenharmony_ci 1248c2ecf20Sopenharmony_ci Size adjustments with constraint flags. 1258c2ecf20Sopenharmony_ci 1268c2ecf20Sopenharmony_ci Behaviour of rectangle adjustment for different constraint flags. 1278c2ecf20Sopenharmony_ci 1288c2ecf20Sopenharmony_ci 1298c2ecf20Sopenharmony_ci 1308c2ecf20Sopenharmony_ci.. c:type:: v4l2_selection 1318c2ecf20Sopenharmony_ci 1328c2ecf20Sopenharmony_ci.. tabularcolumns:: |p{4.4cm}|p{4.4cm}|p{8.7cm}| 1338c2ecf20Sopenharmony_ci 1348c2ecf20Sopenharmony_ci.. flat-table:: struct v4l2_selection 1358c2ecf20Sopenharmony_ci :header-rows: 0 1368c2ecf20Sopenharmony_ci :stub-columns: 0 1378c2ecf20Sopenharmony_ci :widths: 1 1 2 1388c2ecf20Sopenharmony_ci 1398c2ecf20Sopenharmony_ci * - __u32 1408c2ecf20Sopenharmony_ci - ``type`` 1418c2ecf20Sopenharmony_ci - Type of the buffer (from enum 1428c2ecf20Sopenharmony_ci :c:type:`v4l2_buf_type`). 1438c2ecf20Sopenharmony_ci * - __u32 1448c2ecf20Sopenharmony_ci - ``target`` 1458c2ecf20Sopenharmony_ci - Used to select between 1468c2ecf20Sopenharmony_ci :ref:`cropping and composing rectangles <v4l2-selections-common>`. 1478c2ecf20Sopenharmony_ci * - __u32 1488c2ecf20Sopenharmony_ci - ``flags`` 1498c2ecf20Sopenharmony_ci - Flags controlling the selection rectangle adjustments, refer to 1508c2ecf20Sopenharmony_ci :ref:`selection flags <v4l2-selection-flags>`. 1518c2ecf20Sopenharmony_ci * - struct :c:type:`v4l2_rect` 1528c2ecf20Sopenharmony_ci - ``r`` 1538c2ecf20Sopenharmony_ci - The selection rectangle. 1548c2ecf20Sopenharmony_ci * - __u32 1558c2ecf20Sopenharmony_ci - ``reserved[9]`` 1568c2ecf20Sopenharmony_ci - Reserved fields for future use. Drivers and applications must zero 1578c2ecf20Sopenharmony_ci this array. 1588c2ecf20Sopenharmony_ci 1598c2ecf20Sopenharmony_ci.. note:: 1608c2ecf20Sopenharmony_ci Unfortunately in the case of multiplanar buffer types 1618c2ecf20Sopenharmony_ci (``V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE`` and ``V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE``) 1628c2ecf20Sopenharmony_ci this API was messed up with regards to how the :c:type:`v4l2_selection` ``type`` field 1638c2ecf20Sopenharmony_ci should be filled in. Some drivers only accepted the ``_MPLANE`` buffer type while 1648c2ecf20Sopenharmony_ci other drivers only accepted a non-multiplanar buffer type (i.e. without the 1658c2ecf20Sopenharmony_ci ``_MPLANE`` at the end). 1668c2ecf20Sopenharmony_ci 1678c2ecf20Sopenharmony_ci Starting with kernel 4.13 both variations are allowed. 1688c2ecf20Sopenharmony_ci 1698c2ecf20Sopenharmony_ciReturn Value 1708c2ecf20Sopenharmony_ci============ 1718c2ecf20Sopenharmony_ci 1728c2ecf20Sopenharmony_ciOn success 0 is returned, on error -1 and the ``errno`` variable is set 1738c2ecf20Sopenharmony_ciappropriately. The generic error codes are described at the 1748c2ecf20Sopenharmony_ci:ref:`Generic Error Codes <gen-errors>` chapter. 1758c2ecf20Sopenharmony_ci 1768c2ecf20Sopenharmony_ciEINVAL 1778c2ecf20Sopenharmony_ci Given buffer type ``type`` or the selection target ``target`` is not 1788c2ecf20Sopenharmony_ci supported, or the ``flags`` argument is not valid. 1798c2ecf20Sopenharmony_ci 1808c2ecf20Sopenharmony_ciERANGE 1818c2ecf20Sopenharmony_ci It is not possible to adjust struct :c:type:`v4l2_rect` 1828c2ecf20Sopenharmony_ci ``r`` rectangle to satisfy all constraints given in the ``flags`` 1838c2ecf20Sopenharmony_ci argument. 1848c2ecf20Sopenharmony_ci 1858c2ecf20Sopenharmony_ciENODATA 1868c2ecf20Sopenharmony_ci Selection is not supported for this input or output. 1878c2ecf20Sopenharmony_ci 1888c2ecf20Sopenharmony_ciEBUSY 1898c2ecf20Sopenharmony_ci It is not possible to apply change of the selection rectangle at the 1908c2ecf20Sopenharmony_ci moment. Usually because streaming is in progress. 191