Patch Detail
Show a patch.
GET /api/patches/19041/?format=api
{ "id": 19041, "url": "https://patchwork.libcamera.org/api/patches/19041/?format=api", "web_url": "https://patchwork.libcamera.org/patch/19041/", "project": { "id": 1, "url": "https://patchwork.libcamera.org/api/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": "<20230916121930.29490-4-jacopo.mondi@ideasonboard.com>", "date": "2023-09-16T12:19:21", "name": "[libcamera-devel,v4,03/12] libcamera: camera_sensor: Support SensorConfiguration", "commit_ref": null, "pull_url": null, "state": "accepted", "archived": false, "hash": "fbe5ec7f284c9ff3075dccb3b11060fd6f413843", "submitter": { "id": 143, "url": "https://patchwork.libcamera.org/api/people/143/?format=api", "name": "Jacopo Mondi", "email": "jacopo.mondi@ideasonboard.com" }, "delegate": null, "mbox": "https://patchwork.libcamera.org/patch/19041/mbox/", "series": [ { "id": 4027, "url": "https://patchwork.libcamera.org/api/series/4027/?format=api", "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/19041/comments/", "check": "pending", "checks": "https://patchwork.libcamera.org/api/patches/19041/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 BCBDBBD160\n\tfor <parsemail@patchwork.libcamera.org>;\n\tSat, 16 Sep 2023 12:19:42 +0000 (UTC)", "from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id 490126292A;\n\tSat, 16 Sep 2023 14:19:42 +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 E23866291C\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tSat, 16 Sep 2023 14:19:38 +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 9DCF88BE;\n\tSat, 16 Sep 2023 14:18:04 +0200 (CEST)" ], "DKIM-Signature": [ "v=1; a=rsa-sha256; c=relaxed/simple; d=libcamera.org;\n\ts=mail; t=1694866782;\n\tbh=Te5nnrRTr32+HLX+QA/gnxn2lc1Wxq8owOHIdBsRk1c=;\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=vdyoLt7BCy9tH3+Gb6pe1Yc2YtL4eLoSv5nrK6WGLwz+6QYYs8ICnX4HZ8+tTCZ1B\n\tmt8QWfibTIDUXpZaqAG5LK7/InPklyIsQx6bmKRwngyMqyco9bd8Nh/JqV0kJV2bMD\n\tblOjqnjxwzx3sFs4Z1ekd3SLNYVnVZtNfDayZuAXQtwEptCIWVT4oA+bxISqLnt8AE\n\txvrDYVG6SB9gXQ836qtjJbYbjf6sxyPl8LoDaXtiDzKCJcftOzlnFZ/64zId7bDanD\n\ts5VoS3EGvQEPnS8vmLKE9grgiwMBmoRrMAofvfpyGERNaw6OKNo/l0ZOErzBgJH0Uh\n\tmh1eRGI32KB3w==", "v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com;\n\ts=mail; t=1694866684;\n\tbh=Te5nnrRTr32+HLX+QA/gnxn2lc1Wxq8owOHIdBsRk1c=;\n\th=From:To:Cc:Subject:Date:In-Reply-To:References:From;\n\tb=Eut56pVdEiWj0VcVrM5ZiBzu3yEVzaTHgs5cPveP1Im2Afhi6VF/FBm7haGEkCnlO\n\tnA2csjeNeGK9QHm7QuvwGD3LBXkEnAyyUPrV45uJY6oJhKPy7B55dRGE/FAuUWo2sB\n\t4se5gkqUuc54+IMvQfUznL0ipI7SwyAyewncrarY=" ], "Authentication-Results": "lancelot.ideasonboard.com; dkim=pass (1024-bit key; \n\tunprotected) header.d=ideasonboard.com\n\theader.i=@ideasonboard.com\n\theader.b=\"Eut56pVd\"; dkim-atps=neutral", "To": "libcamera-devel@lists.libcamera.org", "Date": "Sat, 16 Sep 2023 14:19:21 +0200", "Message-ID": "<20230916121930.29490-4-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 03/12] libcamera: camera_sensor:\n\tSupport SensorConfiguration", "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": "Add a class function to the CameraSensor class to apply a full\nconfiguration to the sensor.\n\nThe configuration shall be fully populated and shall apply without\nmodifications to the sensor.\n\nSigned-off-by: Jacopo Mondi <jacopo.mondi@ideasonboard.com>\nReviewed-by: Naushir Patuck <naush@raspberrypi.com>\nReviewed-by: Kieran Bingham <kieran.bingham@ideasonboard.com>\n---\n include/libcamera/internal/camera_sensor.h | 5 ++\n src/libcamera/camera_sensor.cpp | 91 ++++++++++++++++++++++\n 2 files changed, 96 insertions(+)", "diff": "diff --git a/include/libcamera/internal/camera_sensor.h b/include/libcamera/internal/camera_sensor.h\nindex 02c77ab037da..06791c3c6425 100644\n--- a/include/libcamera/internal/camera_sensor.h\n+++ b/include/libcamera/internal/camera_sensor.h\n@@ -29,6 +29,7 @@ namespace libcamera {\n class BayerFormat;\n class CameraLens;\n class MediaEntity;\n+class SensorConfiguration;\n \n struct CameraSensorProperties;\n \n@@ -58,6 +59,10 @@ public:\n \t\t Transform transform = Transform::Identity);\n \tint tryFormat(V4L2SubdeviceFormat *format) const;\n \n+\tint applyConfiguration(const SensorConfiguration &config,\n+\t\t\t Transform transform = Transform::Identity,\n+\t\t\t V4L2SubdeviceFormat *sensorFormat = nullptr);\n+\n \tconst ControlInfoMap &controls() const;\n \tControlList getControls(const std::vector<uint32_t> &ids);\n \tint setControls(ControlList *ctrls);\ndiff --git a/src/libcamera/camera_sensor.cpp b/src/libcamera/camera_sensor.cpp\nindex f3a5aa37149f..6c74d0736252 100644\n--- a/src/libcamera/camera_sensor.cpp\n+++ b/src/libcamera/camera_sensor.cpp\n@@ -15,6 +15,7 @@\n #include <math.h>\n #include <string.h>\n \n+#include <libcamera/camera.h>\n #include <libcamera/property_ids.h>\n \n #include <libcamera/base/utils.h>\n@@ -822,6 +823,96 @@ int CameraSensor::tryFormat(V4L2SubdeviceFormat *format) const\n \t\t\t\t V4L2Subdevice::Whence::TryFormat);\n }\n \n+/**\n+ * \\brief Apply a sensor configuration to the camera sensor\n+ * \\param[in] config The sensor configuration\n+ * \\param[in] transform The transform to be applied on the sensor.\n+ * Defaults to Identity\n+ * \\param[out] sensorFormat Optional output parameter where the format\n+ * actually applied to the sensor is returned to the caller\n+ *\n+ * Apply to the camera sensor the configuration \\a config.\n+ *\n+ * \\todo The configuration shall be fully populated and if any of the fields\n+ * specified cannot be applied exactly, an error code is returned.\n+ *\n+ * \\return 0 if \\a config unpopulated or is applied correctly to the camera\n+ * sensor, a negative error code otherwise\n+ */\n+int CameraSensor::applyConfiguration(const SensorConfiguration &config,\n+\t\t\t\t Transform transform,\n+\t\t\t\t V4L2SubdeviceFormat *sensorFormat)\n+{\n+\tif (!config.valid()) {\n+\t\tLOG(CameraSensor, Error) << \"Invalid sensor configuration\";\n+\t\treturn -EINVAL;\n+\t}\n+\n+\tif (!config.populated()) {\n+\t\tLOG(CameraSensor, Debug) << \"Sensor configuration unpopulated\";\n+\t\treturn 0;\n+\t}\n+\n+\tstd::vector<unsigned int> filteredCodes;\n+\tstd::copy_if(mbusCodes_.begin(), mbusCodes_.end(),\n+\t\t std::back_inserter(filteredCodes),\n+\t\t [&config](unsigned int mbusCode) {\n+\t\t\t BayerFormat bayer = BayerFormat::fromMbusCode(mbusCode);\n+\t\t\t if (bayer.bitDepth == config.bitDepth)\n+\t\t\t\t return true;\n+\t\t\t return false;\n+\t\t });\n+\tif (filteredCodes.empty()) {\n+\t\tLOG(CameraSensor, Error)\n+\t\t\t<< \"Cannot find any format with bit depth \"\n+\t\t\t<< config.bitDepth;\n+\t\treturn -EINVAL;\n+\t}\n+\n+\t/*\n+\t * Compute the sensor's data frame size by applying the cropping\n+\t * rectangle, subsampling and output crop to the sensor's pixel array\n+\t * size.\n+\t *\n+\t * \\todo The actual size computation is for now ignored and only the\n+\t * output size is considered. This implies that resolutions obtained\n+\t * with two different cropping/subsampling will look identical and\n+\t * only the first found one will be considered.\n+\t */\n+\tV4L2SubdeviceFormat subdevFormat = {};\n+\tfor (unsigned int code : filteredCodes) {\n+\t\tfor (const Size &size : sizes(code)) {\n+\t\t\tif (size.width != config.outputSize.width ||\n+\t\t\t size.height != config.outputSize.height)\n+\t\t\t\tcontinue;\n+\n+\t\t\tsubdevFormat.mbus_code = code;\n+\t\t\tsubdevFormat.size = size;\n+\t\t\tbreak;\n+\t\t}\n+\t}\n+\tif (!subdevFormat.mbus_code) {\n+\t\tLOG(CameraSensor, Error) << \"Invalid output size in sensor configuration\";\n+\t\treturn -EINVAL;\n+\t}\n+\n+\tint ret = setFormat(&subdevFormat, transform);\n+\tif (ret)\n+\t\treturn ret;\n+\n+\t/*\n+\t * Return to the caller the format actually applied to the sensor.\n+\t * This is relevant if transform has changed the bayer pattern order.\n+\t */\n+\tif (sensorFormat)\n+\t\t*sensorFormat = subdevFormat;\n+\n+\t/* \\todo Handle AnalogCrop. Most sensors do not support set_selection */\n+\t/* \\todo Handle scaling in the digital domain. */\n+\n+\treturn 0;\n+}\n+\n /**\n * \\brief Retrieve the supported V4L2 controls and their information\n *\n", "prefixes": [ "libcamera-devel", "v4", "03/12" ] }