Implemented seeking to an arbitrary time point in the session file.


git-svn-id: svn://svn.code.sf.net/p/tigervnc/code/trunk@2511 3789f03b-4d11-0410-bbf8-ca57d06f2519
diff --git a/java/src/com/tightvnc/rfbplayer/FbsInputStream.java b/java/src/com/tightvnc/rfbplayer/FbsInputStream.java
index f35219d..f5aeb2d 100644
--- a/java/src/com/tightvnc/rfbplayer/FbsInputStream.java
+++ b/java/src/com/tightvnc/rfbplayer/FbsInputStream.java
@@ -28,6 +28,7 @@
   protected InputStream in;
   protected long startTime;
   protected long timeOffset;
+  protected long seekOffset;
   protected boolean paused;
 
   protected byte[] buffer;
@@ -51,6 +52,7 @@
     this.in = in;
     startTime = System.currentTimeMillis();
     timeOffset = 0;
+    seekOffset = -1;
     paused = false;
 
     byte[] b = new byte[12];
@@ -97,6 +99,7 @@
     in = null;
     startTime = -1;
     timeOffset = 0;
+    seekOffset = -1;
     paused = false;
 
     buffer = null;
@@ -113,13 +116,17 @@
     return timeOffset;
   }
 
-  public void setTimeOffset(int pos)
+  public synchronized void setTimeOffset(int pos)
   {
+    // FIXME: Seeking works only in paused mode.
+    paused = true;
+    seekOffset = pos;
+    notify();
   }
 
   public boolean isSeeking()
   {
-    return false;
+    return (seekOffset >= 0);
   }
 
   public synchronized void pausePlayback()
@@ -160,6 +167,13 @@
       return false;
     }
 
+    if (seekOffset >= 0) {
+      if (timeOffset >= seekOffset) {
+	seekOffset = -1;
+      }
+      return true;
+    }
+
     while (true) {
       long timeDiff = startTime + timeOffset - System.currentTimeMillis();
       if (timeDiff <= 0) {
@@ -183,7 +197,7 @@
 
   private void waitWhilePaused()
   {
-    while (paused) {
+    while (paused && !isSeeking()) {
       synchronized(this) {
 	try {
 	  wait();
diff --git a/java/src/com/tightvnc/rfbplayer/VncCanvas.java b/java/src/com/tightvnc/rfbplayer/VncCanvas.java
index fa4bde7..6332532 100644
--- a/java/src/com/tightvnc/rfbplayer/VncCanvas.java
+++ b/java/src/com/tightvnc/rfbplayer/VncCanvas.java
@@ -60,6 +60,11 @@
   // which decodes and loads JPEG images.
   Rectangle jpegRect;
 
+  // When we're in the seeking mode, we should not update the desktop. 
+  // This variable helps us to remember that repainting the desktop at
+  // once is necessary when the seek operation is finished.
+  boolean seekMode;
+
   //
   // The constructor.
   //
@@ -67,6 +72,7 @@
   VncCanvas(RfbPlayer player) throws IOException {
     this.player = player;
     rfb = player.rfb;
+    seekMode = false;
 
     cm24 = new DirectColorModel(24, 0xFF0000, 0x00FF00, 0x0000FF);
 
@@ -809,9 +815,19 @@
   //
 
   void scheduleRepaint(int x, int y, int w, int h) {
-    // Request repaint if not in the seeking mode.
-    if (!player.fbsStream.isSeeking())
-      repaint(player.deferScreenUpdates, x, y, w, h);
+    if (player.fbsStream.isSeeking()) {
+      // Do nothing, and remember we are seeking.
+      seekMode = true;
+    } else {
+      if (seekMode) {
+	// Full-screen immediate repaint after seeking.
+	repaint();
+      } else {
+	// Usual incremental repaint in playback mode.
+	repaint(player.deferScreenUpdates, x, y, w, h);
+      }
+      seekMode = false;
+    }
   }
 
 }