core/audio: Add audio_error() to handle error messages

Signed-off-by: Anna Schumaker <Anna@OcarinaProject.net>
This commit is contained in:
Anna Schumaker 2015-12-17 09:17:25 -05:00
parent a5556ac10a
commit 1d76990fd1
3 changed files with 48 additions and 3 deletions

View File

@ -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) {

View File

@ -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);

View File

@ -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);