VIDIOC_G_SELECTION - VIDIOC_S_SELECTION - Get or set one of the selection rectangles
argp
The ioctls are used to query and configure selection rectangles.
To query the cropping (composing) rectangle set struct v4l2_selection type field to the respective buffer type. Do not use the multiplanar buffer types. Use V4L2_BUF_TYPE_VIDEO_CAPTURE instead of V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE and use V4L2_BUF_TYPE_VIDEO_OUTPUT instead of V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE. The next step is setting the value of struct v4l2_selection target field to V4L2_SEL_TGT_CROP (V4L2_SEL_TGT_COMPOSE). Please refer to table Common selection definitions or API for cropping, composing and scaling for additional targets. The flags and reserved fields of struct v4l2_selection 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, the struct v4l2_rect r rectangle 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 the struct v4l2_selection type field 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 the value of struct v4l2_selection target to V4L2_SEL_TGT_CROP (V4L2_SEL_TGT_COMPOSE). Please refer to table Common selection definitions or API for cropping, composing and scaling for additional targets. The struct v4l2_rect r rectangle need to be set to the desired active area. Field struct v4l2_selection reserved is ignored and must be filled with zeros. The driver may adjust coordinates of the requested rectangle. An application may introduce constraints to control rounding behaviour. The struct v4l2_selection flags field must be set to one of the following:
Please refer to 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:
On success the struct v4l2_rect r field 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.
Selection targets and flags are documented in Common selection definitions.
__u32 | type | Type of the buffer (from enum v4l2_buf_type). |
__u32 | target | Used to select between cropping and composing rectangles. |
__u32 | flags | Flags controlling the selection rectangle adjustments, refer to selection flags. |
struct v4l2_rect | r | The selection rectangle. |
__u32 | reserved[9] | Reserved fields for future use. Drivers and applications must zero this array. |
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.