udp: allow per feature registration
authorStéphane Cerveau <scerveau@collabora.com>
Tue, 16 Feb 2021 13:49:56 +0000 (14:49 +0100)
committerStéphane Cerveau <scerveau@collabora.com>
Mon, 29 Mar 2021 10:45:23 +0000 (12:45 +0200)
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: <https://gitlab.freedesktop.org/gstreamer/gst-plugins-good/-/merge_requests/876>

gst/udp/gstdynudpsink.c
gst/udp/gstmultiudpsink.c
gst/udp/gstudp.c
gst/udp/gstudpelement.c [new file with mode: 0644]
gst/udp/gstudpelements.h [new file with mode: 0644]
gst/udp/gstudpsink.c
gst/udp/gstudpsrc.c
gst/udp/meson.build

index e9d542d..42f2e02 100644 (file)
@@ -24,6 +24,7 @@
 #ifdef HAVE_CONFIG_H
 #include "config.h"
 #endif
+#include "gstudpelements.h"
 #include "gstdynudpsink.h"
 
 #include <gst/net/gstnetaddressmeta.h>
@@ -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)
index 3cece6a..7f1cbbf 100644 (file)
@@ -33,6 +33,7 @@
 #ifdef HAVE_CONFIG_H
 #include "config.h"
 #endif
+#include "gstudpelements.h"
 #include "gstmultiudpsink.h"
 
 #include <string.h>
@@ -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)
index 66d3f2e..d5a21f2 100644 (file)
 #include "config.h"
 #endif
 
-#include <gst/net/gstnetaddressmeta.h>
+#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 (file)
index 0000000..96d0ae4
--- /dev/null
@@ -0,0 +1,47 @@
+/* GStreamer
+ * Copyright (C) <1999> Erik Walthinsen <omega@cse.ogi.edu>
+ * Copyright (C) 2020 Huawei Technologies Co., Ltd.
+ *   @Author: Julian Bouzas <julian.bouzas@collabora.com>
+ *
+ * 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/net/gstnetaddressmeta.h>
+
+#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 (file)
index 0000000..e9b116c
--- /dev/null
@@ -0,0 +1,41 @@
+/*
+ * Copyright (C) <1999> Erik Walthinsen <omega@cse.ogi.edu>
+ * Copyright (C) 2020 Huawei Technologies Co., Ltd.
+ *   @Author: Julian Bouzas <julian.bouzas@collabora.com>
+ *
+ * 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 <gst/gst.h>
+
+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__ */
index cfe8fde..e4320ad 100644 (file)
@@ -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)
index 2054d38..cb6ee55 100644 (file)
 #endif
 
 #include <string.h>
+#include "gstudpelements.h"
 #include "gstudpsrc.h"
 
 #include <gst/net/gstnetaddressmeta.h>
@@ -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)
index ab7f4ac..26ee7a5 100644 (file)
@@ -1,5 +1,6 @@
 udp_sources = [
   'gstudp.c',
+  'gstudpelement.c',
   'gstudpsrc.c',
   'gstudpsink.c',
   'gstmultiudpsink.c',