From patchwork Fri May 26 12:34:04 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Cedric Nugteren X-Patchwork-Id: 18651 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 8F012C31E9 for ; Fri, 26 May 2023 12:36:40 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id A71D5626FA; Fri, 26 May 2023 14:36:39 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=libcamera.org; s=mail; t=1685104599; bh=W866H5kbCEUwh5fIycfidnPIqYMuYFuG8E7mUh2JP0M=; h=Date:To:Subject:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:From; b=F28iPY2fEW8D/BFR2fJjNZ1wVO6rruG+XgYSpFy9IfnuD1Ymywn3KjRUJ1BqARgHD +PGE/CwjetY9q30S6/z0Kg5JCxJYDM9SBfkVbpJoJkhzavOrlUk8y5ZVax2XcCn3js eZE8J/+1ikER/sD/JuQ9gQvMJ/DlfZcZpLw9kPXENFLDf1I1gDBFDpWzwTzVgrbzly ytb4m1xDWRGfqFD+SpTA8KrY6UPgJuDFRKiUgO08B3GJv+Gc3RyjbMnDZtA74O/35u //+fnFqtl/ZV5ceJXW/EdDyj18CD+Jw7UmRtPofUuEtWORgAfly6ka1ikE/InamUby 3ShMEtpI+HhpQ== Received: from mail-vs1-xe35.google.com (mail-vs1-xe35.google.com [IPv6:2607:f8b0:4864:20::e35]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 27C69626F4 for ; Fri, 26 May 2023 14:34:16 +0200 (CEST) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (1024-bit key; unprotected) header.d=plumerai.com header.i=@plumerai.com header.b="VBd9fNto"; dkim-atps=neutral Received: by mail-vs1-xe35.google.com with SMTP id ada2fe7eead31-437de9222a9so187589137.0 for ; Fri, 26 May 2023 05:34:16 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=plumerai.com; s=google; t=1685104455; x=1687696455; h=to:subject:message-id:date:from:mime-version:from:to:cc:subject :date:message-id:reply-to; bh=OULDYyBlH5S8WjkIGirJC3/gxqZyg3VQf80Rh3Ncuj4=; b=VBd9fNtoYZ5aEIBh0A8oQABMBmJp994Mi8rbgclHyY+W+tQMFw7TVbRCW2htSnTsOh OrguQ9GIbZ0Xe0UWhAxZ/Nnsj3ojP5WrXmB9ZIbDYqsmLamgdmLqB9kSfjJyhV6RsFTo hxEVAQ0YOgY8a/9EiA5QqfDvmJNh7w4BNmDL8= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1685104455; x=1687696455; h=to:subject:message-id:date:from:mime-version:x-gm-message-state :from:to:cc:subject:date:message-id:reply-to; bh=OULDYyBlH5S8WjkIGirJC3/gxqZyg3VQf80Rh3Ncuj4=; b=M7JqXqCJ8Era3gEVaWXtZuv2qd1NrI6p7i1Fn8NpjstSPsHUKPcyhALgQWQ21ZOm1d kaMUCR6aHnGBQ7f9woPC5mEJiz8k5mWkVAQU3k7hvBaxa00hNsCbRMNNUGVbdEO8jlvf n7Yqj+249kpu02q7QyH22K15lDklCq14mg0k6AfKn2vnQ5yu9UBvE370q1r8Ge+QZiU8 rDpez52LRH1BC/y9PENrwqMFHGl7zCwyRz1SG3XQzIfEYwjAdlsTNhvA35maaibuxMUC wmuLwsQTZ3rXW8nk2eVcZcUrkwQ4wBUnTU/WAM6EzeWBWL+MPF/kkE0wFp0zSJLpyzBC rqTw== X-Gm-Message-State: AC+VfDxftJyiJL6xhVJ4xIVCoXW7YZUpFyb7P52xJ3iFO0cFE0kquNUP JQ977EENVImoWsZsa+Eypq96PQFFQ8Zxlk7v04rzl/2As7NuOeygFgdmYw== X-Google-Smtp-Source: ACHHUZ68FxO/k7Qrw37/x+ddWk/zh2got+j7C7wXrIhd23oLlYftVc9OUZpumaahE8MARptetQ0/j6ei9pTA8ejtsRY= X-Received: by 2002:a67:fdd1:0:b0:436:897:4d44 with SMTP id l17-20020a67fdd1000000b0043608974d44mr352751vsq.23.1685104454782; Fri, 26 May 2023 05:34:14 -0700 (PDT) MIME-Version: 1.0 Date: Fri, 26 May 2023 14:34:04 +0200 Message-ID: To: libcamera-devel@lists.libcamera.org X-Mailman-Approved-At: Fri, 26 May 2023 14:36:38 +0200 Subject: [libcamera-devel] [PATCH] 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 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. Signed-off-by: Cedric Nugteren --- src/gstreamer/gstlibcameraprovider.cpp | 13 ++++++++++++ src/gstreamer/gstlibcamerasrc.cpp | 29 +++++++++++++++++++++++++- 2 files changed, 41 insertions(+), 1 deletion(-) 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); + GParamSpec *spec2 = 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, spec2); + } diff --git a/src/gstreamer/gstlibcameraprovider.cpp b/src/gstreamer/gstlibcameraprovider.cpp index 6eb0a0eb..86fa2542 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; + gboolean 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; } @@ -68,6 +71,7 @@ gst_libcamera_device_reconfigure_element(GstDevice *device, return FALSE; g_object_set(element, "camera-name", GST_LIBCAMERA_DEVICE(device)->name, nullptr); + g_object_set(element, "enable-auto-focus", GST_LIBCAMERA_DEVICE(device)->enable_auto_focus, nullptr); return TRUE; } @@ -82,6 +86,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 +128,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); + GParamSpec *spec2 = 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, spec2); } static GstDevice * diff --git a/src/gstreamer/gstlibcamerasrc.cpp b/src/gstreamer/gstlibcamerasrc.cpp index a10cbd4f..672ea38a 100644 --- a/src/gstreamer/gstlibcamerasrc.cpp +++ b/src/gstreamer/gstlibcamerasrc.cpp @@ -146,6 +146,7 @@ struct _GstLibcameraSrc { GstTask *task; gchar *camera_name; + gboolean 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,