diff options
author | Constantin Kaplinsky <const@tightvnc.com> | 2008-06-18 09:28:30 +0000 |
---|---|---|
committer | Constantin Kaplinsky <const@tightvnc.com> | 2008-06-18 09:28:30 +0000 |
commit | 7b55c4f4183f71a15610e4d1937211f7cf0c9f74 (patch) | |
tree | 1df524d28ab54c315db3196f16d4a600c768af17 /java/src | |
parent | 8920b550bc0e2f77be8086187bbd297d53e38915 (diff) | |
download | tigervnc-7b55c4f4183f71a15610e4d1937211f7cf0c9f74.tar.gz tigervnc-7b55c4f4183f71a15610e4d1937211f7cf0c9f74.zip |
Code refactoring. Now RfbPlayer maintains FbsInputStream and RfbProto instances separately. Also, RfbProto does not need FbsInputStream any more, it can work with any InputStream.
git-svn-id: svn://svn.code.sf.net/p/tigervnc/code/trunk@2589 3789f03b-4d11-0410-bbf8-ca57d06f2519
Diffstat (limited to 'java/src')
-rw-r--r-- | java/src/com/tightvnc/rfbplayer/RfbPlayer.java | 54 | ||||
-rw-r--r-- | java/src/com/tightvnc/rfbplayer/RfbProto.java | 55 | ||||
-rw-r--r-- | java/src/com/tightvnc/rfbplayer/VncCanvas.java | 6 |
3 files changed, 60 insertions, 55 deletions
diff --git a/java/src/com/tightvnc/rfbplayer/RfbPlayer.java b/java/src/com/tightvnc/rfbplayer/RfbPlayer.java index 98b15055..8cff6e19 100644 --- a/java/src/com/tightvnc/rfbplayer/RfbPlayer.java +++ b/java/src/com/tightvnc/rfbplayer/RfbPlayer.java @@ -52,6 +52,7 @@ public class RfbPlayer extends java.applet.Applet String[] mainArgs; + FbsInputStream fbs; RfbProto rfb; Thread rfbThread; @@ -134,7 +135,9 @@ public class RfbPlayer extends java.applet.Applet } else { url = new URL(sessionURL); } - rfb = new RfbProto(url, initialTimeOffset); + newFbsConnection(); + fbs.setTimeOffset(initialTimeOffset); + rfb = new RfbProto(fbs); vc = new VncCanvas(this); gbc.weightx = 1.0; @@ -178,19 +181,23 @@ public class RfbPlayer extends java.applet.Applet while (!isQuitting) { try { setPaused(!autoPlay); - rfb.fbs.setSpeed(playbackSpeed); + fbs.setSpeed(playbackSpeed); vc.processNormalProtocol(); } catch (EOFException e) { + long newTimeOffset; if (e.getMessage() != null && e.getMessage().equals("[REWIND]")) { // A special type of EOFException allowing us to seek backwards. - initialTimeOffset = rfb.fbs.getSeekOffset(); - autoPlay = !rfb.fbs.isPaused(); + newTimeOffset = fbs.getSeekOffset(); + autoPlay = !fbs.isPaused(); } else { // Return to the beginning after the playback is finished. - initialTimeOffset = 0; + newTimeOffset = 0; autoPlay = false; } - rfb.newSession(url, initialTimeOffset); + fbs.close(); + newFbsConnection(); + fbs.setTimeOffset(newTimeOffset); + rfb.newSession(fbs); vc.updateFramebufferSize(); } catch (NullPointerException e) { // catching this causes a hang with 1.4.1 JVM's under Win32 IE @@ -207,6 +214,17 @@ public class RfbPlayer extends java.applet.Applet } + /** + * Open new connection specified by this.url, save new FbsInputStream in + * this.fbs. + * + * @throws java.io.IOException + */ + void newFbsConnection() throws IOException { + URLConnection connection = url.openConnection(); + fbs = new FbsInputStream(connection.getInputStream()); + } + public void setPausedInt(String paused) { // default to true (pause) int pause = 1; @@ -227,9 +245,9 @@ public class RfbPlayer extends java.applet.Applet if (showControls) buttonPanel.setPaused(paused); if (paused) { - rfb.fbs.pausePlayback(); + fbs.pausePlayback(); } else { - rfb.fbs.resumePlayback(); + fbs.resumePlayback(); } } @@ -239,27 +257,27 @@ public class RfbPlayer extends java.applet.Applet public void setSpeed(double speed) { playbackSpeed = speed; - rfb.fbs.setSpeed(speed); + fbs.setSpeed(speed); } public void jumpTo(long pos) { - long diff = Math.abs(pos - rfb.fbs.getTimeOffset()); + long diff = Math.abs(pos - fbs.getTimeOffset()); // Current threshold is 5 seconds if (diff > 5000) { - rfb.fbs.pausePlayback(); + fbs.pausePlayback(); setPos(pos); - rfb.fbs.resumePlayback(); + fbs.resumePlayback(); } } public void setPos(long pos) { - rfb.fbs.setTimeOffset(pos); + fbs.setTimeOffset(pos); } public void updatePos() { if (showControls && buttonPanel != null) - buttonPanel.setPos(rfb.fbs.getTimeOffset()); + buttonPanel.setPos(fbs.getTimeOffset()); } // @@ -402,8 +420,12 @@ public class RfbPlayer extends java.applet.Applet public void destroy() { isQuitting = true; vncContainer.removeAll(); - if (rfb != null) { - rfb.quit(); + if (fbs != null) { + fbs.quit(); + try { + fbs.close(); + } catch (IOException e) { + } } try { rfbThread.join(); diff --git a/java/src/com/tightvnc/rfbplayer/RfbProto.java b/java/src/com/tightvnc/rfbplayer/RfbProto.java index 4afad719..191173ef 100644 --- a/java/src/com/tightvnc/rfbplayer/RfbProto.java +++ b/java/src/com/tightvnc/rfbplayer/RfbProto.java @@ -28,7 +28,6 @@ package com.tightvnc.rfbplayer; import java.io.*; -import java.net.*; class RfbProto { @@ -88,52 +87,36 @@ class RfbProto { final static int TightMinToCompress = 12; - FbsInputStream fbs; DataInputStream is; - - // - // Constructor. - // - RfbProto(URL url, long timeOffset) throws Exception { - fbs = null; - newSession(url, timeOffset); + /** + * Constructor. It calls <code>{@link #newSession(InputStream)}</code> to open + * new session. + * + * @param is the input stream from which RFB data will be read. + * @throws java.lang.Exception + * @throws java.io.IOException + */ + RfbProto(InputStream is) throws Exception { + newSession(is); } - // Force processing to quit - public void quit() { - fbs.quit(); - try { - fbs.close(); - } catch (IOException e) { - System.out.println("IOException quitting RfbProto: " + e); - } - } + /** + * Open new session that can be read from the specified InputStream. + * + * @param is the input stream. + * @throws java.lang.Exception + * @throws java.io.IOException + */ + public void newSession(InputStream is) throws Exception { - // - // Open new session URL. - // - public void newSession(URL url, long timeOffset) throws Exception { - if (fbs != null) - fbs.close(); - - // open the connection, and use caching - URLConnection connection = url.openConnection(); - connection.setUseCaches(true); - - fbs = new FbsInputStream(connection.getInputStream()); - is = new DataInputStream(fbs); + this.is = new DataInputStream(is); readVersionMsg(); if (readAuthScheme() != NoAuth) { throw new Exception("Wrong authentication type in the session file"); } readServerInit(); - - // Go to initial position but make sure not to seek backwards. - if (timeOffset > fbs.getTimeOffset()) { - fbs.setTimeOffset(timeOffset); - } } // diff --git a/java/src/com/tightvnc/rfbplayer/VncCanvas.java b/java/src/com/tightvnc/rfbplayer/VncCanvas.java index 8c3313bf..7bb8d296 100644 --- a/java/src/com/tightvnc/rfbplayer/VncCanvas.java +++ b/java/src/com/tightvnc/rfbplayer/VncCanvas.java @@ -353,7 +353,7 @@ class VncCanvas extends Component // Tell our FbsInputStream object to notify us when it goes to the // `paused' mode. - rfb.fbs.addObserver(this); + appClass.fbs.addObserver(this); // // main dispatch loop @@ -1004,7 +1004,7 @@ class VncCanvas extends Component // Tell JVM to repaint specified desktop area. // void scheduleRepaint(int x, int y, int w, int h) { - if (rfb.fbs.isSeeking()) { + if (appClass.fbs.isSeeking()) { // Do nothing, and remember we are seeking. seekMode = true; } else { @@ -1315,7 +1315,7 @@ class VncCanvas extends Component } void scheduleCursorRepaint(int x, int y, int w, int h, int n) { - if (rfb.fbs.isSeeking()) { + if (appClass.fbs.isSeeking()) { // Do nothing, and remember we are seeking. seekMode = true; } else { |