]> source.dussan.org Git - tigervnc.git/commitdiff
Implemented variable playback speed, adjustable using a text field.
authorConstantin Kaplinsky <const@tightvnc.com>
Thu, 30 May 2002 15:54:56 +0000 (15:54 +0000)
committerConstantin Kaplinsky <const@tightvnc.com>
Thu, 30 May 2002 15:54:56 +0000 (15:54 +0000)
git-svn-id: svn://svn.code.sf.net/p/tigervnc/code/trunk@2513 3789f03b-4d11-0410-bbf8-ca57d06f2519

java/src/com/tightvnc/rfbplayer/ButtonPanel.java
java/src/com/tightvnc/rfbplayer/FbsInputStream.java
java/src/com/tightvnc/rfbplayer/RfbPlayer.java

index 7a1e8884d8910d637b89e383923eae8fe639f2b4..222c519d12ef8238add2e82c451069ccbac46fb6 100644 (file)
@@ -48,8 +48,6 @@ class ButtonPanel extends Panel implements ActionListener {
     add(new Label(" Speed:"));
     timeScaleText = new TextField(5);
     timeScaleText.setText("1.0");
-    timeScaleText.setEnabled(false);
-    timeScaleText.setEditable(false);
     add(timeScaleText);
     timeScaleText.addActionListener(this);
   }
@@ -88,6 +86,8 @@ class ButtonPanel extends Panel implements ActionListener {
       player.setPaused(playButton.getLabel().equals("Pause"));
     } else if (evt.getSource() == posText) {
       player.setPos(Integer.parseInt(posText.getText()));
+    } else if (evt.getSource() == timeScaleText) {
+      player.setSpeed(Double.parseDouble(timeScaleText.getText()));
     }
   }
 }
index d47953ab0ac8190063a2802e08e230a70e62dd3c..7baa145fbca4cd55d6a0921cdf2f9fc9c75cf23e 100644 (file)
@@ -30,6 +30,7 @@ class FbsInputStream extends InputStream {
   protected long timeOffset;
   protected long seekOffset;
   protected boolean paused;
+  protected double playbackSpeed;
 
   protected byte[] buffer;
   protected int bufferSize;
@@ -54,6 +55,7 @@ class FbsInputStream extends InputStream {
     timeOffset = 0;
     seekOffset = -1;
     paused = false;
+    playbackSpeed = 1.0;
 
     byte[] b = new byte[12];
     readFully(b);
@@ -101,6 +103,7 @@ class FbsInputStream extends InputStream {
     timeOffset = 0;
     seekOffset = -1;
     paused = false;
+    playbackSpeed = 1.0;
 
     buffer = null;
     bufferSize = 0;
@@ -111,19 +114,29 @@ class FbsInputStream extends InputStream {
   // Methods providing additional functionality.
   //
 
-  public long getTimeOffset()
+  public synchronized long getTimeOffset()
   {
-    return timeOffset;
+    return (long)(timeOffset * playbackSpeed);
   }
 
   public synchronized void setTimeOffset(long pos)
   {
     // FIXME: Seeking works only in paused mode.
     paused = true;
-    seekOffset = pos;
+    seekOffset = (long)(pos / playbackSpeed);
     notify();
   }
 
+  public synchronized void setSpeed(double newSpeed)
+  {
+    timeOffset = (long)(timeOffset * playbackSpeed / newSpeed);
+    startTime = System.currentTimeMillis() - timeOffset;
+    if (isSeeking()) {
+      seekOffset = (long)(seekOffset * playbackSpeed / newSpeed);
+    }
+    playbackSpeed = newSpeed;
+  }
+
   public boolean isSeeking()
   {
     return (seekOffset >= 0);
@@ -146,7 +159,7 @@ class FbsInputStream extends InputStream {
   // Methods for internal use.
   //
 
-  private boolean fillBuffer() throws IOException
+  private synchronized boolean fillBuffer() throws IOException
   {
     waitWhilePaused();
 
@@ -156,8 +169,7 @@ class FbsInputStream extends InputStream {
       buffer = new byte[realSize];
       readFully(buffer);
       bufferPos = 0;
-
-      timeOffset = readUnsigned32();
+      timeOffset = (long)(readUnsigned32() / playbackSpeed);
     }
 
     if (bufferSize < 0 || timeOffset < 0) {
@@ -179,11 +191,9 @@ class FbsInputStream extends InputStream {
       if (timeDiff <= 0) {
        break;
       }
-      synchronized(this) {
-       try {
-         wait(timeDiff);
-       } catch (InterruptedException e) {
-       }
+      try {
+       wait(timeDiff);
+      } catch (InterruptedException e) {
       }
       waitWhilePaused();
     }
index 0d8700602b8a6f09c8517509f85b69c48990815b..55ac5686a8b98db9beca2af6157b797b1ca113db 100644 (file)
@@ -191,10 +191,15 @@ public class RfbPlayer extends java.applet.Applet
     }
   }
 
+  public void setSpeed(double speed) {
+    fbsStream.setSpeed(speed);
+  }
+
   public void setPos(int pos) {
     fbsStream.setTimeOffset(pos * 1000);
   }
 
+
   public void updatePos() {
     if (showControls)
       buttonPanel.setPos((int)(fbsStream.getTimeOffset() / 1000));