요약·해설과 원문, 전문 번역을 서로 분리했습니다. API 이름, symbol, source path는 원문 표기를 사용합니다.
1. 요약·해설
원문의 핵심 논리와 kernel programming 관점의 보충 설명입니다. 아래의 전문 번역과는 별도로 작성했습니다.
2. 영어 원문 전체
번역 기준이 된 Linux v6.18.37 원문입니다. 줄 번호는 이 버전의 파일 좌표입니다.
원문 전체 펼치기
.. SPDX-License-Identifier: GFDL-1.1-no-invariants-or-later
.. c:namespace:: V4L
.. _VIDIOC_G_SELECTION:
********************************************
ioctl VIDIOC_G_SELECTION, VIDIOC_S_SELECTION
********************************************
Name
====
VIDIOC_G_SELECTION - VIDIOC_S_SELECTION - Get or set one of the selection rectangles
Synopsis
========
.. c:macro:: VIDIOC_G_SELECTION
``int ioctl(int fd, VIDIOC_G_SELECTION, struct v4l2_selection *argp)``
.. c:macro:: VIDIOC_S_SELECTION
``int ioctl(int fd, VIDIOC_S_SELECTION, struct v4l2_selection *argp)``
Arguments
=========
``fd``
File descriptor returned by :c:func:`open()`.
``argp``
Pointer to struct :c:type:`v4l2_selection`.
Description
===========
The ioctls are used to query and configure selection rectangles.
To query the cropping (composing) rectangle set struct
:c:type:`v4l2_selection` ``type`` field to the
respective buffer type. The next step is setting the
value of struct :c:type:`v4l2_selection` ``target``
field to ``V4L2_SEL_TGT_CROP`` (``V4L2_SEL_TGT_COMPOSE``). Please refer
to table :ref:`v4l2-selections-common` or :ref:`selection-api` for
additional targets. The ``flags`` and ``reserved`` fields of struct
:c:type:`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 :c:type:`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
:c:type:`v4l2_selection` ``type`` field to the
respective buffer type. The next step is setting the
value of struct :c:type:`v4l2_selection` ``target`` to
``V4L2_SEL_TGT_CROP`` (``V4L2_SEL_TGT_COMPOSE``). Please refer to table
:ref:`v4l2-selections-common` or :ref:`selection-api` for additional
targets. The struct :c:type:`v4l2_rect` ``r`` rectangle need
to be set to the desired active area. Field struct
:c:type:`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 :c:type:`v4l2_selection`
``flags`` field must be set to one of the following:
- ``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 :ref:`sel-const-adjust`.
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:
1. Satisfy constraints from struct
:c:type:`v4l2_selection` ``flags``.
2. Adjust width, height, left, and top to hardware limits and
alignments.
3. Keep center of adjusted rectangle as close as possible to the
original one.
4. Keep width and height as close as possible to original ones.
5. Keep horizontal and vertical offset as close as possible to original
ones.
On success the struct :c:type:`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
:ref:`v4l2-selections-common`.
.. _sel-const-adjust:
.. kernel-figure:: constraints.svg
:alt: constraints.svg
:align: center
Size adjustments with constraint flags.
Behaviour of rectangle adjustment for different constraint flags.
.. c:type:: v4l2_selection
.. tabularcolumns:: |p{4.4cm}|p{4.4cm}|p{8.5cm}|
.. flat-table:: struct v4l2_selection
:header-rows: 0
:stub-columns: 0
:widths: 1 1 2
* - __u32
- ``type``
- Type of the buffer (from enum
:c:type:`v4l2_buf_type`).
* - __u32
- ``target``
- Used to select between
:ref:`cropping and composing rectangles <v4l2-selections-common>`.
* - __u32
- ``flags``
- Flags controlling the selection rectangle adjustments, refer to
:ref:`selection flags <v4l2-selection-flags>`.
* - struct :c:type:`v4l2_rect`
- ``r``
- The selection rectangle.
* - __u32
- ``reserved[9]``
- Reserved fields for future use. Drivers and applications must zero
this array.
.. note::
Unfortunately in the case of multiplanar buffer types
(``V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE`` and ``V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE``)
this API was messed up with regards to how the :c:type:`v4l2_selection` ``type`` field
should be filled in. Some drivers only accepted the ``_MPLANE`` buffer type while
other drivers only accepted a non-multiplanar buffer type (i.e. without the
``_MPLANE`` at the end).
Starting with kernel 4.13 both variations are allowed.
Return Value
============
On success 0 is returned, on error -1 and the ``errno`` variable is set
appropriately. The generic error codes are described at the
:ref:`Generic Error Codes <gen-errors>` chapter.
EINVAL
Given buffer type ``type`` or the selection target ``target`` is not
supported, or the ``flags`` argument is not valid.
ERANGE
It is not possible to adjust struct :c:type:`v4l2_rect`
``r`` rectangle to satisfy all constraints given in the ``flags``
argument.
ENODATA
Selection is not supported for this input or output.
EBUSY
It is not possible to apply change of the selection rectangle at the
moment. Usually because streaming is in progress.
3. 한국어 전문 번역
영어 원문의 문단 순서와 의미를 유지한 전체 번역입니다. 코드, 함수명, symbol과 URL은 원문 표기를 유지합니다.
목적, 호출 형식과 인자
1-34`VIDIOC_G_SELECTION`과 `VIDIOC_S_SELECTION`은 cropping·composing 등 selection rectangle을 조회하거나 설정합니다. 두 명령은 `struct v4l2_selection *argp`를 사용합니다.
`fd`는 `open()`이 반환한 파일 디스크립터이며 구조체는 buffer type, selection target, 조정 flag와 `v4l2_rect`를 담습니다.
.. SPDX-License-Identifier: GFDL-1.1-no-invariants-or-later
.. c:namespace:: V4L
.. _VIDIOC_G_SELECTION:
********************************************
ioctl VIDIOC_G_SELECTION, VIDIOC_S_SELECTION
********************************************
Name
====
VIDIOC_G_SELECTION - VIDIOC_S_SELECTION - Get or set one of the selection rectangles
Synopsis
========
.. c:macro:: VIDIOC_G_SELECTION
``int ioctl(int fd, VIDIOC_G_SELECTION, struct v4l2_selection *argp)``
.. c:macro:: VIDIOC_S_SELECTION
``int ioctl(int fd, VIDIOC_S_SELECTION, struct v4l2_selection *argp)``
Arguments
=========
``fd``
File descriptor returned by :c:func:`open()`.
``argp``
Pointer to struct :c:type:`v4l2_selection`.
selection rectangle 조회
35-57crop 또는 compose rectangle을 조회하려면 `type`을 해당 buffer type, `target`을 `V4L2_SEL_TGT_CROP` 또는 `V4L2_SEL_TGT_COMPOSE`로 설정합니다. 추가 target은 공통 selection 표와 Selection API 문서에 정의됩니다.
조회에서는 `flags`와 `reserved`가 무시되지만 반드시 0으로 채워야 합니다. 잘못된 buffer type 또는 target이면 `EINVAL`입니다.
cropping 또는 composing을 지원하지 않으면 active rectangle은 변경할 수 없고 항상 bounds rectangle과 같습니다. 성공하면 현재 좌표가 `r`에 돌아옵니다.
좌표 단위는 드라이버에 따라 다릅니다. 예외적으로 raw format 영상의 rectangle 좌표는 항상 pixel 단위입니다.
Description
===========
The ioctls are used to query and configure selection rectangles.
To query the cropping (composing) rectangle set struct
:c:type:`v4l2_selection` ``type`` field to the
respective buffer type. The next step is setting the
value of struct :c:type:`v4l2_selection` ``target``
field to ``V4L2_SEL_TGT_CROP`` (``V4L2_SEL_TGT_COMPOSE``). Please refer
to table :ref:`v4l2-selections-common` or :ref:`selection-api` for
additional targets. The ``flags`` and ``reserved`` fields of struct
:c:type:`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 :c:type:`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.
rectangle 설정, 제약과 조정 순서
58-116설정할 때도 `type`과 `target`을 지정하고 원하는 active area를 `r`에 넣으며 `reserved`를 0으로 만듭니다. 드라이버는 하드웨어와 pipeline 제약에 맞춰 요청 좌표를 조정할 수 있습니다.
rectangle 크기를 반올림·정렬할 때 허용되는 방향을 제한합니다.
조정은 하드웨어 한계뿐 아니라 capture·output window나 TV display가 정하는 bounds 등 pipeline의 다른 요소도 고려합니다.
드라이버는 아래 순서대로 가장 가까운 유효 rectangle을 선택합니다.
성공하면 조정된 rectangle이 `r`에 반환됩니다. 적합하지 않으면 crop·compose 또는 영상 매개변수를 수정해 만족할 때까지 협상을 반복할 수 있습니다.
constraint flag를 지키는 rectangle이 하나도 없으면 `ERANGE`입니다. 단순히 요청값이 조정됐다는 뜻이 아니라 모든 제약을 동시에 만족하는 rectangle이 존재하지 않는다는 뜻입니다.
To change the cropping (composing) rectangle set the struct
:c:type:`v4l2_selection` ``type`` field to the
respective buffer type. The next step is setting the
value of struct :c:type:`v4l2_selection` ``target`` to
``V4L2_SEL_TGT_CROP`` (``V4L2_SEL_TGT_COMPOSE``). Please refer to table
:ref:`v4l2-selections-common` or :ref:`selection-api` for additional
targets. The struct :c:type:`v4l2_rect` ``r`` rectangle need
to be set to the desired active area. Field struct
:c:type:`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 :c:type:`v4l2_selection`
``flags`` field must be set to one of the following:
- ``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 :ref:`sel-const-adjust`.
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:
1. Satisfy constraints from struct
:c:type:`v4l2_selection` ``flags``.
2. Adjust width, height, left, and top to hardware limits and
alignments.
3. Keep center of adjusted rectangle as close as possible to the
original one.
4. Keep width and height as close as possible to original ones.
5. Keep horizontal and vertical offset as close as possible to original
ones.
On success the struct :c:type:`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
:ref:`v4l2-selections-common`.
제약 flag에 따른 크기 조정 도식
117-129원문의 `constraints.svg` 도식은 `GE`, `LE`, 두 flag의 결합에 따라 요청 rectangle과 조정 rectangle의 포함 관계가 어떻게 달라지는지 보여 줍니다.
원본 R과 조정 결과 A의 크기 관계입니다.
.. _sel-const-adjust:
.. kernel-figure:: constraints.svg
:alt: constraints.svg
:align: center
Size adjustments with constraint flags.
Behaviour of rectangle adjustment for different constraint flags.
struct v4l2_selection과 MPLANE 호환
130-168selection 대상과 조정 결과 rectangle을 전달합니다.
multi-planar buffer type의 `type` 처리에는 역사적 불일치가 있습니다. 일부 드라이버는 `_MPLANE` type만, 다른 드라이버는 접미사가 없는 non-multiplanar type만 받았습니다.
Linux kernel 4.13부터 `V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE`·`V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE`과 대응 non-multiplanar 변형을 모두 허용합니다.
.. c:type:: v4l2_selection
.. tabularcolumns:: |p{4.4cm}|p{4.4cm}|p{8.5cm}|
.. flat-table:: struct v4l2_selection
:header-rows: 0
:stub-columns: 0
:widths: 1 1 2
* - __u32
- ``type``
- Type of the buffer (from enum
:c:type:`v4l2_buf_type`).
* - __u32
- ``target``
- Used to select between
:ref:`cropping and composing rectangles <v4l2-selections-common>`.
* - __u32
- ``flags``
- Flags controlling the selection rectangle adjustments, refer to
:ref:`selection flags <v4l2-selection-flags>`.
* - struct :c:type:`v4l2_rect`
- ``r``
- The selection rectangle.
* - __u32
- ``reserved[9]``
- Reserved fields for future use. Drivers and applications must zero
this array.
.. note::
Unfortunately in the case of multiplanar buffer types
(``V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE`` and ``V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE``)
this API was messed up with regards to how the :c:type:`v4l2_selection` ``type`` field
should be filled in. Some drivers only accepted the ``_MPLANE`` buffer type while
other drivers only accepted a non-multiplanar buffer type (i.e. without the
``_MPLANE`` at the end).
Starting with kernel 4.13 both variations are allowed.
반환값과 오류
169-190성공하면 0을 반환합니다. 오류가 발생하면 -1을 반환하고 `errno`를 설정하며 Generic Error Codes 장의 공통 오류도 적용됩니다.
type·target·flag와 현재 streaming 상태에 따른 오류입니다.
Return Value
============
On success 0 is returned, on error -1 and the ``errno`` variable is set
appropriately. The generic error codes are described at the
:ref:`Generic Error Codes <gen-errors>` chapter.
EINVAL
Given buffer type ``type`` or the selection target ``target`` is not
supported, or the ``flags`` argument is not valid.
ERANGE
It is not possible to adjust struct :c:type:`v4l2_rect`
``r`` rectangle to satisfy all constraints given in the ``flags``
argument.
ENODATA
Selection is not supported for this input or output.
EBUSY
It is not possible to apply change of the selection rectangle at the
moment. Usually because streaming is in progress.
요약·해설
vidioc-g-selection.rst:1-190selection rectangle과 조정 constraint 및 오류 협상을 다룹니다.