core/audio: audio_{load, next, prev}() should start playback
The GUI needed an extra function to do this manually, which means it's something that core should do instead. Signed-off-by: Anna Schumaker <Anna@OcarinaProject.net>
This commit is contained in:
parent
0cf5187867
commit
ece432bb22
10
core/audio.c
10
core/audio.c
|
@ -99,7 +99,7 @@ void audio_init(int *argc, char ***argv, struct audio_ops *ops)
|
||||||
if (file_open(&audio_file, OPEN_READ)) {
|
if (file_open(&audio_file, OPEN_READ)) {
|
||||||
file_readf(&audio_file, "%u", &track);
|
file_readf(&audio_file, "%u", &track);
|
||||||
file_close(&audio_file);
|
file_close(&audio_file);
|
||||||
audio_load(track_get(track));
|
__audio_load(track_get(track), GST_STATE_PAUSED);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -119,7 +119,7 @@ bool audio_load(struct track *track)
|
||||||
{
|
{
|
||||||
if (track == audio_track)
|
if (track == audio_track)
|
||||||
return false;
|
return false;
|
||||||
if (__audio_load(track, audio_cur_state())) {
|
if (__audio_load(track, GST_STATE_PLAYING)) {
|
||||||
history_add(audio_track);
|
history_add(audio_track);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
@ -195,13 +195,13 @@ int64_t audio_duration()
|
||||||
|
|
||||||
struct track *audio_next()
|
struct track *audio_next()
|
||||||
{
|
{
|
||||||
return __audio_next(audio_cur_state());
|
return __audio_next(GST_STATE_PLAYING);
|
||||||
}
|
}
|
||||||
|
|
||||||
struct track *audio_prev()
|
struct track *audio_prev()
|
||||||
{
|
{
|
||||||
struct track *track = history_prev();
|
struct track *track = history_prev();
|
||||||
__audio_load(track, audio_cur_state());
|
__audio_load(track, GST_STATE_PLAYING);
|
||||||
return track;
|
return track;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -238,7 +238,7 @@ void audio_error(GstMessage *error)
|
||||||
if (debug)
|
if (debug)
|
||||||
g_print("Debug details: %s\n", debug);
|
g_print("Debug details: %s\n", debug);
|
||||||
|
|
||||||
audio_next();
|
__audio_next(audio_cur_state());
|
||||||
|
|
||||||
g_error_free(err);
|
g_error_free(err);
|
||||||
g_free(debug);
|
g_free(debug);
|
||||||
|
|
15
gui/gst.cpp
15
gui/gst.cpp
|
@ -117,22 +117,11 @@ static bool on_timeout()
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
void gst :: play() { audio_play(); }
|
void gst :: play() { audio_play(); }
|
||||||
void gst :: pause() { audio_pause(); }
|
void gst :: pause() { audio_pause(); }
|
||||||
void gst :: stop() { audio_stop(); }
|
void gst :: stop() { audio_stop(); }
|
||||||
|
void gst :: next() { audio_next(); }
|
||||||
void gst :: next()
|
void gst :: prev() { audio_prev(); }
|
||||||
{
|
|
||||||
audio_next();
|
|
||||||
gst :: play();
|
|
||||||
}
|
|
||||||
|
|
||||||
void gst :: prev()
|
|
||||||
{
|
|
||||||
audio_prev();
|
|
||||||
}
|
|
||||||
|
|
||||||
void gst :: toggle()
|
void gst :: toggle()
|
||||||
{
|
{
|
||||||
|
|
|
@ -31,7 +31,7 @@ static void test_send_error()
|
||||||
|
|
||||||
error = g_error_new(1, G_FILE_ERROR_BADF, "Simulated Error");
|
error = g_error_new(1, G_FILE_ERROR_BADF, "Simulated Error");
|
||||||
message = gst_message_new_error(GST_OBJECT(test_audio_player()),
|
message = gst_message_new_error(GST_OBJECT(test_audio_player()),
|
||||||
error, "Error generated for testing");
|
error, "Fake error for testing");
|
||||||
audio_error(message);
|
audio_error(message);
|
||||||
|
|
||||||
gst_message_unref(message);
|
gst_message_unref(message);
|
||||||
|
@ -91,29 +91,19 @@ static void test_init()
|
||||||
|
|
||||||
static void test_playback()
|
static void test_playback()
|
||||||
{
|
{
|
||||||
test_equal(audio_load(track_get(0)), (bool)true);
|
struct track *tracks[3] = { track_get(0), NULL, track_get(0) };
|
||||||
test_equal(load_count, 1);
|
unsigned int i;
|
||||||
test_equal(state_count, 0);
|
|
||||||
test_equal((void *)audio_cur_track(), (void *)track_get(0));
|
|
||||||
test_equal(audio_cur_state(), GST_STATE_NULL);
|
|
||||||
test_equal(queue_size(history_get_queue()), 1);
|
|
||||||
test_equal(audio_duration(), track_get(0)->tr_length * GST_SECOND);
|
|
||||||
|
|
||||||
test_equal(audio_load(NULL), (bool)false);
|
for (i = 0; i < 3; i++) {
|
||||||
test_equal(load_count, 1);
|
test_loop_equal(audio_load(tracks[i]), (bool)(i == 0), i);
|
||||||
test_equal(state_count, 0);
|
test_loop_equal(queue_size(history_get_queue()), 1, i);
|
||||||
test_equal((void *)audio_cur_track(), (void *)track_get(0));
|
test_loop_equal(load_count, 1, i);
|
||||||
test_equal(queue_size(history_get_queue()), 1);
|
test_loop_equal(state_count, 1, i);
|
||||||
|
test_loop_equal(audio_cur_state(), GST_STATE_PLAYING, i);
|
||||||
test_equal(audio_load(track_get(0)), (bool)false);
|
test_loop_equal((void *)audio_cur_track(), (void *)tracks[0], i);
|
||||||
test_equal(load_count, 1);
|
test_loop_equal(audio_duration(),
|
||||||
test_equal(state_count, 0);
|
tracks[0]->tr_length * GST_SECOND, i);
|
||||||
test_equal(queue_size(history_get_queue()), 1);
|
} test_loop_passed();
|
||||||
|
|
||||||
test_equal(audio_play(), (bool)true);
|
|
||||||
test_equal(audio_play(), (bool)false);
|
|
||||||
test_equal(state_count, 1);
|
|
||||||
test_equal(audio_cur_state(), GST_STATE_PLAYING);
|
|
||||||
|
|
||||||
test_equal(audio_pause(), (bool)true);
|
test_equal(audio_pause(), (bool)true);
|
||||||
test_equal(audio_pause(), (bool)false);
|
test_equal(audio_pause(), (bool)false);
|
||||||
|
@ -132,6 +122,7 @@ static void test_playback()
|
||||||
test_equal(audio_position(), 42 * GST_SECOND);
|
test_equal(audio_position(), 42 * GST_SECOND);
|
||||||
|
|
||||||
test_equal(audio_play(), (bool)true);
|
test_equal(audio_play(), (bool)true);
|
||||||
|
test_equal(audio_play(), (bool)false);
|
||||||
test_equal(state_count, 3);
|
test_equal(state_count, 3);
|
||||||
test_equal(audio_stop(), (bool)true);
|
test_equal(audio_stop(), (bool)true);
|
||||||
test_equal(state_count, 4);
|
test_equal(state_count, 4);
|
||||||
|
@ -162,7 +153,7 @@ static void test_next()
|
||||||
test_send_error();
|
test_send_error();
|
||||||
test_loop_equal((void *)queue_at(history_q, 0),
|
test_loop_equal((void *)queue_at(history_q, 0),
|
||||||
(void *)track_get(i), i);
|
(void *)track_get(i), i);
|
||||||
test_loop_equal(audio_cur_state(), GST_STATE_PAUSED, i);
|
test_loop_equal(audio_cur_state(), GST_STATE_PLAYING, i);
|
||||||
test_loop_equal((void *)audio_cur_track(),
|
test_loop_equal((void *)audio_cur_track(),
|
||||||
(void *)track_get(i), i);
|
(void *)track_get(i), i);
|
||||||
} test_loop_passed();
|
} test_loop_passed();
|
||||||
|
@ -170,7 +161,6 @@ static void test_next()
|
||||||
test_equal((void *)tempq_get(0), NULL);
|
test_equal((void *)tempq_get(0), NULL);
|
||||||
|
|
||||||
/* Tracks should now be picked from the collection. */
|
/* Tracks should now be picked from the collection. */
|
||||||
test_equal(audio_play(), (bool)true);
|
|
||||||
for (i = 1; i <= 3; i++) {
|
for (i = 1; i <= 3; i++) {
|
||||||
if (i < 3) {
|
if (i < 3) {
|
||||||
test_loop_equal(audio_next()->tr_track, i, i);
|
test_loop_equal(audio_next()->tr_track, i, i);
|
||||||
|
@ -180,7 +170,7 @@ static void test_next()
|
||||||
test_loop_equal(audio_cur_state(), GST_STATE_PLAYING, i);
|
test_loop_equal(audio_cur_state(), GST_STATE_PLAYING, i);
|
||||||
test_loop_equal(audio_cur_track()->tr_track, i, i);
|
test_loop_equal(audio_cur_track()->tr_track, i, i);
|
||||||
} test_loop_passed();
|
} test_loop_passed();
|
||||||
test_equal(state_count, 7);
|
test_equal(state_count, 6);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void test_prev()
|
static void test_prev()
|
||||||
|
@ -204,19 +194,19 @@ static void test_prev()
|
||||||
test_equal(audio_pause(), (bool)true);
|
test_equal(audio_pause(), (bool)true);
|
||||||
test_equal(audio_prev()->tr_dbe.dbe_index, 0);
|
test_equal(audio_prev()->tr_dbe.dbe_index, 0);
|
||||||
test_equal((void *)queue_at(history_q, 0), (void *)track);
|
test_equal((void *)queue_at(history_q, 0), (void *)track);
|
||||||
test_equal(audio_cur_state(), GST_STATE_PAUSED);
|
test_equal(audio_cur_state(), GST_STATE_PLAYING);
|
||||||
test_equal(audio_cur_track()->tr_dbe.dbe_index, 0);
|
test_equal(audio_cur_track()->tr_dbe.dbe_index, 0);
|
||||||
test_equal(state_count, 4);
|
test_equal(state_count, 4);
|
||||||
|
|
||||||
test_equal(audio_prev()->tr_dbe.dbe_index, 1);
|
test_equal(audio_prev()->tr_dbe.dbe_index, 1);
|
||||||
test_equal((void *)queue_at(history_q, 0), (void *)track);
|
test_equal((void *)queue_at(history_q, 0), (void *)track);
|
||||||
test_equal(audio_cur_state(), GST_STATE_PAUSED);
|
test_equal(audio_cur_state(), GST_STATE_PLAYING);
|
||||||
test_equal(audio_cur_track()->tr_dbe.dbe_index, 1);
|
test_equal(audio_cur_track()->tr_dbe.dbe_index, 1);
|
||||||
test_equal(state_count, 5);
|
test_equal(state_count, 5);
|
||||||
|
|
||||||
test_equal(audio_prev()->tr_dbe.dbe_index, 2);
|
test_equal(audio_prev()->tr_dbe.dbe_index, 2);
|
||||||
test_equal((void *)queue_at(history_q, 0), (void *)track);
|
test_equal((void *)queue_at(history_q, 0), (void *)track);
|
||||||
test_equal(audio_cur_state(), GST_STATE_PAUSED);
|
test_equal(audio_cur_state(), GST_STATE_PLAYING);
|
||||||
test_equal(audio_cur_track()->tr_dbe.dbe_index, 2);
|
test_equal(audio_cur_track()->tr_dbe.dbe_index, 2);
|
||||||
test_equal(state_count, 6);
|
test_equal(state_count, 6);
|
||||||
}
|
}
|
||||||
|
@ -226,9 +216,6 @@ void test_autopause()
|
||||||
struct queue *history_q = history_get_queue();
|
struct queue *history_q = history_get_queue();
|
||||||
int i;
|
int i;
|
||||||
|
|
||||||
test_equal(audio_play(), (bool)true);
|
|
||||||
test_equal(pause_count, 0);
|
|
||||||
|
|
||||||
audio_pause_after(3);
|
audio_pause_after(3);
|
||||||
test_equal(pause_count, 3);
|
test_equal(pause_count, 3);
|
||||||
|
|
||||||
|
@ -251,7 +238,11 @@ void test_autopause()
|
||||||
|
|
||||||
audio_eos();
|
audio_eos();
|
||||||
test_equal(pause_count, -1);
|
test_equal(pause_count, -1);
|
||||||
test_not_equal(audio_cur_state(), GST_STATE_PLAYING);
|
test_equal(audio_cur_state(), GST_STATE_PAUSED);
|
||||||
|
test_equal(state_count, 6);
|
||||||
|
|
||||||
|
test_send_error();
|
||||||
|
test_equal(audio_cur_state(), GST_STATE_PAUSED);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void test_deinit()
|
static void test_deinit()
|
||||||
|
|
Loading…
Reference in New Issue