changeset 45:21fa49d9e0f3

add splitdata
author Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
date Mon, 30 Apr 2012 13:40:38 +0900
parents 3e41bb95119b
children f5690aa77f69
files src/treeVnc/MyRfbProtoProxy.java
diffstat 1 files changed, 121 insertions(+), 19 deletions(-) [+]
line wrap: on
line diff
--- a/src/treeVnc/MyRfbProtoProxy.java	Mon Apr 30 12:33:21 2012 +0900
+++ b/src/treeVnc/MyRfbProtoProxy.java	Mon Apr 30 13:40:38 2012 +0900
@@ -404,10 +404,10 @@
 		cliListTmp.clear();
 	}
 
-//	boolean ready() throws IOException {
-//		BufferedReader br = new BufferedReader(new InputStreamReader(is));
-//		return br.ready();
-//	}
+	// boolean ready() throws IOException {
+	// BufferedReader br = new BufferedReader(new InputStreamReader(is));
+	// return br.ready();
+	// }
 
 	int cliSize() {
 		return cliList.size();
@@ -433,7 +433,7 @@
 			zLen = readU32();
 		else
 			zLen = 0;
-		//System.out.println(zLen);
+		// System.out.println(zLen);
 		is.reset();
 
 	}
@@ -763,7 +763,7 @@
 
 				startTiming();
 				readFully(inputData.array(), 0, inputData.capacity());
-//				System.out.println(dataLen);
+				// System.out.println(dataLen);
 				inputData.limit(dataLen - 20);
 				stopTiming();
 
@@ -778,15 +778,20 @@
 				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);
+
+				if (dataLen > 64000) {
+					splitData(out, header);
+				} else {
 
-				bufs.addFirst(header);
-			//	if(dataLen<=64000)
+					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();
 
 				/*
@@ -922,7 +927,7 @@
 												// after.
 					// writeFramebufferUpdateRequest(0,0, framebufferWidth,
 					// framebufferHeight, false );
-					int i  = 0;
+					int i = 0;
 					for (;;) {
 						LinkedList<ByteBuffer> bufs = c.poll();
 						int inputIndex = 0;
@@ -936,11 +941,8 @@
 							// System.out.println("client "+ myId);
 						}
 						/*
-						if(i%20==0){
-							sendDataCheckDelay();
-						}
-						i++;
-						*/
+						 * if(i%20==0){ sendDataCheckDelay(); } i++;
+						 */
 						writeToClient(os, bufs, inputIndex);
 						writerRunning.set(1); // yes my client is awaking.
 					}
@@ -1101,4 +1103,104 @@
 		};
 	}
 
+	private LinkedList<ByteBuffer> splitBuffer(LinkedList<ByteBuffer> input) {
+		LinkedList<ByteBuffer> output = new LinkedList<ByteBuffer>();
+		// int high = rectH / 4;
+		// System.out.println(INFLATE_BUFSIZE * (input.size() - 1)+
+		// input.getLast().limit());
+		int dataLen = rectW * 64 * 3 * 2;
+		int temp = 0;
+		int count = rectH / 128;
+
+		if (rectW % 64 == 0)
+			dataLen += (rectW / 64) * 2;
+		else
+			dataLen += (((rectW / 64) + 1) * 2);
+
+		for (int i = 0; i < count; i++) {
+			int tempDataLen = dataLen - temp;
+
+			while (tempDataLen > INFLATE_BUFSIZE) {
+				output.addLast(input.poll());
+				tempDataLen -= INFLATE_BUFSIZE;
+			}
+			if (tempDataLen == INFLATE_BUFSIZE) {
+				output.addLast(input.poll());
+				output.addLast(null);
+				temp = INFLATE_BUFSIZE;
+			} else {
+				// System.out.println("THROWIO");
+				ByteBuffer tempBuf = input.poll();
+
+				// System.out.println(tempBuf.remaining());
+				ByteBuffer buf1 = ByteBuffer.allocate(INFLATE_BUFSIZE);
+				ByteBuffer buf2 = ByteBuffer.allocate(INFLATE_BUFSIZE);
+				tempBuf.get(buf1.array(), 0, tempDataLen);
+				tempBuf.get(buf2.array(), 0, tempBuf.remaining());
+				buf1.limit(tempDataLen);
+				// insert into createHeader
+				// insert into this area zipcode and buf1 clear
+				buf2.limit(INFLATE_BUFSIZE - tempDataLen);
+				buf2.position(0);
+				output.addLast(buf1);
+				output.addLast(null);
+				output.addLast(buf2);
+				temp = INFLATE_BUFSIZE - tempDataLen;
+			}
+		}
+
+		while (input.size() != 0) {
+			output.addLast(input.poll());
+		}
+
+		return output;
+	}
+
+	private void splitData(LinkedList<ByteBuffer> input, ByteBuffer header)
+			throws IOException, DataFormatException {
+
+		int sum2 = 0;
+		LinkedList<ByteBuffer> buf = splitBuffer(input);
+		for (int i = 0; i < (rectH / 128) + 1; i++) {
+			int sum = 0;
+			LinkedList<ByteBuffer> tempBuf = new LinkedList<ByteBuffer>();
+			while (buf.peek() != null) {
+				tempBuf.addLast(buf.poll());
+				sum2 += tempBuf.getLast().limit();
+			}
+			// Deflater nDeflater = deflater;
+			Deflater nDeflater = new Deflater();
+			LinkedList<ByteBuffer> bufs = new LinkedList<ByteBuffer>();
+			for (ByteBuffer b : tempBuf) {
+				sum += b.limit();
+			}
+
+			int len2 = zip(nDeflater, tempBuf, 0, bufs);
+			ByteBuffer blen = ByteBuffer.allocate(4);
+			blen.putInt(len2);
+			blen.flip();
+			bufs.addFirst(blen);
+			createHeader(header, i);
+
+			System.out.println(sum - (header.getShort(10) * header.getShort(8))
+					* 3);
+			System.out.println("sum2=" + sum2);
+
+			bufs.addFirst(header);
+			// broadcastqueue.put(bufs);
+			multicastqueue.put(bufs);
+			// System.out.println("pass");
+			if (buf.size() != 0)
+				buf.remove();
+		}
+		// System.out.println("throw");
+	}
+
+	private void createHeader(ByteBuffer header, int count) {
+		int rH = Math.min(128, rectH - (128 * count));
+		int rY = rectY + (128 * count);
+		header.putShort(10, (short) rH);
+		header.putShort(6, (short) rY);
+	}
+
 }