gst: Various driver cleanups
Signed-off-by: Anna Schumaker <Anna@OcarinaProject.net>
This commit is contained in:
parent
a4ad0aa79b
commit
955129edce
129
gui/gst.cpp
129
gui/gst.cpp
|
@ -35,48 +35,57 @@ private:
|
|||
std::string cur_file;
|
||||
|
||||
public:
|
||||
/**
|
||||
* Load a track into the gstreamer pipeline.
|
||||
* @param filepath The file to be loaded.
|
||||
*/
|
||||
void load(const std::string &);
|
||||
void load(const std::string &filepath)
|
||||
{
|
||||
gchar *uri;
|
||||
|
||||
/**
|
||||
* Begin playback on the GStreamer pipeline.
|
||||
* @return True if the state change was successful.
|
||||
*/
|
||||
bool play();
|
||||
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);
|
||||
g_free(uri);
|
||||
}
|
||||
|
||||
/**
|
||||
* Pause the GStreamer pipeline.
|
||||
* @return True if the state change was successful.
|
||||
*/
|
||||
bool pause();
|
||||
bool play()
|
||||
{
|
||||
return gst_change_state(GST_STATE_PLAYING);
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if the GStreamer pipeline is playing.
|
||||
* @return True if the pipeline is playing.
|
||||
*/
|
||||
bool is_playing();
|
||||
bool pause()
|
||||
{
|
||||
return gst_change_state(GST_STATE_PAUSED);
|
||||
}
|
||||
|
||||
bool is_playing()
|
||||
{
|
||||
GstState state;
|
||||
gst_element_get_state(gst_player, &state, NULL, GST_CLOCK_TIME_NONE);
|
||||
return state == GST_STATE_PLAYING;
|
||||
}
|
||||
|
||||
/**
|
||||
* Seek to a specific position in the pipeline.
|
||||
* @param offset Offset from the beginning of the pipeline, in nanoseconds.
|
||||
*/
|
||||
void seek_to(long);
|
||||
void seek_to(long offset)
|
||||
{
|
||||
gst_element_seek_simple(gst_player,
|
||||
GST_FORMAT_TIME,
|
||||
GST_SEEK_FLAG_FLUSH,
|
||||
offset);
|
||||
}
|
||||
|
||||
/**
|
||||
* Find the current playback position of the pipeline.
|
||||
* @return The current position of the pipeline, in nanoseconds.
|
||||
*/
|
||||
long position();
|
||||
long position()
|
||||
{
|
||||
long position;
|
||||
if (gst_element_query_position(gst_player, GST_FORMAT_TIME, &position))
|
||||
return position;
|
||||
return 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* Find the duration of the pipeline.
|
||||
* @return The duration of the pipeline, in nanoseconds.
|
||||
*/
|
||||
long duration();
|
||||
long duration()
|
||||
{
|
||||
long duration;
|
||||
if (gst_element_query_duration(gst_player, GST_FORMAT_TIME, &duration))
|
||||
return duration;
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
|
@ -107,56 +116,6 @@ static void parse_gst_error(GstMessage *error, const std::string filepath)
|
|||
g_free(debug);
|
||||
}
|
||||
|
||||
void GSTDriver :: 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);
|
||||
g_free(uri);
|
||||
}
|
||||
|
||||
bool GSTDriver :: play()
|
||||
{
|
||||
return gst_change_state(GST_STATE_PLAYING);
|
||||
}
|
||||
|
||||
bool GSTDriver :: pause()
|
||||
{
|
||||
return gst_change_state(GST_STATE_PAUSED);
|
||||
}
|
||||
|
||||
bool GSTDriver :: is_playing()
|
||||
{
|
||||
GstState state;
|
||||
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(gst_player, GST_FORMAT_TIME, GST_SEEK_FLAG_FLUSH, offset);
|
||||
}
|
||||
|
||||
long GSTDriver :: position()
|
||||
{
|
||||
long position;
|
||||
if (gst_element_query_position(gst_player, GST_FORMAT_TIME, &position))
|
||||
return position;
|
||||
return 0;
|
||||
}
|
||||
|
||||
long GSTDriver :: duration()
|
||||
{
|
||||
long duration;
|
||||
|
||||
if (gst_element_query_duration(gst_player, GST_FORMAT_TIME, &duration))
|
||||
return duration;
|
||||
return 0;
|
||||
}
|
||||
|
||||
void GSTDriver :: on_message(GstMessage *message)
|
||||
{
|
||||
switch (GST_MESSAGE_TYPE(message)) {
|
||||
|
|
Loading…
Reference in New Issue