{"id":13676,"url":"https://patchwork.libcamera.org/api/1.1/patches/13676/?format=json","web_url":"https://patchwork.libcamera.org/patch/13676/","project":{"id":1,"url":"https://patchwork.libcamera.org/api/1.1/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-10-laurent.pinchart@ideasonboard.com>","date":"2021-09-06T22:56:16","name":"[libcamera-devel,v3,10/30] libcamera: v4l2_videodevice: Cache PixelFormatInfo","commit_ref":null,"pull_url":null,"state":"accepted","archived":false,"hash":"7fe415217c5720785638888de8d9d9a73940d10a","submitter":{"id":2,"url":"https://patchwork.libcamera.org/api/1.1/people/2/?format=json","name":"Laurent Pinchart","email":"laurent.pinchart@ideasonboard.com"},"delegate":null,"mbox":"https://patchwork.libcamera.org/patch/13676/mbox/","series":[{"id":2482,"url":"https://patchwork.libcamera.org/api/1.1/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/13676/comments/","check":"pending","checks":"https://patchwork.libcamera.org/api/patches/13676/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 0E68ABE175\n\tfor <parsemail@patchwork.libcamera.org>;\n\tMon,  6 Sep 2021 22:57:15 +0000 (UTC)","from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id 966A46916D;\n\tTue,  7 Sep 2021 00:57:14 +0200 (CEST)","from perceval.ideasonboard.com (perceval.ideasonboard.com\n\t[213.167.242.64])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id 177146917A\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tTue,  7 Sep 2021 00:57:03 +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 AB877B75;\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=\"EgbkBjFn\"; dkim-atps=neutral","DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com;\n\ts=mail; t=1630969022;\n\tbh=yKy+10GjDbrM8APjEW8E8CZpYga7jglPDb7x0BCWsUc=;\n\th=From:To:Cc:Subject:Date:In-Reply-To:References:From;\n\tb=EgbkBjFnIqo9ahAcx7zCA1asx1YfMDrBO9QN/AUzNR0DQsc+Wc5dA56Ju9lS0+j0C\n\tXxYfGERUEy79vvlaay06F+VQjBceiXQb/SoLPEgzQinoBrqcbq7W0t7HFvg3VOOQ/c\n\tZ4x68KTTjkfpSuQAghf0YvOrkwIFD416NW0M40vY=","From":"Laurent Pinchart <laurent.pinchart@ideasonboard.com>","To":"libcamera-devel@lists.libcamera.org","Date":"Tue,  7 Sep 2021 01:56:16 +0300","Message-Id":"<20210906225636.14683-10-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 10/30] libcamera: v4l2_videodevice:\n\tCache PixelFormatInfo","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":"Cache the PixelFormatInfo instead of looking it up in every call to\ncreateBuffer(). This prepares for usage of the info in queueBuffer(), to\navoid a looking every time a buffer is queued.\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 since v1:\n\n- Add a comment to explain why formatInfo_ isn't guaranteed to be valid\n---\n include/libcamera/internal/v4l2_videodevice.h |  1 +\n src/libcamera/v4l2_videodevice.cpp            | 28 +++++++++++++------\n 2 files changed, 21 insertions(+), 8 deletions(-)","diff":"diff --git a/include/libcamera/internal/v4l2_videodevice.h b/include/libcamera/internal/v4l2_videodevice.h\nindex 087ad067e37e..efe34d47e72b 100644\n--- a/include/libcamera/internal/v4l2_videodevice.h\n+++ b/include/libcamera/internal/v4l2_videodevice.h\n@@ -241,6 +241,7 @@ private:\n \n \tV4L2Capability caps_;\n \tV4L2DeviceFormat format_;\n+\tconst PixelFormatInfo *formatInfo_;\n \n \tenum v4l2_buf_type bufferType_;\n \tenum v4l2_memory memoryType_;\ndiff --git a/src/libcamera/v4l2_videodevice.cpp b/src/libcamera/v4l2_videodevice.cpp\nindex 1c4e6fbf7fe7..1483181a0856 100644\n--- a/src/libcamera/v4l2_videodevice.cpp\n+++ b/src/libcamera/v4l2_videodevice.cpp\n@@ -482,8 +482,8 @@ const std::string V4L2DeviceFormat::toString() const\n  * \\param[in] deviceNode The file-system path to the video device node\n  */\n V4L2VideoDevice::V4L2VideoDevice(const std::string &deviceNode)\n-\t: V4L2Device(deviceNode), cache_(nullptr), fdBufferNotifier_(nullptr),\n-\t  streaming_(false)\n+\t: V4L2Device(deviceNode), formatInfo_(nullptr), cache_(nullptr),\n+\t  fdBufferNotifier_(nullptr), streaming_(false)\n {\n \t/*\n \t * We default to an MMAP based CAPTURE video device, however this will\n@@ -586,6 +586,8 @@ int V4L2VideoDevice::open()\n \t\treturn ret;\n \t}\n \n+\tformatInfo_ = &PixelFormatInfo::info(format_.fourcc);\n+\n \treturn 0;\n }\n \n@@ -681,6 +683,8 @@ int V4L2VideoDevice::open(int handle, enum v4l2_buf_type type)\n \t\treturn ret;\n \t}\n \n+\tformatInfo_ = &PixelFormatInfo::info(format_.fourcc);\n+\n \treturn 0;\n }\n \n@@ -695,6 +699,8 @@ void V4L2VideoDevice::close()\n \treleaseBuffers();\n \tdelete fdBufferNotifier_;\n \n+\tformatInfo_ = nullptr;\n+\n \tV4L2Device::close();\n }\n \n@@ -787,6 +793,8 @@ int V4L2VideoDevice::setFormat(V4L2DeviceFormat *format)\n \t\treturn ret;\n \n \tformat_ = *format;\n+\tformatInfo_ = &PixelFormatInfo::info(format_.fourcc);\n+\n \treturn 0;\n }\n \n@@ -1325,19 +1333,23 @@ std::unique_ptr<FrameBuffer> V4L2VideoDevice::createBuffer(unsigned int index)\n \t\tplanes.push_back(std::move(plane));\n \t}\n \n-\tconst auto &info = PixelFormatInfo::info(format_.fourcc);\n-\tif (info.isValid() && info.numPlanes() != numPlanes) {\n+\t/*\n+\t * The format info is not guaranteed to be valid, as there are no\n+\t * PixelFormatInfo for metadata formats, so check it first.\n+\t */\n+\tif (formatInfo_->isValid() && formatInfo_->numPlanes() != numPlanes) {\n \t\tASSERT(numPlanes == 1u);\n-\t\tconst size_t numColorPlanes = info.numPlanes();\n-\t\tplanes.resize(numColorPlanes);\n+\n+\t\tplanes.resize(formatInfo_->numPlanes());\n \t\tconst FileDescriptor &fd = planes[0].fd;\n \t\tsize_t offset = 0;\n-\t\tfor (size_t i = 0; i < numColorPlanes; ++i) {\n+\n+\t\tfor (size_t i = 0; i < planes.size(); ++i) {\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 = info.planeSize(format_.size, i);\n+\t\t\tplanes[i].length = formatInfo_->planeSize(format_.size, i);\n \t\t\toffset += planes[i].length;\n \t\t}\n \t}\n","prefixes":["libcamera-devel","v3","10/30"]}