adaptivedemux2: fix plugin/element init
authorStéphane Cerveau <scerveau@collabora.com>
Mon, 2 May 2022 14:55:34 +0000 (16:55 +0200)
committerGStreamer Marge Bot <gitlab-merge-bot@gstreamer-foundation.org>
Mon, 30 May 2022 13:13:48 +0000 (13:13 +0000)
In case of per features registration such as the
customizable gstreamer-full library, each
element should check that the soup library can be loaded to
facilitate the element registration.

Initialize the debug categories properly

Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer/-/merge_requests/2348>

subprojects/gst-plugins-good/ext/adaptivedemux2/dash/gstdashdemux.c
subprojects/gst-plugins-good/ext/adaptivedemux2/dash/gstdashdemux.h
subprojects/gst-plugins-good/ext/adaptivedemux2/gstadaptivedemux.c
subprojects/gst-plugins-good/ext/adaptivedemux2/gstadaptivedemuxelement.c [new file with mode: 0644]
subprojects/gst-plugins-good/ext/adaptivedemux2/gstadaptivedemuxelements.h [new file with mode: 0644]
subprojects/gst-plugins-good/ext/adaptivedemux2/hls/gsthlsdemux.c
subprojects/gst-plugins-good/ext/adaptivedemux2/hls/gsthlsdemux.h
subprojects/gst-plugins-good/ext/adaptivedemux2/meson.build
subprojects/gst-plugins-good/ext/adaptivedemux2/mss/gstmssdemux.c
subprojects/gst-plugins-good/ext/adaptivedemux2/mss/gstmssdemux.h
subprojects/gst-plugins-good/ext/adaptivedemux2/plugin.c

index c142d2b..9eef006 100644 (file)
 #include <gst/tag/tag.h>
 #include <gst/net/gstnet.h>
 
+#include "gstadaptivedemuxelements.h"
 #include "gstdashdemux.h"
 #include "gstdash_debug.h"
 
@@ -467,13 +468,11 @@ gst_dash_demux_stream_class_init (GstDashDemux2StreamClass * klass)
 
 
 #define gst_dash_demux2_parent_class parent_class
-G_DEFINE_TYPE_WITH_CODE (GstDashDemux2, gst_dash_demux2,
-    GST_TYPE_ADAPTIVE_DEMUX, GST_DEBUG_CATEGORY_INIT (gst_dash_demux2_debug,
-        "dashdemux2", 0, "dashdemux2 element")
-    );
+G_DEFINE_TYPE (GstDashDemux2, gst_dash_demux2, GST_TYPE_ADAPTIVE_DEMUX);
 
-GST_ELEMENT_REGISTER_DEFINE (dashdemux2, "dashdemux2",
-    GST_RANK_PRIMARY + 1, GST_TYPE_DASH_DEMUX2);
+static gboolean dashdemux2_element_init (GstPlugin * plugin);
+
+GST_ELEMENT_REGISTER_DEFINE_CUSTOM (dashdemux2, dashdemux2_element_init);
 
 static void
 gst_dash_demux_dispose (GObject * obj)
@@ -3967,3 +3966,20 @@ gst_dash_demux_get_server_now_utc (GstDashDemux2 * demux)
   g_date_time_unref (client_now);
   return server_now;
 }
+
+static gboolean
+dashdemux2_element_init (GstPlugin * plugin)
+{
+  gboolean ret = TRUE;
+
+  GST_DEBUG_CATEGORY_INIT (gst_dash_demux2_debug,
+      "dashdemux2", 0, "dashdemux2 element");
+
+  if (!adaptivedemux2_base_element_init (plugin))
+    return TRUE;
+
+  ret = gst_element_register (plugin, "dashdemux2",
+      GST_RANK_PRIMARY + 1, GST_TYPE_DASH_DEMUX2);
+
+  return ret;
+}
index 44307da..24d1ebb 100644 (file)
@@ -165,8 +165,6 @@ struct _GstDashDemux2Class
 GType gst_dash_demux2_get_type (void);
 GType gst_dash_demux_stream_get_type (void);
 
-GST_ELEMENT_REGISTER_DECLARE (dashdemux2);
-
 G_END_DECLS
 #endif /* __GST_DASH_DEMUX_H__ */
 
index 6588112..1d39a3f 100644 (file)
@@ -109,7 +109,7 @@ By using the api_lock a thread is protected against other API calls.
 #include <gst/base/gstadapter.h>
 #include <gst/app/gstappsrc.h>
 
-GST_DEBUG_CATEGORY (adaptivedemux2_debug);
+GST_DEBUG_CATEGORY_EXTERN (adaptivedemux2_debug);
 #define GST_CAT_DEFAULT adaptivedemux2_debug
 
 #define DEFAULT_FAILED_COUNT 3
diff --git a/subprojects/gst-plugins-good/ext/adaptivedemux2/gstadaptivedemuxelement.c b/subprojects/gst-plugins-good/ext/adaptivedemux2/gstadaptivedemuxelement.c
new file mode 100644 (file)
index 0000000..1d8f537
--- /dev/null
@@ -0,0 +1,46 @@
+/* GStreamer
+ * Copyright (C) 2021-2022 Jan Schmidt <jan@centricular.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 "gstadaptivedemuxelements.h"
+#include "../soup/gstsouploader.h"
+
+GST_DEBUG_CATEGORY (adaptivedemux2_debug);
+#define GST_CAT_DEFAULT adaptivedemux2_debug
+
+gboolean
+adaptivedemux2_base_element_init (GstPlugin * plugin)
+{
+  static gsize res = FALSE;
+  if (g_once_init_enter (&res)) {
+    GST_DEBUG_CATEGORY_INIT (adaptivedemux2_debug, "adaptivedemux2", 0,
+        "adaptivedemux2");
+    g_once_init_leave (&res, TRUE);
+  }
+#ifndef STATIC_SOUP
+  if (!gst_soup_load_library ()) {
+    GST_WARNING ("Failed to load libsoup library");
+    return FALSE;
+  }
+#endif
+  return TRUE;
+}
diff --git a/subprojects/gst-plugins-good/ext/adaptivedemux2/gstadaptivedemuxelements.h b/subprojects/gst-plugins-good/ext/adaptivedemux2/gstadaptivedemuxelements.h
new file mode 100644 (file)
index 0000000..50487eb
--- /dev/null
@@ -0,0 +1,35 @@
+/* GStreamer
+ * Copyright (C) 2021-2022 Jan Schmidt <jan@centricular.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_ADAPTIVEDEMUX2_ELEMENTS_H__
+#define __GST_ADAPTIVEDEMUX2_ELEMENTS_H__
+
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+
+#include <gst/gst.h>
+
+gboolean adaptivedemux2_base_element_init (GstPlugin * plugin);
+
+GST_ELEMENT_REGISTER_DECLARE (mssdemux2);
+GST_ELEMENT_REGISTER_DECLARE (hlsdemux2);
+GST_ELEMENT_REGISTER_DECLARE (dashdemux2);
+
+#endif
index 67051d1..d9838fa 100644 (file)
@@ -51,6 +51,7 @@
 #include <gst/tag/tag.h>
 
 #include "gsthlselements.h"
+#include "gstadaptivedemuxelements.h"
 #include "gsthlsdemux.h"
 
 static GstStaticPadTemplate sinktemplate = GST_STATIC_PAD_TEMPLATE ("sink",
@@ -147,8 +148,9 @@ static void gst_hls_demux_stream_finalize (GObject * object);
 G_DEFINE_TYPE (GstHLSDemuxStream, gst_hls_demux_stream,
     GST_TYPE_ADAPTIVE_DEMUX2_STREAM);
 
-GST_ELEMENT_REGISTER_DEFINE (hlsdemux2, "hlsdemux2",
-    GST_RANK_PRIMARY + 1, GST_TYPE_HLS_DEMUX2);
+static gboolean hlsdemux2_element_init (GstPlugin * plugin);
+
+GST_ELEMENT_REGISTER_DEFINE_CUSTOM (hlsdemux2, hlsdemux2_element_init);
 
 static void
 gst_hls_demux_stream_class_init (GstHLSDemuxStreamClass * klass)
@@ -279,9 +281,6 @@ gst_hls_demux2_class_init (GstHLSDemux2Class * klass)
   adaptivedemux_class->start_fragment = gst_hls_demux_start_fragment;
   adaptivedemux_class->finish_fragment = gst_hls_demux_finish_fragment;
   adaptivedemux_class->data_received = gst_hls_demux_data_received;
-
-  GST_DEBUG_CATEGORY_INIT (gst_hls_demux2_debug, "hlsdemux2", 0,
-      "hlsdemux2 element");
 }
 
 static void
@@ -2674,3 +2673,20 @@ gst_hls_demux_get_live_seek_range (GstAdaptiveDemux * demux, gint64 * start,
 
   return ret;
 }
+
+static gboolean
+hlsdemux2_element_init (GstPlugin * plugin)
+{
+  gboolean ret = TRUE;
+
+  GST_DEBUG_CATEGORY_INIT (gst_hls_demux2_debug, "hlsdemux2", 0,
+      "hlsdemux2 element");
+
+  if (!adaptivedemux2_base_element_init (plugin))
+    return TRUE;
+
+  ret = gst_element_register (plugin, "hlsdemux2",
+      GST_RANK_PRIMARY + 1, GST_TYPE_HLS_DEMUX2);
+
+  return ret;
+}
index 3a0109d..041e93b 100644 (file)
@@ -246,7 +246,5 @@ GstHLSTimeMap *gst_hls_find_time_map (GstHLSDemux * demux, gint64 dsn);
 GType gst_hls_demux2_get_type (void);
 GType gst_hls_demux_stream_get_type (void);
 
-GST_ELEMENT_REGISTER_DECLARE (hlsdemux2);
-
 G_END_DECLS
 #endif /* __GST_HLS_DEMUX_H__ */
index 61fc394..4d8f50a 100644 (file)
@@ -41,6 +41,7 @@ plugin_sources = [
   'plugin.c',
   'gstisoff.c',
   'gstadaptivedemux.c',
+  'gstadaptivedemuxelement.c',
   'gstadaptivedemuxutils.c',
   'gstadaptivedemux-period.c',
   'gstadaptivedemux-stream.c',
index 14d2a8b..2829429 100644 (file)
 #include <stdlib.h>
 #include <string.h>
 
+#include "gstadaptivedemuxelements.h"
 #include "gstmssdemux.h"
 
 GST_DEBUG_CATEGORY (mssdemux2_debug);
+#define GST_CAT_DEFAULT mssdemux2_debug
 
 static GstStaticPadTemplate gst_mss_demux_sink_template =
 GST_STATIC_PAD_TEMPLATE ("sink",
@@ -106,8 +108,9 @@ G_DEFINE_TYPE (GstMssDemux2, gst_mss_demux2, GST_TYPE_ADAPTIVE_DEMUX);
 G_DEFINE_TYPE (GstMssDemuxStream, gst_mss_demux_stream,
     GST_TYPE_ADAPTIVE_DEMUX2_STREAM);
 
-GST_ELEMENT_REGISTER_DEFINE (mssdemux2, "mssdemux2",
-    GST_RANK_PRIMARY + 1, GST_TYPE_MSS_DEMUX2);
+static gboolean mssdemux_element_init (GstPlugin * plugin);
+
+GST_ELEMENT_REGISTER_DEFINE_CUSTOM (mssdemux2, mssdemux_element_init);
 
 static void gst_mss_demux_dispose (GObject * object);
 
@@ -204,8 +207,6 @@ gst_mss_demux2_class_init (GstMssDemuxClass * klass)
   gstadaptivedemux_class->requires_periodical_playlist_update =
       gst_mss_demux_requires_periodical_playlist_update;
 
-  GST_DEBUG_CATEGORY_INIT (mssdemux2_debug, "mssdemux2", 0,
-      "mssdemux2 element");
 }
 
 static void
@@ -688,3 +689,21 @@ gst_stream_type_from_mss_type (GstMssStreamType mtype)
       return GST_STREAM_TYPE_UNKNOWN;
   }
 }
+
+static gboolean
+mssdemux_element_init (GstPlugin * plugin)
+{
+  gboolean ret = TRUE;
+
+  GST_DEBUG_CATEGORY_INIT (mssdemux2_debug, "mssdemux2", 0,
+      "mssdemux2 element");
+
+  if (!adaptivedemux2_base_element_init (plugin))
+    return TRUE;
+
+  ret =
+      gst_element_register (plugin, "mssdemux2", GST_RANK_PRIMARY + 1,
+      GST_TYPE_MSS_DEMUX2);
+
+  return ret;
+}
index 2d12119..c1331bc 100644 (file)
@@ -32,9 +32,6 @@
 
 G_BEGIN_DECLS
 
-GST_DEBUG_CATEGORY_EXTERN (mssdemux2_debug);
-#define GST_CAT_DEFAULT mssdemux2_debug
-
 #define GST_TYPE_MSS_DEMUX2 \
   (gst_mss_demux2_get_type())
 #define GST_MSS_DEMUX(obj) \
@@ -80,7 +77,7 @@ struct _GstMssDemux2Class {
 GType gst_mss_demux2_get_type (void);
 GType gst_mss_demux_stream_get_type (void);
 
-GST_ELEMENT_REGISTER_DECLARE (mssdemux2);
+
 G_END_DECLS
 
 #endif /* __GST_MSSDEMUX_H__ */
index ade4053..b13816b 100644 (file)
 #  include <config.h>
 #endif
 
-#include "dash/gstdashdemux.h"
-#include "hls/gsthlsdemux.h"
-#include "mss/gstmssdemux.h"
-#include "../soup/gstsouploader.h"
+#include "gstadaptivedemuxelements.h"
 
 static gboolean
 plugin_init (GstPlugin * plugin)
 {
   gboolean ret = TRUE;
 
-#ifndef STATIC_SOUP
-  if (!gst_soup_load_library ()) {
-    GST_WARNING ("Failed to load libsoup library");
-    return TRUE;
-  }
-#endif
-
   ret |= GST_ELEMENT_REGISTER (hlsdemux2, plugin);
   ret |= GST_ELEMENT_REGISTER (dashdemux2, plugin);
   ret |= GST_ELEMENT_REGISTER (mssdemux2, plugin);