Patch Detail
Show a patch.
GET /api/patches/18912/?format=api
{ "id": 18912, "url": "https://patchwork.libcamera.org/api/patches/18912/?format=api", "web_url": "https://patchwork.libcamera.org/patch/18912/", "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": "<20230731113115.5915-4-jacopo.mondi@ideasonboard.com>", "date": "2023-07-31T11:31:14", "name": "[libcamera-devel,v2,3/4] libcamera: camera_sensor: Add function to apply a config", "commit_ref": null, "pull_url": null, "state": "superseded", "archived": false, "hash": "315d16f44fb8dc3abb6f73b1188405852cb61ee0", "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/18912/mbox/", "series": [ { "id": 3997, "url": "https://patchwork.libcamera.org/api/series/3997/?format=api", "web_url": "https://patchwork.libcamera.org/project/libcamera/list/?series=3997", "date": "2023-07-31T11:31:11", "name": "libcamera: Introduce SensorConfiguration", "version": 2, "mbox": "https://patchwork.libcamera.org/series/3997/mbox/" } ], "comments": "https://patchwork.libcamera.org/api/patches/18912/comments/", "check": "pending", "checks": "https://patchwork.libcamera.org/api/patches/18912/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 CEB98C32A9\n\tfor <parsemail@patchwork.libcamera.org>;\n\tMon, 31 Jul 2023 11:31:40 +0000 (UTC)", "from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id 0AB35627F4;\n\tMon, 31 Jul 2023 13:31:40 +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 0F5AB627EF\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tMon, 31 Jul 2023 13:31:36 +0200 (CEST)", "from uno.localdomain (mob-5-90-53-43.net.vodafone.it [5.90.53.43])\n\tby perceval.ideasonboard.com (Postfix) with ESMTPSA id 9B3D012B1; \n\tMon, 31 Jul 2023 13:30:33 +0200 (CEST)" ], "DKIM-Signature": [ "v=1; a=rsa-sha256; c=relaxed/simple; d=libcamera.org;\n\ts=mail; t=1690803100;\n\tbh=Lcsp5bxXyF6F9amD/MIYkbupCUgOZQJ9MVE6UGRCTYs=;\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=C/ATEv87n9GPCgjKcjUnefbh0XcbpUpSXQ6F2qiIBc+Fc8Nlvz3SHoA6BTdSnr3GF\n\tb81R774yw2OSDWsuR42ppG9cFWc5fm6HEybS14Mnd/h12bfkW0Bp1vYI2JQm0SHQno\n\t4QaI1w9I5De+XqHQjKXUa9gXZLk3txZatgJqCX6Df3iLmnlNTNtm38ygztVmK6wtNx\n\t+ggAdj69TLn7zVcrOYhvGplQwYIlWviCdiKrVn8wihThbjsJP6nbr3TbWhHRQcvNED\n\t6Zsa5qdJqzEQ1572zMSzmN0x2/4gIe1od+jIgPCZ1TnoIhXLvP8c5y02hMcDl9+4xg\n\tm10lBIH9CyrqA==", "v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com;\n\ts=mail; t=1690803033;\n\tbh=Lcsp5bxXyF6F9amD/MIYkbupCUgOZQJ9MVE6UGRCTYs=;\n\th=From:To:Cc:Subject:Date:In-Reply-To:References:From;\n\tb=jRGw6xZ1K9WEq4DJiu5E5wrS7WoQ3/oEpHUt2Txl1HLrcAo++ndYRiaYayzYeLjDg\n\t/D1ywMjMixeA1RTsG8sjxRysSJ9IeIAbiNSowpmkI9v8jfh4F7twbXIen9cPXOyn9o\n\t83OyFjWSrTxATZHlpPB7QCjQrm0HAd695eh68f5w=" ], "Authentication-Results": "lancelot.ideasonboard.com; dkim=pass (1024-bit key; \n\tunprotected) header.d=ideasonboard.com\n\theader.i=@ideasonboard.com\n\theader.b=\"jRGw6xZ1\"; dkim-atps=neutral", "To": "libcamera-devel@lists.libcamera.org", "Date": "Mon, 31 Jul 2023 13:31:14 +0200", "Message-Id": "<20230731113115.5915-4-jacopo.mondi@ideasonboard.com>", "X-Mailer": "git-send-email 2.40.1", "In-Reply-To": "<20230731113115.5915-1-jacopo.mondi@ideasonboard.com>", "References": "<20230731113115.5915-1-jacopo.mondi@ideasonboard.com>", "MIME-Version": "1.0", "Content-Transfer-Encoding": "8bit", "Subject": "[libcamera-devel] [PATCH v2 3/4] libcamera: camera_sensor: Add\n\tfunction to apply a config", "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 to the CameraSensor class a function to apply to the sensor\na full configuration.\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>\n---\n include/libcamera/internal/camera_sensor.h | 5 ++\n src/libcamera/camera_sensor.cpp | 86 ++++++++++++++++++++++\n 2 files changed, 91 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..96b618572a3d 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,91 @@ 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+ * there specified cannot be applied as it is, an error code is returned.\n+ *\n+ * \\return 0 if \\a config is applied to the camera sensor, a negative error code\n+ * 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) {\n+\t\tLOG(CameraSensor, Error) << \"Invalid sensor configuration\";\n+\t\treturn -EINVAL;\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", "v2", "3/4" ] }