From bbe0258e1d2a17cef0c66782217d4f0ecd3ee483 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?St=C3=A9phane=20Cerveau?= Date: Wed, 24 Feb 2021 12:39:22 +0100 Subject: [PATCH] srt: 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: --- ext/srt/gstsrt.c | 105 +++++---------------------------------- ext/srt/gstsrtelement.c | 90 +++++++++++++++++++++++++++++++++ ext/srt/gstsrtelements.h | 39 +++++++++++++++ ext/srt/gstsrtplugin.c | 52 +++++++++++++++++++ ext/srt/gstsrtsink.c | 3 ++ ext/srt/gstsrtsrc.c | 3 ++ ext/srt/meson.build | 2 + 7 files changed, 201 insertions(+), 93 deletions(-) create mode 100644 ext/srt/gstsrtelement.c create mode 100644 ext/srt/gstsrtelements.h create mode 100644 ext/srt/gstsrtplugin.c diff --git a/ext/srt/gstsrt.c b/ext/srt/gstsrt.c index b498076665..358dd48170 100644 --- a/ext/srt/gstsrt.c +++ b/ext/srt/gstsrt.c @@ -22,13 +22,10 @@ #include "config.h" #endif +#include "gstsrtelements.h" #include "gstsrtsrc.h" #include "gstsrtsink.h" -GST_DEBUG_CATEGORY_STATIC (gst_debug_srtlib); -GST_DEBUG_CATEGORY (gst_debug_srtobject); -#define GST_CAT_DEFAULT gst_debug_srtobject - #ifndef GST_REMOVE_DEPRECATED #define GST_TYPE_SRT_CLIENT_SRC gst_srt_client_src_get_type() @@ -55,9 +52,20 @@ static GType gst_srt_client_sink_get_type (void); static GType gst_srt_server_sink_get_type (void); G_DEFINE_TYPE (GstSRTClientSrc, gst_srt_client_src, GST_TYPE_SRT_SRC); +GST_ELEMENT_REGISTER_DEFINE_WITH_CODE (srtclientsrc, "srtclientsrc", + GST_RANK_NONE, GST_TYPE_SRT_CLIENT_SRC, srt_element_init (plugin)); + G_DEFINE_TYPE (GstSRTServerSrc, gst_srt_server_src, GST_TYPE_SRT_SRC); +GST_ELEMENT_REGISTER_DEFINE_WITH_CODE (srtserversrc, "srtserversrc", + GST_RANK_NONE, GST_TYPE_SRT_SERVER_SRC, srt_element_init (plugin)); + G_DEFINE_TYPE (GstSRTClientSink, gst_srt_client_sink, GST_TYPE_SRT_SINK); +GST_ELEMENT_REGISTER_DEFINE_WITH_CODE (srtclientsink, "srtclientsink", + GST_RANK_NONE, GST_TYPE_SRT_CLIENT_SINK, srt_element_init (plugin)); + G_DEFINE_TYPE (GstSRTServerSink, gst_srt_server_sink, GST_TYPE_SRT_SINK); +GST_ELEMENT_REGISTER_DEFINE_WITH_CODE (srtserversink, "srtserversink", + GST_RANK_NONE, GST_TYPE_SRT_SERVER_SINK, srt_element_init (plugin)); static void gst_srt_client_src_init (GstSRTClientSrc * src) @@ -100,92 +108,3 @@ gst_srt_server_sink_class_init (GstSRTServerSinkClass * klass) } #endif - -#ifndef GST_DISABLE_GST_DEBUG -static void -gst_srt_log_handler (void *opaque, int level, const char *file, int line, - const char *area, const char *message) -{ - GstDebugLevel gst_level; - - switch (level) { - case LOG_CRIT: - gst_level = GST_LEVEL_ERROR; - break; - - case LOG_ERR: - gst_level = GST_LEVEL_WARNING; - break; - - case LOG_WARNING: - gst_level = GST_LEVEL_INFO; - break; - - case LOG_NOTICE: - gst_level = GST_LEVEL_DEBUG; - break; - - case LOG_DEBUG: - gst_level = GST_LEVEL_LOG; - break; - - default: - gst_level = GST_LEVEL_FIXME; - break; - } - - if (G_UNLIKELY (gst_level <= _gst_debug_min)) { - gst_debug_log (gst_debug_srtlib, gst_level, file, area, line, NULL, "%s", - message); - } -} -#endif - -static gboolean -plugin_init (GstPlugin * plugin) -{ - GST_DEBUG_CATEGORY_INIT (gst_debug_srtobject, "srtobject", 0, "SRT Object"); - GST_DEBUG_CATEGORY_INIT (gst_debug_srtlib, "srtlib", 0, "SRT Library"); - -#ifndef GST_DISABLE_GST_DEBUG - srt_setloghandler (NULL, gst_srt_log_handler); - srt_setlogflags (SRT_LOGF_DISABLE_TIME | SRT_LOGF_DISABLE_THREADNAME | - SRT_LOGF_DISABLE_SEVERITY | SRT_LOGF_DISABLE_EOL); - srt_setloglevel (LOG_DEBUG); -#endif - - if (!gst_element_register (plugin, "srtsrc", GST_RANK_PRIMARY, - GST_TYPE_SRT_SRC)) - return FALSE; - - if (!gst_element_register (plugin, "srtsink", GST_RANK_PRIMARY, - GST_TYPE_SRT_SINK)) - return FALSE; - - /* deprecated */ -#ifndef GST_REMOVE_DEPRECATED - if (!gst_element_register (plugin, "srtclientsrc", GST_RANK_NONE, - GST_TYPE_SRT_CLIENT_SRC)) - return FALSE; - - if (!gst_element_register (plugin, "srtserversrc", GST_RANK_NONE, - GST_TYPE_SRT_SERVER_SRC)) - return FALSE; - - if (!gst_element_register (plugin, "srtclientsink", GST_RANK_NONE, - GST_TYPE_SRT_CLIENT_SINK)) - return FALSE; - - if (!gst_element_register (plugin, "srtserversink", GST_RANK_NONE, - GST_TYPE_SRT_SERVER_SINK)) - return FALSE; -#endif - - return TRUE; -} - -GST_PLUGIN_DEFINE (GST_VERSION_MAJOR, - GST_VERSION_MINOR, - srt, - "transfer data via SRT", - plugin_init, VERSION, GST_LICENSE, GST_PACKAGE_NAME, GST_PACKAGE_ORIGIN); diff --git a/ext/srt/gstsrtelement.c b/ext/srt/gstsrtelement.c new file mode 100644 index 0000000000..87f7bb6e5d --- /dev/null +++ b/ext/srt/gstsrtelement.c @@ -0,0 +1,90 @@ +/* GStreamer + * Copyright (C) 2017, Collabora Ltd. + * Author:Justin Kim + * Copyright (C) <2020> The GStreamer Contributors. + * + * 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 "gstsrtelements.h" +#include + + +GST_DEBUG_CATEGORY_STATIC (gst_debug_srtlib); +GST_DEBUG_CATEGORY (gst_debug_srtobject); +#define GST_CAT_DEFAULT gst_debug_srtobject + +#ifndef GST_DISABLE_GST_DEBUG +static void +gst_srt_log_handler (void *opaque, int level, const char *file, int line, + const char *area, const char *message) +{ + GstDebugLevel gst_level; + + switch (level) { + case LOG_CRIT: + gst_level = GST_LEVEL_ERROR; + break; + + case LOG_ERR: + gst_level = GST_LEVEL_WARNING; + break; + + case LOG_WARNING: + gst_level = GST_LEVEL_INFO; + break; + + case LOG_NOTICE: + gst_level = GST_LEVEL_DEBUG; + break; + + case LOG_DEBUG: + gst_level = GST_LEVEL_LOG; + break; + + default: + gst_level = GST_LEVEL_FIXME; + break; + } + + if (G_UNLIKELY (gst_level <= _gst_debug_min)) { + gst_debug_log (gst_debug_srtlib, gst_level, file, area, line, NULL, "%s", + message); + } +} +#endif + +void +srt_element_init (GstPlugin * plugin) +{ + static gsize res = FALSE; + + if (g_once_init_enter (&res)) { + GST_DEBUG_CATEGORY_INIT (gst_debug_srtobject, "srtobject", 0, "SRT Object"); + GST_DEBUG_CATEGORY_INIT (gst_debug_srtlib, "srtlib", 0, "SRT Library"); +#ifndef GST_DISABLE_GST_DEBUG + srt_setloghandler (NULL, gst_srt_log_handler); + srt_setlogflags (SRT_LOGF_DISABLE_TIME | SRT_LOGF_DISABLE_THREADNAME | + SRT_LOGF_DISABLE_SEVERITY | SRT_LOGF_DISABLE_EOL); + srt_setloglevel (LOG_DEBUG); +#endif + g_once_init_leave (&res, TRUE); + } +} diff --git a/ext/srt/gstsrtelements.h b/ext/srt/gstsrtelements.h new file mode 100644 index 0000000000..c89e1742a0 --- /dev/null +++ b/ext/srt/gstsrtelements.h @@ -0,0 +1,39 @@ +/* GStreamer + * Copyright (C) <2020> The GStreamer Contributors. + * + * 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_SRT_ELEMENTS_H__ +#define __GST_SRT_ELEMENTS_H__ + +#ifdef HAVE_CONFIG_H +#include +#endif + +#include + +void srt_element_init (GstPlugin * plugin); + +GST_ELEMENT_REGISTER_DECLARE (srtclientsrc); +GST_ELEMENT_REGISTER_DECLARE (srtserversrc); +GST_ELEMENT_REGISTER_DECLARE (srtclientsink); +GST_ELEMENT_REGISTER_DECLARE (srtserversink); +GST_ELEMENT_REGISTER_DECLARE (srtsink); +GST_ELEMENT_REGISTER_DECLARE (srtsrc); + +#endif /* __GST_SRT_ELEMENT_H__ */ diff --git a/ext/srt/gstsrtplugin.c b/ext/srt/gstsrtplugin.c new file mode 100644 index 0000000000..562b11d462 --- /dev/null +++ b/ext/srt/gstsrtplugin.c @@ -0,0 +1,52 @@ +/* GStreamer + * Copyright (C) 2017, Collabora Ltd. + * Author:Justin Kim + * Copyright (C) <2020> The GStreamer Contributors. + * + * 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 "gstsrtelements.h" + + +static gboolean +plugin_init (GstPlugin * plugin) +{ + gboolean ret = FALSE; + + ret |= GST_ELEMENT_REGISTER (srtsrc, plugin); + ret |= GST_ELEMENT_REGISTER (srtsink, plugin); + + /* deprecated */ +#ifndef GST_REMOVE_DEPRECATED + ret |= GST_ELEMENT_REGISTER (srtclientsrc, plugin); + ret |= GST_ELEMENT_REGISTER (srtserversrc, plugin); + ret |= GST_ELEMENT_REGISTER (srtclientsink, plugin); + ret |= GST_ELEMENT_REGISTER (srtserversink, plugin); +#endif + + return ret; +} + +GST_PLUGIN_DEFINE (GST_VERSION_MAJOR, + GST_VERSION_MINOR, + srt, + "transfer data via SRT", + plugin_init, VERSION, GST_LICENSE, GST_PACKAGE_NAME, GST_PACKAGE_ORIGIN); diff --git a/ext/srt/gstsrtsink.c b/ext/srt/gstsrtsink.c index 53ef6a13da..3cb00bc52b 100644 --- a/ext/srt/gstsrtsink.c +++ b/ext/srt/gstsrtsink.c @@ -42,6 +42,7 @@ #include #endif +#include "gstsrtelements.h" #include "gstsrtsink.h" static GstStaticPadTemplate sink_template = GST_STATIC_PAD_TEMPLATE ("sink", @@ -78,6 +79,8 @@ G_DEFINE_TYPE_WITH_CODE (GstSRTSink, gst_srt_sink, GST_TYPE_BASE_SINK, G_IMPLEMENT_INTERFACE (GST_TYPE_URI_HANDLER, gst_srt_sink_uri_handler_init) GST_DEBUG_CATEGORY_INIT (GST_CAT_DEFAULT, "srtsink", 0, "SRT Sink")); +GST_ELEMENT_REGISTER_DEFINE_WITH_CODE (srtsink, "srtsink", GST_RANK_PRIMARY, + GST_TYPE_SRT_SINK, srt_element_init (plugin)); static gboolean default_caller_connecting (GstSRTSink * self, diff --git a/ext/srt/gstsrtsrc.c b/ext/srt/gstsrtsrc.c index 7e1e6b7c00..7a47f407fe 100644 --- a/ext/srt/gstsrtsrc.c +++ b/ext/srt/gstsrtsrc.c @@ -45,6 +45,7 @@ #include #endif +#include "gstsrtelements.h" #include "gstsrtsrc.h" static GstStaticPadTemplate src_template = GST_STATIC_PAD_TEMPLATE ("src", @@ -81,6 +82,8 @@ G_DEFINE_TYPE_WITH_CODE (GstSRTSrc, gst_srt_src, GST_TYPE_PUSH_SRC, G_IMPLEMENT_INTERFACE (GST_TYPE_URI_HANDLER, gst_srt_src_uri_handler_init) GST_DEBUG_CATEGORY_INIT (GST_CAT_DEFAULT, "srtsrc", 0, "SRT Source")); +GST_ELEMENT_REGISTER_DEFINE_WITH_CODE (srtsrc, "srtsrc", GST_RANK_PRIMARY, + GST_TYPE_SRT_SRC, srt_element_init (plugin)); static gboolean src_default_caller_connecting (GstSRTSrc * self, diff --git a/ext/srt/meson.build b/ext/srt/meson.build index 195e8be853..0966336341 100644 --- a/ext/srt/meson.build +++ b/ext/srt/meson.build @@ -1,5 +1,7 @@ srt_sources = [ 'gstsrt.c', + 'gstsrtelement.c', + 'gstsrtplugin.c', 'gstsrtobject.c', 'gstsrtsink.c', 'gstsrtsrc.c'