linux-media.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Hans Verkuil <hverkuil@xs4all.nl>
To: Tomasz Figa <tfiga@chromium.org>, linux-media@vger.kernel.org
Cc: linux-kernel@vger.kernel.org,
	"Mauro Carvalho Chehab" <mchehab@kernel.org>,
	"Pawel Osciak" <posciak@chromium.org>,
	"Alexandre Courbot" <acourbot@chromium.org>,
	"Kamil Debski" <kamil@wypas.org>,
	"Andrzej Hajda" <a.hajda@samsung.com>,
	"Kyungmin Park" <kyungmin.park@samsung.com>,
	"Jeongtae Park" <jtp.park@samsung.com>,
	"Philipp Zabel" <p.zabel@pengutronix.de>,
	"Tiffany Lin (林慧珊)" <tiffany.lin@mediatek.com>,
	"Andrew-CT Chen (陳智迪)" <andrew-ct.chen@mediatek.com>,
	"Stanimir Varbanov" <stanimir.varbanov@linaro.org>,
	"Todor Tomov" <todor.tomov@linaro.org>,
	"Nicolas Dufresne" <nicolas@ndufresne.ca>,
	"Paul Kocialkowski" <paul.kocialkowski@bootlin.com>,
	"Laurent Pinchart" <laurent.pinchart@ideasonboard.com>,
	dave.stevenson@raspberrypi.org,
	"Ezequiel Garcia" <ezequiel@collabora.com>,
	"Maxime Jourdan" <maxi.jourdan@wanadoo.fr>
Subject: Re: [PATCH v3 2/2] media: docs-rst: Document memory-to-memory video encoder interface
Date: Mon, 25 Mar 2019 17:33:35 +0100	[thread overview]
Message-ID: <7528bda2-a5a1-8f06-603c-00b7990c8bce@xs4all.nl> (raw)
In-Reply-To: <cb3c73e0-9481-54d1-8730-69e51655d7d8@xs4all.nl>

On 3/25/19 2:12 PM, Hans Verkuil wrote:
> Another comment found while creating compliance tests:
> 
> On 1/24/19 11:04 AM, Tomasz Figa wrote:
>> +Drain
>> +=====
>> +
>> +To ensure that all the queued ``OUTPUT`` buffers have been processed and the
>> +related ``CAPTURE`` buffers are given to the client, the client must follow the
>> +drain sequence described below. After the drain sequence ends, the client has
>> +received all encoded frames for all ``OUTPUT`` buffers queued before the
>> +sequence was started.
>> +
>> +1. Begin the drain sequence by issuing :c:func:`VIDIOC_ENCODER_CMD`.
>> +
>> +   * **Required fields:**
>> +
>> +     ``cmd``
>> +         set to ``V4L2_ENC_CMD_STOP``
>> +
>> +     ``flags``
>> +         set to 0
>> +
>> +     ``pts``
>> +         set to 0
>> +
>> +   .. warning::
>> +
>> +      The sequence can be only initiated if both ``OUTPUT`` and ``CAPTURE``
>> +      queues are streaming. For compatibility reasons, the call to
>> +      :c:func:`VIDIOC_ENCODER_CMD` will not fail even if any of the queues is
>> +      not streaming, but at the same time it will not initiate the `Drain`
>> +      sequence and so the steps described below would not be applicable.
>> +
>> +2. Any ``OUTPUT`` buffers queued by the client before the
>> +   :c:func:`VIDIOC_ENCODER_CMD` was issued will be processed and encoded as
>> +   normal. The client must continue to handle both queues independently,
>> +   similarly to normal encode operation. This includes:
>> +
>> +   * queuing and dequeuing ``CAPTURE`` buffers, until a buffer marked with the
>> +     ``V4L2_BUF_FLAG_LAST`` flag is dequeued,
>> +
>> +     .. warning::
>> +
>> +        The last buffer may be empty (with :c:type:`v4l2_buffer`
>> +        ``bytesused`` = 0) and in that case it must be ignored by the client,
>> +        as it does not contain an encoded frame.
>> +
>> +     .. note::
>> +
>> +        Any attempt to dequeue more buffers beyond the buffer marked with
>> +        ``V4L2_BUF_FLAG_LAST`` will result in a -EPIPE error from
>> +        :c:func:`VIDIOC_DQBUF`.
>> +
>> +   * dequeuing processed ``OUTPUT`` buffers, until all the buffers queued
>> +     before the ``V4L2_ENC_CMD_STOP`` command are dequeued,
>> +
>> +   * dequeuing the ``V4L2_EVENT_EOS`` event, if the client subscribes to it.
>> +
>> +   .. note::
>> +
>> +      For backwards compatibility, the encoder will signal a ``V4L2_EVENT_EOS``
>> +      event when the last frame has been decoded and all frames are ready to be
>> +      dequeued. It is deprecated behavior and the client must not rely on it.
>> +      The ``V4L2_BUF_FLAG_LAST`` buffer flag should be used instead.
>> +
>> +3. Once all ``OUTPUT`` buffers queued before the ``V4L2_ENC_CMD_STOP`` call are
>> +   dequeued and the last ``CAPTURE`` buffer is dequeued, the encoder is stopped
>> +   and it will accept, but not process any newly queued ``OUTPUT`` buffers
>> +   until the client issues any of the following operations:
>> +
>> +   * ``V4L2_ENC_CMD_START`` - the encoder will not be reset and will resume
>> +     operation normally, with all the state from before the drain,
> 
> I assume that calling CMD_START when *not* draining will succeed but does nothing.
> 
> In other words: while draining is in progress START will return EBUSY. When draining
> was finished, then START will resume the encoder. In all other cases it just returns
> 0 since the encoder is really already started.
> 
>> +
>> +   * a pair of :c:func:`VIDIOC_STREAMOFF` and :c:func:`VIDIOC_STREAMON` on the
>> +     ``CAPTURE`` queue - the encoder will be reset (see the `Reset` sequence)
>> +     and then resume encoding,
>> +
>> +   * a pair of :c:func:`VIDIOC_STREAMOFF` and :c:func:`VIDIOC_STREAMON` on the
>> +     ``OUTPUT`` queue - the encoder will resume operation normally, however any
>> +     source frames queued to the ``OUTPUT`` queue between ``V4L2_ENC_CMD_STOP``
>> +     and :c:func:`VIDIOC_STREAMOFF` will be discarded.
>> +
>> +.. note::
>> +
>> +   Once the drain sequence is initiated, the client needs to drive it to
>> +   completion, as described by the steps above, unless it aborts the process by
>> +   issuing :c:func:`VIDIOC_STREAMOFF` on any of the ``OUTPUT`` or ``CAPTURE``
>> +   queues.  The client is not allowed to issue ``V4L2_ENC_CMD_START`` or
>> +   ``V4L2_ENC_CMD_STOP`` again while the drain sequence is in progress and they
>> +   will fail with -EBUSY error code if attempted.
> 
> I assume calling STOP again once the drain sequence completed just returns 0 and
> doesn't do anything else (since we're already stopped).
> 
>> +
>> +   Although mandatory, the availability of encoder commands may be queried
>> +   using :c:func:`VIDIOC_TRY_ENCODER_CMD`.
> 
> Some corner cases:
> 
> 1) No buffers are queued on either vb2_queue, but STREAMON is called for both queues.
>    Now ENC_CMD_STOP is issued. What should happen?
> 
>    Proposal: the next time the applications queues a CAPTURE buffer it is returned
>    at once as an empty buffer with FLAG_LAST set.
> 
> 2) Both queues are streaming and buffers have been encoded, but currently no buffers
>    are queued on either vb2_queue. Now ENC_CMD_STOP is issued. What should happen?
> 
>    Proposal: the next time the applications queues a CAPTURE buffer it is returned
>    at once as an empty buffer with FLAG_LAST set. This is consistent with the
>    previous corner case.
> 
> 3) The CAPTURE queue contains buffers, the OUTPUT queue does not. Now ENC_CMD_STOP
>    is issued. What should happen?
> 
>    Proposal: the oldest CAPTURE buffer in the ready queue is returned as an empty
>    buffer with FLAG_LAST set.
> 
> 4) Both queues have queued buffers. ENC_CMD_STOP is issued to start the drain process.
>    Before the drain process completes STREAMOFF is called for either CAPTURE or
>    OUTPUT queue. What should happen?
> 
>    Proposal for STREAMOFF(CAPTURE): aborts the drain process and all CAPTURE buffers are
>    returned to userspace. If encoding is restarted, then any remaining OUTPUT buffers
>    will be used as input to the encoder.
> 
>    Proposal for STREAMOFF(OUTPUT): the next capture buffer will be empty and have
>    FLAG_LAST set.

Note: I'm not quite sure about that last one yet. It's a bit tricky to implement.

I think some of these rules might have to be implemented in v4l2-mem2mem.c to
simplify drivers.

Regards,

	Hans

> 
> Some of this might have to be documented, but these corner cases should certainly be
> tested by v4l2-compliance. Before I write those tests I'd like to know if you agree
> with this.
> 
> Regards,
> 
> 	Hans
> 


  reply	other threads:[~2019-03-25 16:33 UTC|newest]

Thread overview: 48+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-01-24 10:04 [PATCH v3 0/2] Document memory-to-memory video codec interfaces Tomasz Figa
2019-01-24 10:04 ` [PATCH v3 1/2] media: docs-rst: Document memory-to-memory video decoder interface Tomasz Figa
2019-01-29 13:11   ` Hans Verkuil
2019-01-31 10:45   ` Hans Verkuil
2019-01-31 12:30     ` Hans Verkuil
2019-01-31 12:38       ` Hans Verkuil
2019-01-31 12:44       ` Philipp Zabel
2019-01-31 13:19         ` Hans Verkuil
2019-02-07  8:51           ` Tomasz Figa
2019-04-05 10:59   ` Philipp Zabel
2019-04-05 11:21     ` Hans Verkuil
2019-04-09 10:28       ` Tomasz Figa
2019-04-09 16:57       ` Philipp Zabel
2019-04-10  9:29         ` Hans Verkuil
2019-01-24 10:04 ` [PATCH v3 2/2] media: docs-rst: Document memory-to-memory video encoder interface Tomasz Figa
2019-01-29 13:52   ` Hans Verkuil
2019-03-14 13:57     ` Hans Verkuil
2019-04-05  8:12       ` Tomasz Figa
2019-04-05 10:03         ` Hans Verkuil
2019-04-08  9:23           ` Tomasz Figa
2019-04-08 11:11             ` Hans Verkuil
2019-04-09  9:35               ` Tomasz Figa
2019-04-10  8:50                 ` Hans Verkuil
2019-04-10 16:05                   ` Nicolas Dufresne
2019-04-15  8:56                     ` Tomasz Figa
2019-04-15 12:30                       ` Nicolas Dufresne
2019-04-05  5:53     ` Tomasz Figa
2019-04-05  7:09       ` Hans Verkuil
2019-03-21 10:10   ` Hans Verkuil
2019-04-08  6:59     ` Tomasz Figa
2019-04-08  7:43       ` Hans Verkuil
2019-04-08  9:35         ` Tomasz Figa
2019-03-25 13:12   ` Hans Verkuil
2019-03-25 16:33     ` Hans Verkuil [this message]
2019-04-08  8:40       ` Tomasz Figa
2019-04-08  8:36     ` Tomasz Figa
2019-04-08  8:43       ` Hans Verkuil
2019-04-09  7:11         ` Tomasz Figa
2019-04-09  9:37           ` Hans Verkuil
2019-04-09  9:43             ` Tomasz Figa
2019-05-22  8:43               ` Tomasz Figa
2019-05-22  8:51                 ` Hans Verkuil
2019-05-22 14:16                 ` Michael Tretter
2019-04-30 17:34   ` Michael Tretter
2019-05-14  8:12     ` Tomasz Figa
2019-05-16  8:37       ` Michael Tretter
2019-05-16  8:48         ` Tomasz Figa
2019-01-24 10:38 ` [PATCH v3 0/2] Document memory-to-memory video codec interfaces Hans Verkuil

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=7528bda2-a5a1-8f06-603c-00b7990c8bce@xs4all.nl \
    --to=hverkuil@xs4all.nl \
    --cc=a.hajda@samsung.com \
    --cc=acourbot@chromium.org \
    --cc=andrew-ct.chen@mediatek.com \
    --cc=dave.stevenson@raspberrypi.org \
    --cc=ezequiel@collabora.com \
    --cc=jtp.park@samsung.com \
    --cc=kamil@wypas.org \
    --cc=kyungmin.park@samsung.com \
    --cc=laurent.pinchart@ideasonboard.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-media@vger.kernel.org \
    --cc=maxi.jourdan@wanadoo.fr \
    --cc=mchehab@kernel.org \
    --cc=nicolas@ndufresne.ca \
    --cc=p.zabel@pengutronix.de \
    --cc=paul.kocialkowski@bootlin.com \
    --cc=posciak@chromium.org \
    --cc=stanimir.varbanov@linaro.org \
    --cc=tfiga@chromium.org \
    --cc=tiffany.lin@mediatek.com \
    --cc=todor.tomov@linaro.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).