{"id":19046,"url":"https://patchwork.libcamera.org/api/patches/19046/?format=json","web_url":"https://patchwork.libcamera.org/patch/19046/","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":"<20230916121930.29490-9-jacopo.mondi@ideasonboard.com>","date":"2023-09-16T12:19:26","name":"[libcamera-devel,v4,08/12] libcamera: rpi: Cache rawStreams and outStreams","commit_ref":null,"pull_url":null,"state":"accepted","archived":false,"hash":"6f11868acc0e27a1f3b674c3c1942633ee30d3a4","submitter":{"id":143,"url":"https://patchwork.libcamera.org/api/people/143/?format=json","name":"Jacopo Mondi","email":"jacopo.mondi@ideasonboard.com"},"delegate":null,"mbox":"https://patchwork.libcamera.org/patch/19046/mbox/","series":[{"id":4027,"url":"https://patchwork.libcamera.org/api/series/4027/?format=json","web_url":"https://patchwork.libcamera.org/project/libcamera/list/?series=4027","date":"2023-09-16T12:19:18","name":"libcamera: Introduce SensorConfiguration","version":4,"mbox":"https://patchwork.libcamera.org/series/4027/mbox/"}],"comments":"https://patchwork.libcamera.org/api/patches/19046/comments/","check":"pending","checks":"https://patchwork.libcamera.org/api/patches/19046/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 1811CC32B0\n\tfor <parsemail@patchwork.libcamera.org>;\n\tSat, 16 Sep 2023 12:19:49 +0000 (UTC)","from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id B4DA862925;\n\tSat, 16 Sep 2023 14:19:48 +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 D015262921\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tSat, 16 Sep 2023 14:19:40 +0200 (CEST)","from uno.LocalDomain (93-61-96-190.ip145.fastwebnet.it\n\t[93.61.96.190])\n\tby perceval.ideasonboard.com (Postfix) with ESMTPSA id B96E71812;\n\tSat, 16 Sep 2023 14:18:06 +0200 (CEST)"],"DKIM-Signature":["v=1; a=rsa-sha256; c=relaxed/simple; d=libcamera.org;\n\ts=mail; t=1694866788;\n\tbh=Zc9J6NLdY30XhehyRaFBy+qampP6ydKK6Hqcd/w0kz4=;\n\th=To:Date:In-Reply-To:References:Subject:List-Id:List-Unsubscribe:\n\tList-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To:Cc:\n\tFrom;\n\tb=Fk0mJs6y6b/Vi047q8ohx5KPgwtj1BaO682a3oI7++KKWKgjAbj1t6reF53sYHVil\n\tAt9LbraDigUEQQQD8qlIqLGhIdpEIKVfYER041p8gzpo2KhrcCNcNxOPJ2qpg3Hk3m\n\t+GRw5Jj4WtWkGU6AMSsrG7Xl6FWAOznYKnLgFP9sbwB1N81pWY9cvCkFB6gzwrkSLX\n\t2yObEGlMA+GWSB7nMIAqTGnVIDhNG58qZZtn3AWl046wefHTPLCeirR8A9xDwDRnjP\n\tb8eIY9SReT4hSFMXcltlporRg1Xjnluq8pSPz1g3cfIp8hEoKICMTYxnSmOcGsevxG\n\ttS4ULDT9Gmxpg==","v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com;\n\ts=mail; t=1694866687;\n\tbh=Zc9J6NLdY30XhehyRaFBy+qampP6ydKK6Hqcd/w0kz4=;\n\th=From:To:Cc:Subject:Date:In-Reply-To:References:From;\n\tb=q32CetsnGmPl0srVW0QBt2geSjekkCQcH6YuFonifaGiMIJZkiTsbI+bDyimLqOHn\n\tnBsAdgehsCkdGnvETjdtxGLWTPKAHq95rgrfVgCabodHlexePpMM4Q1VTPk5n10K+V\n\tuDxjk0wmkjzo0rWliLSpALMpJT5nl1IQzau3PyTM="],"Authentication-Results":"lancelot.ideasonboard.com; dkim=pass (1024-bit key; \n\tunprotected) header.d=ideasonboard.com\n\theader.i=@ideasonboard.com\n\theader.b=\"q32Cetsn\"; dkim-atps=neutral","To":"libcamera-devel@lists.libcamera.org","Date":"Sat, 16 Sep 2023 14:19:26 +0200","Message-ID":"<20230916121930.29490-9-jacopo.mondi@ideasonboard.com>","X-Mailer":"git-send-email 2.42.0","In-Reply-To":"<20230916121930.29490-1-jacopo.mondi@ideasonboard.com>","References":"<20230916121930.29490-1-jacopo.mondi@ideasonboard.com>","MIME-Version":"1.0","Content-Transfer-Encoding":"8bit","Subject":"[libcamera-devel] [PATCH v4 08/12] libcamera: rpi: Cache rawStreams\n\tand outStreams","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>","From":"Jacopo Mondi via libcamera-devel <libcamera-devel@lists.libcamera.org>","Reply-To":"Jacopo Mondi <jacopo.mondi@ideasonboard.com>","Cc":"Jacopo Mondi <jacopo.mondi@ideasonboard.com>","Errors-To":"libcamera-devel-bounces@lists.libcamera.org","Sender":"\"libcamera-devel\" <libcamera-devel-bounces@lists.libcamera.org>"},"content":"From: Naushir Patuck <naush@raspberrypi.com>\n\nCurrently, the stream configuration is stored in two vectors, rawStreams\nand outStreams for convenience. However, these vectors are constructed\nin both platformValidate() and platformConfigure().\n\nThis change caches these vectors in the RPiCameraConfiguration class to\nconstruct them only once in platformValidate().\n\nPass a pointer to the current configuration to platformValidate() and\nplatformConfigure() so that they can access the streams vectors.\n\nSigned-off-by: Naushir Patuck <naush@raspberrypi.com>\nReviewed-by: Jacopo Mondi <jacopo.mondi@ideasonboard.com>\nSigned-off-by: Jacopo Mondi <jacopo.mondi@ideasonboard.com>\n---\n .../pipeline/rpi/common/pipeline_base.cpp     | 50 +++++++------------\n .../pipeline/rpi/common/pipeline_base.h       | 42 ++++++++--------\n src/libcamera/pipeline/rpi/vc4/vc4.cpp        | 20 ++++----\n 3 files changed, 48 insertions(+), 64 deletions(-)","diff":"diff --git a/src/libcamera/pipeline/rpi/common/pipeline_base.cpp b/src/libcamera/pipeline/rpi/common/pipeline_base.cpp\nindex ebb79337d092..e7fedca7cc8d 100644\n--- a/src/libcamera/pipeline/rpi/common/pipeline_base.cpp\n+++ b/src/libcamera/pipeline/rpi/common/pipeline_base.cpp\n@@ -175,19 +175,21 @@ CameraConfiguration::Status RPiCameraConfiguration::validate()\n \tif (transform != requestedTransform)\n \t\tstatus = Adjusted;\n \n-\tstd::vector<CameraData::StreamParams> rawStreams, outStreams;\n+\trawStreams_.clear();\n+\toutStreams_.clear();\n+\n \tfor (const auto &[index, cfg] : utils::enumerate(config_)) {\n \t\tif (PipelineHandlerBase::isRaw(cfg.pixelFormat))\n-\t\t\trawStreams.emplace_back(index, &cfg);\n+\t\t\trawStreams_.emplace_back(index, &cfg);\n \t\telse\n-\t\t\toutStreams.emplace_back(index, &cfg);\n+\t\t\toutStreams_.emplace_back(index, &cfg);\n \t}\n \n \t/* Sort the streams so the highest resolution is first. */\n-\tstd::sort(rawStreams.begin(), rawStreams.end(),\n+\tstd::sort(rawStreams_.begin(), rawStreams_.end(),\n \t\t  [](auto &l, auto &r) { return l.cfg->size > r.cfg->size; });\n \n-\tstd::sort(outStreams.begin(), outStreams.end(),\n+\tstd::sort(outStreams_.begin(), outStreams_.end(),\n \t\t  [](auto &l, auto &r) { return l.cfg->size > r.cfg->size; });\n \n \t/* Compute the sensor's format then do any platform specific fixups. */\n@@ -198,14 +200,14 @@ CameraConfiguration::Status RPiCameraConfiguration::validate()\n \t\t/* Use the application provided sensor configuration. */\n \t\tbitDepth = sensorConfig.bitDepth;\n \t\tsensorSize = sensorConfig.outputSize;\n-\t} else if (!rawStreams.empty()) {\n+\t} else if (!rawStreams_.empty()) {\n \t\t/* Use the RAW stream format and size. */\n-\t\tBayerFormat bayerFormat = BayerFormat::fromPixelFormat(rawStreams[0].cfg->pixelFormat);\n+\t\tBayerFormat bayerFormat = BayerFormat::fromPixelFormat(rawStreams_[0].cfg->pixelFormat);\n \t\tbitDepth = bayerFormat.bitDepth;\n-\t\tsensorSize = rawStreams[0].cfg->size;\n+\t\tsensorSize = rawStreams_[0].cfg->size;\n \t} else {\n \t\tbitDepth = defaultRawBitDepth;\n-\t\tsensorSize = outStreams[0].cfg->size;\n+\t\tsensorSize = outStreams_[0].cfg->size;\n \t}\n \n \tsensorFormat_ = data_->findBestFormat(sensorSize, bitDepth);\n@@ -226,12 +228,12 @@ CameraConfiguration::Status RPiCameraConfiguration::validate()\n \t}\n \n \t/* Do any platform specific fixups. */\n-\tstatus = data_->platformValidate(this, rawStreams, outStreams);\n+\tstatus = data_->platformValidate(this);\n \tif (status == Invalid)\n \t\treturn Invalid;\n \n \t/* Further fixups on the RAW streams. */\n-\tfor (auto &raw : rawStreams) {\n+\tfor (auto &raw : rawStreams_) {\n \t\tStreamConfiguration &cfg = config_.at(raw.index);\n \n \t\tV4L2DeviceFormat rawFormat;\n@@ -269,7 +271,7 @@ CameraConfiguration::Status RPiCameraConfiguration::validate()\n \t}\n \n \t/* Further fixups on the ISP output streams. */\n-\tfor (auto &out : outStreams) {\n+\tfor (auto &out : outStreams_) {\n \t\tStreamConfiguration &cfg = config_.at(out.index);\n \t\tPixelFormat &cfgPixFmt = cfg.pixelFormat;\n \t\tV4L2VideoDevice::Formats fmts = out.dev->formats();\n@@ -489,24 +491,6 @@ int PipelineHandlerBase::configure(Camera *camera, CameraConfiguration *config)\n \tfor (auto const stream : data->streams_)\n \t\tstream->clearFlags(StreamFlag::External);\n \n-\tstd::vector<CameraData::StreamParams> rawStreams, ispStreams;\n-\n-\tfor (unsigned i = 0; i < config->size(); i++) {\n-\t\tStreamConfiguration *cfg = &config->at(i);\n-\n-\t\tif (isRaw(cfg->pixelFormat))\n-\t\t\trawStreams.emplace_back(i, cfg);\n-\t\telse\n-\t\t\tispStreams.emplace_back(i, cfg);\n-\t}\n-\n-\t/* Sort the streams so the highest resolution is first. */\n-\tstd::sort(rawStreams.begin(), rawStreams.end(),\n-\t\t  [](auto &l, auto &r) { return l.cfg->size > r.cfg->size; });\n-\n-\tstd::sort(ispStreams.begin(), ispStreams.end(),\n-\t\t  [](auto &l, auto &r) { return l.cfg->size > r.cfg->size; });\n-\n \t/*\n \t * Apply the format on the sensor with any cached transform.\n \t *\n@@ -531,9 +515,9 @@ int PipelineHandlerBase::configure(Camera *camera, CameraConfiguration *config)\n \n \t/* Use the user requested packing/bit-depth. */\n \tstd::optional<BayerFormat::Packing> packing;\n-\tif (!rawStreams.empty()) {\n+\tif (!rpiConfig->rawStreams_.empty()) {\n \t\tBayerFormat bayerFormat =\n-\t\t\tBayerFormat::fromPixelFormat(rawStreams[0].cfg->pixelFormat);\n+\t\t\tBayerFormat::fromPixelFormat(rpiConfig->rawStreams_[0].cfg->pixelFormat);\n \t\tpacking = bayerFormat.packing;\n \t}\n \n@@ -541,7 +525,7 @@ int PipelineHandlerBase::configure(Camera *camera, CameraConfiguration *config)\n \t * Platform specific internal stream configuration. This also assigns\n \t * external streams which get configured below.\n \t */\n-\tret = data->platformConfigure(sensorFormat, packing, rawStreams, ispStreams);\n+\tret = data->platformConfigure(sensorFormat, packing, rpiConfig);\n \tif (ret)\n \t\treturn ret;\n \ndiff --git a/src/libcamera/pipeline/rpi/common/pipeline_base.h b/src/libcamera/pipeline/rpi/common/pipeline_base.h\nindex 135b74392140..1a3a13dbb6cf 100644\n--- a/src/libcamera/pipeline/rpi/common/pipeline_base.h\n+++ b/src/libcamera/pipeline/rpi/common/pipeline_base.h\n@@ -57,29 +57,10 @@ public:\n \t{\n \t}\n \n-\tstruct StreamParams {\n-\t\tStreamParams()\n-\t\t\t: index(0), cfg(nullptr), dev(nullptr)\n-\t\t{\n-\t\t}\n-\n-\t\tStreamParams(unsigned int index_, StreamConfiguration *cfg_)\n-\t\t\t: index(index_), cfg(cfg_), dev(nullptr)\n-\t\t{\n-\t\t}\n-\n-\t\tunsigned int index;\n-\t\tStreamConfiguration *cfg;\n-\t\tV4L2VideoDevice *dev;\n-\t};\n-\n-\tvirtual CameraConfiguration::Status platformValidate(RPiCameraConfiguration *rpiConfig,\n-\t\t\t\t\t\t\t     std::vector<StreamParams> &rawStreams,\n-\t\t\t\t\t\t\t     std::vector<StreamParams> &outStreams) const = 0;\n+\tvirtual CameraConfiguration::Status platformValidate(RPiCameraConfiguration *rpiConfig) const = 0;\n \tvirtual int platformConfigure(const V4L2SubdeviceFormat &sensorFormat,\n \t\t\t\t      std::optional<BayerFormat::Packing> packing,\n-\t\t\t\t      std::vector<StreamParams> &rawStreams,\n-\t\t\t\t      std::vector<StreamParams> &outStreams) = 0;\n+\t\t\t\t      const RPiCameraConfiguration *rpiConfig) = 0;\n \tvirtual void platformStart() = 0;\n \tvirtual void platformStop() = 0;\n \n@@ -270,6 +251,25 @@ public:\n \t/* The sensor format computed in validate() */\n \tV4L2SubdeviceFormat sensorFormat_;\n \n+\tstruct StreamParams {\n+\t\tStreamParams()\n+\t\t\t: index(0), cfg(nullptr), dev(nullptr)\n+\t\t{\n+\t\t}\n+\n+\t\tStreamParams(unsigned int index_, StreamConfiguration *cfg_)\n+\t\t\t: index(index_), cfg(cfg_), dev(nullptr)\n+\t\t{\n+\t\t}\n+\n+\t\tunsigned int index;\n+\t\tStreamConfiguration *cfg;\n+\t\tV4L2VideoDevice *dev;\n+\t};\n+\n+\tstd::vector<StreamParams> rawStreams_;\n+\tstd::vector<StreamParams> outStreams_;\n+\n private:\n \tconst CameraData *data_;\n \ndiff --git a/src/libcamera/pipeline/rpi/vc4/vc4.cpp b/src/libcamera/pipeline/rpi/vc4/vc4.cpp\nindex 2670eb8c4bbc..2308577a613b 100644\n--- a/src/libcamera/pipeline/rpi/vc4/vc4.cpp\n+++ b/src/libcamera/pipeline/rpi/vc4/vc4.cpp\n@@ -25,6 +25,7 @@ namespace libcamera {\n LOG_DECLARE_CATEGORY(RPI)\n \n using StreamFlag = RPi::Stream::StreamFlag;\n+using StreamParams = RPi::RPiCameraConfiguration::StreamParams;\n \n namespace {\n \n@@ -65,9 +66,7 @@ public:\n \t{\n \t}\n \n-\tCameraConfiguration::Status platformValidate(RPi::RPiCameraConfiguration *rpiConfig,\n-\t\t\t\t\t\t     std::vector<StreamParams> &rawStreams,\n-\t\t\t\t\t\t     std::vector<StreamParams> &outStreams) const override;\n+\tCameraConfiguration::Status platformValidate(RPi::RPiCameraConfiguration *rpiConfig) const override;\n \n \tint platformPipelineConfigure(const std::unique_ptr<YamlObject> &root) override;\n \n@@ -118,8 +117,7 @@ private:\n \n \tint platformConfigure(const V4L2SubdeviceFormat &sensorFormat,\n \t\t\t      std::optional<BayerFormat::Packing> packing,\n-\t\t\t      std::vector<StreamParams> &rawStreams,\n-\t\t\t      std::vector<StreamParams> &outStreams) override;\n+\t\t\t      const RPi::RPiCameraConfiguration *rpiConfig) override;\n \tint platformConfigureIpa(ipa::RPi::ConfigParams &params) override;\n \n \tint platformInitIpa([[maybe_unused]] ipa::RPi::InitParams &params) override\n@@ -395,10 +393,11 @@ int PipelineHandlerVc4::platformRegister(std::unique_ptr<RPi::CameraData> &camer\n \treturn 0;\n }\n \n-CameraConfiguration::Status Vc4CameraData::platformValidate(RPi::RPiCameraConfiguration *rpiConfig,\n-\t\t\t\t\t\t\t    std::vector<StreamParams> &rawStreams,\n-\t\t\t\t\t\t\t    std::vector<StreamParams> &outStreams) const\n+CameraConfiguration::Status Vc4CameraData::platformValidate(RPi::RPiCameraConfiguration *rpiConfig) const\n {\n+\tstd::vector<StreamParams> &rawStreams = rpiConfig->rawStreams_;\n+\tstd::vector<StreamParams> &outStreams = rpiConfig->outStreams_;\n+\n \tCameraConfiguration::Status status = CameraConfiguration::Status::Valid;\n \n \t/* Can only output 1 RAW stream, or 2 YUV/RGB streams. */\n@@ -503,9 +502,10 @@ int Vc4CameraData::platformPipelineConfigure(const std::unique_ptr<YamlObject> &\n \n int Vc4CameraData::platformConfigure(const V4L2SubdeviceFormat &sensorFormat,\n \t\t\t\t     std::optional<BayerFormat::Packing> packing,\n-\t\t\t\t     std::vector<StreamParams> &rawStreams,\n-\t\t\t\t     std::vector<StreamParams> &outStreams)\n+\t\t\t\t     const RPi::RPiCameraConfiguration *rpiConfig)\n {\n+\tconst std::vector<StreamParams> &rawStreams = rpiConfig->rawStreams_;\n+\tconst std::vector<StreamParams> &outStreams = rpiConfig->outStreams_;\n \tint ret;\n \n \tif (!packing)\n","prefixes":["libcamera-devel","v4","08/12"]}