Show a patch.

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

{
    "id": 16466,
    "url": "https://patchwork.libcamera.org/api/1.1/patches/16466/?format=api",
    "web_url": "https://patchwork.libcamera.org/patch/16466/",
    "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": "<20220630133902.321099-9-jacopo@jmondi.org>",
    "date": "2022-06-30T13:38:47",
    "name": "[libcamera-devel,v3,08/23] libcamera: camera_sensor: Initialize controls",
    "commit_ref": null,
    "pull_url": null,
    "state": "not-applicable",
    "archived": true,
    "hash": "3b1ae757cf0c63434edc086589fb04afc9b900bd",
    "submitter": {
        "id": 3,
        "url": "https://patchwork.libcamera.org/api/1.1/people/3/?format=api",
        "name": "Jacopo Mondi",
        "email": "jacopo@jmondi.org"
    },
    "delegate": null,
    "mbox": "https://patchwork.libcamera.org/patch/16466/mbox/",
    "series": [
        {
            "id": 3238,
            "url": "https://patchwork.libcamera.org/api/1.1/series/3238/?format=api",
            "web_url": "https://patchwork.libcamera.org/project/libcamera/list/?series=3238",
            "date": "2022-06-30T13:38:39",
            "name": "Internal controls, sensor delays and IPA rework",
            "version": 3,
            "mbox": "https://patchwork.libcamera.org/series/3238/mbox/"
        }
    ],
    "comments": "https://patchwork.libcamera.org/api/patches/16466/comments/",
    "check": "pending",
    "checks": "https://patchwork.libcamera.org/api/patches/16466/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 C6B2CC3279\n\tfor <parsemail@patchwork.libcamera.org>;\n\tThu, 30 Jun 2022 13:39:33 +0000 (UTC)",
            "from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id B38116569F;\n\tThu, 30 Jun 2022 15:39:32 +0200 (CEST)",
            "from relay1-d.mail.gandi.net (relay1-d.mail.gandi.net\n\t[217.70.183.193])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id 91EC465657\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tThu, 30 Jun 2022 15:39:28 +0200 (CEST)",
            "(Authenticated sender: jacopo@jmondi.org)\n\tby mail.gandi.net (Postfix) with ESMTPSA id A59BA24000E;\n\tThu, 30 Jun 2022 13:39:27 +0000 (UTC)"
        ],
        "DKIM-Signature": "v=1; a=rsa-sha256; c=relaxed/simple; d=libcamera.org;\n\ts=mail; t=1656596372;\n\tbh=D4LZqFIaG7h5yKFiw2jMPZjigf1V/xSbPCU74OIl17I=;\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=e9AaHM0wf+KNb/1RxUSkPgxKf1kaJHLwMmSWLzsvGIbEF1KMMiXfVOoJaRTv4AHvo\n\tpSzIBSFYyJ4JgppWfoP+fbwyiFEw3JIRF6zmyM7hrDrgU7/ZyE2JrWh7oV/i6LFbJu\n\t6WZ7nPnGmICMUgvyAPJ+YgblMQ5LDV3mzvPIMwqGnjD0wvqIfTOe/8d4wm4wpcgVR1\n\txVGyZnHgFF20aXyYqS5CRTH7YiDpNRQQwCgl/bCYDrnFvScTgqsG2rzYEzrJyD9uDp\n\tDrdGj6NUkCE6uXiKD0XidpY0iDPzgy9QckELT1wUkjpM8i/4+RWgfaYJu3eK4R5gUR\n\t1bG8ST3im/5qg==",
        "To": "libcamera-devel@lists.libcamera.org",
        "Date": "Thu, 30 Jun 2022 15:38:47 +0200",
        "Message-Id": "<20220630133902.321099-9-jacopo@jmondi.org>",
        "X-Mailer": "git-send-email 2.36.1",
        "In-Reply-To": "<20220630133902.321099-1-jacopo@jmondi.org>",
        "References": "<20220630133902.321099-1-jacopo@jmondi.org>",
        "MIME-Version": "1.0",
        "Content-Transfer-Encoding": "8bit",
        "Subject": "[libcamera-devel] [PATCH v3 08/23] 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 controls::internal::AnalogueGain.\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/camera_sensor.cpp | 90 +++++++++++++++++++\n 2 files changed, 93 insertions(+)",
    "diff": "diff --git a/include/libcamera/internal/camera_sensor.h b/include/libcamera/internal/camera_sensor.h\nindex 2a850dedc0aa..1eab5e9d53f0 100644\n--- a/include/libcamera/internal/camera_sensor.h\n+++ b/include/libcamera/internal/camera_sensor.h\n@@ -63,6 +63,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@@ -81,6 +82,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@@ -104,6 +106,7 @@ private:\n \tconst BayerFormat *bayerFormat_;\n \n \tControlList properties_;\n+\tControlInfoMap controls_;\n \n \tstd::unique_ptr<CameraLens> focusLens_;\n \tstd::unique_ptr<CameraSensorHelper> helper_;\ndiff --git a/src/libcamera/camera_sensor/camera_sensor.cpp b/src/libcamera/camera_sensor/camera_sensor.cpp\nindex 26cfa7d0f65a..976d34aaf876 100644\n--- a/src/libcamera/camera_sensor/camera_sensor.cpp\n+++ b/src/libcamera/camera_sensor/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 \t\treturn -ENODEV;\n \t}\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,84 @@ 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+\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+\tconst ControlInfo &v4l2Exposure = subdevControlsInfo.at(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+\tconst ControlInfo &v4l2VBlank = subdevControlsInfo.at(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 * Analogue gain values.\n+\t *\n+\t * Translate the V4L2 analogue gain, expressed in sensor-specific\n+\t * gain codes, and translate them to analogue gain values.\n+\t *\n+\t * \\todo: CameraSensorHelper returns a double; there's no ControlValue\n+\t * overload for the double type.\n+\t */\n+\tconst ControlInfo &v4l2AGain = subdevControlsInfo.at(V4L2_CID_ANALOGUE_GAIN);\n+\tcontrolsMap[&controls::internal::AnalogueGain] =\n+\t\tControlInfo(static_cast<float>(helper_->gain(v4l2AGain.min().get<int32_t>())),\n+\t\t\t    static_cast<float>(helper_->gain(v4l2AGain.max().get<int32_t>())),\n+\t\t\t    static_cast<float>(helper_->gain(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@@ -815,6 +898,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@@ -910,6 +999,7 @@ int CameraSensor::sensorInfo(IPACameraSensorInfo *info) const\n void CameraSensor::updateControlInfo()\n {\n \tsubdev_->updateControlInfo();\n+\tupdateControls();\n }\n \n /**\n",
    "prefixes": [
        "libcamera-devel",
        "v3",
        "08/23"
    ]
}