gst: Begin reworking gst driver
I removed the need for an overridden constructor and destructor. Signed-off-by: Anna Schumaker <Anna@OcarinaProject.net>
This commit is contained in:
parent
e866ea2574
commit
882da67480
86
gui/gst.cpp
86
gui/gst.cpp
|
@ -5,9 +5,22 @@
|
|||
#include <core/driver.h>
|
||||
#include <gst/gst.h>
|
||||
|
||||
class GSTDriver;
|
||||
|
||||
static GSTDriver *gst_driver;
|
||||
static GstBus *gst_bus;
|
||||
static GstElement *gst_player;
|
||||
|
||||
|
||||
bool gst_change_state(GstState state)
|
||||
{
|
||||
GstStateChangeReturn ret = gst_element_set_state(gst_player, state);
|
||||
switch (ret) {
|
||||
case GST_STATE_CHANGE_SUCCESS:
|
||||
case GST_STATE_CHANGE_ASYNC:
|
||||
return true;
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
|
@ -19,21 +32,9 @@ static GSTDriver *gst_driver;
|
|||
class GSTDriver : public Driver
|
||||
{
|
||||
private:
|
||||
GstElement *player;
|
||||
std::string cur_file;
|
||||
bool change_state(GstState state);
|
||||
|
||||
public:
|
||||
/**
|
||||
* GStreamer audio driver constructor.
|
||||
*/
|
||||
GSTDriver(int *, char ***);
|
||||
|
||||
/**
|
||||
* GStreamer audio driver destructor.
|
||||
*/
|
||||
~GSTDriver();
|
||||
|
||||
/**
|
||||
* Called to initialize the GStreamer audio driver.
|
||||
* @param eos_cb End-of-stream callback function.
|
||||
|
@ -91,6 +92,7 @@ public:
|
|||
void on_message(GstMessage *);
|
||||
};
|
||||
|
||||
static GSTDriver *gst_driver;
|
||||
|
||||
static gboolean on_gst_message(GstBus *bus, GstMessage *message, gpointer data)
|
||||
{
|
||||
|
@ -111,35 +113,6 @@ static void parse_gst_error(GstMessage *error, const std::string filepath)
|
|||
g_free(debug);
|
||||
}
|
||||
|
||||
GSTDriver :: GSTDriver(int *argc, char ***argv)
|
||||
: Driver()
|
||||
{
|
||||
GstBus *bus;
|
||||
|
||||
gst_init(argc, argv);
|
||||
player = gst_element_factory_make("playbin", "ocarina_player");
|
||||
bus = gst_pipeline_get_bus(GST_PIPELINE(player));
|
||||
gst_bus_add_watch(bus, on_gst_message, this);
|
||||
}
|
||||
|
||||
GSTDriver :: ~GSTDriver()
|
||||
{
|
||||
change_state(GST_STATE_NULL);
|
||||
gst_deinit();
|
||||
}
|
||||
|
||||
bool GSTDriver :: change_state(GstState state)
|
||||
{
|
||||
GstStateChangeReturn ret = gst_element_set_state(player, state);
|
||||
switch (ret) {
|
||||
case GST_STATE_CHANGE_SUCCESS:
|
||||
case GST_STATE_CHANGE_ASYNC:
|
||||
return true;
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
void GSTDriver :: init(void (*eos_cb)())
|
||||
{
|
||||
on_eos = eos_cb;
|
||||
|
@ -150,38 +123,38 @@ void GSTDriver :: load(const std::string &filepath)
|
|||
gchar *uri;
|
||||
|
||||
cur_file = filepath;
|
||||
change_state(GST_STATE_NULL);
|
||||
gst_change_state(GST_STATE_NULL);
|
||||
uri = gst_filename_to_uri(filepath.c_str(), NULL);
|
||||
g_object_set(G_OBJECT(player), "uri", uri, NULL);
|
||||
g_object_set(G_OBJECT(gst_player), "uri", uri, NULL);
|
||||
g_free(uri);
|
||||
}
|
||||
|
||||
bool GSTDriver :: play()
|
||||
{
|
||||
return change_state(GST_STATE_PLAYING);
|
||||
return gst_change_state(GST_STATE_PLAYING);
|
||||
}
|
||||
|
||||
bool GSTDriver :: pause()
|
||||
{
|
||||
return change_state(GST_STATE_PAUSED);
|
||||
return gst_change_state(GST_STATE_PAUSED);
|
||||
}
|
||||
|
||||
bool GSTDriver :: is_playing()
|
||||
{
|
||||
GstState state;
|
||||
gst_element_get_state(player, &state, NULL, GST_CLOCK_TIME_NONE);
|
||||
gst_element_get_state(gst_player, &state, NULL, GST_CLOCK_TIME_NONE);
|
||||
return state == GST_STATE_PLAYING;
|
||||
}
|
||||
|
||||
void GSTDriver :: seek_to(long offset)
|
||||
{
|
||||
gst_element_seek_simple(player, GST_FORMAT_TIME, GST_SEEK_FLAG_FLUSH, offset);
|
||||
gst_element_seek_simple(gst_player, GST_FORMAT_TIME, GST_SEEK_FLAG_FLUSH, offset);
|
||||
}
|
||||
|
||||
long GSTDriver :: position()
|
||||
{
|
||||
long position;
|
||||
if (gst_element_query_position(player, GST_FORMAT_TIME, &position))
|
||||
if (gst_element_query_position(gst_player, GST_FORMAT_TIME, &position))
|
||||
return position;
|
||||
return 0;
|
||||
}
|
||||
|
@ -190,7 +163,7 @@ long GSTDriver :: duration()
|
|||
{
|
||||
long duration;
|
||||
|
||||
if (gst_element_query_duration(player, GST_FORMAT_TIME, &duration))
|
||||
if (gst_element_query_duration(gst_player, GST_FORMAT_TIME, &duration))
|
||||
return duration;
|
||||
return 0;
|
||||
}
|
||||
|
@ -213,10 +186,19 @@ void GSTDriver :: on_message(GstMessage *message)
|
|||
|
||||
void init_gst(int *argc, char ***argv)
|
||||
{
|
||||
gst_driver = new GSTDriver(argc, argv);
|
||||
gst_init(argc, argv);
|
||||
|
||||
gst_player = gst_element_factory_make("playbin", "ocarina_player");
|
||||
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);
|
||||
}
|
||||
|
||||
void quit_gst()
|
||||
{
|
||||
delete gst_driver;
|
||||
|
||||
gst_change_state(GST_STATE_NULL);
|
||||
gst_deinit();
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue