Merge branch 'akpm' (patches from Andrew)
[cascardo/linux.git] / Documentation / media / uapi / v4l / vidioc-subdev-g-fmt.rst
1 .. -*- coding: utf-8; mode: rst -*-
2
3 .. _VIDIOC_SUBDEV_G_FMT:
4
5 **********************************************
6 ioctl VIDIOC_SUBDEV_G_FMT, VIDIOC_SUBDEV_S_FMT
7 **********************************************
8
9 Name
10 ====
11
12 VIDIOC_SUBDEV_G_FMT - VIDIOC_SUBDEV_S_FMT - Get or set the data format on a subdev pad
13
14
15 Synopsis
16 ========
17
18 .. c:function:: int ioctl( int fd, VIDIOC_SUBDEV_G_FMT, struct v4l2_subdev_format *argp )
19     :name: VIDIOC_SUBDEV_G_FMT
20
21 .. c:function:: int ioctl( int fd, VIDIOC_SUBDEV_S_FMT, struct v4l2_subdev_format *argp )
22     :name: VIDIOC_SUBDEV_S_FMT
23
24
25 Arguments
26 =========
27
28 ``fd``
29     File descriptor returned by :ref:`open() <func-open>`.
30
31 ``argp``
32
33
34 Description
35 ===========
36
37 These ioctls are used to negotiate the frame format at specific subdev
38 pads in the image pipeline.
39
40 To retrieve the current format applications set the ``pad`` field of a
41 struct :c:type:`v4l2_subdev_format` to the desired
42 pad number as reported by the media API and the ``which`` field to
43 ``V4L2_SUBDEV_FORMAT_ACTIVE``. When they call the
44 ``VIDIOC_SUBDEV_G_FMT`` ioctl with a pointer to this structure the
45 driver fills the members of the ``format`` field.
46
47 To change the current format applications set both the ``pad`` and
48 ``which`` fields and all members of the ``format`` field. When they call
49 the ``VIDIOC_SUBDEV_S_FMT`` ioctl with a pointer to this structure the
50 driver verifies the requested format, adjusts it based on the hardware
51 capabilities and configures the device. Upon return the struct
52 :c:type:`v4l2_subdev_format` contains the current
53 format as would be returned by a ``VIDIOC_SUBDEV_G_FMT`` call.
54
55 Applications can query the device capabilities by setting the ``which``
56 to ``V4L2_SUBDEV_FORMAT_TRY``. When set, 'try' formats are not applied
57 to the device by the driver, but are changed exactly as active formats
58 and stored in the sub-device file handle. Two applications querying the
59 same sub-device would thus not interact with each other.
60
61 For instance, to try a format at the output pad of a sub-device,
62 applications would first set the try format at the sub-device input with
63 the ``VIDIOC_SUBDEV_S_FMT`` ioctl. They would then either retrieve the
64 default format at the output pad with the ``VIDIOC_SUBDEV_G_FMT`` ioctl,
65 or set the desired output pad format with the ``VIDIOC_SUBDEV_S_FMT``
66 ioctl and check the returned value.
67
68 Try formats do not depend on active formats, but can depend on the
69 current links configuration or sub-device controls value. For instance,
70 a low-pass noise filter might crop pixels at the frame boundaries,
71 modifying its output frame size.
72
73 Drivers must not return an error solely because the requested format
74 doesn't match the device capabilities. They must instead modify the
75 format to match what the hardware can provide. The modified format
76 should be as close as possible to the original request.
77
78
79 .. tabularcolumns:: |p{4.4cm}|p{4.4cm}|p{8.7cm}|
80
81 .. c:type:: v4l2_subdev_format
82
83 .. flat-table:: struct v4l2_subdev_format
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 controller API.
91     * - __u32
92       - ``which``
93       - Format to modified, from enum
94         :ref:`v4l2_subdev_format_whence <v4l2-subdev-format-whence>`.
95     * - struct :c:type:`v4l2_mbus_framefmt`
96       - ``format``
97       - Definition of an image format, see :c:type:`v4l2_mbus_framefmt` for
98         details.
99     * - __u32
100       - ``reserved``\ [8]
101       - Reserved for future extensions. Applications and drivers must set
102         the array to zero.
103
104
105
106 .. tabularcolumns:: |p{6.6cm}|p{2.2cm}|p{8.7cm}|
107
108 .. _v4l2-subdev-format-whence:
109
110 .. flat-table:: enum v4l2_subdev_format_whence
111     :header-rows:  0
112     :stub-columns: 0
113     :widths:       3 1 4
114
115     * - V4L2_SUBDEV_FORMAT_TRY
116       - 0
117       - Try formats, used for querying device capabilities.
118     * - V4L2_SUBDEV_FORMAT_ACTIVE
119       - 1
120       - Active formats, applied to the hardware.
121
122
123 Return Value
124 ============
125
126 On success 0 is returned, on error -1 and the ``errno`` variable is set
127 appropriately. The generic error codes are described at the
128 :ref:`Generic Error Codes <gen-errors>` chapter.
129
130 EBUSY
131     The format can't be changed because the pad is currently busy. This
132     can be caused, for instance, by an active video stream on the pad.
133     The ioctl must not be retried without performing another action to
134     fix the problem first. Only returned by ``VIDIOC_SUBDEV_S_FMT``
135
136 EINVAL
137     The struct :c:type:`v4l2_subdev_format`
138     ``pad`` references a non-existing pad, or the ``which`` field
139     references a non-existing format.
140
141
142 ============
143
144 On success 0 is returned, on error -1 and the ``errno`` variable is set
145 appropriately. The generic error codes are described at the
146 :ref:`Generic Error Codes <gen-errors>` chapter.