From patchwork Mon Jul 3 19:57:25 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Umang Jain X-Patchwork-Id: 18776 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 E87CEBDC71 for ; Mon, 3 Jul 2023 19:57:32 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 4C808628BB; Mon, 3 Jul 2023 21:57:32 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=libcamera.org; s=mail; t=1688414252; bh=QyRXIJIwpoTgwWts0N6sHQAOhKnBMtnaKela3Bvn1zI=; h=To:Date:Subject:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:Cc:From; b=JYmi6bxrey0rh7NoywKp9vG5lRL/eKEITilLcQ3EvxvO1hnc0l9FP50A3SGAn+wGr cj1WTpHqRbIy3HEB/4t0eer34x/mqEQQ88IVd5sAsjqzr2yuVGWKWxGBQe86VKL0AF rPaMQMlGr93sdQbvJAh3t1CkE3FX5ZdaIqyIHxN6qA8iEUDWv0bV5zAYbCr+1c5I8U b2OI+iALdeNPf0NoYB3a1QS82M5QXAalytKB0aogfzZFty5pkQmLXEZOhVtp8cSXW1 wKPYrBQWupXFtywKy5xcJA2TOvsObRqM44gZj9XI0cTnNohHDyX4+ECCWqALxIWgyl DEpgeaSRqcQ3w== Received: from perceval.ideasonboard.com (perceval.ideasonboard.com [213.167.242.64]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 47425628BB for ; Mon, 3 Jul 2023 21:57:30 +0200 (CEST) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (1024-bit key; unprotected) header.d=ideasonboard.com header.i=@ideasonboard.com header.b="JWC5YB5H"; dkim-atps=neutral Received: from umang.jainideasonboard.com (85-160-45-219.reb.o2.cz [85.160.45.219]) by perceval.ideasonboard.com (Postfix) with ESMTPSA id 1795415E9; Mon, 3 Jul 2023 21:56:46 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1688414206; bh=QyRXIJIwpoTgwWts0N6sHQAOhKnBMtnaKela3Bvn1zI=; h=From:To:Cc:Subject:Date:From; b=JWC5YB5H/6BlknOgWWfnMWUCQaDIDodVFQthqvO2NQjU/m2MioqLlsyFqXOmukweZ wn8P+OyMMEqnDW2uR/ssq9h5I8ujfX7Ve/w3DVpob0AdvqYnNJg9Uva+eF8hxc08lE adub1jZsegk2AkXsE6ZjPXa9v8jBZUkhalEldGv8= To: libcamera-devel@lists.libcamera.org Date: Mon, 3 Jul 2023 21:57:25 +0200 Message-Id: <20230703195725.193585-1-umang.jain@ideasonboard.com> X-Mailer: git-send-email 2.39.1 MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH] gstreamer: Add 'list-cameras' property 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: Umang Jain via libcamera-devel From: Umang Jain Reply-To: Umang Jain Cc: nicolas.dufresne@collabora.com, vedantparanjape160201@gmail.com Errors-To: libcamera-devel-bounces@lists.libcamera.org Sender: "libcamera-devel" Add a new property called 'list-cameras' on libcamerasrc to enumerate and expose the cameras present on the system. The enumeration will help appplications using libcamerasrc to know and set the 'camera-name' property in order to use that camera with libcamerasrc. Signed-off-by: Umang Jain --- src/gstreamer/gstlibcamerasrc.cpp | 46 +++++++++++++++++++++++++++++++ test/gstreamer/gstreamer_test.cpp | 30 ++++++++++++++++++++ test/gstreamer/gstreamer_test.h | 2 ++ 3 files changed, 78 insertions(+) diff --git a/src/gstreamer/gstlibcamerasrc.cpp b/src/gstreamer/gstlibcamerasrc.cpp index 1f10136b..f337728a 100644 --- a/src/gstreamer/gstlibcamerasrc.cpp +++ b/src/gstreamer/gstlibcamerasrc.cpp @@ -152,6 +152,7 @@ struct _GstLibcameraSrc { enum { PROP_0, PROP_CAMERA_NAME, + PROP_LIST_CAMERAS, PROP_AUTO_FOCUS_MODE, }; @@ -666,6 +667,39 @@ gst_libcamera_src_close(GstLibcameraSrc *self) state->cm_.reset(); } +static gboolean +gst_libcamera_src_set_cameras_list(GstLibcameraSrc *self, GValue *value) +{ + std::shared_ptr cm; + GValue val = G_VALUE_INIT; + gint ret; + + g_value_init(&val, G_TYPE_STRING); + g_value_reset(value); + + cm = gst_libcamera_get_camera_manager(ret); + if (ret) { + GST_ELEMENT_ERROR(self, LIBRARY, INIT, + ("Failed listing cameras."), + ("libcamera::CameraMananger::start() failed: %s", g_strerror(-ret))); + return false; + } + + if (cm->cameras().empty()) { + GST_ELEMENT_ERROR(self, RESOURCE, NOT_FOUND, + ("Could not find any supported camera on this system."), + ("libcamera::CameraMananger::cameras() is empty")); + return false; + } + + for (const std::shared_ptr &cam : cm->cameras()) { + g_value_set_string(&val, cam->id().c_str()); + gst_value_array_append_value(value, &val); + } + + return true; +} + static void gst_libcamera_src_set_property(GObject *object, guint prop_id, const GValue *value, GParamSpec *pspec) @@ -699,6 +733,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_LIST_CAMERAS: + gst_libcamera_src_set_cameras_list(self, value); + break; case PROP_AUTO_FOCUS_MODE: { auto auto_focus_mode = self->controls->get(controls::AfMode).value_or(controls::AfModeManual); g_value_set_enum(value, auto_focus_mode); @@ -879,6 +916,15 @@ gst_libcamera_src_class_init(GstLibcameraSrcClass *klass) | G_PARAM_STATIC_STRINGS)); g_object_class_install_property(object_class, PROP_CAMERA_NAME, spec); + spec = gst_param_spec_array("list-cameras", "Cameras list", + "Retrieve list of all cameras", + g_param_spec_string("camera-name", "Camera name", + "Name of the camera", nullptr, + (GParamFlags)(G_PARAM_READABLE + | G_PARAM_STATIC_STRINGS)), + (GParamFlags)(G_PARAM_READABLE | G_PARAM_STATIC_STRINGS)); + g_object_class_install_property(object_class, PROP_LIST_CAMERAS, spec); + spec = g_param_spec_enum("auto-focus-mode", "Set auto-focus mode", "Available options: AfModeManual, " diff --git a/test/gstreamer/gstreamer_test.cpp b/test/gstreamer/gstreamer_test.cpp index 6ad0c15c..7f3ccd2b 100644 --- a/test/gstreamer/gstreamer_test.cpp +++ b/test/gstreamer/gstreamer_test.cpp @@ -97,6 +97,9 @@ bool GstreamerTest::checkMinCameraStreamsAndSetCameraName(unsigned int numStream break; } + for (auto &camera : cm.cameras()) + cameraNames_.push_back(strdup(camera->id().c_str())); + cm.stop(); return cameraFound; @@ -112,6 +115,9 @@ GstreamerTest::~GstreamerTest() int GstreamerTest::createPipeline() { + GValue cameras_list_array = G_VALUE_INIT; + guint index, i; + libcameraSrc_ = gst_element_factory_make("libcamerasrc", "libcamera"); pipeline_ = gst_pipeline_new("test-pipeline"); @@ -125,6 +131,30 @@ int GstreamerTest::createPipeline() g_object_set(libcameraSrc_, "camera-name", cameraName_.c_str(), NULL); g_object_ref_sink(libcameraSrc_); + g_value_init(&cameras_list_array, GST_TYPE_ARRAY); + g_object_get_property(G_OBJECT(libcameraSrc_), "list-cameras", &cameras_list_array); + if (gst_value_array_get_size(&cameras_list_array) != cameraNames_.size()) { + g_printerr("libcamerasrc 'list-cameras' properties count does not match.\n"); + return TestFail; + } + + for (index = 0; index < cameraNames_.size(); index++) { + bool matched = false; + + for (i = 0; i < gst_value_array_get_size(&cameras_list_array); i++) { + const char *cam = g_value_get_string(gst_value_array_get_value(&cameras_list_array, i)); + if (strcmp(cam, cameraNames_[index]) == 0) { + matched = true; + break; + } + } + + if (!matched) { + g_printerr("Camera %s not found in 'list-cameras' property.\n", cameraNames_[index]); + return TestFail; + } + } + return TestPass; } diff --git a/test/gstreamer/gstreamer_test.h b/test/gstreamer/gstreamer_test.h index aa2261e2..5d61bc2a 100644 --- a/test/gstreamer/gstreamer_test.h +++ b/test/gstreamer/gstreamer_test.h @@ -9,6 +9,7 @@ #include #include +#include #include @@ -29,6 +30,7 @@ protected: GstElement *libcameraSrc_; int status_; + std::vector cameraNames_; private: bool checkMinCameraStreamsAndSetCameraName(unsigned int numStreams); };