Patch Detail
Show a patch.
GET /api/1.1/patches/18707/?format=api
{ "id": 18707, "url": "https://patchwork.libcamera.org/api/1.1/patches/18707/?format=api", "web_url": "https://patchwork.libcamera.org/patch/18707/", "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": "<20230605144405.118153-1-web@cedricnugteren.nl>", "date": "2023-06-05T14:44:05", "name": "[libcamera-devel,v2] Add enable_auto_focus option to the GStreamer plugin", "commit_ref": null, "pull_url": null, "state": "accepted", "archived": false, "hash": "1c2b556ee1492508e72ae2ed8dd847a0ce6c5af4", "submitter": { "id": 164, "url": "https://patchwork.libcamera.org/api/1.1/people/164/?format=api", "name": "Cedric Nugteren", "email": "cedric@plumerai.com" }, "delegate": null, "mbox": "https://patchwork.libcamera.org/patch/18707/mbox/", "series": [ { "id": 3908, "url": "https://patchwork.libcamera.org/api/1.1/series/3908/?format=api", "web_url": "https://patchwork.libcamera.org/project/libcamera/list/?series=3908", "date": "2023-06-05T14:44:05", "name": "[libcamera-devel,v2] Add enable_auto_focus option to the GStreamer plugin", "version": 2, "mbox": "https://patchwork.libcamera.org/series/3908/mbox/" } ], "comments": "https://patchwork.libcamera.org/api/patches/18707/comments/", "check": "pending", "checks": "https://patchwork.libcamera.org/api/patches/18707/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 E086DC3200\n\tfor <parsemail@patchwork.libcamera.org>;\n\tMon, 5 Jun 2023 14:44:23 +0000 (UTC)", "from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id 2934362885;\n\tMon, 5 Jun 2023 16:44:23 +0200 (CEST)", "from mail-ej1-x636.google.com (mail-ej1-x636.google.com\n\t[IPv6:2a00:1450:4864:20::636])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id 041EF62709\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tMon, 5 Jun 2023 16:44:20 +0200 (CEST)", "by mail-ej1-x636.google.com with SMTP id\n\ta640c23a62f3a-9741a0fd134so821294966b.0\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tMon, 05 Jun 2023 07:44:20 -0700 (PDT)", "from kaylee.home (177-83-201-31.ftth.glasoperator.nl.\n\t[31.201.83.177]) by smtp.gmail.com with ESMTPSA id\n\tl14-20020a170906a40e00b0095807ab4b57sm4411354ejz.178.2023.06.05.07.44.18\n\t(version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256);\n\tMon, 05 Jun 2023 07:44:19 -0700 (PDT)" ], "DKIM-Signature": [ "v=1; a=rsa-sha256; c=relaxed/simple; d=libcamera.org;\n\ts=mail; t=1685976263;\n\tbh=rqqbRaO7nccOGQ/j4gXQNPGkXYhwxjZBlZGAwGzoiCs=;\n\th=To:Date:Subject:List-Id:List-Unsubscribe:List-Archive:List-Post:\n\tList-Help:List-Subscribe:From:Reply-To:Cc:From;\n\tb=YWsV5Shwtvil1ypqbgt49RoZbnadHzVgShl7lE27rWMjG1VK4bJ3wXboFVCOqpiWn\n\tl+1Ejl5WiYuq+mYsoe3fDpKBKrrMjKXdUb0qTGZPz59XHIDlpItHLPNprxzAcGlQiX\n\tM7krGIsVON6Rc4phDKeJKg3/yaTz4ov8F5FFsuzb9I+rAWuYgGb7FJ7oU/XLCPS2rI\n\tXPW8XYfFSINO69ctY8GcteTuRHpF2KDwJmp0SrISjepfwD78r4mfG2/s1NxJvzV894\n\tEAMkwE4mGqMrErjMxly0m8vyAU0XCx3jOpZ709nkBBWiwWxpC5iwc9mhJyyD2pefna\n\tk5v5vNuS4TbOg==", "v=1; a=rsa-sha256; c=relaxed/relaxed;\n\td=plumerai.com; s=google; t=1685976260; x=1688568260;\n\th=content-transfer-encoding:mime-version:message-id:date:subject:cc\n\t:to:from:from:to:cc:subject:date:message-id:reply-to;\n\tbh=3O9eHJK+dlIDDJILhsTBYEYi7WkuOabyS+KFabAaOqU=;\n\tb=HDNYC0BHDqiUQe7f49eduk8TDBmUuMIweP7IC8rQd3Rvp7dP2x29Qh4T/Suse86yDz\n\tg3TAtIjdpYhea3pYFrlR7wiFNbmHWAGcRABaCevk9X6Iu48U200aRmK/Sf1Rqw50lvrC\n\tpKIo2ztYRhrtRZabON8chPkK88/krG0RT6/E4=" ], "Authentication-Results": "lancelot.ideasonboard.com; dkim=pass (1024-bit key; \n\tunprotected) header.d=plumerai.com\n\theader.i=@plumerai.com header.b=\"HDNYC0BH\"; \n\tdkim-atps=neutral", "X-Google-DKIM-Signature": "v=1; a=rsa-sha256; c=relaxed/relaxed;\n\td=1e100.net; s=20221208; t=1685976260; x=1688568260;\n\th=content-transfer-encoding:mime-version:message-id:date:subject:cc\n\t:to:from:x-gm-message-state:from:to:cc:subject:date:message-id\n\t:reply-to;\n\tbh=3O9eHJK+dlIDDJILhsTBYEYi7WkuOabyS+KFabAaOqU=;\n\tb=i9YQPKe26bf7H76GNnNYfZNE+r4Q8pqONHh9KLKeuvDwEYBbmM1cEIFhk63nLuI/pC\n\t0w8yGLh3wnMipu8cfZcYRNofiVDvIG1nbeNNNbKQwj1Sybn/WjiuP33BbFhDA9JE9Omd\n\t9kcRGBoHdne4rVKCh0e/VgasWG1AeDCOCjz+VC5U9uRF6RCw+DJcmqf3uRlj+DUKx+Mg\n\tbsjupC5rz7nvkVkCqB/Vnwb0ytr2ZiIJi8mO6WaLCZfEGGCg/4R1RqtB8gCcZJ/bXlwY\n\teWisjEfq6k1lZUJa2Fs+22Dr6V/0UR71EdHz0mFFV3BGngNfpnsKBNkVvH+ReK6fyDIX\n\t2q4A==", "X-Gm-Message-State": "AC+VfDyKY7FC92b131RKi1VtYv9z2tTkVP8cMQonrlwBOidIykfgjj2s\n\tylkK23g4DP02DrNUKsRsJrJnqDklfqahqkYW6Kg=", "X-Google-Smtp-Source": "ACHHUZ5CaER0FUjYOUZjLbuebv0fflovKN0WAn3Cgz7uF2atBvd4kFkK9ZnolpSwIzEgbL1CobL7Aw==", "X-Received": "by 2002:a17:907:3f8f:b0:96f:5f44:ea02 with SMTP id\n\thr15-20020a1709073f8f00b0096f5f44ea02mr7584888ejc.8.1685976260421; \n\tMon, 05 Jun 2023 07:44:20 -0700 (PDT)", "X-Google-Original-From": "Cedric Nugteren <web@cedricnugteren.nl>", "To": "libcamera-devel@lists.libcamera.org", "Date": "Mon, 5 Jun 2023 16:44:05 +0200", "Message-Id": "<20230605144405.118153-1-web@cedricnugteren.nl>", "X-Mailer": "git-send-email 2.34.1", "MIME-Version": "1.0", "Content-Transfer-Encoding": "8bit", "Subject": "[libcamera-devel] [PATCH v2] Add enable_auto_focus option to the\n\tGStreamer plugin", "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": "Cedric Nugteren via libcamera-devel\n\t<libcamera-devel@lists.libcamera.org>", "Reply-To": "Cedric Nugteren <cedric@plumerai.com>", "Cc": "Cedric Nugteren <web@cedricnugteren.nl>", "Errors-To": "libcamera-devel-bounces@lists.libcamera.org", "Sender": "\"libcamera-devel\" <libcamera-devel-bounces@lists.libcamera.org>" }, "content": "Cameras such as the PiCam 3 support auto-focus, but the GStreamer plugin\nfor libcamera does not enable auto-focus. With this patch auto-focus can\nbe enabled for cameras that support it. By default it is disabled, which\nmeans default behaviour remains unchanged. For cameras that do not\nsupport auto-focus, an error message shows up if it auto-focus is\nenabled.\n\nThis was tested on cameras that do not support auto-focus (e.g. PiCam2)\nand was tested on a camera that does support auto-focus (PiCam3) by\nenabling it, observing auto-focus, and by disabling it or by not setting\nthe option, both resulting in auto-focus being disabled.\n\nThis should close https://bugs.libcamera.org/show_bug.cgi?id=188.\n\nSigned-off-by: Cedric Nugteren <web@cedricnugteren.nl>\n---\nChanges since v1:\n- Now re-using the GParamSpec variables instead of re-creating.\n- Use bool instead of gboolean for enable_auto_focus.\n- Remove changes from the reconfigure_element functions.\n---\n src/gstreamer/gstlibcameraprovider.cpp | 12 +++++++++++\n src/gstreamer/gstlibcamerasrc.cpp | 29 +++++++++++++++++++++++++-\n 2 files changed, 40 insertions(+), 1 deletion(-)", "diff": "diff --git a/src/gstreamer/gstlibcameraprovider.cpp b/src/gstreamer/gstlibcameraprovider.cpp\nindex 6eb0a0eb..579cb8c0 100644\n--- a/src/gstreamer/gstlibcameraprovider.cpp\n+++ b/src/gstreamer/gstlibcameraprovider.cpp\n@@ -31,6 +31,7 @@ GST_DEBUG_CATEGORY_STATIC(provider_debug);\n \n enum {\n \tPROP_DEVICE_NAME = 1,\n+\tPROP_ENABLE_AUTO_FOCUS = 2,\n };\n \n #define GST_TYPE_LIBCAMERA_DEVICE gst_libcamera_device_get_type()\n@@ -40,6 +41,7 @@ G_DECLARE_FINAL_TYPE(GstLibcameraDevice, gst_libcamera_device,\n struct _GstLibcameraDevice {\n \tGstDevice parent;\n \tgchar *name;\n+\tbool enable_auto_focus = false;\n };\n \n G_DEFINE_TYPE(GstLibcameraDevice, gst_libcamera_device, GST_TYPE_DEVICE)\n@@ -56,6 +58,7 @@ gst_libcamera_device_create_element(GstDevice *device, const gchar *name)\n \tg_assert(source);\n \n \tg_object_set(source, \"camera-name\", GST_LIBCAMERA_DEVICE(device)->name, nullptr);\n+\tg_object_set(source, \"enable-auto-focus\", GST_LIBCAMERA_DEVICE(device)->enable_auto_focus, nullptr);\n \n \treturn source;\n }\n@@ -82,6 +85,9 @@ gst_libcamera_device_set_property(GObject *object, guint prop_id,\n \tcase PROP_DEVICE_NAME:\n \t\tdevice->name = g_value_dup_string(value);\n \t\tbreak;\n+\tcase PROP_ENABLE_AUTO_FOCUS:\n+\t\tdevice->enable_auto_focus = g_value_get_boolean(value);\n+\t\tbreak;\n \tdefault:\n \t\tG_OBJECT_WARN_INVALID_PROPERTY_ID(object, prop_id, pspec);\n \t\tbreak;\n@@ -121,6 +127,12 @@ gst_libcamera_device_class_init(GstLibcameraDeviceClass *klass)\n \t\t\t\t\t\t(GParamFlags)(G_PARAM_STATIC_STRINGS | G_PARAM_WRITABLE |\n \t\t\t\t\t\t\t G_PARAM_CONSTRUCT_ONLY));\n \tg_object_class_install_property(object_class, PROP_DEVICE_NAME, pspec);\n+\tpspec = g_param_spec_boolean(\"enable-auto-focus\",\n+\t \"Enable auto-focus\",\n+\t \"Enable auto-focus if set to true, \"\n+\t \"disable it if set to false\",\n+\t FALSE, G_PARAM_WRITABLE);\n+\tg_object_class_install_property(object_class, PROP_ENABLE_AUTO_FOCUS, pspec);\n }\n \n static GstDevice *\ndiff --git a/src/gstreamer/gstlibcamerasrc.cpp b/src/gstreamer/gstlibcamerasrc.cpp\nindex a10cbd4f..b2d8456b 100644\n--- a/src/gstreamer/gstlibcamerasrc.cpp\n+++ b/src/gstreamer/gstlibcamerasrc.cpp\n@@ -146,6 +146,7 @@ struct _GstLibcameraSrc {\n \tGstTask *task;\n \n \tgchar *camera_name;\n+\tbool enable_auto_focus = false;\n \n \tGstLibcameraSrcState *state;\n \tGstLibcameraAllocator *allocator;\n@@ -154,7 +155,8 @@ struct _GstLibcameraSrc {\n \n enum {\n \tPROP_0,\n-\tPROP_CAMERA_NAME\n+\tPROP_CAMERA_NAME,\n+\tPROP_ENABLE_AUTO_FOCUS,\n };\n \n G_DEFINE_TYPE_WITH_CODE(GstLibcameraSrc, gst_libcamera_src, GST_TYPE_ELEMENT,\n@@ -577,6 +579,18 @@ gst_libcamera_src_task_enter(GstTask *task, [[maybe_unused]] GThread *thread,\n \t\tgst_flow_combiner_add_pad(self->flow_combiner, srcpad);\n \t}\n \n+\tif (self->enable_auto_focus) {\n+\t\tconst ControlInfoMap &infoMap = state->cam_->controls();\n+\t\tif (infoMap.find(&controls::AfMode) != infoMap.end()) {\n+\t\t\tstate->initControls_.set(controls::AfMode, controls::AfModeContinuous);\n+\t\t} else {\n+\t\t\tGST_ELEMENT_ERROR(self, RESOURCE, SETTINGS,\n+\t\t\t\t(\"Failed to enable auto focus\"),\n+\t\t\t\t(\"AfMode not found in camera controls, \"\n+\t\t\t\t\"please retry with 'enable-auto-focus=false'\"));\n+\t\t}\n+\t}\n+\n \tret = state->cam_->start(&state->initControls_);\n \tif (ret) {\n \t\tGST_ELEMENT_ERROR(self, RESOURCE, SETTINGS,\n@@ -659,6 +673,9 @@ gst_libcamera_src_set_property(GObject *object, guint prop_id,\n \t\tg_free(self->camera_name);\n \t\tself->camera_name = g_value_dup_string(value);\n \t\tbreak;\n+\tcase PROP_ENABLE_AUTO_FOCUS:\n+\t\tself->enable_auto_focus = g_value_get_boolean(value);\n+\t\tbreak;\n \tdefault:\n \t\tG_OBJECT_WARN_INVALID_PROPERTY_ID(object, prop_id, pspec);\n \t\tbreak;\n@@ -676,6 +693,9 @@ gst_libcamera_src_get_property(GObject *object, guint prop_id, GValue *value,\n \tcase PROP_CAMERA_NAME:\n \t\tg_value_set_string(value, self->camera_name);\n \t\tbreak;\n+\tcase PROP_ENABLE_AUTO_FOCUS:\n+\t\tg_value_set_boolean(value, self->enable_auto_focus);\n+\t\tbreak;\n \tdefault:\n \t\tG_OBJECT_WARN_INVALID_PROPERTY_ID(object, prop_id, pspec);\n \t\tbreak;\n@@ -844,4 +864,11 @@ gst_libcamera_src_class_init(GstLibcameraSrcClass *klass)\n \t\t\t\t\t\t\t | G_PARAM_READWRITE\n \t\t\t\t\t\t\t | G_PARAM_STATIC_STRINGS));\n \tg_object_class_install_property(object_class, PROP_CAMERA_NAME, spec);\n+\tspec = g_param_spec_boolean(\"enable-auto-focus\",\n+\t \"Enable auto-focus\",\n+\t \"Enable auto-focus if set to true, \"\n+\t \"disable it if set to false\",\n+\t FALSE, G_PARAM_WRITABLE);\n+\tg_object_class_install_property(object_class, PROP_ENABLE_AUTO_FOCUS, spec);\n+\n }\n", "prefixes": [ "libcamera-devel", "v2" ] }