[{"id":27366,"web_url":"https://patchwork.libcamera.org/comment/27366/","msgid":"<4771438e-e441-a2e3-862b-25675c69356a@ideasonboard.com>","date":"2023-06-16T10:18:33","subject":"Re: [libcamera-devel] [PATCH v4] gstreamer: Add enable_auto_focus\n\toption to the GStreamer plugin","submitter":{"id":86,"url":"https://patchwork.libcamera.org/api/people/86/","name":"Umang Jain","email":"umang.jain@ideasonboard.com"},"content":"Hi Cedric,\n\nThank you for v4.\n\nOn 6/16/23 3:33 PM, Cedric Nugteren via libcamera-devel wrote:\n> Cameras such as the PiCam 3 support auto-focus, but the GStreamer plugin\n> for libcamera does not enable auto-focus. With this patch auto-focus can\n> be enabled for cameras that support it. By default it is disabled, which\n> means default behaviour remains unchanged. For cameras that do not\n> support auto-focus, an error message shows up if auto-focus is enabled.\n>\n> This was tested on cameras that do not support auto-focus (e.g. PiCam2)\n> and was tested on a camera that does support auto-focus (PiCam3). The\n> test involved setting the focus to AfModeContinous and observing it.\n> However, by not setting \"auto-focus-mode\" or using AfModeManual as\n> the \"auto-focus-mode\" both resulting in auto-focus being disabled.\n>\n> Bug:https://bugs.libcamera.org/show_bug.cgi?id=188\n>\n> Signed-off-by: Cedric Nugteren<web@cedricnugteren.nl>\n\nPlease always collect tags from previous version and append in the \ncommit message:\n\nReviewed-by: Maarten Lankhorst <dev@lankhorst.se>\n|Reviewed-by: Kieran Bingham <kieran.bingham@ideasonboard.com>|\n||Reviewed-by: Umang Jain <umang.jain@ideasonboard.com>\nTested-by: Umang Jain <umang.jain@ideasonboard.com>\n||\n> ---\n> Changes 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> Changes 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>\n> Changes 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(-)\n>\n> diff --git a/src/gstreamer/gstlibcameraprovider.cpp b/src/gstreamer/gstlibcameraprovider.cpp\n> index 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\nPossibly a new line here as well... I can fixup while applying so no \nneed for v5.\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 *\n> diff --git a/src/gstreamer/gstlibcamerasrc.cpp b/src/gstreamer/gstlibcamerasrc.cpp\n> index 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>   }\n> diff --git a/src/gstreamer/gstlibcamerasrc.h b/src/gstreamer/gstlibcamerasrc.h\n> index 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> +}","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 714DFC322E\n\tfor <parsemail@patchwork.libcamera.org>;\n\tFri, 16 Jun 2023 10:18:41 +0000 (UTC)","from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id 7B697628B7;\n\tFri, 16 Jun 2023 12:18:40 +0200 (CEST)","from perceval.ideasonboard.com (perceval.ideasonboard.com\n\t[213.167.242.64])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id 28F24628AD\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tFri, 16 Jun 2023 12:18:39 +0200 (CEST)","from [192.168.1.108] (unknown [103.86.18.150])\n\tby perceval.ideasonboard.com (Postfix) with ESMTPSA id 4FB632B3;\n\tFri, 16 Jun 2023 12:18:06 +0200 (CEST)"],"DKIM-Signature":["v=1; a=rsa-sha256; c=relaxed/simple; d=libcamera.org;\n\ts=mail; t=1686910720;\n\tbh=671KlDg9XxO6m+dX92s4Yaq0vd9XATOHGn746WhVvSg=;\n\th=Date:To:References:In-Reply-To:Subject:List-Id:List-Unsubscribe:\n\tList-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To:Cc:\n\tFrom;\n\tb=t1+KA5eiFetkA44puip8aTd62PMGdDSeuvVsK6RFgoJ/5JN3kR5xRE8166F3TlaI5\n\tM8XV7UHiD3oQUMS3rZIJ5NJOAKkqKLXVyteBf+g7Ue2xdOkF8oEHk0zAA9p/lAg3Oj\n\tGBctlShJMj0cP74AhxYnscTUDOXUmFgF5mdGtGh+1wAKhxAodJE5KQ9T3ECUCWMMPn\n\t7Ag1vqS4A1IUj2SKPsASa7D1qLyrAcmuzasDQLgxE/A6ZV1BCtROZt6dWow1XW7vcl\n\t5NH4CYlkOueVXDGirz1YMKqK2kHV/QeEjsPhDSB1Ew4sfHK48+y8CeZsou/Qi4pB+L\n\tt9QcK85wcujvQ==","v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com;\n\ts=mail; t=1686910687;\n\tbh=671KlDg9XxO6m+dX92s4Yaq0vd9XATOHGn746WhVvSg=;\n\th=Date:Subject:To:Cc:References:From:In-Reply-To:From;\n\tb=PzJDB80hWoJKocPCCp+H/zl0nK+TAe2e4WL4Fy0wcEygtlOrGdeLyGFaQqfw+v5/6\n\tj9DEbTtSXU32efOdu2YRYjCghL7PX0cK5oTTDd/ETcz+k5KR6snq3mJbc6u8OVt5pd\n\tP02+Pjk4M3OYOg2AjeQwfeoascmH0Uj6Yn0zSlXg="],"Authentication-Results":"lancelot.ideasonboard.com; dkim=pass (1024-bit key; \n\tunprotected) header.d=ideasonboard.com\n\theader.i=@ideasonboard.com\n\theader.b=\"PzJDB80h\"; dkim-atps=neutral","Content-Type":"multipart/alternative;\n\tboundary=\"------------JlMNJzz7Ff50rnk6O4ovM0H8\"","Message-ID":"<4771438e-e441-a2e3-862b-25675c69356a@ideasonboard.com>","Date":"Fri, 16 Jun 2023 15:48:33 +0530","MIME-Version":"1.0","User-Agent":"Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101\n\tThunderbird/102.7.1","To":"Cedric Nugteren <cedric@plumerai.com>,\n\tlibcamera-devel@lists.libcamera.org","References":"<20230616100327.86707-1-web@cedricnugteren.nl>","Content-Language":"en-US","In-Reply-To":"<20230616100327.86707-1-web@cedricnugteren.nl>","Subject":"Re: [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":"Umang Jain via libcamera-devel <libcamera-devel@lists.libcamera.org>","Reply-To":"Umang Jain <umang.jain@ideasonboard.com>","Cc":"Cedric Nugteren <web@cedricnugteren.nl>","Errors-To":"libcamera-devel-bounces@lists.libcamera.org","Sender":"\"libcamera-devel\" <libcamera-devel-bounces@lists.libcamera.org>"}},{"id":27384,"web_url":"https://patchwork.libcamera.org/comment/27384/","msgid":"<4fa73db6-1741-1593-f602-0819cebe7ef9@ideasonboard.com>","date":"2023-06-18T12:18:44","subject":"Re: [libcamera-devel] [PATCH v4] gstreamer: Add enable_auto_focus\n\toption to the GStreamer plugin","submitter":{"id":86,"url":"https://patchwork.libcamera.org/api/people/86/","name":"Umang Jain","email":"umang.jain@ideasonboard.com"},"content":"Hi,\n\nOn 6/16/23 3:48 PM, Umang Jain via libcamera-devel wrote:\n> Hi Cedric,\n>\n> Thank you for v4.\n>\n> On 6/16/23 3:33 PM, Cedric Nugteren via libcamera-devel wrote:\n>> Cameras such as the PiCam 3 support auto-focus, but the GStreamer plugin\n>> for libcamera does not enable auto-focus. With this patch auto-focus can\n>> be enabled for cameras that support it. By default it is disabled, which\n>> means default behaviour remains unchanged. For cameras that do not\n>> support auto-focus, an error message shows up if auto-focus is enabled.\n>>\n>> This was tested on cameras that do not support auto-focus (e.g. PiCam2)\n>> and was tested on a camera that does support auto-focus (PiCam3). The\n>> test involved setting the focus to AfModeContinous and observing it.\n>> However, by not setting \"auto-focus-mode\" or using AfModeManual as\n>> the \"auto-focus-mode\" both resulting in auto-focus being disabled.\n>>\n>> Bug:https://bugs.libcamera.org/show_bug.cgi?id=188\n>>\n>> Signed-off-by: Cedric Nugteren<web@cedricnugteren.nl>\n\nMerged this patch. However your email as the commit author Cedric \nNugteren <cedric@plumerai.com> was different than the S-o-B tag here, \nThe S-o-B should be same as the author Full name and email-ID.\nPlease make sure for future, both refer to the same email.\n\nThanks!\n>\n> Please always collect tags from previous version and append in the \n> commit message:\n>\n> Reviewed-by: Maarten Lankhorst <dev@lankhorst.se>\n> |Reviewed-by: Kieran Bingham <kieran.bingham@ideasonboard.com>|\n> ||Reviewed-by: Umang Jain <umang.jain@ideasonboard.com>\n> Tested-by: Umang Jain <umang.jain@ideasonboard.com>\n> ||\n>> ---\n>> Changes 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>> Changes 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>>\n>> Changes 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(-)\n>>\n>> diff --git a/src/gstreamer/gstlibcameraprovider.cpp b/src/gstreamer/gstlibcameraprovider.cpp\n>> index 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>\n> Possibly a new line here as well... I can fixup while applying so no \n> need for v5.\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 *\n>> diff --git a/src/gstreamer/gstlibcamerasrc.cpp b/src/gstreamer/gstlibcamerasrc.cpp\n>> index 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>>   }\n>> diff --git a/src/gstreamer/gstlibcamerasrc.h b/src/gstreamer/gstlibcamerasrc.h\n>> index 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>","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 BC9F4BD78E\n\tfor <parsemail@patchwork.libcamera.org>;\n\tSun, 18 Jun 2023 12:18:52 +0000 (UTC)","from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id 15810628C3;\n\tSun, 18 Jun 2023 14:18:52 +0200 (CEST)","from perceval.ideasonboard.com (perceval.ideasonboard.com\n\t[IPv6:2001:4b98:dc2:55:216:3eff:fef7:d647])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id 87B8D61E48\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tSun, 18 Jun 2023 14:18:50 +0200 (CEST)","from [192.168.1.108] (unknown [103.86.18.208])\n\tby perceval.ideasonboard.com (Postfix) with ESMTPSA id 035C3E4;\n\tSun, 18 Jun 2023 14:18:15 +0200 (CEST)"],"DKIM-Signature":["v=1; a=rsa-sha256; c=relaxed/simple; d=libcamera.org;\n\ts=mail; t=1687090732;\n\tbh=gbKjoputIKJQuLBNdbZsHUN2067OA5p97YI6U/ZUjAM=;\n\th=Date:To:References:In-Reply-To:Subject:List-Id:List-Unsubscribe:\n\tList-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To:Cc:\n\tFrom;\n\tb=I+OLH7Xbg5nyx/VPZt3YywdLyd2akAX4fquB4IHJqjz+ibIRqHj0eTMGxg3jyTuDV\n\trHcZBCf6qxNg5e4ZdnV0SilDgnNx7ERYZUrEsI6+h3DXXqFgUL5wg9YqmSRQF8oD8c\n\th/l/ZI+053FN7e3P1cvXnElQgOLN1h2Wr8w7syBXMOpp29oLdx2mDWDatNDSvKTTwX\n\tcSFGkXoCfFmjVrBmryAqE+ioihNufjFfMNEvkaWFDUMJ+Ao1ouWqNABMEo+LhQ4Onp\n\tNL4/SvBArqzmq4/XaLGYJV83lLg3ZinaEOTsdHznwtz1/if9d4ZqvgdO/cc8GB/TSD\n\tej0q8tiLnwgng==","v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com;\n\ts=mail; t=1687090697;\n\tbh=gbKjoputIKJQuLBNdbZsHUN2067OA5p97YI6U/ZUjAM=;\n\th=Date:Subject:To:Cc:References:From:In-Reply-To:From;\n\tb=uf+13DxZYxaPlBTxvoNAXxb1JnKgcNOzUbYStUNo6asGUFoMFz6hx7gD41AQ5vbta\n\tjuYrH8IAwAH0ZIUEuZ75W+WFzQsxOKkXkfg2AM7krzW8IpzZkbYFVxP6rDp6nf3wKz\n\tWayX8Y2PgpkxZPftswaQv/QGMKJPVaYRv4lQkJbw="],"Authentication-Results":"lancelot.ideasonboard.com; dkim=pass (1024-bit key; \n\tunprotected) header.d=ideasonboard.com\n\theader.i=@ideasonboard.com\n\theader.b=\"uf+13DxZ\"; dkim-atps=neutral","Content-Type":"multipart/alternative;\n\tboundary=\"------------y40WIp2N4Hk160clRgNZONo0\"","Message-ID":"<4fa73db6-1741-1593-f602-0819cebe7ef9@ideasonboard.com>","Date":"Sun, 18 Jun 2023 17:48:44 +0530","MIME-Version":"1.0","User-Agent":"Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101\n\tThunderbird/102.7.1","Content-Language":"en-US","To":"Cedric Nugteren <cedric@plumerai.com>,\n\tlibcamera-devel@lists.libcamera.org","References":"<20230616100327.86707-1-web@cedricnugteren.nl>\n\t<4771438e-e441-a2e3-862b-25675c69356a@ideasonboard.com>","In-Reply-To":"<4771438e-e441-a2e3-862b-25675c69356a@ideasonboard.com>","Subject":"Re: [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":"Umang Jain via libcamera-devel <libcamera-devel@lists.libcamera.org>","Reply-To":"Umang Jain <umang.jain@ideasonboard.com>","Cc":"Cedric Nugteren <web@cedricnugteren.nl>","Errors-To":"libcamera-devel-bounces@lists.libcamera.org","Sender":"\"libcamera-devel\" <libcamera-devel-bounces@lists.libcamera.org>"}}]