Patch Detail
Show a patch.
GET /api/1.1/patches/19023/?format=api
{ "id": 19023, "url": "https://patchwork.libcamera.org/api/1.1/patches/19023/?format=api", "web_url": "https://patchwork.libcamera.org/patch/19023/", "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": "<20230915130650.35691-5-jacopo.mondi@ideasonboard.com>", "date": "2023-09-15T13:06:42", "name": "[libcamera-devel,v3,04/12] libcamera: rpi: Handle SensorConfiguration", "commit_ref": null, "pull_url": null, "state": "accepted", "archived": false, "hash": "5b9fed5f158ec039b6736091e27daed1c28e7e8f", "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/19023/mbox/", "series": [ { "id": 4025, "url": "https://patchwork.libcamera.org/api/1.1/series/4025/?format=api", "web_url": "https://patchwork.libcamera.org/project/libcamera/list/?series=4025", "date": "2023-09-15T13:06:38", "name": "libcamera: Introduce SensorConfiguration", "version": 3, "mbox": "https://patchwork.libcamera.org/series/4025/mbox/" } ], "comments": "https://patchwork.libcamera.org/api/patches/19023/comments/", "check": "pending", "checks": "https://patchwork.libcamera.org/api/patches/19023/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 7CFF3C3260\n\tfor <parsemail@patchwork.libcamera.org>;\n\tFri, 15 Sep 2023 13:07:15 +0000 (UTC)", "from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id B3AE362931;\n\tFri, 15 Sep 2023 15:07:14 +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 C51D762916\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tFri, 15 Sep 2023 15:07:09 +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 5238F2D14;\n\tFri, 15 Sep 2023 15:05:36 +0200 (CEST)" ], "DKIM-Signature": [ "v=1; a=rsa-sha256; c=relaxed/simple; d=libcamera.org;\n\ts=mail; t=1694783234;\n\tbh=diqPr+bOZt2J1Lky0enY1fCvxe9+SzbQzvAlh0xf60A=;\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=OPlJbQpG06RnwcT5JxtyNEbGgcaP89Zvr7XfOI+KfgflvmehCOiyzmhTqYYbZZ3Wz\n\tkZUXFZHoJE07V5zmTMUgkXEq1Py75YK562EIwjAlJOd4UoJlo0Gkh91/o/6c0q6PL2\n\tOBVv2qVtT2/iijbkz5N3aFrt7mjx7zDGh2V37GBnYIPTlpJJFdkC5ywjQP1Y4yZw8/\n\tFjFUOKh4DZZ/K+YUU4aKr47zm4XM5sXRDmoN+SOceb5SS21/8YOOxKbK13km48nVVa\n\tIoA61yECV0+cAnE02HDUjKEEaliJ0rzNAohUHnzTdfcAgQUXMkSF+AWpcEjZD5Me3W\n\t8XyGmzGXH2t9g==", "v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com;\n\ts=mail; t=1694783136;\n\tbh=diqPr+bOZt2J1Lky0enY1fCvxe9+SzbQzvAlh0xf60A=;\n\th=From:To:Cc:Subject:Date:In-Reply-To:References:From;\n\tb=VI4XnSRMPhVWcIWuKzrquz02NsrIfel4vYG3RaANJPXOD69nxaEi+n2XYkMaWglRt\n\t+1gK1fCV7DScjbHxN8ujmy5dDlBwHSVbIwnc1g36ysMOsrjK7IUG/acw8nGByzlStH\n\tbuzcfscOuva97Z3KmoUexWOL4IhCvG61V+5wfCwI=" ], "Authentication-Results": "lancelot.ideasonboard.com; dkim=pass (1024-bit key; \n\tunprotected) header.d=ideasonboard.com\n\theader.i=@ideasonboard.com\n\theader.b=\"VI4XnSRM\"; dkim-atps=neutral", "To": "libcamera-devel@lists.libcamera.org", "Date": "Fri, 15 Sep 2023 15:06:42 +0200", "Message-ID": "<20230915130650.35691-5-jacopo.mondi@ideasonboard.com>", "X-Mailer": "git-send-email 2.42.0", "In-Reply-To": "<20230915130650.35691-1-jacopo.mondi@ideasonboard.com>", "References": "<20230915130650.35691-1-jacopo.mondi@ideasonboard.com>", "MIME-Version": "1.0", "Content-Transfer-Encoding": "8bit", "Subject": "[libcamera-devel] [PATCH v3 04/12] 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 | 62 ++++++++++++++++---\n .../pipeline/rpi/common/pipeline_base.h | 4 +-\n src/libcamera/pipeline/rpi/vc4/vc4.cpp | 28 ++++++++-\n 3 files changed, 80 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..dff4164a5f02 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,11 @@ CameraConfiguration::Status RPiCameraConfiguration::validate()\n \tif (config_.empty())\n \t\treturn Invalid;\n \n+\tif (!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 +212,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 +496,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", "v3", "04/12" ] }