comparison src/myVncProxy/MyRfbProto.java @ 78:5970410efee7

modify VncProxyService. EncodingRAW -> EncodingZlib
author e085711
date Fri, 29 Jul 2011 19:17:31 +0900
parents fe5925bb9a7e
children 712a047908df 762d2b7f1db2
comparison
equal deleted inserted replaced
77:fe5925bb9a7e 78:5970410efee7
139 void addSockTmp(Socket sock) { 139 void addSockTmp(Socket sock) {
140 System.out.println("connected " + sock.getInetAddress()); 140 System.out.println("connected " + sock.getInetAddress());
141 cliListTmp.add(sock); 141 cliListTmp.add(sock);
142 } 142 }
143 143
144 void mark(int len) throws IOException {
145 is.mark(len);
146 }
147
148 void reset() throws IOException {
149 is.reset();
150 }
151
152 boolean markSupported() { 144 boolean markSupported() {
153 return is.markSupported(); 145 return is.markSupported();
154 } 146 }
155 147
156 void readServerInit() throws IOException { 148 void readServerInit() throws IOException {
157 149
158 mark(255); 150 is.mark(255);
159 skipBytes(20); 151 skipBytes(20);
160 int nlen = readU32(); 152 int nlen = readU32();
161 int blen = 20 + 4 + nlen; 153 int blen = 20 + 4 + nlen;
162 initData = new byte[blen]; 154 initData = new byte[blen];
163 reset(); 155 is.reset();
164 156
165 mark(blen); 157 is.mark(blen);
166 readFully(initData); 158 readFully(initData);
167 reset(); 159 is.reset();
168 160
169 framebufferWidth = readU16(); 161 framebufferWidth = readU16();
170 framebufferHeight = readU16(); 162 framebufferHeight = readU16();
171 bitsPerPixel = readU8(); 163 bitsPerPixel = readU8();
172 depth = readU8(); 164 depth = readU8();
300 void printNumBytesRead() { 292 void printNumBytesRead() {
301 System.out.println("numBytesRead=" + numBytesRead); 293 System.out.println("numBytesRead=" + numBytesRead);
302 } 294 }
303 295
304 void bufResetSend(int size) throws IOException { 296 void bufResetSend(int size) throws IOException {
305 reset(); 297 is.reset();
306 int len = size; 298 int len = size;
307 if (available() < size) 299 if (available() < size)
308 len = available(); 300 len = available();
309 byte buffer[] = new byte[len]; 301 byte buffer[] = new byte[len];
310 readFully(buffer); 302 readFully(buffer);
311 sendData(buffer); 303 sendData(buffer);
312 } 304 }
313 305
314 306
315 void regiFramebufferUpdate() throws IOException { 307 void regiFramebufferUpdate() throws IOException {
316 mark(20); 308 is.mark(20);
317 messageType = readU8(); 309 messageType = readU8();
318 skipBytes(1); 310 skipBytes(1);
319 rectangles = readU16(); 311 rectangles = readU16();
320 rectX = readU16(); 312 rectX = readU16();
321 rectY = readU16(); 313 rectY = readU16();
322 rectW = readU16(); 314 rectW = readU16();
323 rectH = readU16(); 315 rectH = readU16();
324 encoding = readU32(); 316 encoding = readU32();
317 System.out.println("encoding = "+encoding);
325 if (encoding == 16) 318 if (encoding == 16)
326 zLen = readU32(); 319 zLen = readU32();
327 reset(); 320 is.reset();
328 /* 321 /*
329 int dataLen; 322 int dataLen;
330 switch (encoding) { 323 switch (encoding) {
331 case RfbProto.EncodingRaw: 324 case RfbProto.EncodingRaw:
332 dataLen = rectW * rectH * 4 + 16; 325 dataLen = rectW * rectH * 4 + 16;
358 int checkAndMark() throws IOException { 351 int checkAndMark() throws IOException {
359 int dataLen; 352 int dataLen;
360 switch (encoding) { 353 switch (encoding) {
361 case RfbProto.EncodingRaw: 354 case RfbProto.EncodingRaw:
362 dataLen = rectW * rectH * 4 + 16; 355 dataLen = rectW * rectH * 4 + 16;
363 mark(dataLen); 356 is.mark(dataLen);
364 break; 357 break;
365 case RfbProto.EncodingCopyRect: 358 case RfbProto.EncodingCopyRect:
366 dataLen = 16 + 4; 359 dataLen = 16 + 4;
367 mark(dataLen); 360 is.mark(dataLen);
368 break; 361 break;
369 case RfbProto.EncodingRRE: 362 case RfbProto.EncodingRRE:
370 case RfbProto.EncodingCoRRE: 363 case RfbProto.EncodingCoRRE:
371 case RfbProto.EncodingHextile: 364 case RfbProto.EncodingHextile:
372 case RfbProto.EncodingZlib: 365 case RfbProto.EncodingZlib:
373 case RfbProto.EncodingTight: 366 case RfbProto.EncodingTight:
374 case RfbProto.EncodingZRLE: 367 case RfbProto.EncodingZRLE:
375 dataLen = zLen + 20; 368 dataLen = zLen + 20;
376 mark(dataLen); 369 is.mark(dataLen);
370 break;
371 case RfbProto.EncodingXCursor:
372 case RfbProto.EncodingRichCursor:
373 int pixArray = rectW * rectH * 4;
374 int u8Array = (int)Math.floor((rectW + 7)/8) * rectH;
375 dataLen = pixArray + u8Array;
376 printFramebufferUpdate();
377 is.mark(dataLen);
377 break; 378 break;
378 default: 379 default:
379 dataLen = 1000000; 380 dataLen = 1000000;
380 mark(dataLen); 381 is.mark(dataLen);
381 } 382 }
382 return dataLen; 383 return dataLen;
383 } 384 }
384 385
385 void readSendData(int dataLen) throws IOException { 386 void readSendData(int dataLen) throws IOException {
386 byte buffer[] = new byte[dataLen]; 387 byte buffer[] = new byte[dataLen];
387 readFully(buffer); 388 readFully(buffer);
388 multicastqueue.put(buffer); 389 multicastqueue.put(buffer);
389 reset(); 390 is.reset();
390 391
391 /* 392 /*
392 for (Socket cli : cliList) { 393 for (Socket cli : cliList) {
393 try { 394 try {
394 OutputStream out = cli.getOutputStream(); 395 OutputStream out = cli.getOutputStream();
467 void printFramebufferUpdate() { 468 void printFramebufferUpdate() {
468 469
469 System.out.println("messageType=" + messageType); 470 System.out.println("messageType=" + messageType);
470 System.out.println("rectangles=" + rectangles); 471 System.out.println("rectangles=" + rectangles);
471 System.out.println("encoding=" + encoding); 472 System.out.println("encoding=" + encoding);
473 System.out.println("rectX = "+rectX+": rectY = "+rectY);
474 System.out.println("rectW = "+rectW+": rectH = "+rectH);
472 switch (encoding) { 475 switch (encoding) {
473 case RfbProto.EncodingRaw: 476 case RfbProto.EncodingRaw:
474 System.out.println("rectW * rectH * 4 + 16 =" + rectW * rectH * 4 477 System.out.println("rectW * rectH * 4 + 16 =" + rectW * rectH * 4
475 + 16); 478 + 16);
476 break; 479 break;