From ece432bb22f34b0b8c233ad7b5e723e03636855f Mon Sep 17 00:00:00 2001 From: Anna Schumaker Date: Fri, 18 Dec 2015 08:34:42 -0500 Subject: [PATCH] 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 --- core/audio.c | 10 ++++---- gui/gst.cpp | 15 ++---------- tests/core/audio.c | 57 +++++++++++++++++++--------------------------- 3 files changed, 31 insertions(+), 51 deletions(-) diff --git a/core/audio.c b/core/audio.c index 86117a14..99210f1f 100644 --- a/core/audio.c +++ b/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)) { file_readf(&audio_file, "%u", &track); 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) return false; - if (__audio_load(track, audio_cur_state())) { + if (__audio_load(track, GST_STATE_PLAYING)) { history_add(audio_track); return true; } @@ -195,13 +195,13 @@ int64_t audio_duration() struct track *audio_next() { - return __audio_next(audio_cur_state()); + return __audio_next(GST_STATE_PLAYING); } struct track *audio_prev() { struct track *track = history_prev(); - __audio_load(track, audio_cur_state()); + __audio_load(track, GST_STATE_PLAYING); return track; } @@ -238,7 +238,7 @@ void audio_error(GstMessage *error) if (debug) g_print("Debug details: %s\n", debug); - audio_next(); + __audio_next(audio_cur_state()); g_error_free(err); g_free(debug); diff --git a/gui/gst.cpp b/gui/gst.cpp index 9ce4b684..f2140a42 100644 --- a/gui/gst.cpp +++ b/gui/gst.cpp @@ -117,22 +117,11 @@ static bool on_timeout() return true; } - - void gst :: play() { audio_play(); } void gst :: pause() { audio_pause(); } void gst :: stop() { audio_stop(); } - -void gst :: next() -{ - audio_next(); - gst :: play(); -} - -void gst :: prev() -{ - audio_prev(); -} +void gst :: next() { audio_next(); } +void gst :: prev() { audio_prev(); } void gst :: toggle() { diff --git a/tests/core/audio.c b/tests/core/audio.c index 93368e93..ec33aa27 100644 --- a/tests/core/audio.c +++ b/tests/core/audio.c @@ -31,7 +31,7 @@ static void test_send_error() error = g_error_new(1, G_FILE_ERROR_BADF, "Simulated Error"); message = gst_message_new_error(GST_OBJECT(test_audio_player()), - error, "Error generated for testing"); + error, "Fake error for testing"); audio_error(message); gst_message_unref(message); @@ -91,29 +91,19 @@ static void test_init() static void test_playback() { - test_equal(audio_load(track_get(0)), (bool)true); - test_equal(load_count, 1); - 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); + struct track *tracks[3] = { track_get(0), NULL, track_get(0) }; + unsigned int i; - test_equal(audio_load(NULL), (bool)false); - test_equal(load_count, 1); - test_equal(state_count, 0); - test_equal((void *)audio_cur_track(), (void *)track_get(0)); - test_equal(queue_size(history_get_queue()), 1); - - test_equal(audio_load(track_get(0)), (bool)false); - test_equal(load_count, 1); - test_equal(state_count, 0); - test_equal(queue_size(history_get_queue()), 1); - - 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); + for (i = 0; i < 3; i++) { + test_loop_equal(audio_load(tracks[i]), (bool)(i == 0), i); + test_loop_equal(queue_size(history_get_queue()), 1, i); + test_loop_equal(load_count, 1, i); + test_loop_equal(state_count, 1, i); + test_loop_equal(audio_cur_state(), GST_STATE_PLAYING, i); + test_loop_equal((void *)audio_cur_track(), (void *)tracks[0], i); + test_loop_equal(audio_duration(), + tracks[0]->tr_length * GST_SECOND, i); + } test_loop_passed(); test_equal(audio_pause(), (bool)true); test_equal(audio_pause(), (bool)false); @@ -132,6 +122,7 @@ static void test_playback() test_equal(audio_position(), 42 * GST_SECOND); test_equal(audio_play(), (bool)true); + test_equal(audio_play(), (bool)false); test_equal(state_count, 3); test_equal(audio_stop(), (bool)true); test_equal(state_count, 4); @@ -162,7 +153,7 @@ static void test_next() test_send_error(); test_loop_equal((void *)queue_at(history_q, 0), (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(), (void *)track_get(i), i); } test_loop_passed(); @@ -170,7 +161,6 @@ static void test_next() test_equal((void *)tempq_get(0), NULL); /* Tracks should now be picked from the collection. */ - test_equal(audio_play(), (bool)true); for (i = 1; i <= 3; i++) { if (i < 3) { 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_track()->tr_track, i, i); } test_loop_passed(); - test_equal(state_count, 7); + test_equal(state_count, 6); } static void test_prev() @@ -204,19 +194,19 @@ static void test_prev() test_equal(audio_pause(), (bool)true); test_equal(audio_prev()->tr_dbe.dbe_index, 0); 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(state_count, 4); test_equal(audio_prev()->tr_dbe.dbe_index, 1); 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(state_count, 5); test_equal(audio_prev()->tr_dbe.dbe_index, 2); 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(state_count, 6); } @@ -226,9 +216,6 @@ void test_autopause() struct queue *history_q = history_get_queue(); int i; - test_equal(audio_play(), (bool)true); - test_equal(pause_count, 0); - audio_pause_after(3); test_equal(pause_count, 3); @@ -251,7 +238,11 @@ void test_autopause() audio_eos(); 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()