From 0b07d970fe06ec975a4ef0da88d06b555184d7da Mon Sep 17 00:00:00 2001 From: =?utf8?q?St=C3=A9phane=20Cerveau?= Date: Wed, 24 Feb 2021 13:07:30 +0100 Subject: [PATCH] ttml: 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/ttml/gstttmlelement.c | 42 ++++++++++++++++++++++++++++++++++++++++++ ext/ttml/gstttmlelements.h | 35 +++++++++++++++++++++++++++++++++++ ext/ttml/gstttmlparse.c | 24 +++++++++++++++++++++++- ext/ttml/gstttmlplugin.c | 27 +++++---------------------- ext/ttml/gstttmlrender.c | 23 +++++++++++++++++++++++ ext/ttml/meson.build | 1 + 6 files changed, 129 insertions(+), 23 deletions(-) create mode 100644 ext/ttml/gstttmlelement.c create mode 100644 ext/ttml/gstttmlelements.h diff --git a/ext/ttml/gstttmlelement.c b/ext/ttml/gstttmlelement.c new file mode 100644 index 0000000..97e9103 --- /dev/null +++ b/ext/ttml/gstttmlelement.c @@ -0,0 +1,42 @@ +/* GStreamer + * Copyright (C) <1999> Erik Walthinsen + * Copyright (C) 2004 Ronald S. Bultje + * Copyright (C) 2006 Tim-Philipp Müller + * Copyright (C) <2015> British Broadcasting Corporation + * + * 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 +#endif + +#include "gstttmlelements.h" + + +GST_DEBUG_CATEGORY (ttmlrender_debug); + +void +ttml_element_init (GstPlugin * plugin) +{ + static gsize res = FALSE; + + if (g_once_init_enter (&res)) { + gst_plugin_add_dependency_simple (plugin, "GST_TTML_AUTOPLUG", NULL, NULL, + GST_PLUGIN_DEPENDENCY_FLAG_NONE); + g_once_init_leave (&res, TRUE); + } +} diff --git a/ext/ttml/gstttmlelements.h b/ext/ttml/gstttmlelements.h new file mode 100644 index 0000000..000d1ce --- /dev/null +++ b/ext/ttml/gstttmlelements.h @@ -0,0 +1,35 @@ +/* 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_TTML_ELEMENTS_H__ +#define __GST_TTML_ELEMENTS_H__ + +#ifdef HAVE_CONFIG_H +#include +#endif + +#include + +void ttml_element_init (GstPlugin * plugin); + +GST_ELEMENT_REGISTER_DECLARE (ttmlparse); +GST_ELEMENT_REGISTER_DECLARE (ttmlrender); + +#endif /* __GST_TTML_ELEMENTS_H__ */ diff --git a/ext/ttml/gstttmlparse.c b/ext/ttml/gstttmlparse.c index d827a48..7966fba 100644 --- a/ext/ttml/gstttmlparse.c +++ b/ext/ttml/gstttmlparse.c @@ -50,12 +50,14 @@ #include #include +#include "gstttmlelements.h" #include "gstttmlparse.h" #include "ttmlparse.h" -GST_DEBUG_CATEGORY_EXTERN (ttmlparse_debug); +GST_DEBUG_CATEGORY (ttmlparse_debug); #define GST_CAT_DEFAULT ttmlparse_debug + #define DEFAULT_ENCODING NULL static GstStaticPadTemplate sink_templ = GST_STATIC_PAD_TEMPLATE ("sink", @@ -82,9 +84,11 @@ static GstStateChangeReturn gst_ttml_parse_change_state (GstElement * element, static GstFlowReturn gst_ttml_parse_chain (GstPad * sinkpad, GstObject * parent, GstBuffer * buf); +static gboolean gst_element_ttmlparse_init (GstPlugin * plugin); #define gst_ttml_parse_parent_class parent_class G_DEFINE_TYPE (GstTtmlParse, gst_ttml_parse, GST_TYPE_ELEMENT); +GST_ELEMENT_REGISTER_DEFINE_CUSTOM (ttmlparse, gst_element_ttmlparse_init); static void gst_ttml_parse_dispose (GObject * object) @@ -596,3 +600,21 @@ gst_ttml_parse_change_state (GstElement * element, GstStateChange transition) return ret; } + +static gboolean +gst_element_ttmlparse_init (GstPlugin * plugin) +{ + guint rank = GST_RANK_NONE; + + ttml_element_init (plugin); + + /* We don't want this autoplugged by default yet for now */ + if (g_getenv ("GST_TTML_AUTOPLUG")) { + GST_INFO_OBJECT (plugin, "Registering ttml elements with primary rank."); + rank = GST_RANK_PRIMARY; + } + + GST_DEBUG_CATEGORY_INIT (ttmlparse_debug, "ttmlparse", 0, "TTML parser"); + + return gst_element_register (plugin, "ttmlparse", rank, GST_TYPE_TTML_PARSE); +} diff --git a/ext/ttml/gstttmlplugin.c b/ext/ttml/gstttmlplugin.c index 9137a8f..cb36c49 100644 --- a/ext/ttml/gstttmlplugin.c +++ b/ext/ttml/gstttmlplugin.c @@ -24,35 +24,18 @@ #include #endif -#include "gstttmlparse.h" -#include "gstttmlrender.h" +#include "gstttmlelements.h" -GST_DEBUG_CATEGORY (ttmlparse_debug); -GST_DEBUG_CATEGORY (ttmlrender_debug); static gboolean plugin_init (GstPlugin * plugin) { - guint rank = GST_RANK_NONE; + gboolean ret = FALSE; - /* We don't want this autoplugged by default yet for now */ - if (g_getenv ("GST_TTML_AUTOPLUG")) { - GST_INFO_OBJECT (plugin, "Registering ttml elements with primary rank."); - rank = GST_RANK_PRIMARY; - } + ret |= GST_ELEMENT_REGISTER (ttmlparse, plugin); + ret |= GST_ELEMENT_REGISTER (ttmlrender, plugin); - gst_plugin_add_dependency_simple (plugin, "GST_TTML_AUTOPLUG", NULL, NULL, - GST_PLUGIN_DEPENDENCY_FLAG_NONE); - - if (!gst_element_register (plugin, "ttmlparse", rank, GST_TYPE_TTML_PARSE)) - return FALSE; - if (!gst_element_register (plugin, "ttmlrender", rank, GST_TYPE_TTML_RENDER)) - return FALSE; - - GST_DEBUG_CATEGORY_INIT (ttmlparse_debug, "ttmlparse", 0, "TTML parser"); - GST_DEBUG_CATEGORY_INIT (ttmlrender_debug, "ttmlrender", 0, "TTML renderer"); - - return TRUE; + return ret; } GST_PLUGIN_DEFINE (GST_VERSION_MAJOR, diff --git a/ext/ttml/gstttmlrender.c b/ext/ttml/gstttmlrender.c index f8d063f..8589d6b 100644 --- a/ext/ttml/gstttmlrender.c +++ b/ext/ttml/gstttmlrender.c @@ -48,6 +48,7 @@ #include #include +#include "gstttmlelements.h" #include "gstttmlrender.h" #include "subtitle.h" #include "subtitlemeta.h" @@ -196,6 +197,7 @@ static GstTtmlRenderRenderedImage *gst_ttml_render_stitch_images (GPtrArray * images, GstTtmlDirection direction); static gboolean gst_ttml_render_color_is_transparent (GstSubtitleColor * color); +static gboolean gst_element_ttmlrender_init (GstPlugin * plugin); GType gst_ttml_render_get_type (void) @@ -222,6 +224,8 @@ gst_ttml_render_get_type (void) return type; } +GST_ELEMENT_REGISTER_DEFINE_CUSTOM (ttmlrender, gst_element_ttmlrender_init); + static void gst_ttml_render_base_init (gpointer g_class) { @@ -3059,3 +3063,22 @@ gst_ttml_render_change_state (GstElement * element, GstStateChange transition) return ret; } + +static gboolean +gst_element_ttmlrender_init (GstPlugin * plugin) +{ + guint rank = GST_RANK_NONE; + + ttml_element_init (plugin); + + /* We don't want this autoplugged by default yet for now */ + if (g_getenv ("GST_TTML_AUTOPLUG")) { + GST_INFO_OBJECT (plugin, "Registering ttml elements with primary rank."); + rank = GST_RANK_PRIMARY; + } + + GST_DEBUG_CATEGORY_INIT (ttmlrender_debug, "ttmlrender", 0, "TTML renderer"); + + return gst_element_register (plugin, "ttmlrender", rank, + GST_TYPE_TTML_RENDER); +} diff --git a/ext/ttml/meson.build b/ext/ttml/meson.build index 2d22fdf..710a440 100644 --- a/ext/ttml/meson.build +++ b/ext/ttml/meson.build @@ -10,6 +10,7 @@ if libxml_dep.found() and pango_dep.found() and cairo_dep.found() and pangocairo 'gstttmlparse.c', 'ttmlparse.c', 'gstttmlrender.c', + 'gstttmlelement.c', 'gstttmlplugin.c'], c_args : gst_plugins_bad_args, include_directories : [configinc], -- 2.7.4