[{"id":19485,"web_url":"https://patchwork.libcamera.org/comment/19485/","msgid":"<0faffa37-7827-2a90-a457-5d62e7441b0e@ideasonboard.com>","date":"2021-09-06T23:37:49","subject":"Re: [libcamera-devel] [PATCH v3 12/30] libcamera: v4l2_videodevice:\n\tTake stride into account to compute offsets","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> When creating FrameBuffer instances, the V4L2VideoDevice computes plane\n> offsets using minimal stride for the format. This doesn't always produce\n> a valid result when the device requires padding at the end of lines. Fix\n> it by computing offsets using the stride reported by V4L2.\n> \n> Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>\n> Reviewed-by: Jean-Michel Hautbois <jeanmichel.hautbois@ideasonboard.com>\n> Reviewed-by: Hirokazu Honda <hiroh@chromium.org>\n> ---\n>  src/libcamera/v4l2_videodevice.cpp | 16 +++++++++++++---\n>  1 file changed, 13 insertions(+), 3 deletions(-)\n> \n> diff --git a/src/libcamera/v4l2_videodevice.cpp b/src/libcamera/v4l2_videodevice.cpp\n> index 88535f5a07c7..c6c9263c49e9 100644\n> --- a/src/libcamera/v4l2_videodevice.cpp\n> +++ b/src/libcamera/v4l2_videodevice.cpp\n> @@ -1354,11 +1354,21 @@ std::unique_ptr<FrameBuffer> V4L2VideoDevice::createBuffer(unsigned int index)\n>  \t\tsize_t offset = 0;\n>  \n>  \t\tfor (size_t i = 0; i < planes.size(); ++i) {\n> +\t\t\t/*\n> +\t\t\t * The stride is reported by V4L2 for the first plane\n> +\t\t\t * only. Compute the stride of the other planes by\n> +\t\t\t * taking the horizontal subsampling factor into\n> +\t\t\t * account, which is equal to the bytesPerGroup ratio of\n> +\t\t\t * the planes.\n> +\t\t\t */\n\nYikes, this feels like it might be fragile, but I can't see where it\nwould break yet so ... it sounds ok I think.\n\nReviewed-by: Kieran Bingham <kieran.bingham@ideasonboard.com>\n\n> +\t\t\tunsigned int stride = format_.planes[0].bpl\n> +\t\t\t\t\t    * formatInfo_->planes[i].bytesPerGroup\n> +\t\t\t\t\t    / formatInfo_->planes[0].bytesPerGroup;\n> +\n>  \t\t\tplanes[i].fd = fd;\n>  \t\t\tplanes[i].offset = offset;\n> -\n> -\t\t\t/* \\todo Take the V4L2 stride into account */\n> -\t\t\tplanes[i].length = formatInfo_->planeSize(format_.size, i);\n> +\t\t\tplanes[i].length = formatInfo_->planeSize(format_.size.height,\n> +\t\t\t\t\t\t\t\t  i, stride);\n>  \t\t\toffset += planes[i].length;\n>  \t\t}\n>  \t}\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 89E73BDC71\n\tfor <parsemail@patchwork.libcamera.org>;\n\tMon,  6 Sep 2021 23:37:53 +0000 (UTC)","from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id 22BB96916C;\n\tTue,  7 Sep 2021 01:37:53 +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 5789B60253\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tTue,  7 Sep 2021 01:37:52 +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 D61AF891;\n\tTue,  7 Sep 2021 01:37:51 +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=\"hh8GDNqL\"; dkim-atps=neutral","DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com;\n\ts=mail; t=1630971472;\n\tbh=uxA3zq5wQk/RsyOYALepx3NId5mbCMlInwau1mzv/Kw=;\n\th=Subject:To:References:From:Date:In-Reply-To:From;\n\tb=hh8GDNqLtItdsWvcCtV8naDaC65r1XFqVIssVE/OWXXOwKL9tf8qoKzo8a8jKQXXs\n\tHxRtbSbM9MHVO/Y+eMSqX2V45yJRIZhjAHSjmS9LLokPuy5730SUaZzlYzLrA4eAxJ\n\tMme5U+xlfAraBmr++WakRNn4WiWRvyG/GeKiDa/A=","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-12-laurent.pinchart@ideasonboard.com>","From":"Kieran Bingham <kieran.bingham@ideasonboard.com>","Message-ID":"<0faffa37-7827-2a90-a457-5d62e7441b0e@ideasonboard.com>","Date":"Tue, 7 Sep 2021 00:37:49 +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-12-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 12/30] libcamera: v4l2_videodevice:\n\tTake stride into account to compute offsets","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":19490,"web_url":"https://patchwork.libcamera.org/comment/19490/","msgid":"<YTasge56lOwywnGA@pendragon.ideasonboard.com>","date":"2021-09-07T00:04:17","subject":"Re: [libcamera-devel] [PATCH v3 12/30] libcamera: v4l2_videodevice:\n\tTake stride into account to compute offsets","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 12:37:49AM +0100, Kieran Bingham wrote:\n> On 06/09/2021 23:56, Laurent Pinchart wrote:\n> > When creating FrameBuffer instances, the V4L2VideoDevice computes plane\n> > offsets using minimal stride for the format. This doesn't always produce\n> > a valid result when the device requires padding at the end of lines. Fix\n> > it by computing offsets using the stride reported by V4L2.\n> > \n> > Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>\n> > Reviewed-by: Jean-Michel Hautbois <jeanmichel.hautbois@ideasonboard.com>\n> > Reviewed-by: Hirokazu Honda <hiroh@chromium.org>\n> > ---\n> >  src/libcamera/v4l2_videodevice.cpp | 16 +++++++++++++---\n> >  1 file changed, 13 insertions(+), 3 deletions(-)\n> > \n> > diff --git a/src/libcamera/v4l2_videodevice.cpp b/src/libcamera/v4l2_videodevice.cpp\n> > index 88535f5a07c7..c6c9263c49e9 100644\n> > --- a/src/libcamera/v4l2_videodevice.cpp\n> > +++ b/src/libcamera/v4l2_videodevice.cpp\n> > @@ -1354,11 +1354,21 @@ std::unique_ptr<FrameBuffer> V4L2VideoDevice::createBuffer(unsigned int index)\n> >  \t\tsize_t offset = 0;\n> >  \n> >  \t\tfor (size_t i = 0; i < planes.size(); ++i) {\n> > +\t\t\t/*\n> > +\t\t\t * The stride is reported by V4L2 for the first plane\n> > +\t\t\t * only. Compute the stride of the other planes by\n> > +\t\t\t * taking the horizontal subsampling factor into\n> > +\t\t\t * account, which is equal to the bytesPerGroup ratio of\n> > +\t\t\t * the planes.\n> > +\t\t\t */\n> \n> Yikes, this feels like it might be fragile, but I can't see where it\n> would break yet so ... it sounds ok I think.\n\nThat's the rule that V4L2 mandates, so I think it should be fine.\n\n> Reviewed-by: Kieran Bingham <kieran.bingham@ideasonboard.com>\n> \n> > +\t\t\tunsigned int stride = format_.planes[0].bpl\n> > +\t\t\t\t\t    * formatInfo_->planes[i].bytesPerGroup\n> > +\t\t\t\t\t    / formatInfo_->planes[0].bytesPerGroup;\n> > +\n> >  \t\t\tplanes[i].fd = fd;\n> >  \t\t\tplanes[i].offset = offset;\n> > -\n> > -\t\t\t/* \\todo Take the V4L2 stride into account */\n> > -\t\t\tplanes[i].length = formatInfo_->planeSize(format_.size, i);\n> > +\t\t\tplanes[i].length = formatInfo_->planeSize(format_.size.height,\n> > +\t\t\t\t\t\t\t\t  i, stride);\n> >  \t\t\toffset += planes[i].length;\n> >  \t\t}\n> >  \t}","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 DCB8CBE175\n\tfor <parsemail@patchwork.libcamera.org>;\n\tTue,  7 Sep 2021 00:04:38 +0000 (UTC)","from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id AD1176916A;\n\tTue,  7 Sep 2021 02:04:38 +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 E059E60253\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tTue,  7 Sep 2021 02:04:36 +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 7569C891;\n\tTue,  7 Sep 2021 02:04:36 +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=\"M+Xvea0N\"; dkim-atps=neutral","DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com;\n\ts=mail; t=1630973076;\n\tbh=7Wtp91qHBUyUXJ1QH2lo8yUcaBjXKScf3PB93ZfObQQ=;\n\th=Date:From:To:Cc:Subject:References:In-Reply-To:From;\n\tb=M+Xvea0NgvAmgyDMp1dJRqbraYju8sQ7oBvv7k6NsxBYsJWeu1Af06ZREX4rIKCZl\n\t7ycB2FpG2GipXJjbs6y4l/ql5rk/rCFx5mE5CI52G55D/kDOwdK+dn9Np6lPFqrefy\n\t1iOlSNo75dFcb4Rx+HPLsk34qgrfMLyNxhxHYa18=","Date":"Tue, 7 Sep 2021 03:04:17 +0300","From":"Laurent Pinchart <laurent.pinchart@ideasonboard.com>","To":"Kieran Bingham <kieran.bingham@ideasonboard.com>","Message-ID":"<YTasge56lOwywnGA@pendragon.ideasonboard.com>","References":"<20210906225420.13275-1-laurent.pinchart@ideasonboard.com>\n\t<20210906225636.14683-12-laurent.pinchart@ideasonboard.com>\n\t<0faffa37-7827-2a90-a457-5d62e7441b0e@ideasonboard.com>","MIME-Version":"1.0","Content-Type":"text/plain; charset=utf-8","Content-Disposition":"inline","In-Reply-To":"<0faffa37-7827-2a90-a457-5d62e7441b0e@ideasonboard.com>","Subject":"Re: [libcamera-devel] [PATCH v3 12/30] libcamera: v4l2_videodevice:\n\tTake stride into account to compute offsets","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>"}}]