From d58cf8b8d368046891391a2ba65d919d23e63f0d Mon Sep 17 00:00:00 2001 From: Julian Bouzas Date: Tue, 11 Aug 2020 11:47:02 -0400 Subject: [PATCH] ogg: allow per feature registration Split plugin into features including elements and device providers 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/ogg/gstoggaviparse.c | 91 ++++++++------------------ ext/ogg/gstoggdemux.c | 12 +++- ext/ogg/gstoggdemux.h | 2 - ext/ogg/{gstogg.h => gstoggelements.h} | 21 +++--- ext/ogg/gstoggmux.c | 17 +++-- ext/ogg/gstoggparse.c | 69 +++++-------------- ext/ogg/{gstogg.c => gstoggplugin.c} | 18 +++-- ext/ogg/gstogmparse.c | 34 ++++++---- ext/ogg/meson.build | 2 +- 9 files changed, 106 insertions(+), 160 deletions(-) rename ext/ogg/{gstogg.h => gstoggelements.h} (60%) rename ext/ogg/{gstogg.c => gstoggplugin.c} (73%) diff --git a/ext/ogg/gstoggaviparse.c b/ext/ogg/gstoggaviparse.c index 69136e6cd2..3fad6b5c1c 100644 --- a/ext/ogg/gstoggaviparse.c +++ b/ext/ogg/gstoggaviparse.c @@ -37,7 +37,7 @@ #include #include -#include "gstogg.h" +#include "gstoggelements.h" GST_DEBUG_CATEGORY_STATIC (gst_ogg_avi_parse_debug); #define GST_CAT_DEFAULT gst_ogg_avi_parse_debug @@ -72,85 +72,58 @@ struct _GstOggAviParseClass GstElementClass parent_class; }; -static void gst_ogg_avi_parse_base_init (gpointer g_class); -static void gst_ogg_avi_parse_class_init (GstOggAviParseClass * klass); -static void gst_ogg_avi_parse_init (GstOggAviParse * ogg); + static GstElementClass *parent_class = NULL; -static GType -gst_ogg_avi_parse_get_type (void) -{ - static GType ogg_avi_parse_type = 0; +G_DEFINE_TYPE (GstOggAviParse, gst_ogg_avi_parse, GST_TYPE_ELEMENT); - if (!ogg_avi_parse_type) { - static const GTypeInfo ogg_avi_parse_info = { - sizeof (GstOggAviParseClass), - gst_ogg_avi_parse_base_init, - NULL, - (GClassInitFunc) gst_ogg_avi_parse_class_init, - NULL, - NULL, - sizeof (GstOggAviParse), - 0, - (GInstanceInitFunc) gst_ogg_avi_parse_init, - }; +#define _do_init \ + GST_DEBUG_CATEGORY_INIT (gst_ogg_avi_parse_debug, "oggaviparse", 0, "ogg avi parser"); +GST_ELEMENT_REGISTER_DEFINE_WITH_CODE (oggaviparse, "oggaviparse", + GST_RANK_PRIMARY, GST_TYPE_OGG_AVI_PARSE, _do_init) - ogg_avi_parse_type = - g_type_register_static (GST_TYPE_ELEMENT, "GstOggAviParse", - &ogg_avi_parse_info, 0); - } - return ogg_avi_parse_type; -} + enum + { + PROP_0 + }; -enum -{ - PROP_0 -}; - -static GstStaticPadTemplate ogg_avi_parse_src_template_factory = -GST_STATIC_PAD_TEMPLATE ("src", + static GstStaticPadTemplate ogg_avi_parse_src_template_factory = + GST_STATIC_PAD_TEMPLATE ("src", GST_PAD_SRC, GST_PAD_ALWAYS, GST_STATIC_CAPS ("audio/x-vorbis") ); -static GstStaticPadTemplate ogg_avi_parse_sink_template_factory = -GST_STATIC_PAD_TEMPLATE ("sink", + static GstStaticPadTemplate ogg_avi_parse_sink_template_factory = + GST_STATIC_PAD_TEMPLATE ("sink", GST_PAD_SINK, GST_PAD_ALWAYS, GST_STATIC_CAPS ("application/x-ogg-avi") ); -static void gst_ogg_avi_parse_finalize (GObject * object); -static GstStateChangeReturn gst_ogg_avi_parse_change_state (GstElement * + static void gst_ogg_avi_parse_finalize (GObject * object); + static GstStateChangeReturn gst_ogg_avi_parse_change_state (GstElement * element, GstStateChange transition); -static gboolean gst_ogg_avi_parse_event (GstPad * pad, GstObject * parent, + static gboolean gst_ogg_avi_parse_event (GstPad * pad, GstObject * parent, GstEvent * event); -static GstFlowReturn gst_ogg_avi_parse_chain (GstPad * pad, GstObject * parent, - GstBuffer * buffer); -static gboolean gst_ogg_avi_parse_setcaps (GstPad * pad, GstCaps * caps); + static GstFlowReturn gst_ogg_avi_parse_chain (GstPad * pad, + GstObject * parent, GstBuffer * buffer); + static gboolean gst_ogg_avi_parse_setcaps (GstPad * pad, GstCaps * caps); -static void -gst_ogg_avi_parse_base_init (gpointer g_class) + static void gst_ogg_avi_parse_class_init (GstOggAviParseClass * klass) { - GstElementClass *element_class = GST_ELEMENT_CLASS (g_class); + GstElementClass *gstelement_class = GST_ELEMENT_CLASS (klass); + GObjectClass *gobject_class = G_OBJECT_CLASS (klass); - gst_element_class_set_static_metadata (element_class, + gst_element_class_set_static_metadata (gstelement_class, "Ogg AVI parser", "Codec/Parser", "parse an ogg avi stream into pages (info about ogg: http://xiph.org)", "Wim Taymans "); - gst_element_class_add_static_pad_template (element_class, + gst_element_class_add_static_pad_template (gstelement_class, &ogg_avi_parse_sink_template_factory); - gst_element_class_add_static_pad_template (element_class, + gst_element_class_add_static_pad_template (gstelement_class, &ogg_avi_parse_src_template_factory); -} - -static void -gst_ogg_avi_parse_class_init (GstOggAviParseClass * klass) -{ - GstElementClass *gstelement_class = GST_ELEMENT_CLASS (klass); - GObjectClass *gobject_class = G_OBJECT_CLASS (klass); parent_class = g_type_class_peek_parent (klass); @@ -476,13 +449,3 @@ gst_ogg_avi_parse_change_state (GstElement * element, GstStateChange transition) } return result; } - -gboolean -gst_ogg_avi_parse_plugin_init (GstPlugin * plugin) -{ - GST_DEBUG_CATEGORY_INIT (gst_ogg_avi_parse_debug, "oggaviparse", 0, - "ogg avi parser"); - - return gst_element_register (plugin, "oggaviparse", GST_RANK_PRIMARY, - GST_TYPE_OGG_AVI_PARSE); -} diff --git a/ext/ogg/gstoggdemux.c b/ext/ogg/gstoggdemux.c index e88e325f1d..81734e9a2e 100644 --- a/ext/ogg/gstoggdemux.c +++ b/ext/ogg/gstoggdemux.c @@ -44,6 +44,7 @@ #include #include +#include "gstoggelements.h" #include "gstoggdemux.h" #define CHUNKSIZE (8500) /* this is out of vorbisfile */ @@ -2291,10 +2292,16 @@ static GstStateChangeReturn gst_ogg_demux_change_state (GstElement * element, GstStateChange transition); static void gst_ogg_print (GstOggDemux * demux); +static gboolean gst_ogg_demux_plugin_init (GstPlugin * plugin); #define gst_ogg_demux_parent_class parent_class G_DEFINE_TYPE (GstOggDemux, gst_ogg_demux, GST_TYPE_ELEMENT); +#define _do_init \ + ret |= gst_ogg_demux_plugin_init (plugin); +GST_ELEMENT_REGISTER_DEFINE_WITH_CODE (oggdemux, "oggdemux", GST_RANK_PRIMARY, + GST_TYPE_OGG_DEMUX, _do_init); + static void gst_ogg_demux_class_init (GstOggDemuxClass * klass) { @@ -5253,7 +5260,7 @@ gst_ogg_demux_change_state (GstElement * element, GstStateChange transition) return result; } -gboolean +static gboolean gst_ogg_demux_plugin_init (GstPlugin * plugin) { GST_DEBUG_CATEGORY_INIT (gst_ogg_demux_debug, "oggdemux", 0, "ogg demuxer"); @@ -5267,8 +5274,7 @@ gst_ogg_demux_plugin_init (GstPlugin * plugin) bind_textdomain_codeset (GETTEXT_PACKAGE, "UTF-8"); #endif - return gst_element_register (plugin, "oggdemux", GST_RANK_PRIMARY, - GST_TYPE_OGG_DEMUX); + return TRUE; } /* prints all info about the element */ diff --git a/ext/ogg/gstoggdemux.h b/ext/ogg/gstoggdemux.h index 5ac81b7f32..4275070be2 100644 --- a/ext/ogg/gstoggdemux.h +++ b/ext/ogg/gstoggdemux.h @@ -219,8 +219,6 @@ struct _GstOggDemuxClass GstElementClass parent_class; }; -gboolean gst_ogg_demux_plugin_init (GstPlugin * plugin); - G_END_DECLS #endif /* __GST_OGG_DEMUX_H__ */ diff --git a/ext/ogg/gstogg.h b/ext/ogg/gstoggelements.h similarity index 60% rename from ext/ogg/gstogg.h rename to ext/ogg/gstoggelements.h index 9aaac7a50e..6fad0b0754 100644 --- a/ext/ogg/gstogg.h +++ b/ext/ogg/gstoggelements.h @@ -1,7 +1,6 @@ /* GStreamer - * Copyright (C) 2004 Wim Taymans - * - * gstoggdemux.c: ogg stream demuxer + * 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 @@ -19,13 +18,17 @@ * Boston, MA 02110-1301, USA. */ -#ifndef __GST_OGG_H__ -#define __GST_OGG_H__ +#ifndef __GST_OGG_ELEMENT_H__ +#define __GST_OGG_ELEMENT_H__ #include -gboolean gst_ogm_parse_plugin_init (GstPlugin * plugin); -gboolean gst_ogg_parse_plugin_init (GstPlugin * plugin); -gboolean gst_ogg_avi_parse_plugin_init (GstPlugin * plugin); +GST_ELEMENT_REGISTER_DECLARE (oggdemux); +GST_ELEMENT_REGISTER_DECLARE (oggmux); +GST_ELEMENT_REGISTER_DECLARE (ogmaudioparse); +GST_ELEMENT_REGISTER_DECLARE (ogmvideoparse); +GST_ELEMENT_REGISTER_DECLARE (ogmtextparse); +GST_ELEMENT_REGISTER_DECLARE (oggparse); +GST_ELEMENT_REGISTER_DECLARE (oggaviparse); -#endif /* __GST_OGG_H__ */ +#endif /* __GST_OGG_ELEMENT_H__ */ diff --git a/ext/ogg/gstoggmux.c b/ext/ogg/gstoggmux.c index 68b3e7e7e2..1d441c7466 100644 --- a/ext/ogg/gstoggmux.c +++ b/ext/ogg/gstoggmux.c @@ -43,6 +43,7 @@ #include #include +#include "gstoggelements.h" #include "gstoggmux.h" /* memcpy - if someone knows a way to get rid of it, please speak up @@ -134,10 +135,17 @@ static GstStateChangeReturn gst_ogg_mux_change_state (GstElement * element, GstStateChange transition); /*static guint gst_ogg_mux_signals[LAST_SIGNAL] = { 0 }; */ + + #define gst_ogg_mux_parent_class parent_class G_DEFINE_TYPE_WITH_CODE (GstOggMux, gst_ogg_mux, GST_TYPE_ELEMENT, G_IMPLEMENT_INTERFACE (GST_TYPE_PRESET, NULL)); +#define _do_init \ + GST_DEBUG_CATEGORY_INIT (gst_ogg_mux_debug, "oggmux", 0, "ogg muxer"); +GST_ELEMENT_REGISTER_DEFINE_WITH_CODE (oggmux, "oggmux", GST_RANK_PRIMARY, + GST_TYPE_OGG_MUX, _do_init); + static void gst_ogg_mux_class_init (GstOggMuxClass * klass) { @@ -2253,12 +2261,3 @@ gst_ogg_mux_change_state (GstElement * element, GstStateChange transition) return ret; } - -gboolean -gst_ogg_mux_plugin_init (GstPlugin * plugin) -{ - GST_DEBUG_CATEGORY_INIT (gst_ogg_mux_debug, "oggmux", 0, "ogg muxer"); - - return gst_element_register (plugin, "oggmux", GST_RANK_PRIMARY, - GST_TYPE_OGG_MUX); -} diff --git a/ext/ogg/gstoggparse.c b/ext/ogg/gstoggparse.c index 2045263e4b..da237f0387 100644 --- a/ext/ogg/gstoggparse.c +++ b/ext/ogg/gstoggparse.c @@ -36,7 +36,7 @@ #include #include -#include "gstogg.h" +#include "gstoggelements.h" #include "gstoggstream.h" GST_DEBUG_CATEGORY_STATIC (gst_ogg_parse_debug); @@ -81,34 +81,14 @@ struct _GstOggParseClass GstElementClass parent_class; }; -static void gst_ogg_parse_base_init (gpointer g_class); -static void gst_ogg_parse_class_init (GstOggParseClass * klass); -static void gst_ogg_parse_init (GstOggParse * ogg); + static GstElementClass *parent_class = NULL; +G_DEFINE_TYPE (GstOggParse, gst_ogg_parse, GST_TYPE_ELEMENT); -static GType -gst_ogg_parse_get_type (void) -{ - static GType ogg_parse_type = 0; - - if (!ogg_parse_type) { - static const GTypeInfo ogg_parse_info = { - sizeof (GstOggParseClass), - gst_ogg_parse_base_init, - NULL, - (GClassInitFunc) gst_ogg_parse_class_init, - NULL, - NULL, - sizeof (GstOggParse), - 0, - (GInstanceInitFunc) gst_ogg_parse_init, - }; - - ogg_parse_type = g_type_register_static (GST_TYPE_ELEMENT, "GstOggParse", - &ogg_parse_info, 0); - } - return ogg_parse_type; -} +#define _do_init \ + GST_DEBUG_CATEGORY_INIT (gst_ogg_parse_debug, "oggparse", 0, "ogg parser"); +GST_ELEMENT_REGISTER_DEFINE_WITH_CODE (oggparse, "oggparse", GST_RANK_NONE, + GST_TYPE_OGG_PARSE, _do_init); static void free_stream (GstOggStream * stream) @@ -222,28 +202,22 @@ static GstStateChangeReturn gst_ogg_parse_change_state (GstElement * element, static GstFlowReturn gst_ogg_parse_chain (GstPad * pad, GstObject * parent, GstBuffer * buffer); -static void -gst_ogg_parse_base_init (gpointer g_class) -{ - GstElementClass *element_class = GST_ELEMENT_CLASS (g_class); - - gst_element_class_set_static_metadata (element_class, - "Ogg parser", "Codec/Parser", - "parse ogg streams into pages (info about ogg: http://xiph.org)", - "Michael Smith "); - - gst_element_class_add_static_pad_template (element_class, - &ogg_parse_sink_template_factory); - gst_element_class_add_static_pad_template (element_class, - &ogg_parse_src_template_factory); -} - static void gst_ogg_parse_class_init (GstOggParseClass * klass) { GstElementClass *gstelement_class = GST_ELEMENT_CLASS (klass); GObjectClass *gobject_class = G_OBJECT_CLASS (klass); + gst_element_class_set_static_metadata (gstelement_class, + "Ogg parser", "Codec/Parser", + "parse ogg streams into pages (info about ogg: http://xiph.org)", + "Michael Smith "); + + gst_element_class_add_static_pad_template (gstelement_class, + &ogg_parse_sink_template_factory); + gst_element_class_add_static_pad_template (gstelement_class, + &ogg_parse_src_template_factory); + parent_class = g_type_class_peek_parent (klass); gstelement_class->change_state = gst_ogg_parse_change_state; @@ -747,12 +721,3 @@ gst_ogg_parse_change_state (GstElement * element, GstStateChange transition) } return result; } - -gboolean -gst_ogg_parse_plugin_init (GstPlugin * plugin) -{ - GST_DEBUG_CATEGORY_INIT (gst_ogg_parse_debug, "oggparse", 0, "ogg parser"); - - return gst_element_register (plugin, "oggparse", GST_RANK_NONE, - GST_TYPE_OGG_PARSE); -} diff --git a/ext/ogg/gstogg.c b/ext/ogg/gstoggplugin.c similarity index 73% rename from ext/ogg/gstogg.c rename to ext/ogg/gstoggplugin.c index ec73943365..e0d4c36b76 100644 --- a/ext/ogg/gstogg.c +++ b/ext/ogg/gstoggplugin.c @@ -23,20 +23,24 @@ #include -#include "gstogg.h" +#include "gstoggelements.h" #include "gstoggdemux.h" #include "gstoggmux.h" static gboolean plugin_init (GstPlugin * plugin) { - gst_ogg_demux_plugin_init (plugin); - gst_ogg_mux_plugin_init (plugin); - gst_ogm_parse_plugin_init (plugin); - gst_ogg_parse_plugin_init (plugin); - gst_ogg_avi_parse_plugin_init (plugin); + gboolean ret = FALSE; - return TRUE; + ret |= GST_ELEMENT_REGISTER (oggdemux, plugin); + ret |= GST_ELEMENT_REGISTER (oggmux, plugin); + ret |= GST_ELEMENT_REGISTER (ogmaudioparse, plugin); + ret |= GST_ELEMENT_REGISTER (ogmvideoparse, plugin); + ret |= GST_ELEMENT_REGISTER (ogmtextparse, plugin); + ret |= GST_ELEMENT_REGISTER (oggparse, plugin); + ret |= GST_ELEMENT_REGISTER (oggaviparse, plugin); + + return ret; } GST_PLUGIN_DEFINE (GST_VERSION_MAJOR, diff --git a/ext/ogg/gstogmparse.c b/ext/ogg/gstogmparse.c index a3037115fb..d524e18a99 100644 --- a/ext/ogg/gstogmparse.c +++ b/ext/ogg/gstogmparse.c @@ -30,7 +30,7 @@ #include #include -#include "gstogg.h" +#include "gstoggelements.h" GST_DEBUG_CATEGORY_STATIC (gst_ogm_parse_debug); #define GST_CAT_DEFAULT gst_ogm_parse_debug @@ -150,6 +150,7 @@ static void gst_ogm_parse_init (GstOgmParse * ogm); static void gst_ogm_video_parse_init (GstOgmParse * ogm); static void gst_ogm_audio_parse_init (GstOgmParse * ogm); static void gst_ogm_text_parse_init (GstOgmParse * ogm); +static gboolean gst_ogm_parse_element_init (GstPlugin * plugin); static gboolean gst_ogm_parse_sink_event (GstPad * pad, GstObject * parent, GstEvent * event); @@ -270,6 +271,16 @@ gst_ogm_text_parse_get_type (void) return ogm_text_parse_type; } +GST_ELEMENT_REGISTER_DEFINE_WITH_CODE (ogmaudioparse, "ogmaudioparse", + GST_RANK_PRIMARY, GST_TYPE_OGM_AUDIO_PARSE, + gst_ogm_parse_element_init (plugin)); +GST_ELEMENT_REGISTER_DEFINE_WITH_CODE (ogmvideoparse, "ogmvideoparse", + GST_RANK_PRIMARY, GST_TYPE_OGM_VIDEO_PARSE, + gst_ogm_parse_element_init (plugin)); +GST_ELEMENT_REGISTER_DEFINE_WITH_CODE (ogmtextparse, "ogmtextparse", + GST_RANK_PRIMARY, GST_TYPE_OGM_TEXT_PARSE, + gst_ogm_parse_element_init (plugin)); + static void gst_ogm_audio_parse_base_init (GstOgmParseClass * klass) { @@ -955,17 +966,14 @@ gst_ogm_parse_change_state (GstElement * element, GstStateChange transition) return ret; } -gboolean -gst_ogm_parse_plugin_init (GstPlugin * plugin) +static gboolean +gst_ogm_parse_element_init (GstPlugin * plugin) { - gst_riff_init (); - - GST_DEBUG_CATEGORY_INIT (gst_ogm_parse_debug, "ogmparse", 0, "ogm parser"); - - return gst_element_register (plugin, "ogmaudioparse", GST_RANK_PRIMARY, - GST_TYPE_OGM_AUDIO_PARSE) && - gst_element_register (plugin, "ogmvideoparse", GST_RANK_PRIMARY, - GST_TYPE_OGM_VIDEO_PARSE) && - gst_element_register (plugin, "ogmtextparse", GST_RANK_PRIMARY, - GST_TYPE_OGM_TEXT_PARSE); + static gsize res = FALSE; + if (g_once_init_enter (&res)) { + gst_riff_init (); + GST_DEBUG_CATEGORY_INIT (gst_ogm_parse_debug, "ogmparse", 0, "ogm parser"); + g_once_init_leave (&res, TRUE); + } + return res; } diff --git a/ext/ogg/meson.build b/ext/ogg/meson.build index 2272844df7..4ff7b6b27d 100644 --- a/ext/ogg/meson.build +++ b/ext/ogg/meson.build @@ -1,7 +1,7 @@ ogg_sources = [ 'dirac_parse.c', 'gstoggaviparse.c', - 'gstogg.c', + 'gstoggplugin.c', 'gstoggdemux.c', 'gstoggmux.c', 'gstoggparse.c',