Show a patch.

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

{
    "id": 21268,
    "url": "https://patchwork.libcamera.org/api/patches/21268/?format=api",
    "web_url": "https://patchwork.libcamera.org/patch/21268/",
    "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": "<01020191f2bd3860-8a479d82-2724-43c0-895c-779c826ef28a-000000@eu-west-1.amazonses.com>",
    "date": "2024-09-14T22:52:52",
    "name": "[v3] libcamera: pipeline: uvcvideo: Retrieve v4l2 device control information",
    "commit_ref": null,
    "pull_url": null,
    "state": "superseded",
    "archived": false,
    "hash": "b034227dc6b38485a6282b7635b0be9e3f34d769",
    "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/21268/mbox/",
    "series": [
        {
            "id": 4595,
            "url": "https://patchwork.libcamera.org/api/series/4595/?format=api",
            "web_url": "https://patchwork.libcamera.org/project/libcamera/list/?series=4595",
            "date": "2024-09-14T22:52:52",
            "name": "[v3] libcamera: pipeline: uvcvideo: Retrieve v4l2 device control information",
            "version": 3,
            "mbox": "https://patchwork.libcamera.org/series/4595/mbox/"
        }
    ],
    "comments": "https://patchwork.libcamera.org/api/patches/21268/comments/",
    "check": "pending",
    "checks": "https://patchwork.libcamera.org/api/patches/21268/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 46050C324C\n\tfor <parsemail@patchwork.libcamera.org>;\n\tSat, 14 Sep 2024 22:52:56 +0000 (UTC)",
            "from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id 325B0634F5;\n\tSun, 15 Sep 2024 00:52:55 +0200 (CEST)",
            "from a7-11.smtp-out.eu-west-1.amazonses.com\n\t(a7-11.smtp-out.eu-west-1.amazonses.com [54.240.7.11])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id 86960634E3\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tSun, 15 Sep 2024 00:52:53 +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=\"i9swKfyJ\"; dkim=pass (1024-bit key;\n\tunprotected) header.d=amazonses.com header.i=@amazonses.com\n\theader.b=\"UiX8nbwj\"; dkim-atps=neutral",
        "DKIM-Signature": [
            "v=1; a=rsa-sha256; q=dns/txt; c=relaxed/simple;\n\ts=4ymqmigrodjwq5luewph2eedidgwlpqq; d=makewise.pt; t=1726354372;\n\th=From:To:Cc:Subject:Date:Message-Id:MIME-Version:Content-Type:Content-Transfer-Encoding;\n\tbh=SX/Fo0JhDJZ6NzewaEd+ogo1eCyRm2le2L4DPudORlY=;\n\tb=i9swKfyJG6ykgviPQaFzlhtYjTOQEjZAqtzOfATnsaeLTgtREOdEWtZsgCHrRLik\n\t5dDs/QjyZe9kKJVYZo5tOwoPWkTfwsTYVqU9IwoVONoQgqYiGH/5hEPD97ba3w6ckPA\n\tY/BRWHu+aSqT0CfqNV6PQXfrP85xKvhlHA3uN6Pk3m4xER3R1yiqKV3RnARjc+9d4nE\n\tkULuKpNRaesAbvFpQYu6ciyx/m9l7mZZKYVgcisyFvUB+gsbrsLG/lGUa+M6nZ8R0Yg\n\tV8AnIpSGR1t/h5ZQb649DT0OsITvjsloZ5PMAJCuGJ6ZLqw3qQaTYSSLpjSjjd2LRAl\n\tZHe72+2gxQ==",
            "v=1; a=rsa-sha256; q=dns/txt; c=relaxed/simple;\n\ts=uku4taia5b5tsbglxyj6zym32efj7xqv; d=amazonses.com; t=1726354372;\n\th=From:To:Cc:Subject:Date:Message-Id:MIME-Version:Content-Type:Content-Transfer-Encoding:Feedback-ID;\n\tbh=SX/Fo0JhDJZ6NzewaEd+ogo1eCyRm2le2L4DPudORlY=;\n\tb=UiX8nbwjC1KZ1pkxY79BGLD2gLBjPKi+m8SryvzBCFczzWAbgSr3btlBfuWllYSl\n\tmQGPF5TVkJczKfX5UL7/mLYsEClhIXNrFcuI2UmwFaOfTxhU5SbbxZlkbutk80eoRHb\n\tgbC8YFGjAgnZK01k+R7hszKa9QYxI1C27RZGpt1s="
        ],
        "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 v3] libcamera: pipeline: uvcvideo: Retrieve v4l2 device\n\tcontrol information",
        "Date": "Sat, 14 Sep 2024 22:52:52 +0000",
        "Message-ID": "<01020191f2bd3860-8a479d82-2724-43c0-895c-779c826ef28a-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.14-54.240.7.11",
        "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 reported on a distinct patch.\n\n src/libcamera/pipeline/uvcvideo/uvcvideo.cpp | 112 ++++++++++++++++++-\n 1 file changed, 108 insertions(+), 4 deletions(-)",
    "diff": "diff --git a/src/libcamera/pipeline/uvcvideo/uvcvideo.cpp b/src/libcamera/pipeline/uvcvideo/uvcvideo.cpp\nindex 6b32fa18..6313e9e0 100644\n--- a/src/libcamera/pipeline/uvcvideo/uvcvideo.cpp\n+++ b/src/libcamera/pipeline/uvcvideo/uvcvideo.cpp\n@@ -333,8 +333,8 @@ int PipelineHandlerUVC::processControl(ControlList *controls, unsigned int id,\n \n \tcase V4L2_CID_EXPOSURE_AUTO: {\n \t\tint32_t ivalue = value.get<bool>()\n-\t\t\t       ? V4L2_EXPOSURE_APERTURE_PRIORITY\n-\t\t\t       : V4L2_EXPOSURE_MANUAL;\n+\t\t\t\t\t ? V4L2_EXPOSURE_APERTURE_PRIORITY\n+\t\t\t\t\t : V4L2_EXPOSURE_MANUAL;\n \t\tcontrols->set(V4L2_CID_EXPOSURE_AUTO, ivalue);\n \t\tbreak;\n \t}\n@@ -750,10 +750,114 @@ 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\tint ivalue = (value.get<int32_t>() - def) / scale;\n+\t\t\tmetadata->set(controls::Brightness, ivalue);\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\tmetadata->set(controls::Saturation,\n+\t\t\t\t      (value.get<int32_t>() - min) / scale);\n+\t\t\tbreak;\n+\t\t}\n+\n+\t\tcase V4L2_CID_EXPOSURE_AUTO: {\n+\t\t\tint32_t ivalue = value.get<int32_t>();\n+\t\t\tif (ivalue == V4L2_EXPOSURE_APERTURE_PRIORITY)\n+\t\t\t\tmetadata->set(controls::AeEnable, true);\n+\t\t\telse if (ivalue == V4L2_EXPOSURE_MANUAL)\n+\t\t\t\tmetadata->set(controls::AeEnable, false);\n+\t\t\tbreak;\n+\t\t}\n+\n+\t\tcase V4L2_CID_EXPOSURE_ABSOLUTE:\n+\t\t\tmetadata->set(controls::ExposureTime,\n+\t\t\t\t      value.get<int32_t>() * 100);\n+\t\t\tbreak;\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\tmetadata->set(controls::LensPosition,\n+\t\t\t\t      (value.get<int32_t>() - min) * scale);\n+\t\t\tbreak;\n+\t\t}\n+\n+\t\tcase V4L2_CID_FOCUS_AUTO: {\n+\t\t\tmetadata->set(controls::AfMode,\n+\t\t\t\t      value.get<int32_t>() == 0\n+\t\t\t\t\t      ? controls::AfModeManual\n+\t\t\t\t\t      : controls::AfModeContinuous);\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": [
        "v3"
    ]
}