[{"id":19505,"web_url":"https://patchwork.libcamera.org/comment/19505/","msgid":"<2ead3d34-c27f-dda8-c5d2-dec8fdba0b47@ideasonboard.com>","date":"2021-09-07T11:42:13","subject":"Re: [libcamera-devel] [PATCH v3 23/30] cam: drm: Support per-plane\n\tstride values","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 stride is not always identical for all planes for multi-planar\n> formats. Semi-planar YUV formats without horizontal subsampling often\n> have a chroma stride equal to twice the luma stride, and tri-planar YUV\n> formats with a 1/2 horizontal subsampling often have a chroma stride\n> equal to half the luma stride. This isn't correctly taken into account\n> when creating a DRM frame buffer, as the same stride is set for all\n> planes.\n> \n> libcamera doesn't report per-plane stride values yet, but uses chroma\n> strides that match the above description for all currently supported\n> platforms. Calculation the chrome strides appropriately in the KMSSink\n> class, and pass them to DRM::createFrameBuffer().\n> \n> Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>\n> Reviewed-by: Jean-Michel Hautbois <jeanmichel.hautbois@ideasonboard.com>\n> ---\n>  src/cam/drm.cpp      |  7 +++----\n>  src/cam/drm.h        |  5 ++++-\n>  src/cam/kms_sink.cpp | 28 +++++++++++++++++++++++++++-\n>  3 files changed, 34 insertions(+), 6 deletions(-)\n> \n> diff --git a/src/cam/drm.cpp b/src/cam/drm.cpp\n> index da317e27cb19..ac47b8bd3287 100644\n> --- a/src/cam/drm.cpp\n> +++ b/src/cam/drm.cpp\n> @@ -595,12 +595,12 @@ const Object *Device::object(uint32_t id)\n>  std::unique_ptr<FrameBuffer> Device::createFrameBuffer(\n>  \tconst libcamera::FrameBuffer &buffer,\n>  \tconst libcamera::PixelFormat &format,\n> -\tconst libcamera::Size &size, unsigned int stride)\n> +\tconst libcamera::Size &size,\n> +\tconst std::array<uint32_t, 4> &strides)\n>  {\n>  \tstd::unique_ptr<FrameBuffer> fb{ new FrameBuffer(this) };\n>  \n>  \tuint32_t handles[4] = {};\n> -\tuint32_t pitches[4] = {};\n>  \tuint32_t offsets[4] = {};\n>  \tint ret;\n>  \n> @@ -623,13 +623,12 @@ std::unique_ptr<FrameBuffer> Device::createFrameBuffer(\n>  \t\tfb->planes_.push_back({ handle });\n>  \n>  \t\thandles[i] = handle;\n> -\t\tpitches[i] = stride;\n>  \t\toffsets[i] = 0; /* TODO */\n>  \t\t++i;\n>  \t}\n>  \n>  \tret = drmModeAddFB2(fd_, size.width, size.height, format.fourcc(), handles,\n> -\t\t\t    pitches, offsets, &fb->id_, 0);\n> +\t\t\t    strides.data(), offsets, &fb->id_, 0);\n>  \tif (ret < 0) {\n>  \t\tret = -errno;\n>  \t\tstd::cerr\n> diff --git a/src/cam/drm.h b/src/cam/drm.h\n> index ee2304025208..00f7e798b771 100644\n> --- a/src/cam/drm.h\n> +++ b/src/cam/drm.h\n> @@ -7,9 +7,11 @@\n>  #ifndef __CAM_DRM_H__\n>  #define __CAM_DRM_H__\n>  \n> +#include <array>\n>  #include <list>\n>  #include <map>\n>  #include <memory>\n> +#include <stdint.h>\n>  #include <string>\n>  #include <vector>\n>  \n> @@ -298,7 +300,8 @@ public:\n>  \tstd::unique_ptr<FrameBuffer> createFrameBuffer(\n>  \t\tconst libcamera::FrameBuffer &buffer,\n>  \t\tconst libcamera::PixelFormat &format,\n> -\t\tconst libcamera::Size &size, unsigned int stride);\n> +\t\tconst libcamera::Size &size,\n> +\t\tconst std::array<uint32_t, 4> &strides);\n>  \n>  \tlibcamera::Signal<AtomicRequest *> requestComplete;\n>  \n> diff --git a/src/cam/kms_sink.cpp b/src/cam/kms_sink.cpp\n> index 8c0b79c63922..658192efc105 100644\n> --- a/src/cam/kms_sink.cpp\n> +++ b/src/cam/kms_sink.cpp\n> @@ -7,10 +7,12 @@\n>  \n>  #include \"kms_sink.h\"\n>  \n> +#include <array>\n>  #include <algorithm>\n>  #include <assert.h>\n>  #include <iostream>\n>  #include <memory>\n> +#include <stdint.h>\n>  #include <string.h>\n>  \n>  #include <libcamera/camera.h>\n> @@ -65,8 +67,32 @@ KMSSink::KMSSink(const std::string &connectorName)\n>  \n>  void KMSSink::mapBuffer(libcamera::FrameBuffer *buffer)\n>  {\n> +\tstd::array<uint32_t, 4> strides = {};\n> +\n> +\t/* \\todo Should libcamera report per-plane strides ? */\n\nDo you mean from the FrameBufferAllocator here?\nOr to report the stride enforced from the V4L2 Device in some way?\n\nBut yes - if there are underlying stride requirements, they'll need to\nbe reported or discoverable right ?\n\nReviewed-by: Kieran Bingham <kieran.bingham@ideasonboard.com>\n\n> +\tunsigned int uvStrideMultiplier;\n> +\n> +\tswitch (format_) {\n> +\tcase libcamera::formats::NV24:\n> +\tcase libcamera::formats::NV42:\n> +\t\tuvStrideMultiplier = 4;\n> +\t\tbreak;\n> +\tcase libcamera::formats::YUV420:\n> +\tcase libcamera::formats::YVU420:\n> +\tcase libcamera::formats::YUV422:\n> +\t\tuvStrideMultiplier = 1;\n> +\t\tbreak;\n> +\tdefault:\n> +\t\tuvStrideMultiplier = 2;\n> +\t\tbreak;\n> +\t}\n> +\n> +\tstrides[0] = stride_;\n> +\tfor (unsigned int i = 1; i < buffer->planes().size(); ++i)\n> +\t\tstrides[i] = stride_ * uvStrideMultiplier / 2;\n> +\n>  \tstd::unique_ptr<DRM::FrameBuffer> drmBuffer =\n> -\t\tdev_.createFrameBuffer(*buffer, format_, size_, stride_);\n> +\t\tdev_.createFrameBuffer(*buffer, format_, size_, strides);\n>  \tif (!drmBuffer)\n>  \t\treturn;\n>  \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 43009BDC71\n\tfor <parsemail@patchwork.libcamera.org>;\n\tTue,  7 Sep 2021 11:42:19 +0000 (UTC)","from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id A9B466916E;\n\tTue,  7 Sep 2021 13:42:18 +0200 (CEST)","from perceval.ideasonboard.com (perceval.ideasonboard.com\n\t[213.167.242.64])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id 1F27E60251\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tTue,  7 Sep 2021 13:42:17 +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 A56F3499;\n\tTue,  7 Sep 2021 13:42:16 +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=\"brFtGpef\"; dkim-atps=neutral","DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com;\n\ts=mail; t=1631014936;\n\tbh=xj9cVvEdJ/ZABd+d+kjijJ6WcI296KN8MuqgxQ6YGYQ=;\n\th=Subject:To:References:From:Date:In-Reply-To:From;\n\tb=brFtGpefWhyG4l2Qc4kue45DryqLwDKBJI4dq3ZLj6XkrHRJrrym7EhR6a9UIuA7a\n\tIKq/0d1lj17MHfzh7cQBW0ORBQ8MBTilNIM6FIzk5Y6aR7TOTqAMK6k994VU4u+eks\n\t4r2mfPWA6znrfNuceUngQHjQerXdBivuKUHYeSVA=","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-23-laurent.pinchart@ideasonboard.com>","From":"Kieran Bingham <kieran.bingham@ideasonboard.com>","Message-ID":"<2ead3d34-c27f-dda8-c5d2-dec8fdba0b47@ideasonboard.com>","Date":"Tue, 7 Sep 2021 12:42:13 +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-23-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 23/30] cam: drm: Support per-plane\n\tstride values","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":19518,"web_url":"https://patchwork.libcamera.org/comment/19518/","msgid":"<YTd3AAdYPoGi8gyJ@pendragon.ideasonboard.com>","date":"2021-09-07T14:28:16","subject":"Re: [libcamera-devel] [PATCH v3 23/30] cam: drm: Support per-plane\n\tstride values","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:42:13PM +0100, Kieran Bingham wrote:\n> On 06/09/2021 23:56, Laurent Pinchart wrote:\n> > The stride is not always identical for all planes for multi-planar\n> > formats. Semi-planar YUV formats without horizontal subsampling often\n> > have a chroma stride equal to twice the luma stride, and tri-planar YUV\n> > formats with a 1/2 horizontal subsampling often have a chroma stride\n> > equal to half the luma stride. This isn't correctly taken into account\n> > when creating a DRM frame buffer, as the same stride is set for all\n> > planes.\n> > \n> > libcamera doesn't report per-plane stride values yet, but uses chroma\n> > strides that match the above description for all currently supported\n> > platforms. Calculation the chrome strides appropriately in the KMSSink\n> > class, and pass them to DRM::createFrameBuffer().\n> > \n> > Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>\n> > Reviewed-by: Jean-Michel Hautbois <jeanmichel.hautbois@ideasonboard.com>\n> > ---\n> >  src/cam/drm.cpp      |  7 +++----\n> >  src/cam/drm.h        |  5 ++++-\n> >  src/cam/kms_sink.cpp | 28 +++++++++++++++++++++++++++-\n> >  3 files changed, 34 insertions(+), 6 deletions(-)\n> > \n> > diff --git a/src/cam/drm.cpp b/src/cam/drm.cpp\n> > index da317e27cb19..ac47b8bd3287 100644\n> > --- a/src/cam/drm.cpp\n> > +++ b/src/cam/drm.cpp\n> > @@ -595,12 +595,12 @@ const Object *Device::object(uint32_t id)\n> >  std::unique_ptr<FrameBuffer> Device::createFrameBuffer(\n> >  \tconst libcamera::FrameBuffer &buffer,\n> >  \tconst libcamera::PixelFormat &format,\n> > -\tconst libcamera::Size &size, unsigned int stride)\n> > +\tconst libcamera::Size &size,\n> > +\tconst std::array<uint32_t, 4> &strides)\n> >  {\n> >  \tstd::unique_ptr<FrameBuffer> fb{ new FrameBuffer(this) };\n> >  \n> >  \tuint32_t handles[4] = {};\n> > -\tuint32_t pitches[4] = {};\n> >  \tuint32_t offsets[4] = {};\n> >  \tint ret;\n> >  \n> > @@ -623,13 +623,12 @@ std::unique_ptr<FrameBuffer> Device::createFrameBuffer(\n> >  \t\tfb->planes_.push_back({ handle });\n> >  \n> >  \t\thandles[i] = handle;\n> > -\t\tpitches[i] = stride;\n> >  \t\toffsets[i] = 0; /* TODO */\n> >  \t\t++i;\n> >  \t}\n> >  \n> >  \tret = drmModeAddFB2(fd_, size.width, size.height, format.fourcc(), handles,\n> > -\t\t\t    pitches, offsets, &fb->id_, 0);\n> > +\t\t\t    strides.data(), offsets, &fb->id_, 0);\n> >  \tif (ret < 0) {\n> >  \t\tret = -errno;\n> >  \t\tstd::cerr\n> > diff --git a/src/cam/drm.h b/src/cam/drm.h\n> > index ee2304025208..00f7e798b771 100644\n> > --- a/src/cam/drm.h\n> > +++ b/src/cam/drm.h\n> > @@ -7,9 +7,11 @@\n> >  #ifndef __CAM_DRM_H__\n> >  #define __CAM_DRM_H__\n> >  \n> > +#include <array>\n> >  #include <list>\n> >  #include <map>\n> >  #include <memory>\n> > +#include <stdint.h>\n> >  #include <string>\n> >  #include <vector>\n> >  \n> > @@ -298,7 +300,8 @@ public:\n> >  \tstd::unique_ptr<FrameBuffer> createFrameBuffer(\n> >  \t\tconst libcamera::FrameBuffer &buffer,\n> >  \t\tconst libcamera::PixelFormat &format,\n> > -\t\tconst libcamera::Size &size, unsigned int stride);\n> > +\t\tconst libcamera::Size &size,\n> > +\t\tconst std::array<uint32_t, 4> &strides);\n> >  \n> >  \tlibcamera::Signal<AtomicRequest *> requestComplete;\n> >  \n> > diff --git a/src/cam/kms_sink.cpp b/src/cam/kms_sink.cpp\n> > index 8c0b79c63922..658192efc105 100644\n> > --- a/src/cam/kms_sink.cpp\n> > +++ b/src/cam/kms_sink.cpp\n> > @@ -7,10 +7,12 @@\n> >  \n> >  #include \"kms_sink.h\"\n> >  \n> > +#include <array>\n> >  #include <algorithm>\n> >  #include <assert.h>\n> >  #include <iostream>\n> >  #include <memory>\n> > +#include <stdint.h>\n> >  #include <string.h>\n> >  \n> >  #include <libcamera/camera.h>\n> > @@ -65,8 +67,32 @@ KMSSink::KMSSink(const std::string &connectorName)\n> >  \n> >  void KMSSink::mapBuffer(libcamera::FrameBuffer *buffer)\n> >  {\n> > +\tstd::array<uint32_t, 4> strides = {};\n> > +\n> > +\t/* \\todo Should libcamera report per-plane strides ? */\n> \n> Do you mean from the FrameBufferAllocator here?\n> Or to report the stride enforced from the V4L2 Device in some way?\n\nWe do report the stride in the stream configuration, but that's a single\nvalue, not a per-plane value. That's what the comment is about, should\nlibcamera make it per-plane, or leave it to applications to compute\nplane strides ?\n\n> But yes - if there are underlying stride requirements, they'll need to\n> be reported or discoverable right ?\n> \n> Reviewed-by: Kieran Bingham <kieran.bingham@ideasonboard.com>\n> \n> > +\tunsigned int uvStrideMultiplier;\n> > +\n> > +\tswitch (format_) {\n> > +\tcase libcamera::formats::NV24:\n> > +\tcase libcamera::formats::NV42:\n> > +\t\tuvStrideMultiplier = 4;\n> > +\t\tbreak;\n> > +\tcase libcamera::formats::YUV420:\n> > +\tcase libcamera::formats::YVU420:\n> > +\tcase libcamera::formats::YUV422:\n> > +\t\tuvStrideMultiplier = 1;\n> > +\t\tbreak;\n> > +\tdefault:\n> > +\t\tuvStrideMultiplier = 2;\n> > +\t\tbreak;\n> > +\t}\n> > +\n> > +\tstrides[0] = stride_;\n> > +\tfor (unsigned int i = 1; i < buffer->planes().size(); ++i)\n> > +\t\tstrides[i] = stride_ * uvStrideMultiplier / 2;\n> > +\n> >  \tstd::unique_ptr<DRM::FrameBuffer> drmBuffer =\n> > -\t\tdev_.createFrameBuffer(*buffer, format_, size_, stride_);\n> > +\t\tdev_.createFrameBuffer(*buffer, format_, size_, strides);\n> >  \tif (!drmBuffer)\n> >  \t\treturn;\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 F3D9BBDC71\n\tfor <parsemail@patchwork.libcamera.org>;\n\tTue,  7 Sep 2021 14:28:36 +0000 (UTC)","from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id C164D6916C;\n\tTue,  7 Sep 2021 16:28:36 +0200 (CEST)","from perceval.ideasonboard.com (perceval.ideasonboard.com\n\t[213.167.242.64])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id 3B4C760251\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tTue,  7 Sep 2021 16:28:35 +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 D670C24F;\n\tTue,  7 Sep 2021 16:28:34 +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=\"KgJ7yTQl\"; dkim-atps=neutral","DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com;\n\ts=mail; t=1631024915;\n\tbh=8cXUMErTMHMX1/F9nW83OEBP9gGvo45P+qaPuRE1shc=;\n\th=Date:From:To:Cc:Subject:References:In-Reply-To:From;\n\tb=KgJ7yTQlPzDeYFYeWyKGy594jd7ND2OFpJqxTgnRGErYzBHMP4GbQmoBoTFUb7s0u\n\tUbelS0JAqJUyId5TjjeVYn+TWnMGQ+poL+zIw44UUTp1zg/+cNoFkq+ZH49lsKdgiZ\n\tDmMtWY2Nv8MwNAXAqr0Zqcjr+9QxwqNqWxtd5Nd4=","Date":"Tue, 7 Sep 2021 17:28:16 +0300","From":"Laurent Pinchart <laurent.pinchart@ideasonboard.com>","To":"Kieran Bingham <kieran.bingham@ideasonboard.com>","Message-ID":"<YTd3AAdYPoGi8gyJ@pendragon.ideasonboard.com>","References":"<20210906225420.13275-1-laurent.pinchart@ideasonboard.com>\n\t<20210906225636.14683-23-laurent.pinchart@ideasonboard.com>\n\t<2ead3d34-c27f-dda8-c5d2-dec8fdba0b47@ideasonboard.com>","MIME-Version":"1.0","Content-Type":"text/plain; charset=utf-8","Content-Disposition":"inline","In-Reply-To":"<2ead3d34-c27f-dda8-c5d2-dec8fdba0b47@ideasonboard.com>","Subject":"Re: [libcamera-devel] [PATCH v3 23/30] cam: drm: Support per-plane\n\tstride values","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>"}}]