From 3da3c8aeea34903a50e89b1e8617e1e39a0c1661 Mon Sep 17 00:00:00 2001 From: Anna Schumaker Date: Sat, 20 Dec 2014 11:33:08 -0500 Subject: [PATCH] gst: Move the on_message() function out of the driver This function doesn't use anything in the driver class anymore, so it can be removed. Signed-off-by: Anna Schumaker --- gui/gst.cpp | 38 ++++++++++++-------------------------- 1 file changed, 12 insertions(+), 26 deletions(-) diff --git a/gui/gst.cpp b/gui/gst.cpp index d19a4b67..916b856f 100644 --- a/gui/gst.cpp +++ b/gui/gst.cpp @@ -10,7 +10,7 @@ static GstBus *gst_bus; static GstElement *gst_player; -bool gst_change_state(GstState state) +static bool gst_change_state(GstState state) { GstStateChangeReturn ret = gst_element_set_state(gst_player, state); switch (ret) { @@ -31,15 +31,11 @@ bool gst_change_state(GstState state) */ class GSTDriver : public Driver { -private: - std::string cur_file; - public: void load(const std::string &filepath) { gchar *uri; - cur_file = filepath; gst_change_state(GST_STATE_NULL); uri = gst_filename_to_uri(filepath.c_str(), NULL); g_object_set(G_OBJECT(gst_player), "uri", uri, NULL); @@ -86,41 +82,29 @@ public: return duration; return 0; } - - - /** - * Called to handle messages from the GStreamer bus. - * @param message The message to be handled. - */ - void on_message(GstMessage *); }; static GSTDriver *gst_driver; -static gboolean on_gst_message(GstBus *bus, GstMessage *message, gpointer data) -{ - GSTDriver *driver = (GSTDriver *)data; - driver->on_message(message); - return TRUE; -} -static void parse_gst_error(GstMessage *error, const std::string filepath) +static void parse_gst_error(GstMessage *error) { GError *err; - gchar *debug; + Track *track = audio :: current_track(); - gst_message_parse_error(error, &err, &debug); - g_print("Error playing file: %s\n", filepath.c_str()); + gst_message_parse_error(error, &err, NULL); + + if (track) + g_print("Error playing file: %s\n", track->path().c_str()); g_print("Error: %s\n", err->message); g_error_free(err); - g_free(debug); } -void GSTDriver :: on_message(GstMessage *message) +static gboolean on_gst_message(GstBus *bus, GstMessage *message, gpointer data) { switch (GST_MESSAGE_TYPE(message)) { case GST_MESSAGE_ERROR: - parse_gst_error(message, cur_file); + parse_gst_error(message); audio :: next(); break; case GST_MESSAGE_EOS: @@ -129,6 +113,8 @@ void GSTDriver :: on_message(GstMessage *message) default: break; } + + return TRUE; } @@ -140,7 +126,7 @@ void init_gst(int *argc, char ***argv) gst_bus = gst_pipeline_get_bus(GST_PIPELINE(gst_player)); gst_driver = new GSTDriver(); - gst_bus_add_watch(gst_bus, on_gst_message, gst_driver); + gst_bus_add_watch(gst_bus, on_gst_message, NULL); } void quit_gst()