core/audio: Move audio_seek() out of the audio namespace
This commit is contained in:
parent
9097bd0ffc
commit
566ef3bb50
|
@ -162,16 +162,20 @@ bool audio_pause()
|
||||||
return __audio_change_state(GST_STATE_PAUSED);
|
return __audio_change_state(GST_STATE_PAUSED);
|
||||||
}
|
}
|
||||||
|
|
||||||
void audio :: seek_to(int64_t pos)
|
bool audio_seek(gint64 offset)
|
||||||
{
|
{
|
||||||
if (audio_track)
|
if (!audio_track)
|
||||||
cur_driver->seek_to(pos);
|
return false;
|
||||||
|
return gst_element_seek_simple(audio_player,
|
||||||
|
GST_FORMAT_TIME,
|
||||||
|
GST_SEEK_FLAG_FLUSH,
|
||||||
|
offset);
|
||||||
}
|
}
|
||||||
|
|
||||||
void audio :: stop()
|
void audio :: stop()
|
||||||
{
|
{
|
||||||
audio_pause();
|
audio_pause();
|
||||||
seek_to(0);
|
audio_seek(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
int64_t audio :: position()
|
int64_t audio :: position()
|
||||||
|
|
10
gui/gst.cpp
10
gui/gst.cpp
|
@ -83,14 +83,6 @@ public:
|
||||||
return state == GST_STATE_PLAYING;
|
return state == GST_STATE_PLAYING;
|
||||||
}
|
}
|
||||||
|
|
||||||
void seek_to(int64_t offset)
|
|
||||||
{
|
|
||||||
gst_element_seek_simple(audio_get_player(),
|
|
||||||
GST_FORMAT_TIME,
|
|
||||||
GST_SEEK_FLAG_FLUSH,
|
|
||||||
offset);
|
|
||||||
}
|
|
||||||
|
|
||||||
int64_t position()
|
int64_t position()
|
||||||
{
|
{
|
||||||
int64_t position;
|
int64_t position;
|
||||||
|
@ -163,7 +155,7 @@ static gboolean on_gst_message(GstBus *bus, GstMessage *message, gpointer data)
|
||||||
|
|
||||||
static bool on_seek(Gtk::ScrollType type, double value)
|
static bool on_seek(Gtk::ScrollType type, double value)
|
||||||
{
|
{
|
||||||
audio :: seek_to(value);
|
audio_seek(value);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -39,13 +39,6 @@ public:
|
||||||
virtual bool is_playing() = 0;
|
virtual bool is_playing() = 0;
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Seek to a specific position in the current track.
|
|
||||||
*
|
|
||||||
* @param offset Position from the beginning of the track where we will seek to, in nanoseconds.
|
|
||||||
*/
|
|
||||||
virtual void seek_to(int64_t offset) = 0;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Return the current position of the playback.
|
* Return the current position of the playback.
|
||||||
*
|
*
|
||||||
|
@ -73,13 +66,6 @@ public:
|
||||||
namespace audio
|
namespace audio
|
||||||
{
|
{
|
||||||
|
|
||||||
/**
|
|
||||||
* Seek to a specific point in the track.
|
|
||||||
*
|
|
||||||
* @param pos Offset (in nanoseconds) from the beginning of the track.
|
|
||||||
*/
|
|
||||||
void seek_to(int64_t);
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Stop playback and seek to the beginning of the track.
|
* Stop playback and seek to the beginning of the track.
|
||||||
*/
|
*/
|
||||||
|
@ -150,5 +136,8 @@ bool audio_play();
|
||||||
/* Called to pause playback. */
|
/* Called to pause playback. */
|
||||||
bool audio_pause();
|
bool audio_pause();
|
||||||
|
|
||||||
|
/* Called to seek playback to a specific offset, in nanoseconds. */
|
||||||
|
bool audio_seek(gint64);
|
||||||
|
|
||||||
GstElement *audio_get_player();
|
GstElement *audio_get_player();
|
||||||
#endif /* OCARINA_CORE_AUDIO_H */
|
#endif /* OCARINA_CORE_AUDIO_H */
|
||||||
|
|
|
@ -14,6 +14,19 @@ struct track *TRACK_NULL = NULL;
|
||||||
static unsigned int load_count = 0;
|
static unsigned int load_count = 0;
|
||||||
|
|
||||||
|
|
||||||
|
static bool test_audio_seek(gint64 pos)
|
||||||
|
{
|
||||||
|
bool ret = audio_seek(pos);
|
||||||
|
GstState state;
|
||||||
|
|
||||||
|
do {
|
||||||
|
gst_element_get_state(audio_get_player(), &state, NULL,
|
||||||
|
GST_CLOCK_TIME_NONE);
|
||||||
|
} while (state != GST_STATE_PAUSED && state != GST_STATE_PLAYING);
|
||||||
|
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
class TestDriver : public AudioDriver
|
class TestDriver : public AudioDriver
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
|
@ -27,7 +40,6 @@ public:
|
||||||
|
|
||||||
bool is_playing() { return playing; }
|
bool is_playing() { return playing; }
|
||||||
|
|
||||||
void seek_to(int64_t offset) { cur_pos = offset; }
|
|
||||||
int64_t position() { return cur_pos; }
|
int64_t position() { return cur_pos; }
|
||||||
int64_t duration() { return cur_duration; }
|
int64_t duration() { return cur_duration; }
|
||||||
} driver;
|
} driver;
|
||||||
|
@ -61,6 +73,7 @@ static void test_init()
|
||||||
test_equal(audio_load(NULL), false);
|
test_equal(audio_load(NULL), false);
|
||||||
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 :: current_track(), NULL);
|
test_equal(audio :: current_track(), NULL);
|
||||||
test_equal(load_count, 0);
|
test_equal(load_count, 0);
|
||||||
|
|
||||||
|
@ -92,6 +105,9 @@ static void test_playback()
|
||||||
|
|
||||||
test_equal(audio_pause(), true);
|
test_equal(audio_pause(), true);
|
||||||
test_equal(audio_pause(), false);
|
test_equal(audio_pause(), false);
|
||||||
|
|
||||||
|
test_equal(test_audio_seek(5 * GST_SECOND), true);
|
||||||
|
test_equal(test_audio_seek(0), true);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void test_deinit()
|
static void test_deinit()
|
||||||
|
@ -119,7 +135,7 @@ void test_pre_init()
|
||||||
test_equal(driver->playing, true);
|
test_equal(driver->playing, true);
|
||||||
driver->playing = false;
|
driver->playing = false;
|
||||||
|
|
||||||
audio :: seek_to(4242);
|
audio_seek(4242);
|
||||||
test_equal(driver->position(), (long)0);
|
test_equal(driver->position(), (long)0);
|
||||||
|
|
||||||
driver->cur_pos = 4242;
|
driver->cur_pos = 4242;
|
||||||
|
@ -162,7 +178,8 @@ void test_playback_controls()
|
||||||
driver->playing = audio_pause();
|
driver->playing = audio_pause();
|
||||||
test_equal(driver->playing, false);
|
test_equal(driver->playing, false);
|
||||||
|
|
||||||
audio :: seek_to(4242);
|
if (audio_seek(4242))
|
||||||
|
driver->cur_pos = 4242;
|
||||||
test_equal(driver->cur_pos, (long)4242);
|
test_equal(driver->cur_pos, (long)4242);
|
||||||
test_equal(audio :: position(), (long)4242);
|
test_equal(audio :: position(), (long)4242);
|
||||||
|
|
||||||
|
@ -171,7 +188,7 @@ void test_playback_controls()
|
||||||
test_equal(driver->playing, false);
|
test_equal(driver->playing, false);
|
||||||
test_equal(driver->cur_pos, (long)0);
|
test_equal(driver->cur_pos, (long)0);
|
||||||
|
|
||||||
audio :: seek_to(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);
|
||||||
|
@ -197,12 +214,12 @@ void test_track_controls()
|
||||||
test_not_equal(audio :: current_track(), track);
|
test_not_equal(audio :: current_track(), track);
|
||||||
|
|
||||||
track = track_get(0);
|
track = track_get(0);
|
||||||
audio :: seek_to(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_to(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);
|
||||||
|
|
Loading…
Reference in New Issue