tcp: allow per feature registration
authorStéphane Cerveau <scerveau@collabora.com>
Fri, 11 Dec 2020 11:42:03 +0000 (12:42 +0100)
committerGStreamer Marge Bot <gitlab-merge-bot@gstreamer-foundation.org>
Tue, 16 Mar 2021 17:58:59 +0000 (17:58 +0000)
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-base/-/merge_requests/1029>

gst/tcp/gstmultifdsink.c
gst/tcp/gstmultisocketsink.c
gst/tcp/gstsocketsrc.c
gst/tcp/gsttcpclientsink.c
gst/tcp/gsttcpclientsrc.c
gst/tcp/gsttcpelement.c [new file with mode: 0644]
gst/tcp/gsttcpelements.h [new file with mode: 0644]
gst/tcp/gsttcpplugin.c
gst/tcp/gsttcpserversink.c
gst/tcp/gsttcpserversrc.c
gst/tcp/meson.build

index e151dfc..d67f772 100644 (file)
 #include <sys/stat.h>
 #include <netinet/in.h>
 
+#include "gsttcpelements.h"
 #include "gstmultifdsink.h"
 
 #define NOT_IMPLEMENTED 0
@@ -194,6 +195,8 @@ static void gst_multi_fd_sink_get_property (GObject * object, guint prop_id,
 
 #define gst_multi_fd_sink_parent_class parent_class
 G_DEFINE_TYPE (GstMultiFdSink, gst_multi_fd_sink, GST_TYPE_MULTI_HANDLE_SINK);
+GST_ELEMENT_REGISTER_DEFINE_WITH_CODE (multifdsink, "multifdsink",
+    GST_RANK_NONE, GST_TYPE_MULTI_FD_SINK, tcp_element_init (plugin));
 
 static guint gst_multi_fd_sink_signals[LAST_SIGNAL] = { 0 };
 
index da7eaf5..81a4543 100644 (file)
 #include <string.h>
 
 #include "gstmultisocketsink.h"
+#include "gsttcpelements.h"
 
 #ifndef G_OS_WIN32
 #include <netinet/in.h>
@@ -206,6 +207,8 @@ static void gst_multi_socket_sink_get_property (GObject * object, guint prop_id,
 #define gst_multi_socket_sink_parent_class parent_class
 G_DEFINE_TYPE (GstMultiSocketSink, gst_multi_socket_sink,
     GST_TYPE_MULTI_HANDLE_SINK);
+GST_ELEMENT_REGISTER_DEFINE_WITH_CODE (multisocketsink, "multisocketsink",
+    GST_RANK_NONE, GST_TYPE_MULTI_SOCKET_SINK, tcp_element_init (plugin));
 
 static guint gst_multi_socket_sink_signals[LAST_SIGNAL] = { 0 };
 
index 0372f91..613f985 100644 (file)
@@ -51,6 +51,7 @@
 
 #include <gst/gst-i18n-plugin.h>
 #include <gst/net/gstnetcontrolmessagemeta.h>
+#include "gsttcpelements.h"
 #include "gstsocketsrc.h"
 #include "gsttcp.h"
 
@@ -86,7 +87,8 @@ static guint gst_socket_src_signals[LAST_SIGNAL] = { 0 };
 
 #define gst_socket_src_parent_class parent_class
 G_DEFINE_TYPE (GstSocketSrc, gst_socket_src, GST_TYPE_PUSH_SRC);
-
+GST_ELEMENT_REGISTER_DEFINE_WITH_CODE (socketsrc, "socketsrc",
+    GST_RANK_NONE, GST_TYPE_SOCKET_SRC, tcp_element_init (plugin));
 
 static void gst_socket_src_finalize (GObject * gobject);
 
index b44de04..6b701d2 100644 (file)
@@ -44,6 +44,7 @@
 #include <gst/gst-i18n-plugin.h>
 
 #include "gsttcp.h"
+#include "gsttcpelements.h"
 #include "gsttcpclientsink.h"
 
 /* TCPClientSink signals and args */
@@ -90,6 +91,8 @@ static void gst_tcp_client_sink_get_property (GObject * object, guint prop_id,
 
 #define gst_tcp_client_sink_parent_class parent_class
 G_DEFINE_TYPE (GstTCPClientSink, gst_tcp_client_sink, GST_TYPE_BASE_SINK);
+GST_ELEMENT_REGISTER_DEFINE_WITH_CODE (tcpclientsink, "tcpclientsink",
+    GST_RANK_NONE, GST_TYPE_TCP_CLIENT_SINK, tcp_element_init (plugin));
 
 static void
 gst_tcp_client_sink_class_init (GstTCPClientSinkClass * klass)
index d64856e..980edd4 100644 (file)
@@ -44,6 +44,7 @@
 #endif
 
 #include <gst/gst-i18n-plugin.h>
+#include "gsttcpelements.h"
 #include "gsttcpclientsrc.h"
 #include "gsttcpsrcstats.h"
 #include "gsttcp.h"
@@ -72,7 +73,8 @@ enum
 
 #define gst_tcp_client_src_parent_class parent_class
 G_DEFINE_TYPE (GstTCPClientSrc, gst_tcp_client_src, GST_TYPE_PUSH_SRC);
-
+GST_ELEMENT_REGISTER_DEFINE_WITH_CODE (tcpclientsrc, "tcpclientsrc",
+    GST_RANK_NONE, GST_TYPE_TCP_CLIENT_SRC, tcp_element_init (plugin));
 
 static void gst_tcp_client_src_finalize (GObject * gobject);
 
diff --git a/gst/tcp/gsttcpelement.c b/gst/tcp/gsttcpelement.c
new file mode 100644 (file)
index 0000000..6d0ebb2
--- /dev/null
@@ -0,0 +1,38 @@
+/* GStreamer
+ * Copyright (C) <1999> Erik Walthinsen <omega@cse.ogi.edu>
+ * Copyright (C) 2020 Huawei Technologies Co., Ltd.
+ *   @Author: Stéphane Cerveau <scerveau@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 "gsttcpelements.h"
+
+GST_DEBUG_CATEGORY (tcp_debug);
+
+void
+tcp_element_init (GstPlugin * plugin)
+{
+  static gsize res = FALSE;
+  if (g_once_init_enter (&res)) {
+    GST_DEBUG_CATEGORY_INIT (tcp_debug, "tcp", 0, "TCP calls");
+    g_once_init_leave (&res, TRUE);
+  }
+}
diff --git a/gst/tcp/gsttcpelements.h b/gst/tcp/gsttcpelements.h
new file mode 100644 (file)
index 0000000..c6f5edc
--- /dev/null
@@ -0,0 +1,39 @@
+/*
+ * 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_TCP_ELEMENTS_H__
+#define __GST_TCP_ELEMENTS_H__
+
+#include <gst/gst.h>
+
+G_BEGIN_DECLS
+
+G_GNUC_INTERNAL void tcp_element_init (GstPlugin * plugin);
+
+GST_ELEMENT_REGISTER_DECLARE (socketsrc);
+GST_ELEMENT_REGISTER_DECLARE (tcpclientsink);
+GST_ELEMENT_REGISTER_DECLARE (tcpclientsrc);
+GST_ELEMENT_REGISTER_DECLARE (tcpserversink);
+GST_ELEMENT_REGISTER_DECLARE (tcpserversrc);
+GST_ELEMENT_REGISTER_DECLARE (multifdsink);
+GST_ELEMENT_REGISTER_DECLARE (multisocketsink);
+
+G_END_DECLS
+
+#endif /* __GST_TCP_ELEMENTS_H__ */
index 49db6d3..723ae46 100644 (file)
 #include "config.h"
 #endif
 
-#include "gstsocketsrc.h"
-#include "gsttcpclientsrc.h"
-#include "gsttcpclientsink.h"
-#include "gsttcpserversrc.h"
-#include "gsttcpserversink.h"
-#include "gstmultifdsink.h"
-#include "gstmultisocketsink.h"
-
-GST_DEBUG_CATEGORY (tcp_debug);
+#include "gsttcpelements.h"
 
 static gboolean
 plugin_init (GstPlugin * plugin)
 {
-  if (!gst_element_register (plugin, "socketsrc", GST_RANK_NONE,
-          GST_TYPE_SOCKET_SRC))
-    return FALSE;
-  if (!gst_element_register (plugin, "tcpclientsink", GST_RANK_NONE,
-          GST_TYPE_TCP_CLIENT_SINK))
-    return FALSE;
-  if (!gst_element_register (plugin, "tcpclientsrc", GST_RANK_NONE,
-          GST_TYPE_TCP_CLIENT_SRC))
-    return FALSE;
-  if (!gst_element_register (plugin, "tcpserversink", GST_RANK_NONE,
-          GST_TYPE_TCP_SERVER_SINK))
-    return FALSE;
-  if (!gst_element_register (plugin, "tcpserversrc", GST_RANK_NONE,
-          GST_TYPE_TCP_SERVER_SRC))
-    return FALSE;
+  gboolean ret = FALSE;
+
+  ret |= GST_ELEMENT_REGISTER (socketsrc, plugin);
+  ret |= GST_ELEMENT_REGISTER (tcpclientsink, plugin);
+  ret |= GST_ELEMENT_REGISTER (tcpclientsrc, plugin);
+  ret |= GST_ELEMENT_REGISTER (tcpserversink, plugin);
+  ret |= GST_ELEMENT_REGISTER (tcpserversrc, plugin);
+
 #ifdef HAVE_SYS_SOCKET_H
-  if (!gst_element_register (plugin, "multifdsink", GST_RANK_NONE,
-          GST_TYPE_MULTI_FD_SINK))
-    return FALSE;
-#endif
-  if (!gst_element_register (plugin, "multisocketsink", GST_RANK_NONE,
-          GST_TYPE_MULTI_SOCKET_SINK))
-    return FALSE;
+  ret |= GST_ELEMENT_REGISTER (multifdsink, plugin);
 
-  GST_DEBUG_CATEGORY_INIT (tcp_debug, "tcp", 0, "TCP calls");
+#endif
+  ret |= GST_ELEMENT_REGISTER (multisocketsink, plugin);
 
-  return TRUE;
+  return ret;
 }
 
 GST_PLUGIN_DEFINE (GST_VERSION_MAJOR,
index 0e90f76..7053fa1 100644 (file)
@@ -41,6 +41,7 @@
 #include <string.h>             /* memset */
 
 #include "gsttcp.h"
+#include "gsttcpelements.h"
 #include "gsttcpserversink.h"
 
 #define TCP_BACKLOG             5
@@ -71,6 +72,8 @@ static void gst_tcp_server_sink_get_property (GObject * object, guint prop_id,
 #define gst_tcp_server_sink_parent_class parent_class
 G_DEFINE_TYPE (GstTCPServerSink, gst_tcp_server_sink,
     GST_TYPE_MULTI_SOCKET_SINK);
+GST_ELEMENT_REGISTER_DEFINE_WITH_CODE (tcpserversink, "tcpserversink",
+    GST_RANK_NONE, GST_TYPE_TCP_SERVER_SINK, tcp_element_init (plugin));
 
 static void
 gst_tcp_server_sink_class_init (GstTCPServerSinkClass * klass)
index 328f916..ead2819 100644 (file)
@@ -42,6 +42,7 @@
 
 #include <gst/gst-i18n-plugin.h>
 #include "gsttcp.h"
+#include "gsttcpelements.h"
 #include "gsttcpsrcstats.h"
 #include "gsttcpserversrc.h"
 
@@ -69,6 +70,8 @@ enum
 
 #define gst_tcp_server_src_parent_class parent_class
 G_DEFINE_TYPE (GstTCPServerSrc, gst_tcp_server_src, GST_TYPE_PUSH_SRC);
+GST_ELEMENT_REGISTER_DEFINE_WITH_CODE (tcpserversrc, "tcpserversrc",
+    GST_RANK_NONE, GST_TYPE_TCP_SERVER_SRC, tcp_element_init (plugin));
 
 static void gst_tcp_server_src_finalize (GObject * gobject);
 
index 93dfb60..d6274c2 100644 (file)
@@ -4,6 +4,7 @@ tcp_sources = [
   'gstsocketsrc.c',
   'gsttcpclientsrc.c',
   'gsttcpclientsink.c',
+  'gsttcpelement.c',
   'gsttcpserversrc.c',
   'gsttcpserversink.c',
   'gsttcpsrcstats.c',