Patch Detail
Show a patch.
GET /api/1.1/patches/9211/?format=api
{ "id": 9211, "url": "https://patchwork.libcamera.org/api/1.1/patches/9211/?format=api", "web_url": "https://patchwork.libcamera.org/patch/9211/", "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": "<20200805104900.2172763-5-niklas.soderlund@ragnatech.se>", "date": "2020-08-05T10:48:55", "name": "[libcamera-devel,v8,4/9] libcamera: camera_sensor: Generate a sensor ID", "commit_ref": null, "pull_url": null, "state": "accepted", "archived": false, "hash": "a2ea5c3b8f1f6d4a4f37fd802fb014a2e0dd6387", "submitter": { "id": 5, "url": "https://patchwork.libcamera.org/api/1.1/people/5/?format=api", "name": "Niklas Söderlund", "email": "niklas.soderlund@ragnatech.se" }, "delegate": null, "mbox": "https://patchwork.libcamera.org/patch/9211/mbox/", "series": [ { "id": 1192, "url": "https://patchwork.libcamera.org/api/1.1/series/1192/?format=api", "web_url": "https://patchwork.libcamera.org/project/libcamera/list/?series=1192", "date": "2020-08-05T10:48:51", "name": "libcamera: Generate unique and stable camera IDs", "version": 8, "mbox": "https://patchwork.libcamera.org/series/1192/mbox/" } ], "comments": "https://patchwork.libcamera.org/api/patches/9211/comments/", "check": "pending", "checks": "https://patchwork.libcamera.org/api/patches/9211/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 A73D7BD86F\n\tfor <parsemail@patchwork.libcamera.org>;\n\tWed, 5 Aug 2020 10:49:17 +0000 (UTC)", "from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id EED45605AB;\n\tWed, 5 Aug 2020 12:49:16 +0200 (CEST)", "from bin-mail-out-05.binero.net (bin-mail-out-05.binero.net\n\t[195.74.38.228])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id 22E9C60555\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tWed, 5 Aug 2020 12:49:14 +0200 (CEST)", "from bismarck.berto.se (p54ac52a8.dip0.t-ipconnect.de\n\t[84.172.82.168]) by bin-vsp-out-02.atm.binero.net (Halon) with ESMTPA\n\tid 4cbdb497-d709-11ea-a39b-005056917f90;\n\tWed, 05 Aug 2020 12:49:13 +0200 (CEST)" ], "X-Halon-ID": "4cbdb497-d709-11ea-a39b-005056917f90", "Authorized-sender": "niklas@soderlund.pp.se", "From": "=?utf-8?q?Niklas_S=C3=B6derlund?= <niklas.soderlund@ragnatech.se>", "To": "libcamera-devel@lists.libcamera.org", "Date": "Wed, 5 Aug 2020 12:48:55 +0200", "Message-Id": "<20200805104900.2172763-5-niklas.soderlund@ragnatech.se>", "X-Mailer": "git-send-email 2.28.0", "In-Reply-To": "<20200805104900.2172763-1-niklas.soderlund@ragnatech.se>", "References": "<20200805104900.2172763-1-niklas.soderlund@ragnatech.se>", "MIME-Version": "1.0", "Subject": "[libcamera-devel] [PATCH v8 4/9] libcamera: camera_sensor: Generate\n\ta sensor ID", "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>", "Content-Type": "text/plain; charset=\"utf-8\"", "Content-Transfer-Encoding": "base64", "Errors-To": "libcamera-devel-bounces@lists.libcamera.org", "Sender": "\"libcamera-devel\" <libcamera-devel-bounces@lists.libcamera.org>" }, "content": "The ID is generated from information in the firmware description of the\nsensor if available or from module and model information if the sensor\nis virtual (for example VIMC).\n\nSigned-off-by: Niklas Söderlund <niklas.soderlund@ragnatech.se>\nReviewed-by: Jacopo Mondi <jacopo@jmondi.org>\n---\n* Changes sinve v7\n- Use device path stripped of /sys/devices/ prefix instead of modalias\n for virtual sensors.\n\n* Changes sinve v6\n- Do not allow for subclassing\n- Add support for virtual sensors\n- Use new sysfs:: helper.\n\n* Changes since v5\n- Use new utils:: helper.\n- Allow for subclassing\n\n* Changes since v4\n- Fix spelling.\n\n* Changes since v3\n- Update commit message.\n- Add description of how ID are generated to comment.\n---\n include/libcamera/internal/camera_sensor.h | 3 ++\n src/libcamera/camera_sensor.cpp | 37 ++++++++++++++++++++++\n 2 files changed, 40 insertions(+)", "diff": "diff --git a/include/libcamera/internal/camera_sensor.h b/include/libcamera/internal/camera_sensor.h\nindex 06c8292ca30129de..0f65fca46877e89a 100644\n--- a/include/libcamera/internal/camera_sensor.h\n+++ b/include/libcamera/internal/camera_sensor.h\n@@ -67,11 +67,14 @@ protected:\n \tstd::string logPrefix() const override;\n \n private:\n+\tint generateId();\n+\n \tconst MediaEntity *entity_;\n \tstd::unique_ptr<V4L2Subdevice> subdev_;\n \tunsigned int pad_;\n \n \tstd::string model_;\n+\tstd::string id_;\n \n \tV4L2Subdevice::Formats formats_;\n \tSize resolution_;\ndiff --git a/src/libcamera/camera_sensor.cpp b/src/libcamera/camera_sensor.cpp\nindex 350f49accad99c7b..695c4ad0028d5c4c 100644\n--- a/src/libcamera/camera_sensor.cpp\n+++ b/src/libcamera/camera_sensor.cpp\n@@ -9,6 +9,7 @@\n \n #include <algorithm>\n #include <float.h>\n+#include <fstream>\n #include <iomanip>\n #include <limits.h>\n #include <math.h>\n@@ -16,7 +17,9 @@\n \n #include <libcamera/property_ids.h>\n \n+#include \"libcamera/internal/file.h\"\n #include \"libcamera/internal/formats.h\"\n+#include \"libcamera/internal/sysfs.h\"\n #include \"libcamera/internal/utils.h\"\n \n /**\n@@ -204,6 +207,11 @@ int CameraSensor::init()\n \tif (ret < 0)\n \t\treturn ret;\n \n+\t/* Generate a unique ID for the sensor. */\n+\tret = generateId();\n+\tif (ret)\n+\t\treturn ret;\n+\n \t/* Retrieve and store the camera sensor properties. */\n \tconst ControlInfoMap &controls = subdev_->controls();\n \tint32_t propertyValue;\n@@ -541,4 +549,33 @@ std::string CameraSensor::logPrefix() const\n \treturn \"'\" + entity_->name() + \"'\";\n }\n \n+int CameraSensor::generateId()\n+{\n+\tconst std::string devPath = subdev_->devicePath();\n+\n+\t/* Try to get ID from firmware description. */\n+\tid_ = sysfs::firmwareNodePath(devPath);\n+\tif (!id_.empty())\n+\t\treturn 0;\n+\n+\t/*\n+\t * Virtual sensors not described in firmware\n+\t *\n+\t * Verify it's a platform device and construct ID from the deive path\n+\t * and model of sensor.\n+\t */\n+\tif (devPath.rfind(\"/sys/devices/platform/\", 0) == 0) {\n+\t\tid_ = devPath + \" \" + model();\n+\n+\t\tstatic const std::string dropStr = \"/sys/devices/\";\n+\t\tif (id_.find(dropStr) == 0)\n+\t\t\tid_.erase(0, dropStr.length());\n+\n+\t\treturn 0;\n+\t}\n+\n+\tLOG(CameraSensor, Error) << \"Can't generate sensor ID\";\n+\treturn -EINVAL;\n+}\n+\n } /* namespace libcamera */\n", "prefixes": [ "libcamera-devel", "v8", "4/9" ] }