From 279d6e02286f7e8dec2c2fda18a4d10f57a05bed Mon Sep 17 00:00:00 2001 From: Anna Schumaker Date: Wed, 24 Feb 2016 08:18:04 -0500 Subject: [PATCH] core/audio: Load initial track through an idle task Let's save this disk access for when we're idle. Implements #11: Load initial track through an idle task Signed-off-by: Anna Schumaker --- core/audio.c | 22 ++++++++++++++-------- tests/gui/collection.c | 1 + tests/gui/idle.c | 1 + 3 files changed, 16 insertions(+), 8 deletions(-) diff --git a/core/audio.c b/core/audio.c index 2e1e55c9..b8cae084 100644 --- a/core/audio.c +++ b/core/audio.c @@ -4,9 +4,10 @@ #include #include #include +#include #include -static struct file audio_file; +static struct file audio_file = FILE_INIT("cur_track", 0); static struct track *audio_track = NULL; static GstElement *audio_player = NULL; static struct audio_ops *audio_ops = NULL; @@ -92,10 +93,20 @@ static gboolean __audio_message(GstBus *bus, GstMessage *message, gpointer data) return true; } +static void __audio_init_idle(void *data) +{ + unsigned int track; + + if (file_open(&audio_file, OPEN_READ)) { + file_readf(&audio_file, "%u", &track); + file_close(&audio_file); + __audio_load(track_get(track), GST_STATE_PAUSED); + } +} + void audio_init(int *argc, char ***argv, struct audio_ops *ops) { - unsigned int track; GstBus *bus; gst_init(argc, argv); @@ -106,12 +117,7 @@ void audio_init(int *argc, char ***argv, struct audio_ops *ops) audio_bus = gst_bus_add_watch(bus, __audio_message, NULL); gst_object_unref(bus); - file_init(&audio_file, "cur_track", 0); - if (file_open(&audio_file, OPEN_READ)) { - file_readf(&audio_file, "%u", &track); - file_close(&audio_file); - __audio_load(track_get(track), GST_STATE_PAUSED); - } + idle_schedule(__audio_init_idle, NULL); } void audio_deinit() diff --git a/tests/gui/collection.c b/tests/gui/collection.c index b0c72045..4d297c9f 100644 --- a/tests/gui/collection.c +++ b/tests/gui/collection.c @@ -39,6 +39,7 @@ static void test_collection_sidebar() core_init(&argc, NULL, &init_data); gui_view_init(); gui_collection_init(); + while (idle_run_task()) {} main_loop = g_main_loop_new(NULL, FALSE); window = GTK_WINDOW(gui_builder_widget("o_window")); diff --git a/tests/gui/idle.c b/tests/gui/idle.c index caac2a62..02a1e6e2 100644 --- a/tests/gui/idle.c +++ b/tests/gui/idle.c @@ -42,6 +42,7 @@ static void test_idle() gtk_init(&argc, NULL); gui_builder_init("share/ocarina/ocarina6.glade"); core_init(&argc, NULL, &init_data); + while (idle_run_task()) {} main_loop = g_main_loop_new(NULL, FALSE); window = GTK_WINDOW(gui_builder_widget("o_window"));