Received: by 2002:a25:4158:0:0:0:0:0 with SMTP id o85csp3691541yba; Tue, 9 Apr 2019 02:44:48 -0700 (PDT) X-Google-Smtp-Source: APXvYqy4RdZRBTVj1WluWkNQV1jzM2AtcvtK1d2DFFKj8kxuYZ40pMrs6xyETbQFEs1Xfh0HEF4v X-Received: by 2002:a63:dc50:: with SMTP id f16mr33400095pgj.396.1554803088131; Tue, 09 Apr 2019 02:44:48 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1554803088; cv=none; d=google.com; s=arc-20160816; b=ERzbdMSd1C2qolzqeyc93aFtcJrx2nDpDAc5/Ycgoo2zpTK0eM/EtXDgkshAQbhGo9 cfsJX2SN2hWixEScNyTXmvPlAJOYIpJSfEYWrYpecR83/+9XAW4sRs8gRAI4a+bMp3rn VeE06rzMeG/Z7QYLqAkM9XT1U8wxNUYJP+n/5fTgqHnSxOxSRPIu3F4Cj9iZcFp/J0e6 iuovL3/phA8E0fFUp6G53j7Hh7yrhSrxaKAPJiE3Lt2vS1Omx09RZcBEOSWBgQe1bM+Z HKNMp9nmQriYSuEXcuAv5wyfxyGbE/6FFd6z1d5LO+8Wj4G4IROaawFF9vGAuNCM6Ssr ssUg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:dkim-signature; bh=M9Zaom9V3GQHDePgi8JkUzY5eENAYE9Vl1F7+gTeKI0=; b=EeoyqYdBvwncb9QVqPNSshzu/J7I/UmEQx4gTNOvnBVz9MES3avHcHtUeT39+aCI70 dlArnnDkzym8wGdsDtDLrpwKfsYUs3oJGP9qY4HIZ6ONPlz32eLCsUyxGwDaOE/XwYwl sTF+n3QpoDXdmMBURMHMerYpOp45eGPZhZHDO46KkAQMNNd851QQgwwSPfv077j458Y0 hfTzDHpL5H3xtqkI0ffVxwffnRaP7PD4cjsOqexgRwQlV63iVHlqlRhwgLA/3+GFvSFg 2JtwNWv3jyXhXfgl7o+N6jR4xlrSzd6cJFMn/xkox9DEcFlqISpr4mGXGq1QBSrArgs1 ILFw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=B7PBfKlB; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=chromium.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id n34si28376526pld.352.2019.04.09.02.44.32; Tue, 09 Apr 2019 02:44:48 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=B7PBfKlB; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=chromium.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726493AbfDIJns (ORCPT + 99 others); Tue, 9 Apr 2019 05:43:48 -0400 Received: from mail-oi1-f196.google.com ([209.85.167.196]:46834 "EHLO mail-oi1-f196.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726035AbfDIJns (ORCPT ); Tue, 9 Apr 2019 05:43:48 -0400 Received: by mail-oi1-f196.google.com with SMTP id x188so12949573oia.13 for ; Tue, 09 Apr 2019 02:43:47 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=M9Zaom9V3GQHDePgi8JkUzY5eENAYE9Vl1F7+gTeKI0=; b=B7PBfKlBhb4xl/IwLozAO2uBOsEMQhK44U7wUjbBXCpHgKyWoNayK5CpUrYPF/Dh38 LaFx13pwVfODHIvfeZjoZKiba2Nt8OtK7+C2spANp7pONymOY5/zNmLmmgoaNGtSmg7+ hFzcBfTDa+CF+UKagY6Fq2yWJYfxOryFOh8kM= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=M9Zaom9V3GQHDePgi8JkUzY5eENAYE9Vl1F7+gTeKI0=; b=tVj+ANqNEuBK31WS5MmP7vgMJoVDcZzAK+iVa1b4vnV1WsjFAqCQLXpA9/18jFoGip ZycYy1ZFlxNShhy/RJiQXWjZWyAOhwsRKHYQassWNeLixHj5hXZTraYPMSDh1SUJym8f jFYXn/Rr2NHdrhhwvv9I5JjUzv/UKr2eqJkQjMHDj+CbxI7HmVK0xMxF0w/F6PqR2cy7 iMT2maezgT7FYlTNCdH3tz1qb1ogHXPP8GrcOfQPXzWTV+hcLSBk9wgITu/T+h7tOm69 +LzB9FxBK0mSXFL8baOwy7BWekyBGhIOgR7lGdI760bp8yq4TOij+6C+t7s44xWdNsND qYZg== X-Gm-Message-State: APjAAAVvTwj8GPX0lc/Ax2VR8XBJr9717SsY5X8wIdBSspsix/tkE/GB jZinxwJViFTjfIcwfLpvtVGWRzXR4ko= X-Received: by 2002:aca:c683:: with SMTP id w125mr19526909oif.144.1554803026365; Tue, 09 Apr 2019 02:43:46 -0700 (PDT) Received: from mail-oi1-f178.google.com (mail-oi1-f178.google.com. [209.85.167.178]) by smtp.gmail.com with ESMTPSA id j82sm7967145oih.31.2019.04.09.02.43.45 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 09 Apr 2019 02:43:45 -0700 (PDT) Received: by mail-oi1-f178.google.com with SMTP id v84so13003150oif.4 for ; Tue, 09 Apr 2019 02:43:45 -0700 (PDT) X-Received: by 2002:aca:a894:: with SMTP id r142mr19214647oie.112.1554803024849; Tue, 09 Apr 2019 02:43:44 -0700 (PDT) MIME-Version: 1.0 References: <20190124100419.26492-1-tfiga@chromium.org> <20190124100419.26492-3-tfiga@chromium.org> <2376896b-0087-5eee-a4b9-6ad03b0fef9c@xs4all.nl> In-Reply-To: <2376896b-0087-5eee-a4b9-6ad03b0fef9c@xs4all.nl> From: Tomasz Figa Date: Tue, 9 Apr 2019 18:43:33 +0900 X-Gmail-Original-Message-ID: Message-ID: Subject: Re: [PATCH v3 2/2] media: docs-rst: Document memory-to-memory video encoder interface To: Hans Verkuil Cc: Linux Media Mailing List , Linux Kernel Mailing List , Mauro Carvalho Chehab , Pawel Osciak , Alexandre Courbot , Kamil Debski , Andrzej Hajda , Kyungmin Park , Jeongtae Park , Philipp Zabel , =?UTF-8?B?VGlmZmFueSBMaW4gKOael+aFp+ePiik=?= , =?UTF-8?B?QW5kcmV3LUNUIENoZW4gKOmZs+aZuui/qik=?= , Stanimir Varbanov , Todor Tomov , Nicolas Dufresne , Paul Kocialkowski , Laurent Pinchart , dave.stevenson@raspberrypi.org, Ezequiel Garcia , Maxime Jourdan Content-Type: text/plain; charset="UTF-8" Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Tue, Apr 9, 2019 at 6:37 PM Hans Verkuil wrote: > > On 4/9/19 9:11 AM, Tomasz Figa wrote: > > On Mon, Apr 8, 2019 at 5:43 PM Hans Verkuil wrote: > >> > >> On 4/8/19 10:36 AM, Tomasz Figa wrote: > >>> On Mon, Mar 25, 2019 at 10: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. > >>>> > >>> > >>> Yes, that was the intention and seems to be the closest to the > >>> behavior described in the existing documentation. > >>> > >>>>> + > >>>>> + * 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). > >>>> > >>> > >>> Right. > >>> > >>>>> + > >>>>> + 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. > >>>> > >>> > >>> SGTM. It's actually similar to a relatively common case where all > >>> CAPTURE buffers have been dequeued and the application has to refill > >>> the CAPTURE queue, but in the meantime a drain request needs to be > >>> issued. > >>> > >>>> 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. > >>> > >>> Agreed. > >>> > >>>> > >>>> 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. > >>> > >>> Generally agreed, but not sure if there is a reason to specifically > >>> refer to the oldest buffer. (I'm personally for keeping the queues > >>> ordered, though...) > >> > >> Feel free to rephrase. Perhaps: "an empty CAPTURE buffer with FLAG_LAST set should be > >> queued up for userspace to signal that the encoder has stopped." Or something along > >> those lines. > > > > I've added a note: > > > > For reference, handling of various corner cases is described below: > > > > * In case of no buffer in the ``OUTPUT`` queue at the time the > > ``V4L2_ENC_CMD_STOP`` command was issued, the drain sequence completes > > immediately and the encoder returns an empty ``CAPTURE`` buffer with the > > ``V4L2_BUF_FLAG_LAST`` flag set. > > > > * In case of no buffer in the ``CAPTURE`` queue at the time the drain > > sequence completes, the next time the client queues a ``CAPTURE`` buffer > > it is returned at once as an empty buffer with the ``V4L2_BUF_FLAG_LAST`` > > flag set. > > > > * If :c:func:`VIDIOC_STREAMOFF` is called on the ``CAPTURE`` queue in the > > middle of the drain sequence, the drain sequence is cancelled and all > > cancelled -> canceled > > > ``CAPTURE`` buffers are implicitly returned to the userpace. > > userpace -> userspace > Actually changed it to "client". > > > > * If :c:func:`VIDIOC_STREAMOFF` is called on the ``OUTPUT`` queue in the > > middle of the drain sequence, the drain sequence completes immediately and > > next ``CAPTURE`` buffer will be returned empty with the > > ``V4L2_BUF_FLAG_LAST`` flag set. > > > > Slightly changed the split into cases to cover behaviors rather than > > conditions. WDYT? > > Looks good (with those two typos fixed). > Thanks. > Hans > > > > > Best regards, > > Tomasz > > > >> > >> Regards, > >> > >> Hans > >> > >>> > >>>> > >>>> 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. > >>>> > >>> > >>> Agreed. > >>> > >>>> Proposal for STREAMOFF(OUTPUT): the next capture buffer will be empty and have > >>>> FLAG_LAST set. > >>> > >>> Agreed. > >>> > >>>> > >>>> 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. > >>> > >>> Agreed with just one minor comment. Thanks for checking with me! > >>> > >>> Best regards, > >>> Tomasz > >>> > >> >