From 8c4c4b5cff8f2eb8f959b5da540d56dc4895529a Mon Sep 17 00:00:00 2001 From: =?utf8?q?St=C3=A9phane=20Cerveau?= Date: Fri, 12 Feb 2021 11:12:34 +0100 Subject: [PATCH] pulse: 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/pulse/gstpulseelement.c | 53 ++++++++++++++++++++++++++++++++++++++++++++ ext/pulse/gstpulseelements.h | 39 ++++++++++++++++++++++++++++++++ ext/pulse/meson.build | 1 + ext/pulse/plugin.c | 31 +++++--------------------- ext/pulse/pulsesink.c | 3 +++ ext/pulse/pulsesrc.c | 3 +++ 6 files changed, 105 insertions(+), 25 deletions(-) create mode 100644 ext/pulse/gstpulseelement.c create mode 100644 ext/pulse/gstpulseelements.h diff --git a/ext/pulse/gstpulseelement.c b/ext/pulse/gstpulseelement.c new file mode 100644 index 0000000..d539408 --- /dev/null +++ b/ext/pulse/gstpulseelement.c @@ -0,0 +1,53 @@ +/* + * GStreamer pulseaudio plugin + * + * Copyright (c) 2004-2008 Lennart Poettering + * + * gst-pulse is free software; you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as + * published by the Free Software Foundation; either version 2.1 of the + * License, or (at your option) any later version. + * + * gst-pulse 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 + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with gst-pulse; 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 "gstpulseelements.h" +#include "pulsedeviceprovider.h" + +GST_DEBUG_CATEGORY (pulse_debug); + +GST_DEVICE_PROVIDER_REGISTER_DEFINE (pulsedeviceprovider, "pulsedeviceprovider", + GST_RANK_PRIMARY, GST_TYPE_PULSE_DEVICE_PROVIDER); + +void +pulse_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_DEBUG_CATEGORY_INIT (pulse_debug, "pulse", 0, "PulseAudio elements"); + + g_once_init_leave (&res, TRUE); + } +} diff --git a/ext/pulse/gstpulseelements.h b/ext/pulse/gstpulseelements.h new file mode 100644 index 0000000..d356242 --- /dev/null +++ b/ext/pulse/gstpulseelements.h @@ -0,0 +1,39 @@ +/* + * GStreamer pulseaudio plugin + * + * Copyright (c) 2004-2008 Lennart Poettering + * 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_PULSE_ELEMENTS_H__ +#define __GST_PULSE_ELEMENTS_H__ + +#include + +G_BEGIN_DECLS + +void pulse_element_init (GstPlugin * plugin); + +GST_ELEMENT_REGISTER_DECLARE (pulsesink); +GST_ELEMENT_REGISTER_DECLARE (pulsesrc); + +GST_DEVICE_PROVIDER_REGISTER_DECLARE (pulsedeviceprovider); + +G_END_DECLS + +#endif /* __GST_PULSE_ELEMENTS_H__ */ diff --git a/ext/pulse/meson.build b/ext/pulse/meson.build index 0b77abf..53be146 100644 --- a/ext/pulse/meson.build +++ b/ext/pulse/meson.build @@ -1,4 +1,5 @@ pulse_sources = [ + 'gstpulseelement.c', 'plugin.c', 'pulsesink.c', 'pulsesrc.c', diff --git a/ext/pulse/plugin.c b/ext/pulse/plugin.c index a2c8fe5..59d8ab1 100644 --- a/ext/pulse/plugin.c +++ b/ext/pulse/plugin.c @@ -23,38 +23,19 @@ #include "config.h" #endif -#include - -#include "pulsesink.h" -#include "pulsesrc.h" -#include "pulsedeviceprovider.h" - -GST_DEBUG_CATEGORY (pulse_debug); +#include "gstpulseelements.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, "pulsesink", GST_RANK_PRIMARY + 10, - GST_TYPE_PULSESINK)) - return FALSE; + gboolean ret = FALSE; - if (!gst_element_register (plugin, "pulsesrc", GST_RANK_PRIMARY + 10, - GST_TYPE_PULSESRC)) - return FALSE; + ret |= GST_ELEMENT_REGISTER (pulsesink, plugin); + ret |= GST_ELEMENT_REGISTER (pulsesrc, plugin); - if (!gst_device_provider_register (plugin, "pulsedeviceprovider", - GST_RANK_PRIMARY, GST_TYPE_PULSE_DEVICE_PROVIDER)) - return FALSE; + ret |= GST_DEVICE_PROVIDER_REGISTER (pulsedeviceprovider, plugin); - GST_DEBUG_CATEGORY_INIT (pulse_debug, "pulse", 0, "PulseAudio elements"); - return TRUE; + return ret; } GST_PLUGIN_DEFINE (GST_VERSION_MAJOR, diff --git a/ext/pulse/pulsesink.c b/ext/pulse/pulsesink.c index b3a5866..a61c93d 100644 --- a/ext/pulse/pulsesink.c +++ b/ext/pulse/pulsesink.c @@ -59,6 +59,7 @@ #include +#include "gstpulseelements.h" #include "pulsesink.h" #include "pulseutil.h" @@ -1820,6 +1821,8 @@ G_DEFINE_TYPE_WITH_CODE (GstPulseSink, gst_pulsesink, GST_TYPE_AUDIO_BASE_SINK, gst_pulsesink_init_contexts (); G_IMPLEMENT_INTERFACE (GST_TYPE_STREAM_VOLUME, NULL) ); +GST_ELEMENT_REGISTER_DEFINE_WITH_CODE (pulsesink, "pulsesink", + GST_RANK_PRIMARY + 10, GST_TYPE_PULSESINK, pulse_element_init (plugin)); static GstAudioRingBuffer * gst_pulsesink_create_ringbuffer (GstAudioBaseSink * sink) diff --git a/ext/pulse/pulsesrc.c b/ext/pulse/pulsesrc.c index ed74771..a337a59 100644 --- a/ext/pulse/pulsesrc.c +++ b/ext/pulse/pulsesrc.c @@ -45,6 +45,7 @@ #include #include +#include "gstpulseelements.h" #include "pulsesrc.h" #include "pulseutil.h" @@ -115,6 +116,8 @@ static GstClockTime gst_pulsesrc_get_time (GstClock * clock, GstPulseSrc * src); #define gst_pulsesrc_parent_class parent_class G_DEFINE_TYPE_WITH_CODE (GstPulseSrc, gst_pulsesrc, GST_TYPE_AUDIO_SRC, G_IMPLEMENT_INTERFACE (GST_TYPE_STREAM_VOLUME, NULL)); +GST_ELEMENT_REGISTER_DEFINE_WITH_CODE (pulsesrc, "pulsesrc", + GST_RANK_PRIMARY + 10, GST_TYPE_PULSESRC, pulse_element_init (plugin)); static void gst_pulsesrc_class_init (GstPulseSrcClass * klass) -- 2.7.4