diff --git a/core/audio.cpp b/core/audio.cpp index 6259d6a6..5fcdcb4c 100644 --- a/core/audio.cpp +++ b/core/audio.cpp @@ -15,7 +15,7 @@ static struct track *audio_track = NULL; static GstElement *audio_player = NULL; static struct audio_ops *audio_ops = NULL; static int audio_pause_count = -1; - +static guint audio_bus = 0; static void __audio_save() { @@ -64,15 +64,35 @@ static struct track *__audio_next(GstState state) return track; } +static gboolean __audio_message(GstBus *bus, GstMessage *message, gpointer data) +{ + switch (GST_MESSAGE_TYPE(message)) { + case GST_MESSAGE_ERROR: + audio_error(message); + break; + case GST_MESSAGE_EOS: + audio_eos(); + default: + break; + } + + return true; +} + void audio_init(int *argc, char ***argv, struct audio_ops *ops) { unsigned int track; + GstBus *bus; gst_init(argc, argv); audio_player = gst_element_factory_make("playbin", "ocarina_player"); audio_ops = ops; + bus = gst_pipeline_get_bus(GST_PIPELINE(audio_player)); + audio_bus = gst_bus_add_watch(bus, __audio_message, NULL); + gst_object_unref(bus); + file_init(&audio_file, "cur_track", 0); if (file_open(&audio_file, OPEN_READ)) { file_readf(&audio_file, "%u", &track); @@ -85,6 +105,7 @@ void audio_deinit() { gst_element_set_state(audio_player, GST_STATE_NULL); gst_object_unref(GST_ELEMENT(audio_player)); + g_source_remove(audio_bus); audio_player = NULL; audio_track = NULL; @@ -204,14 +225,17 @@ void audio_error(GstMessage *error) gchar *path = NULL, *debug = NULL; GError *err = NULL; - if (audio_track) + if (audio_track) { + collection_check_library(audio_track->tr_library); path = track_path(audio_track); + } if (error) gst_message_parse_error(error, &err, &debug); g_print("Error: %s (%s)\n", err->message, path); if (debug) g_print("Debug details: %s\n", debug); + audio_next(); g_error_free(err); diff --git a/gui/gst.cpp b/gui/gst.cpp index 33e5821d..3da7ded4 100644 --- a/gui/gst.cpp +++ b/gui/gst.cpp @@ -14,8 +14,6 @@ extern "C" { #include -static GstBus *gst_bus; - static Gtk::Button *o_next; static Gtk::Button *o_pause; static Gtk::Button *o_play; @@ -86,45 +84,6 @@ struct audio_ops audio_ops = { }; -static int parse_gst_error(GstMessage *error) -{ - GError *err; - struct track *track = audio_cur_track(); - gchar *path; - int ret = 0; - - gst_message_parse_error(error, &err, NULL); - - if (track) { - path = track_path(track); - g_print("Error playing file: %s\n", path); - ret = collection_check_library(track->tr_library); - g_free(path); - } - g_print("Error: %s\n", err->message); - g_error_free(err); - - return ret; -} - -static gboolean on_gst_message(GstBus *bus, GstMessage *message, gpointer data) -{ - switch (GST_MESSAGE_TYPE(message)) { - case GST_MESSAGE_ERROR: - if (parse_gst_error(message) < 0) - break; - audio_next(); - gst :: play(); - break; - case GST_MESSAGE_EOS: - audio_eos(); - default: - break; - } - - return TRUE; -} - static bool on_seek(Gtk::ScrollType type, double value) { audio_seek(value); @@ -229,7 +188,5 @@ void gst :: init_pre() void gst :: init() { - gst_bus = gst_pipeline_get_bus(GST_PIPELINE(audio_get_player())); - gst_bus_add_watch(gst_bus, on_gst_message, NULL); Glib :: signal_timeout().connect(sigc::ptr_fun(on_timeout), 500); }