driver: Fold eos() into the driver
With this patch I no longer need a Driver :: init() function to handle picking the next track. Signed-off-by: Anna Schumaker <Anna@OcarinaProject.net>
This commit is contained in:
parent
882da67480
commit
a4ad0aa79b
|
@ -19,6 +19,9 @@ static File f_cur_track("cur_track", 0);
|
|||
|
||||
static Driver *cur_driver = NULL;
|
||||
|
||||
static void _load_track(Track *, bool);
|
||||
static bool continue_playback();
|
||||
|
||||
|
||||
Driver :: Driver()
|
||||
{
|
||||
|
@ -30,6 +33,16 @@ Driver :: ~Driver()
|
|||
cur_driver = NULL;
|
||||
}
|
||||
|
||||
void Driver :: eos()
|
||||
{
|
||||
if (cur_track) {
|
||||
cur_track->played();
|
||||
library :: get_queue()->updated(cur_track);
|
||||
}
|
||||
|
||||
_load_track(deck :: next(), continue_playback());
|
||||
}
|
||||
|
||||
|
||||
static void save_state()
|
||||
{
|
||||
|
@ -74,21 +87,10 @@ static bool continue_playback()
|
|||
return ret;
|
||||
}
|
||||
|
||||
static void on_eos()
|
||||
{
|
||||
if (cur_track) {
|
||||
cur_track->played();
|
||||
library :: get_queue()->updated(cur_track);
|
||||
}
|
||||
|
||||
_load_track(deck :: next(), continue_playback());
|
||||
}
|
||||
|
||||
void audio :: init()
|
||||
{
|
||||
unsigned int id;
|
||||
|
||||
cur_driver->init(on_eos);
|
||||
if (f_cur_track.exists()) {
|
||||
f_cur_track.open(OPEN_READ);
|
||||
f_cur_track >> id;
|
||||
|
|
13
gui/gst.cpp
13
gui/gst.cpp
|
@ -35,12 +35,6 @@ private:
|
|||
std::string cur_file;
|
||||
|
||||
public:
|
||||
/**
|
||||
* Called to initialize the GStreamer audio driver.
|
||||
* @param eos_cb End-of-stream callback function.
|
||||
*/
|
||||
void init(void (*)());
|
||||
|
||||
/**
|
||||
* Load a track into the gstreamer pipeline.
|
||||
* @param filepath The file to be loaded.
|
||||
|
@ -113,11 +107,6 @@ static void parse_gst_error(GstMessage *error, const std::string filepath)
|
|||
g_free(debug);
|
||||
}
|
||||
|
||||
void GSTDriver :: init(void (*eos_cb)())
|
||||
{
|
||||
on_eos = eos_cb;
|
||||
}
|
||||
|
||||
void GSTDriver :: load(const std::string &filepath)
|
||||
{
|
||||
gchar *uri;
|
||||
|
@ -176,7 +165,7 @@ void GSTDriver :: on_message(GstMessage *message)
|
|||
audio :: next();
|
||||
break;
|
||||
case GST_MESSAGE_EOS:
|
||||
on_eos();
|
||||
gst_driver->eos();
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
|
|
|
@ -17,20 +17,12 @@ static const unsigned long O_SECOND = 1000000000;
|
|||
*/
|
||||
class Driver {
|
||||
protected:
|
||||
void (*on_eos) (); /**< End-of-stream callback function. */
|
||||
void (*on_error) (); /**< Error handling callback function. */
|
||||
|
||||
public:
|
||||
Driver(); /**< Default Driver constructor. */
|
||||
virtual ~Driver(); /**< Driver destructor. */
|
||||
|
||||
/**
|
||||
* Initialize an audio driver.
|
||||
*
|
||||
* @param eos_cb End-of-stream callback function.
|
||||
*/
|
||||
virtual void init(void (*eos_cb)()) = 0;
|
||||
|
||||
|
||||
/**
|
||||
* Loads an audio file for playback.
|
||||
|
@ -81,6 +73,11 @@ public:
|
|||
* @return The duration of the current track, in nanoseconds.
|
||||
*/
|
||||
virtual long duration() = 0;
|
||||
|
||||
/**
|
||||
* Called to handle reaching the end-of-stream.
|
||||
*/
|
||||
void eos();
|
||||
};
|
||||
|
||||
#endif /* OCARINA_CORE_DRIVER_H */
|
||||
|
|
|
@ -8,7 +8,6 @@
|
|||
#include <tests/test.h>
|
||||
|
||||
Track *TRACK_NULL = NULL;
|
||||
static unsigned int eos_count = 0;
|
||||
|
||||
|
||||
class TestDriver : public Driver
|
||||
|
@ -22,11 +21,6 @@ public:
|
|||
TestDriver() : playing(false), cur_pos(0), cur_duration(0) {}
|
||||
~TestDriver() {};
|
||||
|
||||
void init(void (*eos_cb)())
|
||||
{
|
||||
on_eos = eos_cb;
|
||||
}
|
||||
|
||||
void load(const std::string &file)
|
||||
{
|
||||
cur_file = file;
|
||||
|
@ -51,14 +45,8 @@ public:
|
|||
void seek_to(long offset) { cur_pos = offset; }
|
||||
long position() { return cur_pos; }
|
||||
long duration() { return cur_duration; }
|
||||
|
||||
void eos() { on_eos(); }
|
||||
};
|
||||
|
||||
void on_eos()
|
||||
{
|
||||
eos_count++;
|
||||
}
|
||||
|
||||
void test_driver()
|
||||
{
|
||||
|
@ -70,8 +58,6 @@ void test_driver()
|
|||
test_not_equal(audio :: get_driver(), (Driver *)NULL);
|
||||
test_equal((Driver *)&driver, audio :: get_driver());
|
||||
|
||||
driver.init(on_eos);
|
||||
|
||||
driver.load(file);
|
||||
test_equal(driver.cur_file, file);
|
||||
|
||||
|
@ -90,9 +76,6 @@ void test_driver()
|
|||
driver.cur_duration = 424242;
|
||||
test_equal(driver.duration(), (long)424242);
|
||||
|
||||
driver.eos();
|
||||
test_equal(eos_count, (unsigned)1);
|
||||
|
||||
driver.play();
|
||||
driver.seek_to(4242);
|
||||
driver.load(file);
|
||||
|
|
Loading…
Reference in New Issue