pulse: allow per feature registration
authorStéphane Cerveau <scerveau@collabora.com>
Fri, 12 Feb 2021 10:12:34 +0000 (11:12 +0100)
committerStéphane Cerveau <scerveau@collabora.com>
Mon, 29 Mar 2021 10:45:22 +0000 (12:45 +0200)
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: <https://gitlab.freedesktop.org/gstreamer/gst-plugins-good/-/merge_requests/876>

ext/pulse/gstpulseelement.c [new file with mode: 0644]
ext/pulse/gstpulseelements.h [new file with mode: 0644]
ext/pulse/meson.build
ext/pulse/plugin.c
ext/pulse/pulsesink.c
ext/pulse/pulsesrc.c

diff --git a/ext/pulse/gstpulseelement.c b/ext/pulse/gstpulseelement.c
new file mode 100644 (file)
index 0000000..d539408
--- /dev/null
@@ -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 <gst/gst-i18n-plugin.h>
+
+#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 (file)
index 0000000..d356242
--- /dev/null
@@ -0,0 +1,39 @@
+/*
+ *  GStreamer pulseaudio plugin
+ *
+ *  Copyright (c) 2004-2008 Lennart Poettering
+ * Copyright (C) 2020 Huawei Technologies Co., Ltd.
+ *   @Author: Julian Bouzas <julian.bouzas@collabora.com>
+ *
+ * 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 <gst/gst.h>
+
+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__ */
index 0b77abf..53be146 100644 (file)
@@ -1,4 +1,5 @@
 pulse_sources = [
+  'gstpulseelement.c',
   'plugin.c',
   'pulsesink.c',
   'pulsesrc.c',
index a2c8fe5..59d8ab1 100644 (file)
 #include "config.h"
 #endif
 
-#include <gst/gst-i18n-plugin.h>
-
-#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,
index b3a5866..a61c93d 100644 (file)
@@ -59,6 +59,7 @@
 
 #include <gst/glib-compat-private.h>
 
+#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)
index ed74771..a337a59 100644 (file)
@@ -45,6 +45,7 @@
 #include <gst/gsttaglist.h>
 #include <gst/audio/audio.h>
 
+#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)