Patch Detail
Show a patch.
GET /api/1.1/patches/21264/?format=api
{ "id": 21264, "url": "https://patchwork.libcamera.org/api/1.1/patches/21264/?format=api", "web_url": "https://patchwork.libcamera.org/patch/21264/", "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": "<01020191ec67fb81-a9b3be00-461b-4814-a6bb-892404f7420f-000000@eu-west-1.amazonses.com>", "date": "2024-09-13T17:22:03", "name": "libcamera: pipeline: uvcvideo: Map focus controls", "commit_ref": null, "pull_url": null, "state": "superseded", "archived": false, "hash": "169f7fab0b2e528d4a510952aa00acd8977057f0", "submitter": { "id": 207, "url": "https://patchwork.libcamera.org/api/1.1/people/207/?format=api", "name": "Cláudio Paulo", "email": "claudio.paulo@makewise.pt" }, "delegate": null, "mbox": "https://patchwork.libcamera.org/patch/21264/mbox/", "series": [ { "id": 4591, "url": "https://patchwork.libcamera.org/api/1.1/series/4591/?format=api", "web_url": "https://patchwork.libcamera.org/project/libcamera/list/?series=4591", "date": "2024-09-13T17:22:03", "name": "libcamera: pipeline: uvcvideo: Map focus controls", "version": 1, "mbox": "https://patchwork.libcamera.org/series/4591/mbox/" } ], "comments": "https://patchwork.libcamera.org/api/patches/21264/comments/", "check": "pending", "checks": "https://patchwork.libcamera.org/api/patches/21264/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 12D30C3257\n\tfor <parsemail@patchwork.libcamera.org>;\n\tFri, 13 Sep 2024 17:31:30 +0000 (UTC)", "from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id 7EE21634F4;\n\tFri, 13 Sep 2024 19:31:28 +0200 (CEST)", "from a7-12.smtp-out.eu-west-1.amazonses.com\n\t(a7-12.smtp-out.eu-west-1.amazonses.com [54.240.7.12])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id 114A8634E3\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tFri, 13 Sep 2024 19:22:04 +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=\"MGBp1Gha\"; dkim=pass (1024-bit key;\n\tunprotected) header.d=amazonses.com header.i=@amazonses.com\n\theader.b=\"j+5i2+Pu\"; dkim-atps=neutral", "DKIM-Signature": [ "v=1; a=rsa-sha256; q=dns/txt; c=relaxed/simple;\n\ts=4ymqmigrodjwq5luewph2eedidgwlpqq; d=makewise.pt; t=1726248123;\n\th=From:To:Cc:Subject:Date:Message-Id:MIME-Version:Content-Type:Content-Transfer-Encoding;\n\tbh=JNQ8c3Ek95sIdioEgxD0pxBtdHdPC6snVfWSBO87c1w=;\n\tb=MGBp1GhaLKnr4q/ACcE0NKOFxN2c/OVSXR6BJSQCaf8HvCSWuAKAcjREBBJQRQvs\n\tiMNDqCyQ1wovW0PpbUakDd+93YwLlYLduPr5XDZY8GTLCKY25MagX1fiAsnKWTldvMd\n\tnzB8NI8IlMD6YE1/bD/EJ432RXnNK/eFBG9TVPYUSeQs4IpqUQcXLH02N4YwdSaz2Wh\n\trxIfEC7kwYBkV9B7aAmx4EoldmDjBluX1QMabN+wbtPf+B8BdLMYinHwfMYPpJYFFNR\n\tt7Phn+N+DIt4ixpU485NbN4paZdNNJipYEvHJvVD6De6KWNXYqw2opFqblvS6f9HaYG\n\tzHJiErGlwg==", "v=1; a=rsa-sha256; q=dns/txt; c=relaxed/simple;\n\ts=uku4taia5b5tsbglxyj6zym32efj7xqv; d=amazonses.com; t=1726248123;\n\th=From:To:Cc:Subject:Date:Message-Id:MIME-Version:Content-Type:Content-Transfer-Encoding:Feedback-ID;\n\tbh=JNQ8c3Ek95sIdioEgxD0pxBtdHdPC6snVfWSBO87c1w=;\n\tb=j+5i2+PuYyL3X08NkJRr8P731n6ziLkOI551ltiwHB+EiA3DUfQPgewDw3s+ZHRz\n\tc0Ic7446hbQP8/CiV+4C2hDClukswtFkHu4pjCozGnlZhted2CW2G1mr5SjKji4YiSO\n\tBCbWt/IOqkFODRQBkF+oaDTClIb1geDeYiHHpJR4=" ], "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] libcamera: pipeline: uvcvideo: Map focus controls", "Date": "Fri, 13 Sep 2024 17:22:03 +0000", "Message-ID": "<01020191ec67fb81-a9b3be00-461b-4814-a6bb-892404f7420f-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.13-54.240.7.12", "X-Mailman-Approved-At": "Fri, 13 Sep 2024 19:31:26 +0200", "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---\n include/linux/v4l2-controls.h | 4 +\n src/libcamera/pipeline/uvcvideo/uvcvideo.cpp | 88 +++++++++++++++++---\n 2 files changed, 82 insertions(+), 10 deletions(-)", "diff": "diff --git a/include/linux/v4l2-controls.h b/include/linux/v4l2-controls.h\nindex 882a8180..1ac85507 100644\n--- a/include/linux/v4l2-controls.h\n+++ b/include/linux/v4l2-controls.h\n@@ -994,6 +994,10 @@ enum v4l2_exposure_auto_type {\n #define V4L2_CID_FOCUS_ABSOLUTE\t\t\t(V4L2_CID_CAMERA_CLASS_BASE+10)\n #define V4L2_CID_FOCUS_RELATIVE\t\t\t(V4L2_CID_CAMERA_CLASS_BASE+11)\n #define V4L2_CID_FOCUS_AUTO\t\t\t(V4L2_CID_CAMERA_CLASS_BASE+12)\n+enum v4l2_focus_auto_type {\n+\tV4L2_FOCUS_MANUAL = 0,\n+\tV4L2_FOCUS_AUTO = 1\n+};\n \n #define V4L2_CID_ZOOM_ABSOLUTE\t\t\t(V4L2_CID_CAMERA_CLASS_BASE+13)\n #define V4L2_CID_ZOOM_RELATIVE\t\t\t(V4L2_CID_CAMERA_CLASS_BASE+14)\ndiff --git a/src/libcamera/pipeline/uvcvideo/uvcvideo.cpp b/src/libcamera/pipeline/uvcvideo/uvcvideo.cpp\nindex 6b32fa18..fe3c71d0 100644\n--- a/src/libcamera/pipeline/uvcvideo/uvcvideo.cpp\n+++ b/src/libcamera/pipeline/uvcvideo/uvcvideo.cpp\n@@ -304,13 +304,14 @@ 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 && controls->idMap()->count(V4L2_CID_FOCUS_ABSOLUTE)) // Check if device supports this control\n+\t\tcid = V4L2_CID_FOCUS_ABSOLUTE;\n+\telse if (id == controls::AfMode && controls->idMap()->count(V4L2_CID_FOCUS_AUTO)) // Check if device supports this control\n+\t\tcid = V4L2_CID_FOCUS_AUTO;\n \telse\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 \t/*\n \t * See UVCCameraData::addControl() for explanations of the different\n@@ -318,6 +319,10 @@ int PipelineHandlerUVC::processControl(ControlList *controls, unsigned int id,\n \t */\n \tswitch (cid) {\n \tcase V4L2_CID_BRIGHTNESS: {\n+\t\tint32_t min = v4l2Info.min().get<int32_t>();\n+\t\tint32_t def = v4l2Info.def().get<int32_t>();\n+\t\tint32_t max = v4l2Info.max().get<int32_t>();\n+\n \t\tfloat scale = std::max(max - def, def - min);\n \t\tfloat fvalue = value.get<float>() * scale + def;\n \t\tcontrols->set(cid, static_cast<int32_t>(lroundf(fvalue)));\n@@ -325,6 +330,9 @@ int PipelineHandlerUVC::processControl(ControlList *controls, unsigned int id,\n \t}\n \n \tcase V4L2_CID_SATURATION: {\n+\t\tint32_t min = v4l2Info.min().get<int32_t>();\n+\t\tint32_t def = v4l2Info.def().get<int32_t>();\n+\n \t\tfloat scale = def - min;\n \t\tfloat fvalue = value.get<float>() * scale + min;\n \t\tcontrols->set(cid, static_cast<int32_t>(lroundf(fvalue)));\n@@ -345,6 +353,10 @@ int PipelineHandlerUVC::processControl(ControlList *controls, unsigned int id,\n \n \tcase V4L2_CID_CONTRAST:\n \tcase V4L2_CID_GAIN: {\n+\t\tint32_t min = v4l2Info.min().get<int32_t>();\n+\t\tint32_t def = v4l2Info.def().get<int32_t>();\n+\t\tint32_t max = v4l2Info.max().get<int32_t>();\n+\n \t\tfloat m = (4.0f - 1.0f) / (max - def);\n \t\tfloat p = 1.0f - m * def;\n \n@@ -358,6 +370,22 @@ int PipelineHandlerUVC::processControl(ControlList *controls, unsigned int id,\n \t\tbreak;\n \t}\n \n+\tcase V4L2_CID_FOCUS_ABSOLUTE: {\n+\t\tint32_t min = v4l2Info.min().get<int32_t>();\n+\t\tint32_t max = v4l2Info.max().get<int32_t>();\n+\n+\t\tfloat focusedAt50Cm = 0.15f * (max - min);\n+\t\tfloat scale = focusedAt50Cm / 2.0f;\n+\n+\t\tcontrols->set(cid, static_cast<int>(min + value.get<float>() * scale));\n+\t\tbreak;\n+\t}\n+\n+\tcase V4L2_CID_FOCUS_AUTO: {\n+\t\tcontrols->set(cid, static_cast<int>(value.get<int>() == 0 ? V4L2_FOCUS_MANUAL : V4L2_FOCUS_AUTO));\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,17 @@ 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 \n \tswitch (cid) {\n \tcase V4L2_CID_BRIGHTNESS: {\n@@ -673,6 +704,9 @@ void UVCCameraData::addControl(uint32_t cid, const ControlInfo &v4l2Info,\n \t\t * Accommodate this by restricting the range of the libcamera\n \t\t * control, but always within the maximum limits.\n \t\t */\n+\t\tint32_t min = v4l2Info.min().get<int32_t>();\n+\t\tint32_t max = v4l2Info.max().get<int32_t>();\n+\t\tint32_t def = v4l2Info.def().get<int32_t>();\n \t\tfloat scale = std::max(max - def, def - min);\n \n \t\tinfo = ControlInfo{\n@@ -683,36 +717,42 @@ void UVCCameraData::addControl(uint32_t cid, const ControlInfo &v4l2Info,\n \t\tbreak;\n \t}\n \n-\tcase V4L2_CID_SATURATION:\n+\tcase V4L2_CID_SATURATION: {\n \t\t/*\n \t\t * The Saturation control is a float, with 0.0 mapped to the\n \t\t * minimum value (corresponding to a fully desaturated image)\n \t\t * and 1.0 mapped to the default value. Calculate the maximum\n \t\t * value accordingly.\n \t\t */\n+\t\tint32_t min = v4l2Info.min().get<int32_t>();\n+\t\tint32_t max = v4l2Info.max().get<int32_t>();\n+\t\tint32_t def = v4l2Info.def().get<int32_t>();\n \t\tinfo = ControlInfo{\n \t\t\t{ 0.0f },\n \t\t\t{ static_cast<float>(max - min) / (def - min) },\n \t\t\t{ 1.0f }\n \t\t};\n \t\tbreak;\n-\n+\t}\n \tcase V4L2_CID_EXPOSURE_AUTO:\n \t\tinfo = ControlInfo{ false, true, true };\n \t\tbreak;\n \n-\tcase V4L2_CID_EXPOSURE_ABSOLUTE:\n+\tcase V4L2_CID_EXPOSURE_ABSOLUTE: {\n \t\t/*\n \t\t * ExposureTime is in units of 1 µs, and UVC expects\n \t\t * V4L2_CID_EXPOSURE_ABSOLUTE in units of 100 µs.\n \t\t */\n+\t\tint32_t min = v4l2Info.min().get<int32_t>();\n+\t\tint32_t max = v4l2Info.max().get<int32_t>();\n+\t\tint32_t def = v4l2Info.def().get<int32_t>();\n \t\tinfo = ControlInfo{\n \t\t\t{ min * 100 },\n \t\t\t{ max * 100 },\n \t\t\t{ def * 100 }\n \t\t};\n \t\tbreak;\n-\n+\t}\n \tcase V4L2_CID_CONTRAST:\n \tcase V4L2_CID_GAIN: {\n \t\t/*\n@@ -723,6 +763,9 @@ void UVCCameraData::addControl(uint32_t cid, const ControlInfo &v4l2Info,\n \t\t * maximum values are respectively no lower than 0.5 and no\n \t\t * higher than 4.0.\n \t\t */\n+\t\tint32_t min = v4l2Info.min().get<int32_t>();\n+\t\tint32_t max = v4l2Info.max().get<int32_t>();\n+\t\tint32_t def = v4l2Info.def().get<int32_t>();\n \t\tfloat m = (4.0f - 1.0f) / (max - def);\n \t\tfloat p = 1.0f - m * def;\n \n@@ -738,6 +781,31 @@ 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\tint32_t min = v4l2Info.min().get<int32_t>();\n+\t\tint32_t max = v4l2Info.max().get<int32_t>();\n+\t\tint32_t def = v4l2Info.def().get<int32_t>();\n+\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{ scale * (max - min) },\n+\t\t\t{ scale * (def - min) }\n+\t\t};\n+\t\tbreak;\n+\t}\n+\tcase V4L2_CID_FOCUS_AUTO: {\n+\t\tbool def = v4l2Info.def().get<bool>();\n+\n+\t\tinfo = ControlInfo{\n+\t\t\t{ static_cast<int>(V4L2_FOCUS_MANUAL) },\n+\t\t\t{ static_cast<int>(V4L2_FOCUS_AUTO) },\n+\t\t\t{ static_cast<int>(def ? V4L2_FOCUS_AUTO : V4L2_FOCUS_MANUAL) },\n+\t\t};\n+\t\tbreak;\n+\t}\n \n \tdefault:\n \t\tinfo = v4l2Info;\n", "prefixes": [] }