All of lore.kernel.org
 help / color / mirror / Atom feed
From: Hans Verkuil <hverkuil-cisco@xs4all.nl>
To: Nicolas Dufresne <nicolas@ndufresne.ca>, linux-media@vger.kernel.org
Cc: Michael Tretter <m.tretter@pengutronix.de>,
	Tomasz Figa <tfiga@chromium.org>
Subject: Re: [PATCHv2 1/2] media: docs-rst: Document memory-to-memory video encoder interface
Date: Tue, 26 May 2020 10:32:53 +0200	[thread overview]
Message-ID: <6caf4e56-2cb3-b193-3760-3a9b3c31bfb0@xs4all.nl> (raw)
In-Reply-To: <a14b50176ae678904f9dd39c1bb8edbc5801a030.camel@ndufresne.ca>

On 20/05/2020 22:32, Nicolas Dufresne wrote:
> Le mercredi 20 mai 2020 à 12:01 +0200, Hans Verkuil a écrit :
>> From: Tomasz Figa <tfiga@chromium.org>
>>
>> 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: Tomasz Figa <tfiga@chromium.org>
>> Signed-off-by: Hans Verkuil <hverkuil-cisco@xs4all.nl>
>> ---
>>  .../userspace-api/media/v4l/dev-encoder.rst   | 727 ++++++++++++++++++
>>  .../userspace-api/media/v4l/dev-mem2mem.rst   |   1 +
>>  .../userspace-api/media/v4l/pixfmt-v4l2.rst   |   5 +
>>  .../userspace-api/media/v4l/v4l2.rst          |   2 +
>>  .../media/v4l/vidioc-encoder-cmd.rst          |  51 +-
>>  5 files changed, 766 insertions(+), 20 deletions(-)
>>  create mode 100644 Documentation/userspace-api/media/v4l/dev-encoder.rst
>>
>> diff --git a/Documentation/userspace-api/media/v4l/dev-encoder.rst b/Documentation/userspace-api/media/v4l/dev-encoder.rst

<snip>

>> +5. **Optional** Set the coded frame interval on the ``CAPTURE`` queue via
>> +   :c:func:`VIDIOC_S_PARM`. This is only necessary if the coded frame
>> +   interval is different from the raw frame interval, which is typically
>> +   the case for off-line encoding.
>> +
>> +   * ** Required fields:**
>> +
>> +     ``type``
>> +	 a ``V4L2_BUF_TYPE_*`` enum appropriate for ``CAPTURE``.
>> +
>> +     ``parm.capture``
>> +	 set all fields except ``parm.capture.timeperframe`` to 0.
>> +
>> +     ``parm.capture.timeperframe``
>> +	 the desired coded frame interval; the encoder may adjust it to
>> +	 match hardware requirements.
>> +
>> +   * **Return fields:**
>> +
>> +     ``parm.capture.timeperframe``
>> +	 the adjusted frame interval.
>> +
>> +   .. important::
>> +
>> +      Changing the ``CAPTURE`` frame interval sets the framerate for the
>> +      coded video. It does *not* set the rate at which buffers arrive on the
>> +      ``CAPTURE`` queue, that depends on how fast the encoder is and how
>> +      fast raw frames are queued on the ``OUTPUT`` queue.
>> +
>> +   .. important::
>> +
>> +      ``timeperframe`` deals with *frames*, not fields. So for interlaced
>> +      formats this is the time per two fields, since a frame consists of
>> +      a top and a bottom field.
>> +
>> +   .. note::
>> +
>> +      Not all drivers support this functionality, in that case just set
>> +      the desired coded frame interval for the ``OUTPUT`` queue.
> 
> There is a slight contorsion in the resulting user-space API. When I
> read this, the logical thing to do for live streams would be to just
> set the OUTPUT and the driver will take care of CAPTURE for me.
> 
> While if I want to do offline, I don't know if this is supported or
> not. So the flow would be a bit special:
> 
>   S_PARM(OUTPUT) with coded video frame rate
>   S_PARM(CAPTURE) width coded video
>   if ^ worked:
>      S_PARM(OUTPUT) with fastest rate possible
> 
> Ideally I would have preferred if there was a more straight forward way
> to configure offline encoding for fastest performance with specific
> coded framerate. I don't think it's a blocker though, performance is
> not critical at all here. Maybe I'm missing something that allow to
> check if this is supported or not without trying it ?

Good point. I considered adding a flag for the v4l2_fmtdesc struct that
reports whether you can set the capture framerate independently from the
OUTPUT framerate. Perhaps V4L2_FMT_FLAG_ENC_CAP_FRAME_INTERVAL?

I actually think it would be best if that's added. It is not enough to
rely on whether S_PARM(CAPTURE) works to determine this feature since
at least one encoder drivers supports both OUTPUT and CAPTURE with S_PARM,
but CAPTURE does the same as OUTPUT, so that would be a red herring.

I'll add this flag for v3.

Regards,

	Hans

  reply	other threads:[~2020-05-26  8:33 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-05-20 10:01 [PATCHv2 0/2] Stateful Encoding: final bits Hans Verkuil
2020-05-20 10:01 ` [PATCHv2 1/2] media: docs-rst: Document memory-to-memory video encoder interface Hans Verkuil
2020-05-20 19:07   ` Tomasz Figa
2020-05-20 20:32   ` Nicolas Dufresne
2020-05-26  8:32     ` Hans Verkuil [this message]
2020-05-26 16:01       ` Tomasz Figa
2020-05-28  7:44         ` Michael Tretter
2020-05-28  8:48           ` Hans Verkuil
2020-05-28 12:02           ` Tomasz Figa
2020-05-20 20:33   ` Stanimir Varbanov
2020-05-26  8:18     ` Hans Verkuil
2020-05-20 10:01 ` [PATCHv2 2/2] vidioc-g-parm.rst: update the VIDIOC_G/S_PARM documentation Hans Verkuil
2020-05-20 19:09   ` Tomasz Figa
2020-05-20 19:11 ` [PATCHv2 0/2] Stateful Encoding: final bits Tomasz Figa

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=6caf4e56-2cb3-b193-3760-3a9b3c31bfb0@xs4all.nl \
    --to=hverkuil-cisco@xs4all.nl \
    --cc=linux-media@vger.kernel.org \
    --cc=m.tretter@pengutronix.de \
    --cc=nicolas@ndufresne.ca \
    --cc=tfiga@chromium.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.