[media] docs-next: stop abusing on the cpp domain
[cascardo/linux.git] / Documentation / media / uapi / v4l / vidioc-encoder-cmd.rst
1 .. -*- coding: utf-8; mode: rst -*-
2
3 .. _VIDIOC_ENCODER_CMD:
4
5 ************************************************
6 ioctl VIDIOC_ENCODER_CMD, VIDIOC_TRY_ENCODER_CMD
7 ************************************************
8
9 Name
10 ====
11
12 VIDIOC_ENCODER_CMD - VIDIOC_TRY_ENCODER_CMD - Execute an encoder command
13
14
15 Synopsis
16 ========
17
18 .. c:function:: int ioctl( int fd, int request, struct v4l2_encoder_cmd *argp )
19
20
21 Arguments
22 =========
23
24 ``fd``
25     File descriptor returned by :ref:`open() <func-open>`.
26
27 ``request``
28     VIDIOC_ENCODER_CMD, VIDIOC_TRY_ENCODER_CMD
29
30 ``argp``
31
32
33 Description
34 ===========
35
36 These ioctls control an audio/video (usually MPEG-) encoder.
37 ``VIDIOC_ENCODER_CMD`` sends a command to the encoder,
38 ``VIDIOC_TRY_ENCODER_CMD`` can be used to try a command without actually
39 executing it.
40
41 To send a command applications must initialize all fields of a struct
42 :ref:`v4l2_encoder_cmd <v4l2-encoder-cmd>` and call
43 ``VIDIOC_ENCODER_CMD`` or ``VIDIOC_TRY_ENCODER_CMD`` with a pointer to
44 this structure.
45
46 The ``cmd`` field must contain the command code. The ``flags`` field is
47 currently only used by the STOP command and contains one bit: If the
48 ``V4L2_ENC_CMD_STOP_AT_GOP_END`` flag is set, encoding will continue
49 until the end of the current *Group Of Pictures*, otherwise it will stop
50 immediately.
51
52 A :ref:`read() <func-read>` or :ref:`VIDIOC_STREAMON <VIDIOC_STREAMON>`
53 call sends an implicit START command to the encoder if it has not been
54 started yet. After a STOP command, :ref:`read() <func-read>` calls will read
55 the remaining data buffered by the driver. When the buffer is empty,
56 :ref:`read() <func-read>` will return zero and the next :ref:`read() <func-read>`
57 call will restart the encoder.
58
59 A :ref:`close() <func-close>` or :ref:`VIDIOC_STREAMOFF <VIDIOC_STREAMON>`
60 call of a streaming file descriptor sends an implicit immediate STOP to
61 the encoder, and all buffered data is discarded.
62
63 These ioctls are optional, not all drivers may support them. They were
64 introduced in Linux 2.6.21.
65
66
67 .. tabularcolumns:: |p{4.4cm}|p{4.4cm}|p{8.7cm}|
68
69 .. _v4l2-encoder-cmd:
70
71 .. flat-table:: struct v4l2_encoder_cmd
72     :header-rows:  0
73     :stub-columns: 0
74     :widths:       1 1 2
75
76
77     -  .. row 1
78
79        -  __u32
80
81        -  ``cmd``
82
83        -  The encoder command, see :ref:`encoder-cmds`.
84
85     -  .. row 2
86
87        -  __u32
88
89        -  ``flags``
90
91        -  Flags to go with the command, see :ref:`encoder-flags`. If no
92           flags are defined for this command, drivers and applications must
93           set this field to zero.
94
95     -  .. row 3
96
97        -  __u32
98
99        -  ``data``\ [8]
100
101        -  Reserved for future extensions. Drivers and applications must set
102           the array to zero.
103
104
105
106 .. tabularcolumns:: |p{6.6cm}|p{2.2cm}|p{8.7cm}|
107
108 .. _encoder-cmds:
109
110 .. flat-table:: Encoder Commands
111     :header-rows:  0
112     :stub-columns: 0
113     :widths:       3 1 4
114
115
116     -  .. row 1
117
118        -  ``V4L2_ENC_CMD_START``
119
120        -  0
121
122        -  Start the encoder. When the encoder is already running or paused,
123           this command does nothing. No flags are defined for this command.
124
125     -  .. row 2
126
127        -  ``V4L2_ENC_CMD_STOP``
128
129        -  1
130
131        -  Stop the encoder. When the ``V4L2_ENC_CMD_STOP_AT_GOP_END`` flag
132           is set, encoding will continue until the end of the current *Group
133           Of Pictures*, otherwise encoding will stop immediately. When the
134           encoder is already stopped, this command does nothing. mem2mem
135           encoders will send a ``V4L2_EVENT_EOS`` event when the last frame
136           has been encoded and all frames are ready to be dequeued and will
137           set the ``V4L2_BUF_FLAG_LAST`` buffer flag on the last buffer of
138           the capture queue to indicate there will be no new buffers
139           produced to dequeue. This buffer may be empty, indicated by the
140           driver setting the ``bytesused`` field to 0. Once the
141           ``V4L2_BUF_FLAG_LAST`` flag was set, the
142           :ref:`VIDIOC_DQBUF <VIDIOC_QBUF>` ioctl will not block anymore,
143           but return an ``EPIPE`` error code.
144
145     -  .. row 3
146
147        -  ``V4L2_ENC_CMD_PAUSE``
148
149        -  2
150
151        -  Pause the encoder. When the encoder has not been started yet, the
152           driver will return an ``EPERM`` error code. When the encoder is
153           already paused, this command does nothing. No flags are defined
154           for this command.
155
156     -  .. row 4
157
158        -  ``V4L2_ENC_CMD_RESUME``
159
160        -  3
161
162        -  Resume encoding after a PAUSE command. When the encoder has not
163           been started yet, the driver will return an ``EPERM`` error code. When
164           the encoder is already running, this command does nothing. No
165           flags are defined for this command.
166
167
168 .. tabularcolumns:: |p{6.6cm}|p{2.2cm}|p{8.7cm}|
169
170 .. _encoder-flags:
171
172 .. flat-table:: Encoder Command Flags
173     :header-rows:  0
174     :stub-columns: 0
175     :widths:       3 1 4
176
177
178     -  .. row 1
179
180        -  ``V4L2_ENC_CMD_STOP_AT_GOP_END``
181
182        -  0x0001
183
184        -  Stop encoding at the end of the current *Group Of Pictures*,
185           rather than immediately.
186
187
188 Return Value
189 ============
190
191 On success 0 is returned, on error -1 and the ``errno`` variable is set
192 appropriately. The generic error codes are described at the
193 :ref:`Generic Error Codes <gen-errors>` chapter.
194
195 EINVAL
196     The ``cmd`` field is invalid.
197
198 EPERM
199     The application sent a PAUSE or RESUME command when the encoder was
200     not running.