{"id":24283,"url":"https://patchwork.libcamera.org/api/patches/24283/?format=json","web_url":"https://patchwork.libcamera.org/patch/24283/","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":"<20250904134641.29597-2-laurent.pinchart@ideasonboard.com>","date":"2025-09-04T13:46:40","name":"[v3,1/2] pipelines: Use lambda functions to factor out buffer mapping code","commit_ref":"5e351b89f047bc11835193f24cf5a832a2c26102","pull_url":null,"state":"accepted","archived":false,"hash":"665d989feb4838d994de642d131252f3159fca2c","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/24283/mbox/","series":[{"id":5422,"url":"https://patchwork.libcamera.org/api/series/5422/?format=json","web_url":"https://patchwork.libcamera.org/project/libcamera/list/?series=5422","date":"2025-09-04T13:46:39","name":"libcamera: Use span in FrameBuffer","version":3,"mbox":"https://patchwork.libcamera.org/series/5422/mbox/"}],"comments":"https://patchwork.libcamera.org/api/patches/24283/comments/","check":"pending","checks":"https://patchwork.libcamera.org/api/patches/24283/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 06F02C328C\n\tfor <parsemail@patchwork.libcamera.org>;\n\tThu,  4 Sep 2025 13:47:09 +0000 (UTC)","from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id 6FEBD69346;\n\tThu,  4 Sep 2025 15:47:07 +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 EB31C69338\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tThu,  4 Sep 2025 15:47:04 +0200 (CEST)","from pendragon.ideasonboard.com\n\t(230.215-178-91.adsl-dyn.isp.belgacom.be [91.178.215.230])\n\tby perceval.ideasonboard.com (Postfix) with UTF8SMTPSA id 8A2E6F09\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tThu,  4 Sep 2025 15:45:55 +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=\"Ig1bEfyS\"; dkim-atps=neutral","DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com;\n\ts=mail; t=1756993555;\n\tbh=yP8rwj88dPgAOL7ScJUho2LiEKWBFASC50mUAYHzzII=;\n\th=From:To:Subject:Date:In-Reply-To:References:From;\n\tb=Ig1bEfyS1VqMPifQF1wm32khliOPTKEI3rZc+gYKyyXLhahjGD42Qio0XMYZeoGbs\n\tAGavCizg6/wxlyt6FiIfypeF/yDUY1hsNF8y6rGSTytubBy1IhuXlq5Mm/+0/fQlMl\n\tMTPsRfU0g3MKEpX5TJzm4nI+rU6AHAmu/5tXsSro=","From":"Laurent Pinchart <laurent.pinchart@ideasonboard.com>","To":"libcamera-devel@lists.libcamera.org","Subject":"[PATCH v3 1/2] pipelines: Use lambda functions to factor out buffer\n\tmapping code","Date":"Thu,  4 Sep 2025 15:46:40 +0200","Message-ID":"<20250904134641.29597-2-laurent.pinchart@ideasonboard.com>","X-Mailer":"git-send-email 2.49.1","In-Reply-To":"<20250904134641.29597-1-laurent.pinchart@ideasonboard.com>","References":"<20250904134641.29597-1-laurent.pinchart@ideasonboard.com>","MIME-Version":"1.0","Content-Type":"text/plain; charset=UTF-8","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>\nReviewed-by: Barnabás Pőcze <barnabas.pocze@ideasonboard.com>\n---\nChanges since v1:\n\n- Move for loop to pushBuffers() function\n- Drop unneeded lambda function arguments\n---\n src/libcamera/pipeline/ipu3/ipu3.cpp         | 16 ++++++------\n src/libcamera/pipeline/mali-c55/mali-c55.cpp | 26 +++++++++++---------\n src/libcamera/pipeline/rkisp1/rkisp1.cpp     | 23 +++++++++--------\n 3 files changed, 33 insertions(+), 32 deletions(-)","diff":"diff --git a/src/libcamera/pipeline/ipu3/ipu3.cpp b/src/libcamera/pipeline/ipu3/ipu3.cpp\nindex ad20810e6a26..bfbc80af6a3c 100644\n--- a/src/libcamera/pipeline/ipu3/ipu3.cpp\n+++ b/src/libcamera/pipeline/ipu3/ipu3.cpp\n@@ -678,15 +678,15 @@ 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-\t\tbuffer->setCookie(ipaBufferId++);\n-\t\tipaBuffers_.emplace_back(buffer->cookie(), buffer->planes());\n-\t}\n+\tauto pushBuffers = [&](const std::vector<std::unique_ptr<FrameBuffer>> &buffers) {\n+\t\tfor (const std::unique_ptr<FrameBuffer> &buffer : buffers) {\n+\t\t\tbuffer->setCookie(ipaBufferId++);\n+\t\t\tipaBuffers_.emplace_back(buffer->cookie(), buffer->planes());\n+\t\t}\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+\tpushBuffers(imgu->paramBuffers_);\n+\tpushBuffers(imgu->statBuffers_);\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..97996399fc51 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,29 @@ int PipelineHandlerMaliC55::allocateBuffers(Camera *camera)\n \t\tdata->dsStream_.configuration().bufferCount,\n \t});\n \n+\tauto pushBuffers = [&](const std::vector<std::unique_ptr<FrameBuffer>> &buffers,\n+\t\t\t       std::queue<FrameBuffer *> &queue,\n+\t\t\t       std::vector<IPABuffer> &ipaBuffers) {\n+\t\tfor (const std::unique_ptr<FrameBuffer> &buffer : buffers) {\n+\t\t\tbuffer->setCookie(ipaBufferId++);\n+\t\t\tipaBuffers.emplace_back(buffer->cookie(), buffer->planes());\n+\t\t\tqueue.push(buffer.get());\n+\t\t}\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+\tpushBuffers(statsBuffers_, availableStatsBuffers_,\n+\t\t    data->ipaStatBuffers_);\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+\tpushBuffers(paramsBuffers_, availableParamsBuffers_,\n+\t\t    data->ipaParamBuffers_);\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..291f96836c5e 100644\n--- a/src/libcamera/pipeline/rkisp1/rkisp1.cpp\n+++ b/src/libcamera/pipeline/rkisp1/rkisp1.cpp\n@@ -1028,19 +1028,18 @@ int PipelineHandlerRkISP1::allocateBuffers(Camera *camera)\n \t\t\tavailableMainPathBuffers_.push(buffer.get());\n \t}\n \n-\tfor (std::unique_ptr<FrameBuffer> &buffer : paramBuffers_) {\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+\tauto pushBuffers = [&](const std::vector<std::unique_ptr<FrameBuffer>> &buffers,\n+\t\t\t       std::queue<FrameBuffer *> &queue) {\n+\t\tfor (const std::unique_ptr<FrameBuffer> &buffer : buffers) {\n+\t\t\tbuffer->setCookie(ipaBufferId++);\n+\t\t\tdata->ipaBuffers_.emplace_back(buffer->cookie(),\n+\t\t\t\t\t\t       buffer->planes());\n+\t\t\tqueue.push(buffer.get());\n+\t\t}\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+\tpushBuffers(paramBuffers_, availableParamBuffers_);\n+\tpushBuffers(statBuffers_, availableStatBuffers_);\n \n \tdata->ipa_->mapBuffers(data->ipaBuffers_);\n \n","prefixes":["v3","1/2"]}