Received: by 2002:ac0:a5a6:0:0:0:0:0 with SMTP id m35-v6csp3772681imm; Tue, 11 Sep 2018 01:41:09 -0700 (PDT) X-Google-Smtp-Source: ANB0VdZwgAL4UPlePR2N77R6hBGvFNGa1ERYyH8QdU7BGEykQOYT0u0qp0JrDx2apP64OeEmGfzT X-Received: by 2002:a17:902:4081:: with SMTP id c1-v6mr25945435pld.169.1536655269826; Tue, 11 Sep 2018 01:41:09 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1536655269; cv=none; d=google.com; s=arc-20160816; b=MgvFgQOQJDmjUOvilg6WnJZDpeHgliwiGLi7GprEdWUUdhumPIBsX60n+OKiT9Rajl InfLccPSQazsmk34mh+ODV78e6xUk49izlEhg1N9uFOa67oWLkAt5RnMZPgPYvW2tJmT 9n3SILzPcdCMh1yAz8KO/32WfL7GcYaozaDF4fDALJBTvyWqaG6pzidml/blQ3vWkHDC +yBroF+ZDX+VlaMBFrShl1WVxYCtOwf8ln8hMcSsjNXn/SeWob/j9bKOSFZIUqrVKunu l2Zuq0xQ51iZwjjGqVXbYtDnd4i8O8Of6LoHmxYz/O84odSNVIQ/GNuMCrme4BOr4Mlt jZVA== 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=iypqhurM1l0XkoGz5zlXLjBRk7/r7X7ndkTb+HhG54A=; b=J3YjqoK7vNwZZlGRSrVTcZlPg2vHQ16SdQ4JcOdXH80JcdlFFINdiBJRQBZCU26UXo brys5m3YhI/ejDGpb6I5qpQ/ibZrii+/JDi4pHDsw4k01/QMXuqpGLXMwYvDrWMkIr1o dQQAjNb7wbPuHJKtCPNhY8G+ggg1QcPe1tK2H+3Ex+gAz2t3EexuhWKCX8jx6WqEKw5k ATsRVZ51Tm/178r2y5d7R9YoVIRXIbRXNCRyHB+Gr2Si/UEVQmQ/irnPHULK9Mt5lz0h gA4bWQMYGpZjB8Nnz/vorzeRL49o6JH/l0aR46VxvGqxu8FPd3DA+Zmy4bKzDboxsQTE KEtw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=BualE8a3; 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 n7-v6si18322356pgp.411.2018.09.11.01.40.54; Tue, 11 Sep 2018 01:41:09 -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=BualE8a3; 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 S1726743AbeIKNjA (ORCPT + 99 others); Tue, 11 Sep 2018 09:39:00 -0400 Received: from mail-it0-f66.google.com ([209.85.214.66]:35741 "EHLO mail-it0-f66.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726488AbeIKNjA (ORCPT ); Tue, 11 Sep 2018 09:39:00 -0400 Received: by mail-it0-f66.google.com with SMTP id 139-v6so451326itf.0 for ; Tue, 11 Sep 2018 01:40:44 -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=iypqhurM1l0XkoGz5zlXLjBRk7/r7X7ndkTb+HhG54A=; b=BualE8a3LqqcMc084ko/OGhXaj0B/m87UDXyxHrAiih2INAfUvKEDLFnpn0hXmJjZk C7EW0BHtTs2tjX2BkohAAlQwAf53wDMaf7w7205Oshba+jzOYi452OL/WdqZ/KeWCnDd PTushrttECC92Pcf/VhXfJmDDwmo5Z+n1F4ps= 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=iypqhurM1l0XkoGz5zlXLjBRk7/r7X7ndkTb+HhG54A=; b=edEUFVLUPQVp6jYPtRGVyvDA9R9vszt8M+Ng0tTyhc9z98xrTDAw96GTx07CVby50s HzYHeJqtMOyznMHKz+mvoKPDxeJR2qNXUj5vN4K+/7tP4i95UTD8MemFa+uUaAOqFQQt dzLyJiItuHVvnQ/FqBTEW8bc8onPpIiTt1KCVqsE9HSfDuEjG8xQEQ3wFUeJnuMjIKyQ 3w9Cm8qFALEDdjs3l/jBnE7MynRK6sbCVOwBU6Lw2gLHY29/04tuSlP59Xdk02JYks9Y ooWzNfeqEgmxKrExbVkzQjxiZBAteqXRZgmpvLPzXvFdsWfKXGpxJW8+yeYJRG4VDqoH hALQ== X-Gm-Message-State: APzg51DSYDNNQkkC03AVUrYxJO5qSBA5T6sQeG+vA534OUgPeQcM5R6K 2vsyAUw46evGdw7zFIirH7aaAhk4e9Q= X-Received: by 2002:a24:17d2:: with SMTP id 201-v6mr595402ith.0.1536655243821; Tue, 11 Sep 2018 01:40:43 -0700 (PDT) Received: from mail-it0-f46.google.com (mail-it0-f46.google.com. [209.85.214.46]) by smtp.gmail.com with ESMTPSA id j6-v6sm107192itb.25.2018.09.11.01.40.43 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 11 Sep 2018 01:40:43 -0700 (PDT) Received: by mail-it0-f46.google.com with SMTP id j81-v6so470613ite.0 for ; Tue, 11 Sep 2018 01:40:43 -0700 (PDT) X-Received: by 2002:a02:1e96:: with SMTP id 22-v6mr22591608jat.33.1536655242721; Tue, 11 Sep 2018 01:40:42 -0700 (PDT) MIME-Version: 1.0 References: <20180831074743.235010-1-acourbot@chromium.org> <38b32d24-6957-4bee-9168-b3afbfcae083@xs4all.nl> In-Reply-To: From: Alexandre Courbot Date: Tue, 11 Sep 2018 17:40:31 +0900 X-Gmail-Original-Message-ID: Message-ID: Subject: Re: [RFC PATCH] media: docs-rst: Document m2m stateless video decoder interface To: Hans Verkuil Cc: Tomasz Figa , Paul Kocialkowski , Mauro Carvalho Chehab , Pawel Osciak , Linux Media Mailing List , LKML 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 Mon, Sep 10, 2018 at 9:49 PM Hans Verkuil wrote: > > On 09/10/2018 01:57 PM, Hans Verkuil wrote: > > On 09/10/2018 01:25 PM, Hans Verkuil wrote: > >>> + > >>> +Decoding > >>> +======== > >>> + > >>> +For each frame, the client is responsible for submitting a request to which the > >>> +following is attached: > >>> + > >>> +* Exactly one frame worth of encoded data in a buffer submitted to the > >>> + ``OUTPUT`` queue, > >>> +* All the controls relevant to the format being decoded (see below for details). > >>> + > >>> +``CAPTURE`` buffers must not be part of the request, but must be queued > >>> +independently. The driver will pick one of the queued ``CAPTURE`` buffers and > >>> +decode the frame into it. Although the client has no control over which > >>> +``CAPTURE`` buffer will be used with a given ``OUTPUT`` buffer, it is guaranteed > >>> +that ``CAPTURE`` buffers will be returned in decode order (i.e. the same order > >>> +as ``OUTPUT`` buffers were submitted), so it is trivial to associate a dequeued > >>> +``CAPTURE`` buffer to its originating request and ``OUTPUT`` buffer. > >>> + > >>> +If the request is submitted without an ``OUTPUT`` buffer or if one of the > >>> +required controls are missing, then :c:func:`MEDIA_REQUEST_IOC_QUEUE` will return > >>> +``-EINVAL``. > >> > >> Not entirely true: if buffers are missing, then ENOENT is returned. Missing required > >> controls or more than one OUTPUT buffer will result in EINVAL. This per the latest > >> Request API changes. > >> > >> Decoding errors are signaled by the ``CAPTURE`` buffers being > >>> +dequeued carrying the ``V4L2_BUF_FLAG_ERROR`` flag. > >> > >> Add here that if the reference frame had an error, then all other frames that refer > >> to it should also set the ERROR flag. It is up to userspace to decide whether or > >> not to drop them (part of the frame might still be valid). > >> > >> I am not sure whether this should be documented, but there are some additional > >> restrictions w.r.t. reference frames: > >> > >> Since decoders need access to the decoded reference frames there are some corner > >> cases that need to be checked: > >> > >> 1) V4L2_MEMORY_USERPTR cannot be used for the capture queue: the driver does not > >> know when a malloced but dequeued buffer is freed, so the reference frame > >> could suddenly be gone. > >> > >> 2) V4L2_MEMORY_DMABUF can be used, but drivers should check that the dma buffer is > >> still available AND increase the dmabuf refcount while it is used by the HW. > >> > >> 3) What to do if userspace has requeued a buffer containing a reference frame, > >> and you want to decode a B/P-frame that refers to that buffer? We need to > >> check against that: I think that when you queue a capture buffer whose index > >> is used in a pending request as a reference frame, than that should fail with > >> an error. And trying to queue a request referring to a buffer that has been > >> requeued should also fail. > >> > >> We might need to add some support for this in v4l2-mem2mem.c or vb2. > >> > >> We will have similar (but not quite identical) issues with stateless encoders. > > > > Related to this is the question whether buffer indices that are used to refer > > to reference frames should refer to the capture or output queue. > > > > Using capture indices works if you never queue more than one request at a time: > > you know exactly what the capture buffer index is of the decoded I-frame, and > > you can use that in the following requests. > > > > But if multiple requests are queued, then you don't necessarily know to which > > capture buffer an I-frame will be decoded, so then you can't provide this index > > to following B/P-frames. This puts restrictions on userspace: you can only > > queue B/P-frames once you have decoded the I-frame. This might be perfectly > > acceptable, though. IIUC at the moment we are indeed using CAPTURE buffer indexes, e.g: .. flat-table:: struct v4l2_ctrl_mpeg2_slice_params .. - ``backward_ref_index`` - Index for the V4L2 buffer to use as backward reference, used with B-coded and P-coded frames. So I wonder how is the user-space currently exercising Cedrus doing here? Waiting for each frame used as a reference to be dequeued? > > > > Using output buffer indices will work (the driver will know to which capture > > buffer index the I-frames mapped), but it requires that the output buffer that > > contained a reference frame isn't requeued, since that means that the driver > > will lose this mapping. I think this will make things too confusing, though. > > > > A third option is that you don't refer to reference frames by buffer index, > > but instead by some other counter (sequence counter, perhaps?). > > Definitely not sequence number, since it has the same problem as buffer index. > > This could be a value relative to the frame you are trying to decode: i.e. 'use > the capture buffer from X frames ago'. This makes it index independent and is > still easy to keep track of inside the driver and application. Sounds like that would work, although the driver would need to maintain a history of processed frames indexes. We will still need to make sure that frames referenced have not been re-queued in the meantime. Drivers (or the to-be-designed codec framework?) will also need to be handle the case where user-space did not allocate enough buffers to hold all the reference frames and the frame to be decoded... Sorry, I have more questions than answers I'm afraid.