# HG changeset patch # User Yu Taninari # Date 1335760838 -32400 # Node ID 21fa49d9e0f3e2e369313ae75593a6f702ed97c4 # Parent 3e41bb95119b9064eb1dedd3fde5143fe2661a8d add splitdata diff -r 3e41bb95119b -r 21fa49d9e0f3 src/treeVnc/MyRfbProtoProxy.java --- 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 out = new LinkedList(); 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 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 splitBuffer(LinkedList input) { + LinkedList output = new LinkedList(); + // 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 input, ByteBuffer header) + throws IOException, DataFormatException { + + int sum2 = 0; + LinkedList buf = splitBuffer(input); + for (int i = 0; i < (rectH / 128) + 1; i++) { + int sum = 0; + LinkedList tempBuf = new LinkedList(); + while (buf.peek() != null) { + tempBuf.addLast(buf.poll()); + sum2 += tempBuf.getLast().limit(); + } + // Deflater nDeflater = deflater; + Deflater nDeflater = new Deflater(); + LinkedList bufs = new LinkedList(); + 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); + } + }