changeset 2375:22641735c9b1

- fixed freezing on track end - remember that buffer_free() returns _free_ space, not used.
author Eugene Zagidullin <e.asphyx@gmail.com>
date Sun, 10 Feb 2008 14:46:28 +0300
parents 47f6f73438c3
children e84c4ee208ca
files src/vorbis/vorbis.c
diffstat 1 files changed, 20 insertions(+), 18 deletions(-) [+]
line wrap: on
line diff
--- a/src/vorbis/vorbis.c	Sun Feb 10 07:32:37 2008 +0300
+++ b/src/vorbis/vorbis.c	Sun Feb 10 14:46:28 2008 +0300
@@ -34,8 +34,10 @@
  */
 
 #include "config.h"
-
+/*
+#define AUD_DEBUG
 #define DEBUG
+*/
 
 #define REMOVE_NONEXISTANT_TAG(x)   if (x != NULL && !*x) { x = NULL; }
 
@@ -360,15 +362,12 @@
            /*
             * EOF
             */
+            AUDDBG("EOF\n");
             playback->playing = 0;
-            playback->output->buffer_free();
-            playback->output->buffer_free();
             playback->eof = TRUE;
             current_section = last_section;
         }
 
-        
-
         if (current_section <= last_section) {
             /*
              * The info struct is different in each section.  vf
@@ -387,8 +386,7 @@
             if (vi->rate != samplerate || vi->channels != channels) {
                 samplerate = vi->rate;
                 channels = vi->channels;
-                playback->output->buffer_free();
-                playback->output->buffer_free();
+                while(playback->output->buffer_playing()) g_usleep(50000);
                 playback->output->close_audio();
                 if (!playback->output->
                         open_audio(FMT_FLOAT, vi->rate, vi->channels)) {
@@ -440,17 +438,20 @@
         }
     } /* main loop */
 
-    if (!playback->error)
-        playback->output->close_audio();
-    /* fall through intentional */
+    if (!playback->error) {
+        /*this loop makes it not skip the last ~4 seconds, but the playback 
+         * timer isn't updated in this period, so it still needs a bit of work 
+         *
+         * majeru
+         */
+        if(playback->eof) /* do it only on EOF --asphyx */
+            while(playback->output->buffer_playing()) {
+                AUDDBG("waiting for empty output buffer\n");
+                g_usleep(50000);
+            }
 
-    /*this loop makes it not skip the last ~4 seconds, but the playback 
-     * timer isn't updated in this period, so it still needs a bit of work 
-     *
-     * majeru
-     */
-    while(playback->output->buffer_playing()&& playback->output->buffer_free())
-        g_usleep(50000);
+        playback->output->close_audio();
+    }
 
 
     play_cleanup:
@@ -464,7 +465,6 @@
     ov_clear(&vf);
     g_mutex_unlock(vf_mutex);
     playback->playing = 0;
-    playback->output->buffer_free();
     return NULL;
 }
 
@@ -485,7 +485,9 @@
 {
     if (playback->playing) {
         playback->playing = 0;
+        AUDDBG("waiting for playback thread finished\n");
         g_thread_join(thread);
+        AUDDBG("playback finished\n");
     }
 }