From e1abe94b28e1666804a55f173615012fc9b55c66 Mon Sep 17 00:00:00 2001 From: Anna Schumaker Date: Wed, 16 Dec 2015 08:00:19 -0500 Subject: [PATCH] core/audio: Move audio_duration() out of the audio namespace Signed-off-by: Anna Schumaker --- core/audio.cpp | 9 +++++++-- gui/gst.cpp | 12 +----------- include/core/audio.h | 15 +++------------ tests/core/audio.cpp | 17 ++++++++--------- 4 files changed, 19 insertions(+), 34 deletions(-) diff --git a/core/audio.cpp b/core/audio.cpp index 55925eb3..fcc8075c 100644 --- a/core/audio.cpp +++ b/core/audio.cpp @@ -188,10 +188,15 @@ gint64 audio_position() return 0; } -int64_t audio :: duration() +int64_t audio_duration() { + gint64 duration; + if (gst_element_query_duration(audio_player, + GST_FORMAT_TIME, + &duration)) + return duration; if (audio_track) - return cur_driver->duration(); + return audio_track->tr_length * GST_SECOND; return 0; } diff --git a/gui/gst.cpp b/gui/gst.cpp index 295715fe..6aa42e53 100644 --- a/gui/gst.cpp +++ b/gui/gst.cpp @@ -82,16 +82,6 @@ public: GST_CLOCK_TIME_NONE); return state == GST_STATE_PLAYING; } - - int64_t duration() - { - int64_t duration; - if (gst_element_query_duration(audio_get_player(), - GST_FORMAT_TIME, - &duration)) - return duration; - return 0; - } }; static GSTDriver *gst_driver; @@ -164,7 +154,7 @@ static bool on_timeout() { gchar *pos = string_sec2str(audio_position() / GST_SECOND); - o_progress->set_upper(audio :: duration()); + o_progress->set_upper(audio_duration()); o_progress->set_value(audio_position()); o_position->set_text(pos); g_free(pos); diff --git a/include/core/audio.h b/include/core/audio.h index a06491ca..30928cc4 100644 --- a/include/core/audio.h +++ b/include/core/audio.h @@ -39,13 +39,6 @@ public: virtual bool is_playing() = 0; - /** - * Return the duration of the currently loaded track. - * - * @return The duration of the current track, in nanoseconds. - */ - virtual int64_t duration() = 0; - /** * Called to handle reaching the end-of-stream. */ @@ -64,11 +57,6 @@ namespace audio */ void stop(); - /** - * @return The duration of the currently loaded track (in nanoseconds). - */ - int64_t duration(); - void next(); /**< Find and load the next track that should be played. */ void prev(); /**< Call the deck :: previous() function and load the result. */ @@ -130,5 +118,8 @@ bool audio_seek(gint64); /* Called to find the current playback position, in nanoseconds. */ gint64 audio_position(); +/* Called to find the duration of the current track. */ +gint64 audio_duration(); + GstElement *audio_get_player(); #endif /* OCARINA_CORE_AUDIO_H */ diff --git a/tests/core/audio.cpp b/tests/core/audio.cpp index ed0bfe52..217236a6 100644 --- a/tests/core/audio.cpp +++ b/tests/core/audio.cpp @@ -31,15 +31,12 @@ class TestDriver : public AudioDriver { public: bool playing; - int64_t cur_duration; std::string cur_file; - TestDriver() : playing(false), cur_duration(0) {} + TestDriver() : playing(false) {} ~TestDriver() {}; bool is_playing() { return playing; } - - int64_t duration() { return cur_duration; } } driver; static void test_audio_load(struct track *track, GstState state) @@ -73,6 +70,7 @@ static void test_init() test_equal(audio_pause(), false); test_equal(audio_seek(7), false); test_equal(audio_position(), 0); + test_equal(audio_duration(), 0); test_equal(audio :: current_track(), NULL); test_equal(load_count, 0); @@ -89,6 +87,7 @@ static void test_playback() test_equal(load_count, 1); test_equal(audio :: current_track(), track_get(0)); test_equal(queue_size(history_get_queue()), 1); + test_equal(audio_duration(), track_get(0)->tr_length * GST_SECOND); test_equal(audio_load(NULL), false); test_equal(load_count, 1); @@ -110,6 +109,9 @@ static void test_playback() test_equal(test_audio_seek(0), true); test_equal(audio_position(), 0); + + /* Check duration again now that track is fully loaded. */ + test_equal(audio_duration(), track_get(0)->tr_length * GST_SECOND); } static void test_deinit() @@ -140,9 +142,7 @@ void test_pre_init() audio_seek(4242); test_equal(audio_position(), (long)0); - driver->cur_duration = 4242; - test_equal(audio :: duration(), (long)0); - driver->cur_duration = 0; + test_equal(audio_duration(), (long)0); audio :: next(); test_equal(audio :: current_track(), TRACK_NULL); @@ -184,9 +184,8 @@ void test_playback_controls() test_equal(driver->playing, false); audio_seek(4242); - driver->cur_duration = 424242; test_equal(audio_position(), (long)4242); - test_equal(audio :: duration(), (long)424242); + test_equal(audio_duration(), (long)424242); } void test_track_controls()