Show a patch.

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

{
    "id": 14706,
    "url": "https://patchwork.libcamera.org/api/1.1/patches/14706/?format=api",
    "web_url": "https://patchwork.libcamera.org/patch/14706/",
    "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": "<20211123123751.3194696-3-hanlinchen@chromium.org>",
    "date": "2021-11-23T12:37:49",
    "name": "[libcamera-devel,v4,2/4] libcamera: camera_utils: Add a file for utils common to sensor and lens",
    "commit_ref": null,
    "pull_url": null,
    "state": "superseded",
    "archived": false,
    "hash": "b223c1a4fa2f5b12415ac597bee8f6571e4a99a9",
    "submitter": {
        "id": 98,
        "url": "https://patchwork.libcamera.org/api/1.1/people/98/?format=api",
        "name": "Hanlin Chen",
        "email": "hanlinchen@chromium.org"
    },
    "delegate": null,
    "mbox": "https://patchwork.libcamera.org/patch/14706/mbox/",
    "series": [
        {
            "id": 2743,
            "url": "https://patchwork.libcamera.org/api/1.1/series/2743/?format=api",
            "web_url": "https://patchwork.libcamera.org/project/libcamera/list/?series=2743",
            "date": "2021-11-23T12:37:47",
            "name": "Introduce Lens class and apply auto focus on ipu3",
            "version": 4,
            "mbox": "https://patchwork.libcamera.org/series/2743/mbox/"
        }
    ],
    "comments": "https://patchwork.libcamera.org/api/patches/14706/comments/",
    "check": "pending",
    "checks": "https://patchwork.libcamera.org/api/patches/14706/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 4CB93C324F\n\tfor <parsemail@patchwork.libcamera.org>;\n\tTue, 23 Nov 2021 12:38:08 +0000 (UTC)",
            "from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id 71DE46039C;\n\tTue, 23 Nov 2021 13:38:07 +0100 (CET)",
            "from mail-pj1-x1033.google.com (mail-pj1-x1033.google.com\n\t[IPv6:2607:f8b0:4864:20::1033])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id BC38660121\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tTue, 23 Nov 2021 13:38:05 +0100 (CET)",
            "by mail-pj1-x1033.google.com with SMTP id\n\to6-20020a17090a0a0600b001a64b9a11aeso2784160pjo.3\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tTue, 23 Nov 2021 04:38:05 -0800 (PST)",
            "from localhost ([2401:fa00:1:10:8aa3:febd:fadf:4199])\n\tby smtp.gmail.com with UTF8SMTPSA id\n\ty130sm11960803pfg.202.2021.11.23.04.38.03\n\t(version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128);\n\tTue, 23 Nov 2021 04:38:03 -0800 (PST)"
        ],
        "Authentication-Results": "lancelot.ideasonboard.com;\n\tdkim=fail reason=\"signature verification failed\" (1024-bit key;\n\tunprotected) header.d=chromium.org header.i=@chromium.org\n\theader.b=\"CQGlQQnz\"; dkim-atps=neutral",
        "DKIM-Signature": "v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org;\n\ts=google; \n\th=from:to:cc:subject:date:message-id:in-reply-to:references\n\t:mime-version:content-transfer-encoding;\n\tbh=79Xcfs2Cn5N780DQdk4iOZc3jJXYLSX2EDgtrl8AS6c=;\n\tb=CQGlQQnz5fvN5tKt/oeoybb3fxkw5duwK2nLxJRhpTRrwgKJv49bI6mX3EGv/JJNT8\n\tjJ/pfPeUFxvmcIIvSH728KdhaJiZoCQWDvVadj/V5N7VVtV2tR1ROySGhdCAwYFZ7yd7\n\t35S14lrZRfVu3anTCaYgEci9ov+1RJaG0RNRc=",
        "X-Google-DKIM-Signature": "v=1; a=rsa-sha256; c=relaxed/relaxed;\n\td=1e100.net; s=20210112;\n\th=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to\n\t:references:mime-version:content-transfer-encoding;\n\tbh=79Xcfs2Cn5N780DQdk4iOZc3jJXYLSX2EDgtrl8AS6c=;\n\tb=J+u+JaS5lrnMWgWormI+QNQft70kPUmCKrBvy84V9WLeMA/RnO+1NfNsD7eCHSkryl\n\tNvLB4MeJPRvVREnYodQd+WV4Z5ZZC4ApCW3KEzXO854C8i9s3x7ouqwCYOhkDAzHYIRQ\n\tmD5+Ou8XULKLqXCWWHzlLfqBdVvEap7GWE/grUE4SkXercVSbGAF/5KNp/8WCsKrnwAW\n\toiAPfKPf2l0vwoCDlscje2jzVOiwOoFNLhFG8LsGfk97h7TPBhsDyhO05s0vrhn03jTm\n\tNKkPnPqxXWarwsrPafbNY6Sw2jibCfv4BWozmy0z7l2eiirhWj+NgyiWRfSJVfIplkfZ\n\tzVaQ==",
        "X-Gm-Message-State": "AOAM5310XtUkrl0B7IVtIMrY0L17rr1FRQ92vG1C5O0VdkPtGr56ZjXU\n\t6kF56xT97Zma2kdkQeR38UJcPeLymaXdnQ==",
        "X-Google-Smtp-Source": "ABdhPJy8BbPg53UUzo2lwoc/kFtNshuksRo6pgYh6W7dTHM9Fh5tsHJa9kIisfaYg1AiYVcIXyigSQ==",
        "X-Received": "by 2002:a17:90b:4a05:: with SMTP id\n\tkk5mr2471413pjb.142.1637671084038; \n\tTue, 23 Nov 2021 04:38:04 -0800 (PST)",
        "From": "Han-Lin Chen <hanlinchen@chromium.org>",
        "To": "libcamera-devel@lists.libcamera.org",
        "Date": "Tue, 23 Nov 2021 20:37:49 +0800",
        "Message-Id": "<20211123123751.3194696-3-hanlinchen@chromium.org>",
        "X-Mailer": "git-send-email 2.34.0.rc2.393.gf8c9666880-goog",
        "In-Reply-To": "<20211123123751.3194696-1-hanlinchen@chromium.org>",
        "References": "<20211123123751.3194696-1-hanlinchen@chromium.org>",
        "MIME-Version": "1.0",
        "Content-Transfer-Encoding": "8bit",
        "Subject": "[libcamera-devel] [PATCH v4 2/4] libcamera: camera_utils: Add a\n\tfile for utils common to sensor and lens",
        "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>",
        "Errors-To": "libcamera-devel-bounces@lists.libcamera.org",
        "Sender": "\"libcamera-devel\" <libcamera-devel-bounces@lists.libcamera.org>"
    },
    "content": "Add a file to locate utils common to camera sensor and the following lens\nclass. The patch also moves two functions from camera_sensor.cpp used to\ngenerate id and model name for the sensor into the file.\n\nSigned-off-by: Han-Lin Chen <hanlinchen@chromium.org>\n---\n include/libcamera/internal/camera_sensor.h |  1 -\n include/libcamera/internal/camera_utils.h  | 22 +++++\n include/libcamera/internal/meson.build     |  1 +\n src/libcamera/camera_sensor.cpp            | 45 ++---------\n src/libcamera/camera_utils.cpp             | 94 ++++++++++++++++++++++\n src/libcamera/meson.build                  |  1 +\n 6 files changed, 124 insertions(+), 40 deletions(-)\n create mode 100644 include/libcamera/internal/camera_utils.h\n create mode 100644 src/libcamera/camera_utils.cpp",
    "diff": "diff --git a/include/libcamera/internal/camera_sensor.h b/include/libcamera/internal/camera_sensor.h\nindex d25a1165..134108ff 100644\n--- a/include/libcamera/internal/camera_sensor.h\n+++ b/include/libcamera/internal/camera_sensor.h\n@@ -66,7 +66,6 @@ protected:\n private:\n \tLIBCAMERA_DISABLE_COPY(CameraSensor)\n \n-\tint generateId();\n \tint validateSensorDriver();\n \tvoid initVimcDefaultProperties();\n \tvoid initStaticProperties();\ndiff --git a/include/libcamera/internal/camera_utils.h b/include/libcamera/internal/camera_utils.h\nnew file mode 100644\nindex 00000000..04c5e76f\n--- /dev/null\n+++ b/include/libcamera/internal/camera_utils.h\n@@ -0,0 +1,22 @@\n+/* SPDX-License-Identifier: LGPL-2.1-or-later */\n+/*\n+ * Copyright (C) 2021, Google Inc.\n+ *\n+ * camera_utils.h - Camera related utilities\n+ */\n+#ifndef __LIBCAMERA_INTERNAL_CAMERA_UTILS_H__\n+#define __LIBCAMERA_INTERNAL_CAMERA_UTILS_H__\n+\n+#include <string.h>\n+\n+#include \"libcamera/internal/v4l2_device.h\"\n+\n+namespace libcamera {\n+\n+std::string extractModelFromEntityName(const std::string &entityName);\n+std::string generateIdForV4L2Device(const V4L2Device *dev,\n+\t\t\t\t    const std::string &model);\n+\n+} /* namespace libcamera */\n+\n+#endif /* __LIBCAMERA_INTERNAL_CAMERA_UTILS_H__ */\ndiff --git a/include/libcamera/internal/meson.build b/include/libcamera/internal/meson.build\nindex 665fd6de..de8630fe 100644\n--- a/include/libcamera/internal/meson.build\n+++ b/include/libcamera/internal/meson.build\n@@ -16,6 +16,7 @@ libcamera_internal_headers = files([\n     'camera_controls.h',\n     'camera_sensor.h',\n     'camera_sensor_properties.h',\n+    'camera_utils.h',\n     'control_serializer.h',\n     'control_validator.h',\n     'delayed_controls.h',\ndiff --git a/src/libcamera/camera_sensor.cpp b/src/libcamera/camera_sensor.cpp\nindex 9fdb8c09..e91c2b0a 100644\n--- a/src/libcamera/camera_sensor.cpp\n+++ b/src/libcamera/camera_sensor.cpp\n@@ -6,14 +6,12 @@\n  */\n \n #include \"libcamera/internal/camera_sensor.h\"\n-#include \"libcamera/internal/media_device.h\"\n \n #include <algorithm>\n #include <float.h>\n #include <iomanip>\n #include <limits.h>\n #include <math.h>\n-#include <regex>\n #include <string.h>\n \n #include <libcamera/property_ids.h>\n@@ -22,8 +20,9 @@\n \n #include \"libcamera/internal/bayer_format.h\"\n #include \"libcamera/internal/camera_sensor_properties.h\"\n+#include \"libcamera/internal/camera_utils.h\"\n #include \"libcamera/internal/formats.h\"\n-#include \"libcamera/internal/sysfs.h\"\n+#include \"libcamera/internal/media_device.h\"\n \n /**\n  * \\file camera_sensor.h\n@@ -366,21 +365,13 @@ int CameraSensor::initProperties()\n \t * part of the entity name before the first space if the name contains\n \t * an I2C address, and use the full entity name otherwise.\n \t */\n-\tstd::string entityName = entity_->name();\n-\tstd::regex i2cRegex{ \" [0-9]+-[0-9a-f]{4}\" };\n-\tstd::smatch match;\n-\n-\tif (std::regex_search(entityName, match, i2cRegex))\n-\t\tmodel_ = entityName.substr(0, entityName.find(' '));\n-\telse\n-\t\tmodel_ = entityName;\n-\n+\tmodel_ = extractModelFromEntityName(entity_->name());\n \tproperties_.set(properties::Model, utils::toAscii(model_));\n \n \t/* Generate a unique ID for the sensor. */\n-\tint ret = generateId();\n-\tif (ret)\n-\t\treturn ret;\n+\tid_ = generateIdForV4L2Device(subdev_.get(), model_);\n+\tif (id_.empty())\n+\t\treturn -EINVAL;\n \n \t/* Initialize the static properties from the sensor database. */\n \tinitStaticProperties();\n@@ -820,28 +811,4 @@ 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.find(\"/sys/devices/platform/\", 0) == 0) {\n-\t\tid_ = devPath.substr(strlen(\"/sys/devices/\")) + \" \" + model();\n-\t\treturn 0;\n-\t}\n-\n-\tLOG(CameraSensor, Error) << \"Can't generate sensor ID\";\n-\treturn -EINVAL;\n-}\n-\n } /* namespace libcamera */\ndiff --git a/src/libcamera/camera_utils.cpp b/src/libcamera/camera_utils.cpp\nnew file mode 100644\nindex 00000000..b42911b4\n--- /dev/null\n+++ b/src/libcamera/camera_utils.cpp\n@@ -0,0 +1,94 @@\n+/* SPDX-License-Identifier: LGPL-2.1-or-later */\n+/*\n+ * Copyright (C) 2021, Google Inc.\n+ *\n+ * camera_utils.cpp - Camera related utilities\n+ */\n+\n+#include \"libcamera/internal/camera_utils.h\"\n+\n+#include <regex>\n+\n+#include \"libcamera/internal/sysfs.h\"\n+\n+/**\n+ * \\file camera_utils.h\n+ * \\brief Utilities for Camera instances\n+ */\n+\n+namespace libcamera {\n+\n+/**\n+ * \\brief Extract the sensor or lens model name from the media entity name\n+ * \\param[in] entityName The entity name of a lens or sensor\n+ *\n+ * \\return Model name as string\n+ */\n+std::string extractModelFromEntityName(const std::string &entityName)\n+{\n+\t/*\n+\t * Extract the sensor or lens model name from the media entity name.\n+\t *\n+\t * There is no standardized naming scheme for sensor entities in the\n+\t * Linux kernel at the moment.\n+\t *\n+\t * - The most common rule, used by I2C sensors, associates the model\n+\t *   name with the I2C bus number and address (e.g. 'imx219 0-0010').\n+\t *\n+\t * - When the sensor exposes multiple subdevs, the model name is\n+\t *   usually followed by a function name, as in the smiapp driver (e.g.\n+\t *   'jt8ew9 pixel_array 0-0010').\n+\t *\n+\t * - The vimc driver names its sensors 'Sensor A' and 'Sensor B'.\n+\t *\n+\t * Other schemes probably exist. As a best effort heuristic, use the\n+\t * part of the entity name before the first space if the name contains\n+\t * an I2C address, and use the full entity name otherwise.\n+\t */\n+\tstd::regex i2cRegex{ \" [0-9]+-[0-9a-f]{4}\" };\n+\tstd::smatch match;\n+\n+\tstd::string model;\n+\tif (std::regex_search(entityName, match, i2cRegex))\n+\t\tmodel = entityName.substr(0, entityName.find(' '));\n+\telse\n+\t\tmodel = entityName;\n+\n+\treturn model;\n+}\n+\n+/**\n+ * \\brief Generate ID for V4L2 device\n+ * \\param[in] dev The V4L2Device\n+ * \\param[in] model The ModelName\n+ *\n+ * Contruct ID from the firmware description. If it doesn't exist, contruct it\n+ * from the device path and the provided model name.\n+ * If both fails, return an empty string.\n+ *\n+ * \\return ID as string\n+ */\n+std::string generateIdForV4L2Device(const V4L2Device *dev,\n+\t\t\t\t    const std::string &model)\n+{\n+\tconst std::string devPath = dev->devicePath();\n+\n+\t/* Try to get ID from firmware description. */\n+\tstd::string id = sysfs::firmwareNodePath(devPath);\n+\tif (!id.empty())\n+\t\treturn id;\n+\n+\t/*\n+\t * Virtual device 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 a sensor or lens.\n+\t */\n+\tif (devPath.find(\"/sys/devices/platform/\", 0) == 0) {\n+\t\treturn devPath.substr(strlen(\"/sys/devices/\")) + \" \" + model;\n+\t}\n+\n+\treturn \"\";\n+}\n+\n+} /* namespace libcamera */\ndiff --git a/src/libcamera/meson.build b/src/libcamera/meson.build\nindex 6727a777..563ed861 100644\n--- a/src/libcamera/meson.build\n+++ b/src/libcamera/meson.build\n@@ -8,6 +8,7 @@ libcamera_sources = files([\n     'camera_manager.cpp',\n     'camera_sensor.cpp',\n     'camera_sensor_properties.cpp',\n+    'camera_utils.cpp',\n     'controls.cpp',\n     'control_serializer.cpp',\n     'control_validator.cpp',\n",
    "prefixes": [
        "libcamera-devel",
        "v4",
        "2/4"
    ]
}