{"id":24135,"url":"https://patchwork.libcamera.org/api/1.1/patches/24135/?format=json","web_url":"https://patchwork.libcamera.org/patch/24135/","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":"<20250815113400.20623-6-laurent.pinchart@ideasonboard.com>","date":"2025-08-15T11:33:57","name":"[v2,5/8] pipelines: Use lambda functions to factor out buffer mapping code","commit_ref":null,"pull_url":null,"state":"changes-requested","archived":false,"hash":"33b3f27f036d532de999bad6d114c7f5819faf4d","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/24135/mbox/","series":[{"id":5383,"url":"https://patchwork.libcamera.org/api/1.1/series/5383/?format=json","web_url":"https://patchwork.libcamera.org/project/libcamera/list/?series=5383","date":"2025-08-15T11:33:52","name":"libcamera: Use span in FrameBuffer & assorted cleanups","version":2,"mbox":"https://patchwork.libcamera.org/series/5383/mbox/"}],"comments":"https://patchwork.libcamera.org/api/patches/24135/comments/","check":"pending","checks":"https://patchwork.libcamera.org/api/patches/24135/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 F37E4BEFBE\n\tfor <parsemail@patchwork.libcamera.org>;\n\tFri, 15 Aug 2025 11:34:37 +0000 (UTC)","from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id B1EF86925D;\n\tFri, 15 Aug 2025 13:34:37 +0200 (CEST)","from perceval.ideasonboard.com (perceval.ideasonboard.com\n\t[213.167.242.64])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id 71D8169251\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tFri, 15 Aug 2025 13:34:28 +0200 (CEST)","from pendragon.ideasonboard.com (81-175-209-231.bb.dnainternet.fi\n\t[81.175.209.231])\n\tby perceval.ideasonboard.com (Postfix) with UTF8SMTPSA id 70E1C63B;\n\tFri, 15 Aug 2025 13:33:33 +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=\"bEFX2zPp\"; dkim-atps=neutral","DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com;\n\ts=mail; t=1755257613;\n\tbh=yZc1jB0bY0Wa6dNl9pZAzm5dpSoIOCPGERzEMBhYw4Y=;\n\th=From:To:Cc:Subject:Date:In-Reply-To:References:From;\n\tb=bEFX2zPpByIgHxY1rEEyPuQeTavjJgrfbLJAZM3BUgYxA5rRdeGPXi46Sya5PA7by\n\tgDf9kd3Y+CWnayN8o9J6SDeZublCfncYmsAMsqD8kpJhptvMTY16NecPCIBboL4aMT\n\tNF4kfmVAns5sCnwM1xqK2kplT0xP0oPUPq7HWLBY=","From":"Laurent Pinchart <laurent.pinchart@ideasonboard.com>","To":"libcamera-devel@lists.libcamera.org","Cc":"=?utf-8?q?Daniel_R=C3=A1kos?= <daniel.rakos@rastergrid.com>","Subject":"[PATCH v2 5/8] pipelines: Use lambda functions to factor out buffer\n\tmapping code","Date":"Fri, 15 Aug 2025 14:33:57 +0300","Message-ID":"<20250815113400.20623-6-laurent.pinchart@ideasonboard.com>","X-Mailer":"git-send-email 2.49.1","In-Reply-To":"<20250815113400.20623-1-laurent.pinchart@ideasonboard.com>","References":"<20250815113400.20623-1-laurent.pinchart@ideasonboard.com>","MIME-Version":"1.0","Content-Transfer-Encoding":"8bit","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":"Multiple pipeline handlers duplicate code related to mapping params and\nstats buffers to IPA modules. Factor out the code to lambda functions to\nshare it between the two buffer types.\n\nSigned-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>\n---\n src/libcamera/pipeline/ipu3/ipu3.cpp         | 16 +++++++------\n src/libcamera/pipeline/mali-c55/mali-c55.cpp | 24 ++++++++++----------\n src/libcamera/pipeline/rkisp1/rkisp1.cpp     | 22 +++++++++---------\n 3 files changed, 32 insertions(+), 30 deletions(-)","diff":"diff --git a/src/libcamera/pipeline/ipu3/ipu3.cpp b/src/libcamera/pipeline/ipu3/ipu3.cpp\nindex ad20810e6a26..7ae85e5063db 100644\n--- a/src/libcamera/pipeline/ipu3/ipu3.cpp\n+++ b/src/libcamera/pipeline/ipu3/ipu3.cpp\n@@ -678,15 +678,17 @@ int PipelineHandlerIPU3::allocateBuffers(Camera *camera)\n \t/* Map buffers to the IPA. */\n \tunsigned int ipaBufferId = 1;\n \n-\tfor (const std::unique_ptr<FrameBuffer> &buffer : imgu->paramBuffers_) {\n+\tauto pushBuffer = [&](std::vector<IPABuffer> &buffers,\n+\t\t\t      const std::unique_ptr<FrameBuffer> &buffer) {\n \t\tbuffer->setCookie(ipaBufferId++);\n-\t\tipaBuffers_.emplace_back(buffer->cookie(), buffer->planes());\n-\t}\n+\t\tbuffers.emplace_back(buffer->cookie(), buffer->planes());\n+\t};\n \n-\tfor (const std::unique_ptr<FrameBuffer> &buffer : imgu->statBuffers_) {\n-\t\tbuffer->setCookie(ipaBufferId++);\n-\t\tipaBuffers_.emplace_back(buffer->cookie(), buffer->planes());\n-\t}\n+\tfor (const std::unique_ptr<FrameBuffer> &buffer : imgu->paramBuffers_)\n+\t\tpushBuffer(ipaBuffers_, buffer);\n+\n+\tfor (const std::unique_ptr<FrameBuffer> &buffer : imgu->statBuffers_)\n+\t\tpushBuffer(ipaBuffers_, buffer);\n \n \tdata->ipa_->mapBuffers(ipaBuffers_);\n \ndiff --git a/src/libcamera/pipeline/mali-c55/mali-c55.cpp b/src/libcamera/pipeline/mali-c55/mali-c55.cpp\nindex 76341ed3f363..f03a03fef35c 100644\n--- a/src/libcamera/pipeline/mali-c55/mali-c55.cpp\n+++ b/src/libcamera/pipeline/mali-c55/mali-c55.cpp\n@@ -1133,27 +1133,27 @@ int PipelineHandlerMaliC55::allocateBuffers(Camera *camera)\n \t\tdata->dsStream_.configuration().bufferCount,\n \t});\n \n+\tauto pushBuffer = [&](std::queue<FrameBuffer *> &queue,\n+\t\t\t      std::vector<IPABuffer> &buffers,\n+\t\t\t      const std::unique_ptr<FrameBuffer> &buffer) {\n+\t\tbuffer->setCookie(ipaBufferId++);\n+\t\tbuffers.emplace_back(buffer->cookie(), buffer->planes());\n+\t\tqueue.push(buffer.get());\n+\t};\n+\n \tret = stats_->allocateBuffers(bufferCount, &statsBuffers_);\n \tif (ret < 0)\n \t\treturn ret;\n \n-\tfor (std::unique_ptr<FrameBuffer> &buffer : statsBuffers_) {\n-\t\tbuffer->setCookie(ipaBufferId++);\n-\t\tdata->ipaStatBuffers_.emplace_back(buffer->cookie(),\n-\t\t\t\t\t\t   buffer->planes());\n-\t\tavailableStatsBuffers_.push(buffer.get());\n-\t}\n+\tfor (std::unique_ptr<FrameBuffer> &buffer : statsBuffers_)\n+\t\tpushBuffer(availableStatsBuffers_, data->ipaStatBuffers_, buffer);\n \n \tret = params_->allocateBuffers(bufferCount, &paramsBuffers_);\n \tif (ret < 0)\n \t\treturn ret;\n \n-\tfor (std::unique_ptr<FrameBuffer> &buffer : paramsBuffers_) {\n-\t\tbuffer->setCookie(ipaBufferId++);\n-\t\tdata->ipaParamBuffers_.emplace_back(buffer->cookie(),\n-\t\t\t\t\t\t    buffer->planes());\n-\t\tavailableParamsBuffers_.push(buffer.get());\n-\t}\n+\tfor (std::unique_ptr<FrameBuffer> &buffer : paramsBuffers_)\n+\t\tpushBuffer(availableParamsBuffers_, data->ipaParamBuffers_, buffer);\n \n \tif (data->ipa_) {\n \t\tdata->ipa_->mapBuffers(data->ipaStatBuffers_, true);\ndiff --git a/src/libcamera/pipeline/rkisp1/rkisp1.cpp b/src/libcamera/pipeline/rkisp1/rkisp1.cpp\nindex 55d7d4442caf..99347c9f6258 100644\n--- a/src/libcamera/pipeline/rkisp1/rkisp1.cpp\n+++ b/src/libcamera/pipeline/rkisp1/rkisp1.cpp\n@@ -1028,19 +1028,19 @@ int PipelineHandlerRkISP1::allocateBuffers(Camera *camera)\n \t\t\tavailableMainPathBuffers_.push(buffer.get());\n \t}\n \n-\tfor (std::unique_ptr<FrameBuffer> &buffer : paramBuffers_) {\n+\tauto pushBuffer = [&](std::vector<IPABuffer> &buffers,\n+\t\t\t      std::queue<FrameBuffer *> &queue,\n+\t\t\t      const std::unique_ptr<FrameBuffer> &buffer) {\n \t\tbuffer->setCookie(ipaBufferId++);\n-\t\tdata->ipaBuffers_.emplace_back(buffer->cookie(),\n-\t\t\t\t\t       buffer->planes());\n-\t\tavailableParamBuffers_.push(buffer.get());\n-\t}\n+\t\tbuffers.emplace_back(buffer->cookie(), buffer->planes());\n+\t\tqueue.push(buffer.get());\n+\t};\n \n-\tfor (std::unique_ptr<FrameBuffer> &buffer : statBuffers_) {\n-\t\tbuffer->setCookie(ipaBufferId++);\n-\t\tdata->ipaBuffers_.emplace_back(buffer->cookie(),\n-\t\t\t\t\t       buffer->planes());\n-\t\tavailableStatBuffers_.push(buffer.get());\n-\t}\n+\tfor (std::unique_ptr<FrameBuffer> &buffer : paramBuffers_)\n+\t\tpushBuffer(data->ipaBuffers_, availableParamBuffers_, buffer);\n+\n+\tfor (std::unique_ptr<FrameBuffer> &buffer : statBuffers_)\n+\t\tpushBuffer(data->ipaBuffers_, availableStatBuffers_, buffer);\n \n \tdata->ipa_->mapBuffers(data->ipaBuffers_);\n \n","prefixes":["v2","5/8"]}