From 9e501649e31821bc35be006015057451b33920fa Mon Sep 17 00:00:00 2001 From: Constantin Kaplinsky Date: Mon, 23 Jun 2008 01:57:55 +0000 Subject: [PATCH] [Development] Data format of the .fbi file has been changed. In addition to the list of entry points, it will include RFB initialization data that should be prepended to each keyframe. git-svn-id: svn://svn.code.sf.net/p/tigervnc/code/trunk@2614 3789f03b-4d11-0410-bbf8-ca57d06f2519 --- .../com/tightvnc/rfbplayer/FbsConnection.java | 45 +++++++++---------- 1 file changed, 22 insertions(+), 23 deletions(-) diff --git a/java/src/com/tightvnc/rfbplayer/FbsConnection.java b/java/src/com/tightvnc/rfbplayer/FbsConnection.java index 5c3ca82b..d8bd972c 100644 --- a/java/src/com/tightvnc/rfbplayer/FbsConnection.java +++ b/java/src/com/tightvnc/rfbplayer/FbsConnection.java @@ -36,6 +36,9 @@ public class FbsConnection { /** Index data loaded from the .fbi file. */ FbsEntryPoint[] indexData; int numIndexRecords; + + /** RFB initialization data loaded from the .fbi file. */ + byte[] rfbInitData; FbsConnection(String fbsLocation, String indexLocationPrefix, Applet applet) throws MalformedURLException { @@ -59,6 +62,7 @@ public class FbsConnection { // Try to load the .fbi index file. indexData = null; numIndexRecords = 0; + rfbInitData = null; loadIndex(); } @@ -105,6 +109,7 @@ public class FbsConnection { if (fbiURL != null && fbkURL != null) { FbsEntryPoint[] newIndex; int numRecordsRead = 0; + byte[] newInitData; try { // Connect. URLConnection connection = fbiURL.openConnection(); @@ -130,6 +135,14 @@ public class FbsConnection { } newIndex = new FbsEntryPoint[numRecords]; + // Read byte counter and allocate byte array for RFB initialization. + int initSize = is.readInt(); + if (initSize <= 0) { + System.err.println("Could not load index: bad RFB init data size"); + return; + } + newInitData = new byte[initSize]; + // Load index from the .fbi file. try { for (int i = 0; i < numRecords; i++) { @@ -153,6 +166,7 @@ public class FbsConnection { } else if (numRecordsRead != numRecords) { System.err.println("Warning: read not as much .fbi data as expected"); } + is.readFully(newInitData); } catch (FileNotFoundException e) { System.err.println("Could not load index: .fbi file not found: " + e.getMessage()); @@ -172,6 +186,7 @@ public class FbsConnection { // Loaded successfully. indexData = newIndex; numIndexRecords = numRecordsRead; + rfbInitData = newInitData; System.err.println("Loaded index data, " + numRecordsRead + " records"); } } @@ -207,39 +222,23 @@ public class FbsConnection { return null; } - // Request RFB initialization. + // Seek to the keyframe. // FIXME: Check return value of openHttpByteRange(), it can be null. InputStream is = - openHttpByteRange(fbkURL, 12, indexData[0].key_fpos - 12); + openHttpByteRange(fbkURL, entryPoint.key_fpos, entryPoint.key_size); 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. + // Load keyframe data from the .fbk file, prepend RFB initialization data. int keyDataSize = dis.readInt(); - byte[] keyData = new byte[keyDataSize]; - dis.readFully(keyData); + byte[] keyData = new byte[rfbInitData.length + keyDataSize]; + System.arraycopy(rfbInitData, 0, keyData, 0, rfbInitData.length); + dis.readFully(keyData, rfbInitData.length, keyDataSize); 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. // FIXME: Check return value of openHttpByteRange(), it can be null. is = openHttpByteRange(fbsURL, entryPoint.fbs_fpos, -1); - return new FbsInputStream(is, entryPoint.timestamp, allData, + return new FbsInputStream(is, entryPoint.timestamp, keyData, entryPoint.fbs_skip); } -- 2.39.5