From 1d76990fd14e328a48e9e4ebbb3cdefdfedca551 Mon Sep 17 00:00:00 2001 From: Anna Schumaker Date: Thu, 17 Dec 2015 09:17:25 -0500 Subject: [PATCH] core/audio: Add audio_error() to handle error messages Signed-off-by: Anna Schumaker --- core/audio.cpp | 20 ++++++++++++++++++++ include/core/audio.h | 3 +++ tests/core/audio.cpp | 28 +++++++++++++++++++++++++--- 3 files changed, 48 insertions(+), 3 deletions(-) diff --git a/core/audio.cpp b/core/audio.cpp index c5b1190c..6259d6a6 100644 --- a/core/audio.cpp +++ b/core/audio.cpp @@ -199,6 +199,26 @@ struct track *audio_eos() return __audio_next(GST_STATE_PLAYING); } +void audio_error(GstMessage *error) +{ + gchar *path = NULL, *debug = NULL; + GError *err = NULL; + + if (audio_track) + path = track_path(audio_track); + if (error) + gst_message_parse_error(error, &err, &debug); + + g_print("Error: %s (%s)\n", err->message, path); + if (debug) + g_print("Debug details: %s\n", debug); + audio_next(); + + g_error_free(err); + g_free(debug); + g_free(path); +} + void audio_pause_after(int n) { if (n != audio_pause_count) { diff --git a/include/core/audio.h b/include/core/audio.h index ce3cfe45..41922ccd 100644 --- a/include/core/audio.h +++ b/include/core/audio.h @@ -66,6 +66,9 @@ struct track *audio_prev(); /* Called when playback has reached the end-of-stream position. */ struct track *audio_eos(); +/* Called when gstreamer has received an error. */ +void audio_error(GstMessage *); + /* Called to configure automatic pausing. */ void audio_pause_after(int); diff --git a/tests/core/audio.cpp b/tests/core/audio.cpp index 2e15b97a..062bef47 100644 --- a/tests/core/audio.cpp +++ b/tests/core/audio.cpp @@ -25,6 +25,21 @@ static bool test_audio_seek(gint64 pos) return ret; } +static void test_send_error() +{ + GstMessage *message; + GError *error; + + error = g_error_new(1, G_FILE_ERROR_BADF, "Simulated Error"); + message = gst_message_new_error(GST_OBJECT(audio_get_player()), + error, "Error generated for testing"); + audio_error(message); + + gst_message_unref(message); + g_error_free(error); + +} + static void test_audio_load(struct track *track, GstState state) { load_count++; @@ -58,6 +73,7 @@ static void test_init() test_equal(audio_load(NULL), false); test_equal(audio_next(), NULL); test_equal(audio_prev(), NULL); + test_send_error(); test_equal(audio_play(), false); test_equal(audio_pause(), false); test_equal(audio_stop(), false); @@ -133,17 +149,23 @@ static void test_next() for (i = 2; i >= 0; i--) { test_loop_equal(queue_size(temp_q), i + 1, i); - test_loop_equal(audio_next()->tr_dbe.dbe_index, i, i); + if (i > 0) { + test_loop_equal(audio_next()->tr_dbe.dbe_index, i, i); + } else /* Simulate an error. */ + test_send_error(); test_loop_equal(queue_at(history_q, 0), track_get(i), i); test_loop_equal(audio_cur_state(), GST_STATE_PAUSED, i); test_loop_equal(audio_cur_track(), track_get(i), i); } test_loop_passed(); test_equal(tempq_get(0), NULL); - test_equal(audio_play(), true); /* Tracks should now be picked from the collection. */ + test_equal(audio_play(), true); for (i = 1; i <= 3; i++) { - test_loop_equal(audio_next()->tr_track, i, i); + if (i < 3) { + test_loop_equal(audio_next()->tr_track, i, i); + } else /* Simulate an error. */ + test_send_error(); test_loop_equal(queue_at(history_q, 0)->tr_track, i, i); test_loop_equal(audio_cur_state(), GST_STATE_PLAYING, i); test_loop_equal(audio_cur_track()->tr_track, i, i);