diff options
author | Stefan Kost <ensonic@users.sourceforge.net> | 2007-07-24 15:13:44 +0000 |
---|---|---|
committer | Stefan Kost <ensonic@users.sourceforge.net> | 2007-07-24 15:13:44 +0000 |
commit | 9c8ef16a8af5ca68e61f217b023a7f935587255b (patch) | |
tree | cd918ba01b597f483119e07777b36f4214691b8d /ext/timidity | |
parent | 2a8bc6a2e13844c797603c2de12635e1661b55bb (diff) | |
download | gst-plugins-bad-9c8ef16a8af5ca68e61f217b023a7f935587255b.tar.gz gst-plugins-bad-9c8ef16a8af5ca68e61f217b023a7f935587255b.tar.bz2 gst-plugins-bad-9c8ef16a8af5ca68e61f217b023a7f935587255b.zip |
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.
Diffstat (limited to 'ext/timidity')
-rw-r--r-- | ext/timidity/gstwildmidi.c | 119 | ||||
-rw-r--r-- | ext/timidity/gstwildmidi.h | 2 |
2 files changed, 65 insertions, 56 deletions
diff --git a/ext/timidity/gstwildmidi.c b/ext/timidity/gstwildmidi.c index ae7cba95..8da7a5f4 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 = @@ -828,56 +891,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) { static gchar *exts[] = { "mid", "midi", NULL }; @@ -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 37815ea6..54189572 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; |