changeset 498:8d95d64c33bf

add multicastPut
author oshiro
date Fri, 15 Feb 2019 20:11:47 +0900
parents 62d6e9180a11
children 5455c62a3775
files src/main/java/com/glavsoft/rfb/encoding/decoder/ZRLEDecoder.java src/main/java/com/glavsoft/rfb/encoding/decoder/ZRLEESender.java src/main/java/com/glavsoft/rfb/protocol/ReceiverTask.java src/main/java/jp/ac/u_ryukyu/treevnc/TreeRFBProto.java
diffstat 4 files changed, 32 insertions(+), 16 deletions(-) [+]
line wrap: on
line diff
--- a/src/main/java/com/glavsoft/rfb/encoding/decoder/ZRLEDecoder.java	Tue Feb 12 16:55:23 2019 +0900
+++ b/src/main/java/com/glavsoft/rfb/encoding/decoder/ZRLEDecoder.java	Fri Feb 15 20:11:47 2019 +0900
@@ -27,6 +27,7 @@
 import com.glavsoft.drawing.Renderer;
 import com.glavsoft.exceptions.TransportException;
 import com.glavsoft.transport.Reader;
+import jp.ac.u_ryukyu.treevnc.TreeRFBProto;
 
 public class ZRLEDecoder extends ZlibDecoder {
 	private static final int MAX_TILE_SIZE = 64;
@@ -40,14 +41,16 @@
 		if (0 == zippedLength) return;
 		int length = rect.width * rect.height * renderer.getBytesPerPixel();
 		byte[] bytes = unzip(reader, zippedLength, length, rect.getEncodingType());
-		decode1(renderer, rect, bytes, zippedLength);
+		decode1(renderer, rect, bytes, zippedLength, null);
     }
     
 	public void decode1(Renderer renderer,
-			FramebufferUpdateRectangle rect, byte[] bytes, int zippedLength) throws TransportException {
+						FramebufferUpdateRectangle rect, byte[] bytes, int zippedLength, TreeRFBProto rfbProto) throws TransportException {
 		int offset = zippedLength;
 		int maxX = rect.x + rect.width;
 		int maxY = rect.y + rect.height;
+		int prevoffset = offset;
+		System.out.println("decode1: "+rect);
         if (null == palette) {
             palette = new int [128];
         }
@@ -86,6 +89,8 @@
 					}
 				}
 			}
+			rfbProto.multicastPut(byte, prevoffset, offset);
+			prevoffset = offset;
 		}
 	}
 
--- a/src/main/java/com/glavsoft/rfb/encoding/decoder/ZRLEESender.java	Tue Feb 12 16:55:23 2019 +0900
+++ b/src/main/java/com/glavsoft/rfb/encoding/decoder/ZRLEESender.java	Fri Feb 15 20:11:47 2019 +0900
@@ -25,15 +25,15 @@
                        FramebufferUpdateRectangle rect) throws TransportException, UnsupportedEncodingException {
         // TreeVNC handling
         int dataLen = getZrleLength(rect, reader);
-        byte[] bytes = new byte[rect.width * rect.height * renderer.getBytesPerPixel()];
         reader.reset();
         if (rfb.hasViewer()) {
             ZRLEDecoder decoder = new ZRLEDecoder();
             if (rect.getEncodingType() == EncodingType.ZRLE) {
                 // ReadSendData convert ZRLE to ZRLEE
                 // unzipped data in the bytes
+                byte[] bytes = new byte[rect.x * rect.y * renderer.getBytesPerPixel()];
                 rfb.readSendData(dataLen, reader, bytes, rect);
-                decoder.decode1(renderer, rect, bytes, 0);
+                decoder.decode1(renderer, rect, bytes, 0, rfb);
                 return;
             } else {
                 // no reencoding is required
@@ -49,6 +49,7 @@
                 return;
             }
         }
+        byte[] bytes = new byte[dataLen];
         rfb.readSendData(dataLen, reader, bytes, rect);
     }
 
--- a/src/main/java/com/glavsoft/rfb/protocol/ReceiverTask.java	Tue Feb 12 16:55:23 2019 +0900
+++ b/src/main/java/com/glavsoft/rfb/protocol/ReceiverTask.java	Fri Feb 15 20:11:47 2019 +0900
@@ -190,7 +190,8 @@
                 StringWriter sw = new StringWriter();
                 PrintWriter pw = new PrintWriter(sw);
                 te.printStackTrace(pw);
-                logger.severe("updateRectangle record failed : " + te.getMessage());
+                logger.severe("updateRectangle record failed : " + te);
+                te.printStackTrace();
                 if (isRunning) {
                     context.cleanUpSession(te.getMessage() + "\n" + sw.toString());
                 }
@@ -314,6 +315,7 @@
                     }
                     rfb.setSharingId(id);
                     if (rfb.hasViewer()){
+                        System.out.println("setscreenparameter");
                         setScreenParameter(rect,singleWidth,singleHeight);
                     }
                 } else if (rect.getEncodingType() == EncodingType.CHECK_DELAY) {
--- a/src/main/java/jp/ac/u_ryukyu/treevnc/TreeRFBProto.java	Tue Feb 12 16:55:23 2019 +0900
+++ b/src/main/java/jp/ac/u_ryukyu/treevnc/TreeRFBProto.java	Fri Feb 15 20:11:47 2019 +0900
@@ -12,6 +12,7 @@
 import com.glavsoft.viewer.ViewerInterface;
 import com.glavsoft.viewer.swing.ConnectionParams;
 
+import java.awt.*;
 import java.io.IOException;
 import java.io.OutputStream;
 import java.io.UnsupportedEncodingException;
@@ -73,6 +74,7 @@
     private boolean childrenMulticast = true;
     private static int uniqueNodeId = 0; // uniquenodeid in all trees (less than MAX_UNIQUE_NODE_ID)
     private int deflate_size = 65507;
+    private ByteBuffer header;
 
     public TreeRFBProto(boolean isTreeManager, ViewerInterface viewer) {
         nets.setMyRfb(this);
@@ -621,6 +623,7 @@
         return position;
     }
 
+
     /**
      * Multicast framebufferUpdate to children.
      * read FrameBuffferUpdate. If it is ZLE, make it ZLEE which is self contained compressed packet.
@@ -629,12 +632,10 @@
      * @param dataLen
      * @param reader
      * @throws TransportException
-     * @throws UnsupportedEncodingException
      */
     public void readSendData(int dataLen, Reader reader, byte[] bytes, FramebufferUpdateRectangle rect)
-            throws TransportException,UnsupportedEncodingException {
+            throws TransportException {
         LinkedList<ByteBuffer> bufs = new LinkedList<ByteBuffer>();
-        int BLOCKSIZE = 64 * 1024;
         int headerLen = rect.getEncodingType() == EncodingType.CHECK_DELAY ? 24 : 16;
         ByteBuffer header = multicastqueue.allocate(headerLen);
         ByteBuffer serial = multicastqueue.allocate(4 + 8);
@@ -650,7 +651,7 @@
 
             if (encoding == EncodingType.ZRLE.getId()
                     || encoding == EncodingType.ZLIB.getId()) {
-                if (true) {
+                if (true)  {
                     try {
                         zrleeBlocking(dataLen, reader, bytes, rect, context.getPixelFormat().bitsPerPixel/8, bufs, header);
                     } catch (DataFormatException e) {
@@ -755,16 +756,23 @@
         int inflate_size = rect.width * rect.height * bytePerPixel;
 
         unzip(inflater, inputs, 0, bytes, inflate_size);
+        this.header = header;
         // dump32(inputs);
-        out.add(ByteBuffer.wrap(bytes));
-        int inputIndex = 0;
+        return;
+    }
+
+    public void multicastPut(Rectangle rect, byte[] bytes, int prevoffset, int offset, int bytePerPixel) {
+        byte subencoding = bytes[0];
+        int inputIndex = 1;
         ByteBuffer c1 = multicastqueue.allocate(deflate_size);
         int x = rect.x, y = rect.y, w = 0,  h = 0, w0 = 0, h0 = 0;
         int span = rect.width;
-        while (inputIndex < inflate_size) {
-            deflater.setInput(bytes,inputIndex,span * bytePerPixel);
-            if (c1.remaining() < span * bytePerPixel || inputIndex >= inflate_size - span * bytePerPixel) {
-                deflater.deflate(c1,Deflater.FULL_FLUSH);
+        while (inputIndex < INFLATE_BUFSIZE) {
+            byte save = bytes[inputIndex-1];
+            bytes[inputIndex-1] = subencoding;
+            deflater.setInput(bytes,inputIndex-1,span * bytePerPixel +1);
+            if (c1.remaining() < span * bytePerPixel || inputIndex >= INFLATE_BUFSIZE - span * bytePerPixel) {
+                deflater.deflate(c1, Deflater.FULL_FLUSH);
                 c1.flip();
                 try {
                     writeUpdateRectangleWithHeader(c1,header,c1.remaining(),x+w,y+h,rect.width,h-h0);
@@ -777,6 +785,7 @@
             } else {
                 deflater.deflate(c1,Deflater.SYNC_FLUSH);
             }
+            bytes[inputIndex-1] = save;
             w += span;
             if (w >= rect.width ) {
                 h++;
@@ -785,7 +794,6 @@
             }
             inputIndex += rect.width * bytePerPixel;
         }
-        return;
     }
 
     private void writeUpdateRectangleWithHeader(ByteBuffer c1, ByteBuffer header, int len2, int x, int y, int w, int h) throws InterruptedException {