From b20209ce0dab66b4bf4b607541d6c76f786d2867 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?St=C3=A9phane=20Cerveau?= Date: Tue, 16 Feb 2021 15:29:06 +0100 Subject: [PATCH] v4l2: allow per feature registration Split plugin into features including dynamic types which can be indiviually registered during a static build. More details here: https://gitlab.freedesktop.org/gstreamer/gst-build/-/merge_requests/199 https://gitlab.freedesktop.org/gstreamer/gstreamer/-/merge_requests/661 Part-of: --- sys/v4l2/gstv4l2.c | 32 +++++--------------- sys/v4l2/gstv4l2deviceprovider.c | 3 ++ sys/v4l2/gstv4l2element.c | 50 ++++++++++++++++++++++++++++++++ sys/v4l2/gstv4l2elements.h | 39 +++++++++++++++++++++++++ sys/v4l2/gstv4l2radio.c | 3 ++ sys/v4l2/gstv4l2sink.c | 4 ++- sys/v4l2/gstv4l2src.c | 3 ++ sys/v4l2/meson.build | 1 + 8 files changed, 110 insertions(+), 25 deletions(-) create mode 100644 sys/v4l2/gstv4l2element.c create mode 100644 sys/v4l2/gstv4l2elements.h diff --git a/sys/v4l2/gstv4l2.c b/sys/v4l2/gstv4l2.c index cd75ec5537..dbdcff4563 100644 --- a/sys/v4l2/gstv4l2.c +++ b/sys/v4l2/gstv4l2.c @@ -40,6 +40,7 @@ #include #include "ext/videodev2.h" +#include "gstv4l2elements.h" #include "v4l2-utils.h" #include "gstv4l2object.h" @@ -55,13 +56,8 @@ #include "gstv4l2mpeg4enc.h" #include "gstv4l2vp8enc.h" #include "gstv4l2vp9enc.h" -#include "gstv4l2deviceprovider.h" #include "gstv4l2transform.h" -/* used in gstv4l2object.c and v4l2_calls.c */ -GST_DEBUG_CATEGORY (v4l2_debug); -#define GST_CAT_DEFAULT v4l2_debug - #ifdef GST_V4L2_ENABLE_PROBE /* This is a minimalist probe, for speed, we only enumerate formats */ static GstCaps * @@ -248,37 +244,25 @@ gst_v4l2_probe_and_register (GstPlugin * plugin) static gboolean plugin_init (GstPlugin * plugin) { + gboolean ret = FALSE; const gchar *paths[] = { "/dev", "/dev/v4l2", NULL }; const gchar *names[] = { "video", NULL }; - GST_DEBUG_CATEGORY_INIT (v4l2_debug, "v4l2", 0, "V4L2 API calls"); - /* Add some dependency, so the dynamic features get updated upon changes in * /dev/video* */ gst_plugin_add_dependency (plugin, NULL, paths, names, GST_PLUGIN_DEPENDENCY_FLAG_FILE_NAME_IS_PREFIX); - if (!gst_element_register (plugin, "v4l2src", GST_RANK_PRIMARY, - GST_TYPE_V4L2SRC) || - !gst_element_register (plugin, "v4l2sink", GST_RANK_NONE, - GST_TYPE_V4L2SINK) || - !gst_element_register (plugin, "v4l2radio", GST_RANK_NONE, - GST_TYPE_V4L2RADIO) || - !gst_device_provider_register (plugin, "v4l2deviceprovider", - GST_RANK_PRIMARY, GST_TYPE_V4L2_DEVICE_PROVIDER) - /* etc. */ #ifdef GST_V4L2_ENABLE_PROBE - || !gst_v4l2_probe_and_register (plugin) + ret |= gst_v4l2_probe_and_register (plugin); #endif - ) - return FALSE; -#ifdef ENABLE_NLS - bindtextdomain (GETTEXT_PACKAGE, LOCALEDIR); - bind_textdomain_codeset (GETTEXT_PACKAGE, "UTF-8"); -#endif /* ENABLE_NLS */ + ret |= GST_ELEMENT_REGISTER (v4l2src, plugin); + ret |= GST_ELEMENT_REGISTER (v4l2sink, plugin); + ret |= GST_ELEMENT_REGISTER (v4l2radio, plugin); + ret |= GST_DEVICE_PROVIDER_REGISTER (v4l2deviceprovider, plugin); - return TRUE; + return ret; } GST_PLUGIN_DEFINE (GST_VERSION_MAJOR, diff --git a/sys/v4l2/gstv4l2deviceprovider.c b/sys/v4l2/gstv4l2deviceprovider.c index 83efe0a8de..7c2c87fea3 100644 --- a/sys/v4l2/gstv4l2deviceprovider.c +++ b/sys/v4l2/gstv4l2deviceprovider.c @@ -32,6 +32,7 @@ #include "gstv4l2object.h" #include "v4l2-utils.h" +#include "gstv4l2elements.h" #ifdef HAVE_GUDEV #include @@ -44,6 +45,8 @@ static GstV4l2Device *gst_v4l2_device_new (const gchar * device_path, G_DEFINE_TYPE (GstV4l2DeviceProvider, gst_v4l2_device_provider, GST_TYPE_DEVICE_PROVIDER); +GST_DEVICE_PROVIDER_REGISTER_DEFINE (v4l2deviceprovider, "v4l2deviceprovider", + GST_RANK_PRIMARY, GST_TYPE_V4L2_DEVICE_PROVIDER); static void gst_v4l2_device_provider_finalize (GObject * object); static GList *gst_v4l2_device_provider_probe (GstDeviceProvider * provider); diff --git a/sys/v4l2/gstv4l2element.c b/sys/v4l2/gstv4l2element.c new file mode 100644 index 0000000000..e547e3be70 --- /dev/null +++ b/sys/v4l2/gstv4l2element.c @@ -0,0 +1,50 @@ +/* GStreamer + * + * Copyright (C) 2001-2002 Ronald Bultje + * 2006 Edgard Lima + * + * gstv4l2.c: plugin for v4l2 elements + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Library General Public License for more details. + * + * You should have received a copy of the GNU Library General Public + * License along with this library; if not, write to the + * Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, + * Boston, MA 02110-1301, USA. + */ + +#ifdef HAVE_CONFIG_H +#include "config.h" +#endif + +#include "gst/gst-i18n-plugin.h" +#include + +#include "gstv4l2elements.h" + + +/* used in gstv4l2object.c and v4l2_calls.c */ +GST_DEBUG_CATEGORY (v4l2_debug); +#define GST_CAT_DEFAULT v4l2_debug + +void +v4l2_element_init (GstPlugin * plugin) +{ + static gsize res = FALSE; + if (g_once_init_enter (&res)) { + GST_DEBUG_CATEGORY_INIT (v4l2_debug, "v4l2", 0, "V4L2 API calls"); +#ifdef ENABLE_NLS + bindtextdomain (GETTEXT_PACKAGE, LOCALEDIR); + bind_textdomain_codeset (GETTEXT_PACKAGE, "UTF-8"); +#endif /* ENABLE_NLS */ + g_once_init_leave (&res, TRUE); + } +} diff --git a/sys/v4l2/gstv4l2elements.h b/sys/v4l2/gstv4l2elements.h new file mode 100644 index 0000000000..51c20ff03b --- /dev/null +++ b/sys/v4l2/gstv4l2elements.h @@ -0,0 +1,39 @@ +/* + * Copyright (C) 2020 Julian Bouzas + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Library General Public License for more details. + * + * You should have received a copy of the GNU Library General Public + * License along with this library; if not, write to the Free + * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA. + */ + +#ifndef __GST_V4L2_ELEMENTS_H__ +#define __GST_V4L2_ELEMENTS_H__ + +#ifdef HAVE_CONFIG_H +#include "config.h" +#endif + +#include + +G_BEGIN_DECLS + +void v4l2_element_init (GstPlugin * plugin); + +GST_ELEMENT_REGISTER_DECLARE (v4l2radio); +GST_ELEMENT_REGISTER_DECLARE (v4l2sink); +GST_ELEMENT_REGISTER_DECLARE (v4l2src); +GST_DEVICE_PROVIDER_REGISTER_DECLARE (v4l2deviceprovider); + +G_END_DECLS + +#endif /* __GST_V4L2_ELEMENTS_H__ */ diff --git a/sys/v4l2/gstv4l2radio.c b/sys/v4l2/gstv4l2radio.c index 5cbc18c146..c375492d04 100644 --- a/sys/v4l2/gstv4l2radio.c +++ b/sys/v4l2/gstv4l2radio.c @@ -44,6 +44,7 @@ #include "gst/gst-i18n-plugin.h" +#include "gstv4l2elements.h" #include "gstv4l2object.h" #include "gstv4l2tuner.h" #include "gstv4l2radio.h" @@ -273,6 +274,8 @@ G_DEFINE_TYPE_WITH_CODE (GstV4l2Radio, gst_v4l2radio, GST_TYPE_ELEMENT, gst_v4l2radio_uri_handler_init); G_IMPLEMENT_INTERFACE (GST_TYPE_TUNER, gst_v4l2radio_tuner_interface_reinit)); +GST_ELEMENT_REGISTER_DEFINE_WITH_CODE (v4l2radio, + "v4l2radio", GST_RANK_NONE, GST_TYPE_V4L2RADIO, v4l2_element_init (plugin)); static void gst_v4l2radio_set_property (GObject * object, guint prop_id, const GValue * value, GParamSpec * pspec); diff --git a/sys/v4l2/gstv4l2sink.c b/sys/v4l2/gstv4l2sink.c index e4728ac706..cc601ac947 100644 --- a/sys/v4l2/gstv4l2sink.c +++ b/sys/v4l2/gstv4l2sink.c @@ -59,6 +59,7 @@ #include "gstv4l2tuner.h" #include "gstv4l2vidorient.h" +#include "gstv4l2elements.h" #include "gstv4l2sink.h" #include "gst/gst-i18n-plugin.h" @@ -95,7 +96,8 @@ G_DEFINE_TYPE_WITH_CODE (GstV4l2Sink, gst_v4l2sink, GST_TYPE_VIDEO_SINK, gst_v4l2sink_color_balance_interface_init); G_IMPLEMENT_INTERFACE (GST_TYPE_VIDEO_ORIENTATION, gst_v4l2sink_video_orientation_interface_init)); - +GST_ELEMENT_REGISTER_DEFINE_WITH_CODE (v4l2sink, + "v4l2sink", GST_RANK_NONE, GST_TYPE_V4L2SINK, v4l2_element_init (plugin)); static void gst_v4l2sink_finalize (GstV4l2Sink * v4l2sink); diff --git a/sys/v4l2/gstv4l2src.c b/sys/v4l2/gstv4l2src.c index ca74b9a9c7..d00f7a80dc 100644 --- a/sys/v4l2/gstv4l2src.c +++ b/sys/v4l2/gstv4l2src.c @@ -54,6 +54,7 @@ #include #include +#include "gstv4l2elements.h" #include "gstv4l2src.h" #include "gstv4l2colorbalance.h" @@ -98,6 +99,8 @@ G_DEFINE_TYPE_WITH_CODE (GstV4l2Src, gst_v4l2src, GST_TYPE_PUSH_SRC, gst_v4l2src_color_balance_interface_init); G_IMPLEMENT_INTERFACE (GST_TYPE_VIDEO_ORIENTATION, gst_v4l2src_video_orientation_interface_init)); +GST_ELEMENT_REGISTER_DEFINE_WITH_CODE (v4l2src, + "v4l2src", GST_RANK_PRIMARY, GST_TYPE_V4L2SRC, v4l2_element_init (plugin)); struct PreferredCapsInfo { diff --git a/sys/v4l2/meson.build b/sys/v4l2/meson.build index a1222f0d94..65f551fb64 100644 --- a/sys/v4l2/meson.build +++ b/sys/v4l2/meson.build @@ -1,5 +1,6 @@ v4l2_sources = [ 'gstv4l2.c', + 'gstv4l2element.c', 'gstv4l2allocator.c', 'gstv4l2codec.c', 'gstv4l2colorbalance.c',