Patch Detail
Show a patch.
GET /api/1.1/patches/19068/?format=api
{ "id": 19068, "url": "https://patchwork.libcamera.org/api/1.1/patches/19068/?format=api", "web_url": "https://patchwork.libcamera.org/patch/19068/", "project": { "id": 1, "url": "https://patchwork.libcamera.org/api/1.1/projects/1/?format=api", "name": "libcamera", "link_name": "libcamera", "list_id": "libcamera_core", "list_email": "libcamera-devel@lists.libcamera.org", "web_url": "", "scm_url": "", "webscm_url": "" }, "msgid": "<20230921165550.50956-5-jacopo.mondi@ideasonboard.com>", "date": "2023-09-21T16:55:41", "name": "[libcamera-devel,v5,04/13] libcamera: rpi: Handle SensorConfiguration", "commit_ref": null, "pull_url": null, "state": "accepted", "archived": false, "hash": "bfc41c07ba418e4924650c49bfb6c9600b1b480d", "submitter": { "id": 143, "url": "https://patchwork.libcamera.org/api/1.1/people/143/?format=api", "name": "Jacopo Mondi", "email": "jacopo.mondi@ideasonboard.com" }, "delegate": null, "mbox": "https://patchwork.libcamera.org/patch/19068/mbox/", "series": [ { "id": 4034, "url": "https://patchwork.libcamera.org/api/1.1/series/4034/?format=api", "web_url": "https://patchwork.libcamera.org/project/libcamera/list/?series=4034", "date": "2023-09-21T16:55:37", "name": "libcamera: Introduce SensorConfiguration", "version": 5, "mbox": "https://patchwork.libcamera.org/series/4034/mbox/" } ], "comments": "https://patchwork.libcamera.org/api/patches/19068/comments/", "check": "pending", "checks": "https://patchwork.libcamera.org/api/patches/19068/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 A22FBC326C\n\tfor <parsemail@patchwork.libcamera.org>;\n\tThu, 21 Sep 2023 16:56:09 +0000 (UTC)", "from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id A887A62947;\n\tThu, 21 Sep 2023 18:56: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 6665F628D8\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tThu, 21 Sep 2023 18:56:03 +0200 (CEST)", "from uno.lan (93-46-82-201.ip106.fastwebnet.it [93.46.82.201])\n\tby perceval.ideasonboard.com (Postfix) with ESMTPSA id CCDDD8201;\n\tThu, 21 Sep 2023 18:54:25 +0200 (CEST)" ], "DKIM-Signature": [ "v=1; a=rsa-sha256; c=relaxed/simple; d=libcamera.org;\n\ts=mail; t=1695315367;\n\tbh=qXGx6RyMquUh9GOu6AN6eszqs/7WzI1BqcrEed/s/+k=;\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=WWkYuKB+16ydkCkm19t9lz+VGlTczRF1sDSn8zpdK09CSCO+ZkBQmbbQLhyAB+yrJ\n\t1/eR9sOtxPT2QaF5pAm6gfNp6uyya+AG27Jpwbqf8Yh05LpbjZv2D+Ks9G4QRnS+sy\n\t+Dgy///nyGwLpkxVEPAi6bjClAot2vjtab0CoeDZrXjuPpiqP6QMagEoCsuUxJbFdy\n\tTFTUUUWip/V4L7tlpJPmh8BwzYoo7GhDwwvVHsNtkVg+8MZP7XHyNR1jM+I6+2hbGj\n\tQiEn6b7QrmvXvt8Zjy0vYJ/2KHHgVnmYkkXd6ri8Z2XbORXQch4BxBRpRghbzhzoOt\n\tbkU6DXU0bPGWQ==", "v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com;\n\ts=mail; t=1695315266;\n\tbh=qXGx6RyMquUh9GOu6AN6eszqs/7WzI1BqcrEed/s/+k=;\n\th=From:To:Cc:Subject:Date:In-Reply-To:References:From;\n\tb=L7uHlzuVchT42s2S6oRuGCVlg1tAiizOoVBQ3uJcYGxEgGCUkfOrUxguyn3wgoz2t\n\tnf1shEEH6EgHQlbeN/EMDGPek4M1vRmalq8TRLv3+ZfVEoCc00A85VY7fovEI7JGIv\n\t9d0LdZTqR28pBGwZPCSf/qzMGnImJ4J8NdFU31zk=" ], "Authentication-Results": "lancelot.ideasonboard.com; dkim=pass (1024-bit key; \n\tunprotected) header.d=ideasonboard.com\n\theader.i=@ideasonboard.com\n\theader.b=\"L7uHlzuV\"; dkim-atps=neutral", "To": "libcamera-devel@lists.libcamera.org", "Date": "Thu, 21 Sep 2023 18:55:41 +0200", "Message-ID": "<20230921165550.50956-5-jacopo.mondi@ideasonboard.com>", "X-Mailer": "git-send-email 2.42.0", "In-Reply-To": "<20230921165550.50956-1-jacopo.mondi@ideasonboard.com>", "References": "<20230921165550.50956-1-jacopo.mondi@ideasonboard.com>", "MIME-Version": "1.0", "Content-Transfer-Encoding": "8bit", "Subject": "[libcamera-devel] [PATCH v5 04/13] libcamera: rpi: Handle\n\tSensorConfiguration", "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": "Handle the SensorConfiguration provided by the application in the\npipeline validate() and configure() call chains.\n\nDuring validation, first make sure SensorConfiguration is valid, then\nhandle it to compute the sensor format.\n\nFor the VC4 platform where the RAW stream follows the sensor's\nconfiguration adjust the RAW stream configuration to match the sensor\nconfiguration.\n\nReviewed-by: Naushir Patuck <naush@raspberrypi.com>\nReviewed-by: Kieran Bingham <kieran.bingham@ideasonboard.com>\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 | 66 ++++++++++++++++---\n .../pipeline/rpi/common/pipeline_base.h | 4 +-\n src/libcamera/pipeline/rpi/vc4/vc4.cpp | 28 +++++++-\n 3 files changed, 84 insertions(+), 14 deletions(-)", "diff": "diff --git a/src/libcamera/pipeline/rpi/common/pipeline_base.cpp b/src/libcamera/pipeline/rpi/common/pipeline_base.cpp\nindex 51fa1bbf9aa9..c02ceb65cae8 100644\n--- a/src/libcamera/pipeline/rpi/common/pipeline_base.cpp\n+++ b/src/libcamera/pipeline/rpi/common/pipeline_base.cpp\n@@ -180,6 +180,15 @@ CameraConfiguration::Status RPiCameraConfiguration::validate()\n \tif (config_.empty())\n \t\treturn Invalid;\n \n+\t/*\n+\t * Make sure that if a sensor configuration has been requested it\n+\t * is valid.\n+\t */\n+\tif (sensorConfig && !sensorConfig->valid()) {\n+\t\tLOG(RPI, Error) << \"Invalid sensor configuration request\";\n+\t\treturn Invalid;\n+\t}\n+\n \tstatus = validateColorSpaces(ColorSpaceFlag::StreamsShareColorSpace);\n \n \t/*\n@@ -207,19 +216,43 @@ CameraConfiguration::Status RPiCameraConfiguration::validate()\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 configuration. */\n-\tunsigned int bitDepth = defaultRawBitDepth;\n-\tif (!rawStreams.empty()) {\n+\t/* Compute the sensor's format then do any platform specific fixups. */\n+\tunsigned int bitDepth;\n+\tSize sensorSize;\n+\n+\tif (sensorConfig) {\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\t/* Use the RAW stream format and size. */\n \t\tBayerFormat bayerFormat = BayerFormat::fromPixelFormat(rawStreams[0].cfg->pixelFormat);\n \t\tbitDepth = bayerFormat.bitDepth;\n+\t\tsensorSize = rawStreams[0].cfg->size;\n+\t} else {\n+\t\tbitDepth = defaultRawBitDepth;\n+\t\tsensorSize = outStreams[0].cfg->size;\n \t}\n \n-\tsensorFormat_ = data_->findBestFormat(rawStreams.empty() ? outStreams[0].cfg->size\n-\t\t\t\t\t\t\t\t : rawStreams[0].cfg->size,\n-\t\t\t\t\t bitDepth);\n+\tsensorFormat_ = data_->findBestFormat(sensorSize, bitDepth);\n+\n+\t/*\n+\t * If a sensor configuration has been requested, it should apply\n+\t * without modifications.\n+\t */\n+\tif (sensorConfig) {\n+\t\tBayerFormat bayer = BayerFormat::fromMbusCode(sensorFormat_.mbus_code);\n+\n+\t\tif (bayer.bitDepth != sensorConfig->bitDepth ||\n+\t\t sensorFormat_.size != sensorConfig->outputSize) {\n+\t\t\tLOG(RPI, Error) << \"Invalid sensor configuration: \"\n+\t\t\t\t\t<< \"bitDepth/size mismatch\";\n+\t\t\treturn Invalid;\n+\t\t}\n+\t}\n \n \t/* Do any platform specific fixups. */\n-\tstatus = data_->platformValidate(rawStreams, outStreams);\n+\tstatus = data_->platformValidate(this, rawStreams, outStreams);\n \tif (status == Invalid)\n \t\treturn Invalid;\n \n@@ -467,12 +500,25 @@ int PipelineHandlerBase::configure(Camera *camera, CameraConfiguration *config)\n \tstd::sort(ispStreams.begin(), ispStreams.end(),\n \t\t [](auto &l, auto &r) { return l.cfg->size > r.cfg->size; });\n \n-\t/* Apply the format on the sensor with any cached transform. */\n+\t/*\n+\t * Apply the format on the sensor with any cached transform.\n+\t *\n+\t * If the application has provided a sensor configuration apply it\n+\t * instead of just applying a format.\n+\t */\n \tconst RPiCameraConfiguration *rpiConfig =\n \t\t\t\tstatic_cast<const RPiCameraConfiguration *>(config);\n-\tV4L2SubdeviceFormat sensorFormat = rpiConfig->sensorFormat_;\n+\tV4L2SubdeviceFormat sensorFormat;\n \n-\tret = data->sensor_->setFormat(&sensorFormat, rpiConfig->combinedTransform_);\n+\tif (rpiConfig->sensorConfig) {\n+\t\tret = data->sensor_->applyConfiguration(*rpiConfig->sensorConfig,\n+\t\t\t\t\t\t\trpiConfig->combinedTransform_,\n+\t\t\t\t\t\t\t&sensorFormat);\n+\t} else {\n+\t\tsensorFormat = rpiConfig->sensorFormat_;\n+\t\tret = data->sensor_->setFormat(&sensorFormat,\n+\t\t\t\t\t rpiConfig->combinedTransform_);\n+\t}\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 dbabc61ea48c..81b2b7d2f4d1 100644\n--- a/src/libcamera/pipeline/rpi/common/pipeline_base.h\n+++ b/src/libcamera/pipeline/rpi/common/pipeline_base.h\n@@ -42,6 +42,7 @@ namespace RPi {\n /* Map of mbus codes to supported sizes reported by the sensor. */\n using SensorFormats = std::map<unsigned int, std::vector<Size>>;\n \n+class RPiCameraConfiguration;\n class CameraData : public Camera::Private\n {\n public:\n@@ -72,7 +73,8 @@ public:\n \t\tV4L2VideoDevice *dev;\n \t};\n \n-\tvirtual CameraConfiguration::Status platformValidate(std::vector<StreamParams> &rawStreams,\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 int platformConfigure(const V4L2SubdeviceFormat &sensorFormat,\n \t\t\t\t std::optional<BayerFormat::Packing> packing,\ndiff --git a/src/libcamera/pipeline/rpi/vc4/vc4.cpp b/src/libcamera/pipeline/rpi/vc4/vc4.cpp\nindex 018cf4881d0e..2670eb8c4bbc 100644\n--- a/src/libcamera/pipeline/rpi/vc4/vc4.cpp\n+++ b/src/libcamera/pipeline/rpi/vc4/vc4.cpp\n@@ -65,7 +65,8 @@ public:\n \t{\n \t}\n \n-\tCameraConfiguration::Status platformValidate(std::vector<StreamParams> &rawStreams,\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 \n \tint platformPipelineConfigure(const std::unique_ptr<YamlObject> &root) override;\n@@ -394,7 +395,8 @@ int PipelineHandlerVc4::platformRegister(std::unique_ptr<RPi::CameraData> &camer\n \treturn 0;\n }\n \n-CameraConfiguration::Status Vc4CameraData::platformValidate(std::vector<StreamParams> &rawStreams,\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 {\n \tCameraConfiguration::Status status = CameraConfiguration::Status::Valid;\n@@ -405,9 +407,27 @@ CameraConfiguration::Status Vc4CameraData::platformValidate(std::vector<StreamPa\n \t\treturn CameraConfiguration::Status::Invalid;\n \t}\n \n-\tif (!rawStreams.empty())\n+\tif (!rawStreams.empty()) {\n \t\trawStreams[0].dev = unicam_[Unicam::Image].dev();\n \n+\t\t/* Adjust the RAW stream to match the computed sensor format. */\n+\t\tStreamConfiguration *rawStream = rawStreams[0].cfg;\n+\t\tBayerFormat rawBayer = BayerFormat::fromMbusCode(rpiConfig->sensorFormat_.mbus_code);\n+\n+\t\t/* Handle flips to make sure to match the RAW stream format. */\n+\t\tif (flipsAlterBayerOrder_)\n+\t\t\trawBayer = rawBayer.transform(rpiConfig->combinedTransform_);\n+\t\tPixelFormat rawFormat = rawBayer.toPixelFormat();\n+\n+\t\tif (rawStream->pixelFormat != rawFormat ||\n+\t\t rawStream->size != rpiConfig->sensorFormat_.size) {\n+\t\t\trawStream->pixelFormat = rawFormat;\n+\t\t\trawStream->size = rpiConfig->sensorFormat_.size;\n+\n+\t\t\tstatus = CameraConfiguration::Adjusted;\n+\t\t}\n+\t}\n+\n \t/*\n \t * For the two ISP outputs, one stream must be equal or smaller than the\n \t * other in all dimensions.\n@@ -417,6 +437,8 @@ CameraConfiguration::Status Vc4CameraData::platformValidate(std::vector<StreamPa\n \tfor (unsigned int i = 0; i < outStreams.size(); i++) {\n \t\tSize size;\n \n+\t\t/* \\todo Warn if upscaling: reduces image quality. */\n+\n \t\tsize.width = std::min(outStreams[i].cfg->size.width,\n \t\t\t\t outStreams[0].cfg->size.width);\n \t\tsize.height = std::min(outStreams[i].cfg->size.height,\n", "prefixes": [ "libcamera-devel", "v5", "04/13" ] }