fluiddec: Move logging init into plugin_init
authorJan Alexander Steffens (heftig) <jan.steffens@gmail.com>
Tue, 11 Feb 2020 11:15:09 +0000 (12:15 +0100)
committerGStreamer Merge Bot <gitlab-merge-bot@gstreamer-foundation.org>
Tue, 11 Feb 2020 12:10:50 +0000 (12:10 +0000)
This is a nicer place to keep it. We also initialize it before touching
the drivers.

https://gitlab.freedesktop.org/gstreamer/gst-plugins-bad/merge_requests/1026

ext/fluidsynth/gstfluiddec.c

index 0550f62..41b438f 100644 (file)
@@ -117,33 +117,6 @@ static GstStaticPadTemplate src_factory = GST_STATIC_PAD_TEMPLATE ("src",
 #define parent_class gst_fluid_dec_parent_class
 G_DEFINE_TYPE (GstFluidDec, gst_fluid_dec, GST_TYPE_ELEMENT);
 
-/* fluid_synth log handler */
-static void
-gst_fluid_synth_error_log_function (int level, const char *message, void *data)
-{
-  GST_ERROR ("%s", message);
-}
-
-static void
-gst_fluid_synth_warning_log_function (int level, const char *message,
-    void *data)
-{
-  GST_WARNING ("%s", message);
-}
-
-static void
-gst_fluid_synth_info_log_function (int level, const char *message, void *data)
-{
-  GST_INFO ("%s", message);
-}
-
-static void
-gst_fluid_synth_debug_log_function (int level, const char *message, void *data)
-{
-  GST_DEBUG ("%s", message);
-}
-
-
 /* initialize the plugin's class */
 static void
 gst_fluid_dec_class_init (GstFluidDecClass * klass)
@@ -191,25 +164,6 @@ gst_fluid_dec_class_init (GstFluidDecClass * klass)
       "Midi Synthesizer Element", "Wim Taymans <wim.taymans@gmail.com>");
 
   gstelement_class->change_state = gst_fluid_dec_change_state;
-
-#ifndef GST_DISABLE_GST_DEBUG
-  fluid_set_log_function (FLUID_PANIC,
-      (fluid_log_function_t) gst_fluid_synth_error_log_function, NULL);
-  fluid_set_log_function (FLUID_ERR,
-      (fluid_log_function_t) gst_fluid_synth_warning_log_function, NULL);
-  fluid_set_log_function (FLUID_WARN,
-      (fluid_log_function_t) gst_fluid_synth_warning_log_function, NULL);
-  fluid_set_log_function (FLUID_INFO,
-      (fluid_log_function_t) gst_fluid_synth_info_log_function, NULL);
-  fluid_set_log_function (FLUID_DBG,
-      (fluid_log_function_t) gst_fluid_synth_debug_log_function, NULL);
-#else
-  fluid_set_log_function (FLUID_PANIC, NULL, NULL);
-  fluid_set_log_function (FLUID_ERR, NULL, NULL);
-  fluid_set_log_function (FLUID_WARN, NULL, NULL);
-  fluid_set_log_function (FLUID_INFO, NULL, NULL);
-  fluid_set_log_function (FLUID_DBG, NULL, NULL);
-#endif
 }
 
 /* initialize the new element
@@ -726,12 +680,60 @@ gst_fluid_dec_get_property (GObject * object, guint prop_id,
   }
 }
 
+/* fluid_synth log handler */
+static void
+gst_fluid_synth_error_log_function (int level, const char *message, void *data)
+{
+  GST_ERROR ("%s", message);
+}
+
+static void
+gst_fluid_synth_warning_log_function (int level, const char *message,
+    void *data)
+{
+  GST_WARNING ("%s", message);
+}
+
+static void
+gst_fluid_synth_info_log_function (int level, const char *message, void *data)
+{
+  GST_INFO ("%s", message);
+}
+
+static void
+gst_fluid_synth_debug_log_function (int level, const char *message, void *data)
+{
+  GST_DEBUG ("%s", message);
+}
+
 static gboolean
 plugin_init (GstPlugin * plugin)
 {
   GST_DEBUG_CATEGORY_INIT (gst_fluid_dec_debug, "fluiddec",
       0, "Fluidsynth MIDI decoder plugin");
 
+  /* We modify FluidSynth's global state here; let's hope nobody tries to use
+   * it natively alongside this plugin. */
+
+#ifndef GST_DISABLE_GST_DEBUG
+  fluid_set_log_function (FLUID_PANIC,
+      (fluid_log_function_t) gst_fluid_synth_error_log_function, NULL);
+  fluid_set_log_function (FLUID_ERR,
+      (fluid_log_function_t) gst_fluid_synth_warning_log_function, NULL);
+  fluid_set_log_function (FLUID_WARN,
+      (fluid_log_function_t) gst_fluid_synth_warning_log_function, NULL);
+  fluid_set_log_function (FLUID_INFO,
+      (fluid_log_function_t) gst_fluid_synth_info_log_function, NULL);
+  fluid_set_log_function (FLUID_DBG,
+      (fluid_log_function_t) gst_fluid_synth_debug_log_function, NULL);
+#else
+  fluid_set_log_function (FLUID_PANIC, NULL, NULL);
+  fluid_set_log_function (FLUID_ERR, NULL, NULL);
+  fluid_set_log_function (FLUID_WARN, NULL, NULL);
+  fluid_set_log_function (FLUID_INFO, NULL, NULL);
+  fluid_set_log_function (FLUID_DBG, NULL, NULL);
+#endif
+
 #if GST_HAVE_FLUIDSYNTH_VERSION(1, 1, 9)
   {
     /* Disable all audio drivers so new_fluid_settings() does not probe them.