From patchwork Mon Jun 5 14:44:05 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Cedric Nugteren X-Patchwork-Id: 18707 Return-Path: X-Original-To: parsemail@patchwork.libcamera.org Delivered-To: parsemail@patchwork.libcamera.org Received: from lancelot.ideasonboard.com (lancelot.ideasonboard.com [92.243.16.209]) by patchwork.libcamera.org (Postfix) with ESMTPS id E086DC3200 for ; Mon, 5 Jun 2023 14:44:23 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 2934362885; Mon, 5 Jun 2023 16:44:23 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=libcamera.org; s=mail; t=1685976263; bh=rqqbRaO7nccOGQ/j4gXQNPGkXYhwxjZBlZGAwGzoiCs=; h=To:Date:Subject:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:Cc:From; b=YWsV5Shwtvil1ypqbgt49RoZbnadHzVgShl7lE27rWMjG1VK4bJ3wXboFVCOqpiWn l+1Ejl5WiYuq+mYsoe3fDpKBKrrMjKXdUb0qTGZPz59XHIDlpItHLPNprxzAcGlQiX M7krGIsVON6Rc4phDKeJKg3/yaTz4ov8F5FFsuzb9I+rAWuYgGb7FJ7oU/XLCPS2rI XPW8XYfFSINO69ctY8GcteTuRHpF2KDwJmp0SrISjepfwD78r4mfG2/s1NxJvzV894 EAMkwE4mGqMrErjMxly0m8vyAU0XCx3jOpZ709nkBBWiwWxpC5iwc9mhJyyD2pefna k5v5vNuS4TbOg== Received: from mail-ej1-x636.google.com (mail-ej1-x636.google.com [IPv6:2a00:1450:4864:20::636]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 041EF62709 for ; Mon, 5 Jun 2023 16:44:20 +0200 (CEST) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (1024-bit key; unprotected) header.d=plumerai.com header.i=@plumerai.com header.b="HDNYC0BH"; dkim-atps=neutral Received: by mail-ej1-x636.google.com with SMTP id a640c23a62f3a-9741a0fd134so821294966b.0 for ; Mon, 05 Jun 2023 07:44:20 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=plumerai.com; s=google; t=1685976260; x=1688568260; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=3O9eHJK+dlIDDJILhsTBYEYi7WkuOabyS+KFabAaOqU=; b=HDNYC0BHDqiUQe7f49eduk8TDBmUuMIweP7IC8rQd3Rvp7dP2x29Qh4T/Suse86yDz g3TAtIjdpYhea3pYFrlR7wiFNbmHWAGcRABaCevk9X6Iu48U200aRmK/Sf1Rqw50lvrC pKIo2ztYRhrtRZabON8chPkK88/krG0RT6/E4= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1685976260; x=1688568260; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=3O9eHJK+dlIDDJILhsTBYEYi7WkuOabyS+KFabAaOqU=; b=i9YQPKe26bf7H76GNnNYfZNE+r4Q8pqONHh9KLKeuvDwEYBbmM1cEIFhk63nLuI/pC 0w8yGLh3wnMipu8cfZcYRNofiVDvIG1nbeNNNbKQwj1Sybn/WjiuP33BbFhDA9JE9Omd 9kcRGBoHdne4rVKCh0e/VgasWG1AeDCOCjz+VC5U9uRF6RCw+DJcmqf3uRlj+DUKx+Mg bsjupC5rz7nvkVkCqB/Vnwb0ytr2ZiIJi8mO6WaLCZfEGGCg/4R1RqtB8gCcZJ/bXlwY eWisjEfq6k1lZUJa2Fs+22Dr6V/0UR71EdHz0mFFV3BGngNfpnsKBNkVvH+ReK6fyDIX 2q4A== X-Gm-Message-State: AC+VfDyKY7FC92b131RKi1VtYv9z2tTkVP8cMQonrlwBOidIykfgjj2s ylkK23g4DP02DrNUKsRsJrJnqDklfqahqkYW6Kg= X-Google-Smtp-Source: ACHHUZ5CaER0FUjYOUZjLbuebv0fflovKN0WAn3Cgz7uF2atBvd4kFkK9ZnolpSwIzEgbL1CobL7Aw== X-Received: by 2002:a17:907:3f8f:b0:96f:5f44:ea02 with SMTP id hr15-20020a1709073f8f00b0096f5f44ea02mr7584888ejc.8.1685976260421; Mon, 05 Jun 2023 07:44:20 -0700 (PDT) Received: from kaylee.home (177-83-201-31.ftth.glasoperator.nl. [31.201.83.177]) by smtp.gmail.com with ESMTPSA id l14-20020a170906a40e00b0095807ab4b57sm4411354ejz.178.2023.06.05.07.44.18 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 05 Jun 2023 07:44:19 -0700 (PDT) X-Google-Original-From: Cedric Nugteren 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 Subject: [libcamera-devel] [PATCH v2] Add enable_auto_focus option to the GStreamer plugin X-BeenThere: libcamera-devel@lists.libcamera.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Patchwork-Original-From: Cedric Nugteren via libcamera-devel From: Cedric Nugteren Reply-To: Cedric Nugteren Cc: Cedric Nugteren Errors-To: libcamera-devel-bounces@lists.libcamera.org Sender: "libcamera-devel" Cameras such as the PiCam 3 support auto-focus, but the GStreamer plugin for libcamera does not enable auto-focus. With this patch auto-focus can be enabled for cameras that support it. By default it is disabled, which means default behaviour remains unchanged. For cameras that do not support auto-focus, an error message shows up if it auto-focus is enabled. This was tested on cameras that do not support auto-focus (e.g. PiCam2) and was tested on a camera that does support auto-focus (PiCam3) by enabling it, observing auto-focus, and by disabling it or by not setting the option, both resulting in auto-focus being disabled. This should close https://bugs.libcamera.org/show_bug.cgi?id=188. Signed-off-by: Cedric Nugteren --- Changes since v1: - Now re-using the GParamSpec variables instead of re-creating. - Use bool instead of gboolean for enable_auto_focus. - Remove changes from the reconfigure_element functions. --- src/gstreamer/gstlibcameraprovider.cpp | 12 +++++++++++ src/gstreamer/gstlibcamerasrc.cpp | 29 +++++++++++++++++++++++++- 2 files changed, 40 insertions(+), 1 deletion(-) diff --git a/src/gstreamer/gstlibcameraprovider.cpp b/src/gstreamer/gstlibcameraprovider.cpp index 6eb0a0eb..579cb8c0 100644 --- a/src/gstreamer/gstlibcameraprovider.cpp +++ b/src/gstreamer/gstlibcameraprovider.cpp @@ -31,6 +31,7 @@ GST_DEBUG_CATEGORY_STATIC(provider_debug); enum { PROP_DEVICE_NAME = 1, + PROP_ENABLE_AUTO_FOCUS = 2, }; #define GST_TYPE_LIBCAMERA_DEVICE gst_libcamera_device_get_type() @@ -40,6 +41,7 @@ G_DECLARE_FINAL_TYPE(GstLibcameraDevice, gst_libcamera_device, struct _GstLibcameraDevice { GstDevice parent; gchar *name; + bool enable_auto_focus = false; }; G_DEFINE_TYPE(GstLibcameraDevice, gst_libcamera_device, GST_TYPE_DEVICE) @@ -56,6 +58,7 @@ gst_libcamera_device_create_element(GstDevice *device, const gchar *name) g_assert(source); g_object_set(source, "camera-name", GST_LIBCAMERA_DEVICE(device)->name, nullptr); + g_object_set(source, "enable-auto-focus", GST_LIBCAMERA_DEVICE(device)->enable_auto_focus, nullptr); return source; } @@ -82,6 +85,9 @@ gst_libcamera_device_set_property(GObject *object, guint prop_id, case PROP_DEVICE_NAME: device->name = g_value_dup_string(value); break; + case PROP_ENABLE_AUTO_FOCUS: + device->enable_auto_focus = g_value_get_boolean(value); + break; default: G_OBJECT_WARN_INVALID_PROPERTY_ID(object, prop_id, pspec); break; @@ -121,6 +127,12 @@ gst_libcamera_device_class_init(GstLibcameraDeviceClass *klass) (GParamFlags)(G_PARAM_STATIC_STRINGS | G_PARAM_WRITABLE | G_PARAM_CONSTRUCT_ONLY)); g_object_class_install_property(object_class, PROP_DEVICE_NAME, pspec); + pspec = g_param_spec_boolean("enable-auto-focus", + "Enable auto-focus", + "Enable auto-focus if set to true, " + "disable it if set to false", + FALSE, G_PARAM_WRITABLE); + g_object_class_install_property(object_class, PROP_ENABLE_AUTO_FOCUS, pspec); } static GstDevice * diff --git a/src/gstreamer/gstlibcamerasrc.cpp b/src/gstreamer/gstlibcamerasrc.cpp index a10cbd4f..b2d8456b 100644 --- a/src/gstreamer/gstlibcamerasrc.cpp +++ b/src/gstreamer/gstlibcamerasrc.cpp @@ -146,6 +146,7 @@ struct _GstLibcameraSrc { GstTask *task; gchar *camera_name; + bool enable_auto_focus = false; GstLibcameraSrcState *state; GstLibcameraAllocator *allocator; @@ -154,7 +155,8 @@ struct _GstLibcameraSrc { enum { PROP_0, - PROP_CAMERA_NAME + PROP_CAMERA_NAME, + PROP_ENABLE_AUTO_FOCUS, }; G_DEFINE_TYPE_WITH_CODE(GstLibcameraSrc, gst_libcamera_src, GST_TYPE_ELEMENT, @@ -577,6 +579,18 @@ gst_libcamera_src_task_enter(GstTask *task, [[maybe_unused]] GThread *thread, gst_flow_combiner_add_pad(self->flow_combiner, srcpad); } + if (self->enable_auto_focus) { + const ControlInfoMap &infoMap = state->cam_->controls(); + if (infoMap.find(&controls::AfMode) != infoMap.end()) { + state->initControls_.set(controls::AfMode, controls::AfModeContinuous); + } else { + GST_ELEMENT_ERROR(self, RESOURCE, SETTINGS, + ("Failed to enable auto focus"), + ("AfMode not found in camera controls, " + "please retry with 'enable-auto-focus=false'")); + } + } + ret = state->cam_->start(&state->initControls_); if (ret) { GST_ELEMENT_ERROR(self, RESOURCE, SETTINGS, @@ -659,6 +673,9 @@ gst_libcamera_src_set_property(GObject *object, guint prop_id, g_free(self->camera_name); self->camera_name = g_value_dup_string(value); break; + case PROP_ENABLE_AUTO_FOCUS: + self->enable_auto_focus = g_value_get_boolean(value); + break; default: G_OBJECT_WARN_INVALID_PROPERTY_ID(object, prop_id, pspec); break; @@ -676,6 +693,9 @@ gst_libcamera_src_get_property(GObject *object, guint prop_id, GValue *value, case PROP_CAMERA_NAME: g_value_set_string(value, self->camera_name); break; + case PROP_ENABLE_AUTO_FOCUS: + g_value_set_boolean(value, self->enable_auto_focus); + break; default: G_OBJECT_WARN_INVALID_PROPERTY_ID(object, prop_id, pspec); break; @@ -844,4 +864,11 @@ gst_libcamera_src_class_init(GstLibcameraSrcClass *klass) | G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS)); g_object_class_install_property(object_class, PROP_CAMERA_NAME, spec); + spec = g_param_spec_boolean("enable-auto-focus", + "Enable auto-focus", + "Enable auto-focus if set to true, " + "disable it if set to false", + FALSE, G_PARAM_WRITABLE); + g_object_class_install_property(object_class, PROP_ENABLE_AUTO_FOCUS, spec); + }