diff src/audacious/playback.c @ 3089:f40b8491a812

Remove genevent, seperate playback logic into seperate control thread. This still has bugs, so watch out.
author William Pitcock <nenolod@atheme-project.org>
date Mon, 16 Jul 2007 15:50:32 -0500
parents 20830a69b5f5
children 29d3abbbe0a2 1ddeb9f068ab
line wrap: on
line diff
--- a/src/audacious/playback.c	Mon Jul 16 13:43:37 2007 -0500
+++ b/src/audacious/playback.c	Mon Jul 16 15:50:32 2007 -0500
@@ -123,8 +123,6 @@
     }
 
     vis_playback_start();
-
-    hook_call("playback begin", entry);
 }
 
 void
@@ -158,29 +156,38 @@
 void
 playback_stop(void)
 {
-    if (ip_data.playing && get_current_input_playback()) {
+    InputPlayback *playback = get_current_input_playback();
 
-        if (playback_get_paused()) {
+    if (ip_data.playing && playback != NULL)
+    {
+        if (playback_get_paused())
+        {
             output_flush(get_written_time()); /* to avoid noise */
             playback_pause();
         }
 
         ip_data.playing = FALSE; 
 
-        if (get_current_input_playback()->plugin->stop)
-            get_current_input_playback()->plugin->stop(get_current_input_playback());
+        if (playback->plugin->stop)
+            playback->plugin->stop(playback);
 
         free_vis_data();
         ip_data.paused = FALSE;
 
-        if (input_info_text) {
+        if (input_info_text != NULL)
+        {
             g_free(input_info_text);
             input_info_text = NULL;
             mainwin_set_info_text();
         }
 
-	g_free(get_current_input_playback()->filename);
-	g_free(get_current_input_playback());
+        g_cond_signal(playback->playback_cond);
+        g_thread_join(playback->playback_control);
+        g_cond_free(playback->playback_cond);
+        g_mutex_free(playback->playback_mutex);
+
+	g_free(playback->filename);
+	g_free(playback);
 	set_current_input_playback(NULL);
     }
 
@@ -213,10 +220,37 @@
     gtk_widget_destroy(dialog);
 }
 
+static gpointer
+playback_control_thread(gpointer data)
+{
+    InputPlayback *playback = (InputPlayback *) data;
+    g_return_val_if_fail(playback != NULL, NULL);
+
+    ip_data.playing = TRUE;
+
+    playback->plugin->play_file(playback);
+
+    hook_call("playback begin", playback->entry);
+
+    while (ip_data.playing == TRUE && playback->eof == FALSE && playback->playing == TRUE)
+    {
+        GTimeVal tmwait;
+        g_get_current_time(&tmwait);
+        g_time_val_add(&tmwait, 1000000);
+        g_cond_timed_wait(playback->playback_cond, playback->playback_mutex, &tmwait);
+    }
+
+    ip_data.playing = FALSE;
+
+    hook_call("playback end", playback->entry);
+
+    return NULL;
+}
+
 gboolean
 playback_play_file(PlaylistEntry *entry)
 {
-    InputPlayback * playback;
+    InputPlayback *playback;
     g_return_val_if_fail(entry != NULL, FALSE);
 
     if (!get_current_output_plugin()) {
@@ -244,18 +278,17 @@
     }
 
     playback = g_new0(InputPlayback, 1);
+
+    set_current_input_playback(playback);
     
-    entry->decoder->output = &psuedo_output_plugin;
-
     playback->plugin = entry->decoder;
     playback->output = &psuedo_output_plugin;
+    playback->plugin->output = playback->output;
     playback->filename = g_strdup(entry->filename);
-    
-    set_current_input_playback(playback);
-
-    entry->decoder->play_file(playback);
-
-    ip_data.playing = TRUE;
+    playback->playback_mutex = g_mutex_new();
+    playback->playback_cond = g_cond_new();
+    playback->playback_control = g_thread_create(playback_control_thread, playback, TRUE, NULL);
+    playback->entry = entry;
 
     return TRUE;
 }