Show a patch.

GET /api/1.1/patches/2737/?format=api
HTTP 200 OK
Allow: GET, PUT, PATCH, HEAD, OPTIONS
Content-Type: application/json
Vary: Accept

{
    "id": 2737,
    "url": "https://patchwork.libcamera.org/api/1.1/patches/2737/?format=api",
    "web_url": "https://patchwork.libcamera.org/patch/2737/",
    "project": {
        "id": 1,
        "url": "https://patchwork.libcamera.org/api/1.1/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": "<20200129033210.278800-4-nicolas@ndufresne.ca>",
    "date": "2020-01-29T03:31:50",
    "name": "[libcamera-devel,v1,03/23] gst: Add initial device provider",
    "commit_ref": null,
    "pull_url": null,
    "state": "superseded",
    "archived": false,
    "hash": "73ad0c69f4e97382349c235f16059aa78d9aec6f",
    "submitter": {
        "id": 30,
        "url": "https://patchwork.libcamera.org/api/1.1/people/30/?format=api",
        "name": "Nicolas Dufresne",
        "email": "nicolas@ndufresne.ca"
    },
    "delegate": null,
    "mbox": "https://patchwork.libcamera.org/patch/2737/mbox/",
    "series": [
        {
            "id": 648,
            "url": "https://patchwork.libcamera.org/api/1.1/series/648/?format=api",
            "web_url": "https://patchwork.libcamera.org/project/libcamera/list/?series=648",
            "date": "2020-01-29T03:31:47",
            "name": "GStreamer Element for libcamera",
            "version": 1,
            "mbox": "https://patchwork.libcamera.org/series/648/mbox/"
        }
    ],
    "comments": "https://patchwork.libcamera.org/api/patches/2737/comments/",
    "check": "pending",
    "checks": "https://patchwork.libcamera.org/api/patches/2737/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 5FC7960447\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tWed, 29 Jan 2020 04:35:19 +0100 (CET)",
            "from nicolas-tpx395.localdomain (unknown\n\t[IPv6:2002:c0de:c115:0:66fc:8b:2a38:8313])\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 B11C028EA9F;\n\tWed, 29 Jan 2020 03:35:16 +0000 (GMT)"
        ],
        "From": "Nicolas Dufresne <nicolas@ndufresne.ca>",
        "To": "libcamera-devel@lists.libcamera.org",
        "Cc": "Nicolas Dufresne <nicolas.dufresne@collabora.com>",
        "Date": "Tue, 28 Jan 2020 22:31:50 -0500",
        "Message-Id": "<20200129033210.278800-4-nicolas@ndufresne.ca>",
        "X-Mailer": "git-send-email 2.24.1",
        "In-Reply-To": "<20200129033210.278800-1-nicolas@ndufresne.ca>",
        "References": "<20200129033210.278800-1-nicolas@ndufresne.ca>",
        "MIME-Version": "1.0",
        "Content-Transfer-Encoding": "8bit",
        "Subject": "[libcamera-devel] [PATCH v1 03/23] 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": "Wed, 29 Jan 2020 03:35:19 -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\nImplementations notes:\n  - libcamera does not support polling yet\n  - The device ID isn't unique in libcamera\n  - The \"name\" property does not yet exist in libcamerasrc\n\nSigned-off-by: Nicolas Dufresne <nicolas.dufresne@collabora.com>\n---\n src/gstreamer/gstlibcamera.c           |  10 +-\n src/gstreamer/gstlibcameraprovider.cpp | 227 +++++++++++++++++++++++++\n src/gstreamer/gstlibcameraprovider.h   |  23 +++\n src/gstreamer/meson.build              |   1 +\n 4 files changed, 259 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 953fb29..7356374 100644\n--- a/src/gstreamer/gstlibcamera.c\n+++ b/src/gstreamer/gstlibcamera.c\n@@ -7,12 +7,18 @@\n  */\n \n #include \"gstlibcamerasrc.h\"\n+#include \"gstlibcameraprovider.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..3e27912\n--- /dev/null\n+++ b/src/gstreamer/gstlibcameraprovider.cpp\n@@ -0,0 +1,227 @@\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 \"gstlibcamera-utils.h\"\n+#include \"gstlibcameraprovider.h\"\n+#include \"gstlibcamerasrc.h\"\n+\n+#include <libcamera/camera.h>\n+#include <libcamera/camera_manager.h>\n+\n+using namespace libcamera;\n+\n+GST_DEBUG_CATEGORY_STATIC(provider_debug);\n+#define GST_CAT_DEFAULT provider_debug\n+\n+/**************************************/\n+/* GstLibcameraDevice internal Object */\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;\n+\n+\tsource = gst_element_factory_make(\"libcamerasrc\", name);\n+\tg_assert(source);\n+\n+\tg_object_set(source, \"camera-name\", GST_LIBCAMERA_DEVICE(device)->name, NULL);\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, NULL);\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;\n+\n+\tdevice = 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+\tGParamSpec *pspec;\n+\tGstDeviceClass *device_class = (GstDeviceClass *)klass;\n+\tGObjectClass *object_class = (GObjectClass *)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+\tpspec = g_param_spec_string(\"name\", \"Name\",\n+\t\t\t\t    \"The name of the camera device\", \"\",\n+\t\t\t\t    (GParamFlags)(G_PARAM_STATIC_STRINGS | G_PARAM_WRITABLE |\n+\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+\tg_autoptr(GstStructure) props = NULL;\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 (GstDevice *)g_object_new(GST_TYPE_LIBCAMERA_DEVICE,\n+\t\t\t\t\t /* FIXME not sure name is unique */\n+\t\t\t\t\t \"name\", name,\n+\t\t\t\t\t \"display-name\", name,\n+\t\t\t\t\t \"caps\", caps,\n+\t\t\t\t\t \"device-class\", \"Source/Video\",\n+\t\t\t\t\t \"properties\", props,\n+\t\t\t\t\t NULL);\n+}\n+\n+/*************************************/\n+/* GstLibcameraDeviceProvider Object */\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 = NULL;\n+\tgint ret;\n+\n+\tGST_INFO_OBJECT(self, \"Probing cameras using LibCamera\");\n+\n+\t/* FIXME as long as the manager isn't able to handle hot-plug, we need to\n+\t * cycle start/stop here in order to ensure wthat we have an up to date\n+\t * list */\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 NULL;\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 = (GstDeviceProviderClass *)klass;\n+\tGObjectClass *object_class = (GObjectClass *)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..6dd232d\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+#include <gst/gst.h>\n+\n+#ifndef __GST_LIBCAMERA_PROVIDER_H__\n+#define __GST_LIBCAMERA_PROVIDER_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 39a34e7..7769b78 100644\n--- a/src/gstreamer/meson.build\n+++ b/src/gstreamer/meson.build\n@@ -2,6 +2,7 @@ libcamera_gst_sources = [\n     'gstlibcamera.c',\n     'gstlibcamera-utils.cpp',\n     'gstlibcamerasrc.cpp',\n+    'gstlibcameraprovider.cpp',\n ]\n \n libcamera_gst_c_args = [\n",
    "prefixes": [
        "libcamera-devel",
        "v1",
        "03/23"
    ]
}