diff options
author | Constantin Kaplinsky <const@tightvnc.com> | 2008-06-22 07:24:11 +0000 |
---|---|---|
committer | Constantin Kaplinsky <const@tightvnc.com> | 2008-06-22 07:24:11 +0000 |
commit | 31b7a24a1aca6f44fd13977f7ad8f66961cc366b (patch) | |
tree | f63c49884f353656fa2cf44b1914a7e562a551d0 /java | |
parent | 3e51615673ca2d5efc6deedaf7148309dcb41673 (diff) | |
download | tigervnc-31b7a24a1aca6f44fd13977f7ad8f66961cc366b.tar.gz tigervnc-31b7a24a1aca6f44fd13977f7ad8f66961cc366b.zip |
[Development] Indexed seeking (using HTTP 1.1 Range request headers) is working for initial file positioning, and for seeking backwards.
git-svn-id: svn://svn.code.sf.net/p/tigervnc/code/trunk@2612 3789f03b-4d11-0410-bbf8-ca57d06f2519
Diffstat (limited to 'java')
-rw-r--r-- | java/src/com/tightvnc/rfbplayer/FbsConnection.java | 51 |
1 files changed, 39 insertions, 12 deletions
diff --git a/java/src/com/tightvnc/rfbplayer/FbsConnection.java b/java/src/com/tightvnc/rfbplayer/FbsConnection.java index 4e83335c..9b38652e 100644 --- a/java/src/com/tightvnc/rfbplayer/FbsConnection.java +++ b/java/src/com/tightvnc/rfbplayer/FbsConnection.java @@ -195,36 +195,63 @@ public class FbsConnection { // Make sure the protocol is HTTP. if (!fbkURL.getProtocol().equalsIgnoreCase("http") || !fbsURL.getProtocol().equalsIgnoreCase("http")) { + System.err.println("Indexed access requires HTTP protocol in URLs"); return null; } - // Prepare URLConnection to the right part of the .fbk file. + // Request RFB initialization. + // FIXME: Check return value of openHttpByteRange(), it can be null. InputStream is = - openByteRange(fbkURL, entryPoint.key_fpos, entryPoint.key_size); + openHttpByteRange(fbkURL, 12, indexData[0].key_fpos - 12); DataInputStream dis = new DataInputStream(is); + // Read RFB initialization. + int initDataSize = dis.readInt(); + byte[] initData = new byte[initDataSize]; + dis.readFully(initData); + dis.close(); + + // Seek to the keyframe. + // FIXME: Check return value of openHttpByteRange(), it can be null. + is = openHttpByteRange(fbkURL, entryPoint.key_fpos, entryPoint.key_size); + dis = new DataInputStream(is); + // Load keyframe data from the .fbk file. int keyDataSize = dis.readInt(); byte[] keyData = new byte[keyDataSize]; dis.readFully(keyData); dis.close(); + // Concatenate init and keyframe data. + // FIXME: Get rid of concatenation, read both parts to one array. + byte[] allData = new byte[initDataSize + keyDataSize]; + System.arraycopy(initData, 0, allData, 0, initDataSize); + System.arraycopy(keyData, 0, allData, initDataSize, keyDataSize); + // Open the FBS stream. - URLConnection fbsConn = fbsURL.openConnection(); - fbsConn.connect(); - return new FbsInputStream(fbsConn.getInputStream(), entryPoint.timestamp, - keyData, entryPoint.fbs_skip); + // FIXME: Check return value of openHttpByteRange(), it can be null. + is = openHttpByteRange(fbsURL, entryPoint.fbs_fpos, -1); + return new FbsInputStream(is, entryPoint.timestamp, allData, + entryPoint.fbs_skip); } - private static InputStream openByteRange(URL url, long offset, long length) + private static InputStream openHttpByteRange(URL url, long offset, long len) throws IOException { - URLConnection conn = url.openConnection(); - long lastByteOffset = offset + length - 1; - String rangeSpec = "bytes=" + offset + "-" + lastByteOffset; - System.err.println("Range: " + rangeSpec); + HttpURLConnection conn = (HttpURLConnection)url.openConnection(); + String rangeSpec = "bytes=" + offset + "-"; + if (len != -1) { + long lastByteOffset = offset + len - 1; + rangeSpec += lastByteOffset; + } conn.setRequestProperty("Range", rangeSpec); conn.connect(); - return conn.getInputStream(); + InputStream is = conn.getInputStream(); + if (conn.getResponseCode() != HttpURLConnection.HTTP_PARTIAL) { + System.err.println("HTTP server does not support Range request headers"); + is.close(); + return null; + } + return is; } } |