diff --git a/gst/matroska/gstmatroskaelement.c b/gst/matroska/gstmatroskaelement.c new file mode 100644 index 0000000000..19cc6ec61a --- /dev/null +++ b/gst/matroska/gstmatroskaelement.c @@ -0,0 +1,43 @@ +/* GStreamer Matroska muxer/demuxer + * (c) 2003 Ronald Bultje + * + * matroska.c: plugin loader + * + * 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 "gstmatroskaelements.h" +#include "matroska-parse.h" +#include "matroska-read-common.h" + +#include + +void +matroska_element_init (GstPlugin * plugin) +{ + static gsize res = FALSE; + if (g_once_init_enter (&res)) { + gst_pb_utils_init (); + gst_matroska_register_tags (); + GST_DEBUG_CATEGORY_INIT (matroskareadcommon_debug, "matroskareadcommon", 0, + "Matroska demuxer/parser shared debug"); + g_once_init_leave (&res, TRUE); + } +} diff --git a/gst/matroska/gstmatroskaelements.h b/gst/matroska/gstmatroskaelements.h new file mode 100644 index 0000000000..0eff6fab80 --- /dev/null +++ b/gst/matroska/gstmatroskaelements.h @@ -0,0 +1,41 @@ +/* + * (c) 2003 Ronald Bultje + * 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. + */ + +#ifndef __GST_MATROSKA_ELEMENTS_H__ +#define __GST_MATROSKA_ELEMENTS_H__ + +#ifdef HAVE_CONFIG_H +#include "config.h" +#endif + +#include + +G_BEGIN_DECLS + +void matroska_element_init (GstPlugin * plugin); + +GST_ELEMENT_REGISTER_DECLARE (matroskademux); +GST_ELEMENT_REGISTER_DECLARE (matroskaparse); +GST_ELEMENT_REGISTER_DECLARE (matroskamux); +GST_ELEMENT_REGISTER_DECLARE (webmmux); + +G_END_DECLS + +#endif /* __GST_MATROSKA_ELEMENTS_H__ */ diff --git a/gst/matroska/matroska-demux.c b/gst/matroska/matroska-demux.c index 68215d2ca2..e898a3a80f 100644 --- a/gst/matroska/matroska-demux.c +++ b/gst/matroska/matroska-demux.c @@ -66,6 +66,7 @@ #include #include +#include "gstmatroskaelements.h" #include "matroska-demux.h" #include "matroska-ids.h" @@ -195,6 +196,13 @@ static void gst_matroska_demux_get_property (GObject * object, GType gst_matroska_demux_get_type (void); #define parent_class gst_matroska_demux_parent_class G_DEFINE_TYPE (GstMatroskaDemux, gst_matroska_demux, GST_TYPE_ELEMENT); +#define _do_init \ + gst_riff_init (); \ + matroska_element_init (plugin); \ + GST_DEBUG_CATEGORY_INIT (ebmlread_debug, "ebmlread", 0, "EBML stream helper class"); + +GST_ELEMENT_REGISTER_DEFINE_WITH_CODE (matroskademux, "matroskademux", + GST_RANK_PRIMARY, GST_TYPE_MATROSKA_DEMUX, _do_init); static void gst_matroska_demux_finalize (GObject * object) @@ -7303,20 +7311,3 @@ gst_matroska_track_encoding_scope_name (gint val) en = g_enum_get_value (G_ENUM_CLASS (enum_class), val); return en ? en->value_nick : NULL; } - -gboolean -gst_matroska_demux_plugin_init (GstPlugin * plugin) -{ - gst_riff_init (); - - /* parser helper separate debug */ - GST_DEBUG_CATEGORY_INIT (ebmlread_debug, "ebmlread", - 0, "EBML stream helper class"); - - /* create an elementfactory for the matroska_demux element */ - if (!gst_element_register (plugin, "matroskademux", - GST_RANK_PRIMARY, GST_TYPE_MATROSKA_DEMUX)) - return FALSE; - - return TRUE; -} diff --git a/gst/matroska/matroska-demux.h b/gst/matroska/matroska-demux.h index a1f0f8908a..a0a27947e5 100644 --- a/gst/matroska/matroska-demux.h +++ b/gst/matroska/matroska-demux.h @@ -135,8 +135,6 @@ typedef struct _GstMatroskaDemuxClass { GstElementClass parent; } GstMatroskaDemuxClass; -gboolean gst_matroska_demux_plugin_init (GstPlugin *plugin); - G_END_DECLS #endif /* __GST_MATROSKA_DEMUX_H__ */ diff --git a/gst/matroska/matroska-mux.c b/gst/matroska/matroska-mux.c index 3cb9bae68b..c18bd9af56 100644 --- a/gst/matroska/matroska-mux.c +++ b/gst/matroska/matroska-mux.c @@ -55,6 +55,7 @@ #include #include +#include "gstmatroskaelements.h" #include "matroska-mux.h" #include "matroska-ids.h" @@ -299,6 +300,9 @@ gst_matroska_mux_get_type (void) return object_type; } +GST_ELEMENT_REGISTER_DEFINE_WITH_CODE (matroskamux, "matroskamux", + GST_RANK_PRIMARY, GST_TYPE_MATROSKA_MUX, matroska_element_init (plugin)); + static void gst_matroska_mux_class_init (GstMatroskaMuxClass * klass) { diff --git a/gst/matroska/matroska-parse.c b/gst/matroska/matroska-parse.c index 19a1f77146..3fcb5c55e8 100644 --- a/gst/matroska/matroska-parse.c +++ b/gst/matroska/matroska-parse.c @@ -63,6 +63,7 @@ #include +#include "gstmatroskaelements.h" #include "matroska-parse.h" #include "matroska-ids.h" @@ -141,6 +142,11 @@ static GstCaps *gst_matroska_parse_forge_caps (gboolean is_webm, GType gst_matroska_parse_get_type (void); #define parent_class gst_matroska_parse_parent_class G_DEFINE_TYPE (GstMatroskaParse, gst_matroska_parse, GST_TYPE_ELEMENT); +#define _do_init \ + gst_riff_init (); \ + matroska_element_init (plugin); +GST_ELEMENT_REGISTER_DEFINE_WITH_CODE (matroskaparse, "matroskaparse", + GST_RANK_NONE, GST_TYPE_MATROSKA_PARSE, _do_init); static void gst_matroska_parse_finalize (GObject * object) @@ -3264,16 +3270,3 @@ gst_matroska_parse_change_state (GstElement * element, return ret; } - -gboolean -gst_matroska_parse_plugin_init (GstPlugin * plugin) -{ - gst_riff_init (); - - /* create an elementfactory for the matroska_parse element */ - if (!gst_element_register (plugin, "matroskaparse", - GST_RANK_NONE, GST_TYPE_MATROSKA_PARSE)) - return FALSE; - - return TRUE; -} diff --git a/gst/matroska/matroska-parse.h b/gst/matroska/matroska-parse.h index 7d598f2806..4a28fb86da 100644 --- a/gst/matroska/matroska-parse.h +++ b/gst/matroska/matroska-parse.h @@ -98,8 +98,6 @@ typedef struct _GstMatroskaParseClass { GstElementClass parent; } GstMatroskaParseClass; -gboolean gst_matroska_parse_plugin_init (GstPlugin *plugin); - G_END_DECLS #endif /* __GST_MATROSKA_PARSE_H__ */ diff --git a/gst/matroska/matroska.c b/gst/matroska/matroska.c index 6e43972f66..f73168747e 100644 --- a/gst/matroska/matroska.c +++ b/gst/matroska/matroska.c @@ -23,33 +23,17 @@ #include "config.h" #endif -#include "matroska-demux.h" -#include "matroska-parse.h" -#include "matroska-read-common.h" -#include "matroska-mux.h" -#include "matroska-ids.h" -#include "webm-mux.h" - -#include +#include "gstmatroskaelements.h" static gboolean plugin_init (GstPlugin * plugin) { - gboolean ret; + gboolean ret = FALSE; - gst_pb_utils_init (); - - gst_matroska_register_tags (); - - GST_DEBUG_CATEGORY_INIT (matroskareadcommon_debug, "matroskareadcommon", 0, - "Matroska demuxer/parser shared debug"); - - ret = gst_matroska_demux_plugin_init (plugin); - ret &= gst_matroska_parse_plugin_init (plugin); - ret &= gst_element_register (plugin, "matroskamux", GST_RANK_PRIMARY, - GST_TYPE_MATROSKA_MUX); - ret &= gst_element_register (plugin, "webmmux", GST_RANK_PRIMARY, - GST_TYPE_WEBM_MUX); + ret |= GST_ELEMENT_REGISTER (matroskademux, plugin); + ret |= GST_ELEMENT_REGISTER (matroskaparse, plugin); + ret |= GST_ELEMENT_REGISTER (matroskamux, plugin); + ret |= GST_ELEMENT_REGISTER (webmmux, plugin); return ret; } diff --git a/gst/matroska/meson.build b/gst/matroska/meson.build index 4d2f1e14b1..d8a6a961fc 100644 --- a/gst/matroska/meson.build +++ b/gst/matroska/meson.build @@ -1,6 +1,7 @@ matroska_sources = [ 'ebml-read.c', 'ebml-write.c', + 'gstmatroskaelement.c', 'matroska.c', 'matroska-demux.c', 'matroska-parse.c', diff --git a/gst/matroska/webm-mux.c b/gst/matroska/webm-mux.c index 6d29931357..0738d5a4fe 100644 --- a/gst/matroska/webm-mux.c +++ b/gst/matroska/webm-mux.c @@ -42,6 +42,7 @@ #include "config.h" #endif +#include "gstmatroskaelements.h" #include "webm-mux.h" #define COMMON_VIDEO_CAPS \ @@ -54,6 +55,8 @@ "rate = (int) [ 1, MAX ]" G_DEFINE_TYPE (GstWebMMux, gst_webm_mux, GST_TYPE_MATROSKA_MUX); +GST_ELEMENT_REGISTER_DEFINE_WITH_CODE (webmmux, "webmmux", + GST_RANK_PRIMARY, GST_TYPE_WEBM_MUX, matroska_element_init (plugin)); static GstStaticPadTemplate webm_src_templ = GST_STATIC_PAD_TEMPLATE ("src", GST_PAD_SRC,