diff --git a/ext/wavpack/gstwavpack.c b/ext/wavpack/gstwavpack.c index 1609aa2e1e..17fe96850e 100644 --- a/ext/wavpack/gstwavpack.c +++ b/ext/wavpack/gstwavpack.c @@ -1,7 +1,7 @@ /* GStreamer wavpack plugin * (c) 2004 Arwed v. Merkatz * - * gstwavpack.c: plugin loader + * gstwavpackplugin.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 @@ -23,28 +23,17 @@ #include "config.h" #endif -#include - -#include "gstwavpackdec.h" -#include "gstwavpackenc.h" - -/* debug category for common code */ -GST_DEBUG_CATEGORY (wavpack_debug); +#include "gstwavpackelements.h" static gboolean plugin_init (GstPlugin * plugin) { - GST_DEBUG_CATEGORY_INIT (wavpack_debug, "wavpack", 0, "Wavpack elements"); + gboolean ret = FALSE; -#ifdef ENABLE_NLS - GST_DEBUG ("binding text domain %s to locale dir %s", GETTEXT_PACKAGE, - LOCALEDIR); - bindtextdomain (GETTEXT_PACKAGE, LOCALEDIR); - bind_textdomain_codeset (GETTEXT_PACKAGE, "UTF-8"); -#endif + ret |= GST_ELEMENT_REGISTER (wavpackdec, plugin); + ret |= GST_ELEMENT_REGISTER (wavpackenc, plugin); - return (gst_wavpack_dec_plugin_init (plugin) - && gst_wavpack_enc_plugin_init (plugin)); + return ret; } GST_PLUGIN_DEFINE (GST_VERSION_MAJOR, diff --git a/ext/wavpack/gstwavpackdec.c b/ext/wavpack/gstwavpackdec.c index 9fc32d8350..47368929e6 100644 --- a/ext/wavpack/gstwavpackdec.c +++ b/ext/wavpack/gstwavpackdec.c @@ -49,6 +49,7 @@ #include #include +#include "gstwavpackelements.h" #include "gstwavpackdec.h" #include "gstwavpackcommon.h" #include "gstwavpackstreamreader.h" @@ -101,6 +102,12 @@ static void gst_wavpack_dec_post_tags (GstWavpackDec * dec); #define gst_wavpack_dec_parent_class parent_class G_DEFINE_TYPE (GstWavpackDec, gst_wavpack_dec, GST_TYPE_AUDIO_DECODER); +#define _do_init \ + GST_DEBUG_CATEGORY_INIT (gst_wavpack_dec_debug, "wavpackdec", 0, \ + "Wavpack decoder"); \ + wavpack_element_init (plugin); +GST_ELEMENT_REGISTER_DEFINE_WITH_CODE (wavpackdec, "wavpackdec", + GST_RANK_PRIMARY, GST_TYPE_WAVPACK_DEC, _do_init); static void gst_wavpack_dec_class_init (GstWavpackDecClass * klass) @@ -473,14 +480,3 @@ decode_error: goto out; } } - -gboolean -gst_wavpack_dec_plugin_init (GstPlugin * plugin) -{ - if (!gst_element_register (plugin, "wavpackdec", - GST_RANK_PRIMARY, GST_TYPE_WAVPACK_DEC)) - return FALSE; - GST_DEBUG_CATEGORY_INIT (gst_wavpack_dec_debug, "wavpackdec", 0, - "Wavpack decoder"); - return TRUE; -} diff --git a/ext/wavpack/gstwavpackelement.c b/ext/wavpack/gstwavpackelement.c new file mode 100644 index 0000000000..65ec0e8e78 --- /dev/null +++ b/ext/wavpack/gstwavpackelement.c @@ -0,0 +1,48 @@ +/* GStreamer wavpack plugin + * (c) 2004 Arwed v. Merkatz + * + * gstwavpack.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 + +#include "gstwavpackelements.h" + +/* debug category for common code */ +GST_DEBUG_CATEGORY (wavpack_debug); + +void +wavpack_element_init (GstPlugin * plugin) +{ + static gsize res = FALSE; + if (g_once_init_enter (&res)) { + GST_DEBUG_CATEGORY_INIT (wavpack_debug, "wavpack", 0, "Wavpack elements"); + +#ifdef ENABLE_NLS + GST_DEBUG ("binding text domain %s to locale dir %s", GETTEXT_PACKAGE, + LOCALEDIR); + bindtextdomain (GETTEXT_PACKAGE, LOCALEDIR); + bind_textdomain_codeset (GETTEXT_PACKAGE, "UTF-8"); +#endif + g_once_init_leave (&res, TRUE); + } +} diff --git a/ext/wavpack/gstwavpackelements.h b/ext/wavpack/gstwavpackelements.h new file mode 100644 index 0000000000..d165540e47 --- /dev/null +++ b/ext/wavpack/gstwavpackelements.h @@ -0,0 +1,38 @@ +/* + * 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_WAVPACK_ELEMENTS_H__ +#define __GST_WAVPACK_ELEMENTS_H__ + +#ifdef HAVE_CONFIG_H +#include "config.h" +#endif + +#include + +G_BEGIN_DECLS + +void wavpack_element_init (GstPlugin * plugin); + +GST_ELEMENT_REGISTER_DECLARE (wavpackdec); +GST_ELEMENT_REGISTER_DECLARE (wavpackenc); + +G_END_DECLS + +#endif /* __GST_WAVPACK_ELEMENTS_H__ */ diff --git a/ext/wavpack/gstwavpackenc.c b/ext/wavpack/gstwavpackenc.c index 7c38aaea87..972a5a3975 100644 --- a/ext/wavpack/gstwavpackenc.c +++ b/ext/wavpack/gstwavpackenc.c @@ -54,6 +54,7 @@ #include #include "gstwavpackenc.h" #include "gstwavpackcommon.h" +#include "gstwavpackelements.h" static gboolean gst_wavpack_enc_start (GstAudioEncoder * enc); static gboolean gst_wavpack_enc_stop (GstAudioEncoder * enc); @@ -200,6 +201,12 @@ gst_wavpack_enc_joint_stereo_mode_get_type (void) #define gst_wavpack_enc_parent_class parent_class G_DEFINE_TYPE (GstWavpackEnc, gst_wavpack_enc, GST_TYPE_AUDIO_ENCODER); +#define _do_init \ + GST_DEBUG_CATEGORY_INIT (gst_wavpack_enc_debug, "wavpackenc", 0, \ + "Wavpack encoder"); \ + wavpack_element_init (plugin); +GST_ELEMENT_REGISTER_DEFINE_WITH_CODE (wavpackenc, "wavpackenc", GST_RANK_NONE, + GST_TYPE_WAVPACK_ENC, _do_init); static void gst_wavpack_enc_class_init (GstWavpackEncClass * klass) @@ -994,16 +1001,3 @@ gst_wavpack_enc_get_property (GObject * object, guint prop_id, GValue * value, break; } } - -gboolean -gst_wavpack_enc_plugin_init (GstPlugin * plugin) -{ - if (!gst_element_register (plugin, "wavpackenc", - GST_RANK_NONE, GST_TYPE_WAVPACK_ENC)) - return FALSE; - - GST_DEBUG_CATEGORY_INIT (gst_wavpack_enc_debug, "wavpackenc", 0, - "Wavpack encoder"); - - return TRUE; -} diff --git a/ext/wavpack/meson.build b/ext/wavpack/meson.build index ce94faf942..7293283f79 100644 --- a/ext/wavpack/meson.build +++ b/ext/wavpack/meson.build @@ -1,4 +1,5 @@ wavpack_sources = [ + 'gstwavpackelement.c', 'gstwavpack.c', 'gstwavpackcommon.c', 'gstwavpackdec.c',