From 1b30f6072a495af4a9443efaa0f062393ad8c652 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?St=C3=A9phane=20Cerveau?= Date: Fri, 19 Feb 2021 12:30:50 +0100 Subject: [PATCH] sndfile: 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/sndfile/gstsf.c | 91 +---------------- ext/sndfile/gstsfdec.c | 4 +- ext/sndfile/gstsfdec.h | 2 +- ext/sndfile/gstsfelement.c | 121 +++++++++++++++++++++++ ext/sndfile/{gstsf.h => gstsfelements.h} | 16 +-- ext/sndfile/gstsfsink.h | 5 + ext/sndfile/meson.build | 2 +- 7 files changed, 138 insertions(+), 103 deletions(-) create mode 100644 ext/sndfile/gstsfelement.c rename ext/sndfile/{gstsf.h => gstsfelements.h} (74%) diff --git a/ext/sndfile/gstsf.c b/ext/sndfile/gstsf.c index ab589bd097..6fb9668258 100644 --- a/ext/sndfile/gstsf.c +++ b/ext/sndfile/gstsf.c @@ -25,100 +25,13 @@ #include #include -#include "gstsf.h" +#include "gstsfelements.h" -/* sf formats */ - -GstCaps * -gst_sf_create_audio_template_caps (void) -{ - GstCaps *caps = gst_caps_new_empty (); - SF_FORMAT_INFO format_info; - const gchar *fmt; - gint k, count; - - sf_command (NULL, SFC_GET_FORMAT_MAJOR_COUNT, &count, sizeof (gint)); - - for (k = 0; k < count; k++) { - format_info.format = k; - sf_command (NULL, SFC_GET_FORMAT_MAJOR, &format_info, sizeof (format_info)); - - switch (format_info.format) { - case SF_FORMAT_IRCAM: /* Berkeley/IRCAM/CARL */ - fmt = "audio/x-ircam"; - break; - case SF_FORMAT_NIST: /* Sphere NIST format. */ - fmt = "audio/x-nist"; - break; - case SF_FORMAT_PAF: /* Ensoniq PARIS file format. */ - fmt = "audio/x-paris"; - break; - case SF_FORMAT_SDS: /* Midi Sample Dump Standard */ - fmt = "audio/x-sds"; - break; - case SF_FORMAT_SVX: /* Amiga IFF / SVX8 / SV16 format. */ - fmt = "audio/x-svx"; - break; - case SF_FORMAT_VOC: /* VOC files. */ - fmt = "audio/x-voc"; - break; - case SF_FORMAT_W64: /* Sonic Foundry's 64 bit RIFF/WAV */ - fmt = "audio/x-w64"; - break; - case SF_FORMAT_XI: /* Fasttracker 2 Extended Instrument */ - fmt = "audio/x-xi"; - break; - case SF_FORMAT_RF64: /* RF64 WAV file */ - fmt = "audio/x-rf64"; - break; - /* does not make sense to expose that */ - case SF_FORMAT_RAW: /* RAW PCM data. */ - /* we have other elements to handle these */ - case SF_FORMAT_AIFF: /* Apple/SGI AIFF format */ - case SF_FORMAT_AU: /* Sun/NeXT AU format */ - case SF_FORMAT_FLAC: /* FLAC lossless file format */ - case SF_FORMAT_OGG: /* Xiph OGG container */ - case SF_FORMAT_WAV: /* Microsoft WAV format */ - case SF_FORMAT_WAVEX: /* MS WAVE with WAVEFORMATEX */ - fmt = NULL; - GST_LOG ("skipping format '%s'", format_info.name); - break; - case SF_FORMAT_MAT4: /* Matlab (tm) V4.2 / GNU Octave 2.0 */ - case SF_FORMAT_MAT5: /* Matlab (tm) V5.0 / GNU Octave 2.1 */ - case SF_FORMAT_PVF: /* Portable Voice Format */ - case SF_FORMAT_HTK: /* HMM Tool Kit format */ - case SF_FORMAT_AVR: /* Audio Visual Research */ - case SF_FORMAT_SD2: /* Sound Designer 2 */ - case SF_FORMAT_CAF: /* Core Audio File format */ - case SF_FORMAT_WVE: /* Psion WVE format */ - case SF_FORMAT_MPC2K: /* Akai MPC 2000 sampler */ - default: - fmt = NULL; - GST_WARNING ("format 0x%x: '%s' is not mapped", format_info.format, - format_info.name); - } - if (fmt != NULL) { - gst_caps_append_structure (caps, gst_structure_new_empty (fmt)); - } - } - return gst_caps_simplify (caps); -} 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 /* ENABLE_NLS */ - - if (!gst_element_register (plugin, "sfdec", GST_RANK_MARGINAL, - gst_sf_dec_get_type ())) - return FALSE; - - return TRUE; + return GST_ELEMENT_REGISTER (sfdec, plugin); } GST_PLUGIN_DEFINE (GST_VERSION_MAJOR, diff --git a/ext/sndfile/gstsfdec.c b/ext/sndfile/gstsfdec.c index 24a0e2dd32..646f9535c2 100644 --- a/ext/sndfile/gstsfdec.c +++ b/ext/sndfile/gstsfdec.c @@ -25,6 +25,7 @@ #include #include +#include "gstsfelements.h" #include "gstsfdec.h" #define FORMATS \ @@ -62,7 +63,8 @@ static gboolean gst_sf_dec_stop (GstSFDec * bsrc); GST_DEBUG_CATEGORY_INIT (gst_sf_dec_debug, "sfdec", 0, "sfdec element"); #define gst_sf_dec_parent_class parent_class G_DEFINE_TYPE_WITH_CODE (GstSFDec, gst_sf_dec, GST_TYPE_ELEMENT, _do_init); - +GST_ELEMENT_REGISTER_DEFINE_WITH_CODE (sfdec, "sfdec", GST_RANK_MARGINAL, + GST_TYPE_SF_DEC, sf_element_init (plugin)); /* sf virtual io */ static sf_count_t diff --git a/ext/sndfile/gstsfdec.h b/ext/sndfile/gstsfdec.h index bcc20eddb0..8e4dda1a65 100644 --- a/ext/sndfile/gstsfdec.h +++ b/ext/sndfile/gstsfdec.h @@ -22,7 +22,6 @@ #define __GST_SF_DEC_H__ -#include "gstsf.h" #include @@ -69,6 +68,7 @@ struct _GstSFDecClass { GstElementClass parent_class; }; +GType gst_sf_dec_get_type (void); G_END_DECLS diff --git a/ext/sndfile/gstsfelement.c b/ext/sndfile/gstsfelement.c new file mode 100644 index 0000000000..2151a457ba --- /dev/null +++ b/ext/sndfile/gstsfelement.c @@ -0,0 +1,121 @@ +/* GStreamer libsndfile plugin + * Copyright (C) 2003 Andy Wingo + * + * 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 + +#include "gstsfelements.h" + +/* sf formats */ + +GstCaps * +gst_sf_create_audio_template_caps (void) +{ + GstCaps *caps = gst_caps_new_empty (); + SF_FORMAT_INFO format_info; + const gchar *fmt; + gint k, count; + + sf_command (NULL, SFC_GET_FORMAT_MAJOR_COUNT, &count, sizeof (gint)); + + for (k = 0; k < count; k++) { + format_info.format = k; + sf_command (NULL, SFC_GET_FORMAT_MAJOR, &format_info, sizeof (format_info)); + + switch (format_info.format) { + case SF_FORMAT_IRCAM: /* Berkeley/IRCAM/CARL */ + fmt = "audio/x-ircam"; + break; + case SF_FORMAT_NIST: /* Sphere NIST format. */ + fmt = "audio/x-nist"; + break; + case SF_FORMAT_PAF: /* Ensoniq PARIS file format. */ + fmt = "audio/x-paris"; + break; + case SF_FORMAT_SDS: /* Midi Sample Dump Standard */ + fmt = "audio/x-sds"; + break; + case SF_FORMAT_SVX: /* Amiga IFF / SVX8 / SV16 format. */ + fmt = "audio/x-svx"; + break; + case SF_FORMAT_VOC: /* VOC files. */ + fmt = "audio/x-voc"; + break; + case SF_FORMAT_W64: /* Sonic Foundry's 64 bit RIFF/WAV */ + fmt = "audio/x-w64"; + break; + case SF_FORMAT_XI: /* Fasttracker 2 Extended Instrument */ + fmt = "audio/x-xi"; + break; + case SF_FORMAT_RF64: /* RF64 WAV file */ + fmt = "audio/x-rf64"; + break; + /* does not make sense to expose that */ + case SF_FORMAT_RAW: /* RAW PCM data. */ + /* we have other elements to handle these */ + case SF_FORMAT_AIFF: /* Apple/SGI AIFF format */ + case SF_FORMAT_AU: /* Sun/NeXT AU format */ + case SF_FORMAT_FLAC: /* FLAC lossless file format */ + case SF_FORMAT_OGG: /* Xiph OGG container */ + case SF_FORMAT_WAV: /* Microsoft WAV format */ + case SF_FORMAT_WAVEX: /* MS WAVE with WAVEFORMATEX */ + fmt = NULL; + GST_LOG ("skipping format '%s'", format_info.name); + break; + case SF_FORMAT_MAT4: /* Matlab (tm) V4.2 / GNU Octave 2.0 */ + case SF_FORMAT_MAT5: /* Matlab (tm) V5.0 / GNU Octave 2.1 */ + case SF_FORMAT_PVF: /* Portable Voice Format */ + case SF_FORMAT_HTK: /* HMM Tool Kit format */ + case SF_FORMAT_AVR: /* Audio Visual Research */ + case SF_FORMAT_SD2: /* Sound Designer 2 */ + case SF_FORMAT_CAF: /* Core Audio File format */ + case SF_FORMAT_WVE: /* Psion WVE format */ + case SF_FORMAT_MPC2K: /* Akai MPC 2000 sampler */ + default: + fmt = NULL; + GST_WARNING ("format 0x%x: '%s' is not mapped", format_info.format, + format_info.name); + } + if (fmt != NULL) { + gst_caps_append_structure (caps, gst_structure_new_empty (fmt)); + } + } + return gst_caps_simplify (caps); +} + +void +sf_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 /* ENABLE_NLS */ + g_once_init_leave (&res, TRUE); + } +} diff --git a/ext/sndfile/gstsf.h b/ext/sndfile/gstsfelements.h similarity index 74% rename from ext/sndfile/gstsf.h rename to ext/sndfile/gstsfelements.h index 71584569f1..0670726eec 100644 --- a/ext/sndfile/gstsf.h +++ b/ext/sndfile/gstsfelements.h @@ -18,27 +18,21 @@ */ -#ifndef __GST_SFSINK_H__ -#define __GST_SFSINK_H__ +#ifndef __GST_SFELEMENTS_H__ +#define __GST_SFELEMENTS_H__ #include #include - G_BEGIN_DECLS GstCaps *gst_sf_create_audio_template_caps (void); +void sf_element_init(GstPlugin * plugin); -#define GST_TYPE_SF_MAJOR_TYPES (gst_sf_major_types_get_type()) -#define GST_TYPE_SF_MINOR_TYPES (gst_sf_minor_types_get_type()) - -GType gst_sf_major_types_get_type (void); -GType gst_sf_minor_types_get_type (void); - -GType gst_sf_dec_get_type (void); +GST_ELEMENT_REGISTER_DECLARE (sfdec); G_END_DECLS -#endif /* __GST_SFSINK_H__ */ +#endif /* __GST_SFELEMENTS_H__ */ diff --git a/ext/sndfile/gstsfsink.h b/ext/sndfile/gstsfsink.h index 28eedd2543..c9e86ec9ea 100644 --- a/ext/sndfile/gstsfsink.h +++ b/ext/sndfile/gstsfsink.h @@ -66,6 +66,11 @@ struct _GstSFSinkClass { GstBaseSinkClass parent_class; }; +#define GST_TYPE_SF_MAJOR_TYPES (gst_sf_major_types_get_type()) +#define GST_TYPE_SF_MINOR_TYPES (gst_sf_minor_types_get_type()) + +GType gst_sf_major_types_get_type (void); +GType gst_sf_minor_types_get_type (void); G_END_DECLS diff --git a/ext/sndfile/meson.build b/ext/sndfile/meson.build index 6e048f55b3..a0e850a77f 100644 --- a/ext/sndfile/meson.build +++ b/ext/sndfile/meson.build @@ -2,7 +2,7 @@ sndfile_dep = dependency('sndfile', version: '>= 1.0.16', required: get_option(' if sndfile_dep.found() gstsndfile = library('gstsndfile', - 'gstsf.c', 'gstsfdec.c', # 'gstsfsink.c', 'gstsfsrc.c', + 'gstsf.c', 'gstsfelement.c', 'gstsfdec.c', # 'gstsfsink.c', 'gstsfsrc.c', c_args: gst_plugins_bad_args, include_directories: [configinc, libsinc], dependencies: [gstaudio_dep, gst_dep, sndfile_dep],