Patch Detail
Show a patch.
GET /api/patches/21269/?format=api
{ "id": 21269, "url": "https://patchwork.libcamera.org/api/patches/21269/?format=api", "web_url": "https://patchwork.libcamera.org/patch/21269/", "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": "<01020191f6184753-fa7f549e-0b7c-4f7a-9bcf-c9389c9f6fd1-000000@eu-west-1.amazonses.com>", "date": "2024-09-15T14:31:11", "name": "[v3] libcamera: pipeline: uvcvideo: Map focus controls", "commit_ref": null, "pull_url": null, "state": "superseded", "archived": false, "hash": "54efe336ce45387da3b954981c4f7324c61bad49", "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/21269/mbox/", "series": [ { "id": 4596, "url": "https://patchwork.libcamera.org/api/series/4596/?format=api", "web_url": "https://patchwork.libcamera.org/project/libcamera/list/?series=4596", "date": "2024-09-15T14:31:11", "name": "[v3] libcamera: pipeline: uvcvideo: Map focus controls", "version": 3, "mbox": "https://patchwork.libcamera.org/series/4596/mbox/" } ], "comments": "https://patchwork.libcamera.org/api/patches/21269/comments/", "check": "pending", "checks": "https://patchwork.libcamera.org/api/patches/21269/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 CA93FC324C\n\tfor <parsemail@patchwork.libcamera.org>;\n\tSun, 15 Sep 2024 14:31:15 +0000 (UTC)", "from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id 4E2B4634FC;\n\tSun, 15 Sep 2024 16:31:14 +0200 (CEST)", "from a7-19.smtp-out.eu-west-1.amazonses.com\n\t(a7-19.smtp-out.eu-west-1.amazonses.com [54.240.7.19])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id A8BB3634F4\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tSun, 15 Sep 2024 16:31:12 +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=\"FLXlWQV0\"; dkim=pass (1024-bit key;\n\tunprotected) header.d=amazonses.com header.i=@amazonses.com\n\theader.b=\"MS/cOchO\"; dkim-atps=neutral", "DKIM-Signature": [ "v=1; a=rsa-sha256; q=dns/txt; c=relaxed/simple;\n\ts=4ymqmigrodjwq5luewph2eedidgwlpqq; d=makewise.pt; t=1726410672;\n\th=From:To:Cc:Subject:Date:Message-Id:MIME-Version:Content-Type:Content-Transfer-Encoding;\n\tbh=iDFSTNnUYEk1/+j3ZEtc+GCdKO/AFUXH2UVmfKFukLw=;\n\tb=FLXlWQV0jo2LPLZvP+HGTRI4ZcsrnpCQQHQtcomn1Z6n8iP/DUaC+hQgFPlu8YjV\n\tRs94gheKxn8IY5+0KTE2QU52iDTAK583FqMpoECpoPqPrhQlkF/dxB4QV2MyBW3rb+Q\n\tBCxDf2qW3Av1hFgtBqpTB4wH64h+wgA7yNIXf/4UeYcLzGDrfToqx11YGGZx8KuRx06\n\tnWO93OfCUMzceEaaci7fnQHVKDQ7bO4PzMAywqxTUv3OqKKCPN7ITHN/QB3v019PBG7\n\tn2CKYwt0vBjLAlogcJ46T8pzTbwp3Yv23KAWxlKSgp2E1D4zx5XhLU5ynm0/LCsJMLn\n\tiVrWowU4zQ==", "v=1; a=rsa-sha256; q=dns/txt; c=relaxed/simple;\n\ts=uku4taia5b5tsbglxyj6zym32efj7xqv; d=amazonses.com; t=1726410672;\n\th=From:To:Cc:Subject:Date:Message-Id:MIME-Version:Content-Type:Content-Transfer-Encoding:Feedback-ID;\n\tbh=iDFSTNnUYEk1/+j3ZEtc+GCdKO/AFUXH2UVmfKFukLw=;\n\tb=MS/cOchOlRG/0/UNhk0bQq0Uue7OOORzL6a+vAarxfc7x9hTaJaiwKS+c7NRKEfy\n\toO5+xuHnJAshGKyFSIMUchgWOvK4/nQRdIMP8N8kUBu9g/RlVW2F4scg7Uu2vHGh7ZQ\n\tyNYnw5D0SLZ1MN0xYklDcHq2r2aT+MenICzKGPx0=" ], "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: Map focus controls", "Date": "Sun, 15 Sep 2024 14:31:11 +0000", "Message-ID": "<01020191f6184753-fa7f549e-0b7c-4f7a-9bcf-c9389c9f6fd1-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.19", "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": "Added mapping of controls::LensPosition and controls::AfMode to\nv4l2 controls V4L2_CID_FOCUS_ABSOLUTE and V4L2_CID_FOCUS_AUTO\nrespectively when the device supports them.\n\nIf not supported, they are not registered.\n\nSigned-off-by: Cláudio Paulo <claudio.paulo@makewise.pt>\n---\nFixed more issues raised in review.\n\n src/libcamera/pipeline/uvcvideo/uvcvideo.cpp | 97 ++++++++++++++++++--\n 1 file changed, 91 insertions(+), 6 deletions(-)", "diff": "diff --git a/src/libcamera/pipeline/uvcvideo/uvcvideo.cpp b/src/libcamera/pipeline/uvcvideo/uvcvideo.cpp\nindex 6b32fa18..401d3052 100644\n--- a/src/libcamera/pipeline/uvcvideo/uvcvideo.cpp\n+++ b/src/libcamera/pipeline/uvcvideo/uvcvideo.cpp\n@@ -304,13 +304,26 @@ int PipelineHandlerUVC::processControl(ControlList *controls, unsigned int id,\n \t\tcid = V4L2_CID_EXPOSURE_ABSOLUTE;\n \telse if (id == controls::AnalogueGain)\n \t\tcid = V4L2_CID_GAIN;\n+\telse if (id == controls::LensPosition)\n+\t\tcid = V4L2_CID_FOCUS_ABSOLUTE;\n+\telse if (id == controls::AfMode)\n+\t\tcid = V4L2_CID_FOCUS_AUTO;\n \telse\n \t\treturn -EINVAL;\n \n+\t/* Check if the device supports this control. */\n+\tif (controls->idMap()->find(cid) == controls->idMap()->end())\n+\t\treturn -EINVAL;\n+\n \tconst ControlInfo &v4l2Info = controls->infoMap()->at(cid);\n-\tint32_t min = v4l2Info.min().get<int32_t>();\n-\tint32_t def = v4l2Info.def().get<int32_t>();\n-\tint32_t max = v4l2Info.max().get<int32_t>();\n+\n+\tint32_t min = -1, def = -1, max = -1;\n+\tif (v4l2Info.min().type() == ControlTypeInteger32)\n+\t\tmin = v4l2Info.min().get<int32_t>();\n+\tif (v4l2Info.min().type() == ControlTypeInteger32)\n+\t\tdef = v4l2Info.def().get<int32_t>();\n+\tif (v4l2Info.min().type() == ControlTypeInteger32)\n+\t\tmax = v4l2Info.max().get<int32_t>();\n \n \t/*\n \t * See UVCCameraData::addControl() for explanations of the different\n@@ -358,6 +371,21 @@ int PipelineHandlerUVC::processControl(ControlList *controls, unsigned int id,\n \t\tbreak;\n \t}\n \n+\tcase V4L2_CID_FOCUS_ABSOLUTE: {\n+\t\tfloat focusedAt50Cm = 0.15f * (max - min);\n+\t\tfloat scale = focusedAt50Cm / 2.0f;\n+\n+\t\tfloat fvalue = value.get<float>() * scale + min;\n+\t\tcontrols->set(cid, static_cast<int32_t>(lroundf(fvalue)));\n+\t\tbreak;\n+\t}\n+\n+\tcase V4L2_CID_FOCUS_AUTO: {\n+\t\tint32_t ivalue = value.get<int32_t>() != controls::AfModeManual;\n+\t\tcontrols->set(cid, ivalue);\n+\t\tbreak;\n+\t}\n+\n \tdefault: {\n \t\tint32_t ivalue = value.get<int32_t>();\n \t\tcontrols->set(cid, ivalue);\n@@ -655,14 +683,32 @@ void UVCCameraData::addControl(uint32_t cid, const ControlInfo &v4l2Info,\n \tcase V4L2_CID_GAIN:\n \t\tid = &controls::AnalogueGain;\n \t\tbreak;\n+\tcase V4L2_CID_FOCUS_ABSOLUTE:\n+\t\tid = &controls::LensPosition;\n+\t\tbreak;\n+\tcase V4L2_CID_FOCUS_AUTO:\n+\t\tid = &controls::AfMode;\n+\t\tbreak;\n \tdefault:\n \t\treturn;\n \t}\n \n \t/* Map the control info. */\n-\tint32_t min = v4l2Info.min().get<int32_t>();\n-\tint32_t max = v4l2Info.max().get<int32_t>();\n-\tint32_t def = v4l2Info.def().get<int32_t>();\n+\tint32_t min = -1, def = -1, max = -1;\n+\tif (v4l2Info.min().type() == ControlTypeInteger32)\n+\t\tmin = v4l2Info.min().get<int32_t>();\n+\telse if (v4l2Info.min().type() == ControlTypeBool)\n+\t\tmin = v4l2Info.min().get<bool>();\n+\n+\tif (v4l2Info.def().type() == ControlTypeInteger32)\n+\t\tdef = v4l2Info.def().get<int32_t>();\n+\telse if (v4l2Info.def().type() == ControlTypeBool)\n+\t\tdef = v4l2Info.def().get<bool>();\n+\n+\tif (v4l2Info.max().type() == ControlTypeInteger32)\n+\t\tmax = v4l2Info.max().get<int32_t>();\n+\telse if (v4l2Info.max().type() == ControlTypeBool)\n+\t\tmax = v4l2Info.max().get<bool>();\n \n \tswitch (cid) {\n \tcase V4L2_CID_BRIGHTNESS: {\n@@ -738,6 +784,45 @@ void UVCCameraData::addControl(uint32_t cid, const ControlInfo &v4l2Info,\n \t\t};\n \t\tbreak;\n \t}\n+\tcase V4L2_CID_FOCUS_ABSOLUTE: {\n+\t\t/*\n+\t\t * LensPosition expects values to be in the range of\n+\t\t * [0.0f, maxDioptres], while a value of 0 means focused to\n+\t\t * infinity, 0.5 means focused at 2m, 2 means focused at 50cm\n+\t\t * and maxDioptres will be the closest possible focus which\n+\t\t * will equate to a focus distance of (1 / maxDioptres) metres.\n+\t\t *\n+\t\t * \\todo These values will definitely vary for each different\n+\t\t * hardware, so this should be tunable somehow. In this case\n+\t\t * 0.15f (~= 150 / (1023 - 1)) was a value read from\n+\t\t * V4L2_CID_FOCUS_ABSOLUTE control when using a random camera\n+\t\t * and having it autofocus at a distance of about 50cm.\n+\t\t * This means the minimum focus distance of this camera should\n+\t\t * be 75mm (0.15 / 2) which equals a maxDioptres value of ~=\n+\t\t * 13.3333 (2 / 0.15). Also, the values might not scale\n+\t\t * linearly, but this implementation assumes they do.\n+\t\t */\n+\t\tfloat focusedAt50Cm = 0.15f * (max - min);\n+\t\tfloat scale = 2.0f / focusedAt50Cm;\n+\n+\t\tinfo = ControlInfo{\n+\t\t\t{ 0.0f },\n+\t\t\t{ (max - min) * scale },\n+\t\t\t{ (def - min) * scale }\n+\t\t};\n+\t\tbreak;\n+\t}\n+\tcase V4L2_CID_FOCUS_AUTO: {\n+\t\tint32_t manual = controls::AfModeManual;\n+\t\tint32_t continuous = controls::AfModeContinuous;\n+\n+\t\tinfo = ControlInfo{\n+\t\t\t{ manual },\n+\t\t\t{ continuous },\n+\t\t\t{ def ? continuous : manual },\n+\t\t};\n+\t\tbreak;\n+\t}\n \n \tdefault:\n \t\tinfo = v4l2Info;\n", "prefixes": [ "v3" ] }