diff --git a/gst/tcp/gstmultifdsink.c b/gst/tcp/gstmultifdsink.c index e151dfc73b..d67f772868 100644 --- a/gst/tcp/gstmultifdsink.c +++ b/gst/tcp/gstmultifdsink.c @@ -119,6 +119,7 @@ #include #include +#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 }; diff --git a/gst/tcp/gstmultisocketsink.c b/gst/tcp/gstmultisocketsink.c index da7eaf5f18..81a4543c8c 100644 --- a/gst/tcp/gstmultisocketsink.c +++ b/gst/tcp/gstmultisocketsink.c @@ -109,6 +109,7 @@ #include #include "gstmultisocketsink.h" +#include "gsttcpelements.h" #ifndef G_OS_WIN32 #include @@ -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 }; diff --git a/gst/tcp/gstsocketsrc.c b/gst/tcp/gstsocketsrc.c index 0372f91a3b..613f985fab 100644 --- a/gst/tcp/gstsocketsrc.c +++ b/gst/tcp/gstsocketsrc.c @@ -51,6 +51,7 @@ #include #include +#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); diff --git a/gst/tcp/gsttcpclientsink.c b/gst/tcp/gsttcpclientsink.c index b44de0469f..6b701d2666 100644 --- a/gst/tcp/gsttcpclientsink.c +++ b/gst/tcp/gsttcpclientsink.c @@ -44,6 +44,7 @@ #include #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) diff --git a/gst/tcp/gsttcpclientsrc.c b/gst/tcp/gsttcpclientsrc.c index d64856ed4d..980edd4c51 100644 --- a/gst/tcp/gsttcpclientsrc.c +++ b/gst/tcp/gsttcpclientsrc.c @@ -44,6 +44,7 @@ #endif #include +#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 index 0000000000..6d0ebb2d5c --- /dev/null +++ b/gst/tcp/gsttcpelement.c @@ -0,0 +1,38 @@ +/* GStreamer + * Copyright (C) <1999> Erik Walthinsen + * Copyright (C) 2020 Huawei Technologies Co., Ltd. + * @Author: Stéphane Cerveau + * + * 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 index 0000000000..c6f5edcc5e --- /dev/null +++ b/gst/tcp/gsttcpelements.h @@ -0,0 +1,39 @@ +/* + * 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_TCP_ELEMENTS_H__ +#define __GST_TCP_ELEMENTS_H__ + +#include + +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__ */ diff --git a/gst/tcp/gsttcpplugin.c b/gst/tcp/gsttcpplugin.c index 49db6d3ea1..723ae46c29 100644 --- a/gst/tcp/gsttcpplugin.c +++ b/gst/tcp/gsttcpplugin.c @@ -21,46 +21,26 @@ #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; + ret |= GST_ELEMENT_REGISTER (multifdsink, plugin); + #endif - if (!gst_element_register (plugin, "multisocketsink", GST_RANK_NONE, - GST_TYPE_MULTI_SOCKET_SINK)) - return FALSE; + ret |= GST_ELEMENT_REGISTER (multisocketsink, plugin); - GST_DEBUG_CATEGORY_INIT (tcp_debug, "tcp", 0, "TCP calls"); - - return TRUE; + return ret; } GST_PLUGIN_DEFINE (GST_VERSION_MAJOR, diff --git a/gst/tcp/gsttcpserversink.c b/gst/tcp/gsttcpserversink.c index 0e90f7631c..7053fa1df0 100644 --- a/gst/tcp/gsttcpserversink.c +++ b/gst/tcp/gsttcpserversink.c @@ -41,6 +41,7 @@ #include /* 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) diff --git a/gst/tcp/gsttcpserversrc.c b/gst/tcp/gsttcpserversrc.c index 328f916423..ead28191ec 100644 --- a/gst/tcp/gsttcpserversrc.c +++ b/gst/tcp/gsttcpserversrc.c @@ -42,6 +42,7 @@ #include #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); diff --git a/gst/tcp/meson.build b/gst/tcp/meson.build index 93dfb6056a..d6274c2311 100644 --- a/gst/tcp/meson.build +++ b/gst/tcp/meson.build @@ -4,6 +4,7 @@ tcp_sources = [ 'gstsocketsrc.c', 'gsttcpclientsrc.c', 'gsttcpclientsink.c', + 'gsttcpelement.c', 'gsttcpserversrc.c', 'gsttcpserversink.c', 'gsttcpsrcstats.c',