From 72c7ae54ddd69ed85209df84ccd18950e786152f Mon Sep 17 00:00:00 2001 From: =?utf8?q?St=C3=A9phane=20Cerveau?= Date: Tue, 16 Feb 2021 14:49:56 +0100 Subject: [PATCH] udp: 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: --- gst/udp/gstdynudpsink.c | 3 +++ gst/udp/gstmultiudpsink.c | 3 +++ gst/udp/gstudp.c | 31 +++++++------------------------ gst/udp/gstudpelement.c | 47 +++++++++++++++++++++++++++++++++++++++++++++++ gst/udp/gstudpelements.h | 41 +++++++++++++++++++++++++++++++++++++++++ gst/udp/gstudpsink.c | 3 +++ gst/udp/gstudpsrc.c | 3 +++ gst/udp/meson.build | 1 + 8 files changed, 108 insertions(+), 24 deletions(-) create mode 100644 gst/udp/gstudpelement.c create mode 100644 gst/udp/gstudpelements.h diff --git a/gst/udp/gstdynudpsink.c b/gst/udp/gstdynudpsink.c index e9d542d..42f2e02 100644 --- a/gst/udp/gstdynudpsink.c +++ b/gst/udp/gstdynudpsink.c @@ -24,6 +24,7 @@ #ifdef HAVE_CONFIG_H #include "config.h" #endif +#include "gstudpelements.h" #include "gstdynudpsink.h" #include @@ -83,6 +84,8 @@ static guint gst_dynudpsink_signals[LAST_SIGNAL] = { 0 }; #define gst_dynudpsink_parent_class parent_class G_DEFINE_TYPE (GstDynUDPSink, gst_dynudpsink, GST_TYPE_BASE_SINK); +GST_ELEMENT_REGISTER_DEFINE_WITH_CODE (dynudpsink, "dynudpsink", GST_RANK_NONE, + GST_TYPE_DYNUDPSINK, udp_element_init (plugin)); static void gst_dynudpsink_class_init (GstDynUDPSinkClass * klass) diff --git a/gst/udp/gstmultiudpsink.c b/gst/udp/gstmultiudpsink.c index 3cece6a..7f1cbbf 100644 --- a/gst/udp/gstmultiudpsink.c +++ b/gst/udp/gstmultiudpsink.c @@ -33,6 +33,7 @@ #ifdef HAVE_CONFIG_H #include "config.h" #endif +#include "gstudpelements.h" #include "gstmultiudpsink.h" #include @@ -140,6 +141,8 @@ static guint gst_multiudpsink_signals[LAST_SIGNAL] = { 0 }; #define gst_multiudpsink_parent_class parent_class G_DEFINE_TYPE (GstMultiUDPSink, gst_multiudpsink, GST_TYPE_BASE_SINK); +GST_ELEMENT_REGISTER_DEFINE_WITH_CODE (multiudpsink, "multiudpsink", + GST_RANK_NONE, GST_TYPE_MULTIUDPSINK, udp_element_init (plugin)); static void gst_multiudpsink_class_init (GstMultiUDPSinkClass * klass) diff --git a/gst/udp/gstudp.c b/gst/udp/gstudp.c index 66d3f2e..d5a21f2 100644 --- a/gst/udp/gstudp.c +++ b/gst/udp/gstudp.c @@ -21,37 +21,20 @@ #include "config.h" #endif -#include +#include "gstudpelements.h" -#include "gstudpsrc.h" -#include "gstmultiudpsink.h" -#include "gstudpsink.h" -#include "gstdynudpsink.h" static gboolean plugin_init (GstPlugin * plugin) { - /* register info of the netaddress metadata so that we can use it from - * multiple threads right away. Note that the plugin loading is always - * serialized */ - gst_net_address_meta_get_info (); + gboolean ret = FALSE; - if (!gst_element_register (plugin, "udpsink", GST_RANK_NONE, - GST_TYPE_UDPSINK)) - return FALSE; + ret |= GST_ELEMENT_REGISTER (udpsink, plugin); + ret |= GST_ELEMENT_REGISTER (multiudpsink, plugin); + ret |= GST_ELEMENT_REGISTER (dynudpsink, plugin); + ret |= GST_ELEMENT_REGISTER (udpsrc, plugin); - if (!gst_element_register (plugin, "multiudpsink", GST_RANK_NONE, - GST_TYPE_MULTIUDPSINK)) - return FALSE; - - if (!gst_element_register (plugin, "dynudpsink", GST_RANK_NONE, - GST_TYPE_DYNUDPSINK)) - return FALSE; - - if (!gst_element_register (plugin, "udpsrc", GST_RANK_NONE, GST_TYPE_UDPSRC)) - return FALSE; - - return TRUE; + return ret; } GST_PLUGIN_DEFINE (GST_VERSION_MAJOR, diff --git a/gst/udp/gstudpelement.c b/gst/udp/gstudpelement.c new file mode 100644 index 0000000..96d0ae4 --- /dev/null +++ b/gst/udp/gstudpelement.c @@ -0,0 +1,47 @@ +/* GStreamer + * Copyright (C) <1999> Erik Walthinsen + * Copyright (C) 2020 Huawei Technologies Co., Ltd. + * @Author: 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. + */ + +#ifdef HAVE_CONFIG_H +#include "config.h" +#endif + +#include + +#include "gstudpelements.h" + +void +udp_element_init (GstPlugin * plugin) +{ + static gsize res = FALSE; + if (g_once_init_enter (&res)) { + /* not using GLIB_CHECK_VERSION on purpose, run-time version matters */ + if (glib_check_version (2, 36, 0) != NULL) { + GST_WARNING ("Your GLib version is < 2.36, UDP multicasting support may " + "be broken, see https://bugzilla.gnome.org/show_bug.cgi?id=688378"); + } + + /* register info of the netaddress metadata so that we can use it from + * multiple threads right away. Note that the plugin loading is always + * serialized */ + gst_net_address_meta_get_info (); + g_once_init_leave (&res, TRUE); + } +} diff --git a/gst/udp/gstudpelements.h b/gst/udp/gstudpelements.h new file mode 100644 index 0000000..e9b116c --- /dev/null +++ b/gst/udp/gstudpelements.h @@ -0,0 +1,41 @@ +/* + * Copyright (C) <1999> Erik Walthinsen + * Copyright (C) 2020 Huawei Technologies Co., Ltd. + * @Author: 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_UDP_ELEMENTS_H__ +#define __GST_UDP_ELEMENTS_H__ + +#ifdef HAVE_CONFIG_H +#include "config.h" +#endif + +#include + +G_BEGIN_DECLS + +void udp_element_init (GstPlugin * plugin); + +GST_ELEMENT_REGISTER_DECLARE (dynudpsink); +GST_ELEMENT_REGISTER_DECLARE (multiudpsink); +GST_ELEMENT_REGISTER_DECLARE (udpsink); +GST_ELEMENT_REGISTER_DECLARE (udpsrc); + +G_END_DECLS + +#endif /* __GST_UDP_ELEMENTS_H__ */ diff --git a/gst/udp/gstudpsink.c b/gst/udp/gstudpsink.c index cfe8fde..e4320ad 100644 --- a/gst/udp/gstudpsink.c +++ b/gst/udp/gstudpsink.c @@ -35,6 +35,7 @@ #ifdef HAVE_CONFIG_H #include "config.h" #endif +#include "gstudpelements.h" #include "gstudpsink.h" #define UDP_DEFAULT_HOST "localhost" @@ -70,6 +71,8 @@ static void gst_udpsink_get_property (GObject * object, guint prop_id, #define gst_udpsink_parent_class parent_class G_DEFINE_TYPE_WITH_CODE (GstUDPSink, gst_udpsink, GST_TYPE_MULTIUDPSINK, G_IMPLEMENT_INTERFACE (GST_TYPE_URI_HANDLER, gst_udpsink_uri_handler_init)); +GST_ELEMENT_REGISTER_DEFINE_WITH_CODE (udpsink, "udpsink", GST_RANK_NONE, + GST_TYPE_UDPSINK, udp_element_init (plugin)); static void gst_udpsink_class_init (GstUDPSinkClass * klass) diff --git a/gst/udp/gstudpsrc.c b/gst/udp/gstudpsrc.c index 2054d38..cb6ee55 100644 --- a/gst/udp/gstudpsrc.c +++ b/gst/udp/gstudpsrc.c @@ -114,6 +114,7 @@ #endif #include +#include "gstudpelements.h" #include "gstudpsrc.h" #include @@ -615,6 +616,8 @@ static GstStateChangeReturn gst_udpsrc_change_state (GstElement * element, #define gst_udpsrc_parent_class parent_class G_DEFINE_TYPE_WITH_CODE (GstUDPSrc, gst_udpsrc, GST_TYPE_PUSH_SRC, G_IMPLEMENT_INTERFACE (GST_TYPE_URI_HANDLER, gst_udpsrc_uri_handler_init)); +GST_ELEMENT_REGISTER_DEFINE_WITH_CODE (udpsrc, "udpsrc", GST_RANK_NONE, + GST_TYPE_UDPSRC, udp_element_init (plugin)); static void gst_udpsrc_class_init (GstUDPSrcClass * klass) diff --git a/gst/udp/meson.build b/gst/udp/meson.build index ab7f4ac..26ee7a5 100644 --- a/gst/udp/meson.build +++ b/gst/udp/meson.build @@ -1,5 +1,6 @@ udp_sources = [ 'gstudp.c', + 'gstudpelement.c', 'gstudpsrc.c', 'gstudpsink.c', 'gstmultiudpsink.c', -- 2.7.4