diff --git a/ext/vorbis/gstivorbisdec.c b/ext/vorbis/gstivorbisdec.c index a47a094fc5..3dc2a60350 100644 --- a/ext/vorbis/gstivorbisdec.c +++ b/ext/vorbis/gstivorbisdec.c @@ -21,22 +21,21 @@ #include "config.h" #endif -#include "gstvorbisdec.h" +#include "gstvorbiselements.h" GST_DEBUG_CATEGORY (ivorbisdec_debug); static gboolean plugin_init (GstPlugin * plugin) { - - if (!gst_element_register (plugin, "ivorbisdec", GST_RANK_SECONDARY, - gst_vorbis_dec_get_type ())) - return FALSE; + gboolean ret = FALSE; GST_DEBUG_CATEGORY_INIT (ivorbisdec_debug, "ivorbisdec", 0, "vorbis decoding element (integer decoder)"); - return TRUE; + ret |= GST_ELEMENT_REGISTER (ivorbisdec, plugin); + + return ret; } GST_PLUGIN_DEFINE (GST_VERSION_MAJOR, diff --git a/ext/vorbis/gstvorbis.c b/ext/vorbis/gstvorbis.c index 67254a8106..51b9a76123 100644 --- a/ext/vorbis/gstvorbis.c +++ b/ext/vorbis/gstvorbis.c @@ -21,49 +21,19 @@ #include "config.h" #endif -#include "gst/tag/tag.h" - -#include "gstvorbisenc.h" -#include "gstvorbisdec.h" -#include "gstvorbisparse.h" -#include "gstvorbistag.h" - -GST_DEBUG_CATEGORY (vorbisenc_debug); -GST_DEBUG_CATEGORY (vorbisdec_debug); -GST_DEBUG_CATEGORY (vorbisparse_debug); -GST_DEBUG_CATEGORY (vorbistag_debug); +#include "gstvorbiselements.h" static gboolean plugin_init (GstPlugin * plugin) { - if (!gst_element_register (plugin, "vorbisenc", GST_RANK_PRIMARY, - GST_TYPE_VORBISENC)) - return FALSE; + gboolean ret = FALSE; - if (!gst_element_register (plugin, "vorbisdec", GST_RANK_PRIMARY, - gst_vorbis_dec_get_type ())) - return FALSE; + ret |= GST_ELEMENT_REGISTER (vorbisenc, plugin); + ret |= GST_ELEMENT_REGISTER (vorbisdec, plugin); + ret |= GST_ELEMENT_REGISTER (vorbisparse, plugin); + ret |= GST_ELEMENT_REGISTER (vorbistag, plugin); - if (!gst_element_register (plugin, "vorbisparse", GST_RANK_NONE, - gst_vorbis_parse_get_type ())) - return FALSE; - - if (!gst_element_register (plugin, "vorbistag", GST_RANK_NONE, - gst_vorbis_tag_get_type ())) - return FALSE; - - GST_DEBUG_CATEGORY_INIT (vorbisenc_debug, "vorbisenc", 0, - "vorbis encoding element"); - GST_DEBUG_CATEGORY_INIT (vorbisdec_debug, "vorbisdec", 0, - "vorbis decoding element"); - GST_DEBUG_CATEGORY_INIT (vorbisparse_debug, "vorbisparse", 0, - "vorbis parsing element"); - GST_DEBUG_CATEGORY_INIT (vorbistag_debug, "vorbistag", 0, - "vorbis tagging element"); - - gst_tag_register_musicbrainz_tags (); - - return TRUE; + return ret; } GST_PLUGIN_DEFINE (GST_VERSION_MAJOR, diff --git a/ext/vorbis/gstvorbisdec.c b/ext/vorbis/gstvorbisdec.c index bb865d771a..817b17f969 100644 --- a/ext/vorbis/gstvorbisdec.c +++ b/ext/vorbis/gstvorbisdec.c @@ -44,6 +44,7 @@ #include #include +#include "gstvorbiselements.h" #include "gstvorbiscommon.h" #ifndef TREMOR @@ -69,6 +70,11 @@ GST_STATIC_PAD_TEMPLATE ("sink", #define gst_vorbis_dec_parent_class parent_class G_DEFINE_TYPE (GstVorbisDec, gst_vorbis_dec, GST_TYPE_AUDIO_DECODER); +GST_ELEMENT_REGISTER_DEFINE_WITH_CODE (vorbisdec, "vorbisdec", + GST_RANK_PRIMARY, GST_TYPE_VORBIS_DEC, vorbis_element_init (plugin)); + +GST_ELEMENT_REGISTER_DEFINE (ivorbisdec, "ivorbisdec", + GST_RANK_SECONDARY, GST_TYPE_VORBIS_DEC); static void vorbis_dec_finalize (GObject * object); diff --git a/ext/vorbis/gstvorbiselement.c b/ext/vorbis/gstvorbiselement.c new file mode 100644 index 0000000000..1ff85a5e54 --- /dev/null +++ b/ext/vorbis/gstvorbiselement.c @@ -0,0 +1,43 @@ +/* GStreamer + * Copyright (C) <1999> Erik Walthinsen + * 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. + */ + +#ifdef HAVE_CONFIG_H +#include "config.h" +#endif + +#include "gstvorbiselements.h" +#include "gst/tag/tag.h" + +GST_DEBUG_CATEGORY (vorbisenc_debug); +GST_DEBUG_CATEGORY (vorbisdec_debug); +GST_DEBUG_CATEGORY (vorbisparse_debug); +GST_DEBUG_CATEGORY (vorbistag_debug); + +void +vorbis_element_init (GstPlugin * plugin) +{ + static gsize res = FALSE; + + if (g_once_init_enter (&res)) { + gst_tag_register_musicbrainz_tags (); + g_once_init_leave (&res, TRUE); + } +} diff --git a/ext/vorbis/gstvorbiselements.h b/ext/vorbis/gstvorbiselements.h new file mode 100644 index 0000000000..218ddb9f02 --- /dev/null +++ b/ext/vorbis/gstvorbiselements.h @@ -0,0 +1,38 @@ +/* + * Copyright (C) <1999> Erik Walthinsen + * 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_VORBIS_ELEMENTS_H__ +#define __GST_VORBIS_ELEMENTS_H__ + +#include + +G_BEGIN_DECLS + +G_GNUC_INTERNAL void vorbis_element_init (GstPlugin * plugin); + +GST_ELEMENT_REGISTER_DECLARE (vorbisenc); +GST_ELEMENT_REGISTER_DECLARE (vorbisdec); +GST_ELEMENT_REGISTER_DECLARE (vorbisparse); +GST_ELEMENT_REGISTER_DECLARE (vorbistag); +GST_ELEMENT_REGISTER_DECLARE (ivorbisdec); + +G_END_DECLS + +#endif /* __GST_VORBIS_ELEMENTS_H__ */ diff --git a/ext/vorbis/gstvorbisenc.c b/ext/vorbis/gstvorbisenc.c index 1c0b2c2e2c..b2cb66c74c 100644 --- a/ext/vorbis/gstvorbisenc.c +++ b/ext/vorbis/gstvorbisenc.c @@ -52,6 +52,7 @@ #include #include "gstvorbisenc.h" +#include "gstvorbiselements.h" #include "gstvorbiscommon.h" GST_DEBUG_CATEGORY_EXTERN (vorbisenc_debug); @@ -108,6 +109,8 @@ static void gst_vorbis_enc_flush (GstAudioEncoder * vorbisenc); #define gst_vorbis_enc_parent_class parent_class G_DEFINE_TYPE_WITH_CODE (GstVorbisEnc, gst_vorbis_enc, GST_TYPE_AUDIO_ENCODER, G_IMPLEMENT_INTERFACE (GST_TYPE_TAG_SETTER, NULL)); +GST_ELEMENT_REGISTER_DEFINE_WITH_CODE (vorbisenc, "vorbisenc", + GST_RANK_PRIMARY, GST_TYPE_VORBISENC, vorbis_element_init (plugin)); static void gst_vorbis_enc_class_init (GstVorbisEncClass * klass) diff --git a/ext/vorbis/gstvorbisparse.c b/ext/vorbis/gstvorbisparse.c index ada2b5ba52..20dd67e127 100644 --- a/ext/vorbis/gstvorbisparse.c +++ b/ext/vorbis/gstvorbisparse.c @@ -53,6 +53,7 @@ # include "config.h" #endif +#include "gstvorbiselements.h" #include "gstvorbisparse.h" GST_DEBUG_CATEGORY_EXTERN (vorbisparse_debug); @@ -74,6 +75,8 @@ GST_STATIC_PAD_TEMPLATE ("src", #define gst_vorbis_parse_parent_class parent_class G_DEFINE_TYPE (GstVorbisParse, gst_vorbis_parse, GST_TYPE_ELEMENT); +GST_ELEMENT_REGISTER_DEFINE_WITH_CODE (vorbisparse, "vorbisparse", + GST_RANK_NONE, GST_TYPE_VORBIS_PARSE, vorbis_element_init (plugin)); static GstFlowReturn vorbis_parse_chain (GstPad * pad, GstObject * parent, GstBuffer * buffer); diff --git a/ext/vorbis/gstvorbistag.c b/ext/vorbis/gstvorbistag.c index 19ddb3ef9a..6613c27a51 100644 --- a/ext/vorbis/gstvorbistag.c +++ b/ext/vorbis/gstvorbistag.c @@ -55,6 +55,7 @@ #include +#include "gstvorbiselements.h" #include "gstvorbistag.h" @@ -67,6 +68,8 @@ static GstFlowReturn gst_vorbis_tag_parse_packet (GstVorbisParse * parse, #define gst_vorbis_tag_parent_class parent_class G_DEFINE_TYPE_WITH_CODE (GstVorbisTag, gst_vorbis_tag, GST_TYPE_VORBIS_PARSE, G_IMPLEMENT_INTERFACE (GST_TYPE_TAG_SETTER, NULL)); +GST_ELEMENT_REGISTER_DEFINE_WITH_CODE (vorbistag, "vorbistag", + GST_RANK_NONE, GST_TYPE_VORBIS_TAG, vorbis_element_init (plugin)); static void gst_vorbis_tag_class_init (GstVorbisTagClass * klass) diff --git a/ext/vorbis/meson.build b/ext/vorbis/meson.build index 46001061ef..a55249acc6 100644 --- a/ext/vorbis/meson.build +++ b/ext/vorbis/meson.build @@ -1,5 +1,6 @@ vorbis_sources = [ 'gstvorbis.c', + 'gstvorbiselement.c', 'gstvorbisdec.c', 'gstvorbisdeclib.c', 'gstvorbisenc.c', @@ -10,6 +11,7 @@ vorbis_sources = [ vorbisidec_sources = [ 'gstivorbisdec.c', + 'gstvorbiselement.c', 'gstvorbisdec.c', 'gstvorbisdeclib.c', 'gstvorbiscommon.c',