From 955129edce5e2fe6d8579439b6f0fc5dffc3e9e4 Mon Sep 17 00:00:00 2001 From: Anna Schumaker Date: Sat, 20 Dec 2014 11:15:38 -0500 Subject: [PATCH] gst: Various driver cleanups Signed-off-by: Anna Schumaker --- gui/gst.cpp | 129 ++++++++++++++++++---------------------------------- 1 file changed, 44 insertions(+), 85 deletions(-) diff --git a/gui/gst.cpp b/gui/gst.cpp index 67784a28..d19a4b67 100644 --- a/gui/gst.cpp +++ b/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)) {