VIDIOC_G_SELECTION, VIDIOC_S_SELECTION — Get or set one of the selection rectangles
int fsfuncioctl( | int fd, |
int request, | |
struct v4l2_selection *argp) ; |
This is an experimental interface and may change in the future.
The ioctls are used to query and configure selection rectangles.
To query the cropping (composing) rectangle set
struct v4l2_selection::type
to the respective buffer type. Do not
use multiplanar buffers. Use V4L2_BUF_TYPE_VIDEO_CAPTURE
instead of V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE
. Use V4L2_BUF_TYPE_VIDEO_OUTPUT
instead of
V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE
. The next step is
setting struct v4l2_selection::target
to value
V4L2_SEL_TGT_CROP_ACTIVE
(
V4L2_SEL_TGT_COMPOSE_ACTIVE
). Please refer to table Table A.72, “Selection targets.” or the section called “Experimental API for cropping, composing and scaling” for additional
targets. Fields struct v4l2_selection::flags
and
struct v4l2_selection::reserved
are ignored and they
must be filled with zeros. The driver fills the rest of the structure or
returns EINVAL error code if incorrect buffer type or target was used. If cropping
(composing) is not supported then the active rectangle is not mutable and it is
always equal to the bounds rectangle. Finally, structure
struct v4l2_selection::r
is filled with the current cropping
(composing) coordinates. The coordinates are expressed in driver-dependent
units. The only exception are rectangles for images in raw formats, whose
coordinates are always expressed in pixels.
To change the cropping (composing) rectangle set
struct v4l2_selection::type
to the respective buffer type. Do not
use multiplanar buffers. Use V4L2_BUF_TYPE_VIDEO_CAPTURE
instead of V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE
. Use V4L2_BUF_TYPE_VIDEO_OUTPUT
instead of
V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE
. The next step is
setting struct v4l2_selection::target
to value
V4L2_SEL_TGT_CROP_ACTIVE
(
V4L2_SEL_TGT_COMPOSE_ACTIVE
). Please refer to table Table A.72, “Selection targets.” or the section called “Experimental API for cropping, composing and scaling” for additional
targets. Set desired active area into the field
struct v4l2_selection::r
. Field
struct v4l2_selection::reserved
is ignored and must be filled with
zeros. The driver may adjust the rectangle coordinates. An application may
introduce constraints to control rounding behaviour. Set the field
struct v4l2_selection::flags
to one of values:
0
- The driver can adjust the rectangle size freely
and shall choose a crop/compose rectangle as close as possible to the requested
one.
V4L2_SEL_FLAG_GE
- The driver is not allowed to
shrink the rectangle. The original rectangle must lay inside the adjusted
one.
V4L2_SEL_FLAG_LE
- The driver is not allowed to
enlarge the rectangle. The adjusted rectangle must lay inside the original
one.
V4L2_SEL_FLAG_GE | V4L2_SEL_FLAG_LE
- The driver
must choose the size exactly the same as in the requested rectangle.
Please refer to Figure A.1, “Size adjustments with constraint flags.”.
The driver may have to adjusts the requested dimensions against hardware limits and other parts as the pipeline, i.e. the bounds given by the capture/output window or TV display. The closest possible values of horizontal and vertical offset and sizes are chosen according to following priority:
Satisfy constraints from struct v4l2_selection::flags
.
Adjust width, height, left, and top to hardware limits and alignments.
Keep center of adjusted rectangle as close as possible to the original one.
Keep width and height as close as possible to original ones.
Keep horizontal and vertical offset as close as possible to original ones.
On success the field struct v4l2_selection::r
contains
the adjusted rectangle. When the parameters are unsuitable the application may
modify the cropping (composing) or image parameters and repeat the cycle until
satisfactory parameters have been negotiated. If constraints flags have to be
violated at then ERANGE is returned. The error indicates that there
exist no rectangle that satisfies the constraints.
Table A.72. Selection targets.
V4L2_SEL_TGT_CROP_ACTIVE | 0 | area that is currently cropped by hardware |
V4L2_SEL_TGT_CROP_DEFAULT | 1 | suggested cropping rectangle that covers the "whole picture" |
V4L2_SEL_TGT_CROP_BOUNDS | 2 | limits for the cropping rectangle |
V4L2_SEL_TGT_COMPOSE_ACTIVE | 256 | area to which data are composed by hardware |
V4L2_SEL_TGT_COMPOSE_DEFAULT | 257 | suggested composing rectangle that covers the "whole picture" |
V4L2_SEL_TGT_COMPOSE_BOUNDS | 258 | limits for the composing rectangle |
V4L2_SEL_TGT_COMPOSE_PADDED | 259 | the active area and all padding pixels that are inserted or modified by the hardware |
Table A.73. Selection constraint flags
V4L2_SEL_FLAG_GE | 0x00000001 | indicate that adjusted rectangle must contain a rectangle from struct v4l2_selection::r |
V4L2_SEL_FLAG_LE | 0x00000002 | indicate that adjusted rectangle must be inside a rectangle from struct v4l2_selection::r |
Table A.74. struct v4l2_selection
__u32 | type | Type of the buffer (from enum v4l2_buf_type) |
__u32 | target | used to select between cropping and composing rectangles |
__u32 | flags | control over coordinates adjustments, refer to selection flags |
struct v4l2_rect | r | selection rectangle |
__u32 | reserved[9] | Reserved fields for future use |
On success 0 is returned, on error -1 and the errno
variable is set appropriately. The generic error codes are described at the Generic Error Codes chapter.
The buffer struct v4l2_selection::type
or struct v4l2_selection::target
is not supported, or
the struct v4l2_selection::flags
are invalid.
it is not possible to adjust a rectangle
struct v4l2_selection::r
that satisfies all contraints from
struct v4l2_selection::flags
.
it is not possible to apply change of selection rectangle at the moment. Usually because streaming is in progress.