opus: allow per feature registration
authorStéphane Cerveau <scerveau@collabora.com>
Fri, 11 Dec 2020 15:59:50 +0000 (16:59 +0100)
committerGStreamer Marge Bot <gitlab-merge-bot@gstreamer-foundation.org>
Tue, 16 Mar 2021 17:58:59 +0000 (17:58 +0000)
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-base/-/merge_requests/1029>

ext/opus/gstopus.c
ext/opus/gstopusdec.c
ext/opus/gstopuselement.c [new file with mode: 0644]
ext/opus/gstopuselements.h [new file with mode: 0644]
ext/opus/gstopusenc.c
ext/opus/meson.build

index e16acea..43e5954 100644 (file)
 #include <config.h>
 #endif
 
-#include "gstopusdec.h"
-#include "gstopusenc.h"
-
-#include <gst/tag/tag.h>
+#include "gstopuselements.h"
 
 static gboolean
 plugin_init (GstPlugin * plugin)
 {
+  gboolean ret = FALSE;
 
-  if (!gst_element_register (plugin, "opusenc", GST_RANK_PRIMARY,
-          GST_TYPE_OPUS_ENC))
-    return FALSE;
-
-  if (!gst_element_register (plugin, "opusdec", GST_RANK_PRIMARY,
-          GST_TYPE_OPUS_DEC))
-    return FALSE;
-
-  gst_tag_register_musicbrainz_tags ();
+  ret |= GST_ELEMENT_REGISTER (opusenc, plugin);
+  ret |= GST_ELEMENT_REGISTER (opusdec, plugin);
 
-  return TRUE;
+  return ret;
 }
 
 GST_PLUGIN_DEFINE (GST_VERSION_MAJOR,
index 987c8f0..c4f5df8 100644 (file)
@@ -46,6 +46,7 @@
 #include <math.h>
 #include <string.h>
 #include <stdio.h>
+#include "gstopuselements.h"
 #include "gstopusheader.h"
 #include "gstopuscommon.h"
 #include "gstopusdec.h"
@@ -78,6 +79,8 @@ static GstStaticPadTemplate opus_dec_sink_factory =
     );
 
 G_DEFINE_TYPE (GstOpusDec, gst_opus_dec, GST_TYPE_AUDIO_DECODER);
+GST_ELEMENT_REGISTER_DEFINE_WITH_CODE (opusdec, "opusdec",
+    GST_RANK_PRIMARY, GST_TYPE_OPUS_DEC, opus_element_init (plugin));
 
 #define DB_TO_LINEAR(x) pow (10., (x) / 20.)
 
diff --git a/ext/opus/gstopuselement.c b/ext/opus/gstopuselement.c
new file mode 100644 (file)
index 0000000..3c661d2
--- /dev/null
@@ -0,0 +1,39 @@
+/* GStreamer
+ * Copyright (C) <1999> Erik Walthinsen <omega@cse.ogi.edu>
+ * Copyright (C) <2008> Sebastian Dröge <sebastian.droege@collabora.co.uk>
+ * 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.
+ */
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+
+#include "gstopuselements.h"
+
+#include <gst/tag/tag.h>
+
+void
+opus_element_init (GstPlugin * plugin)
+{
+  static gsize res = FALSE;
+
+  if (g_once_init_enter (&res)) {
+    gst_tag_register_musicbrainz_tags ();
+    g_once_init_leave (&res, TRUE);
+  }
+}
diff --git a/ext/opus/gstopuselements.h b/ext/opus/gstopuselements.h
new file mode 100644 (file)
index 0000000..e4e671b
--- /dev/null
@@ -0,0 +1,37 @@
+/*
+ * Copyright (C) <1999> Erik Walthinsen <omega@cse.ogi.edu>
+ * Copyright (C) <2008> Sebastian Dröge <sebastian.droege@collabora.co.uk>
+ * 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_OPUS_ELEMENTS_H__
+#define __GST_OPUS_ELEMENTS_H__
+
+#include <gst/gst.h>
+
+G_BEGIN_DECLS
+
+
+G_GNUC_INTERNAL void opus_element_init (GstPlugin * plugin);
+
+GST_ELEMENT_REGISTER_DECLARE (opusenc);
+GST_ELEMENT_REGISTER_DECLARE (opusdec);
+
+G_END_DECLS
+
+#endif /* __GST_OPUS_ELEMENTS_H__ */
index bbe1f99..305663a 100644 (file)
@@ -52,6 +52,8 @@
 #include <gst/pbutils/pbutils.h>
 #include <gst/tag/tag.h>
 #include <gst/glib-compat-private.h>
+
+#include "gstopuselements.h"
 #include "gstopusheader.h"
 #include "gstopuscommon.h"
 #include "gstopusenc.h"
@@ -243,6 +245,8 @@ static GstFlowReturn gst_opus_enc_encode (GstOpusEnc * enc, GstBuffer * buffer);
 G_DEFINE_TYPE_WITH_CODE (GstOpusEnc, gst_opus_enc, GST_TYPE_AUDIO_ENCODER,
     G_IMPLEMENT_INTERFACE (GST_TYPE_TAG_SETTER, NULL);
     G_IMPLEMENT_INTERFACE (GST_TYPE_PRESET, NULL));
+GST_ELEMENT_REGISTER_DEFINE_WITH_CODE (opusenc, "opusenc",
+    GST_RANK_PRIMARY, GST_TYPE_OPUS_ENC, opus_element_init (plugin));
 
 static void
 gst_opus_enc_set_tags (GstOpusEnc * enc)
index cca4a3b..2b49902 100644 (file)
@@ -1,5 +1,6 @@
 opus_sources = [
   'gstopus.c',
+  'gstopuselement.c',
   'gstopuscommon.c',
   'gstopusdec.c',
   'gstopusenc.c',