+ switch(GST_MESSAGE_TYPE(message)) {
+ case GST_MESSAGE_ERROR:
+ {
+ gst_message_parse_error(message, &err, &debug_message);
+ IO_WARNING(_("GStreamer error"), err->message, debug_message);
+ g_error_free(err);
+ g_free(debug_message);
+ clean_up_after_playing_sound(s);
+ }
+ break;
+ case GST_MESSAGE_WARNING:
+ {
+ gst_message_parse_warning(message, &err, &debug_message);
+ IO_WARNING(_("GStreamer warning"), err->message, debug_message);
+ g_error_free(err);
+ g_free(debug_message);
+ }
+ break;
+ case GST_MESSAGE_INFO:
+ {
+ gst_message_parse_info(message, &err, &debug_message);
+ g_message("GStreamer info \"%s\": %s", err->message, debug_message);
+ g_error_free(err);
+ g_free(debug_message);
+ }
+ break;
+ case GST_MESSAGE_EOS: /* End of stream */
+ /* Decrease repeats if not set to forever */
+ if(s->repeats != (glui32)-1)
+ s->repeats--;
+ if(s->repeats > 0) {
+ if(!gst_element_seek_simple(s->pipeline, GST_FORMAT_TIME, GST_SEEK_FLAG_FLUSH | GST_SEEK_FLAG_KEY_UNIT, 0)) {
+ WARNING(_("Could not execute GStreamer seek"));
+ clean_up_after_playing_sound(s);
+ }
+ } else {
+ clean_up_after_playing_sound(s);
+ /* Sound ended normally, send a notification if requested */
+ if(s->notify)
+ event_throw(s->glk, evtype_SoundNotify, NULL, s->resource, s->notify);
+ }
+ break;
+ default:
+ /* unhandled message */
+ break;
+ }
+}
+
+/* This signal is thrown when the OGG demuxer element has decided what kind of
+ outputs it will output. We connect the decoder element dynamically. */
+static void
+on_ogg_demuxer_pad_added(GstElement *demux, GstPad *pad, schanid_t s)
+{
+ GstPad *sinkpad;
+
+ /* We can now link this pad with the vorbis-decoder sink pad */
+ sinkpad = gst_element_get_static_pad(s->decode, "sink");
+ if(gst_pad_link(pad, sinkpad) != GST_PAD_LINK_OK)
+ WARNING(_("Could not link OGG demuxer with Vorbis decoder"));
+ gst_object_unref(sinkpad);
+}
+
+/* This signal is thrown when the typefinder element has found the type of its
+ input. Now that we know what kind of input stream we have, we can connect the
+ proper demuxer/decoder elements. */
+static void
+on_type_found(GstElement *typefind, guint probability, GstCaps *caps, schanid_t s)
+{
+ gchar *type = gst_caps_to_string(caps);
+ if(strcmp(type, "application/ogg") == 0) {
+ s->demux = gst_element_factory_make("oggdemux", NULL);
+ s->decode = gst_element_factory_make("vorbisdec", NULL);
+ if(!s->demux || !s->decode) {
+ WARNING(_("Could not create one or more GStreamer elements"));
+ goto finally;
+ }
+ gst_bin_add_many(GST_BIN(s->pipeline), s->demux, s->decode, NULL);
+ if(!gst_element_link(s->typefind, s->demux) || !gst_element_link(s->decode, s->convert)) {
+ WARNING(_("Could not link GStreamer elements"));
+ goto finally;
+ }
+ /* We link the demuxer and decoder together dynamically, since the
+ demuxer doesn't know what source pads it will have until it starts
+ demuxing the stream */
+ g_signal_connect(s->demux, "pad-added", G_CALLBACK(on_ogg_demuxer_pad_added), s);
+ } else if(strcmp(type, "audio/x-aiff") == 0) {
+ s->decode = gst_element_factory_make("aiffparse", NULL);
+ if(!s->decode) {
+ WARNING(_("Could not create 'aiffparse' GStreamer element"));
+ goto finally;
+ }
+ gst_bin_add(GST_BIN(s->pipeline), s->decode);
+ if(!gst_element_link_many(s->typefind, s->decode, s->convert, NULL)) {
+ WARNING(_("Could not link GStreamer elements"));
+ goto finally;
+ }
+ } else if(strcmp(type, "audio/x-mod") == 0) {
+ s->decode = gst_element_factory_make("modplug", NULL);
+ if(!s->decode) {
+ WARNING(_("Could not create 'modplug' GStreamer element"));
+ goto finally;
+ }
+ gst_bin_add(GST_BIN(s->pipeline), s->decode);
+ if(!gst_element_link_many(s->typefind, s->decode, s->convert, NULL)) {
+ WARNING(_("Could not link GStreamer elements"));
+ goto finally;
+ }
+ } else {
+ WARNING_S(_("Unexpected audio type in blorb"), type);
+ }
+
+finally:
+ g_free(type);
+}
+#endif /* GSTREAMER_SOUND */