Patch Detail
Show a patch.
GET /api/1.1/patches/9050/?format=api
{ "id": 9050, "url": "https://patchwork.libcamera.org/api/1.1/patches/9050/?format=api", "web_url": "https://patchwork.libcamera.org/patch/9050/", "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": "<20200728234225.3505868-2-niklas.soderlund@ragnatech.se>", "date": "2020-07-28T23:42:22", "name": "[libcamera-devel,v3,2/5] libcamera: camera_sensor: Generate a sensor ID", "commit_ref": null, "pull_url": null, "state": "superseded", "archived": false, "hash": "c0e69dff04bcde6a3cfc498eb183b24f29ccaa34", "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/9050/mbox/", "series": [ { "id": 1158, "url": "https://patchwork.libcamera.org/api/1.1/series/1158/?format=api", "web_url": "https://patchwork.libcamera.org/project/libcamera/list/?series=1158", "date": "2020-07-28T23:37:39", "name": "libcamera: Generate unique and stable camera names", "version": 3, "mbox": "https://patchwork.libcamera.org/series/1158/mbox/" } ], "comments": "https://patchwork.libcamera.org/api/patches/9050/comments/", "check": "pending", "checks": "https://patchwork.libcamera.org/api/patches/9050/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 377F2BD86F\n\tfor <parsemail@patchwork.libcamera.org>;\n\tTue, 28 Jul 2020 23:42:42 +0000 (UTC)", "from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id A641F613C6;\n\tWed, 29 Jul 2020 01:42:40 +0200 (CEST)", "from bin-mail-out-06.binero.net (bin-mail-out-06.binero.net\n\t[195.74.38.229])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id 1284460535\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tWed, 29 Jul 2020 01:42:39 +0200 (CEST)", "from bismarck.berto.se (p4fca2eca.dip0.t-ipconnect.de\n\t[79.202.46.202]) by bin-vsp-out-02.atm.binero.net (Halon) with ESMTPA\n\tid 05040132-d12c-11ea-8fb8-005056917f90;\n\tWed, 29 Jul 2020 01:42:38 +0200 (CEST)" ], "X-Halon-ID": "05040132-d12c-11ea-8fb8-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, 29 Jul 2020 01:42:22 +0200", "Message-Id": "<20200728234225.3505868-2-niklas.soderlund@ragnatech.se>", "X-Mailer": "git-send-email 2.27.0", "In-Reply-To": "<20200728234225.3505868-1-niklas.soderlund@ragnatech.se>", "References": "<20200728233744.3503740-1-niklas.soderlund@ragnatech.se>\n\t<20200728234225.3505868-1-niklas.soderlund@ragnatech.se>", "MIME-Version": "1.0", "Subject": "[libcamera-devel] [PATCH v3 2/5] 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": "Generate a constant and unique string ID for the sensor. The ID is\ngenerated from firmware information fetched from the hardware that backs\nthe sensor. The ID is unique and persistent across reboots of the\nsystem.\n\nFor OF based systems the ID is the full path of the sensors in the\ndevice tree description. For ACPI bases systems the ID is the ACPI\nfirmware nodes path. Both ID sources are guaranteed to be unique and\npersistent as long as the firmware of the system is not changed.\n\nA special case is needed to deal with the VIMC pipeline that implements\na virtual pipeline that is not backed by any hardware device and is\ntherefore not described in the device firmware.\n\nSigned-off-by: Niklas Söderlund <niklas.soderlund@ragnatech.se>\n---\n include/libcamera/internal/camera_sensor.h | 4 +\n src/libcamera/camera_sensor.cpp | 85 ++++++++++++++++++++++\n 2 files changed, 89 insertions(+)", "diff": "diff --git a/include/libcamera/internal/camera_sensor.h b/include/libcamera/internal/camera_sensor.h\nindex 06c8292ca30129de..e0d2d9f63b47c2fe 100644\n--- a/include/libcamera/internal/camera_sensor.h\n+++ b/include/libcamera/internal/camera_sensor.h\n@@ -47,6 +47,7 @@ public:\n \tint init();\n \n \tconst std::string &model() const { return model_; }\n+\tconst std::string &id() const { return id_; }\n \tconst MediaEntity *entity() const { return entity_; }\n \tconst std::vector<unsigned int> &mbusCodes() const { return mbusCodes_; }\n \tconst std::vector<Size> &sizes() const { return sizes_; }\n@@ -67,11 +68,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..a4339759bc847ff0 100644\n--- a/src/libcamera/camera_sensor.cpp\n+++ b/src/libcamera/camera_sensor.cpp\n@@ -9,10 +9,12 @@\n \n #include <algorithm>\n #include <float.h>\n+#include <fstream>\n #include <iomanip>\n #include <limits.h>\n #include <math.h>\n #include <regex>\n+#include <sys/stat.h>\n \n #include <libcamera/property_ids.h>\n \n@@ -204,6 +206,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@@ -283,6 +290,17 @@ int CameraSensor::init()\n * \\return The sensor model name\n */\n \n+/**\n+ * \\fn CameraSensor::id()\n+ * \\brief Retrieve the sensor ID\n+ *\n+ * The sensor ID is a free-formed string that uniquely identifies the sensor in\n+ * the system. The ID is persisted between different instances of libcamera and\n+ * between resets of the system.\n+ *\n+ * \\return The sensor ID\n+ */\n+\n /**\n * \\fn CameraSensor::entity()\n * \\brief Retrieve the sensor media entity\n@@ -541,4 +559,71 @@ std::string CameraSensor::logPrefix() const\n \treturn \"'\" + entity_->name() + \"'\";\n }\n \n+int CameraSensor::generateID()\n+{\n+\tstd::string path, devPath = subdev_->devicePath();\n+\tstruct stat statbuf;\n+\n+\t/* Try to generate ID from OF device tree path. */\n+\tpath = devPath + \"/of_node\";\n+\tif (stat(path.c_str(), &statbuf) == 0) {\n+\t\tchar ofPath[PATH_MAX];\n+\n+\t\tif (!realpath(path.c_str(), ofPath)) {\n+\t\t\tLOG(CameraSensor, Error) << \"Failed to read sensor OF based ID\";\n+\t\t\treturn -EINVAL;\n+\t\t}\n+\n+\t\tid_ = ofPath;\n+\t\tconst std::string dropStr = \"/sys/firmware/devicetree/\";\n+\t\tif (id_.find(dropStr) == 0)\n+\t\t\tid_.erase(0, dropStr.length());\n+\n+\t\treturn 0;\n+\t}\n+\n+\t/* Try to generate ID from ACPI path. */\n+\tpath = devPath + \"/firmware_node/path\";\n+\tif (stat(path.c_str(), &statbuf) == 0) {\n+\t\tstd::ifstream file(path.c_str());\n+\n+\t\tif (!file.is_open()) {\n+\t\t\tLOG(CameraSensor, Error) << \"Failed to read sensor ACPI based ID\";\n+\t\t\treturn -EINVAL;\n+\t\t}\n+\n+\t\tstd::getline(file, id_);\n+\t\tfile.close();\n+\n+\t\treturn 0;\n+\t}\n+\n+\t/*\n+\t * VIMC is a virtual video pipeline not backed hardware and have no OF\n+\t * or ACPI firmware nodes. Handle this pipeline as a special case and\n+\t * generate IDs based on the sensor model.\n+\t */\n+\tpath = devPath + \"/modalias\";\n+\tif (stat(path.c_str(), &statbuf) == 0) {\n+\t\tstd::ifstream file(path.c_str());\n+\n+\t\tif (!file.is_open()) {\n+\t\t\tLOG(CameraSensor, Error) << \"Failed to read sensor ACPI based ID\";\n+\t\t\treturn -EINVAL;\n+\t\t}\n+\n+\t\tstd::string modalias;\n+\t\tstd::getline(file, modalias);\n+\t\tfile.close();\n+\n+\t\tif (modalias == \"platform:vimc\") {\n+\t\t\tid_ = \"VIMC \" + model();\n+\t\t\treturn 0;\n+\t\t}\n+\t}\n+\n+\tLOG(CameraSensor, Error) << \"Unknown sensor device type, can not generate ID\";\n+\treturn -EINVAL;\n+}\n+\n } /* namespace libcamera */\n", "prefixes": [ "libcamera-devel", "v3", "2/5" ] }