Show a patch.

GET /api/1.1/patches/9056/?format=api
HTTP 200 OK
Allow: GET, PUT, PATCH, HEAD, OPTIONS
Content-Type: application/json
Vary: Accept

{
    "id": 9056,
    "url": "https://patchwork.libcamera.org/api/1.1/patches/9056/?format=api",
    "web_url": "https://patchwork.libcamera.org/patch/9056/",
    "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": "<20200729092122.3765539-3-niklas.soderlund@ragnatech.se>",
    "date": "2020-07-29T09:21:19",
    "name": "[libcamera-devel,v4,2/5] libcamera: camera_sensor: Generate a sensor ID",
    "commit_ref": null,
    "pull_url": null,
    "state": "superseded",
    "archived": false,
    "hash": "cc54a4d00dc19da1d0a9b0b2489a80594f13d6cf",
    "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/9056/mbox/",
    "series": [
        {
            "id": 1159,
            "url": "https://patchwork.libcamera.org/api/1.1/series/1159/?format=api",
            "web_url": "https://patchwork.libcamera.org/project/libcamera/list/?series=1159",
            "date": "2020-07-29T09:21:17",
            "name": "libcamera: Generate unique and stable camera names",
            "version": 4,
            "mbox": "https://patchwork.libcamera.org/series/1159/mbox/"
        }
    ],
    "comments": "https://patchwork.libcamera.org/api/patches/9056/comments/",
    "check": "pending",
    "checks": "https://patchwork.libcamera.org/api/patches/9056/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 C0796BD878\n\tfor <parsemail@patchwork.libcamera.org>;\n\tWed, 29 Jul 2020 09:21:40 +0000 (UTC)",
            "from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id 9396961988;\n\tWed, 29 Jul 2020 11:21:39 +0200 (CEST)",
            "from vsp-unauthed02.binero.net (vsp-unauthed02.binero.net\n\t[195.74.38.227])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id 45448617AF\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tWed, 29 Jul 2020 11:21:37 +0200 (CEST)",
            "from bismarck.berto.se (p4fca2eca.dip0.t-ipconnect.de\n\t[79.202.46.202]) by bin-vsp-out-03.atm.binero.net (Halon) with ESMTPA\n\tid b9409a43-d17c-11ea-86ee-0050569116f7;\n\tWed, 29 Jul 2020 11:20:20 +0200 (CEST)"
        ],
        "X-Halon-ID": "b9409a43-d17c-11ea-86ee-0050569116f7",
        "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 11:21:19 +0200",
        "Message-Id": "<20200729092122.3765539-3-niklas.soderlund@ragnatech.se>",
        "X-Mailer": "git-send-email 2.27.0",
        "In-Reply-To": "<20200729092122.3765539-1-niklas.soderlund@ragnatech.se>",
        "References": "<20200729092122.3765539-1-niklas.soderlund@ragnatech.se>",
        "MIME-Version": "1.0",
        "Subject": "[libcamera-devel] [PATCH v4 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 information from the firmware description of the camera\nimage 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 based 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>\nReviewed-by: Jacopo Mondi <jacopo@jmondi.org>\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 |  4 +\n src/libcamera/camera_sensor.cpp            | 94 ++++++++++++++++++++++\n 2 files changed, 98 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..a12d196ad898bb92 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,26 @@ 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 persistent between different instances of libcamera and\n+ * between resets of the system.\n+ *\n+ * For OF based systems the ID is the full path of the sensors in the device\n+ * tree description. For ACPI based systems the ID is the ACPI firmware nodes\n+ * path. Both ID sources are guaranteed to be unique and persistent as long as\n+ * the firmware of the system is not changed.\n+ *\n+ * A special case is needed to deal with the VIMC pipeline that implements a\n+ * virtual pipeline that is not backed by any hardware device and is therefore\n+ * not described in the device firmware.\n+ *\n+ * \\return The sensor ID\n+ */\n+\n /**\n  * \\fn CameraSensor::entity()\n  * \\brief Retrieve the sensor media entity\n@@ -541,4 +568,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",
        "v4",
        "2/5"
    ]
}