[{"id":19515,"web_url":"https://patchwork.libcamera.org/comment/19515/","msgid":"<2c986781-2f73-452c-a795-24c43c841622@ideasonboard.com>","date":"2021-09-07T14:17:48","subject":"Re: [libcamera-devel] [PATCH v3 30/30] v4l2: Sum bytesused for all\n\tplanes when dequeuing buffer","submitter":{"id":4,"url":"https://patchwork.libcamera.org/api/people/4/","name":"Kieran Bingham","email":"kieran.bingham@ideasonboard.com"},"content":"On 06/09/2021 23:56, Laurent Pinchart wrote:\n> The V4L2 compatibility layer supports the single-planar API only, and\n> thuss expose a single V4L2 buffer plane to applications, regardless of\n\ns/thuss/thus/\ns/expose/exposes/\n\n> the number of planes in the FrameBuffer. For multi-planar frame buffers,\n> the bytesused value isn't correct as it only takes the first plane into\n> account. Fix it by summing the bytesused values for all FrameBuffer\n> planes.\n> \n> Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>\n> ---\n>  src/v4l2/v4l2_camera_proxy.cpp | 7 ++++++-\n>  1 file changed, 6 insertions(+), 1 deletion(-)\n> \n> diff --git a/src/v4l2/v4l2_camera_proxy.cpp b/src/v4l2/v4l2_camera_proxy.cpp\n> index 07d2250bb846..aeffef26c5bf 100644\n> --- a/src/v4l2/v4l2_camera_proxy.cpp\n> +++ b/src/v4l2/v4l2_camera_proxy.cpp\n> @@ -11,6 +11,7 @@\n>  #include <array>\n>  #include <errno.h>\n>  #include <linux/videodev2.h>\n> +#include <numeric>\n>  #include <set>\n>  #include <string.h>\n>  #include <sys/mman.h>\n> @@ -211,7 +212,11 @@ void V4L2CameraProxy::updateBuffers()\n>  \n>  \t\tswitch (fmd.status) {\n>  \t\tcase FrameMetadata::FrameSuccess:\n> -\t\t\tbuf.bytesused = fmd.planes()[0].bytesused;\n> +\t\t\tbuf.bytesused = std::accumulate(fmd.planes().begin(),\n> +\t\t\t\t\t\t\tfmd.planes().end(), 0,\n> +\t\t\t\t\t\t\t[](unsigned int total, const auto &plane) {\n\nlambda's always look like black magic to me.\nI assume total is either automatically initialised, or initialised by\nthe 0 after fmd.planes().end()\n\nReviewed-by: Kieran Bingham <kieran.bingham@ideasonboard.com>\n\n> +\t\t\t\t\t\t\t\treturn total + plane.bytesused;\n> +\t\t\t\t\t\t\t});\n>  \t\t\tbuf.field = V4L2_FIELD_NONE;\n>  \t\t\tbuf.timestamp.tv_sec = fmd.timestamp / 1000000000;\n>  \t\t\tbuf.timestamp.tv_usec = fmd.timestamp % 1000000;\n>","headers":{"Return-Path":"<libcamera-devel-bounces@lists.libcamera.org>","X-Original-To":"parsemail@patchwork.libcamera.org","Delivered-To":"parsemail@patchwork.libcamera.org","Received":["from lancelot.ideasonboard.com (lancelot.ideasonboard.com\n\t[92.243.16.209])\n\tby patchwork.libcamera.org (Postfix) with ESMTPS id 99644BE175\n\tfor <parsemail@patchwork.libcamera.org>;\n\tTue,  7 Sep 2021 14:17:51 +0000 (UTC)","from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id 5F5166916C;\n\tTue,  7 Sep 2021 16:17:51 +0200 (CEST)","from perceval.ideasonboard.com (perceval.ideasonboard.com\n\t[IPv6:2001:4b98:dc2:55:216:3eff:fef7:d647])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id B162660251\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tTue,  7 Sep 2021 16:17:50 +0200 (CEST)","from [192.168.0.20]\n\t(cpc89244-aztw30-2-0-cust3082.18-1.cable.virginm.net [86.31.172.11])\n\tby perceval.ideasonboard.com (Postfix) with ESMTPSA id 3CFED24F;\n\tTue,  7 Sep 2021 16:17:50 +0200 (CEST)"],"Authentication-Results":"lancelot.ideasonboard.com; dkim=pass (1024-bit key;\n\tunprotected) header.d=ideasonboard.com header.i=@ideasonboard.com\n\theader.b=\"MqRzI22J\"; dkim-atps=neutral","DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com;\n\ts=mail; t=1631024270;\n\tbh=LlIOCaCE1hUXEWyeIj1kvULBc5RQPcMjzdjCmQgw6dc=;\n\th=Subject:To:References:From:Date:In-Reply-To:From;\n\tb=MqRzI22JSXcLlUjvTprwEQkh83ckMk6fj8Ftem9Pn/lbrXUZ1WqH4f5mRhBcJ/hnu\n\tnlEVo0AQ/nhvWioEH9GS98UTSSXQ5kbjAVJ2htw6NfO4mhH/o8h1eqc5cttarKjfIl\n\tbcgIcCq+Jty64eDe3ZgsHmmPBky4YOIAd0ob/Ojk=","To":"Laurent Pinchart <laurent.pinchart@ideasonboard.com>,\n\tlibcamera-devel@lists.libcamera.org","References":"<20210906225420.13275-1-laurent.pinchart@ideasonboard.com>\n\t<20210906225636.14683-30-laurent.pinchart@ideasonboard.com>","From":"Kieran Bingham <kieran.bingham@ideasonboard.com>","Message-ID":"<2c986781-2f73-452c-a795-24c43c841622@ideasonboard.com>","Date":"Tue, 7 Sep 2021 15:17:48 +0100","User-Agent":"Mozilla/5.0 (X11; Linux x86_64; rv:78.0) Gecko/20100101\n\tThunderbird/78.11.0","MIME-Version":"1.0","In-Reply-To":"<20210906225636.14683-30-laurent.pinchart@ideasonboard.com>","Content-Type":"text/plain; charset=utf-8","Content-Language":"en-GB","Content-Transfer-Encoding":"7bit","Subject":"Re: [libcamera-devel] [PATCH v3 30/30] v4l2: Sum bytesused for all\n\tplanes when dequeuing buffer","X-BeenThere":"libcamera-devel@lists.libcamera.org","X-Mailman-Version":"2.1.29","Precedence":"list","List-Id":"<libcamera-devel.lists.libcamera.org>","List-Unsubscribe":"<https://lists.libcamera.org/options/libcamera-devel>,\n\t<mailto:libcamera-devel-request@lists.libcamera.org?subject=unsubscribe>","List-Archive":"<https://lists.libcamera.org/pipermail/libcamera-devel/>","List-Post":"<mailto:libcamera-devel@lists.libcamera.org>","List-Help":"<mailto:libcamera-devel-request@lists.libcamera.org?subject=help>","List-Subscribe":"<https://lists.libcamera.org/listinfo/libcamera-devel>,\n\t<mailto:libcamera-devel-request@lists.libcamera.org?subject=subscribe>","Errors-To":"libcamera-devel-bounces@lists.libcamera.org","Sender":"\"libcamera-devel\" <libcamera-devel-bounces@lists.libcamera.org>"}},{"id":19517,"web_url":"https://patchwork.libcamera.org/comment/19517/","msgid":"<170230ad-2395-bd53-1934-571641bdae4c@ideasonboard.com>","date":"2021-09-07T14:26:55","subject":"Re: [libcamera-devel] [PATCH v3 30/30] v4l2: Sum bytesused for all\n\tplanes when dequeuing buffer","submitter":{"id":75,"url":"https://patchwork.libcamera.org/api/people/75/","name":"Jean-Michel Hautbois","email":"jeanmichel.hautbois@ideasonboard.com"},"content":"Hi Laurent,\n\nOn 07/09/2021 16:17, Kieran Bingham wrote:\n> On 06/09/2021 23:56, Laurent Pinchart wrote:\n>> The V4L2 compatibility layer supports the single-planar API only, and\n>> thuss expose a single V4L2 buffer plane to applications, regardless of\n> \n> s/thuss/thus/\n> s/expose/exposes/\n> \n>> the number of planes in the FrameBuffer. For multi-planar frame buffers,\n>> the bytesused value isn't correct as it only takes the first plane into\n>> account. Fix it by summing the bytesused values for all FrameBuffer\n>> planes.\n>>\n>> Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>\n>> ---\n>>  src/v4l2/v4l2_camera_proxy.cpp | 7 ++++++-\n>>  1 file changed, 6 insertions(+), 1 deletion(-)\n>>\n>> diff --git a/src/v4l2/v4l2_camera_proxy.cpp b/src/v4l2/v4l2_camera_proxy.cpp\n>> index 07d2250bb846..aeffef26c5bf 100644\n>> --- a/src/v4l2/v4l2_camera_proxy.cpp\n>> +++ b/src/v4l2/v4l2_camera_proxy.cpp\n>> @@ -11,6 +11,7 @@\n>>  #include <array>\n>>  #include <errno.h>\n>>  #include <linux/videodev2.h>\n>> +#include <numeric>\n>>  #include <set>\n>>  #include <string.h>\n>>  #include <sys/mman.h>\n>> @@ -211,7 +212,11 @@ void V4L2CameraProxy::updateBuffers()\n>>  \n>>  \t\tswitch (fmd.status) {\n>>  \t\tcase FrameMetadata::FrameSuccess:\n>> -\t\t\tbuf.bytesused = fmd.planes()[0].bytesused;\n>> +\t\t\tbuf.bytesused = std::accumulate(fmd.planes().begin(),\n>> +\t\t\t\t\t\t\tfmd.planes().end(), 0,\n>> +\t\t\t\t\t\t\t[](unsigned int total, const auto &plane) {\n> \n> lambda's always look like black magic to me.\n> I assume total is either automatically initialised, or initialised by\n> the 0 after fmd.planes().end()\n\nI read back cpp reference for that one :-), and yes, total takes the\nvalue of init, which is 0.\n\n> \n> Reviewed-by: Kieran Bingham <kieran.bingham@ideasonboard.com>\nReviewed-by: Jean-Michel Hautbois <jeanmichel.hautbois@ideasonboard.com>\n> \n>> +\t\t\t\t\t\t\t\treturn total + plane.bytesused;\n>> +\t\t\t\t\t\t\t});\n>>  \t\t\tbuf.field = V4L2_FIELD_NONE;\n>>  \t\t\tbuf.timestamp.tv_sec = fmd.timestamp / 1000000000;\n>>  \t\t\tbuf.timestamp.tv_usec = fmd.timestamp % 1000000;\n>>","headers":{"Return-Path":"<libcamera-devel-bounces@lists.libcamera.org>","X-Original-To":"parsemail@patchwork.libcamera.org","Delivered-To":"parsemail@patchwork.libcamera.org","Received":["from lancelot.ideasonboard.com (lancelot.ideasonboard.com\n\t[92.243.16.209])\n\tby patchwork.libcamera.org (Postfix) with ESMTPS id A4CF7BE175\n\tfor <parsemail@patchwork.libcamera.org>;\n\tTue,  7 Sep 2021 14:26:59 +0000 (UTC)","from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id 3A4A46916C;\n\tTue,  7 Sep 2021 16:26:59 +0200 (CEST)","from perceval.ideasonboard.com (perceval.ideasonboard.com\n\t[213.167.242.64])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id EF11560251\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tTue,  7 Sep 2021 16:26:57 +0200 (CEST)","from tatooine.ideasonboard.com (unknown\n\t[IPv6:2a01:e0a:169:7140:e0a9:3439:7934:19a5])\n\tby perceval.ideasonboard.com (Postfix) with ESMTPSA id 89C7C24F;\n\tTue,  7 Sep 2021 16:26:57 +0200 (CEST)"],"Authentication-Results":"lancelot.ideasonboard.com; dkim=pass (1024-bit key;\n\tunprotected) header.d=ideasonboard.com header.i=@ideasonboard.com\n\theader.b=\"gF/KlxSx\"; dkim-atps=neutral","DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com;\n\ts=mail; t=1631024817;\n\tbh=b1oq7MGvnPLeMVGK31g+QdK3B1CImygP1dm6uMEevUM=;\n\th=Subject:To:References:From:Date:In-Reply-To:From;\n\tb=gF/KlxSxiNxb+M+Ssxzol8p5ViLy2RN6KjD0sBrEESTFQKZSSXPUoYybAXwphLivY\n\tjemPYo4m1fCk2QfYQW42VIYWpAWsxw8N2ub70dnlMWiMJsHj/AeZkeE1scIhMIW+mC\n\tQcd4y4uibGaXzFuBynddk2VWPnDpuAPJiazGuGFM=","To":"Kieran Bingham <kieran.bingham@ideasonboard.com>,\n\tLaurent Pinchart <laurent.pinchart@ideasonboard.com>,\n\tlibcamera-devel@lists.libcamera.org","References":"<20210906225420.13275-1-laurent.pinchart@ideasonboard.com>\n\t<20210906225636.14683-30-laurent.pinchart@ideasonboard.com>\n\t<2c986781-2f73-452c-a795-24c43c841622@ideasonboard.com>","From":"Jean-Michel Hautbois <jeanmichel.hautbois@ideasonboard.com>","Message-ID":"<170230ad-2395-bd53-1934-571641bdae4c@ideasonboard.com>","Date":"Tue, 7 Sep 2021 16:26:55 +0200","User-Agent":"Mozilla/5.0 (X11; Linux x86_64; rv:78.0) Gecko/20100101\n\tThunderbird/78.13.0","MIME-Version":"1.0","In-Reply-To":"<2c986781-2f73-452c-a795-24c43c841622@ideasonboard.com>","Content-Type":"text/plain; charset=utf-8","Content-Language":"en-US","Content-Transfer-Encoding":"7bit","Subject":"Re: [libcamera-devel] [PATCH v3 30/30] v4l2: Sum bytesused for all\n\tplanes when dequeuing buffer","X-BeenThere":"libcamera-devel@lists.libcamera.org","X-Mailman-Version":"2.1.29","Precedence":"list","List-Id":"<libcamera-devel.lists.libcamera.org>","List-Unsubscribe":"<https://lists.libcamera.org/options/libcamera-devel>,\n\t<mailto:libcamera-devel-request@lists.libcamera.org?subject=unsubscribe>","List-Archive":"<https://lists.libcamera.org/pipermail/libcamera-devel/>","List-Post":"<mailto:libcamera-devel@lists.libcamera.org>","List-Help":"<mailto:libcamera-devel-request@lists.libcamera.org?subject=help>","List-Subscribe":"<https://lists.libcamera.org/listinfo/libcamera-devel>,\n\t<mailto:libcamera-devel-request@lists.libcamera.org?subject=subscribe>","Errors-To":"libcamera-devel-bounces@lists.libcamera.org","Sender":"\"libcamera-devel\" <libcamera-devel-bounces@lists.libcamera.org>"}},{"id":19521,"web_url":"https://patchwork.libcamera.org/comment/19521/","msgid":"<YTd9eunhwB1IxFAy@pendragon.ideasonboard.com>","date":"2021-09-07T14:55:54","subject":"Re: [libcamera-devel] [PATCH v3 30/30] v4l2: Sum bytesused for all\n\tplanes when dequeuing buffer","submitter":{"id":2,"url":"https://patchwork.libcamera.org/api/people/2/","name":"Laurent Pinchart","email":"laurent.pinchart@ideasonboard.com"},"content":"Hi Kieran,\n\nOn Tue, Sep 07, 2021 at 03:17:48PM +0100, Kieran Bingham wrote:\n> On 06/09/2021 23:56, Laurent Pinchart wrote:\n> > The V4L2 compatibility layer supports the single-planar API only, and\n> > thuss expose a single V4L2 buffer plane to applications, regardless of\n> \n> s/thuss/thus/\n> s/expose/exposes/\n> \n> > the number of planes in the FrameBuffer. For multi-planar frame buffers,\n> > the bytesused value isn't correct as it only takes the first plane into\n> > account. Fix it by summing the bytesused values for all FrameBuffer\n> > planes.\n> > \n> > Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>\n> > ---\n> >  src/v4l2/v4l2_camera_proxy.cpp | 7 ++++++-\n> >  1 file changed, 6 insertions(+), 1 deletion(-)\n> > \n> > diff --git a/src/v4l2/v4l2_camera_proxy.cpp b/src/v4l2/v4l2_camera_proxy.cpp\n> > index 07d2250bb846..aeffef26c5bf 100644\n> > --- a/src/v4l2/v4l2_camera_proxy.cpp\n> > +++ b/src/v4l2/v4l2_camera_proxy.cpp\n> > @@ -11,6 +11,7 @@\n> >  #include <array>\n> >  #include <errno.h>\n> >  #include <linux/videodev2.h>\n> > +#include <numeric>\n> >  #include <set>\n> >  #include <string.h>\n> >  #include <sys/mman.h>\n> > @@ -211,7 +212,11 @@ void V4L2CameraProxy::updateBuffers()\n> >  \n> >  \t\tswitch (fmd.status) {\n> >  \t\tcase FrameMetadata::FrameSuccess:\n> > -\t\t\tbuf.bytesused = fmd.planes()[0].bytesused;\n> > +\t\t\tbuf.bytesused = std::accumulate(fmd.planes().begin(),\n> > +\t\t\t\t\t\t\tfmd.planes().end(), 0,\n> > +\t\t\t\t\t\t\t[](unsigned int total, const auto &plane) {\n> \n> lambda's always look like black magic to me.\n> I assume total is either automatically initialised, or initialised by\n> the 0 after fmd.planes().end()\n\nThe latter (https://en.cppreference.com/w/cpp/algorithm/accumulate).\n\n> Reviewed-by: Kieran Bingham <kieran.bingham@ideasonboard.com>\n> \n> > +\t\t\t\t\t\t\t\treturn total + plane.bytesused;\n> > +\t\t\t\t\t\t\t});\n> >  \t\t\tbuf.field = V4L2_FIELD_NONE;\n> >  \t\t\tbuf.timestamp.tv_sec = fmd.timestamp / 1000000000;\n> >  \t\t\tbuf.timestamp.tv_usec = fmd.timestamp % 1000000;","headers":{"Return-Path":"<libcamera-devel-bounces@lists.libcamera.org>","X-Original-To":"parsemail@patchwork.libcamera.org","Delivered-To":"parsemail@patchwork.libcamera.org","Received":["from lancelot.ideasonboard.com (lancelot.ideasonboard.com\n\t[92.243.16.209])\n\tby patchwork.libcamera.org (Postfix) with ESMTPS id 87ED2BE175\n\tfor <parsemail@patchwork.libcamera.org>;\n\tTue,  7 Sep 2021 14:56:14 +0000 (UTC)","from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id 576DE60252;\n\tTue,  7 Sep 2021 16:56:14 +0200 (CEST)","from perceval.ideasonboard.com (perceval.ideasonboard.com\n\t[IPv6:2001:4b98:dc2:55:216:3eff:fef7:d647])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id E87BF60251\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tTue,  7 Sep 2021 16:56:12 +0200 (CEST)","from pendragon.ideasonboard.com (62-78-145-57.bb.dnainternet.fi\n\t[62.78.145.57])\n\tby perceval.ideasonboard.com (Postfix) with ESMTPSA id 832E024F;\n\tTue,  7 Sep 2021 16:56:12 +0200 (CEST)"],"Authentication-Results":"lancelot.ideasonboard.com; dkim=pass (1024-bit key;\n\tunprotected) header.d=ideasonboard.com header.i=@ideasonboard.com\n\theader.b=\"QnTJr0Zc\"; dkim-atps=neutral","DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com;\n\ts=mail; t=1631026572;\n\tbh=ntHcZrpEVeWdt4uKW2Qnjz0tB13xcvO9xDjcAaKU1v4=;\n\th=Date:From:To:Cc:Subject:References:In-Reply-To:From;\n\tb=QnTJr0ZcnuNsiq8nRT1ZNndwAjH/1dKJbrOGmoQguVFsA174cp3hwesfvxB5D9wV6\n\tf77YAIm7SWzgZHyY67nO9jcdWn8uIWK4clC2BVPfJnC/XFxji+kiRPnmtPzADidsqR\n\teBQUsPnhudxMKXwoqxmPztJkhYsepA02Qqo8c30A=","Date":"Tue, 7 Sep 2021 17:55:54 +0300","From":"Laurent Pinchart <laurent.pinchart@ideasonboard.com>","To":"Kieran Bingham <kieran.bingham@ideasonboard.com>","Message-ID":"<YTd9eunhwB1IxFAy@pendragon.ideasonboard.com>","References":"<20210906225420.13275-1-laurent.pinchart@ideasonboard.com>\n\t<20210906225636.14683-30-laurent.pinchart@ideasonboard.com>\n\t<2c986781-2f73-452c-a795-24c43c841622@ideasonboard.com>","MIME-Version":"1.0","Content-Type":"text/plain; charset=utf-8","Content-Disposition":"inline","In-Reply-To":"<2c986781-2f73-452c-a795-24c43c841622@ideasonboard.com>","Subject":"Re: [libcamera-devel] [PATCH v3 30/30] v4l2: Sum bytesused for all\n\tplanes when dequeuing buffer","X-BeenThere":"libcamera-devel@lists.libcamera.org","X-Mailman-Version":"2.1.29","Precedence":"list","List-Id":"<libcamera-devel.lists.libcamera.org>","List-Unsubscribe":"<https://lists.libcamera.org/options/libcamera-devel>,\n\t<mailto:libcamera-devel-request@lists.libcamera.org?subject=unsubscribe>","List-Archive":"<https://lists.libcamera.org/pipermail/libcamera-devel/>","List-Post":"<mailto:libcamera-devel@lists.libcamera.org>","List-Help":"<mailto:libcamera-devel-request@lists.libcamera.org?subject=help>","List-Subscribe":"<https://lists.libcamera.org/listinfo/libcamera-devel>,\n\t<mailto:libcamera-devel-request@lists.libcamera.org?subject=subscribe>","Cc":"libcamera-devel@lists.libcamera.org","Errors-To":"libcamera-devel-bounces@lists.libcamera.org","Sender":"\"libcamera-devel\" <libcamera-devel-bounces@lists.libcamera.org>"}}]