Patch Detail
Show a patch.
GET /api/patches/3009/?format=api
{ "id": 3009, "url": "https://patchwork.libcamera.org/api/patches/3009/?format=api", "web_url": "https://patchwork.libcamera.org/patch/3009/", "project": { "id": 1, "url": "https://patchwork.libcamera.org/api/projects/1/?format=api", "name": "libcamera", "link_name": "libcamera", "list_id": "libcamera_core", "list_email": "libcamera-devel@lists.libcamera.org", "web_url": "", "scm_url": "", "webscm_url": "" }, "msgid": "<20200306202637.525587-4-nicolas@ndufresne.ca>", "date": "2020-03-06T20:26:13", "name": "[libcamera-devel,v3,03/27] gst: Add initial device provider", "commit_ref": null, "pull_url": null, "state": "accepted", "archived": false, "hash": "3d4fba6319d8f00365a2f66968a8bc4bef1e2ca8", "submitter": { "id": 30, "url": "https://patchwork.libcamera.org/api/people/30/?format=api", "name": "Nicolas Dufresne", "email": "nicolas@ndufresne.ca" }, "delegate": null, "mbox": "https://patchwork.libcamera.org/patch/3009/mbox/", "series": [ { "id": 705, "url": "https://patchwork.libcamera.org/api/series/705/?format=api", "web_url": "https://patchwork.libcamera.org/project/libcamera/list/?series=705", "date": "2020-03-06T20:26:10", "name": "GStreamer Element for libcamera", "version": 3, "mbox": "https://patchwork.libcamera.org/series/705/mbox/" } ], "comments": "https://patchwork.libcamera.org/api/patches/3009/comments/", "check": "pending", "checks": "https://patchwork.libcamera.org/api/patches/3009/checks/", "tags": {}, "headers": { "Return-Path": "<nicolas@ndufresne.ca>", "Received": [ "from bhuna.collabora.co.uk (bhuna.collabora.co.uk\n\t[IPv6:2a00:1098:0:82:1000:25:2eeb:e3e3])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id 32D8560424\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tFri, 6 Mar 2020 21:27:01 +0100 (CET)", "from nicolas-tpx395.localdomain (unknown [IPv6:2610:98:8005::527])\n\t(using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256\n\tbits))\n\t(No client certificate requested) (Authenticated sender: nicolas)\n\tby bhuna.collabora.co.uk (Postfix) with ESMTPSA id 950942970E7;\n\tFri, 6 Mar 2020 20:27:00 +0000 (GMT)" ], "From": "Nicolas Dufresne <nicolas@ndufresne.ca>", "To": "libcamera-devel@lists.libcamera.org", "Cc": "Nicolas Dufresne <nicolas.dufresne@collabora.com>,\n\tLaurent Pinchart <laurent.pinchart@ideasonboard.com>", "Date": "Fri, 6 Mar 2020 15:26:13 -0500", "Message-Id": "<20200306202637.525587-4-nicolas@ndufresne.ca>", "X-Mailer": "git-send-email 2.24.1", "In-Reply-To": "<20200306202637.525587-1-nicolas@ndufresne.ca>", "References": "<20200306202637.525587-1-nicolas@ndufresne.ca>", "MIME-Version": "1.0", "Content-Transfer-Encoding": "8bit", "Subject": "[libcamera-devel] [PATCH v3 03/27] gst: Add initial device provider", "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>", "X-List-Received-Date": "Fri, 06 Mar 2020 20:27:01 -0000" }, "content": "From: Nicolas Dufresne <nicolas.dufresne@collabora.com>\n\nThis feature is used with GstDeviceMonitor in order to enumerate\nand monitor devices to be used with the source element. The resulting\nGstDevice implementation is also used by application to abstract the\nconfiguration of the source element.\n\nImplementation notes:\n - libcamera does not support polling yet\n - The device ID isn't unique in libcamera yet\n - The \"name\" property does not yet exist in libcamerasrc yet\n\nSigned-off-by: Nicolas Dufresne <nicolas.dufresne@collabora.com>\nReviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>\n---\n src/gstreamer/gstlibcamera.c | 10 +-\n src/gstreamer/gstlibcameraprovider.cpp | 238 +++++++++++++++++++++++++\n src/gstreamer/gstlibcameraprovider.h | 23 +++\n src/gstreamer/meson.build | 1 +\n 4 files changed, 270 insertions(+), 2 deletions(-)\n create mode 100644 src/gstreamer/gstlibcameraprovider.cpp\n create mode 100644 src/gstreamer/gstlibcameraprovider.h", "diff": "diff --git a/src/gstreamer/gstlibcamera.c b/src/gstreamer/gstlibcamera.c\nindex 7dd94ca..81c7bb1 100644\n--- a/src/gstreamer/gstlibcamera.c\n+++ b/src/gstreamer/gstlibcamera.c\n@@ -6,13 +6,19 @@\n * gstlibcamera.c - GStreamer plugin\n */\n \n+#include \"gstlibcameraprovider.h\"\n #include \"gstlibcamerasrc.h\"\n \n static gboolean\n plugin_init(GstPlugin *plugin)\n {\n-\treturn gst_element_register(plugin, \"libcamerasrc\", GST_RANK_PRIMARY,\n-\t\t\t\t GST_TYPE_LIBCAMERA_SRC);\n+\tif (!gst_element_register(plugin, \"libcamerasrc\", GST_RANK_PRIMARY,\n+\t\t\t\t GST_TYPE_LIBCAMERA_SRC) ||\n+\t !gst_device_provider_register(plugin, \"libcameraprovider\",\n+\t\t\t\t\t GST_RANK_PRIMARY,\n+\t\t\t\t\t GST_TYPE_LIBCAMERA_PROVIDER))\n+\t\treturn FALSE;\n+\n \treturn TRUE;\n }\n \ndiff --git a/src/gstreamer/gstlibcameraprovider.cpp b/src/gstreamer/gstlibcameraprovider.cpp\nnew file mode 100644\nindex 0000000..914ed4f\n--- /dev/null\n+++ b/src/gstreamer/gstlibcameraprovider.cpp\n@@ -0,0 +1,238 @@\n+/* SPDX-License-Identifier: LGPL-2.1-or-later */\n+/*\n+ * Copyright (C) 2020, Collabora Ltd.\n+ * Author: Nicolas Dufresne <nicolas.dufresne@collabora.com>\n+ *\n+ * gstlibcameraprovider.c - GStreamer Device Provider\n+ */\n+\n+#include \"gstlibcameraprovider.h\"\n+\n+#include <libcamera/camera.h>\n+#include <libcamera/camera_manager.h>\n+\n+#include \"gstlibcamerasrc.h\"\n+#include \"gstlibcamera-utils.h\"\n+\n+using namespace libcamera;\n+\n+GST_DEBUG_CATEGORY_STATIC(provider_debug);\n+#define GST_CAT_DEFAULT provider_debug\n+\n+/**\n+ * \\struct _GstLibcameraDevice\n+ * \\brief libcamera GstDevice implementation\n+ *\n+ * This object is used by GstLibcameraProvider to abstract a libcamera\n+ * device. It also provides helpers to create and configure the\n+ * libcamerasrc GstElement to be used with this device. The implementation is\n+ * private to the plugin.\n+ */\n+\n+enum {\n+\tPROP_DEVICE_NAME = 1,\n+};\n+\n+#define GST_TYPE_LIBCAMERA_DEVICE gst_libcamera_device_get_type()\n+G_DECLARE_FINAL_TYPE(GstLibcameraDevice, gst_libcamera_device,\n+\t\t GST_LIBCAMERA, DEVICE, GstDevice);\n+\n+struct _GstLibcameraDevice {\n+\tGstDevice parent;\n+\tgchar *name;\n+};\n+\n+G_DEFINE_TYPE(GstLibcameraDevice, gst_libcamera_device, GST_TYPE_DEVICE);\n+\n+static GstElement *\n+gst_libcamera_device_create_element(GstDevice *device, const gchar *name)\n+{\n+\tGstElement *source = gst_element_factory_make(\"libcamerasrc\", name);\n+\n+\t/*\n+\t * Provider and source lives in the same plugin, so making the source\n+\t * should never fail.\n+\t */\n+\tg_assert(source);\n+\n+\tg_object_set(source, \"camera-name\", GST_LIBCAMERA_DEVICE(device)->name, nullptr);\n+\n+\treturn source;\n+}\n+\n+static gboolean\n+gst_libcamera_device_reconfigure_element(GstDevice *device,\n+\t\t\t\t\t GstElement *element)\n+{\n+\tif (!GST_LIBCAMERA_IS_SRC(element))\n+\t\treturn FALSE;\n+\n+\tg_object_set(element, \"camera-name\", GST_LIBCAMERA_DEVICE(device)->name, nullptr);\n+\n+\treturn TRUE;\n+}\n+\n+static void\n+gst_libcamera_device_set_property(GObject *object, guint prop_id,\n+\t\t\t\t const GValue *value, GParamSpec *pspec)\n+{\n+\tGstLibcameraDevice *device = GST_LIBCAMERA_DEVICE(object);\n+\n+\tswitch (prop_id) {\n+\tcase PROP_DEVICE_NAME:\n+\t\tdevice->name = g_value_dup_string(value);\n+\t\tbreak;\n+\tdefault:\n+\t\tG_OBJECT_WARN_INVALID_PROPERTY_ID(object, prop_id, pspec);\n+\t\tbreak;\n+\t}\n+}\n+\n+static void\n+gst_libcamera_device_init(GstLibcameraDevice *self)\n+{\n+}\n+\n+static void\n+gst_libcamera_device_finalize(GObject *object)\n+{\n+\tGstLibcameraDevice *self = GST_LIBCAMERA_DEVICE(object);\n+\tgpointer klass = gst_libcamera_device_parent_class;\n+\n+\tg_free(self->name);\n+\n+\tG_OBJECT_GET_CLASS(klass)->finalize(object);\n+}\n+\n+static void\n+gst_libcamera_device_class_init(GstLibcameraDeviceClass *klass)\n+{\n+\tGstDeviceClass *device_class = GST_DEVICE_CLASS(klass);\n+\tGObjectClass *object_class = G_OBJECT_CLASS(klass);\n+\n+\tdevice_class->create_element = gst_libcamera_device_create_element;\n+\tdevice_class->reconfigure_element = gst_libcamera_device_reconfigure_element;\n+\n+\tobject_class->set_property = gst_libcamera_device_set_property;\n+\tobject_class->finalize = gst_libcamera_device_finalize;\n+\n+\tGParamSpec *pspec = g_param_spec_string(\"name\", \"Name\",\n+\t\t\t\t\t\t\"The name of the camera device\", \"\",\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+}\n+\n+static GstDevice *\n+gst_libcamera_device_new(const std::shared_ptr<Camera> &camera)\n+{\n+\tg_autoptr(GstCaps) caps = gst_caps_new_empty();\n+\tconst gchar *name = camera->name().c_str();\n+\tStreamRoles roles;\n+\n+\troles.push_back(StreamRole::VideoRecording);\n+\tstd::unique_ptr<CameraConfiguration> config = camera->generateConfiguration(roles);\n+\n+\tfor (const StreamConfiguration &stream_cfg : *config) {\n+\t\tGstCaps *sub_caps = gst_libcamera_stream_formats_to_caps(stream_cfg.formats());\n+\t\tif (sub_caps)\n+\t\t\tgst_caps_append(caps, sub_caps);\n+\t}\n+\n+\treturn GST_DEVICE(g_object_new(GST_TYPE_LIBCAMERA_DEVICE,\n+\t\t\t\t /* \\todo Use a unique identifier instead of camera name. */\n+\t\t\t\t \"name\", name,\n+\t\t\t\t \"display-name\", name,\n+\t\t\t\t \"caps\", caps,\n+\t\t\t\t \"device-class\", \"Source/Video\",\n+\t\t\t\t nullptr));\n+}\n+\n+/**\n+ * \\struct _GstLibcameraProvider\n+ * \\brief libcamera GstDeviceProvider implementation\n+ *\n+ * This GstFeature is used by GstDeviceMonitor to probe the available\n+ * libcamera devices. The implementation is private to the plugin.\n+ */\n+\n+struct _GstLibcameraProvider {\n+\tGstDeviceProvider parent;\n+\tCameraManager *cm;\n+};\n+\n+G_DEFINE_TYPE_WITH_CODE(GstLibcameraProvider, gst_libcamera_provider,\n+\t\t\tGST_TYPE_DEVICE_PROVIDER,\n+\t\t\tGST_DEBUG_CATEGORY_INIT(provider_debug, \"libcamera-provider\", 0,\n+\t\t\t\t\t\t\"libcamera Device Provider\"));\n+\n+static GList *\n+gst_libcamera_provider_probe(GstDeviceProvider *provider)\n+{\n+\tGstLibcameraProvider *self = GST_LIBCAMERA_PROVIDER(provider);\n+\tCameraManager *cm = self->cm;\n+\tGList *devices = nullptr;\n+\tgint ret;\n+\n+\tGST_INFO_OBJECT(self, \"Probing cameras using libcamera\");\n+\n+\t/* \\todo Move the CameraMananger start()/stop() calls into\n+\t * GstDeviceProvider start()/stop() virtual function when CameraMananger\n+\t * gains monitoring support. Meanwhile we need to cycle start()/stop()\n+\t * to ensure every probe() calls return the latest list.\n+\t */\n+\tret = cm->start();\n+\tif (ret) {\n+\t\tGST_ERROR_OBJECT(self, \"Failed to retrieve device list: %s\",\n+\t\t\t\t g_strerror(-ret));\n+\t\treturn nullptr;\n+\t}\n+\n+\tfor (const std::shared_ptr<Camera> &camera : cm->cameras()) {\n+\t\tGST_INFO_OBJECT(self, \"Found camera '%s'\", camera->name().c_str());\n+\t\tdevices = g_list_append(devices,\n+\t\t\t\t\tg_object_ref_sink(gst_libcamera_device_new(camera)));\n+\t}\n+\n+\tcm->stop();\n+\n+\treturn devices;\n+}\n+\n+static void\n+gst_libcamera_provider_init(GstLibcameraProvider *self)\n+{\n+\tGstDeviceProvider *provider = GST_DEVICE_PROVIDER(self);\n+\n+\tself->cm = new CameraManager();\n+\n+\t/* Avoid devices being duplicated. */\n+\tgst_device_provider_hide_provider(provider, \"v4l2deviceprovider\");\n+}\n+\n+static void\n+gst_libcamera_provider_finalize(GObject *object)\n+{\n+\tGstLibcameraProvider *self = GST_LIBCAMERA_PROVIDER(object);\n+\tgpointer klass = gst_libcamera_provider_parent_class;\n+\n+\tdelete self->cm;\n+\n+\treturn G_OBJECT_GET_CLASS(klass)->finalize(object);\n+}\n+\n+static void\n+gst_libcamera_provider_class_init(GstLibcameraProviderClass *klass)\n+{\n+\tGstDeviceProviderClass *provider_class = GST_DEVICE_PROVIDER_CLASS(klass);\n+\tGObjectClass *object_class = G_OBJECT_CLASS(klass);\n+\n+\tprovider_class->probe = gst_libcamera_provider_probe;\n+\tobject_class->finalize = gst_libcamera_provider_finalize;\n+\n+\tgst_device_provider_class_set_metadata(provider_class,\n+\t\t\t\t\t \"libcamera Device Provider\",\n+\t\t\t\t\t \"Source/Video\",\n+\t\t\t\t\t \"List camera device using libcamera\",\n+\t\t\t\t\t \"Nicolas Dufresne <nicolas.dufresne@collabora.com>\");\n+}\ndiff --git a/src/gstreamer/gstlibcameraprovider.h b/src/gstreamer/gstlibcameraprovider.h\nnew file mode 100644\nindex 0000000..bdd19db\n--- /dev/null\n+++ b/src/gstreamer/gstlibcameraprovider.h\n@@ -0,0 +1,23 @@\n+/* SPDX-License-Identifier: LGPL-2.1-or-later */\n+/*\n+ * Copyright (C) 2020, Collabora Ltd.\n+ * Author: Nicolas Dufresne <nicolas.dufresne@collabora.com>\n+ *\n+ * gstlibcameraprovider.h - GStreamer Device Provider\n+ */\n+\n+#ifndef __GST_LIBCAMERA_PROVIDER_H__\n+#define __GST_LIBCAMERA_PROVIDER_H__\n+\n+#include <gst/gst.h>\n+\n+G_BEGIN_DECLS\n+\n+#define GST_TYPE_LIBCAMERA_PROVIDER gst_libcamera_provider_get_type()\n+G_DECLARE_FINAL_TYPE(GstLibcameraProvider, gst_libcamera_provider,\n+\t\t GST_LIBCAMERA, PROVIDER, GstDeviceProvider)\n+\n+G_END_DECLS\n+\n+#endif /* __GST_LIBCAMERA_PROVIDER_H__ */\n+\ndiff --git a/src/gstreamer/meson.build b/src/gstreamer/meson.build\nindex 1539d9e..12c8ae1 100644\n--- a/src/gstreamer/meson.build\n+++ b/src/gstreamer/meson.build\n@@ -1,6 +1,7 @@\n libcamera_gst_sources = [\n 'gstlibcamera-utils.cpp',\n 'gstlibcamera.c',\n+ 'gstlibcameraprovider.cpp',\n 'gstlibcamerasrc.cpp',\n ]\n \n", "prefixes": [ "libcamera-devel", "v3", "03/27" ] }