diff src/myVncProxy/MyRfbProto.java @ 107:a8b2712de4c5

ZRLEE extension
author Shinji KONO <kono@ie.u-ryukyu.ac.jp>
date Fri, 05 Aug 2011 08:57:00 +0900
parents 7a7baebdd3cf
children 3f73ebf918bd
line wrap: on
line diff
--- a/src/myVncProxy/MyRfbProto.java	Thu Aug 04 21:09:17 2011 +0900
+++ b/src/myVncProxy/MyRfbProto.java	Fri Aug 05 08:57:00 2011 +0900
@@ -32,7 +32,7 @@
 import java.io.OutputStream;
 
 public
-class MyRfbProto<ByteBuffersIterator> extends RfbProto {
+class MyRfbProto extends RfbProto {
 	final static String versionMsg_3_998 = "RFB 003.998\n";
 	/**
 	 * CheckMillis is one of new msgType for RFB 3.998. 
@@ -310,7 +310,7 @@
 		rectH = readU16();           //  10
 		encoding = readU32();      //   12
 		System.out.println("encoding = "+encoding);
-		if (encoding == EncodingZRLE)
+		if (encoding == EncodingZRLE|| encoding==EncodingZRLEE||encoding==EncodingZlib)
 			zLen = readU32();
 		else
 			zLen = 0;
@@ -338,6 +338,7 @@
 			break;
 		case RfbProto.EncodingZlib:
 		case RfbProto.EncodingZRLE:
+		case RfbProto.EncodingZRLEE:
 			dataLen = zLen + 20;
 			is.mark(dataLen);
 			break;
@@ -581,26 +582,24 @@
 		header.limit(16);
 		if (header.get(0)==RfbProto.FramebufferUpdate) {
 			int encoding = header.getInt(12);
-			if (encoding==RfbProto.EncodingZlib||encoding==RfbProto.EncodingZRLE) {
+			if (encoding==RfbProto.EncodingZRLE||encoding==RfbProto.EncodingZlib) { // ZRLEE is already recompressed
 				ByteBuffer len = ByteBuffer.allocate(4);
 				readFully(len.array(),0,4); len.limit(4);
 				ByteBuffer inputData = ByteBuffer.allocate(dataLen-20);
 				readFully(inputData.array(),0,inputData.capacity()); inputData.limit(dataLen-20);
 				LinkedList<ByteBuffer>inputs = new LinkedList<ByteBuffer>();
 				inputs.add(inputData);
-				// int length = rectW * rectH * (bitsPerPixel/8);
-				if (clicomp) {
-					unzip(inflater, inputs, 0, bufs, INFLATE_BUFSIZE);
-				} else {
-					// using new Deflecter every time is incompatible with the protocol, clients have to be modified.
-					Deflater nDeflater = deflater; // new Deflater();
-					LinkedList<ByteBuffer> out = new LinkedList<ByteBuffer>();
-					unzip(inflater, inputs, 0 , out, INFLATE_BUFSIZE);
-					// dump32(inputs);
-					int len2 = zip(nDeflater, out, 0, bufs);
-					ByteBuffer blen = ByteBuffer.allocate(4); blen.putInt(len2); blen.flip();
-					bufs.addFirst(blen);
-				}
+
+				header.putInt(12, RfbProto.EncodingZRLEE); // means recompress every time
+				// using new Deflecter every time is incompatible with the protocol, clients have to be modified.
+				Deflater nDeflater = deflater; // new Deflater();
+				LinkedList<ByteBuffer> out = new LinkedList<ByteBuffer>();
+				unzip(inflater, inputs, 0 , out, INFLATE_BUFSIZE);
+				// dump32(inputs);
+				int len2 = zip(nDeflater, out, 0, bufs);
+				ByteBuffer blen = ByteBuffer.allocate(4); blen.putInt(len2); blen.flip();
+				bufs.addFirst(blen);
+
 				bufs.addFirst(header);
 				multicastqueue.put(bufs);
 				is.reset();
@@ -647,9 +646,9 @@
 				}
 			}
 		};
+		final int myId = clients; 
 		Runnable sender = new Runnable() {
 			public void run() {
-			    Deflater deflater = new Deflater();
 				try {
 					/**
 					 *  initial connection of RFB protocol
@@ -668,24 +667,7 @@
 						ByteBuffer header = bufs.get(inputIndex++);
 						if (header==null) continue;
 						if (header.get(0)==RfbProto.FramebufferUpdate) {
-							System.out.println("client "+ clients);
-							int encoding = header.getInt(12);
-							if (encoding==RfbProto.EncodingZlib||encoding==RfbProto.EncodingZRLE) {
-								LinkedList<ByteBuffer> outs;
-								if (clicomp) {
-									outs = new LinkedList<ByteBuffer>();
-									int len2 = zip(deflater, bufs, inputIndex, outs);
-									ByteBuffer blen = ByteBuffer.allocate(4); blen.putInt(len2); blen.flip();
-									outs.addFirst(blen);
-									outs.addFirst(header);
-									inputIndex = 0;
-								} else {
-									outs = bufs;
-									inputIndex = 0;
-								}
-								writeToClient(os,bufs,inputIndex);
-								continue;
-							}
+							System.out.println("client "+ myId);
 						}
 						os.write(header.array(),header.position(),header.limit());
 						writeToClient(os, bufs, inputIndex);
@@ -738,14 +720,15 @@
 			LinkedList<ByteBuffer> in = new LinkedList<ByteBuffer>();
 			LinkedList<ByteBuffer> out = new LinkedList<ByteBuffer>();
 			LinkedList<ByteBuffer> out2 = new LinkedList<ByteBuffer>();
-			if (false) {
-			for(int i=0;i<10;i++) {
-				in.add(ByteBuffer.wrap("test1".getBytes()));
-				in.add(ByteBuffer.wrap("test2".getBytes()));
-				in.add(ByteBuffer.wrap("test3".getBytes()));
-				in.add(ByteBuffer.wrap("test44".getBytes()));
-			}
-			} else {
+//			if (false) {
+//			for(int i=0;i<10;i++) {
+//				in.add(ByteBuffer.wrap("test1".getBytes()));
+//				in.add(ByteBuffer.wrap("test2".getBytes()));
+//				in.add(ByteBuffer.wrap("test3".getBytes()));
+//				in.add(ByteBuffer.wrap("test44".getBytes()));
+//			}
+//			} else 
+			{
 				String t = "";
 				for(int i=0;i<10;i++) {
 					t += "test1";