comparison src/myVncProxy/MyRfbProto.java @ 82:0cbe556e2c54

remove item to reduce memory
author Shinji KONO <kono@ie.u-ryukyu.ac.jp>
date Wed, 03 Aug 2011 04:26:58 +0900
parents 9109273b96dc
children d4236fd2efe1
comparison
equal deleted inserted replaced
81:9109273b96dc 82:0cbe556e2c54
30 final static String versionMsg_3_998 = "RFB 003.998\n"; 30 final static String versionMsg_3_998 = "RFB 003.998\n";
31 /** 31 /**
32 * CheckMillis is one of new msgType for RFB 3.998. 32 * CheckMillis is one of new msgType for RFB 3.998.
33 */ 33 */
34 final static int SpeedCheckMillis = 4; 34 final static int SpeedCheckMillis = 4;
35 private static final int INFLATE_BUFSIZE = 1024*1024*16; 35 private static final int INFLATE_BUFSIZE = 1024*1024;
36 boolean printStatusFlag = false; 36 boolean printStatusFlag = false;
37 long startCheckTime; 37 long startCheckTime;
38 38
39 private int messageType; 39 private int messageType;
40 private int rectangles; 40 private int rectangles;
55 55
56 ExecutorService executor; 56 ExecutorService executor;
57 57
58 byte[] pngBytes; 58 byte[] pngBytes;
59 59
60 private MulticastQueue<byte[]> multicastqueue = new MulticastQueue<byte[]>(); 60 private MulticastQueue<byte[]> multicastqueue = new MostRecentMultiCast<byte[]>(10);
61 private int clients = 0; 61 private int clients = 0;
62 private Inflater inflater = new Inflater(); 62 private Inflater inflater = new Inflater();
63 63
64 MyRfbProto(String h, int p, VncViewer v) throws IOException { 64 MyRfbProto(String h, int p, VncViewer v) throws IOException {
65 super(h, p, v); 65 super(h, p, v);
376 readFully(b); 376 readFully(b);
377 377
378 if (b[0]==RfbProto.FramebufferUpdate) { 378 if (b[0]==RfbProto.FramebufferUpdate) {
379 int encoding = ((b[12]*256+b[13])*256+b[14])*256+b[15]; 379 int encoding = ((b[12]*256+b[13])*256+b[14])*256+b[15];
380 if (encoding==RfbProto.EncodingZlib||encoding==RfbProto.EncodingZRLE) { 380 if (encoding==RfbProto.EncodingZlib||encoding==RfbProto.EncodingZRLE) {
381 byte inf[] = new byte[INFLATE_BUFSIZE]; 381 int len;
382 inflater.setInput(b, 20, b.length-20); 382 inflater.setInput(b, 20, b.length-20);
383 int len = inflater.inflate(inf,20,inf.length-20); 383 do {
384 if (len==INFLATE_BUFSIZE) throw new DataFormatException(); // too large 384 byte inf[] = new byte[INFLATE_BUFSIZE+20];
385 for(int i = 0;i<20;i++) inf[i] = b[i]; 385 len = inflater.inflate(inf,20,inf.length-20);
386 inf[16+0] = (byte) ((len >>> 24) & 0xFF); 386 for(int i = 0;i<20;i++) inf[i] = b[i];
387 inf[16+1] = (byte) ((len >>> 16) & 0xFF); 387 inf[16+0] = (byte) ((len >>> 24) & 0xFF);
388 inf[16+2] = (byte) ((len >>> 8) & 0xFF); 388 inf[16+1] = (byte) ((len >>> 16) & 0xFF);
389 inf[16+3] = (byte) ((len >>> 0) & 0xFF); 389 inf[16+2] = (byte) ((len >>> 8) & 0xFF);
390 multicastqueue.put(inf); 390 inf[16+3] = (byte) ((len >>> 0) & 0xFF);
391 multicastqueue.put(inf);
392 } while (len ==INFLATE_BUFSIZE);
391 is.reset(); 393 is.reset();
392 return; 394 return;
393 } 395 }
394 } 396 }
395 multicastqueue.put(b); 397 multicastqueue.put(b);
553 for (;;) { 555 for (;;) {
554 byte[] b = c.poll(); 556 byte[] b = c.poll();
555 if (b[0]==RfbProto.FramebufferUpdate) { 557 if (b[0]==RfbProto.FramebufferUpdate) {
556 int encoding = ((b[12]*256+b[13])*256+b[14])*256+b[15]; 558 int encoding = ((b[12]*256+b[13])*256+b[14])*256+b[15];
557 if (encoding==RfbProto.EncodingZlib||encoding==RfbProto.EncodingZRLE) { 559 if (encoding==RfbProto.EncodingZlib||encoding==RfbProto.EncodingZRLE) {
558 byte[] c = new byte[INFLATE_BUFSIZE]; 560 byte[] c1 = new byte[INFLATE_BUFSIZE];
559 int clen = ((b[16]*256+b[17])*256+b[18])*256+b[19]; 561 int len=0,len1,clen;
560 deflater.setInput(b,20,clen); 562 do {
561 int len = deflater.deflate(c); 563 clen = ((b[16]*256+b[17])*256+b[18])*256+b[19];
564 deflater.setInput(b,20,clen);
565 len1 = deflater.deflate(c1);
566 if (clen==INFLATE_BUFSIZE) b = c.poll();
567 len += len1;
568 } while(clen== INFLATE_BUFSIZE);
562 byte[] blen = castIntByte(len); 569 byte[] blen = castIntByte(len);
563 os.write(b,0,16); 570 os.write(b,0,16);
564 os.write(blen,0,4); 571 os.write(blen,0,4);
565 os.write(c,0,len); 572 os.write(c1,0,len);
566 } 573 }
567 } else 574 } else
568 os.write(b, 0, b.length); 575 os.write(b, 0, b.length);
569 } 576 }
570 } catch (IOException e) { 577 } catch (IOException e) {