Changes in architecture to support pausing in the FbsInputStream
instead of using VncCanvas for that. RfbPlayer does not need to
remember current state any more. Play/Stop button removed. Added a
field to set playback speed, non-working yet.
git-svn-id: svn://svn.code.sf.net/p/tigervnc/code/trunk@2509 3789f03b-4d11-0410-bbf8-ca57d06f2519
diff --git a/java/src/com/tightvnc/rfbplayer/FbsInputStream.java b/java/src/com/tightvnc/rfbplayer/FbsInputStream.java
index 30ee42b..48c5b41 100644
--- a/java/src/com/tightvnc/rfbplayer/FbsInputStream.java
+++ b/java/src/com/tightvnc/rfbplayer/FbsInputStream.java
@@ -27,6 +27,7 @@
protected InputStream in;
protected long startTime;
+ protected long pausedTime;
protected long timeOffset;
protected byte[] buffer;
@@ -41,10 +42,15 @@
throw new IOException("FbsInputStream: no such constructor");
}
+ //
+ // Construct FbsInputStream object, begin playback.
+ //
+
FbsInputStream(InputStream in) throws IOException
{
this.in = in;
startTime = System.currentTimeMillis();
+ pausedTime = -1;
timeOffset = 0;
byte[] b = new byte[12];
@@ -85,11 +91,12 @@
return bufferSize;
}
- public void close() throws IOException
+ public synchronized void close() throws IOException
{
in.close();
in = null;
- startTime = 0;
+ startTime = -1;
+ pausedTime = -1;
timeOffset = 0;
buffer = null;
@@ -101,12 +108,12 @@
// Methods providing additional functionality.
//
- public int getPos()
+ public long getTimeOffset()
{
- return (int)(timeOffset / 1000);
+ return timeOffset;
}
- public void setPos(int pos)
+ public void setTimeOffset(int pos)
{
}
@@ -115,13 +122,18 @@
return false;
}
- public void pausePlayback()
+ public synchronized void pausePlayback()
{
+ // FIXME: There is no need to remember the time?
+ pausedTime = System.currentTimeMillis();
+ notify();
}
- public void resumePlayback()
+ public synchronized void resumePlayback()
{
startTime = System.currentTimeMillis() - timeOffset;
+ pausedTime = -1;
+ notify();
}
//
@@ -130,6 +142,8 @@
private boolean fillBuffer() throws IOException
{
+ waitWhilePaused();
+
bufferSize = (int)readUnsigned32();
if (bufferSize >= 0) {
int realSize = (bufferSize + 3) & 0xFFFFFFFC;
@@ -152,15 +166,34 @@
if (timeDiff <= 0) {
break;
}
- try {
- Thread.currentThread().sleep(timeDiff);
- } catch (InterruptedException e) {
+ synchronized(this) {
+ try {
+ wait(timeDiff);
+ } catch (InterruptedException e) {
+ }
}
+ waitWhilePaused();
}
return true;
}
+ //
+ // In paused mode, wait for external notification on this object.
+ //
+
+ private void waitWhilePaused()
+ {
+ while (pausedTime >= 0) {
+ synchronized(this) {
+ try {
+ wait();
+ } catch (InterruptedException e) {
+ }
+ }
+ }
+ }
+
private long readUnsigned32() throws IOException
{
byte[] buf = new byte[4];