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 <Anna@OcarinaProject.net>
This commit is contained in:
Anna Schumaker 2014-12-20 11:33:08 -05:00
parent 955129edce
commit 3da3c8aeea
1 changed files with 12 additions and 26 deletions

View File

@ -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()