Show a patch.

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

{
    "id": 16389,
    "url": "https://patchwork.libcamera.org/api/patches/16389/?format=api",
    "web_url": "https://patchwork.libcamera.org/patch/16389/",
    "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": "<20220627162732.33160-9-jacopo@jmondi.org>",
    "date": "2022-06-27T16:27:25",
    "name": "[libcamera-devel,08/15] libcamera: camera_sensor: Initialize controls",
    "commit_ref": null,
    "pull_url": null,
    "state": "not-applicable",
    "archived": true,
    "hash": "7be34d6c12ee2398746ed3f80809aa8db2a178b9",
    "submitter": {
        "id": 3,
        "url": "https://patchwork.libcamera.org/api/people/3/?format=api",
        "name": "Jacopo Mondi",
        "email": "jacopo@jmondi.org"
    },
    "delegate": null,
    "mbox": "https://patchwork.libcamera.org/patch/16389/mbox/",
    "series": [
        {
            "id": 3224,
            "url": "https://patchwork.libcamera.org/api/series/3224/?format=api",
            "web_url": "https://patchwork.libcamera.org/project/libcamera/list/?series=3224",
            "date": "2022-06-27T16:27:17",
            "name": "Internal controls, sensor delays and IPA init/configure rework",
            "version": 1,
            "mbox": "https://patchwork.libcamera.org/series/3224/mbox/"
        }
    ],
    "comments": "https://patchwork.libcamera.org/api/patches/16389/comments/",
    "check": "pending",
    "checks": "https://patchwork.libcamera.org/api/patches/16389/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 F2F64BD808\n\tfor <parsemail@patchwork.libcamera.org>;\n\tMon, 27 Jun 2022 16:27:55 +0000 (UTC)",
            "from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id 73DEF6563E;\n\tMon, 27 Jun 2022 18:27:55 +0200 (CEST)",
            "from relay7-d.mail.gandi.net (relay7-d.mail.gandi.net\n\t[IPv6:2001:4b98:dc4:8::227])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id 392B465636\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tMon, 27 Jun 2022 18:27:48 +0200 (CEST)",
            "(Authenticated sender: jacopo@jmondi.org)\n\tby mail.gandi.net (Postfix) with ESMTPSA id 6E62420009;\n\tMon, 27 Jun 2022 16:27:47 +0000 (UTC)"
        ],
        "DKIM-Signature": "v=1; a=rsa-sha256; c=relaxed/simple; d=libcamera.org;\n\ts=mail; t=1656347275;\n\tbh=y2h0WznafB5q+/INu0P7L8XWOVslu0KaZmIrAPC07d8=;\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:\n\tFrom;\n\tb=uae3sTqwbQTLni+zWNlJhbNGGs/8xRa6Q+9w5EjoFw4ZOE9w5Ks6X1oJssXUNGeLz\n\t4q2khufbN8WsEY+fUDbykp29ElCzld2iyhKp9nOiElD3IjQ251GTHGTX6Tc2hQezHd\n\t5ZNoJlyJozkv87GIJKWhI1q3onki2qpjuJVj2l5/nVukFrGjszfvnzcFuFQ4GIAoul\n\t4rRGxHbZdas3azcbFWJoOgh1rdvvKQRncWkAIyABNeC7LET5mYTY7NZpR8CuFWAVG4\n\trWZEpsTD9ZiHiUzKbKn5HnC5zT80Mw9sWXWPlwF51JrgVslxBQtLVZYnRynW2lMszW\n\t8XmlfDuXujAzA==",
        "To": "libcamera-devel@lists.libcamera.org",
        "Date": "Mon, 27 Jun 2022 18:27:25 +0200",
        "Message-Id": "<20220627162732.33160-9-jacopo@jmondi.org>",
        "X-Mailer": "git-send-email 2.36.1",
        "In-Reply-To": "<20220627162732.33160-1-jacopo@jmondi.org>",
        "References": "<20220627162732.33160-1-jacopo@jmondi.org>",
        "MIME-Version": "1.0",
        "Content-Transfer-Encoding": "8bit",
        "Subject": "[libcamera-devel] [PATCH 08/15] libcamera: camera_sensor:\n\tInitialize controls",
        "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@jmondi.org>",
        "Errors-To": "libcamera-devel-bounces@lists.libcamera.org",
        "Sender": "\"libcamera-devel\" <libcamera-devel-bounces@lists.libcamera.org>"
    },
    "content": "Initialize the control interface of the CameraSensor class by\nregistering the control limits for controls::internal::ExposureTime,\ncontrols::internal::FrameDuration and\ncontrols::internal::draft::SensorAnalogueGain.\n\nUpdate the CameraSensor controls in the CameraSensor::updateControlInfo()\nfunction after having updated the subdevice V4L2 controls.\n\nSigned-off-by: Jacopo Mondi <jacopo@jmondi.org>\n---\n include/libcamera/internal/camera_sensor.h |  3 +\n src/libcamera/camera_sensor.cpp            | 89 ++++++++++++++++++++++\n src/libcamera/internal_control_ids.yaml    | 10 +++\n 3 files changed, 102 insertions(+)",
    "diff": "diff --git a/include/libcamera/internal/camera_sensor.h b/include/libcamera/internal/camera_sensor.h\nindex 0bed6e679840..c71f93f230d1 100644\n--- a/include/libcamera/internal/camera_sensor.h\n+++ b/include/libcamera/internal/camera_sensor.h\n@@ -66,6 +66,7 @@ public:\n \tV4L2Subdevice *device() { return subdev_.get(); }\n \n \tconst ControlList &properties() const { return properties_; }\n+\tconst ControlInfoMap &controls() const { return controls_; }\n \tint sensorInfo(IPACameraSensorInfo *info) const;\n \n \tvoid updateControlInfo();\n@@ -84,6 +85,7 @@ private:\n \tvoid initStaticProperties();\n \tvoid initTestPatternModes();\n \tint initProperties();\n+\tint updateControls();\n \tint applyTestPatternMode(controls::draft::TestPatternModeEnum mode);\n \tint discoverAncillaryDevices();\n \n@@ -107,6 +109,7 @@ private:\n \tconst BayerFormat *bayerFormat_;\n \n \tControlList properties_;\n+\tControlInfoMap controls_;\n \n \tstd::unique_ptr<CameraLens> focusLens_;\n };\ndiff --git a/src/libcamera/camera_sensor.cpp b/src/libcamera/camera_sensor.cpp\nindex e3354530380c..82e51272cccc 100644\n--- a/src/libcamera/camera_sensor.cpp\n+++ b/src/libcamera/camera_sensor.cpp\n@@ -22,6 +22,7 @@\n #include \"libcamera/internal/bayer_format.h\"\n #include \"libcamera/internal/camera_lens.h\"\n #include \"libcamera/internal/camera_sensor_properties.h\"\n+#include \"libcamera/internal/control_ids.h\"\n #include \"libcamera/internal/formats.h\"\n #include \"libcamera/internal/sysfs.h\"\n \n@@ -180,6 +181,10 @@ int CameraSensor::init()\n \tif (ret)\n \t\treturn ret;\n \n+\tret = updateControls();\n+\tif (ret)\n+\t\treturn ret;\n+\n \tret = discoverAncillaryDevices();\n \tif (ret)\n \t\treturn ret;\n@@ -455,6 +460,83 @@ int CameraSensor::initProperties()\n \treturn 0;\n }\n \n+int CameraSensor::updateControls()\n+{\n+\tif (!bayerFormat_)\n+\t\treturn 0;\n+\n+\tControlInfoMap::Map controlsMap;\n+\n+\t/* The subdev driver has been validate already, the controls are there! */\n+\tControlList subdevControls = subdev_->getControls({ V4L2_CID_PIXEL_RATE,\n+\t\t\t\t\t\t\t    V4L2_CID_HBLANK,\n+\t\t\t\t\t\t\t    V4L2_CID_VBLANK });\n+\tuint64_t pixelRate = subdevControls.get(V4L2_CID_PIXEL_RATE).get<int64_t>();\n+\tuint32_t hblank = subdevControls.get(V4L2_CID_HBLANK).get<int32_t>();\n+\n+\t/*  Assume the sensor has a single source pad #0. */\n+\tV4L2SubdeviceFormat subdevFormat;\n+\tsubdev_->getFormat(0, &subdevFormat);\n+\n+\tconst ControlInfoMap &subdevControlsInfo = subdev_->controls();\n+\n+\t/*\n+\t * Compute controls::ExposureTime limits by using line length and pixel\n+\t * rate converted to microseconds. Use the V4L2_CID_EXPOSURE control to\n+\t * get exposure min, max and default and convert it from lines to\n+\t * microseconds.\n+\t */\n+\tuint32_t lineLength = subdevFormat.size.width + hblank;\n+\tdouble lineDuration = lineLength / (pixelRate / 1000000.0F);\n+\tauto &[expId, v4l2Exposure] = *subdevControlsInfo.find(V4L2_CID_EXPOSURE);\n+\tint32_t minExposure = v4l2Exposure.min().get<int32_t>() * lineDuration;\n+\tint32_t maxExposure = v4l2Exposure.max().get<int32_t>() * lineDuration;\n+\tint32_t defExposure = v4l2Exposure.def().get<int32_t>() * lineDuration;\n+\n+\tcontrolsMap[&controls::internal::ExposureTime] =\n+\t\tControlInfo(minExposure, maxExposure, defExposure);\n+\n+\t/*\n+\t * Compute the frame duration limits.\n+\t *\n+\t * The frame length is computed assuming a fixed line length combined\n+\t * with the vertical frame sizes.\n+\t */\n+\tauto &[vblankId, v4l2VBlank] = *subdevControlsInfo.find(V4L2_CID_VBLANK);\n+\tstd::array<uint32_t, 3> frameHeights{\n+\t\tv4l2VBlank.min().get<int32_t>() + subdevFormat.size.height,\n+\t\tv4l2VBlank.max().get<int32_t>() + subdevFormat.size.height,\n+\t\tv4l2VBlank.def().get<int32_t>() + subdevFormat.size.height,\n+\t};\n+\n+\tstd::array<int64_t, 3> frameDurations;\n+\tfor (unsigned int i = 0; i < frameHeights.size(); ++i) {\n+\t\tuint64_t frameSize = lineLength * frameHeights[i];\n+\t\tframeDurations[i] = frameSize / (pixelRate / 1000000.0F);\n+\t}\n+\n+\tcontrolsMap[&controls::internal::FrameDuration] =\n+\t\tControlInfo(frameDurations[0], frameDurations[1], frameDurations[2]);\n+\n+\t/*\n+\t * For analogue gain collect the raw V4L2 control values which express\n+\t * the gain codes as seen from the sensor and need to be translated\n+\t * on the IPA side.\n+\t *\n+\t * \\todo Translate it by using a CameraSensorHelper.\n+\t */\n+\tauto &[gainId, v4l2AGain] = *subdevControlsInfo.find(V4L2_CID_ANALOGUE_GAIN);\n+\tcontrolsMap[&controls::internal::draft::SensorAnalogueGain] =\n+\t\tControlInfo(v4l2AGain.min().get<int32_t>(),\n+\t\t\t    v4l2AGain.max().get<int32_t>(),\n+\t\t\t    v4l2AGain.def().get<int32_t>());\n+\n+\tcontrols_ = ControlInfoMap(std::move(controlsMap),\n+\t\t\t\t   controls::internal::controls);\n+\n+\treturn 0;\n+}\n+\n /**\n  * \\brief Check for and initialise any ancillary devices\n  *\n@@ -837,6 +919,12 @@ int CameraSensor::setV4L2Controls(ControlList *ctrls)\n  * \\return The list of camera sensor properties\n  */\n \n+/**\n+ * \\fn CameraSensor::controls()\n+ * \\brief Retrieve the map of the camera sensor controls limits\n+ * \\return The map of camera sensor control information\n+ */\n+\n /**\n  * \\brief Assemble and return the camera sensor info\n  * \\param[out] info The camera sensor info\n@@ -932,6 +1020,7 @@ int CameraSensor::sensorInfo(IPACameraSensorInfo *info) const\n void CameraSensor::updateControlInfo()\n {\n \tsubdev_->updateControlInfo();\n+\tupdateControls();\n }\n \n /**\ndiff --git a/src/libcamera/internal_control_ids.yaml b/src/libcamera/internal_control_ids.yaml\nindex e69e0d30657c..c6e6bd111cf7 100644\n--- a/src/libcamera/internal_control_ids.yaml\n+++ b/src/libcamera/internal_control_ids.yaml\n@@ -9,6 +9,16 @@\n \n controls:\n \n+  - ExposureTime:\n+      type: int32_t\n+      description: |\n+        The sensor exposure time in milliseconds.\n+\n+  - FrameDuration:\n+      type: int64_t\n+      description: |\n+        The sensor frame duration time in milliseconds.\n+\n   # ----------------------------------------------------------------------------\n   # Draft controls section\n \n",
    "prefixes": [
        "libcamera-devel",
        "08/15"
    ]
}