diff --git a/ext/speex/gstspeex.c b/ext/speex/gstspeex.c index 9688cd5c2e..f904efba06 100644 --- a/ext/speex/gstspeex.c +++ b/ext/speex/gstspeex.c @@ -20,26 +20,18 @@ #include #endif -#include "gstspeexdec.h" -#include "gstspeexenc.h" +#include "gstspeexelements.h" -#include static gboolean plugin_init (GstPlugin * plugin) { + gboolean ret = FALSE; - if (!gst_element_register (plugin, "speexenc", GST_RANK_PRIMARY, - GST_TYPE_SPEEX_ENC)) - return FALSE; + ret |= GST_ELEMENT_REGISTER (speexenc, plugin); + ret |= GST_ELEMENT_REGISTER (speexdec, plugin); - if (!gst_element_register (plugin, "speexdec", GST_RANK_PRIMARY, - GST_TYPE_SPEEX_DEC)) - return FALSE; - - gst_tag_register_musicbrainz_tags (); - - return TRUE; + return ret; } GST_PLUGIN_DEFINE (GST_VERSION_MAJOR, diff --git a/ext/speex/gstspeexdec.c b/ext/speex/gstspeexdec.c index 3c29ec7ac2..eeb7af7e8b 100644 --- a/ext/speex/gstspeexdec.c +++ b/ext/speex/gstspeexdec.c @@ -39,6 +39,7 @@ # include "config.h" #endif +#include "gstspeexelements.h" #include "gstspeexdec.h" #include #include @@ -77,6 +78,8 @@ GST_STATIC_PAD_TEMPLATE ("sink", #define gst_speex_dec_parent_class parent_class G_DEFINE_TYPE (GstSpeexDec, gst_speex_dec, GST_TYPE_AUDIO_DECODER); +GST_ELEMENT_REGISTER_DEFINE_WITH_CODE (speexdec, "speexdec", + GST_RANK_PRIMARY, GST_TYPE_SPEEX_DEC, speex_element_init (plugin)); static gboolean gst_speex_dec_start (GstAudioDecoder * dec); static gboolean gst_speex_dec_stop (GstAudioDecoder * dec); diff --git a/ext/speex/gstspeexelement.c b/ext/speex/gstspeexelement.c new file mode 100644 index 0000000000..773430598a --- /dev/null +++ b/ext/speex/gstspeexelement.c @@ -0,0 +1,36 @@ + +/* GStreamer + * Copyright (C) <1999> Erik Walthinsen + * + * 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 "gstspeexelements.h" + +#include + +void +speex_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/speex/gstspeexelements.h b/ext/speex/gstspeexelements.h new file mode 100644 index 0000000000..b37ea818bc --- /dev/null +++ b/ext/speex/gstspeexelements.h @@ -0,0 +1,34 @@ +/* + * 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_SPEEX_ELEMENTS_H__ +#define __GST_SPEEX_ELEMENTS_H__ + +#include + +G_BEGIN_DECLS + +void speex_element_init (GstPlugin * plugin); + +GST_ELEMENT_REGISTER_DECLARE (speexenc); +GST_ELEMENT_REGISTER_DECLARE (speexdec); + +G_END_DECLS + +#endif /* __GST_SPEEX_ELEMENTS_H__ */ diff --git a/ext/speex/gstspeexenc.c b/ext/speex/gstspeexenc.c index dc39d0adf6..3eac649a39 100644 --- a/ext/speex/gstspeexenc.c +++ b/ext/speex/gstspeexenc.c @@ -46,6 +46,7 @@ #include #include #include +#include "gstspeexelements.h" #include "gstspeexenc.h" GST_DEBUG_CATEGORY_STATIC (speexenc_debug); @@ -143,6 +144,8 @@ static gboolean gst_speex_enc_sink_event (GstAudioEncoder * enc, G_DEFINE_TYPE_WITH_CODE (GstSpeexEnc, gst_speex_enc, GST_TYPE_AUDIO_ENCODER, G_IMPLEMENT_INTERFACE (GST_TYPE_TAG_SETTER, NULL); G_IMPLEMENT_INTERFACE (GST_TYPE_PRESET, NULL)); +GST_ELEMENT_REGISTER_DEFINE_WITH_CODE (speexenc, "speexenc", + GST_RANK_PRIMARY, GST_TYPE_SPEEX_ENC, speex_element_init (plugin)); static void gst_speex_enc_class_init (GstSpeexEncClass * klass) diff --git a/ext/speex/meson.build b/ext/speex/meson.build index f7e2fdb1fc..6a65d0d90f 100644 --- a/ext/speex/meson.build +++ b/ext/speex/meson.build @@ -1,4 +1,5 @@ speex_sources = [ + 'gstspeexelement.c', 'gstspeex.c', 'gstspeexdec.c', 'gstspeexenc.c',