changeset 2999:e2e8f927a08a

Patch from John Lindgren <john.lindgren@tds.net> to support seeking whilst paused, Debian bug #517692.
author Tony Vroon <chainsaw@gentoo.org>
date Wed, 04 Mar 2009 12:48:20 +0000
parents fc666525b410
children b13c904dcd40
files src/sndfile/plugin.c
diffstat 1 files changed, 23 insertions(+), 8 deletions(-) [+]
line wrap: on
line diff
--- a/src/sndfile/plugin.c	Wed Mar 04 12:48:09 2009 +0000
+++ b/src/sndfile/plugin.c	Wed Mar 04 12:48:20 2009 +0000
@@ -47,6 +47,7 @@
 static gint song_length;
 static gint bit_rate = 0;
 static glong seek_time = -1;
+static volatile char pause_flag;
 
 static GThread *decode_thread;
 static GMutex *decode_mutex;
@@ -121,6 +122,7 @@
 plugin_init (void)
 {
     seek_time = -1;
+    pause_flag = 0;
 
     decode_mutex = g_mutex_new();
     decode_cond = g_cond_new();
@@ -364,6 +366,22 @@
     return TRUE;
 }
 
+static void do_seek (InputPlayback * playback) {
+   playback->output->flush (seek_time);
+   sf_seek (sndfile, (long long) seek_time * sfinfo.samplerate / 1000, SEEK_SET);
+   seek_time = -1;
+}
+
+static void do_pause (InputPlayback * playback) {
+   playback->output->pause (1);
+   while (pause_flag) {
+      if (seek_time != -1)
+         do_seek (playback);
+      g_usleep(50000);
+   }
+   playback->output->pause (0);
+}
+
 static gpointer
 play_loop (gpointer arg)
 {
@@ -413,13 +431,10 @@
             break;
         }
 
-        /* Do seek if seek_time is valid. */
-        if (seek_time >= 0) {
-            sf_seek (sndfile, (sf_count_t)((gint64)seek_time * (gint64)sfinfo.samplerate / 1000L),
-                     SEEK_SET);
-            playback->output->flush (seek_time);
-            seek_time = -1;
-        }
+        if (seek_time != -1)
+           do_seek (playback);
+        if (pause_flag)
+           do_pause (playback);
 
         if (playback->playing == FALSE)
             break;
@@ -479,7 +494,7 @@
 static void
 play_pause (InputPlayback *playback, gshort p)
 {
-    playback->output->pause(p);
+   pause_flag = p;
 }
 
 static void