{"id":13675,"url":"https://patchwork.libcamera.org/api/patches/13675/?format=json","web_url":"https://patchwork.libcamera.org/patch/13675/","project":{"id":1,"url":"https://patchwork.libcamera.org/api/projects/1/?format=json","name":"libcamera","link_name":"libcamera","list_id":"libcamera_core","list_email":"libcamera-devel@lists.libcamera.org","web_url":"","scm_url":"","webscm_url":""},"msgid":"<20210906225636.14683-9-laurent.pinchart@ideasonboard.com>","date":"2021-09-06T22:56:15","name":"[libcamera-devel,v3,09/30] libcamera: framebuffer: Add a function to check if planes are contiguous","commit_ref":null,"pull_url":null,"state":"accepted","archived":false,"hash":"b5e50a491dfff0a4109d3ba4a3424a49ea1d5367","submitter":{"id":2,"url":"https://patchwork.libcamera.org/api/people/2/?format=json","name":"Laurent Pinchart","email":"laurent.pinchart@ideasonboard.com"},"delegate":null,"mbox":"https://patchwork.libcamera.org/patch/13675/mbox/","series":[{"id":2482,"url":"https://patchwork.libcamera.org/api/series/2482/?format=json","web_url":"https://patchwork.libcamera.org/project/libcamera/list/?series=2482","date":"2021-09-06T22:54:20","name":"libcamera: Handle fallout of FrameBuffer offset support","version":3,"mbox":"https://patchwork.libcamera.org/series/2482/mbox/"}],"comments":"https://patchwork.libcamera.org/api/patches/13675/comments/","check":"pending","checks":"https://patchwork.libcamera.org/api/patches/13675/checks/","tags":{},"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 C7258BE175\n\tfor <parsemail@patchwork.libcamera.org>;\n\tMon,  6 Sep 2021 22:57:13 +0000 (UTC)","from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id 642236917C;\n\tTue,  7 Sep 2021 00:57:13 +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 B2CCF69171\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tTue,  7 Sep 2021 00:57:02 +0200 (CEST)","from pendragon.lan (62-78-145-57.bb.dnainternet.fi [62.78.145.57])\n\tby perceval.ideasonboard.com (Postfix) with ESMTPSA id 47A4A993;\n\tTue,  7 Sep 2021 00:57:02 +0200 (CEST)"],"Authentication-Results":"lancelot.ideasonboard.com;\n\tdkim=fail reason=\"signature verification failed\" (1024-bit key;\n\tunprotected) header.d=ideasonboard.com header.i=@ideasonboard.com\n\theader.b=\"pw2gJD/h\"; dkim-atps=neutral","DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com;\n\ts=mail; t=1630969022;\n\tbh=yQzDE330FE4bfpnJvwkRVv4LxSn+BVXbC0iceJxsrrI=;\n\th=From:To:Cc:Subject:Date:In-Reply-To:References:From;\n\tb=pw2gJD/hgz5l7c+gtXrTYQ8OBZEQJfcD8IVEwNoqIZsVAKnRG0invFvAg5ww81TLA\n\tmG28IVIYEgljgMnyU+sepEXmuQBhdhPxwX0H04Yn5kEW/En7XSKftv4QoLzWOk+WKY\n\t5o+vYC18wHtLLBoNbyFQPYesG+VHcQ90O/iVwvtw=","From":"Laurent Pinchart <laurent.pinchart@ideasonboard.com>","To":"libcamera-devel@lists.libcamera.org","Date":"Tue,  7 Sep 2021 01:56:15 +0300","Message-Id":"<20210906225636.14683-9-laurent.pinchart@ideasonboard.com>","X-Mailer":"git-send-email 2.32.0","In-Reply-To":"<20210906225420.13275-1-laurent.pinchart@ideasonboard.com>","References":"<20210906225420.13275-1-laurent.pinchart@ideasonboard.com>","MIME-Version":"1.0","Content-Transfer-Encoding":"8bit","Subject":"[libcamera-devel] [PATCH v3 09/30] libcamera: framebuffer: Add a\n\tfunction to check if planes are contiguous","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>"},"content":"Multi-planar frame buffers can store their planes contiguously in\nmemory, or split them in discontiguous memory areas. Add a private\nfunction to check in which of these two categories the frame buffer\nbelongs. This will be used to correctly handle the differences between\nthe V4L2 single and multi planar APIs.\n\nSigned-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>\nReviewed-by: Kieran Bingham <kieran.bingham@ideasonboard.com>\nReviewed-by: Hirokazu Honda <hiroh@chromium.org>\n---\nChanges v1:\n\n- Merge both loops in FrameBuffer::FrameBuffer()\n---\n include/libcamera/internal/framebuffer.h |  2 ++\n src/libcamera/framebuffer.cpp            | 45 ++++++++++++++++++++++--\n 2 files changed, 45 insertions(+), 2 deletions(-)","diff":"diff --git a/include/libcamera/internal/framebuffer.h b/include/libcamera/internal/framebuffer.h\nindex 606aed2b4782..cd33c295466e 100644\n--- a/include/libcamera/internal/framebuffer.h\n+++ b/include/libcamera/internal/framebuffer.h\n@@ -21,9 +21,11 @@ public:\n \tPrivate();\n \n \tvoid setRequest(Request *request) { request_ = request; }\n+\tbool isContiguous() const { return isContiguous_; }\n \n private:\n \tRequest *request_;\n+\tbool isContiguous_;\n };\n \n } /* namespace libcamera */\ndiff --git a/src/libcamera/framebuffer.cpp b/src/libcamera/framebuffer.cpp\nindex ad63a34a83bf..e71c2ffae034 100644\n--- a/src/libcamera/framebuffer.cpp\n+++ b/src/libcamera/framebuffer.cpp\n@@ -106,7 +106,7 @@ LOG_DEFINE_CATEGORY(Buffer)\n  */\n \n FrameBuffer::Private::Private()\n-\t: request_(nullptr)\n+\t: request_(nullptr), isContiguous_(true)\n {\n }\n \n@@ -120,6 +120,17 @@ FrameBuffer::Private::Private()\n  * handlers, it is called by the pipeline handlers themselves.\n  */\n \n+/**\n+ * \\fn FrameBuffer::Private::isContiguous()\n+ * \\brief Check if the frame buffer stores planes contiguously in memory\n+ *\n+ * Multi-planar frame buffers can store their planes contiguously in memory, or\n+ * split them into discontiguous memory areas. This function checks in which of\n+ * these two categories the frame buffer belongs.\n+ *\n+ * \\return True if the planes are stored contiguously in memory, false otherwise\n+ */\n+\n /**\n  * \\class FrameBuffer\n  * \\brief Frame buffer data and its associated dynamic metadata\n@@ -199,8 +210,38 @@ FrameBuffer::FrameBuffer(const std::vector<Plane> &planes, unsigned int cookie)\n \t: Extensible(std::make_unique<Private>()), planes_(planes),\n \t  cookie_(cookie)\n {\n-\tfor (const auto &plane : planes_)\n+\tunsigned int offset = 0;\n+\tbool isContiguous = true;\n+\tino_t inode = 0;\n+\n+\tfor (const auto &plane : planes_) {\n \t\tASSERT(plane.offset != Plane::kInvalidOffset);\n+\n+\t\tif (plane.offset != offset) {\n+\t\t\tisContiguous = false;\n+\t\t\tbreak;\n+\t\t}\n+\n+\t\t/*\n+\t\t * Two different dmabuf file descriptors may still refer to the\n+\t\t * same dmabuf instance. Check this using inodes.\n+\t\t */\n+\t\tif (plane.fd.fd() != planes_[0].fd.fd()) {\n+\t\t\tif (!inode)\n+\t\t\t\tinode = planes_[0].fd.inode();\n+\t\t\tif (plane.fd.inode() != inode) {\n+\t\t\t\tisContiguous = false;\n+\t\t\t\tbreak;\n+\t\t\t}\n+\t\t}\n+\n+\t\toffset += plane.length;\n+\t}\n+\n+\tLOG(Buffer, Debug)\n+\t\t<< \"Buffer is \" << (isContiguous ? \"not \" : \"\") << \"contiguous\";\n+\n+\t_d()->isContiguous_ = isContiguous;\n }\n \n /**\n","prefixes":["libcamera-devel","v3","09/30"]}