Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp477114imu; Sat, 17 Nov 2018 03:39:34 -0800 (PST) X-Google-Smtp-Source: AJdET5ecX+xB2wN0dM7GraZOTS/UzEre7I6/pS190yHSZpYP4tnOyovHvDkmkGJuUQCzLFly3HL6 X-Received: by 2002:a17:902:50ec:: with SMTP id c41-v6mr14321004plj.176.1542454774423; Sat, 17 Nov 2018 03:39:34 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1542454774; cv=none; d=google.com; s=arc-20160816; b=Hygyeet2n2K5vSOjV7ggIHdgnOOmQHtoAR9g4bFMIjS39/qe+fGI1ix2tS1y4Vh926 zn1e4rx88aexOXLAOpgUGVV1M5Y2A1/IjC+X2xjNilqgT7QPXvKYbmdQlIoru5570Rjs iguYRrFPQHoGXq21pd355dYrZbFv6DN2rD3hmLQElNZDZw1vgZT5GB2snG/4yD6msdj/ TQKI7hB3PVNm09BxSaGbNnn/y+4arbbDd29iMYufxulsthl3IM3euR8IahctXz0E2lSK oSQ7Nmdm5dNuWnvHcFHcwTOUjTHy8QbFDuKHp2PMJqDK/5dEAh+W2manOrKNCV5oF+J2 VoaQ== 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 :content-language:in-reply-to:mime-version:user-agent:date :message-id:from:references:cc:to:subject; bh=9/jYLYoA0rsTTfykprQDeCRy9N2J4iGxHEK8I6rLwko=; b=kH+XXBpFT+EgyRjv4Q/BVTc2hCaGyaN1e1+cu6n59egq+IutIinnxm7SeIrTZdXNl/ GjMm0WM8y2ZgcpQGuXUgBcESVZ9E6RzA0G76jAi/LyW9NPFpJ4YXpvjbr/689opNUKqc 0/+DDHdrkOlKLa+JBG4hCUC+q5kVrL2eZpLBoY3MRjoWWNLQvPqMc3s88hHeJ8pFaqsn BIF/FAlw4SK8qUfI4hjI0Wn1SBIud+O8WqVeT2iqx5KOLch6//kUlsMa8Jm7g+nWM24w gN+q0uHzreRSnhzyy/xAXyPuhJP6vXvXtayveJJzyiTZuq4pACf7xja94UMTOt/pqzTp 2rhA== ARC-Authentication-Results: i=1; mx.google.com; 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id i64si32460087pge.361.2018.11.17.03.39.17; Sat, 17 Nov 2018 03:39:34 -0800 (PST) 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; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726096AbeKQVxo (ORCPT + 99 others); Sat, 17 Nov 2018 16:53:44 -0500 Received: from lb2-smtp-cloud8.xs4all.net ([194.109.24.25]:34261 "EHLO lb2-smtp-cloud8.xs4all.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725929AbeKQVxo (ORCPT ); Sat, 17 Nov 2018 16:53:44 -0500 Received: from [IPv6:2001:983:e9a7:1:b167:1e29:5b51:e4fb] ([IPv6:2001:983:e9a7:1:b167:1e29:5b51:e4fb]) by smtp-cloud8.xs4all.net with ESMTPA id NyuWgHGU7cvkSNyuXgT0Ua; Sat, 17 Nov 2018 12:37:17 +0100 Subject: Re: [PATCH v2 2/2] media: docs-rst: Document memory-to-memory video encoder interface To: Nicolas Dufresne , Tomasz Figa , linux-media@vger.kernel.org Cc: linux-kernel@vger.kernel.org, Mauro Carvalho Chehab , =?UTF-8?B?UGF3ZcWCIE/Fm2NpYWs=?= , Alexandre Courbot , Kamil Debski , Andrzej Hajda , Kyungmin Park , Jeongtae Park , Philipp Zabel , Tiffany Lin , Andrew-CT Chen , Stanimir Varbanov , Todor Tomov , Paul Kocialkowski , Laurent Pinchart , dave.stevenson@raspberrypi.org, Ezequiel Garcia , Maxime Jourdan References: <20181022144901.113852-1-tfiga@chromium.org> <20181022144901.113852-3-tfiga@chromium.org> <4cd223f0-b09c-da07-f26c-3b3f7a8868d7@xs4all.nl> <5fb0f2db44ba7aa3788b61f2aa9a30d4f4984de5.camel@ndufresne.ca> From: Hans Verkuil Message-ID: Date: Sat, 17 Nov 2018 12:37:12 +0100 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Thunderbird/52.9.1 MIME-Version: 1.0 In-Reply-To: <5fb0f2db44ba7aa3788b61f2aa9a30d4f4984de5.camel@ndufresne.ca> Content-Type: text/plain; charset=utf-8 Content-Language: en-US Content-Transfer-Encoding: 8bit X-CMAE-Envelope: MS4wfCwjmUQBzHWdQ4aD9M/22k6tpAPYl1DLc2BK8J0+L12aD3UdvdKVuMnAxD4AgZ+fvlZCV1kQt0TIaRnrbYFMlnj0O51csnRqtyam3Zkv2Xc4hPBtxQeE dsFA3T2D2mUg/xuQZGpDOo/zJGjKT/e5TdUqe1+QW9LviBeWRiOxjXVdYW2uJjqN4nsGSHcszGicOVMYYdlK3cgHXEGWkKeu84G3GW7LEo3sJce+Y596vZj2 srFmB7X5zQeycX2JuxKCQINfnrABch4I3m8NguEm1BXD1ER4oOu8S77kGzdTqN2RbmKMNEcykkb8Qs5eNbmwZvFVq1wvlv3Y7zw2RNkn/R0ftohP/xmZRDkq I8n0xl1mTlz6WhrTlKZk7c+W1tMgReCijiay/zVT/w4hnT+gcLpGLoJmcor0jJDV3xfW3N5gXCngVdTbYdoCnMEfs8aZ1kOhnyOt7d+NLQ290CEhXdRPhf5l ZnPGIFF6e6L+BY0ZTYztioSt050ZvRANzmjqdxTIG2ktQRi0Ajzh9PMmfldCpqWqpUakE59JUjpcqo8ly7MI0WrazWZIagR+yiBxviV5j/UWmkpSpVNj6In1 d7sV/ZbR0xo9tmgzLFhshqL91ZkhFr0RTAClarYHqe1Xuf39H/AygmK0cNbTs+UDqlJKhsNJg4uxBwN6Kx5tDhgeM7AorjKWbt3xC129cHiL9RAeFQwQhJUV T+u4QR9C8VyZvZZUmoMHNI+nNhoDwv9ly+gfsKgycBYh26pPKkQ89/V64Jjk4O9upO6TZt3Y1gtxMBGj25WcVRnQ8mdh/exQTlcsbDf7ivXFw6K5iB1oi3qF oN+DldOPoANfcVp9stC8Iv7D6FLgjCUv809KZIl5ak0J0a7wZmR+uuxub5+s98om9fKAQZdmcNv9zEsNowhMPA7nbPv42/IewsrDFUapcQ0PMcCFknZBoSVp NO3y/YmQaEQ8uiDo/vOEwhxlZ6KnAPVG1uI6pg8Jwp56mIpl Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 11/17/2018 05:18 AM, Nicolas Dufresne wrote: > Le lundi 12 novembre 2018 à 14:23 +0100, Hans Verkuil a écrit : >> On 10/22/2018 04:49 PM, Tomasz Figa wrote: >>> 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 >>> --- >>> Documentation/media/uapi/v4l/dev-encoder.rst | 579 ++++++++++++++++++ >>> Documentation/media/uapi/v4l/devices.rst | 1 + >>> Documentation/media/uapi/v4l/pixfmt-v4l2.rst | 5 + >>> Documentation/media/uapi/v4l/v4l2.rst | 2 + >>> .../media/uapi/v4l/vidioc-encoder-cmd.rst | 38 +- >>> 5 files changed, 610 insertions(+), 15 deletions(-) >>> create mode 100644 Documentation/media/uapi/v4l/dev-encoder.rst >>> >>> diff --git a/Documentation/media/uapi/v4l/dev-encoder.rst b/Documentation/media/uapi/v4l/dev-encoder.rst >>> new file mode 100644 >>> index 000000000000..41139e5e48eb >>> --- /dev/null >>> +++ b/Documentation/media/uapi/v4l/dev-encoder.rst >>> +6. Allocate buffers for both ``OUTPUT`` and ``CAPTURE`` via >>> + :c:func:`VIDIOC_REQBUFS`. This may be performed in any order. >>> + >>> + * **Required fields:** >>> + >>> + ``count`` >>> + requested number of buffers to allocate; greater than zero >>> + >>> + ``type`` >>> + a ``V4L2_BUF_TYPE_*`` enum appropriate for ``OUTPUT`` or >>> + ``CAPTURE`` >>> + >>> + other fields >>> + follow standard semantics >>> + >>> + * **Return fields:** >>> + >>> + ``count`` >>> + actual number of buffers allocated >>> + >>> + .. warning:: >>> + >>> + 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. >>> + >>> + .. note:: >>> + >>> + To allocate more than the minimum number of buffers (for pipeline depth), >>> + the client may query the ``V4L2_CID_MIN_BUFFERS_FOR_OUTPUT`` or >>> + ``V4L2_CID_MIN_BUFFERS_FOR_CAPTURE`` control respectively, to get the >>> + minimum number of buffers required by the encoder/format, and pass the >>> + obtained value plus the number of additional buffers needed in the >>> + ``count`` field to :c:func:`VIDIOC_REQBUFS`. >> >> Does V4L2_CID_MIN_BUFFERS_FOR_CAPTURE make any sense for encoders? > > We do account for it in GStreamer (the capture/output handling is > generic), but I don't know if it's being used anywhere. Do you use this value directly for REQBUFS, or do you use it as the minimum value but in practice use more buffers? > >> >> V4L2_CID_MIN_BUFFERS_FOR_OUTPUT can make sense depending on GOP size etc. > > Not really the GOP size. In video conference we often run the encoder > with an open GOP and do key frame request on demand. Mostly the DPB > size. DPB is specific term use in certain CODEC, but they nearly all > keep some backlog, except for key frame only codecs (jpeg, png, etc.). > >> >>> +.. note:: >>> + >>> + To let the client distinguish between frame types (keyframes, intermediate >>> + frames; the exact list of types depends on the coded format), the >>> + ``CAPTURE`` buffers will have corresponding flag bits set in their >>> + :c:type:`v4l2_buffer` struct when dequeued. See the documentation of >>> + :c:type:`v4l2_buffer` and each coded pixel format for exact list of flags >>> + and their meanings. >> >> Is this required? (I think it should, but it isn't the case today). > > Most CODEC do provide this metadata, if it's absent, placing the stream > into a container may require more parsing. > >> >> Is the current set of buffer flags (Key/B/P frame) sufficient for the current >> set of codecs? > > Doe it matter ? It can be extended when new codec get added. There is a > lot things in AV1 as an example, but we can add these when HW and > drivers starts shipping. I was just curious :-) It doesn't really matter, I agree. >>> + rely on it. The ``V4L2_BUF_FLAG_LAST`` buffer flag should be used >>> + instead. >> >> Question: should new codec drivers still implement the EOS event? > > I'm been asking around, but I think here is a good place. Do we really > need the FLAG_LAST in userspace ? Userspace can also wait for the first > EPIPE return from DQBUF. I'm interested in hearing Tomasz' opinion. This flag is used already, so there definitely is a backwards compatibility issue here. > >> >>> + >>> +3. Once all ``OUTPUT`` buffers queued before the ``V4L2_ENC_CMD_STOP`` call and >>> + the last ``CAPTURE`` buffer are 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 resume operation normally, >> >> Perhaps mention that this does not reset the encoder? It's not immediately clear >> when reading this. > > Which drivers supports this ? I believe I tried with Exynos in the > past, and that didn't work. How do we know if a driver supports this or > not. Do we make it mandatory ? When it's not supported, it basically > mean userspace need to cache and resend the header in userspace, and > also need to skip to some sync point. Once we agree on the spec, then the next step will be to add good compliance checks and update drivers that fail the tests. To check if the driver support this ioctl you can call VIDIOC_TRY_ENCODER_CMD to see if the functionality is supported. Regards, Hans