X-Git-Url: https://git.stderr.nl/gitweb?a=blobdiff_plain;f=libchimara%2Fschannel.c;h=b64470db222addbcf9a30c9595f9309676e1ce14;hb=1e0dc5378f314f555e3b923c6d95f5017abd528b;hp=617adc19eb90b46736ecf817468beadf7db6c80b;hpb=eec3f2cefd211052c2cc19a0a3add4fbef171459;p=projects%2Fchimara%2Fchimara.git diff --git a/libchimara/schannel.c b/libchimara/schannel.c index 617adc1..b64470d 100644 --- a/libchimara/schannel.c +++ b/libchimara/schannel.c @@ -15,7 +15,7 @@ #define VOLUME_TIMER_RESOLUTION 1.0 /* In milliseconds */ -extern GPrivate *glk_data_key; +extern GPrivate glk_data_key; #ifdef GSTREAMER_SOUND /* Stop any currently playing sound on this channel, and remove any @@ -25,6 +25,11 @@ clean_up_after_playing_sound(schanid_t chan) { if(!gst_element_set_state(chan->pipeline, GST_STATE_NULL)) WARNING_S(_("Could not set GstElement state to"), "NULL"); + if(chan->source) + { + gst_bin_remove(GST_BIN(chan->pipeline), chan->source); + chan->source = NULL; + } if(chan->demux) { gst_bin_remove(GST_BIN(chan->pipeline), chan->demux); @@ -216,7 +221,7 @@ schanid_t glk_schannel_create_ext(glui32 rock, glui32 volume) { #ifdef GSTREAMER_SOUND - ChimaraGlkPrivate *glk_data = g_private_get(glk_data_key); + ChimaraGlkPrivate *glk_data = g_private_get(&glk_data_key); schanid_t s = g_new0(struct glk_schannel_struct, 1); s->magic = MAGIC_SCHANNEL; @@ -243,12 +248,11 @@ glk_schannel_create_ext(glui32 rock, glui32 volume) gst_object_unref(bus); /* Create GStreamer elements to put in the pipeline */ - s->source = gst_element_factory_make("giostreamsrc", NULL); s->typefind = gst_element_factory_make("typefind", NULL); s->convert = gst_element_factory_make("audioconvert", NULL); s->filter = gst_element_factory_make("volume", NULL); s->sink = gst_element_factory_make("autoaudiosink", NULL); - if(!s->source || !s->typefind || !s->convert || !s->filter || !s->sink) { + if(!s->typefind || !s->convert || !s->filter || !s->sink) { WARNING(_("Could not create one or more GStreamer elements")); goto fail; } @@ -258,9 +262,10 @@ glk_schannel_create_ext(glui32 rock, glui32 volume) /* Put the elements in the pipeline and link as many together as we can without knowing the type of the audio stream */ - gst_bin_add_many(GST_BIN(s->pipeline), s->source, s->typefind, s->convert, s->filter, s->sink, NULL); - /* Link elements: Source -> typefinder -> ??? -> Converter -> Volume filter -> Sink */ - if(!gst_element_link(s->source, s->typefind) || !gst_element_link_many(s->convert, s->filter, s->sink, NULL)) { + gst_bin_add_many(GST_BIN(s->pipeline), s->typefind, s->convert, s->filter, s->sink, NULL); + + /* Link elements: ??? -> Converter -> Volume filter -> Sink */ + if(!gst_element_link_many(s->convert, s->filter, s->sink, NULL)) { WARNING(_("Could not link GStreamer elements")); goto fail; } @@ -289,7 +294,7 @@ glk_schannel_destroy(schanid_t chan) VALID_SCHANNEL(chan, return); #ifdef GSTREAMER_SOUND - ChimaraGlkPrivate *glk_data = g_private_get(glk_data_key); + ChimaraGlkPrivate *glk_data = g_private_get(&glk_data_key); if(!gst_element_set_state(chan->pipeline, GST_STATE_NULL)) WARNING_S(_("Could not set GstElement state to"), "NULL"); @@ -331,7 +336,7 @@ glk_schannel_iterate(schanid_t chan, glui32 *rockptr) VALID_SCHANNEL_OR_NULL(chan, return NULL); #ifdef GSTREAMER_SOUND - ChimaraGlkPrivate *glk_data = g_private_get(glk_data_key); + ChimaraGlkPrivate *glk_data = g_private_get(&glk_data_key); GList *retnode; if(chan == NULL) @@ -438,7 +443,7 @@ glk_schannel_play_ext(schanid_t chan, glui32 snd, glui32 repeats, glui32 notify) { VALID_SCHANNEL(chan, return 0); #ifdef GSTREAMER_SOUND - ChimaraGlkPrivate *glk_data = g_private_get(glk_data_key); + ChimaraGlkPrivate *glk_data = g_private_get(&glk_data_key); GInputStream *stream; /* Stop the previous sound */ @@ -483,15 +488,24 @@ glk_schannel_play_ext(schanid_t chan, glui32 snd, glui32 repeats, glui32 notify) stream = g_memory_input_stream_new_from_data(resource.data.ptr, resource.length, NULL); } + chan->source = gst_element_factory_make("giostreamsrc", NULL); + g_object_set(chan->source, "stream", stream, NULL); + g_object_unref(stream); /* Now owned by GStreamer element */ + gst_bin_add(GST_BIN(chan->pipeline), chan->source); + if(!gst_element_link(chan->source, chan->typefind)) { + WARNING(_("Could not link GStreamer elements")); + clean_up_after_playing_sound(chan); + return 0; + } + chan->repeats = repeats; chan->resource = snd; chan->notify = notify; - g_object_set(chan->source, "stream", stream, NULL); - g_object_unref(stream); /* Now owned by GStreamer element */ /* Play the sound; unless the channel is paused, then pause it instead */ if(!gst_element_set_state(chan->pipeline, chan->paused? GST_STATE_PAUSED : GST_STATE_PLAYING)) { WARNING_S(_("Could not set GstElement state to"), chan->paused? "PAUSED" : "PLAYING"); + clean_up_after_playing_sound(chan); return 0; } return 1; @@ -543,7 +557,7 @@ glk_schannel_play_multi(schanid_t *chanarray, glui32 chancount, glui32 *sndarray VALID_SCHANNEL(chanarray[count], return 0); #ifdef GSTREAMER_SOUND - ChimaraGlkPrivate *glk_data = g_private_get(glk_data_key); + ChimaraGlkPrivate *glk_data = g_private_get(&glk_data_key); GInputStream *stream; if(!glk_data->resource_map && !glk_data->resource_load_callback) { @@ -591,11 +605,18 @@ glk_schannel_play_multi(schanid_t *chanarray, glui32 chancount, glui32 *sndarray stream = g_memory_input_stream_new_from_data(resource.data.ptr, resource.length, NULL); } + chanarray[count]->source = gst_element_factory_make("giostreamsrc", NULL); + g_object_set(chanarray[count]->source, "stream", stream, NULL); + g_object_unref(stream); /* Now owned by GStreamer element */ + gst_bin_add(GST_BIN(chanarray[count]->pipeline), chanarray[count]->source); + if(!gst_element_link(chanarray[count]->source, chanarray[count]->typefind)) { + WARNING(_("Could not link GStreamer elements")); + clean_up_after_playing_sound(chanarray[count]); + } + chanarray[count]->repeats = 1; chanarray[count]->resource = sndarray[count]; chanarray[count]->notify = notify; - g_object_set(chanarray[count]->source, "stream", stream, NULL); - g_object_unref(stream); /* Now owned by GStreamer element */ } /* Start all the sounds as close to each other as possible. */ @@ -608,6 +629,7 @@ glk_schannel_play_multi(schanid_t *chanarray, glui32 chancount, glui32 *sndarray if(!gst_element_set_state(chanarray[count]->pipeline, chanarray[count]->paused? GST_STATE_PAUSED : GST_STATE_PLAYING)) { WARNING_S(_("Could not set GstElement state to"), chanarray[count]->paused? "PAUSED" : "PLAYING"); skiparray[count] = TRUE; + clean_up_after_playing_sound(chanarray[count]); continue; } successes++; @@ -872,7 +894,7 @@ void glk_sound_load_hint(glui32 snd, glui32 flag) { #ifdef GSTREAMER_SOUND - ChimaraGlkPrivate *glk_data = g_private_get(glk_data_key); + ChimaraGlkPrivate *glk_data = g_private_get(&glk_data_key); giblorb_result_t resource; giblorb_err_t result;