Received: by 2002:a05:6a10:5bc5:0:0:0:0 with SMTP id os5csp3103831pxb; Mon, 1 Nov 2021 07:57:41 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzfO2DdyLl9UckWzLIkKxjCTyuSxtIGl1u4AiGgSGDqS2FygSVUdrr/OfKcGaVodayow2sV X-Received: by 2002:a17:906:3acc:: with SMTP id z12mr36887254ejd.215.1635778661003; Mon, 01 Nov 2021 07:57:41 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1635778660; cv=none; d=google.com; s=arc-20160816; b=ykY+Na/Ez60D6PShIftFHCQXCIR0uXHCEVB0bO23sCs5O/K0ShmSP+/gcs+3Er6e8h bAnth1kDMbd/nsJlPlEHmBbGYb1hSmqA4wVWIY91rthGrteCx1OClgJ+ElmuBTS8R3Dn JnDRygB37DbUm/Of4+SbtiYnKGnSqTO74tI8AYemFdDMVnlYcMwhcn6IoQevJ271Kbh0 TQTEA6RRvrlSPxYXnzxitMc+ZI/QGvXk6cBt2ovAPZcNQ+wHGrTV5nsNJQQn1h3eBp+w 4bqtKX6BRRtxAPga564h/ConE8r1nInDfy79ylS2CwGwf0nOAJvU2HHnr0S+Ha7M4Nd6 sAuQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:date:cc:to:from:subject :message-id:dkim-signature; bh=mpvNT8Ri6AwqEAbY0lXNb8KCZijn3p0iMge2tpFnF0M=; b=D5BLhbzNgXlA50vmyqrq5hGwAoEXyn/H5+WDN+spj3z41LyxlDhRoqsO1XIZSrnP19 ZAsltRD3SebxR5+FypShccYuMBXaKxr3eKuMkk1pqICuh7uoO1n1PhuoNiopzDP2nZYh 1x6W4ZQD04mMifn8VFjP1kD44x7Em5uG6UBehNtFxYTrtnvB6LHoHrlxqXmVGMeJLyfV 4kmBWqbd50AfOtmHIwt3nceqnRDbA2GUCv+48mmMfXxNEVyZicDnrU2eYGQtn9J200ri P5uH72NJYShDx2ZxGyC8AcDUw/16GaiVq48xjggWd1oD97UuxkeADjvfhr4C8FsHlQah qBHA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@ndufresne-ca.20210112.gappssmtp.com header.s=20210112 header.b=gYFcfpoz; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id a20si6886535edj.610.2021.11.01.07.57.16; Mon, 01 Nov 2021 07:57:40 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@ndufresne-ca.20210112.gappssmtp.com header.s=20210112 header.b=gYFcfpoz; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231362AbhKAOzO (ORCPT + 99 others); Mon, 1 Nov 2021 10:55:14 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:33794 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229826AbhKAOzO (ORCPT ); Mon, 1 Nov 2021 10:55:14 -0400 Received: from mail-qt1-x82d.google.com (mail-qt1-x82d.google.com [IPv6:2607:f8b0:4864:20::82d]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 919AAC061714 for ; Mon, 1 Nov 2021 07:52:40 -0700 (PDT) Received: by mail-qt1-x82d.google.com with SMTP id h14so15232504qtb.3 for ; Mon, 01 Nov 2021 07:52:40 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ndufresne-ca.20210112.gappssmtp.com; s=20210112; h=message-id:subject:from:to:cc:date:in-reply-to:references :user-agent:mime-version:content-transfer-encoding; bh=mpvNT8Ri6AwqEAbY0lXNb8KCZijn3p0iMge2tpFnF0M=; b=gYFcfpozzpHSUVgfxwxaPadsAqpgcmqTGigotPMhTxb2xsahsKb8P3ZraJ94GXFhQi 0IksXfpjirucdEvciGM0dsyAkZ/pPw4wZQ/+YNt8vu8nzmconlrGozSJ4CPp5Q25Ly9d VouUjaOAA0JsNiTUoq83voi+7jYcu+dtxtQ+9PsZ5hC+ONOfbq7hdW7QT+pBrO0TfLyo gXW75QosgGlqgcUITWa3Hrh+LnsZjNoe+nTqSxcf9HUVJ1otiz1gRNJPLJ8rGZIDGlrX NtP1hvRyUoiQq7aIm2xC9ULZ8Q9V8qVL441FLxKajFtcUEOEUc6hcCAzWFwWT8BNHrxo ydeQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:message-id:subject:from:to:cc:date:in-reply-to :references:user-agent:mime-version:content-transfer-encoding; bh=mpvNT8Ri6AwqEAbY0lXNb8KCZijn3p0iMge2tpFnF0M=; b=Ipr7A09juKHykPjnAYpxZUYOoD3+88+2pVBjAaGkL46pEHloewfDFo2GfJuxhYLwgC YvlnU26qzC8zkTKJodGUafP1lSEBZiZsJjr7pBEsUR2fb87wwmYz7oYCxPwQ0Yxag88k U5/M935X+YjQy65NKRcJGNGQpLf7+EJCIcFiFJwmPckjXYQ1JYzuKSHNIMY8qzYTmTiJ +euE4rnsgUOlk0VlmSN6fRKtIC7LwqSZLQgdbrOxxUA1oFkBWceLtFX91qEBiQwJu8xj PnTPSYRbk8TvtEfOmVsuWVmYBBwDI2cnPLBjzAuJ//5EKM64uUy/qUAtzyYypfLhKUr3 ZVhg== X-Gm-Message-State: AOAM533QrJS+ITmuyhF0lxAzDY0Z8vZBNdSiVtppUaiLHXxax5wCdQGq CaDeoOd30SzWAJWRcGkw86m1Ww== X-Received: by 2002:ac8:5794:: with SMTP id v20mr30445002qta.243.1635778359759; Mon, 01 Nov 2021 07:52:39 -0700 (PDT) Received: from nicolas-tpx395.localdomain (mtl.collabora.ca. [66.171.169.34]) by smtp.gmail.com with ESMTPSA id z19sm10100639qts.96.2021.11.01.07.52.38 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 01 Nov 2021 07:52:39 -0700 (PDT) Message-ID: Subject: Re: [EXT] Re: [PATCH] media: docs: dev-decoder: add restrictions about CAPTURE buffers From: Nicolas Dufresne To: Stanimir Varbanov , Ming Qian , Alexandre Courbot , Mauro Carvalho Chehab , Hans Verkuil , Tomasz Figa Cc: "linux-media@vger.kernel.org" , "linux-kernel@vger.kernel.org" Date: Mon, 01 Nov 2021 10:52:38 -0400 In-Reply-To: References: <20211018091427.88468-1-acourbot@chromium.org> <9cb4f64e2ec3959df44b71dd69ef95697920dc4b.camel@ndufresne.ca> Content-Type: text/plain; charset="UTF-8" User-Agent: Evolution 3.40.4 (3.40.4-2.fc34) MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Le vendredi 29 octobre 2021 à 10:28 +0300, Stanimir Varbanov a écrit : > > On 10/29/21 5:10 AM, Ming Qian wrote: > > > -----Original Message----- > > > From: Nicolas Dufresne [mailto:nicolas@ndufresne.ca] > > > Sent: Tuesday, October 26, 2021 10:12 PM > > > To: Alexandre Courbot ; Mauro Carvalho Chehab > > > ; Hans Verkuil ; Tomasz Figa > > > > > > Cc: linux-media@vger.kernel.org; linux-kernel@vger.kernel.org > > > Subject: [EXT] Re: [PATCH] media: docs: dev-decoder: add restrictions about > > > CAPTURE buffers > > > > > > Caution: EXT Email > > > > > > Le lundi 18 octobre 2021 à 18:14 +0900, Alexandre Courbot a écrit : > > > > CAPTURE buffers might be read by the hardware after they are dequeued, > > > > which goes against the general idea that userspace has full control > > > > over dequeued buffers. Explain why and document the restrictions that > > > > this implies for userspace. > > > > > > > > Signed-off-by: Alexandre Courbot > > > > --- > > > > .../userspace-api/media/v4l/dev-decoder.rst | 17 > > > +++++++++++++++++ > > > > 1 file changed, 17 insertions(+) > > > > > > > > diff --git a/Documentation/userspace-api/media/v4l/dev-decoder.rst > > > > b/Documentation/userspace-api/media/v4l/dev-decoder.rst > > > > index 5b9b83feeceb..3cf2b496f2d0 100644 > > > > --- a/Documentation/userspace-api/media/v4l/dev-decoder.rst > > > > +++ b/Documentation/userspace-api/media/v4l/dev-decoder.rst > > > > @@ -752,6 +752,23 @@ available to dequeue. Specifically: > > > > buffers are out-of-order compared to the ``OUTPUT`` buffers): > > > ``CAPTURE`` > > > > timestamps will not retain the order of ``OUTPUT`` timestamps. > > > > > > > > +.. note:: > > > > + > > > > + The backing memory of ``CAPTURE`` buffers that are used as reference > > > frames > > > > + by the stream may be read by the hardware even after they are > > > dequeued. > > > > + Consequently, the client should avoid writing into this memory while the > > > > + ``CAPTURE`` queue is streaming. Failure to observe this may result in > > > > + corruption of decoded frames. > > > > + > > > > + Similarly, when using a memory type other than > > > ``V4L2_MEMORY_MMAP``, the > > > > + client should make sure that each ``CAPTURE`` buffer is always queued > > > with > > > > + the same backing memory for as long as the ``CAPTURE`` queue is > > > streaming. > > > > + The reason for this is that V4L2 buffer indices can be used by drivers to > > > > + identify frames. Thus, if the backing memory of a reference frame is > > > > + submitted under a different buffer ID, the driver may misidentify it and > > > > + decode a new frame into it while it is still in use, resulting in corruption > > > > + of the following frames. > > > > + > > > > > > I think this is nice addition, but insufficient. We should extend the API with a > > > flags that let application know if the buffers are reference or secondary. For the > > > context, we have a mix of CODEC that will output usable reference frames and > > > needs careful manipulation and many other drivers where the buffers *maybe* > > > secondary, meaning they may have been post-processed and modifying these > > > in- place may have no impact. > > > > > > The problem is the "may", that will depends on the chosen CAPTURE format. I > > > believe we should flag this, this flag should be set by the driver, on CAPTURE > > > queue. The information is known after S_FMT, so Format Flag, Reqbufs > > > capabilities or querybuf flags are candidates. I think the buffer flags are the > > > best named flag, though we don't expect this to differ per buffer. Though, > > > userspace needs to call querybuf for all buf in order to export or map them. > > > > > > What userspace can do with this is to export the DMABuf as read-only, and > > > signal this internally in its own context. This is great to avoid any unwanted > > > side effect described here. > > > > I think a flag should be add to tell a buffer is reference or secondary. > > But for some codec, it's hard to determine the buffer flag when reqbufs. > > The buffer flag should be dynamically updated by driver. > > User can check the flag after dqbuf every time. > > +1 > > I'm not familiar with stateless decoders where on the reqbuf time it > could work, debut for stateful coders it should be a dynamic flag on > every capture buffer. This isn't very clear request here, on which C structure to you say you would prefer this ? There is no difference for stateful/stateless for this regard. The capture format must have been configured prior to reqbuf, so nothing post S_FMT(CAPTURE) can every be very dynamic. I think the flag in S_FMT is miss-named and would create confusion. struct v4l2_reqbufs vs struc v4l2_buffer are equivalent. The seconds opens for flexibility. In fact, for some certain CODEC, there exist B-Frames that are never used as references, so these could indeed can be written to even if the buffer are not secondary. I think recommending to flag this in v4l2_buffer, and read through VIDIOC_QUERYBUF would be the best choice. > > > > > > > > > > During the decoding, the decoder may initiate one of the special > > > > sequences, as listed below. The sequences will result in the decoder > > > > returning all the ``CAPTURE`` buffers that originated from all the > > > > ``OUTPUT`` buffers processed > > > > > >