summaryrefslogtreecommitdiff
path: root/src/gstreamer/gstlibcamerasrc.cpp
diff options
context:
space:
mode:
authorCedric Nugteren <cedric@plumerai.com>2023-06-16 12:03:27 +0200
committerUmang Jain <umang.jain@ideasonboard.com>2023-06-18 17:44:29 +0530
commit5a142438b025b448eedfa67678fe8e169c66f566 (patch)
tree62441e0068e2c28e1ac9465266210ba42c7a75a4 /src/gstreamer/gstlibcamerasrc.cpp
parentb9113a86269281ec8cda96140be24e6227abe791 (diff)
gstreamer: Add enable_auto_focus option to the GStreamer plugin
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 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). The test involved setting the focus to AfModeContinous and observing it. However, by not setting "auto-focus-mode" or using AfModeManual as the "auto-focus-mode" both resulting in auto-focus being disabled. Bug: https://bugs.libcamera.org/show_bug.cgi?id=188 Signed-off-by: Cedric Nugteren <cedric@plumerai.com> Reviewed-by: Maarten Lankhorst <dev@lankhorst.se> Reviewed-by: Kieran Bingham <kieran.bingham@ideasonboard.com> Reviewed-by: Umang Jain <umang.jain@ideasonboard.com> Tested-by: Umang Jain <umang.jain@ideasonboard.com> Signed-off-by: Umang Jain <umang.jain@ideasonboard.com>
Diffstat (limited to 'src/gstreamer/gstlibcamerasrc.cpp')
-rw-r--r--src/gstreamer/gstlibcamerasrc.cpp31
1 files changed, 30 insertions, 1 deletions
diff --git a/src/gstreamer/gstlibcamerasrc.cpp b/src/gstreamer/gstlibcamerasrc.cpp
index a10cbd4f..47d8ff43 100644
--- a/src/gstreamer/gstlibcamerasrc.cpp
+++ b/src/gstreamer/gstlibcamerasrc.cpp
@@ -146,6 +146,7 @@ struct _GstLibcameraSrc {
GstTask *task;
gchar *camera_name;
+ controls::AfModeEnum auto_focus_mode = controls::AfModeManual;
GstLibcameraSrcState *state;
GstLibcameraAllocator *allocator;
@@ -154,7 +155,8 @@ struct _GstLibcameraSrc {
enum {
PROP_0,
- PROP_CAMERA_NAME
+ PROP_CAMERA_NAME,
+ PROP_AUTO_FOCUS_MODE,
};
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->auto_focus_mode != controls::AfModeManual) {
+ const ControlInfoMap &infoMap = state->cam_->controls();
+ if (infoMap.find(&controls::AfMode) != infoMap.end()) {
+ state->initControls_.set(controls::AfMode, self->auto_focus_mode);
+ } else {
+ GST_ELEMENT_ERROR(self, RESOURCE, SETTINGS,
+ ("Failed to enable auto focus"),
+ ("AfMode not supported by this camera, "
+ "please retry with 'auto-focus-mode=AfModeManual'"));
+ }
+ }
+
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_AUTO_FOCUS_MODE:
+ self->auto_focus_mode = static_cast<controls::AfModeEnum>(g_value_get_enum(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_AUTO_FOCUS_MODE:
+ g_value_set_enum(value, static_cast<gint>(self->auto_focus_mode));
+ break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID(object, prop_id, pspec);
break;
@@ -844,4 +864,13 @@ 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_enum("auto-focus-mode",
+ "Set auto-focus mode",
+ "Available options: AfModeManual, "
+ "AfModeAuto or AfModeContinuous.",
+ gst_libcamera_auto_focus_get_type(),
+ static_cast<gint>(controls::AfModeManual),
+ G_PARAM_WRITABLE);
+ g_object_class_install_property(object_class, PROP_AUTO_FOCUS_MODE, spec);
}