ext/timidity/gstwildmidi.*: Initialize wildmidi only once in the plugin init function instead of once for every insta...

Original commit message from CVS:
Based on a patch by:  Sonicadvance1 at GMAIL dot COM
* ext/timidity/gstwildmidi.c: (gst_wildmidi_init),
(gst_wildmidi_change_state), (plugin_init):
* ext/timidity/gstwildmidi.h:
Initialize wildmidi only once in the plugin init function instead
of once for every instance. The second and following calls to the
wildmidi initialization function will fail. Fixes bug #525613.
Also don't register the element at all if wildmidi initialization
fails.
This commit is contained in:
Sebastian Dröge 2008-06-11 07:58:44 +00:00
parent 744f3efec5
commit a14d311c96
3 changed files with 46 additions and 14 deletions

View file

@ -1,3 +1,17 @@
2008-06-11 Sebastian Dröge <slomo@circular-chaos.org>
Based on a patch by: Sonicadvance1 at GMAIL dot COM
* ext/timidity/gstwildmidi.c: (gst_wildmidi_init),
(gst_wildmidi_change_state), (plugin_init):
* ext/timidity/gstwildmidi.h:
Initialize wildmidi only once in the plugin init function instead
of once for every instance. The second and following calls to the
wildmidi initialization function will fail. Fixes bug #525613.
Also don't register the element at all if wildmidi initialization
fails.
2008-06-10 Sebastian Dröge <slomo@circular-chaos.org> 2008-06-10 Sebastian Dröge <slomo@circular-chaos.org>
* ext/soundtouch/gstpitch.cc: * ext/soundtouch/gstpitch.cc:

View file

@ -86,14 +86,19 @@ enum
}; };
static void gst_wildmidi_base_init (gpointer g_class); static void gst_wildmidi_base_init (gpointer g_class);
static void gst_wildmidi_class_init (GstWildmidiClass * klass); static void gst_wildmidi_class_init (GstWildmidiClass * klass);
static gboolean gst_wildmidi_src_event (GstPad * pad, GstEvent * event); static gboolean gst_wildmidi_src_event (GstPad * pad, GstEvent * event);
static GstStateChangeReturn gst_wildmidi_change_state (GstElement * element, static GstStateChangeReturn gst_wildmidi_change_state (GstElement * element,
GstStateChange transition); GstStateChange transition);
static gboolean gst_wildmidi_activate (GstPad * pad); static gboolean gst_wildmidi_activate (GstPad * pad);
static gboolean gst_wildmidi_activatepull (GstPad * pad, gboolean active); static gboolean gst_wildmidi_activatepull (GstPad * pad, gboolean active);
static void gst_wildmidi_loop (GstPad * sinkpad); static void gst_wildmidi_loop (GstPad * sinkpad);
static gboolean gst_wildmidi_src_query (GstPad * pad, GstQuery * query); static gboolean gst_wildmidi_src_query (GstPad * pad, GstQuery * query);
static void gst_wildmidi_set_property (GObject * object, guint prop_id, static void gst_wildmidi_set_property (GObject * object, guint prop_id,
@ -134,6 +139,7 @@ static gboolean
wildmidi_open_config () wildmidi_open_config ()
{ {
gchar *path = g_strdup (g_getenv ("WILDMIDI_CFG")); gchar *path = g_strdup (g_getenv ("WILDMIDI_CFG"));
gint ret; gint ret;
GST_DEBUG ("trying %s", GST_STR_NULL (path)); GST_DEBUG ("trying %s", GST_STR_NULL (path));
@ -226,6 +232,7 @@ static void
gst_wildmidi_class_init (GstWildmidiClass * klass) gst_wildmidi_class_init (GstWildmidiClass * klass)
{ {
GObjectClass *gobject_class; GObjectClass *gobject_class;
GstElementClass *gstelement_class; GstElementClass *gstelement_class;
gobject_class = (GObjectClass *) klass; gobject_class = (GObjectClass *) klass;
@ -254,13 +261,6 @@ gst_wildmidi_init (GstWildmidi * filter, GstWildmidiClass * g_class)
{ {
GstElementClass *klass = GST_ELEMENT_GET_CLASS (filter); 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 = filter->sinkpad =
gst_pad_new_from_template (gst_element_class_get_pad_template (klass, gst_pad_new_from_template (gst_element_class_get_pad_template (klass,
"sink"), "sink"); "sink"), "sink");
@ -295,6 +295,7 @@ gst_wildmidi_src_convert (GstWildmidi * wildmidi,
GstFormat * dest_format, gint64 * dest_value) GstFormat * dest_format, gint64 * dest_value)
{ {
gboolean res = TRUE; gboolean res = TRUE;
gint64 frames; gint64 frames;
if (src_format == *dest_format) { if (src_format == *dest_format) {
@ -340,8 +341,11 @@ static gboolean
gst_wildmidi_src_query (GstPad * pad, GstQuery * query) gst_wildmidi_src_query (GstPad * pad, GstQuery * query)
{ {
gboolean res = TRUE; gboolean res = TRUE;
GstWildmidi *wildmidi = GST_WILDMIDI (gst_pad_get_parent (pad)); GstWildmidi *wildmidi = GST_WILDMIDI (gst_pad_get_parent (pad));
GstFormat src_format, dst_format; GstFormat src_format, dst_format;
gint64 src_value, dst_value; gint64 src_value, dst_value;
if (!wildmidi->song) { if (!wildmidi->song) {
@ -396,7 +400,9 @@ static gboolean
gst_wildmidi_get_upstream_size (GstWildmidi * wildmidi, gint64 * size) gst_wildmidi_get_upstream_size (GstWildmidi * wildmidi, gint64 * size)
{ {
GstFormat format = GST_FORMAT_BYTES; GstFormat format = GST_FORMAT_BYTES;
gboolean res = FALSE; gboolean res = FALSE;
GstPad *peer = gst_pad_get_peer (wildmidi->sinkpad); GstPad *peer = gst_pad_get_peer (wildmidi->sinkpad);
if (peer != NULL) if (peer != NULL)
@ -441,6 +447,7 @@ gst_wildmidi_get_new_segment_event (GstWildmidi * wildmidi, GstFormat format,
gboolean update) gboolean update)
{ {
GstSegment *segment; GstSegment *segment;
GstEvent *event; GstEvent *event;
segment = gst_wildmidi_get_segment (wildmidi, format, update); segment = gst_wildmidi_get_segment (wildmidi, format, update);
@ -458,6 +465,7 @@ static gboolean
gst_wildmidi_src_event (GstPad * pad, GstEvent * event) gst_wildmidi_src_event (GstPad * pad, GstEvent * event)
{ {
gboolean res = FALSE; gboolean res = FALSE;
GstWildmidi *wildmidi = GST_WILDMIDI (gst_pad_get_parent (pad)); GstWildmidi *wildmidi = GST_WILDMIDI (gst_pad_get_parent (pad));
GST_DEBUG_OBJECT (pad, "%s event received", GST_EVENT_TYPE_NAME (event)); GST_DEBUG_OBJECT (pad, "%s event received", GST_EVENT_TYPE_NAME (event));
@ -466,10 +474,15 @@ gst_wildmidi_src_event (GstPad * pad, GstEvent * event)
case GST_EVENT_SEEK: case GST_EVENT_SEEK:
{ {
gdouble rate; gdouble rate;
GstFormat src_format, dst_format; GstFormat src_format, dst_format;
GstSeekFlags flags; GstSeekFlags flags;
GstSeekType start_type, stop_type; GstSeekType start_type, stop_type;
gint64 orig_start, start, stop; gint64 orig_start, start, stop;
gboolean flush, update; gboolean flush, update;
if (!wildmidi->song) if (!wildmidi->song)
@ -562,7 +575,9 @@ static GstBuffer *
gst_wildmidi_clip_buffer (GstWildmidi * wildmidi, GstBuffer * buffer) gst_wildmidi_clip_buffer (GstWildmidi * wildmidi, GstBuffer * buffer)
{ {
gint64 new_start, new_stop; gint64 new_start, new_stop;
gint64 offset, length; gint64 offset, length;
GstBuffer *out; GstBuffer *out;
return buffer; return buffer;
@ -599,6 +614,7 @@ static GstBuffer *
gst_wildmidi_fill_buffer (GstWildmidi * wildmidi, GstBuffer * buffer) gst_wildmidi_fill_buffer (GstWildmidi * wildmidi, GstBuffer * buffer)
{ {
size_t bytes_read; size_t bytes_read;
gint64 samples; gint64 samples;
bytes_read = bytes_read =
@ -659,7 +675,9 @@ static void
gst_wildmidi_loop (GstPad * sinkpad) gst_wildmidi_loop (GstPad * sinkpad)
{ {
GstWildmidi *wildmidi = GST_WILDMIDI (GST_PAD_PARENT (sinkpad)); GstWildmidi *wildmidi = GST_WILDMIDI (GST_PAD_PARENT (sinkpad));
GstBuffer *out; GstBuffer *out;
GstFlowReturn ret; GstFlowReturn ret;
if (wildmidi->mididata_size == 0) { if (wildmidi->mididata_size == 0) {
@ -679,6 +697,7 @@ gst_wildmidi_loop (GstPad * sinkpad)
if (wildmidi->mididata_offset < wildmidi->mididata_size) { if (wildmidi->mididata_offset < wildmidi->mididata_size) {
GstBuffer *buffer; GstBuffer *buffer;
gint64 size; gint64 size;
GST_DEBUG_OBJECT (wildmidi, "loading song"); GST_DEBUG_OBJECT (wildmidi, "loading song");
@ -822,12 +841,8 @@ static GstStateChangeReturn
gst_wildmidi_change_state (GstElement * element, GstStateChange transition) gst_wildmidi_change_state (GstElement * element, GstStateChange transition)
{ {
GstStateChangeReturn ret = GST_STATE_CHANGE_SUCCESS; GstStateChangeReturn ret = GST_STATE_CHANGE_SUCCESS;
GstWildmidi *wildmidi = GST_WILDMIDI (element);
if (!wildmidi->initialized) { GstWildmidi *wildmidi = GST_WILDMIDI (element);
GST_WARNING ("WildMidi renderer is not initialized");
return GST_STATE_CHANGE_FAILURE;
}
switch (transition) { switch (transition) {
case GST_STATE_CHANGE_NULL_TO_READY: case GST_STATE_CHANGE_NULL_TO_READY:
@ -925,6 +940,11 @@ plugin_init (GstPlugin * plugin)
GST_DEBUG_CATEGORY_INIT (gst_wildmidi_debug, "wildmidi", GST_DEBUG_CATEGORY_INIT (gst_wildmidi_debug, "wildmidi",
0, "Wildmidi plugin"); 0, "Wildmidi plugin");
if (!wildmidi_open_config ()) {
GST_WARNING ("Can't initialize wildmidi");
return FALSE;
}
return gst_element_register (plugin, "wildmidi", return gst_element_register (plugin, "wildmidi",
GST_RANK_SECONDARY, GST_TYPE_WILDMIDI); GST_RANK_SECONDARY, GST_TYPE_WILDMIDI);
} }

View file

@ -51,8 +51,6 @@ struct _GstWildmidi
GstPad *sinkpad, *srcpad; GstPad *sinkpad, *srcpad;
gboolean initialized;
/* input stream properties */ /* input stream properties */
gint64 mididata_size, mididata_offset; gint64 mididata_size, mididata_offset;
gchar *mididata; gchar *mididata;