Show a patch.

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

{
    "id": 21270,
    "url": "https://patchwork.libcamera.org/api/patches/21270/?format=api",
    "web_url": "https://patchwork.libcamera.org/patch/21270/",
    "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": "<01020191f61a4608-322d1924-5c78-4e1e-93fc-a8d715af8c83-000000@eu-west-1.amazonses.com>",
    "date": "2024-09-15T14:33:22",
    "name": "[v4] libcamera: pipeline: uvcvideo: Retrieve v4l2 device control information",
    "commit_ref": null,
    "pull_url": null,
    "state": "new",
    "archived": false,
    "hash": "761e3624f02c08e282f8edff0cf61f3320368384",
    "submitter": {
        "id": 207,
        "url": "https://patchwork.libcamera.org/api/people/207/?format=api",
        "name": "Cláudio Paulo",
        "email": "claudio.paulo@makewise.pt"
    },
    "delegate": null,
    "mbox": "https://patchwork.libcamera.org/patch/21270/mbox/",
    "series": [
        {
            "id": 4597,
            "url": "https://patchwork.libcamera.org/api/series/4597/?format=api",
            "web_url": "https://patchwork.libcamera.org/project/libcamera/list/?series=4597",
            "date": "2024-09-15T14:33:22",
            "name": "[v4] libcamera: pipeline: uvcvideo: Retrieve v4l2 device control information",
            "version": 4,
            "mbox": "https://patchwork.libcamera.org/series/4597/mbox/"
        }
    ],
    "comments": "https://patchwork.libcamera.org/api/patches/21270/comments/",
    "check": "pending",
    "checks": "https://patchwork.libcamera.org/api/patches/21270/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 00675C324C\n\tfor <parsemail@patchwork.libcamera.org>;\n\tSun, 15 Sep 2024 14:33:26 +0000 (UTC)",
            "from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id EC825634F5;\n\tSun, 15 Sep 2024 16:33:25 +0200 (CEST)",
            "from a7-10.smtp-out.eu-west-1.amazonses.com\n\t(a7-10.smtp-out.eu-west-1.amazonses.com [54.240.7.10])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id 72F29634F4\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tSun, 15 Sep 2024 16:33:23 +0200 (CEST)"
        ],
        "Authentication-Results": "lancelot.ideasonboard.com; dkim=pass (2048-bit key;\n\tunprotected) header.d=makewise.pt header.i=@makewise.pt\n\theader.b=\"jcxCOPD7\"; dkim=pass (1024-bit key;\n\tunprotected) header.d=amazonses.com header.i=@amazonses.com\n\theader.b=\"dmktEO45\"; dkim-atps=neutral",
        "DKIM-Signature": [
            "v=1; a=rsa-sha256; q=dns/txt; c=relaxed/simple;\n\ts=4ymqmigrodjwq5luewph2eedidgwlpqq; d=makewise.pt; t=1726410802;\n\th=From:To:Cc:Subject:Date:Message-Id:MIME-Version:Content-Type:Content-Transfer-Encoding;\n\tbh=um5wbCeILzvMYQA1uSzoz2yUh5ugb3K+i3jCeJ8Ayjw=;\n\tb=jcxCOPD7oxFY3nWWWNLsvxNq+GeSiSJmfRIu9B4uuIhPrBpk7HSAmb3VRczZNFe2\n\twJPAlg6tOXgdchaXshjPfyhWj/PvF5J3KzJQrlhg0+g9fNgwuPlTDKz4W6NxbX2m3gP\n\tGqNI6aIKYkCAXRMR0HNnfH8OUJas/G6WZLGJiXAEKP2G7r4b3jgEQGJdBQMZ9akmxMo\n\tpuScsjUFBoko4E+RDa7VuSdKpzZ8XwzgecjivR0y3kO1ZAoCVwmhRd+P7LySBDkdyH3\n\tzdImBpi/1v9Uuex6+HN2yScsS/B8O0ePsFVqTP34hYh6CT8sQYBmc2aef/axDHEAOOM\n\tOC/WXb6ZYA==",
            "v=1; a=rsa-sha256; q=dns/txt; c=relaxed/simple;\n\ts=uku4taia5b5tsbglxyj6zym32efj7xqv; d=amazonses.com; t=1726410802;\n\th=From:To:Cc:Subject:Date:Message-Id:MIME-Version:Content-Type:Content-Transfer-Encoding:Feedback-ID;\n\tbh=um5wbCeILzvMYQA1uSzoz2yUh5ugb3K+i3jCeJ8Ayjw=;\n\tb=dmktEO456h+OrhgQ53cnKemDufo1p8btDLhe6Yk5f3BgKrdxDNU8YpJaVFVP+ia1\n\tcIXYUWW3hKwwbhpWrXXltHHslWGseui1T0vLCKWCOEdnBmR9sm6dXVlNgEXKs/c6HJQ\n\tncRGbS12krOtIn4XN4sy8QCVn6D6yKSsUU6FeZY0="
        ],
        "From": "=?utf-8?q?Cl=C3=A1udio_Paulo?= <claudio.paulo@makewise.pt>",
        "To": "libcamera-devel@lists.libcamera.org",
        "Cc": "=?utf-8?q?Cl=C3=A1udio_Paulo?= <claudio.paulo@makewise.pt>",
        "Subject": "[PATCH v4] libcamera: pipeline: uvcvideo: Retrieve v4l2 device\n\tcontrol information",
        "Date": "Sun, 15 Sep 2024 14:33:22 +0000",
        "Message-ID": "<01020191f61a4608-322d1924-5c78-4e1e-93fc-a8d715af8c83-000000@eu-west-1.amazonses.com>",
        "X-Mailer": "git-send-email 2.34.1",
        "MIME-Version": "1.0",
        "Content-Type": "text/plain; charset=UTF-8",
        "Content-Transfer-Encoding": "8bit",
        "Feedback-ID": "::1.eu-west-1.z8xjvhxVxUk+kM5mx7i/KMS/a2avhcAXFe/noI67NVQ=:AmazonSES",
        "X-SES-Outgoing": "2024.09.15-54.240.7.10",
        "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": "Populate frame metadata by using V4L2Device::getControls() to get\nthe values for all supported controls on each frame.\n\nSigned-off-by: Cláudio Paulo <claudio.paulo@makewise.pt>\n---\nFixed similar issues raised in review of a distinct patch.\n\n src/libcamera/pipeline/uvcvideo/uvcvideo.cpp | 106 ++++++++++++++++++-\n 1 file changed, 104 insertions(+), 2 deletions(-)",
    "diff": "diff --git a/src/libcamera/pipeline/uvcvideo/uvcvideo.cpp b/src/libcamera/pipeline/uvcvideo/uvcvideo.cpp\nindex 6b32fa18..e89884db 100644\n--- a/src/libcamera/pipeline/uvcvideo/uvcvideo.cpp\n+++ b/src/libcamera/pipeline/uvcvideo/uvcvideo.cpp\n@@ -750,10 +750,112 @@ void UVCCameraData::addControl(uint32_t cid, const ControlInfo &v4l2Info,\n void UVCCameraData::bufferReady(FrameBuffer *buffer)\n {\n \tRequest *request = buffer->request();\n+\tControlList *metadata = &request->metadata();\n \n \t/* \\todo Use the UVC metadata to calculate a more precise timestamp */\n-\trequest->metadata().set(controls::SensorTimestamp,\n-\t\t\t\tbuffer->metadata().timestamp);\n+\tmetadata->set(controls::SensorTimestamp, buffer->metadata().timestamp);\n+\n+\t/* Retrieve control as reported by the device. */\n+\tstd::vector<uint32_t> ids;\n+\tfor (const auto &[controlId, _] : video_->controls()) {\n+\t\tswitch (uint32_t cid = controlId->id()) {\n+\t\tcase V4L2_CID_BRIGHTNESS:\n+\t\tcase V4L2_CID_CONTRAST:\n+\t\tcase V4L2_CID_SATURATION:\n+\t\tcase V4L2_CID_EXPOSURE_AUTO:\n+\t\tcase V4L2_CID_EXPOSURE_ABSOLUTE:\n+\t\tcase V4L2_CID_GAIN:\n+\t\tcase V4L2_CID_FOCUS_ABSOLUTE:\n+\t\tcase V4L2_CID_FOCUS_AUTO:\n+\t\t\tids.push_back(cid);\n+\t\t\tbreak;\n+\t\tdefault:;\n+\t\t}\n+\t}\n+\n+\t/*\n+\t * See UVCCameraData::addControl() for explanations of the different\n+\t * value mappings.\n+\t */\n+\tControlList deviceControls = video_->getControls(ids);\n+\tfor (const auto &[cid, value] : deviceControls) {\n+\t\tControlInfo v4l2Info = video_->controls().at(cid);\n+\n+\t\tint32_t min = -1, def = -1, max = -1;\n+\t\tif (v4l2Info.min().type() == ControlTypeInteger32)\n+\t\t\tmin = v4l2Info.min().get<int32_t>();\n+\t\tif (v4l2Info.min().type() == ControlTypeInteger32)\n+\t\t\tdef = v4l2Info.def().get<int32_t>();\n+\t\tif (v4l2Info.min().type() == ControlTypeInteger32)\n+\t\t\tmax = v4l2Info.max().get<int32_t>();\n+\n+\t\tswitch (cid) {\n+\t\tcase V4L2_CID_BRIGHTNESS: {\n+\t\t\tfloat scale = std::max(max - def, def - min);\n+\n+\t\t\tfloat fvalue = (value.get<int32_t>() - def) / scale;\n+\t\t\tmetadata->set(controls::Brightness, fvalue);\n+\t\t\tbreak;\n+\t\t}\n+\n+\t\tcase V4L2_CID_GAIN:\n+\t\tcase V4L2_CID_CONTRAST: {\n+\t\t\tfloat m = (4.0f - 1.0f) / (max - def);\n+\t\t\tfloat p = 1.0f - m * def;\n+\n+\t\t\tif (m * min + p < 0.5f) {\n+\t\t\t\tm = (1.0f - 0.5f) / (def - min);\n+\t\t\t\tp = 1.0f - m * def;\n+\t\t\t}\n+\n+\t\t\tfloat fvalue = m * value.get<int32_t>() + p;\n+\t\t\tif (cid == V4L2_CID_GAIN)\n+\t\t\t\tmetadata->set(controls::AnalogueGain, fvalue);\n+\t\t\telse if (cid == V4L2_CID_CONTRAST)\n+\t\t\t\tmetadata->set(controls::Contrast, fvalue);\n+\t\t\tbreak;\n+\t\t}\n+\n+\t\tcase V4L2_CID_SATURATION: {\n+\t\t\tfloat scale = def - min;\n+\n+\t\t\tfloat fvalue = (value.get<int32_t>() - min) / scale;\n+\t\t\tmetadata->set(controls::Saturation, fvalue);\n+\t\t\tbreak;\n+\t\t}\n+\n+\t\tcase V4L2_CID_EXPOSURE_AUTO: {\n+\t\t\tbool bvalue = value.get<int32_t>() != V4L2_EXPOSURE_MANUAL;\n+\t\t\tmetadata->set(controls::AeEnable, bvalue);\n+\t\t\tbreak;\n+\t\t}\n+\n+\t\tcase V4L2_CID_EXPOSURE_ABSOLUTE: {\n+\t\t\tint32_t ivalue = value.get<int32_t>() * 100;\n+\t\t\tmetadata->set(controls::ExposureTime, ivalue);\n+\t\t\tbreak;\n+\t\t}\n+\n+\t\tcase V4L2_CID_FOCUS_ABSOLUTE: {\n+\t\t\tfloat focusedAt50Cm = 0.15f * (max - min);\n+\t\t\tfloat scale = 2.0f / focusedAt50Cm;\n+\n+\t\t\tfloat fvalue = (value.get<int32_t>() - min) * scale;\n+\t\t\tmetadata->set(controls::LensPosition, fvalue);\n+\t\t\tbreak;\n+\t\t}\n+\n+\t\tcase V4L2_CID_FOCUS_AUTO: {\n+\t\t\tuint32_t ivalue = value.get<int32_t>() == 0\n+\t\t\t\t\t? controls::AfModeManual\n+\t\t\t\t\t: controls::AfModeContinuous;\n+\t\t\tmetadata->set(controls::AfMode, ivalue);\n+\t\t\tbreak;\n+\t\t}\n+\n+\t\tdefault:;\n+\t\t}\n+\t}\n \n \tpipe()->completeBuffer(request, buffer);\n \tpipe()->completeRequest(request);\n",
    "prefixes": [
        "v4"
    ]
}