Commit 9ec656cf authored by Tomasz Figa's avatar Tomasz Figa Committed by Mauro Carvalho Chehab

media: docs-rst: Document memory-to-memory video encoder interface

Due to complexity of the video encoding process, the V4L2 drivers of
stateful encoder hardware require specific sequences of V4L2 API calls
to be followed. These include capability enumeration, initialization,
encoding, encode parameters change, drain and reset.

Specifics of the above have been discussed during Media Workshops at
LinuxCon Europe 2012 in Barcelona and then later Embedded Linux
Conference Europe 2014 in Düsseldorf. The de facto Codec API that
originated at those events was later implemented by the drivers we already
have merged in mainline, such as s5p-mfc or coda.

The only thing missing was the real specification included as a part of
Linux Media documentation. Fix it now and document the encoder part of
the Codec API.
Signed-off-by: default avatarTomasz Figa <tfiga@chromium.org>
Signed-off-by: default avatarHans Verkuil <hverkuil-cisco@xs4all.nl>
Reviewed-by: default avatarMichael Tretter <m.tretter@pengutronix.de>
Signed-off-by: default avatarMauro Carvalho Chehab <mchehab+huawei@kernel.org>
parent 62a4cd01
This diff is collapsed.
...@@ -46,4 +46,5 @@ devices are given in the following sections. ...@@ -46,4 +46,5 @@ devices are given in the following sections.
:maxdepth: 1 :maxdepth: 1
dev-decoder dev-decoder
dev-encoder
dev-stateless-decoder dev-stateless-decoder
...@@ -44,6 +44,11 @@ Single-planar format structure ...@@ -44,6 +44,11 @@ Single-planar format structure
inside the stream, when fed to a stateful mem2mem decoder, the fields inside the stream, when fed to a stateful mem2mem decoder, the fields
may be zero to rely on the decoder to detect the right values. For more may be zero to rely on the decoder to detect the right values. For more
details see :ref:`decoder` and format descriptions. details see :ref:`decoder` and format descriptions.
For compressed formats on the CAPTURE side of a stateful mem2mem
encoder, the fields must be zero, since the coded size is expected to
be calculated internally by the encoder itself, based on the OUTPUT
side. For more details see :ref:`encoder` and format descriptions.
* - __u32 * - __u32
- ``pixelformat`` - ``pixelformat``
- The pixel format or type of compression, set by the application. - The pixel format or type of compression, set by the application.
......
...@@ -63,6 +63,7 @@ Authors, in alphabetical order: ...@@ -63,6 +63,7 @@ Authors, in alphabetical order:
- Figa, Tomasz <tfiga@chromium.org> - Figa, Tomasz <tfiga@chromium.org>
- Documented the memory-to-memory decoder interface. - Documented the memory-to-memory decoder interface.
- Documented the memory-to-memory encoder interface.
- H Schimek, Michael <mschimek@gmx.at> - H Schimek, Michael <mschimek@gmx.at>
...@@ -75,6 +76,7 @@ Authors, in alphabetical order: ...@@ -75,6 +76,7 @@ Authors, in alphabetical order:
- Osciak, Pawel <posciak@chromium.org> - Osciak, Pawel <posciak@chromium.org>
- Documented the memory-to-memory decoder interface. - Documented the memory-to-memory decoder interface.
- Documented the memory-to-memory encoder interface.
- Osciak, Pawel <pawel@osciak.com> - Osciak, Pawel <pawel@osciak.com>
......
...@@ -51,25 +51,26 @@ To send a command applications must initialize all fields of a struct ...@@ -51,25 +51,26 @@ To send a command applications must initialize all fields of a struct
``VIDIOC_ENCODER_CMD`` or ``VIDIOC_TRY_ENCODER_CMD`` with a pointer to ``VIDIOC_ENCODER_CMD`` or ``VIDIOC_TRY_ENCODER_CMD`` with a pointer to
this structure. this structure.
The ``cmd`` field must contain the command code. The ``flags`` field is The ``cmd`` field must contain the command code. Some commands use the
currently only used by the STOP command and contains one bit: If the ``flags`` field for additional information.
``V4L2_ENC_CMD_STOP_AT_GOP_END`` flag is set, encoding will continue
until the end of the current *Group Of Pictures*, otherwise it will stop
immediately.
A :ref:`read() <func-read>` or :ref:`VIDIOC_STREAMON <VIDIOC_STREAMON>` After a STOP command, :ref:`read() <func-read>` calls will read
call sends an implicit START command to the encoder if it has not been
started yet. After a STOP command, :ref:`read() <func-read>` calls will read
the remaining data buffered by the driver. When the buffer is empty, the remaining data buffered by the driver. When the buffer is empty,
:ref:`read() <func-read>` will return zero and the next :ref:`read() <func-read>` :ref:`read() <func-read>` will return zero and the next :ref:`read() <func-read>`
call will restart the encoder. call will restart the encoder.
A :ref:`read() <func-read>` or :ref:`VIDIOC_STREAMON <VIDIOC_STREAMON>`
call sends an implicit START command to the encoder if it has not been
started yet. Applies to both queues of mem2mem encoders.
A :ref:`close() <func-close>` or :ref:`VIDIOC_STREAMOFF <VIDIOC_STREAMON>` A :ref:`close() <func-close>` or :ref:`VIDIOC_STREAMOFF <VIDIOC_STREAMON>`
call of a streaming file descriptor sends an implicit immediate STOP to call of a streaming file descriptor sends an implicit immediate STOP to
the encoder, and all buffered data is discarded. the encoder, and all buffered data is discarded. Applies to both queues of
mem2mem encoders.
These ioctls are optional, not all drivers may support them. They were These ioctls are optional, not all drivers may support them. They were
introduced in Linux 2.6.21. introduced in Linux 2.6.21. They are, however, mandatory for stateful mem2mem
encoders (as further documented in :ref:`encoder`).
.. tabularcolumns:: |p{4.4cm}|p{4.4cm}|p{8.7cm}| .. tabularcolumns:: |p{4.4cm}|p{4.4cm}|p{8.7cm}|
...@@ -109,21 +110,24 @@ introduced in Linux 2.6.21. ...@@ -109,21 +110,24 @@ introduced in Linux 2.6.21.
- 0 - 0
- Start the encoder. When the encoder is already running or paused, - Start the encoder. When the encoder is already running or paused,
this command does nothing. No flags are defined for this command. this command does nothing. No flags are defined for this command.
For a device implementing the :ref:`encoder`, once the drain sequence
is initiated with the ``V4L2_ENC_CMD_STOP`` command, it must be driven
to completion before this command can be invoked. Any attempt to
invoke the command while the drain sequence is in progress will trigger
an ``EBUSY`` error code. See :ref:`encoder` for more details.
* - ``V4L2_ENC_CMD_STOP`` * - ``V4L2_ENC_CMD_STOP``
- 1 - 1
- Stop the encoder. When the ``V4L2_ENC_CMD_STOP_AT_GOP_END`` flag - Stop the encoder. When the ``V4L2_ENC_CMD_STOP_AT_GOP_END`` flag
is set, encoding will continue until the end of the current *Group is set, encoding will continue until the end of the current *Group
Of Pictures*, otherwise encoding will stop immediately. When the Of Pictures*, otherwise encoding will stop immediately. When the
encoder is already stopped, this command does nothing. mem2mem encoder is already stopped, this command does nothing.
encoders will send a ``V4L2_EVENT_EOS`` event when the last frame
has been encoded and all frames are ready to be dequeued and will For a device implementing the :ref:`encoder`, the command will initiate
set the ``V4L2_BUF_FLAG_LAST`` buffer flag on the last buffer of the drain sequence as documented in :ref:`encoder`. No flags or other
the capture queue to indicate there will be no new buffers arguments are accepted in this case. Any attempt to invoke the command
produced to dequeue. This buffer may be empty, indicated by the again before the sequence completes will trigger an ``EBUSY`` error
driver setting the ``bytesused`` field to 0. Once the code.
``V4L2_BUF_FLAG_LAST`` flag was set, the
:ref:`VIDIOC_DQBUF <VIDIOC_QBUF>` ioctl will not block anymore,
but return an ``EPIPE`` error code.
* - ``V4L2_ENC_CMD_PAUSE`` * - ``V4L2_ENC_CMD_PAUSE``
- 2 - 2
- Pause the encoder. When the encoder has not been started yet, the - Pause the encoder. When the encoder has not been started yet, the
...@@ -152,6 +156,8 @@ introduced in Linux 2.6.21. ...@@ -152,6 +156,8 @@ introduced in Linux 2.6.21.
- Stop encoding at the end of the current *Group Of Pictures*, - Stop encoding at the end of the current *Group Of Pictures*,
rather than immediately. rather than immediately.
Does not apply to :ref:`encoder`.
Return Value Return Value
============ ============
...@@ -160,6 +166,11 @@ On success 0 is returned, on error -1 and the ``errno`` variable is set ...@@ -160,6 +166,11 @@ On success 0 is returned, on error -1 and the ``errno`` variable is set
appropriately. The generic error codes are described at the appropriately. The generic error codes are described at the
:ref:`Generic Error Codes <gen-errors>` chapter. :ref:`Generic Error Codes <gen-errors>` chapter.
EBUSY
A drain sequence of a device implementing the :ref:`encoder` is still in
progress. It is not allowed to issue another encoder command until it
completes.
EINVAL EINVAL
The ``cmd`` field is invalid. The ``cmd`` field is invalid.
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment