162306a36Sopenharmony_ci.. SPDX-License-Identifier: GFDL-1.1-no-invariants-or-later 262306a36Sopenharmony_ci.. c:namespace:: V4L 362306a36Sopenharmony_ci 462306a36Sopenharmony_ci.. _VIDIOC_G_SELECTION: 562306a36Sopenharmony_ci 662306a36Sopenharmony_ci******************************************** 762306a36Sopenharmony_ciioctl VIDIOC_G_SELECTION, VIDIOC_S_SELECTION 862306a36Sopenharmony_ci******************************************** 962306a36Sopenharmony_ci 1062306a36Sopenharmony_ciName 1162306a36Sopenharmony_ci==== 1262306a36Sopenharmony_ci 1362306a36Sopenharmony_ciVIDIOC_G_SELECTION - VIDIOC_S_SELECTION - Get or set one of the selection rectangles 1462306a36Sopenharmony_ci 1562306a36Sopenharmony_ciSynopsis 1662306a36Sopenharmony_ci======== 1762306a36Sopenharmony_ci 1862306a36Sopenharmony_ci.. c:macro:: VIDIOC_G_SELECTION 1962306a36Sopenharmony_ci 2062306a36Sopenharmony_ci``int ioctl(int fd, VIDIOC_G_SELECTION, struct v4l2_selection *argp)`` 2162306a36Sopenharmony_ci 2262306a36Sopenharmony_ci.. c:macro:: VIDIOC_S_SELECTION 2362306a36Sopenharmony_ci 2462306a36Sopenharmony_ci``int ioctl(int fd, VIDIOC_S_SELECTION, struct v4l2_selection *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_selection`. 3462306a36Sopenharmony_ci 3562306a36Sopenharmony_ciDescription 3662306a36Sopenharmony_ci=========== 3762306a36Sopenharmony_ci 3862306a36Sopenharmony_ciThe ioctls are used to query and configure selection rectangles. 3962306a36Sopenharmony_ci 4062306a36Sopenharmony_ciTo query the cropping (composing) rectangle set struct 4162306a36Sopenharmony_ci:c:type:`v4l2_selection` ``type`` field to the 4262306a36Sopenharmony_cirespective buffer type. The next step is setting the 4362306a36Sopenharmony_civalue of struct :c:type:`v4l2_selection` ``target`` 4462306a36Sopenharmony_cifield to ``V4L2_SEL_TGT_CROP`` (``V4L2_SEL_TGT_COMPOSE``). Please refer 4562306a36Sopenharmony_cito table :ref:`v4l2-selections-common` or :ref:`selection-api` for 4662306a36Sopenharmony_ciadditional targets. The ``flags`` and ``reserved`` fields of struct 4762306a36Sopenharmony_ci:c:type:`v4l2_selection` are ignored and they must be 4862306a36Sopenharmony_cifilled with zeros. The driver fills the rest of the structure or returns 4962306a36Sopenharmony_ciEINVAL error code if incorrect buffer type or target was used. If 5062306a36Sopenharmony_cicropping (composing) is not supported then the active rectangle is not 5162306a36Sopenharmony_cimutable and it is always equal to the bounds rectangle. Finally, the 5262306a36Sopenharmony_cistruct :c:type:`v4l2_rect` ``r`` rectangle is filled with 5362306a36Sopenharmony_cithe current cropping (composing) coordinates. The coordinates are 5462306a36Sopenharmony_ciexpressed in driver-dependent units. The only exception are rectangles 5562306a36Sopenharmony_cifor images in raw formats, whose coordinates are always expressed in 5662306a36Sopenharmony_cipixels. 5762306a36Sopenharmony_ci 5862306a36Sopenharmony_ciTo change the cropping (composing) rectangle set the struct 5962306a36Sopenharmony_ci:c:type:`v4l2_selection` ``type`` field to the 6062306a36Sopenharmony_cirespective buffer type. The next step is setting the 6162306a36Sopenharmony_civalue of struct :c:type:`v4l2_selection` ``target`` to 6262306a36Sopenharmony_ci``V4L2_SEL_TGT_CROP`` (``V4L2_SEL_TGT_COMPOSE``). Please refer to table 6362306a36Sopenharmony_ci:ref:`v4l2-selections-common` or :ref:`selection-api` for additional 6462306a36Sopenharmony_citargets. The struct :c:type:`v4l2_rect` ``r`` rectangle need 6562306a36Sopenharmony_cito be set to the desired active area. Field struct 6662306a36Sopenharmony_ci:c:type:`v4l2_selection` ``reserved`` is ignored and 6762306a36Sopenharmony_cimust be filled with zeros. The driver may adjust coordinates of the 6862306a36Sopenharmony_cirequested rectangle. An application may introduce constraints to control 6962306a36Sopenharmony_cirounding behaviour. The struct :c:type:`v4l2_selection` 7062306a36Sopenharmony_ci``flags`` field must be set to one of the following: 7162306a36Sopenharmony_ci 7262306a36Sopenharmony_ci- ``0`` - The driver can adjust the rectangle size freely and shall 7362306a36Sopenharmony_ci choose a crop/compose rectangle as close as possible to the requested 7462306a36Sopenharmony_ci one. 7562306a36Sopenharmony_ci 7662306a36Sopenharmony_ci- ``V4L2_SEL_FLAG_GE`` - The driver is not allowed to shrink the 7762306a36Sopenharmony_ci rectangle. The original rectangle must lay inside the adjusted one. 7862306a36Sopenharmony_ci 7962306a36Sopenharmony_ci- ``V4L2_SEL_FLAG_LE`` - The driver is not allowed to enlarge the 8062306a36Sopenharmony_ci rectangle. The adjusted rectangle must lay inside the original one. 8162306a36Sopenharmony_ci 8262306a36Sopenharmony_ci- ``V4L2_SEL_FLAG_GE | V4L2_SEL_FLAG_LE`` - The driver must choose the 8362306a36Sopenharmony_ci size exactly the same as in the requested rectangle. 8462306a36Sopenharmony_ci 8562306a36Sopenharmony_ciPlease refer to :ref:`sel-const-adjust`. 8662306a36Sopenharmony_ci 8762306a36Sopenharmony_ciThe driver may have to adjusts the requested dimensions against hardware 8862306a36Sopenharmony_cilimits and other parts as the pipeline, i.e. the bounds given by the 8962306a36Sopenharmony_cicapture/output window or TV display. The closest possible values of 9062306a36Sopenharmony_cihorizontal and vertical offset and sizes are chosen according to 9162306a36Sopenharmony_cifollowing priority: 9262306a36Sopenharmony_ci 9362306a36Sopenharmony_ci1. Satisfy constraints from struct 9462306a36Sopenharmony_ci :c:type:`v4l2_selection` ``flags``. 9562306a36Sopenharmony_ci 9662306a36Sopenharmony_ci2. Adjust width, height, left, and top to hardware limits and 9762306a36Sopenharmony_ci alignments. 9862306a36Sopenharmony_ci 9962306a36Sopenharmony_ci3. Keep center of adjusted rectangle as close as possible to the 10062306a36Sopenharmony_ci original one. 10162306a36Sopenharmony_ci 10262306a36Sopenharmony_ci4. Keep width and height as close as possible to original ones. 10362306a36Sopenharmony_ci 10462306a36Sopenharmony_ci5. Keep horizontal and vertical offset as close as possible to original 10562306a36Sopenharmony_ci ones. 10662306a36Sopenharmony_ci 10762306a36Sopenharmony_ciOn success the struct :c:type:`v4l2_rect` ``r`` field 10862306a36Sopenharmony_cicontains the adjusted rectangle. When the parameters are unsuitable the 10962306a36Sopenharmony_ciapplication may modify the cropping (composing) or image parameters and 11062306a36Sopenharmony_cirepeat the cycle until satisfactory parameters have been negotiated. If 11162306a36Sopenharmony_ciconstraints flags have to be violated at then ``ERANGE`` is returned. The 11262306a36Sopenharmony_cierror indicates that *there exist no rectangle* that satisfies the 11362306a36Sopenharmony_ciconstraints. 11462306a36Sopenharmony_ci 11562306a36Sopenharmony_ciSelection targets and flags are documented in 11662306a36Sopenharmony_ci:ref:`v4l2-selections-common`. 11762306a36Sopenharmony_ci 11862306a36Sopenharmony_ci.. _sel-const-adjust: 11962306a36Sopenharmony_ci 12062306a36Sopenharmony_ci.. kernel-figure:: constraints.svg 12162306a36Sopenharmony_ci :alt: constraints.svg 12262306a36Sopenharmony_ci :align: center 12362306a36Sopenharmony_ci 12462306a36Sopenharmony_ci Size adjustments with constraint flags. 12562306a36Sopenharmony_ci 12662306a36Sopenharmony_ci Behaviour of rectangle adjustment for different constraint flags. 12762306a36Sopenharmony_ci 12862306a36Sopenharmony_ci 12962306a36Sopenharmony_ci 13062306a36Sopenharmony_ci.. c:type:: v4l2_selection 13162306a36Sopenharmony_ci 13262306a36Sopenharmony_ci.. tabularcolumns:: |p{4.4cm}|p{4.4cm}|p{8.5cm}| 13362306a36Sopenharmony_ci 13462306a36Sopenharmony_ci.. flat-table:: struct v4l2_selection 13562306a36Sopenharmony_ci :header-rows: 0 13662306a36Sopenharmony_ci :stub-columns: 0 13762306a36Sopenharmony_ci :widths: 1 1 2 13862306a36Sopenharmony_ci 13962306a36Sopenharmony_ci * - __u32 14062306a36Sopenharmony_ci - ``type`` 14162306a36Sopenharmony_ci - Type of the buffer (from enum 14262306a36Sopenharmony_ci :c:type:`v4l2_buf_type`). 14362306a36Sopenharmony_ci * - __u32 14462306a36Sopenharmony_ci - ``target`` 14562306a36Sopenharmony_ci - Used to select between 14662306a36Sopenharmony_ci :ref:`cropping and composing rectangles <v4l2-selections-common>`. 14762306a36Sopenharmony_ci * - __u32 14862306a36Sopenharmony_ci - ``flags`` 14962306a36Sopenharmony_ci - Flags controlling the selection rectangle adjustments, refer to 15062306a36Sopenharmony_ci :ref:`selection flags <v4l2-selection-flags>`. 15162306a36Sopenharmony_ci * - struct :c:type:`v4l2_rect` 15262306a36Sopenharmony_ci - ``r`` 15362306a36Sopenharmony_ci - The selection rectangle. 15462306a36Sopenharmony_ci * - __u32 15562306a36Sopenharmony_ci - ``reserved[9]`` 15662306a36Sopenharmony_ci - Reserved fields for future use. Drivers and applications must zero 15762306a36Sopenharmony_ci this array. 15862306a36Sopenharmony_ci 15962306a36Sopenharmony_ci.. note:: 16062306a36Sopenharmony_ci Unfortunately in the case of multiplanar buffer types 16162306a36Sopenharmony_ci (``V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE`` and ``V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE``) 16262306a36Sopenharmony_ci this API was messed up with regards to how the :c:type:`v4l2_selection` ``type`` field 16362306a36Sopenharmony_ci should be filled in. Some drivers only accepted the ``_MPLANE`` buffer type while 16462306a36Sopenharmony_ci other drivers only accepted a non-multiplanar buffer type (i.e. without the 16562306a36Sopenharmony_ci ``_MPLANE`` at the end). 16662306a36Sopenharmony_ci 16762306a36Sopenharmony_ci Starting with kernel 4.13 both variations are allowed. 16862306a36Sopenharmony_ci 16962306a36Sopenharmony_ciReturn Value 17062306a36Sopenharmony_ci============ 17162306a36Sopenharmony_ci 17262306a36Sopenharmony_ciOn success 0 is returned, on error -1 and the ``errno`` variable is set 17362306a36Sopenharmony_ciappropriately. The generic error codes are described at the 17462306a36Sopenharmony_ci:ref:`Generic Error Codes <gen-errors>` chapter. 17562306a36Sopenharmony_ci 17662306a36Sopenharmony_ciEINVAL 17762306a36Sopenharmony_ci Given buffer type ``type`` or the selection target ``target`` is not 17862306a36Sopenharmony_ci supported, or the ``flags`` argument is not valid. 17962306a36Sopenharmony_ci 18062306a36Sopenharmony_ciERANGE 18162306a36Sopenharmony_ci It is not possible to adjust struct :c:type:`v4l2_rect` 18262306a36Sopenharmony_ci ``r`` rectangle to satisfy all constraints given in the ``flags`` 18362306a36Sopenharmony_ci argument. 18462306a36Sopenharmony_ci 18562306a36Sopenharmony_ciENODATA 18662306a36Sopenharmony_ci Selection is not supported for this input or output. 18762306a36Sopenharmony_ci 18862306a36Sopenharmony_ciEBUSY 18962306a36Sopenharmony_ci It is not possible to apply change of the selection rectangle at the 19062306a36Sopenharmony_ci moment. Usually because streaming is in progress. 191