core/audio: Move audio_duration() out of the audio namespace

Signed-off-by: Anna Schumaker <Anna@OcarinaProject.net>
This commit is contained in:
Anna Schumaker 2015-12-16 08:00:19 -05:00
parent 20bb01ef4e
commit e1abe94b28
4 changed files with 19 additions and 34 deletions

View File

@ -188,10 +188,15 @@ gint64 audio_position()
return 0; 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) if (audio_track)
return cur_driver->duration(); return audio_track->tr_length * GST_SECOND;
return 0; return 0;
} }

View File

@ -82,16 +82,6 @@ public:
GST_CLOCK_TIME_NONE); GST_CLOCK_TIME_NONE);
return state == GST_STATE_PLAYING; 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; static GSTDriver *gst_driver;
@ -164,7 +154,7 @@ static bool on_timeout()
{ {
gchar *pos = string_sec2str(audio_position() / GST_SECOND); 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_progress->set_value(audio_position());
o_position->set_text(pos); o_position->set_text(pos);
g_free(pos); g_free(pos);

View File

@ -39,13 +39,6 @@ public:
virtual bool is_playing() = 0; 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. * Called to handle reaching the end-of-stream.
*/ */
@ -64,11 +57,6 @@ namespace audio
*/ */
void stop(); 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 next(); /**< Find and load the next track that should be played. */
void prev(); /**< Call the deck :: previous() function and load the result. */ 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. */ /* Called to find the current playback position, in nanoseconds. */
gint64 audio_position(); gint64 audio_position();
/* Called to find the duration of the current track. */
gint64 audio_duration();
GstElement *audio_get_player(); GstElement *audio_get_player();
#endif /* OCARINA_CORE_AUDIO_H */ #endif /* OCARINA_CORE_AUDIO_H */

View File

@ -31,15 +31,12 @@ class TestDriver : public AudioDriver
{ {
public: public:
bool playing; bool playing;
int64_t cur_duration;
std::string cur_file; std::string cur_file;
TestDriver() : playing(false), cur_duration(0) {} TestDriver() : playing(false) {}
~TestDriver() {}; ~TestDriver() {};
bool is_playing() { return playing; } bool is_playing() { return playing; }
int64_t duration() { return cur_duration; }
} driver; } driver;
static void test_audio_load(struct track *track, GstState state) 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_pause(), false);
test_equal(audio_seek(7), false); test_equal(audio_seek(7), false);
test_equal(audio_position(), 0); test_equal(audio_position(), 0);
test_equal(audio_duration(), 0);
test_equal(audio :: current_track(), NULL); test_equal(audio :: current_track(), NULL);
test_equal(load_count, 0); test_equal(load_count, 0);
@ -89,6 +87,7 @@ static void test_playback()
test_equal(load_count, 1); test_equal(load_count, 1);
test_equal(audio :: current_track(), track_get(0)); test_equal(audio :: current_track(), track_get(0));
test_equal(queue_size(history_get_queue()), 1); 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(audio_load(NULL), false);
test_equal(load_count, 1); test_equal(load_count, 1);
@ -110,6 +109,9 @@ static void test_playback()
test_equal(test_audio_seek(0), true); test_equal(test_audio_seek(0), true);
test_equal(audio_position(), 0); 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() static void test_deinit()
@ -140,9 +142,7 @@ void test_pre_init()
audio_seek(4242); audio_seek(4242);
test_equal(audio_position(), (long)0); test_equal(audio_position(), (long)0);
driver->cur_duration = 4242; test_equal(audio_duration(), (long)0);
test_equal(audio :: duration(), (long)0);
driver->cur_duration = 0;
audio :: next(); audio :: next();
test_equal(audio :: current_track(), TRACK_NULL); test_equal(audio :: current_track(), TRACK_NULL);
@ -184,9 +184,8 @@ void test_playback_controls()
test_equal(driver->playing, false); test_equal(driver->playing, false);
audio_seek(4242); audio_seek(4242);
driver->cur_duration = 424242;
test_equal(audio_position(), (long)4242); test_equal(audio_position(), (long)4242);
test_equal(audio :: duration(), (long)424242); test_equal(audio_duration(), (long)424242);
} }
void test_track_controls() void test_track_controls()