From 762e3c31b5429c7be38f76402d5974e8f743a61a Mon Sep 17 00:00:00 2001 From: =?utf8?q?St=C3=A9phane=20Cerveau?= Date: Thu, 11 Feb 2021 19:53:30 +0100 Subject: [PATCH] flac: allow per feature registration Split plugin into features including dynamic types 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/flac/gstflac.c | 30 ++++++------------------------ ext/flac/gstflacdec.c | 5 +++++ ext/flac/gstflacelement.c | 43 +++++++++++++++++++++++++++++++++++++++++++ ext/flac/gstflacelements.h | 36 ++++++++++++++++++++++++++++++++++++ ext/flac/gstflacenc.c | 4 ++++ ext/flac/gstflactag.c | 3 +++ ext/flac/meson.build | 1 + 7 files changed, 98 insertions(+), 24 deletions(-) create mode 100644 ext/flac/gstflacelement.c create mode 100644 ext/flac/gstflacelements.h diff --git a/ext/flac/gstflac.c b/ext/flac/gstflac.c index 2b88b2a..399deaa 100644 --- a/ext/flac/gstflac.c +++ b/ext/flac/gstflac.c @@ -21,36 +21,18 @@ #include "config.h" #endif -#include "gstflacenc.h" -#include "gstflacdec.h" -#include "gstflactag.h" - -#include -#include +#include "gstflacelements.h" static gboolean plugin_init (GstPlugin * plugin) { -#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 - - if (!gst_element_register (plugin, "flacenc", GST_RANK_PRIMARY, - GST_TYPE_FLAC_ENC)) - return FALSE; - if (!gst_element_register (plugin, "flacdec", GST_RANK_PRIMARY, - GST_TYPE_FLAC_DEC)) - return FALSE; - if (!gst_element_register (plugin, "flactag", GST_RANK_PRIMARY, - gst_flac_tag_get_type ())) - return FALSE; + gboolean ret = FALSE; - gst_tag_register_musicbrainz_tags (); + ret |= GST_ELEMENT_REGISTER (flacdec, plugin); + ret |= GST_ELEMENT_REGISTER (flacenc, plugin); + ret |= GST_ELEMENT_REGISTER (flactag, plugin); - return TRUE; + return ret; } GST_PLUGIN_DEFINE (GST_VERSION_MAJOR, diff --git a/ext/flac/gstflacdec.c b/ext/flac/gstflacdec.c index 468675d..361d181 100644 --- a/ext/flac/gstflacdec.c +++ b/ext/flac/gstflacdec.c @@ -47,6 +47,8 @@ #include #include +#include "gstflacelements.h" + /* Taken from http://flac.sourceforge.net/format.html#frame_header */ static const GstAudioChannelPosition channel_positions[8][8] = { {GST_AUDIO_CHANNEL_POSITION_MONO}, @@ -114,6 +116,9 @@ static GstFlowReturn gst_flac_dec_handle_frame (GstAudioDecoder * audio_dec, GstBuffer * buf); G_DEFINE_TYPE (GstFlacDec, gst_flac_dec, GST_TYPE_AUDIO_DECODER); +GST_ELEMENT_REGISTER_DEFINE_WITH_CODE (flacdec, "flacdec", GST_RANK_PRIMARY, + GST_TYPE_FLAC_DEC, flac_element_init (plugin)); + #if G_BYTE_ORDER == G_LITTLE_ENDIAN #define FORMATS "{ S8, S16LE, S24_32LE, S32LE } " diff --git a/ext/flac/gstflacelement.c b/ext/flac/gstflacelement.c new file mode 100644 index 0000000..23eb3ba --- /dev/null +++ b/ext/flac/gstflacelement.c @@ -0,0 +1,43 @@ +/* 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 "config.h" +#endif + +#include "gstflacelements.h" + +#include +#include + +void +flac_element_init (GstPlugin * plugin) +{ + static gsize res = FALSE; + if (g_once_init_enter (&res)) { +#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 + gst_tag_register_musicbrainz_tags (); + g_once_init_leave (&res, TRUE); + } +} diff --git a/ext/flac/gstflacelements.h b/ext/flac/gstflacelements.h new file mode 100644 index 0000000..6e24972 --- /dev/null +++ b/ext/flac/gstflacelements.h @@ -0,0 +1,36 @@ +/* + * 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_FLAC_ELEMENTS_H__ +#define __GST_FLAC_ELEMENTS_H__ + +#include + +G_BEGIN_DECLS + + +void flac_element_init (GstPlugin * plugin); + +GST_ELEMENT_REGISTER_DECLARE (flacenc); +GST_ELEMENT_REGISTER_DECLARE (flacdec); +GST_ELEMENT_REGISTER_DECLARE (flactag); + +G_END_DECLS + +#endif /* __GST_FLAC_ELEMENTS_H__ */ diff --git a/ext/flac/gstflacenc.c b/ext/flac/gstflacenc.c index 7c0016e..1993e7d 100644 --- a/ext/flac/gstflacenc.c +++ b/ext/flac/gstflacenc.c @@ -55,6 +55,8 @@ #include #include +#include "gstflacelements.h" + /* Taken from http://flac.sourceforge.net/format.html#frame_header */ static const GstAudioChannelPosition channel_positions[8][8] = { {GST_AUDIO_CHANNEL_POSITION_MONO}, @@ -131,6 +133,8 @@ G_DEFINE_TYPE_WITH_CODE (GstFlacEnc, gst_flac_enc, GST_TYPE_AUDIO_ENCODER, G_IMPLEMENT_INTERFACE (GST_TYPE_TAG_SETTER, NULL) G_IMPLEMENT_INTERFACE (GST_TYPE_TOC_SETTER, NULL) ); +GST_ELEMENT_REGISTER_DEFINE_WITH_CODE (flacenc, "flacenc", GST_RANK_PRIMARY, + GST_TYPE_FLAC_ENC, flac_element_init (plugin)); static gboolean gst_flac_enc_start (GstAudioEncoder * enc); static gboolean gst_flac_enc_stop (GstAudioEncoder * enc); diff --git a/ext/flac/gstflactag.c b/ext/flac/gstflactag.c index 1ae694a..4dff282 100644 --- a/ext/flac/gstflactag.c +++ b/ext/flac/gstflactag.c @@ -54,6 +54,7 @@ #include #include +#include "gstflacelements.h" #include "gstflactag.h" GST_DEBUG_CATEGORY_STATIC (flactag_debug); @@ -89,6 +90,8 @@ static gboolean gst_flac_tag_sink_event (GstPad * pad, GstObject * parent, #define gst_flac_tag_parent_class parent_class G_DEFINE_TYPE_WITH_CODE (GstFlacTag, gst_flac_tag, GST_TYPE_ELEMENT, G_IMPLEMENT_INTERFACE (GST_TYPE_TAG_SETTER, NULL)); +GST_ELEMENT_REGISTER_DEFINE_WITH_CODE (flactag, "flactag", GST_RANK_PRIMARY, + GST_TYPE_FLAC_TAG, flac_element_init (plugin)); static void diff --git a/ext/flac/meson.build b/ext/flac/meson.build index f004adc..f6b1dee 100644 --- a/ext/flac/meson.build +++ b/ext/flac/meson.build @@ -1,5 +1,6 @@ flac_sources = [ 'gstflac.c', + 'gstflacelement.c', 'gstflacdec.c', 'gstflacenc.c', 'gstflactag.c', -- 2.7.4