Received: by 2002:ac0:aa62:0:0:0:0:0 with SMTP id w31-v6csp1874255ima; Sun, 21 Oct 2018 23:27:40 -0700 (PDT) X-Google-Smtp-Source: ACcGV63jfqqQLgDRU/iSZK+TkS0vCWbux05KojCQYk5kr9z/eye17hMCSiSBYvFixTgw7KVkiBMF X-Received: by 2002:a17:902:28e7:: with SMTP id f94-v6mr34655468plb.297.1540189660031; Sun, 21 Oct 2018 23:27:40 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1540189660; cv=none; d=google.com; s=arc-20160816; b=pVtxUw8soEcS7SQGwBWfvqJSLHl8zQUOhWWuIuBJs0FyUHFrJ5f2XETb7fUN/XO+JB mXDFc2JLri+6+IotuFnhcvlp2bQKaWa1E8nGzD9MWZx3s2jJe8ksdJM0UGR7yvFOVLyK 5yWHpBmpc2e/cssRburaZGy7Zje/jlHhDepCIDGmJ4q7mxvRXJEDvnMwbEc3OH5CzbDR h9nAmgss0UUvgN/YfuJ3GjILI88zgKY88WURuuXdO3yGWrsECCKxM5Kj12Qmyz5a3YWo xR7kdx0/OmuP7tMnVQbf89I5JTP2nq0CtBBfWPKYkLbAn3mFPEZAQOywoK26uCgUuRCm AvoA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:cc:to:subject :message-id:date:from:in-reply-to:references:mime-version :dkim-signature; bh=vG4flJMkRRq86P5QsPgTd8oNXN00HYfxkGjOZaQ2rRk=; b=kQLThtxy/bREIgredjbsG/75GquDiz4ocIn+/zL/kPrXBZ5etiJvZirFQ3Je9dDLmH wvgN3rxWxzEqp3vTmtKdGVw1k7SuuFgoF6CijzM4tdeg8qdc//veZ82zHC/q8dJ+SmMQ TXuhp8nJvGqWC7NPUVtuzYzjB48lmCgecuQnA75nobYT9wbKCJa2CAbzBWGb1vKoWE1i r5HsczVZqK+WfWc+m1vY++fyQ1J/W7Y56UdJoqQjhkhkEzfvPm8/gL/oYM6UKAXV4Ihk ooBwARzHdoa2zno3Ly2f7DPRD5jxYNWUY5Bq+dLPMUY16pjvJzrrU1vSHq0CQUrO0mLy VbFA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=G9E1p1jA; 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 n11-v6si32557154plg.176.2018.10.21.23.27.08; Sun, 21 Oct 2018 23:27:39 -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=G9E1p1jA; 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 S1727492AbeJVOnh (ORCPT + 99 others); Mon, 22 Oct 2018 10:43:37 -0400 Received: from mail-yw1-f66.google.com ([209.85.161.66]:39944 "EHLO mail-yw1-f66.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727348AbeJVOng (ORCPT ); Mon, 22 Oct 2018 10:43:36 -0400 Received: by mail-yw1-f66.google.com with SMTP id l79-v6so15557427ywc.7 for ; Sun, 21 Oct 2018 23:26:28 -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:content-transfer-encoding; bh=vG4flJMkRRq86P5QsPgTd8oNXN00HYfxkGjOZaQ2rRk=; b=G9E1p1jAKV3Ynoopc3My0TDA7WVTC3JLI2wYfcL4A0qhPNsJ2dmMJCK9qZ6fhTTt6s zL6/jS850Pbsn9zcppoaA3Km4H7jcMcZwrrMkdKjdrR107CCCsJHyn+mGdt7Ta7/xiAT mxPPCO6owE93rMOmGjb/eTMHRfSV87hMpEMEc= 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:content-transfer-encoding; bh=vG4flJMkRRq86P5QsPgTd8oNXN00HYfxkGjOZaQ2rRk=; b=DytF338JaFjut7cMbhgX6OyevSauDhkR5N5ZEwneenJWtR2ChnIXYVBJEXNlccuvB0 yETXdrar6UVJd0K56dgTs8NELkU0WK2Q20pf+kaJvuY3J61QxOQ42rSu/tOBAsoQb0QC lxvsc4rJR3eK+oWHWpD9DkAHPGkBUlyEGekJ2i/U2LLUHj8ex0W+QFRT4gqPA16eNgiD ImhTFn8YZp9eKinuKs6fZAxooMeZBfSbK6Ml0B0c87QdmnlHmJ/wWe0EQeXLRTz9n8bt oKoD7WJBgXc1OSwSr0LY8mj3Skqei2CkDQxkouZyp7T394lwaQ/Tv5+LOs8iep653WqB 3pJw== X-Gm-Message-State: ABuFfojp/+tozISuBxdKvUFz+lkpz6yIbSKkMjzcZ99xEbiwBVZLC3n6 VGw0bhj84NUSRXhWDRKDFKyn+xan3dk= X-Received: by 2002:a0d:ce42:: with SMTP id q63-v6mr401205ywd.369.1540189587404; Sun, 21 Oct 2018 23:26:27 -0700 (PDT) Received: from mail-yw1-f54.google.com (mail-yw1-f54.google.com. [209.85.161.54]) by smtp.gmail.com with ESMTPSA id u131-v6sm662118ywa.32.2018.10.21.23.26.27 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sun, 21 Oct 2018 23:26:27 -0700 (PDT) Received: by mail-yw1-f54.google.com with SMTP id a197-v6so15549439ywh.9 for ; Sun, 21 Oct 2018 23:26:27 -0700 (PDT) X-Received: by 2002:a81:8144:: with SMTP id r65-v6mr30217179ywf.403.1540189159314; Sun, 21 Oct 2018 23:19:19 -0700 (PDT) MIME-Version: 1.0 References: <20180724140621.59624-1-tfiga@chromium.org> <4766921.vZCsLckqXW@avalon> <2340231.s4xOQAu5Wh@avalon> In-Reply-To: <2340231.s4xOQAu5Wh@avalon> From: Tomasz Figa Date: Mon, 22 Oct 2018 15:19:07 +0900 X-Gmail-Original-Message-ID: Message-ID: Subject: Re: [PATCH 1/2] media: docs-rst: Document memory-to-memory video decoder interface To: Laurent Pinchart Cc: Linux Media Mailing List , Linux Kernel Mailing List , Stanimir Varbanov , Mauro Carvalho Chehab , Hans Verkuil , Pawel Osciak , Alexandre Courbot , kamil@wypas.org, a.hajda@samsung.com, Kyungmin Park , jtp.park@samsung.com, Philipp Zabel , =?UTF-8?B?VGlmZmFueSBMaW4gKOael+aFp+ePiik=?= , =?UTF-8?B?QW5kcmV3LUNUIENoZW4gKOmZs+aZuui/qik=?= , todor.tomov@linaro.org, nicolas@ndufresne.ca, Paul Kocialkowski , dave.stevenson@raspberrypi.org, Ezequiel Garcia Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Sun, Oct 21, 2018 at 6:23 PM Laurent Pinchart wrote: > > Hi Tomasz, > > On Saturday, 20 October 2018 11:52:57 EEST Tomasz Figa wrote: > > On Thu, Oct 18, 2018 at 8:22 PM Laurent Pinchart wrote: > > > On Thursday, 18 October 2018 13:03:33 EEST Tomasz Figa wrote: > > >> On Wed, Oct 17, 2018 at 10:34 PM Laurent Pinchart wrote: > > >>> On Tuesday, 24 July 2018 17:06:20 EEST Tomasz Figa wrote: > > >>>> Due to complexity of the video decoding process, the V4L2 drivers = of > > >>>> stateful decoder hardware require specific sequences of V4L2 API > > >>>> calls to be followed. These include capability enumeration, > > >>>> initialization, decoding, seek, pause, dynamic resolution change, = drain > > >>>> and end of stream. > > >>>> > > >>>> 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=C3=BCsseldorf. 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 pa= rt > > >>>> of Linux Media documentation. Fix it now and document the decoder = part > > >>>> of the Codec API. > > >>>> > > >>>> Signed-off-by: Tomasz Figa > > >>>> --- > > >>>> > > >>>> Documentation/media/uapi/v4l/dev-decoder.rst | 872 ++++++++++++++= +++++ > > >>>> Documentation/media/uapi/v4l/devices.rst | 1 + > > >>>> Documentation/media/uapi/v4l/v4l2.rst | 10 +- > > >>>> 3 files changed, 882 insertions(+), 1 deletion(-) > > >>>> create mode 100644 Documentation/media/uapi/v4l/dev-decoder.rst > > >>>> > > >>>> diff --git a/Documentation/media/uapi/v4l/dev-decoder.rst > > >>>> b/Documentation/media/uapi/v4l/dev-decoder.rst new file mode 10064= 4 > > >>>> index 000000000000..f55d34d2f860 > > >>>> --- /dev/null > > >>>> +++ b/Documentation/media/uapi/v4l/dev-decoder.rst > > >>>> @@ -0,0 +1,872 @@ > > > > > > [snip] > > > > > >>>> +4. Allocate source (bitstream) buffers via :c:func:`VIDIOC_REQBU= FS` > > >>>> on > > >>>> + ``OUTPUT``. > > >>>> + > > >>>> + * **Required fields:** > > >>>> + > > >>>> + ``count`` > > >>>> + requested number of buffers to allocate; greater than z= ero > > >>>> + > > >>>> + ``type`` > > >>>> + a ``V4L2_BUF_TYPE_*`` enum appropriate for ``OUTPUT`` > > >>>> + > > >>>> + ``memory`` > > >>>> + follows standard semantics > > >>>> + > > >>>> + ``sizeimage`` > > >>>> + follows standard semantics; the client is free to choos= e > > >>>> any > > >>>> + suitable size, however, it may be subject to change by = the > > >>>> + driver > > >>>> + > > >>>> + * **Return fields:** > > >>>> + > > >>>> + ``count`` > > >>>> + actual number of buffers allocated > > >>>> + > > >>>> + * The driver must adjust count to minimum of required number = of > > >>>> + ``OUTPUT`` buffers for given format and count passed. > > >>> > > >>> Isn't it the maximum, not the minimum ? > > >> > > >> It's actually neither. All we can generally say here is that the > > >> number will be adjusted and the client must note it. > > > > > > I expect it to be clamp(requested count, driver minimum, driver maxim= um). > > > I'm not sure it's worth capturing this in the document though, but we > > > could say > > > > > > "The driver must clam count to the minimum and maximum number of requ= ired > > > ``OUTPUT`` buffers for the given format ." > > > > I'd leave the details to the documentation of VIDIOC_REQBUFS, if > > needed. This document focuses on the decoder UAPI and with this note I > > want to ensure that the applications don't assume that exactly the > > requested number of buffers is always allocated. > > > > How about making it even simpler: > > > > The actual number of allocated buffers may differ from the ``count`` > > given. The client must check the updated value of ``count`` after the > > call returns. > > That works for me. You may want to see "... given, as specified in the > VIDIOC_REQBUFS documentation.". > The "Conventions[...]" section mentions that 1. The general V4L2 API rules apply if not specified in this document otherwise. so I think I'll skip this additional explanation. > > >>>> The client must > > >>>> + check this value after the ioctl returns to get the number = of > > >>>> + buffers allocated. > > >>>> + > > >>>> + .. note:: > > >>>> + > > >>>> + To allocate more than minimum number of buffers (for pipel= ine > > >>>> + depth), use G_CTRL(``V4L2_CID_MIN_BUFFERS_FOR_OUTPUT``) to > > >>>> + get minimum number of buffers required by the driver/forma= t, > > >>>> + and pass the obtained value plus the number of additional > > >>>> + buffers needed in count to :c:func:`VIDIOC_REQBUFS`. > > >>>> + > > >>>> +5. Start streaming on ``OUTPUT`` queue via > > >>>> :c:func:`VIDIOC_STREAMON`. > > >>>> + > > >>>> +6. This step only applies to coded formats that contain resoluti= on > > >>>> + information in the stream. Continue queuing/dequeuing bitstre= am > > >>>> + buffers to/from the ``OUTPUT`` queue via :c:func:`VIDIOC_QBUF= ` > > >>>> and > > >>>> + :c:func:`VIDIOC_DQBUF`. The driver must keep processing and > > >>>> returning > > >>>> + each buffer to the client until required metadata to configur= e > > >>>> the > > >>>> + ``CAPTURE`` queue are found. This is indicated by the driver > > >>>> sending > > >>>> + a ``V4L2_EVENT_SOURCE_CHANGE`` event with > > >>>> + ``V4L2_EVENT_SRC_CH_RESOLUTION`` source change type. There is= no > > >>>> + requirement to pass enough data for this to occur in the firs= t > > >>>> buffer > > >>>> + and the driver must be able to process any number. > > >>>> + > > >>>> + * If data in a buffer that triggers the event is required to > > >>>> decode > > >>>> + the first frame, the driver must not return it to the clien= t, > > >>>> + but must retain it for further decoding. > > >>>> + > > >>>> + * If the client set width and height of ``OUTPUT`` format to = 0, > > >>>> calling > > >>>> + :c:func:`VIDIOC_G_FMT` on the ``CAPTURE`` queue will return > > >>>> -EPERM, > > >>>> + until the driver configures ``CAPTURE`` format according to > > >>>> stream > > >>>> + metadata. > > >>> > > >>> That's a pretty harsh handling for this condition. What's the > > >>> rationale for returning -EPERM instead of for instance succeeding w= ith > > >>> width and height set to 0 ? > > >> > > >> I don't like it, but the error condition must stay for compatibility > > >> reasons as that's what current drivers implement and applications > > >> expect. (Technically current drivers would return -EINVAL, but we > > >> concluded that existing applications don't care about the exact valu= e, > > >> so we can change it to make more sense.) > > > > > > Fair enough :-/ A bit of a shame though. Should we try to use an erro= r > > > code that would have less chance of being confused with an actual > > > permission problem ? -EILSEQ could be an option for "illegal sequence= " of > > > operations, but better options could exist. > > > > In Request API we concluded that -EACCES is the right code to return > > for G_EXT_CTRLS on a request that has not finished yet. The case here > > is similar - the capture queue is not yet set up. What do you think? > > Good question. -EPERM is documented as "Operation not permitted", while - > EACCES is documented as "Permission denied". The former appears to be > understood as "This isn't a good idea, I can't let you do that", and the > latter as "You don't have sufficient privileges, if you retry with the co= rrect > privileges this will succeed". Neither are a perfect match, but -EACCES m= ight > be better if you replace getting privileges by performing the required se= tup. > AFAIR that was also the rationale behind it for the Request API. > > >>>> + * If the client subscribes to ``V4L2_EVENT_SOURCE_CHANGE`` > > >>>> events and > > >>>> + the event is signaled, the decoding process will not contin= ue > > >>>> until > > >>>> + it is acknowledged by either (re-)starting streaming on > > >>>> ``CAPTURE``, > > >>>> + or via :c:func:`VIDIOC_DECODER_CMD` with > > >>>> ``V4L2_DEC_CMD_START`` > > >>>> + command. > > >>>> + > > >>>> + .. note:: > > >>>> + > > >>>> + No decoded frames are produced during this phase. > > >>>> + > > [snip] > > > >> Also added a note: > > >> To fulfill those requirements, the client may attempt to use > > >> :c:func:`VIDIOC_CREATE_BUFS` to add more buffers. However, du= e to > > >> hardware limitations, the decoder may not support adding buff= ers > > >> at this point and the client must be able to handle a failure > > >> using the steps below. > > > > > > I wonder if there could be a way to work around those limitations on = the > > > driver side. At the beginning of step 7, the decoder is effectively > > > stopped. If the hardware doesn't support adding new buffers on the fl= y, > > > can't the driver support the VIDIOC_CREATE_BUFS + V4L2_DEC_CMD_START > > > sequence the same way it would support the VIDIOC_STREAMOFF + > > > VIDIOC_REQBUFS(0) + > > > VIDIOC_REQBUFS(n) + VIDIOC_STREAMON ? > > > > I guess that would work. I would only allow it for the case where > > existing buffers are already big enough and just more buffers are > > needed. Otherwise it would lead to some weird cases, such as some old > > buffers already in the CAPTURE queue, blocking the decode of further > > frames. (While it could be handled by the driver returning them with > > an error state, it would only complicate the interface.) > > Good point. I wonder if this could be handled in the framework. If it can= 't, > or with non trivial support code on the driver side, then I would agree w= ith > you. Otherwise, handling the workaround in the framework would ensure > consistent behaviour across drivers with minimal cost, and simplify the > userspace API, so I think it would be a good thing. I think it should be possible to handle in the framework, but right now we don't have a framework for codecs and it would definitely be a non-trivial piece of code. I'd stick to the restricted behavior for now, since it's easy to lift the restrictions in the future, but if we make it mandatory, the userspace could start relying on it. Best regards, Tomasz