core/audio: Move audio_position() out of the audio namespace
Signed-off-by: Anna Schumaker <Anna@OcarinaProject.net>
This commit is contained in:
parent
566ef3bb50
commit
20bb01ef4e
|
@ -178,10 +178,13 @@ void audio :: stop()
|
||||||
audio_seek(0);
|
audio_seek(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
int64_t audio :: position()
|
gint64 audio_position()
|
||||||
{
|
{
|
||||||
if (audio_track)
|
gint64 position;
|
||||||
return cur_driver->position();
|
if (gst_element_query_position(audio_player,
|
||||||
|
GST_FORMAT_TIME,
|
||||||
|
&position))
|
||||||
|
return position;
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
14
gui/gst.cpp
14
gui/gst.cpp
|
@ -83,16 +83,6 @@ public:
|
||||||
return state == GST_STATE_PLAYING;
|
return state == GST_STATE_PLAYING;
|
||||||
}
|
}
|
||||||
|
|
||||||
int64_t position()
|
|
||||||
{
|
|
||||||
int64_t position;
|
|
||||||
if (gst_element_query_position(audio_get_player(),
|
|
||||||
GST_FORMAT_TIME,
|
|
||||||
&position))
|
|
||||||
return position;
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
int64_t duration()
|
int64_t duration()
|
||||||
{
|
{
|
||||||
int64_t duration;
|
int64_t duration;
|
||||||
|
@ -172,10 +162,10 @@ static void on_pause_enabled()
|
||||||
|
|
||||||
static bool on_timeout()
|
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);
|
||||||
return true;
|
return true;
|
||||||
|
|
|
@ -39,13 +39,6 @@ public:
|
||||||
virtual bool is_playing() = 0;
|
virtual bool is_playing() = 0;
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Return the current position of the playback.
|
|
||||||
*
|
|
||||||
* @return The current playback position, in nanoseconds.
|
|
||||||
*/
|
|
||||||
virtual int64_t position() = 0;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Return the duration of the currently loaded track.
|
* Return the duration of the currently loaded track.
|
||||||
*
|
*
|
||||||
|
@ -71,11 +64,6 @@ namespace audio
|
||||||
*/
|
*/
|
||||||
void stop();
|
void stop();
|
||||||
|
|
||||||
/**
|
|
||||||
* @return The current position of the audio playback (in nanoseconds).
|
|
||||||
*/
|
|
||||||
int64_t position();
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return The duration of the currently loaded track (in nanoseconds).
|
* @return The duration of the currently loaded track (in nanoseconds).
|
||||||
*/
|
*/
|
||||||
|
@ -139,5 +127,8 @@ bool audio_pause();
|
||||||
/* Called to seek playback to a specific offset, in nanoseconds. */
|
/* Called to seek playback to a specific offset, in nanoseconds. */
|
||||||
bool audio_seek(gint64);
|
bool audio_seek(gint64);
|
||||||
|
|
||||||
|
/* Called to find the current playback position, in nanoseconds. */
|
||||||
|
gint64 audio_position();
|
||||||
|
|
||||||
GstElement *audio_get_player();
|
GstElement *audio_get_player();
|
||||||
#endif /* OCARINA_CORE_AUDIO_H */
|
#endif /* OCARINA_CORE_AUDIO_H */
|
||||||
|
|
|
@ -31,16 +31,14 @@ class TestDriver : public AudioDriver
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
bool playing;
|
bool playing;
|
||||||
int64_t cur_pos;
|
|
||||||
int64_t cur_duration;
|
int64_t cur_duration;
|
||||||
std::string cur_file;
|
std::string cur_file;
|
||||||
|
|
||||||
TestDriver() : playing(false), cur_pos(0), cur_duration(0) {}
|
TestDriver() : playing(false), cur_duration(0) {}
|
||||||
~TestDriver() {};
|
~TestDriver() {};
|
||||||
|
|
||||||
bool is_playing() { return playing; }
|
bool is_playing() { return playing; }
|
||||||
|
|
||||||
int64_t position() { return cur_pos; }
|
|
||||||
int64_t duration() { return cur_duration; }
|
int64_t duration() { return cur_duration; }
|
||||||
} driver;
|
} driver;
|
||||||
|
|
||||||
|
@ -74,6 +72,7 @@ static void test_init()
|
||||||
test_equal(audio_play(), false);
|
test_equal(audio_play(), false);
|
||||||
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 :: current_track(), NULL);
|
test_equal(audio :: current_track(), NULL);
|
||||||
test_equal(load_count, 0);
|
test_equal(load_count, 0);
|
||||||
|
|
||||||
|
@ -107,7 +106,10 @@ static void test_playback()
|
||||||
test_equal(audio_pause(), false);
|
test_equal(audio_pause(), false);
|
||||||
|
|
||||||
test_equal(test_audio_seek(5 * GST_SECOND), true);
|
test_equal(test_audio_seek(5 * GST_SECOND), true);
|
||||||
|
test_equal(audio_position(), 5 * GST_SECOND);
|
||||||
|
|
||||||
test_equal(test_audio_seek(0), true);
|
test_equal(test_audio_seek(0), true);
|
||||||
|
test_equal(audio_position(), 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void test_deinit()
|
static void test_deinit()
|
||||||
|
@ -136,11 +138,7 @@ void test_pre_init()
|
||||||
driver->playing = false;
|
driver->playing = false;
|
||||||
|
|
||||||
audio_seek(4242);
|
audio_seek(4242);
|
||||||
test_equal(driver->position(), (long)0);
|
test_equal(audio_position(), (long)0);
|
||||||
|
|
||||||
driver->cur_pos = 4242;
|
|
||||||
test_equal(audio :: position(), (long)0);
|
|
||||||
driver->cur_pos = 0;
|
|
||||||
|
|
||||||
driver->cur_duration = 4242;
|
driver->cur_duration = 4242;
|
||||||
test_equal(audio :: duration(), (long)0);
|
test_equal(audio :: duration(), (long)0);
|
||||||
|
@ -178,19 +176,16 @@ void test_playback_controls()
|
||||||
driver->playing = audio_pause();
|
driver->playing = audio_pause();
|
||||||
test_equal(driver->playing, false);
|
test_equal(driver->playing, false);
|
||||||
|
|
||||||
if (audio_seek(4242))
|
audio_seek(4242);
|
||||||
driver->cur_pos = 4242;
|
test_equal(audio_position(), (long)4242);
|
||||||
test_equal(driver->cur_pos, (long)4242);
|
|
||||||
test_equal(audio :: position(), (long)4242);
|
|
||||||
|
|
||||||
audio_play();
|
audio_play();
|
||||||
audio :: stop();
|
audio :: stop();
|
||||||
test_equal(driver->playing, false);
|
test_equal(driver->playing, false);
|
||||||
test_equal(driver->cur_pos, (long)0);
|
|
||||||
|
|
||||||
audio_seek(4242);
|
audio_seek(4242);
|
||||||
driver->cur_duration = 424242;
|
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);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -217,12 +212,12 @@ void test_track_controls()
|
||||||
audio_seek(4242);
|
audio_seek(4242);
|
||||||
audio_load(track);
|
audio_load(track);
|
||||||
test_equal(driver->is_playing(), true);
|
test_equal(driver->is_playing(), true);
|
||||||
test_equal(audio :: position(), (long)0);
|
test_equal(audio_position(), (long)0);
|
||||||
|
|
||||||
audio_seek(4242);
|
audio_seek(4242);
|
||||||
audio_load(track);
|
audio_load(track);
|
||||||
test_equal(driver->is_playing(), true);
|
test_equal(driver->is_playing(), true);
|
||||||
test_equal(audio :: position(), (long)4242);
|
test_equal(audio_position(), (long)4242);
|
||||||
|
|
||||||
track = audio :: current_track();
|
track = audio :: current_track();
|
||||||
driver->eos();
|
driver->eos();
|
||||||
|
|
Loading…
Reference in New Issue
Block a user