Show a patch.

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

{
    "id": 18747,
    "url": "https://patchwork.libcamera.org/api/patches/18747/?format=api",
    "web_url": "https://patchwork.libcamera.org/patch/18747/",
    "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": "<20230616100327.86707-1-web@cedricnugteren.nl>",
    "date": "2023-06-16T10:03:27",
    "name": "[libcamera-devel,v4] gstreamer: Add enable_auto_focus option to the GStreamer plugin",
    "commit_ref": null,
    "pull_url": null,
    "state": "accepted",
    "archived": false,
    "hash": "65b34548138c3c388ad6b707bd6542d293e69dea",
    "submitter": {
        "id": 164,
        "url": "https://patchwork.libcamera.org/api/people/164/?format=api",
        "name": "Cedric Nugteren",
        "email": "cedric@plumerai.com"
    },
    "delegate": null,
    "mbox": "https://patchwork.libcamera.org/patch/18747/mbox/",
    "series": [
        {
            "id": 3928,
            "url": "https://patchwork.libcamera.org/api/series/3928/?format=api",
            "web_url": "https://patchwork.libcamera.org/project/libcamera/list/?series=3928",
            "date": "2023-06-16T10:03:27",
            "name": "[libcamera-devel,v4] gstreamer: Add enable_auto_focus option to the GStreamer plugin",
            "version": 4,
            "mbox": "https://patchwork.libcamera.org/series/3928/mbox/"
        }
    ],
    "comments": "https://patchwork.libcamera.org/api/patches/18747/comments/",
    "check": "pending",
    "checks": "https://patchwork.libcamera.org/api/patches/18747/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 94C96BD78E\n\tfor <parsemail@patchwork.libcamera.org>;\n\tFri, 16 Jun 2023 10:03:34 +0000 (UTC)",
            "from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id D640D628AE;\n\tFri, 16 Jun 2023 12:03:33 +0200 (CEST)",
            "from mail-ed1-x536.google.com (mail-ed1-x536.google.com\n\t[IPv6:2a00:1450:4864:20::536])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id 3AD09628AD\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tFri, 16 Jun 2023 12:03:32 +0200 (CEST)",
            "by mail-ed1-x536.google.com with SMTP id\n\t4fb4d7f45d1cf-51a2fa4a45eso662159a12.0\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tFri, 16 Jun 2023 03:03:32 -0700 (PDT)",
            "from kaylee.. (92-68-83-157.biz.kpn.net. [92.68.83.157])\n\tby smtp.gmail.com with ESMTPSA id\n\tr23-20020a056402035700b0051a2c4b1743sm1479974edw.21.2023.06.16.03.03.30\n\t(version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256);\n\tFri, 16 Jun 2023 03:03:31 -0700 (PDT)"
        ],
        "DKIM-Signature": [
            "v=1; a=rsa-sha256; c=relaxed/simple; d=libcamera.org;\n\ts=mail; t=1686909813;\n\tbh=ZXlN82+xYshFIMijo0bH+u3sSX6f13ZPPAhE7IFs1PY=;\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=2h8lqbNcmEUDSuN8viym0HjDMPAXDyptj3X7hb30xK4tTBD4tFJDTSi15DxhEwN9O\n\t0EKJkCTuJEpmeYaKVa4tNqZasRZzT6e47RYT9hCSJ/yfUY7u96M/5MwsffKx5CF28b\n\tdpq9Q/kuRxAyBEhaXAf5Wg8LDY+mRNUIadCoOR+Is4uqX5N8axQmkV9qZaxAuX+Fq9\n\tB1UQP3QIkS80hSYZTwJXuXspVj3d7eYA7iSorZEOGxI7P/tQFowDsV/jWmA9YQ6O47\n\txSSpxNXJto0aVTqEUt/oWZrIvuvvDiW8Puev81idgU+NZvmYhNavbe7ASLmUPKsAUu\n\tvZ56QYpDgjZmg==",
            "v=1; a=rsa-sha256; c=relaxed/relaxed;\n\td=plumerai.com; s=google; t=1686909811; x=1689501811;\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=E59dRrYZlRucjxD1I+BCKdQ7O6+MoGo4uHa8CGEVIq8=;\n\tb=iFLdaLESLxzBnkF2dmb5d+0ANeHJMG8KN8ty2labxHGMmmURTb4LwB9KGHK2tdxh9G\n\tqNyAPNEYc92Rhb0Ulv+uAt5+mibeKR2ajJaa0OxkTNNWcaQGfw/KxjdvlOilngEOHl3P\n\teMjcrn4bEsde5G/D/OqdGkl08gQOjr/VSMF5g="
        ],
        "Authentication-Results": "lancelot.ideasonboard.com; dkim=pass (1024-bit key; \n\tunprotected) header.d=plumerai.com\n\theader.i=@plumerai.com header.b=\"iFLdaLES\"; \n\tdkim-atps=neutral",
        "X-Google-DKIM-Signature": "v=1; a=rsa-sha256; c=relaxed/relaxed;\n\td=1e100.net; s=20221208; t=1686909811; x=1689501811;\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=E59dRrYZlRucjxD1I+BCKdQ7O6+MoGo4uHa8CGEVIq8=;\n\tb=AzHhaapZyXDZlWmTW/FBa8aFUJ8uV3YIzOo9u0Ed0Ba1cNzYJd8dohVBRBTJZptQ3k\n\tN6HX0ZeKWbPvxSQl4uRCffhObv5+Pqoroxch71CeNqsCbmb6SQrSZrquU/xVVh+dXrV+\n\tXjwU1+43h0AfnfNVNqqbHBJjF9J/GBvxPfMWKHerK0UPNdiAVRd5qjgLu1ljBomavlCi\n\tTi8zGav8bm7iLCqOvn4e1pwsbBkWRA+RJy+RKGdeHXMh9HddgfA4qE2JYznuxSf36ptB\n\tH9LxyfV7c8Ig7mqEV8/SoSmKE3rra5bP5r5DkoLMmKGqEhkcjuyvzQtYOCQa59v4A0KO\n\tWm9A==",
        "X-Gm-Message-State": "AC+VfDxLftB750584JgSVSTGpas46dbQ4zCU0nseLzvurE3/OK29HMy6\n\tZH6C8UJpSD9mrvnz+qUVMRCzvgAhekEfLjdxkv8=",
        "X-Google-Smtp-Source": "ACHHUZ4yxoWsQKLmow8IQ6po+UfiEn8mQshZZI5F5vVsjzEaLU/b1YgpYu6xP+JwekUnN1a3rx/vzg==",
        "X-Received": "by 2002:a05:6402:111a:b0:514:a110:6bed with SMTP id\n\tu26-20020a056402111a00b00514a1106bedmr942599edv.27.1686909811625; \n\tFri, 16 Jun 2023 03:03:31 -0700 (PDT)",
        "X-Google-Original-From": "Cedric Nugteren <web@cedricnugteren.nl>",
        "To": "libcamera-devel@lists.libcamera.org",
        "Date": "Fri, 16 Jun 2023 12:03:27 +0200",
        "Message-Id": "<20230616100327.86707-1-web@cedricnugteren.nl>",
        "X-Mailer": "git-send-email 2.34.1",
        "MIME-Version": "1.0",
        "Content-Transfer-Encoding": "8bit",
        "Subject": "[libcamera-devel] [PATCH v4] gstreamer: Add enable_auto_focus\n\toption to the GStreamer 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 auto-focus is enabled.\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). The\ntest involved setting the focus to AfModeContinous and observing it.\nHowever, by not setting \"auto-focus-mode\" or using AfModeManual as\nthe \"auto-focus-mode\" both resulting in auto-focus being disabled.\n\nBug: 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\nChanges since v2:\n- Fix a typo in the commit message (remove 'it').\n- Fix the link to the actual bug.\n- Apply the style suggestions of utils/checkstyle.py.\n- Start the commit message with 'gstreamer:'.\n- Change the boolean to a 3-option AfMode enum and change variable\n  names and strings accordingly.\n\nChanges since v3:\n- Removed a period at the end of the bug link.\n- Split the long sentence in the commit message in three parts.\n- Remove unnecessary use of \"libcamera::\".\n- Use controls::AfModeEnum enum instead of int.\n- Add a newline before 'g_param_spec_enum'.\n\n---\n src/gstreamer/gstlibcameraprovider.cpp | 14 ++++++++++++\n src/gstreamer/gstlibcamerasrc.cpp      | 31 +++++++++++++++++++++++++-\n src/gstreamer/gstlibcamerasrc.h        | 31 ++++++++++++++++++++++++++\n 3 files changed, 75 insertions(+), 1 deletion(-)",
    "diff": "diff --git a/src/gstreamer/gstlibcameraprovider.cpp b/src/gstreamer/gstlibcameraprovider.cpp\nindex 6eb0a0eb..d9216046 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_AUTO_FOCUS_MODE = 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+\tcontrols::AfModeEnum auto_focus_mode = controls::AfModeManual;\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, \"auto-focus-mode\", GST_LIBCAMERA_DEVICE(device)->auto_focus_mode, 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_AUTO_FOCUS_MODE:\n+\t\tdevice->auto_focus_mode = static_cast<controls::AfModeEnum>(g_value_get_enum(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,14 @@ 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_enum(\"auto-focus-mode\",\n+\t\t\t\t  \"Set auto-focus mode\",\n+\t\t\t\t  \"Available options: AfModeManual, \"\n+\t\t\t\t  \"AfModeAuto or AfModeContinuous.\",\n+\t\t\t\t  gst_libcamera_auto_focus_get_type(),\n+\t\t\t\t  static_cast<gint>(controls::AfModeManual),\n+\t\t\t\t  G_PARAM_WRITABLE);\n+\tg_object_class_install_property(object_class, PROP_AUTO_FOCUS_MODE, pspec);\n }\n \n static GstDevice *\ndiff --git a/src/gstreamer/gstlibcamerasrc.cpp b/src/gstreamer/gstlibcamerasrc.cpp\nindex a10cbd4f..47d8ff43 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+\tcontrols::AfModeEnum auto_focus_mode = controls::AfModeManual;\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_AUTO_FOCUS_MODE,\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->auto_focus_mode != controls::AfModeManual) {\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, self->auto_focus_mode);\n+\t\t} else {\n+\t\t\tGST_ELEMENT_ERROR(self, RESOURCE, SETTINGS,\n+\t\t\t\t\t  (\"Failed to enable auto focus\"),\n+\t\t\t\t\t  (\"AfMode not supported by this camera, \"\n+\t\t\t\t\t   \"please retry with 'auto-focus-mode=AfModeManual'\"));\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_AUTO_FOCUS_MODE:\n+\t\tself->auto_focus_mode = static_cast<controls::AfModeEnum>(g_value_get_enum(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_AUTO_FOCUS_MODE:\n+\t\tg_value_set_enum(value, static_cast<gint>(self->auto_focus_mode));\n+\t\tbreak;\n \tdefault:\n \t\tG_OBJECT_WARN_INVALID_PROPERTY_ID(object, prop_id, pspec);\n \t\tbreak;\n@@ -844,4 +864,13 @@ 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+\n+\tspec = g_param_spec_enum(\"auto-focus-mode\",\n+\t\t\t\t \"Set auto-focus mode\",\n+\t\t\t\t \"Available options: AfModeManual, \"\n+\t\t\t\t \"AfModeAuto or AfModeContinuous.\",\n+\t\t\t\t gst_libcamera_auto_focus_get_type(),\n+\t\t\t\t static_cast<gint>(controls::AfModeManual),\n+\t\t\t\t G_PARAM_WRITABLE);\n+\tg_object_class_install_property(object_class, PROP_AUTO_FOCUS_MODE, spec);\n }\ndiff --git a/src/gstreamer/gstlibcamerasrc.h b/src/gstreamer/gstlibcamerasrc.h\nindex fdea2f10..0a88ba02 100644\n--- a/src/gstreamer/gstlibcamerasrc.h\n+++ b/src/gstreamer/gstlibcamerasrc.h\n@@ -8,6 +8,8 @@\n \n #pragma once\n \n+#include <libcamera/control_ids.h>\n+\n #include <gst/gst.h>\n \n G_BEGIN_DECLS\n@@ -17,3 +19,32 @@ G_DECLARE_FINAL_TYPE(GstLibcameraSrc, gst_libcamera_src,\n \t\t     GST_LIBCAMERA, SRC, GstElement)\n \n G_END_DECLS\n+\n+inline GType\n+gst_libcamera_auto_focus_get_type()\n+{\n+\tstatic GType type = 0;\n+\tstatic const GEnumValue values[] = {\n+\t\t{\n+\t\t\tstatic_cast<gint>(libcamera::controls::AfModeManual),\n+\t\t\t\"AfModeManual\",\n+\t\t\t\"manual-focus\",\n+\t\t},\n+\t\t{\n+\t\t\tstatic_cast<gint>(libcamera::controls::AfModeAuto),\n+\t\t\t\"AfModeAuto\",\n+\t\t\t\"automatic-auto-focus\",\n+\t\t},\n+\t\t{\n+\t\t\tstatic_cast<gint>(libcamera::controls::AfModeContinuous),\n+\t\t\t\"AfModeContinuous\",\n+\t\t\t\"continuous-auto-focus\",\n+\t\t},\n+\t\t{ 0, NULL, NULL }\n+\t};\n+\n+\tif (!type)\n+\t\ttype = g_enum_register_static(\"GstLibcameraAutoFocus\", values);\n+\n+\treturn type;\n+}\n",
    "prefixes": [
        "libcamera-devel",
        "v4"
    ]
}