← Documents Documentation/userspace-api/media/v4l/vidioc-subdev-g-crop.rst GitHub 원문 ↗

Linux 6.18.37 · 사용자 공간 API

VIDIOC_SUBDEV_G_CROP 및 VIDIOC_SUBDEV_S_CROP ioctl

폐기 예정인 서브디바이스 crop API의 ACTIVE·TRY 처리, 조정 규칙과 오류를 설명합니다.

Source pathDocumentation/userspace-api/media/v4l/vidioc-subdev-g-crop.rst
Source versionLinux v6.18.37
TranslationDUJINLABS 전문 번역 + 해설

요약·해설과 원문, 전문 번역을 서로 분리했습니다. API 이름, symbol, source path는 원문 표기를 사용합니다.

1. 요약·해설

원문의 핵심 논리와 kernel programming 관점의 보충 설명입니다. 아래의 전문 번역과는 별도로 작성했습니다.

요약·해설

vidioc-subdev-g-crop.rst:1-127

새 구현은 selection API를 사용해야 하며, 기존 crop API를 다룰 때도 요청값이 아니라 드라이버가 조정해 반환한 사각형을 실제 결과로 취급해야 합니다.

2. 영어 원문 전체

번역 기준이 된 Linux v6.18.37 원문입니다. 줄 번호는 이 버전의 파일 좌표입니다.

원문 전체 펼치기
1 .. SPDX-License-Identifier: GFDL-1.1-no-invariants-or-later
2 .. c:namespace:: V4L
3
4 .. _VIDIOC_SUBDEV_G_CROP:
5
6 ************************************************
7 ioctl VIDIOC_SUBDEV_G_CROP, VIDIOC_SUBDEV_S_CROP
8 ************************************************
9
10 Name
11 ====
12
13 VIDIOC_SUBDEV_G_CROP - VIDIOC_SUBDEV_S_CROP - Get or set the crop rectangle on a subdev pad
14
15 Synopsis
16 ========
17
18 .. c:macro:: VIDIOC_SUBDEV_G_CROP
19
20 ``int ioctl(int fd, VIDIOC_SUBDEV_G_CROP, struct v4l2_subdev_crop *argp)``
21
22 .. c:macro:: VIDIOC_SUBDEV_S_CROP
23
24 ``int ioctl(int fd, VIDIOC_SUBDEV_S_CROP, const struct v4l2_subdev_crop *argp)``
25
26 Arguments
27 =========
28
29 ``fd``
30 File descriptor returned by :c:func:`open()`.
31
32 ``argp``
33 Pointer to struct :c:type:`v4l2_subdev_crop`.
34
35 Description
36 ===========
37
38 .. note::
39
40 This is an :ref:`obsolete` interface and may be removed in the future. It is
41 superseded by :ref:`the selection API <VIDIOC_SUBDEV_G_SELECTION>`. No new
42 extensions to the :c:type:`v4l2_subdev_crop` structure will be accepted.
43
44 To retrieve the current crop rectangle applications set the ``pad``
45 field of a struct :c:type:`v4l2_subdev_crop` to the
46 desired pad number as reported by the media API and the ``which`` field
47 to ``V4L2_SUBDEV_FORMAT_ACTIVE``. They then call the
48 ``VIDIOC_SUBDEV_G_CROP`` ioctl with a pointer to this structure. The
49 driver fills the members of the ``rect`` field or returns ``EINVAL`` error
50 code if the input arguments are invalid, or if cropping is not supported
51 on the given pad.
52
53 To change the current crop rectangle applications set both the ``pad``
54 and ``which`` fields and all members of the ``rect`` field. They then
55 call the ``VIDIOC_SUBDEV_S_CROP`` ioctl with a pointer to this
56 structure. The driver verifies the requested crop rectangle, adjusts it
57 based on the hardware capabilities and configures the device. Upon
58 return the struct :c:type:`v4l2_subdev_crop`
59 contains the current format as would be returned by a
60 ``VIDIOC_SUBDEV_G_CROP`` call.
61
62 Applications can query the device capabilities by setting the ``which``
63 to ``V4L2_SUBDEV_FORMAT_TRY``. When set, 'try' crop rectangles are not
64 applied to the device by the driver, but are mangled exactly as active
65 crop rectangles and stored in the sub-device file handle. Two
66 applications querying the same sub-device would thus not interact with
67 each other.
68
69 If the subdev device node has been registered in read-only mode, calls to
70 ``VIDIOC_SUBDEV_S_CROP`` are only valid if the ``which`` field is set to
71 ``V4L2_SUBDEV_FORMAT_TRY``, otherwise an error is returned and the errno
72 variable is set to ``-EPERM``.
73
74 Drivers must not return an error solely because the requested crop
75 rectangle doesn't match the device capabilities. They must instead
76 modify the rectangle to match what the hardware can provide. The
77 modified format should be as close as possible to the original request.
78
79 .. c:type:: v4l2_subdev_crop
80
81 .. tabularcolumns:: |p{4.4cm}|p{4.4cm}|p{8.5cm}|
82
83 .. flat-table:: struct v4l2_subdev_crop
84 :header-rows: 0
85 :stub-columns: 0
86 :widths: 1 1 2
87
88 * - __u32
89 - ``pad``
90 - Pad number as reported by the media framework.
91 * - __u32
92 - ``which``
93 - Crop rectangle to get or set, from enum
94 :ref:`v4l2_subdev_format_whence <v4l2-subdev-format-whence>`.
95 * - struct :c:type:`v4l2_rect`
96 - ``rect``
97 - Crop rectangle boundaries, in pixels.
98 * - __u32
99 - ``stream``
100 - Stream identifier.
101 * - __u32
102 - ``reserved``\ [7]
103 - Reserved for future extensions. Applications and drivers must set
104 the array to zero.
105
106 Return Value
107 ============
108
109 On success 0 is returned, on error -1 and the ``errno`` variable is set
110 appropriately. The generic error codes are described at the
111 :ref:`Generic Error Codes <gen-errors>` chapter.
112
113 EBUSY
114 The crop rectangle can't be changed because the pad is currently
115 busy. This can be caused, for instance, by an active video stream on
116 the pad. The ioctl must not be retried without performing another
117 action to fix the problem first. Only returned by
118 ``VIDIOC_SUBDEV_S_CROP``
119
120 EINVAL
121 The struct :c:type:`v4l2_subdev_crop` ``pad`` references a non-existing pad,
122 the ``which`` field has an unsupported value, or cropping is not supported
123 on the given subdev pad.
124
125 EPERM
126 The ``VIDIOC_SUBDEV_S_CROP`` ioctl has been called on a read-only subdevice
127 and the ``which`` field is set to ``V4L2_SUBDEV_FORMAT_ACTIVE``.
128

3. 한국어 전문 번역

영어 원문의 문단 순서와 의미를 유지한 전체 번역입니다. 코드, 함수명, symbol과 URL은 원문 표기를 유지합니다.

목적, 호출 형식과 폐기 예정 경고

1-43

`VIDIOC_SUBDEV_G_CROP`과 `VIDIOC_SUBDEV_S_CROP`은 서브디바이스 pad의 crop 사각형을 조회하거나 설정합니다. `argp`는 `struct v4l2_subdev_crop`을 가리킵니다.

이 인터페이스는 obsolete 상태이며 향후 제거될 수 있습니다. 새 코드는 이를 대체한 selection API인 `VIDIOC_SUBDEV_G_SELECTION`을 사용해야 하고, `v4l2_subdev_crop` 구조체에는 새로운 확장이 허용되지 않습니다.

.. SPDX-License-Identifier: GFDL-1.1-no-invariants-or-later
.. c:namespace:: V4L

.. _VIDIOC_SUBDEV_G_CROP:

************************************************
ioctl VIDIOC_SUBDEV_G_CROP, VIDIOC_SUBDEV_S_CROP
************************************************

Name
====

VIDIOC_SUBDEV_G_CROP - VIDIOC_SUBDEV_S_CROP - Get or set the crop rectangle on a subdev pad

Synopsis
========

.. c:macro:: VIDIOC_SUBDEV_G_CROP

``int ioctl(int fd, VIDIOC_SUBDEV_G_CROP, struct v4l2_subdev_crop *argp)``

.. c:macro:: VIDIOC_SUBDEV_S_CROP

``int ioctl(int fd, VIDIOC_SUBDEV_S_CROP, const struct v4l2_subdev_crop *argp)``

Arguments
=========

``fd``
    File descriptor returned by :c:func:`open()`.

``argp``
    Pointer to struct :c:type:`v4l2_subdev_crop`.

Description
===========

.. note::

    This is an :ref:`obsolete` interface and may be removed in the future. It is
    superseded by :ref:`the selection API <VIDIOC_SUBDEV_G_SELECTION>`. No new
    extensions to the :c:type:`v4l2_subdev_crop` structure will be accepted.

ACTIVE와 TRY crop 처리

44-78

현재 crop을 조회하려면 `pad`를 Media API가 보고한 번호로, `which`를 `V4L2_SUBDEV_FORMAT_ACTIVE`로 설정하고 G_CROP을 호출합니다. 드라이버는 `rect`를 채우며 인자가 잘못되거나 해당 pad가 crop을 지원하지 않으면 `EINVAL`을 반환합니다.

현재 crop을 바꾸려면 `pad`, `which`, `rect`의 모든 멤버를 설정해 S_CROP을 호출합니다. 드라이버는 요청을 검증하고 하드웨어가 제공할 수 있는 가장 가까운 사각형으로 조정해 장치에 적용하며, 호출 뒤 구조체에는 G_CROP으로 얻을 현재 값이 들어 있습니다.

`which = V4L2_SUBDEV_FORMAT_TRY`이면 사각형을 실제 장치에 적용하지 않습니다. ACTIVE와 같은 방식으로 조정한 결과를 해당 서브디바이스 파일 핸들에 저장하므로 서로 다른 응용 프로그램의 try 상태는 간섭하지 않습니다.

읽기 전용으로 등록된 서브디바이스 노드에서는 S_CROP이 TRY에만 허용됩니다. ACTIVE를 설정하려 하면 `EPERM`이 반환됩니다.

요청한 사각형이 capability와 정확히 맞지 않는다는 이유만으로 드라이버가 오류를 반환해서는 안 됩니다. 가능한 한 요청에 가까운 지원 사각형으로 수정해야 합니다.

Crop 설정 경로
pad, which, rect 설정드라이버가 하드웨어 제약에 맞게 rect 조정TRY이면 파일 핸들에만 저장ACTIVE이면 장치에 적용조정된 현재 rect를 호출자에게 반환

TRY와 ACTIVE의 저장 위치와 효과를 구분합니다.

To retrieve the current crop rectangle applications set the ``pad``
field of a struct :c:type:`v4l2_subdev_crop` to the
desired pad number as reported by the media API and the ``which`` field
to ``V4L2_SUBDEV_FORMAT_ACTIVE``. They then call the
``VIDIOC_SUBDEV_G_CROP`` ioctl with a pointer to this structure. The
driver fills the members of the ``rect`` field or returns ``EINVAL`` error
code if the input arguments are invalid, or if cropping is not supported
on the given pad.

To change the current crop rectangle applications set both the ``pad``
and ``which`` fields and all members of the ``rect`` field. They then
call the ``VIDIOC_SUBDEV_S_CROP`` ioctl with a pointer to this
structure. The driver verifies the requested crop rectangle, adjusts it
based on the hardware capabilities and configures the device. Upon
return the struct :c:type:`v4l2_subdev_crop`
contains the current format as would be returned by a
``VIDIOC_SUBDEV_G_CROP`` call.

Applications can query the device capabilities by setting the ``which``
to ``V4L2_SUBDEV_FORMAT_TRY``. When set, 'try' crop rectangles are not
applied to the device by the driver, but are mangled exactly as active
crop rectangles and stored in the sub-device file handle. Two
applications querying the same sub-device would thus not interact with
each other.

If the subdev device node has been registered in read-only mode, calls to
``VIDIOC_SUBDEV_S_CROP`` are only valid if the ``which`` field is set to
``V4L2_SUBDEV_FORMAT_TRY``, otherwise an error is returned and the errno
variable is set to ``-EPERM``.

Drivers must not return an error solely because the requested crop
rectangle doesn't match the device capabilities. They must instead
modify the rectangle to match what the hardware can provide. The
modified format should be as close as possible to the original request.

struct v4l2_subdev_crop

79-104
서브디바이스 crop 구조체
형식필드의미
`__u32``pad`Media framework가 보고한 pad 번호
`__u32``which``v4l2_subdev_format_whence`에 따른 ACTIVE 또는 TRY crop
`struct v4l2_rect``rect`픽셀 단위 crop 사각형 경계
`__u32``stream`스트림 식별자
`__u32[7]``reserved[7]`향후 확장용이며 응용 프로그램과 드라이버가 모두 0으로 설정

crop 대상과 사각형 경계를 지정합니다.

.. c:type:: v4l2_subdev_crop

.. tabularcolumns:: |p{4.4cm}|p{4.4cm}|p{8.5cm}|

.. flat-table:: struct v4l2_subdev_crop
    :header-rows:  0
    :stub-columns: 0
    :widths:       1 1 2

    * - __u32
      - ``pad``
      - Pad number as reported by the media framework.
    * - __u32
      - ``which``
      - Crop rectangle to get or set, from enum
	:ref:`v4l2_subdev_format_whence <v4l2-subdev-format-whence>`.
    * - struct :c:type:`v4l2_rect`
      - ``rect``
      - Crop rectangle boundaries, in pixels.
    * - __u32
      - ``stream``
      - Stream identifier.
    * - __u32
      - ``reserved``\ [7]
      - Reserved for future extensions. Applications and drivers must set
	the array to zero.

반환값과 오류

105-127

성공하면 0, 오류이면 -1을 반환하고 `errno`를 설정합니다.

Crop ioctl 오류
errno조건
`EBUSY`활성 스트림 등으로 pad가 사용 중이라 crop을 바꿀 수 없음. 문제를 해결하는 다른 동작 없이 재시도해서는 안 되며 S_CROP만 반환
`EINVAL`pad가 없거나 which가 미지원이거나 해당 pad가 crop을 지원하지 않음
`EPERM`읽기 전용 서브디바이스에서 S_CROP으로 ACTIVE crop을 변경하려 함

S_CROP 전용 상태 오류와 공통 입력 오류를 구분합니다.


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.

EBUSY
    The crop rectangle can't be changed because the pad is currently
    busy. This can be caused, for instance, by an active video stream on
    the pad. The ioctl must not be retried without performing another
    action to fix the problem first. Only returned by
    ``VIDIOC_SUBDEV_S_CROP``

EINVAL
    The struct :c:type:`v4l2_subdev_crop` ``pad`` references a non-existing pad,
    the ``which`` field has an unsupported value, or cropping is not supported
    on the given subdev pad.

EPERM
    The ``VIDIOC_SUBDEV_S_CROP`` ioctl has been called on a read-only subdevice
    and the ``which`` field is set to ``V4L2_SUBDEV_FORMAT_ACTIVE``.