core/audio: Move audio_eos() out of the AudioDriver
This change lets me remove the AudioDriver, too. Signed-off-by: Anna Schumaker <Anna@OcarinaProject.net>
This commit is contained in:
parent
276c56406a
commit
a5556ac10a
|
@ -16,8 +16,6 @@ static GstElement *audio_player = NULL;
|
||||||
static struct audio_ops *audio_ops = NULL;
|
static struct audio_ops *audio_ops = NULL;
|
||||||
static int audio_pause_count = -1;
|
static int audio_pause_count = -1;
|
||||||
|
|
||||||
static AudioDriver *cur_driver = NULL;
|
|
||||||
|
|
||||||
|
|
||||||
static void __audio_save()
|
static void __audio_save()
|
||||||
{
|
{
|
||||||
|
@ -56,46 +54,17 @@ static bool __audio_load(struct track *track, GstState state)
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
static GstState continue_playback()
|
static struct track *__audio_next(GstState state)
|
||||||
{
|
{
|
||||||
if (audio_pause_count >= 0) {
|
struct track *track = tempq_next();
|
||||||
audio_pause_after(audio_pause_count - 1);
|
|
||||||
if (audio_pause_count == -1)
|
|
||||||
return GST_STATE_PAUSED;
|
|
||||||
}
|
|
||||||
return GST_STATE_PLAYING;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
AudioDriver :: AudioDriver()
|
|
||||||
{
|
|
||||||
cur_driver = this;
|
|
||||||
}
|
|
||||||
|
|
||||||
AudioDriver :: ~AudioDriver()
|
|
||||||
{
|
|
||||||
cur_driver = NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
void AudioDriver :: eos()
|
|
||||||
{
|
|
||||||
struct track *track;
|
|
||||||
|
|
||||||
if (audio_track) {
|
|
||||||
track_played(audio_track);
|
|
||||||
queue_updated(collection_get_queue(), audio_track);
|
|
||||||
}
|
|
||||||
|
|
||||||
track = tempq_next();
|
|
||||||
if (!track)
|
if (!track)
|
||||||
track = queue_next(collection_get_queue());
|
track = queue_next(collection_get_queue());
|
||||||
if (__audio_load(track, continue_playback()))
|
if (__audio_load(track, state))
|
||||||
history_add(track);
|
history_add(track);
|
||||||
|
return track;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
void audio_init(int *argc, char ***argv, struct audio_ops *ops)
|
void audio_init(int *argc, char ***argv, struct audio_ops *ops)
|
||||||
{
|
{
|
||||||
unsigned int track;
|
unsigned int track;
|
||||||
|
@ -115,7 +84,7 @@ void audio_init(int *argc, char ***argv, struct audio_ops *ops)
|
||||||
void audio_deinit()
|
void audio_deinit()
|
||||||
{
|
{
|
||||||
gst_element_set_state(audio_player, GST_STATE_NULL);
|
gst_element_set_state(audio_player, GST_STATE_NULL);
|
||||||
gst_object_unref(audio_player);
|
gst_object_unref(GST_ELEMENT(audio_player));
|
||||||
|
|
||||||
audio_player = NULL;
|
audio_player = NULL;
|
||||||
audio_track = NULL;
|
audio_track = NULL;
|
||||||
|
@ -203,12 +172,7 @@ int64_t audio_duration()
|
||||||
|
|
||||||
struct track *audio_next()
|
struct track *audio_next()
|
||||||
{
|
{
|
||||||
struct track *track = tempq_next();
|
return __audio_next(audio_cur_state());
|
||||||
if (!track)
|
|
||||||
track = queue_next(collection_get_queue());
|
|
||||||
if (__audio_load(track, audio_cur_state()))
|
|
||||||
history_add(audio_track);
|
|
||||||
return track;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
struct track *audio_prev()
|
struct track *audio_prev()
|
||||||
|
@ -218,6 +182,23 @@ struct track *audio_prev()
|
||||||
return track;
|
return track;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
struct track *audio_eos()
|
||||||
|
{
|
||||||
|
/* Mark current track as played */
|
||||||
|
if (audio_track) {
|
||||||
|
track_played(audio_track);
|
||||||
|
queue_updated(collection_get_queue(), audio_track);
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Check pause count and pick the next track */
|
||||||
|
if (audio_pause_count >= 0) {
|
||||||
|
audio_pause_after(audio_pause_count - 1);
|
||||||
|
if (audio_pause_count == -1)
|
||||||
|
return __audio_next(GST_STATE_PAUSED);
|
||||||
|
}
|
||||||
|
return __audio_next(GST_STATE_PLAYING);
|
||||||
|
}
|
||||||
|
|
||||||
void audio_pause_after(int n)
|
void audio_pause_after(int n)
|
||||||
{
|
{
|
||||||
if (n != audio_pause_count) {
|
if (n != audio_pause_count) {
|
||||||
|
@ -226,11 +207,6 @@ void audio_pause_after(int n)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
AudioDriver *audio :: get_driver()
|
|
||||||
{
|
|
||||||
return cur_driver;
|
|
||||||
}
|
|
||||||
|
|
||||||
GstElement *audio_get_player()
|
GstElement *audio_get_player()
|
||||||
{
|
{
|
||||||
return audio_player;
|
return audio_player;
|
||||||
|
|
|
@ -80,8 +80,6 @@ static void on_config_pause(int n)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
class GSTDriver : public AudioDriver {} gst_driver;
|
|
||||||
|
|
||||||
struct audio_ops audio_ops = {
|
struct audio_ops audio_ops = {
|
||||||
on_load,
|
on_load,
|
||||||
on_config_pause,
|
on_config_pause,
|
||||||
|
@ -119,8 +117,7 @@ static gboolean on_gst_message(GstBus *bus, GstMessage *message, gpointer data)
|
||||||
gst :: play();
|
gst :: play();
|
||||||
break;
|
break;
|
||||||
case GST_MESSAGE_EOS:
|
case GST_MESSAGE_EOS:
|
||||||
gst_driver.eos();
|
audio_eos();
|
||||||
break;
|
|
||||||
default:
|
default:
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
|
@ -21,37 +21,6 @@ struct audio_ops {
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* The audio driver class gives us an interface for using multiple
|
|
||||||
* audio frameworks for audio playback.
|
|
||||||
*/
|
|
||||||
class AudioDriver {
|
|
||||||
public:
|
|
||||||
AudioDriver(); /**< Default AudioDriver constructor. */
|
|
||||||
virtual ~AudioDriver(); /**< AudioDriver destructor. */
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Called to handle reaching the end-of-stream.
|
|
||||||
*/
|
|
||||||
void eos();
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Namespace for higher-level audio controls.
|
|
||||||
*/
|
|
||||||
namespace audio
|
|
||||||
{
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Called to access an audio driver.
|
|
||||||
*
|
|
||||||
* @return The current driver used by the application.
|
|
||||||
*/
|
|
||||||
AudioDriver *get_driver();
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
/* Called to initialize the audio manager. */
|
/* Called to initialize the audio manager. */
|
||||||
void audio_init(int *, char ***, struct audio_ops *);
|
void audio_init(int *, char ***, struct audio_ops *);
|
||||||
|
|
||||||
|
@ -94,6 +63,9 @@ struct track *audio_next();
|
||||||
/* Called to load the previous track. */
|
/* Called to load the previous track. */
|
||||||
struct track *audio_prev();
|
struct track *audio_prev();
|
||||||
|
|
||||||
|
/* Called when playback has reached the end-of-stream position. */
|
||||||
|
struct track *audio_eos();
|
||||||
|
|
||||||
/* Called to configure automatic pausing. */
|
/* Called to configure automatic pausing. */
|
||||||
void audio_pause_after(int);
|
void audio_pause_after(int);
|
||||||
|
|
||||||
|
|
|
@ -11,7 +11,6 @@ extern "C" {
|
||||||
#include <core/core.h>
|
#include <core/core.h>
|
||||||
#include "test.h"
|
#include "test.h"
|
||||||
|
|
||||||
struct track *TRACK_NULL = NULL;
|
|
||||||
static unsigned int load_count = 0;
|
static unsigned int load_count = 0;
|
||||||
static int pause_count = 0;
|
static int pause_count = 0;
|
||||||
|
|
||||||
|
@ -26,17 +25,6 @@ static bool test_audio_seek(gint64 pos)
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
class TestDriver : public AudioDriver
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
bool playing;
|
|
||||||
std::string cur_file;
|
|
||||||
|
|
||||||
TestDriver() : playing(false) {}
|
|
||||||
~TestDriver() {};
|
|
||||||
bool is_playing() { return playing; }
|
|
||||||
} driver;
|
|
||||||
|
|
||||||
static void test_audio_load(struct track *track, GstState state)
|
static void test_audio_load(struct track *track, GstState state)
|
||||||
{
|
{
|
||||||
load_count++;
|
load_count++;
|
||||||
|
@ -196,7 +184,6 @@ static void test_prev()
|
||||||
|
|
||||||
void test_autopause()
|
void test_autopause()
|
||||||
{
|
{
|
||||||
TestDriver *driver = (TestDriver *)audio :: get_driver();
|
|
||||||
struct queue *history_q = history_get_queue();
|
struct queue *history_q = history_get_queue();
|
||||||
int i;
|
int i;
|
||||||
|
|
||||||
|
@ -214,13 +201,13 @@ void test_autopause()
|
||||||
test_equal(pause_count, 5);
|
test_equal(pause_count, 5);
|
||||||
|
|
||||||
for (i = 4; i > -1; i--) {
|
for (i = 4; i > -1; i--) {
|
||||||
driver->eos();
|
audio_eos();
|
||||||
test_loop_equal(pause_count, i, i);
|
test_loop_equal(pause_count, i, i);
|
||||||
test_loop_equal(audio_cur_state(), GST_STATE_PLAYING, i);
|
test_loop_equal(audio_cur_state(), GST_STATE_PLAYING, i);
|
||||||
test_loop_equal(queue_at(history_q, 0), audio_cur_track(), i);
|
test_loop_equal(queue_at(history_q, 0), audio_cur_track(), i);
|
||||||
} test_loop_passed();
|
} test_loop_passed();
|
||||||
|
|
||||||
driver->eos();
|
audio_eos();
|
||||||
test_equal(pause_count, -1);
|
test_equal(pause_count, -1);
|
||||||
test_not_equal(audio_cur_state(), GST_STATE_PLAYING);
|
test_not_equal(audio_cur_state(), GST_STATE_PLAYING);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue