Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp81692imu; Mon, 26 Nov 2018 08:12:29 -0800 (PST) X-Google-Smtp-Source: AFSGD/WKMTNSiu6UHUN79yqU4KOvdzoLwlVaJ6dCzcjhXUT+volMBP4eOBQR7bVswDk4gbkEOiec X-Received: by 2002:a63:5664:: with SMTP id g36mr25286680pgm.313.1543248749097; Mon, 26 Nov 2018 08:12:29 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1543248749; cv=none; d=google.com; s=arc-20160816; b=FSw1Ext97gLRcntSzgwkQhZg1QjbaIH4NesZBCGbM6P7+Ub3V4hEfqX1vVp4mx1hOJ 5NCtngPMuIC4FdiJFxlNkNKZqNPdbb3VOI3tbNxqT1AMITYMCr0tfqkad4p45S4Ga2bI XUG8BfPzFRuc7fcySgD5OnBTHg9bzxv+b+EQ0ikfLuNumenR4FXm5jtins2eiJ1r++uH Nl3D9G43ace8vJyxNl0+w26LIOu26dzeKmi+H9d0rk/QGyxIFPL9NVgWa+33yEwqufqd 2o2Uy+rZRm11PEKbz2TRcC4Dxcmx3T3RVeSXX+S5Qu86u5f+6GDXHBgCZn/PQUaouJKn krug== 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=5vmevvKkHGktpMcUCcOUxUXKw84LE0ckbwMcnxes624=; b=GjdSRsrIE+haerjkRkT/RN2IwbfhrFUKl/f/aDP/nb1u6qfojgODplK+D5xEYTYN6g CqxYJXohQlOObJWe53CQK+LewSmoslZXDCjjvYvABp6Hop/IZWcYMHoYKBijjdWriV4S FDxotbf0mIXmn2282rgsGEL8EtBuPIoZraC3iKnqMMXNQCGvvZFRzOFyNYecYHGhUVYN quMOSBSWJaUzjKCKCVu085TcKrUzWorzsq6IpVkvkONVzLQrTKOKRfyeby1M5keaFxcI E8U3Ogwl3Kj3oBNy8+VXdJRqTOzQuKwoiqqIWIVzCxBoM0AdQpZpOXGsGpo+nyA1wGU4 CbXw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=io5sm20O; 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 d8si794813pln.128.2018.11.26.08.10.46; Mon, 26 Nov 2018 08:12:29 -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; dkim=pass header.i=@chromium.org header.s=google header.b=io5sm20O; 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 S1726500AbeK0DB5 (ORCPT + 99 others); Mon, 26 Nov 2018 22:01:57 -0500 Received: from mail-yw1-f66.google.com ([209.85.161.66]:33135 "EHLO mail-yw1-f66.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726315AbeK0DB4 (ORCPT ); Mon, 26 Nov 2018 22:01:56 -0500 Received: by mail-yw1-f66.google.com with SMTP id q11so7770274ywa.0 for ; Mon, 26 Nov 2018 08:07:23 -0800 (PST) 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=5vmevvKkHGktpMcUCcOUxUXKw84LE0ckbwMcnxes624=; b=io5sm20OJu8Tm1hraLjDTWjiYjfwoQ0SvEhA4Kilg0knzn52z/UClmZ4EaaPLGbzUc P279CBV8Dtddz6VYMCfm/QpMT+xyh3KMJ+5ZApkK19U/1uWHx+Hji14+9k/pjZLx6mZN mpzN92B9xHGGzKrzQoa9yoF5WnfsMspr0LXkA= 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=5vmevvKkHGktpMcUCcOUxUXKw84LE0ckbwMcnxes624=; b=TxaNvJ4e5Mlt4dMk5BF90UB8qHGv9JaGPh41ValF7mUBZoa8LRqaqPZ2XLHHYkvfGM Run22Y6gSRmm6ndQEqq3S6gsLDoehFGDquGKWuP6VBG5wTcBZQwpmqFLdcA75z/gju+7 yDMrKwasO02azfhECA87ht4631vWSPlo2232/tpPaR3wmY9d/WmJFu/gW43hbVociXUw doKxrvUMkuuE8k99O3M6ol2vPv1OY5jJW0HVQYhXFlMm5JRDHjE2o0i8kEP/8X4urQ1v I+ekidLyv1+qtbTbLV1P1SZQF7jHWiPUtWBuUVdLZ623k22TfEDt9ep84FFyZ4XhBSYo 3pgg== X-Gm-Message-State: AGRZ1gJHKmqf0bbkpAFY4ZjcerCQvZNJq7M9lzcZphKs+H3M6I99yYSR vAgFV5lC8ePkI+/giv5J0i7MQQM3SvM= X-Received: by 2002:a81:3e27:: with SMTP id l39mr27757354ywa.89.1543248442488; Mon, 26 Nov 2018 08:07:22 -0800 (PST) Received: from mail-yw1-f47.google.com (mail-yw1-f47.google.com. [209.85.161.47]) by smtp.gmail.com with ESMTPSA id e194sm198750ywa.85.2018.11.26.08.07.20 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 26 Nov 2018 08:07:22 -0800 (PST) Received: by mail-yw1-f47.google.com with SMTP id y194so7753975ywg.3 for ; Mon, 26 Nov 2018 08:07:20 -0800 (PST) X-Received: by 2002:a81:3dc4:: with SMTP id k187-v6mr29993044ywa.415.1543248439826; Mon, 26 Nov 2018 08:07:19 -0800 (PST) MIME-Version: 1.0 References: <1543227173-2160-1-git-send-email-mgottam@codeaurora.org> <57b28a7f-8c5c-22d2-2f89-e6d6ebdcb8a2@xs4all.nl> <2a8bbdf7-cec6-4bdf-5833-93d5014ddf89@xs4all.nl> In-Reply-To: <2a8bbdf7-cec6-4bdf-5833-93d5014ddf89@xs4all.nl> From: Tomasz Figa Date: Tue, 27 Nov 2018 01:07:06 +0900 X-Gmail-Original-Message-ID: Message-ID: Subject: Re: [PATCH v3] media: venus: amend buffer size for bitstream plane To: Hans Verkuil Cc: Stanimir Varbanov , mgottam@codeaurora.org, Mauro Carvalho Chehab , Linux Media Mailing List , Linux Kernel Mailing List , linux-arm-msm , Alexandre Courbot , vgarodia@codeaurora.org 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, Nov 27, 2018 at 1:00 AM Hans Verkuil wrote: > > On 11/26/2018 04:44 PM, Tomasz Figa wrote: > > Hi Hans, > > > > On Tue, Nov 27, 2018 at 12:24 AM Hans Verkuil wrote: > >> > >> On 11/26/2018 03:57 PM, Stanimir Varbanov wrote: > >>> Hi Hans, > >>> > >>> On 11/26/18 3:37 PM, Hans Verkuil wrote: > >>>> On 11/26/2018 11:12 AM, Malathi Gottam wrote: > >>>>> Accept the buffer size requested by client and compare it > >>>>> against driver calculated size and set the maximum to > >>>>> bitstream plane. > >>>>> > >>>>> Signed-off-by: Malathi Gottam > >>>> > >>>> Sorry, this isn't allowed. It is the driver that sets the sizeimage value, > >>>> never the other way around. > >>> > >>> I think for decoders (OUTPUT queue) and encoders (CAPTURE queue) we > >>> allowed userspace to set sizeimage for buffers. See [1] Initialization > >>> paragraph point 2: > >>> > >>> ``sizeimage`` > >>> desired size of ``CAPTURE`` buffers; the encoder may adjust it to > >>> match hardware requirements > >>> > >>> Similar patch we be needed for decoder as well. > >> > >> I may have missed that change since it wasn't present in v1 of the stateful > >> encoder spec. > > > > It's been there from the very beginning, even before I started working > > on it. Actually, even the early slides from Kamil mention the > > application setting the buffer size for compressed streams: > > https://events.static.linuxfound.org/images/stories/pdf/lceu2012_debski.pdf > > > >> > >> Tomasz, what was the reason for this change? I vaguely remember some thread > >> about this, but I forgot the details. Since this would be a departure of > >> the current API this should be explained in more detail. > > > > The kernel is not the place to encode assumptions about optimal > > bitstream chunk sizes. It depends on the use case and the application > > should be able decide. It may for example want to use smaller buffers, > > optimizing for the well compressible video streams and just reallocate > > if bigger chunks are needed. > > > >> > >> I don't really see the point of requiring userspace to fill this in. For > >> stateful codecs it can just return some reasonable size. Possibly calculated > >> using the provided width/height values or (if those are 0) some default value. > > > > How do we decide what's "reasonable"? Would it be reasonable for all > > applications? > > In theory it should be the minimum size that the hardware supports. But it is > silly to i.e. provide the size of one PAGE as the minimum. In practice you > probably want to set sizeimage to something larger than that. Depending on > the typical compression ratio perhaps 5 or 10% of what a raw YUV 4:2:0 frame > would be. > > > > >> > >> Ditto for decoders. > >> > >> Stanimir, I certainly cannot merge this until this has been fully nailed down > >> as it would be a departure from the current API. > > > > It would not be a departure, because I can see existing stateful > > drivers behaving like that: > > https://elixir.bootlin.com/linux/v4.20-rc4/source/drivers/media/platform/s5p-mfc/s5p_mfc_enc.c#L1444 > > https://elixir.bootlin.com/linux/v4.20-rc4/source/drivers/media/platform/mtk-vcodec/mtk_vcodec_enc.c#L469 > > Yes, and that's out of spec. Clearly v4l2-compliance doesn't test for this. > It should have been caught at least for the mtk driver. > Perhaps we should make it a part of the spec then? Actually I'm not really sure if we can say that this is out of spec There has been no clear spec for the stateful codecs for many years, with drivers doing wildly whatever they like and applications ending up relying on those quirks. My spec actually attempts to incorporate what was decided on the earlier summits, including what's in Kamil's slides, the drivers are already doing and existing applications rely on. The sizeimage handling is just a part of it. > > > > Also, Chromium has been setting the size on its own for long time > > using its own heuristics. > > > >> > >> And looking at the venus patch I do not see how it helps userspace. > >> > >> Regards, > >> > >> Hans > >> > >>> > >>>> > >>>> If you need to allocate larger buffers, then use VIDIOC_CREATE_BUFS instead > >>>> of VIDIOC_REQBUFS. > > > > CREATE_BUFS wouldn't work, because one needs to use TRY_FMT to obtain > > a format for it and the format returned by it would have the sizeimage > > as hardcoded in the driver... > > ??? > > Userspace can change the sizeimage to whatever it wants before calling > CREATE_BUFS as long as it is >= the sizeimage of the current format. > > If we want to allow smaller sizes, then I think that would not be > unreasonable for stateful codecs. I actually think that drivers can > already do this in queue_setup(), but the spec would have to be updated > a bit. Existing applications rely on REQBUFS honoring the size they set in sizeimage, though... Best regards, Tomasz