Mercurial > hg > Members > you > TreeVNC
changeset 40:816cdfe3a129
update
author | Yu Taninari <you@cr.ie.u-ryukyu.ac.jp> |
---|---|
date | Sun, 29 Apr 2012 19:56:52 +0900 |
parents | 7afe8d10ad66 |
children | a4bb20871509 |
files | src/test/BlockingUpdateRectangle.java src/treeVnc/MyRfbProtoProxy.java src/treeVnc/ReadHandler.java src/treeVnc/RfbProto.java src/treeVnc/VncProxyService.java |
diffstat | 5 files changed, 45 insertions(+), 127 deletions(-) [+] |
line wrap: on
line diff
--- a/src/test/BlockingUpdateRectangle.java Tue Apr 24 20:24:10 2012 +0900 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,123 +0,0 @@ -package test; - -import java.io.IOException; -import java.nio.ByteBuffer; -import java.util.LinkedList; -import java.util.zip.Deflater; - -import org.junit.Test; -import treeVnc.RfbProto; - -public class BlockingUpdateRectangle { - - int INFLATE_BUFSIZE = 1024*100; - - - @Test - public void test() { - ByteBuffer input = ByteBuffer.allocate(4096); - createUpdateRectangle(input); - RfbProto rfb = new RfbProto(); - LinkedList<ByteBuffer> output = rfb.BlockingUpdateRectangle(input); - - - fail("Not yet implemented"); - } - - private void createUpdateRectangle(ByteBuffer input) { - int x = 512; - int y = 512; - int count = 1; - int bytePixel = 3; - int mode = 0; - byte[] palette = new byte[count*bytePixel]; - input.put((byte)mode); - for(byte b: palette) - input.put(b); - int[] pixel = new int[x*y*bytePixel]; - for(int i = 0 ; i < x*y ; i+=bytePixel) { - } - - int[] dst = new int[x*y*bytePixel]; - for(int i = 0 ; i < x*y ; i++) { - dst[i] = ((pixel[i * 3 + 2] & 0xFF) << 16 - | (pixel[i * 3 + 1] & 0xFF) << 8 | (pixel[i * 3] & 0xFF)); - } - } - - 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 = 64*64; - int temp = 0; - int tempDataLen = 0; - ByteBuffer buf1 = ByteBuffer.allocate(INFLATE_BUFSIZE); - ByteBuffer buf2 = ByteBuffer.allocate(INFLATE_BUFSIZE); - buf2 = input.poll(); - - for (int ty = rectY; ty < rectY + rectH; ty += 64) { - - int th = Math.min(rectY + rectH - ty, 64); - - for (int tx = rectX; tx < rectX + rectW; tx += 64) { - - int tw = Math.min(rectX + rectW - tx, 64); - - if(buf2.limit()-buf2.position() >= dataLen) { - buf2.get(buf1.array(),0,dataLen); - temp += dataLen; - buf2.position(temp); - } else { - buf2.get(buf1.array(),0,buf2.remaining()); - temp = th*tw - buf2.remaining(); - buf2 = input.poll(); - buf2.get(buf1.array(), 0, temp); - buf2.position(temp); - } - } - } - return output; - } - - private void splitData(LinkedList<ByteBuffer> input, ByteBuffer header) - throws IOException { - -// System.out.println(test++); - LinkedList<ByteBuffer> bufs = new LinkedList<ByteBuffer>(); - LinkedList<ByteBuffer> buf = splitBuffer(input); - for (int i = 1; i < 5; i++) { - LinkedList<ByteBuffer> tempBuf = new LinkedList<ByteBuffer>(); - while (buf.peek() != null) { - tempBuf.addLast(buf.poll()); - } - Deflater nDeflater = deflater; - int len2 = zip(nDeflater, tempBuf, 0, bufs); - ByteBuffer blen = ByteBuffer.allocate(4); - blen.putInt(len2); - blen.flip(); - bufs.addFirst(blen); - // ByteBuffer tempheader = createHeader(header,i); - // bufs.addFirst(tempheader); - bufs.addFirst(header); - multicastqueue.put(bufs); - buf.remove(); - } - } - - private ByteBuffer createHeader(ByteBuffer header, int count) { - ByteBuffer tempheader = header; - int h = tempheader.getShort(10); - int y = tempheader.getShort(6); - int high = h / 4; - if (count != 4) - y = y + high * count; - else - y = y + high * count + (h % 4); - tempheader.put(10, (byte) high); - tempheader.put(6, (byte) y); - return tempheader; - } - - -}
--- a/src/treeVnc/MyRfbProtoProxy.java Tue Apr 24 20:24:10 2012 +0900 +++ b/src/treeVnc/MyRfbProtoProxy.java Sun Apr 29 19:56:52 2012 +0900 @@ -111,6 +111,12 @@ // requestThread = new Thread(new RequestScreenThread(this)); } + public MyRfbProtoProxy(String h, int p, boolean b) throws IOException { + super(h, p, b); + rThread = new RequestScreenThread(this); + requestThread = new Thread(rThread); + } + // over write void writeVersionMsg() throws IOException { clientMajor = 3;
--- a/src/treeVnc/ReadHandler.java Tue Apr 24 20:24:10 2012 +0900 +++ b/src/treeVnc/ReadHandler.java Sun Apr 29 19:56:52 2012 +0900 @@ -1,5 +1,6 @@ package treeVnc; +import java.nio.channels.SocketChannel; import java.nio.channels.spi.AbstractSelectableChannel; public class ReadHandler { @@ -8,7 +9,10 @@ public ReadHandler(RfbProto rfbProto, AbstractSelectableChannel ssChannel) { this.setChannel(ssChannel); - + } + + public ReadHandler(InputStreamTest inputStreamTest, SocketChannel ssChannel) { + this.setChannel(ssChannel); } public AbstractSelectableChannel getChannel() {
--- a/src/treeVnc/RfbProto.java Tue Apr 24 20:24:10 2012 +0900 +++ b/src/treeVnc/RfbProto.java Sun Apr 29 19:56:52 2012 +0900 @@ -31,8 +31,10 @@ import java.net.InetSocketAddress; import java.net.Socket; import java.net.SocketException; +import java.net.UnknownHostException; import java.nio.channels.DatagramChannel; import java.nio.channels.SelectionKey; +import java.nio.channels.ServerSocketChannel; import java.nio.channels.SocketChannel; import java.nio.channels.spi.AbstractSelector; import java.nio.channels.spi.SelectorProvider; @@ -225,7 +227,7 @@ host = h; port = p; - sock = newSocket(host, port); + sock = new Socket(host, port); is = new DataInputStream1(new BufferedInputStream(sock.getInputStream(), 16384)); os = sock.getOutputStream(); @@ -242,7 +244,8 @@ // check this using netstat -an result tcp46. try { InetSocketAddress address = new InetSocketAddress(host, port); - ssChannel.socket().bind(address); + //ssChannel.socket().bind(address); + ssChannel.socket().connect(address); } catch (SocketException e) { // for some bad IPv6 implementation ssChannel.socket().bind(new InetSocketAddress(port)); @@ -273,6 +276,19 @@ } + public RfbProto(String h, int p, boolean b) throws UnknownHostException, IOException { + host = h; + port = p; + sock = new Socket(host, port); + is = new DataInputStream1(new BufferedInputStream(sock.getInputStream(), + 16384)); + os = sock.getOutputStream(); + + timing = false; + timeWaitedIn100us = 5; + timedKbits = 0; + } + public void initOnce() throws IOException { selector = SelectorProvider.provider().openSelector(); }
--- a/src/treeVnc/VncProxyService.java Tue Apr 24 20:24:10 2012 +0900 +++ b/src/treeVnc/VncProxyService.java Sun Apr 29 19:56:52 2012 +0900 @@ -12,7 +12,6 @@ VncProxyService v = new VncProxyService(); // v.checkArgs(argv); - v.mainArgs = argv; v.init(); @@ -130,6 +129,15 @@ readParameters(); + + try { + rfb = new MyRfbProtoProxy(host, port, true); + rfb.initOnce(); + //rfb.close(); + } catch (IOException e1) { + e1.printStackTrace(); + } + options = new OptionsNoFrame(this); recordingSync = new Object(); @@ -158,6 +166,13 @@ if(changeFlag){ acceptThread.changeRfb(rfb); } else {*/ + + /*try { + rfb.initOnce(); + } catch (IOException e) { + e.printStackTrace(); + }*/ + rfb.selectPort(5999); rfbThread = new Thread(this); acceptThread = new AcceptThread(rfb, 5999);