From 9c8ef16a8af5ca68e61f217b023a7f935587255b Mon Sep 17 00:00:00 2001 From: Stefan Kost Date: Tue, 24 Jul 2007 15:13:44 +0000 Subject: [PATCH] ext/timidity/gstwildmidi.*: Don't initialize wildmidi in plugin_init as it also setups audio filters which is slow. Original commit message from CVS: * ext/timidity/gstwildmidi.c: (wildmidi_open_config), (gst_wildmidi_init), (gst_wildmidi_change_state), (plugin_init): * ext/timidity/gstwildmidi.h: Don't initialize wildmidi in plugin_init as it also setups audio filters which is slow. --- ChangeLog | 8 +++ ext/timidity/gstwildmidi.c | 119 ++++++++++++++++++++----------------- ext/timidity/gstwildmidi.h | 2 + 3 files changed, 73 insertions(+), 56 deletions(-) diff --git a/ChangeLog b/ChangeLog index aa0d1a4bbd..0fe53c6a32 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,11 @@ +2007-07-24 Stefan Kost + + * ext/timidity/gstwildmidi.c: (wildmidi_open_config), + (gst_wildmidi_init), (gst_wildmidi_change_state), (plugin_init): + * ext/timidity/gstwildmidi.h: + Don't initialize wildmidi in plugin_init as it also setups audio + filters which is slow. + 2007-07-24 Hans de Goede reviewed by: Edward Hervey diff --git a/ext/timidity/gstwildmidi.c b/ext/timidity/gstwildmidi.c index ae7cba959a..8da7a5f4d1 100644 --- a/ext/timidity/gstwildmidi.c +++ b/ext/timidity/gstwildmidi.c @@ -126,6 +126,57 @@ gst_wildmidi_base_init (gpointer gclass) gst_element_class_set_details (element_class, &gst_wildmidi_details); } +static gboolean +wildmidi_open_config () +{ + gchar *path = g_strdup (g_getenv ("WILDMIDI_CFG")); + gint ret; + + GST_DEBUG ("trying %s", GST_STR_NULL (path)); + if (path && (g_access (path, R_OK) == -1)) { + g_free (path); + path = NULL; + } + + if (path == NULL) { + path = + g_build_path (G_DIR_SEPARATOR_S, g_get_home_dir (), ".wildmidirc", + NULL); + GST_DEBUG ("trying %s", path); + if (path && (g_access (path, R_OK) == -1)) { + g_free (path); + path = NULL; + } + } + + if (path == NULL) { + path = g_build_path (G_DIR_SEPARATOR_S, "/etc", "wildmidi.cfg", NULL); + GST_DEBUG ("trying %s", path); + if (path && (g_access (path, R_OK) == -1)) { + g_free (path); + path = NULL; + } + } + + if (path == NULL) { + /* I've created a symlink to get it playing + * ln -s /usr/share/timidity/timidity.cfg /etc/wildmidi.cfg + * we could make it use : TIMIDITY_CFG + * but unfortunately it fails to create a proper filename if the config + * has a redirect + * http://sourceforge.net/tracker/index.php?func=detail&aid=1657358&group_id=42635&atid=433744 + */ + GST_WARNING ("no config file, can't initialise"); + return FALSE; + } + + /* this also initializes a some filter and stuff and thus is slow */ + ret = WildMidi_Init (path, WILDMIDI_RATE, 0); + g_free (path); + + return (ret == 0); +} + /* initialize the plugin's class */ static void gst_wildmidi_class_init (GstWildmidiClass * klass) @@ -159,6 +210,13 @@ gst_wildmidi_init (GstWildmidi * filter, GstWildmidiClass * g_class) { GstElementClass *klass = GST_ELEMENT_GET_CLASS (filter); + /* initialise wildmidi library */ + if (wildmidi_open_config ()) { + filter->initialized = TRUE; + } else { + GST_WARNING ("can't initialize wildmidi"); + } + filter->sinkpad = gst_pad_new_from_template (gst_element_class_get_pad_template (klass, "sink"), "sink"); @@ -722,6 +780,11 @@ gst_wildmidi_change_state (GstElement * element, GstStateChange transition) GstStateChangeReturn ret = GST_STATE_CHANGE_SUCCESS; GstWildmidi *wildmidi = GST_WILDMIDI (element); + if (!wildmidi->initialized) { + GST_WARNING ("WildMidi renderer is not initialized"); + return GST_STATE_CHANGE_FAILURE; + } + switch (transition) { case GST_STATE_CHANGE_NULL_TO_READY: wildmidi->out_caps = @@ -827,56 +890,6 @@ gst_wildmidi_typefind (GstTypeFind * tf, gpointer _data) } } -static gboolean -wildmidi_open_config () -{ - gchar *path = g_strdup (g_getenv ("WILDMIDI_CFG")); - gint ret; - - GST_DEBUG ("trying %s", GST_STR_NULL (path)); - if (path && (g_access (path, R_OK) == -1)) { - g_free (path); - path = NULL; - } - - if (path == NULL) { - path = - g_build_path (G_DIR_SEPARATOR_S, g_get_home_dir (), ".wildmidirc", - NULL); - GST_DEBUG ("trying %s", path); - if (path && (g_access (path, R_OK) == -1)) { - g_free (path); - path = NULL; - } - } - - if (path == NULL) { - path = g_build_path (G_DIR_SEPARATOR_S, "/etc", "wildmidi.cfg", NULL); - GST_DEBUG ("trying %s", path); - if (path && (g_access (path, R_OK) == -1)) { - g_free (path); - path = NULL; - } - } - - if (path == NULL) { - /* I've created a symlink to get it playing - * ln -s /usr/share/timidity/timidity.cfg /etc/wildmidi.cfg - * we could make it use : TIMIDITY_CFG - * but unfortunately it fails to create a proper filename if the config - * has a redirect - * http://sourceforge.net/tracker/index.php?func=detail&aid=1657358&group_id=42635&atid=433744 - */ - GST_WARNING ("no config file, can't initialise"); - return FALSE; - } - - ret = WildMidi_Init (path, WILDMIDI_RATE, 0); - g_free (path); - - return (ret == 0); -} - static gboolean plugin_init (GstPlugin * plugin) { @@ -886,12 +899,6 @@ plugin_init (GstPlugin * plugin) GST_DEBUG_CATEGORY_INIT (gst_wildmidi_debug, "wildmidi", 0, "Wildmidi plugin"); - /* initialise wildmidi library, fail loading the plugin if this fails */ - if (!wildmidi_open_config ()) { - GST_WARNING ("can't initialize wildmidi"); - return FALSE; - } - if (!gst_type_find_register (plugin, "audio/midi", GST_RANK_SECONDARY, gst_wildmidi_typefind, exts, gst_caps_new_simple ("audio/midi", NULL), NULL, NULL)) { diff --git a/ext/timidity/gstwildmidi.h b/ext/timidity/gstwildmidi.h index 37815ea60a..54189572df 100644 --- a/ext/timidity/gstwildmidi.h +++ b/ext/timidity/gstwildmidi.h @@ -51,6 +51,8 @@ struct _GstWildmidi GstPad *sinkpad, *srcpad; + gboolean initialized; + /* input stream properties */ gint64 mididata_size, mididata_offset; gchar *mididata;