From f86147cb6d19ab998376871f59c33e0d348a7b9a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?St=C3=A9phane=20Cerveau?= Date: Fri, 12 Feb 2021 08:57:55 +0100 Subject: [PATCH] gdk_pixbuf: 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/gdk_pixbuf/gstgdkpixbufdec.c | 4 ++ ext/gdk_pixbuf/gstgdkpixbufelement.c | 89 +++++++++++++++++++++++++++ ext/gdk_pixbuf/gstgdkpixbufelements.h | 37 +++++++++++ ext/gdk_pixbuf/gstgdkpixbufoverlay.c | 4 ++ ext/gdk_pixbuf/gstgdkpixbufplugin.c | 74 ++-------------------- ext/gdk_pixbuf/gstgdkpixbufsink.c | 3 + ext/gdk_pixbuf/meson.build | 1 + 7 files changed, 144 insertions(+), 68 deletions(-) create mode 100644 ext/gdk_pixbuf/gstgdkpixbufelement.c create mode 100644 ext/gdk_pixbuf/gstgdkpixbufelements.h diff --git a/ext/gdk_pixbuf/gstgdkpixbufdec.c b/ext/gdk_pixbuf/gstgdkpixbufdec.c index dbcac203e3..5482998c0d 100644 --- a/ext/gdk_pixbuf/gstgdkpixbufdec.c +++ b/ext/gdk_pixbuf/gstgdkpixbufdec.c @@ -27,6 +27,7 @@ #include #include +#include "gstgdkpixbufelements.h" #include "gstgdkpixbufdec.h" GST_DEBUG_CATEGORY_STATIC (gdkpixbufdec_debug); @@ -74,6 +75,9 @@ static gboolean gst_gdk_pixbuf_dec_sink_event (GstPad * pad, GstObject * parent, #define gst_gdk_pixbuf_dec_parent_class parent_class G_DEFINE_TYPE (GstGdkPixbufDec, gst_gdk_pixbuf_dec, GST_TYPE_ELEMENT); +GST_ELEMENT_REGISTER_DEFINE_WITH_CODE (gdkpixbufdec, "gdkpixbufdec", + GST_RANK_SECONDARY, GST_TYPE_GDK_PIXBUF_DEC, + gdk_pixbuf_element_init (plugin)); static gboolean gst_gdk_pixbuf_dec_sink_setcaps (GstGdkPixbufDec * filter, GstCaps * caps) diff --git a/ext/gdk_pixbuf/gstgdkpixbufelement.c b/ext/gdk_pixbuf/gstgdkpixbufelement.c new file mode 100644 index 0000000000..32bac343c3 --- /dev/null +++ b/ext/gdk_pixbuf/gstgdkpixbufelement.c @@ -0,0 +1,89 @@ +/* GStreamer GdkPixbuf plugin + * Copyright (C) 1999-2001 Erik Walthinsen + * Copyright (C) 2003 David A. Schleef + * + * 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 + +#include "gstgdkpixbufelements.h" + +#if 0 +static void gst_gdk_pixbuf_type_find (GstTypeFind * tf, gpointer ignore); + +#define GST_GDK_PIXBUF_TYPE_FIND_SIZE 1024 + +static void +gst_gdk_pixbuf_type_find (GstTypeFind * tf, gpointer ignore) +{ + guint8 *data; + GdkPixbufLoader *pixbuf_loader; + GdkPixbufFormat *format; + + data = gst_type_find_peek (tf, 0, GST_GDK_PIXBUF_TYPE_FIND_SIZE); + if (data == NULL) + return; + + GST_DEBUG ("creating new loader"); + + pixbuf_loader = gdk_pixbuf_loader_new (); + + gdk_pixbuf_loader_write (pixbuf_loader, data, GST_GDK_PIXBUF_TYPE_FIND_SIZE, + NULL); + + format = gdk_pixbuf_loader_get_format (pixbuf_loader); + + if (format != NULL) { + GstCaps *caps; + gchar **p; + gchar **mlist = gdk_pixbuf_format_get_mime_types (format); + + for (p = mlist; *p; ++p) { + GST_DEBUG ("suggesting mime type %s", *p); + caps = gst_caps_new_simple (*p, NULL); + gst_type_find_suggest (tf, GST_TYPE_FIND_MINIMUM, caps); + gst_caps_free (caps); + } + g_strfreev (mlist); + } + + GST_DEBUG ("closing pixbuf loader, hope it doesn't hang ..."); + /* librsvg 2.4.x has a bug where it triggers an endless loop in trying + to close a gzip that's not an svg; fixed upstream but no good way + to work around it */ + gdk_pixbuf_loader_close (pixbuf_loader, NULL); + GST_DEBUG ("closed pixbuf loader"); + g_object_unref (G_OBJECT (pixbuf_loader)); +} +#endif + +void +gdk_pixbuf_element_init (GstPlugin * plugin) +{ + static gsize res = FALSE; + if (g_once_init_enter (&res)) { +#if 0 + gst_type_find_register (plugin, "image/*", GST_RANK_MARGINAL, + gst_gdk_pixbuf_type_find, NULL, GST_CAPS_ANY, NULL); +#endif + g_once_init_leave (&res, TRUE); + } +} diff --git a/ext/gdk_pixbuf/gstgdkpixbufelements.h b/ext/gdk_pixbuf/gstgdkpixbufelements.h new file mode 100644 index 0000000000..cd18b3503f --- /dev/null +++ b/ext/gdk_pixbuf/gstgdkpixbufelements.h @@ -0,0 +1,37 @@ +/* + * Copyright (C) 1999-2001 Erik Walthinsen + * Copyright (C) 2003 David A. Schleef + * 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_GDK_PIXBUF_ELEMENTS_H__ +#define __GST_GDK_PIXBUF_ELEMENTS_H__ + +#include + +G_BEGIN_DECLS + +void gdk_pixbuf_element_init (GstPlugin * plugin); + +GST_ELEMENT_REGISTER_DECLARE (gdkpixbufdec); +GST_ELEMENT_REGISTER_DECLARE (gdkpixbufoverlay); +GST_ELEMENT_REGISTER_DECLARE (gdkpixbufsink); + +G_END_DECLS + +#endif /* __GST_GDK_PIXBUF_ELEMENTS_H__ */ diff --git a/ext/gdk_pixbuf/gstgdkpixbufoverlay.c b/ext/gdk_pixbuf/gstgdkpixbufoverlay.c index 00da3cb593..a2585f385d 100644 --- a/ext/gdk_pixbuf/gstgdkpixbufoverlay.c +++ b/ext/gdk_pixbuf/gstgdkpixbufoverlay.c @@ -49,6 +49,7 @@ #include #include "gstgdkpixbufoverlay.h" +#include "gstgdkpixbufelements.h" #include GST_DEBUG_CATEGORY_STATIC (gdkpixbufoverlay_debug); @@ -113,6 +114,9 @@ static GstStaticPadTemplate src_template = GST_STATIC_PAD_TEMPLATE ("src", G_DEFINE_TYPE (GstGdkPixbufOverlay, gst_gdk_pixbuf_overlay, GST_TYPE_VIDEO_FILTER); +GST_ELEMENT_REGISTER_DEFINE_WITH_CODE (gdkpixbufoverlay, "gdkpixbufoverlay", + GST_RANK_NONE, GST_TYPE_GDK_PIXBUF_OVERLAY, + gdk_pixbuf_element_init (plugin)); #define GST_TYPE_GDK_PIXBUF_POSITIONING_MODE \ (gst_gdk_pixbuf_positioning_mode_get_type()) diff --git a/ext/gdk_pixbuf/gstgdkpixbufplugin.c b/ext/gdk_pixbuf/gstgdkpixbufplugin.c index 4f58b9d478..123063f0e7 100644 --- a/ext/gdk_pixbuf/gstgdkpixbufplugin.c +++ b/ext/gdk_pixbuf/gstgdkpixbufplugin.c @@ -24,81 +24,19 @@ #include -#include "gstgdkpixbufdec.h" -#include "gstgdkpixbufoverlay.h" -#include "gstgdkpixbufsink.h" +#include "gstgdkpixbufelements.h" -#if 0 -static void gst_gdk_pixbuf_type_find (GstTypeFind * tf, gpointer ignore); - -#define GST_GDK_PIXBUF_TYPE_FIND_SIZE 1024 - -static void -gst_gdk_pixbuf_type_find (GstTypeFind * tf, gpointer ignore) -{ - guint8 *data; - GdkPixbufLoader *pixbuf_loader; - GdkPixbufFormat *format; - - data = gst_type_find_peek (tf, 0, GST_GDK_PIXBUF_TYPE_FIND_SIZE); - if (data == NULL) - return; - - GST_DEBUG ("creating new loader"); - - pixbuf_loader = gdk_pixbuf_loader_new (); - - gdk_pixbuf_loader_write (pixbuf_loader, data, GST_GDK_PIXBUF_TYPE_FIND_SIZE, - NULL); - - format = gdk_pixbuf_loader_get_format (pixbuf_loader); - - if (format != NULL) { - GstCaps *caps; - gchar **p; - gchar **mlist = gdk_pixbuf_format_get_mime_types (format); - - for (p = mlist; *p; ++p) { - GST_DEBUG ("suggesting mime type %s", *p); - caps = gst_caps_new_simple (*p, NULL); - gst_type_find_suggest (tf, GST_TYPE_FIND_MINIMUM, caps); - gst_caps_free (caps); - } - g_strfreev (mlist); - } - - GST_DEBUG ("closing pixbuf loader, hope it doesn't hang ..."); - /* librsvg 2.4.x has a bug where it triggers an endless loop in trying - to close a gzip that's not an svg; fixed upstream but no good way - to work around it */ - gdk_pixbuf_loader_close (pixbuf_loader, NULL); - GST_DEBUG ("closed pixbuf loader"); - g_object_unref (G_OBJECT (pixbuf_loader)); -} -#endif - static gboolean plugin_init (GstPlugin * plugin) { - if (!gst_element_register (plugin, "gdkpixbufdec", GST_RANK_SECONDARY, - GST_TYPE_GDK_PIXBUF_DEC)) - return FALSE; + gboolean ret = FALSE; -#if 0 - gst_type_find_register (plugin, "image/*", GST_RANK_MARGINAL, - gst_gdk_pixbuf_type_find, NULL, GST_CAPS_ANY, NULL); -#endif + ret |= GST_ELEMENT_REGISTER (gdkpixbufdec, plugin); + ret |= GST_ELEMENT_REGISTER (gdkpixbufoverlay, plugin); + ret |= GST_ELEMENT_REGISTER (gdkpixbufsink, plugin); - if (!gst_element_register (plugin, "gdkpixbufoverlay", GST_RANK_NONE, - GST_TYPE_GDK_PIXBUF_OVERLAY)) - return FALSE; - - if (!gst_element_register (plugin, "gdkpixbufsink", GST_RANK_NONE, - GST_TYPE_GDK_PIXBUF_SINK)) - return FALSE; - - return TRUE; + return ret; } GST_PLUGIN_DEFINE (GST_VERSION_MAJOR, diff --git a/ext/gdk_pixbuf/gstgdkpixbufsink.c b/ext/gdk_pixbuf/gstgdkpixbufsink.c index 8c1aef47b6..01e75bb026 100644 --- a/ext/gdk_pixbuf/gstgdkpixbufsink.c +++ b/ext/gdk_pixbuf/gstgdkpixbufsink.c @@ -84,6 +84,7 @@ #include "config.h" #endif +#include "gstgdkpixbufelements.h" #include "gstgdkpixbufsink.h" #include @@ -101,6 +102,8 @@ enum G_DEFINE_TYPE (GstGdkPixbufSink, gst_gdk_pixbuf_sink, GST_TYPE_VIDEO_SINK); +GST_ELEMENT_REGISTER_DEFINE_WITH_CODE (gdkpixbufsink, "gdkpixbufsink", + GST_RANK_NONE, GST_TYPE_GDK_PIXBUF_SINK, gdk_pixbuf_element_init (plugin)); static void gst_gdk_pixbuf_sink_set_property (GObject * object, guint prop_id, const GValue * value, GParamSpec * pspec); diff --git a/ext/gdk_pixbuf/meson.build b/ext/gdk_pixbuf/meson.build index eb8578fe58..985e8eb4b1 100644 --- a/ext/gdk_pixbuf/meson.build +++ b/ext/gdk_pixbuf/meson.build @@ -1,6 +1,7 @@ pixbuf_sources = [ 'gstgdkpixbufdec.c', 'gstgdkpixbufoverlay.c', + 'gstgdkpixbufelement.c', 'gstgdkpixbufplugin.c', 'gstgdkpixbufsink.c', ]