Mercurial > hg > Applications > TreeVNC
changeset 577:a236602a9191
fix multicastput
author | riono |
---|---|
date | Fri, 07 Feb 2020 17:08:01 +0900 |
parents | d5138119d8c4 |
children | c6893847c73a |
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 |
diffstat | 3 files changed, 38 insertions(+), 30 deletions(-) [+] |
line wrap: on
line diff
--- a/src/main/java/com/glavsoft/rfb/encoding/decoder/ZRLEDecoder.java Fri Feb 07 14:50:01 2020 +0900 +++ b/src/main/java/com/glavsoft/rfb/encoding/decoder/ZRLEDecoder.java Fri Feb 07 17:08:01 2020 +0900 @@ -75,9 +75,8 @@ */ public TileLoop(TreeRFBProto rfb, int offset) { - prevoffset = prevLineOffset = offset; + prevoffset = prevLineOffset = flushOffset = offset; prevC1Offset = 0; - flushOffset = 0; if (rfb == null || offset < deflate_size + spanGap) { // packet size fit in broadcast send it all at once blocking = false; @@ -155,30 +154,35 @@ int MAX_ZTILE = 512; public void multicastPut(TreeRFBProto rfb, boolean last, FramebufferUpdateRectangle rect, byte[] bytes, int offset, int tileW, int tileH) { - boolean flush = false; if (!blocking) return; int span = offset - prevoffset; deflater.setInput(bytes, prevoffset, span); - int output = deflater.deflate(c1, Deflater.NO_FLUSH); - if (output==0 && ! deflater.needsInput() ) { - // compression failed - deflater.setInput(bytes, prevoffset, 0); - output = deflater.deflate(c1, Deflater.FULL_FLUSH); - prevoffset = offset; + long prevBytesRead = deflater.getBytesRead(); + do { + int output = deflater.deflate(c1, Deflater.NO_FLUSH); + long bytesRead = deflater.getBytesRead(); + if (output == 0) { + // compression failed + c1.limit(c1.limit() + 5); + deflater.setInput(bytes, prevoffset, 0); + deflater.deflate(c1, Deflater.FULL_FLUSH); + long spanBytesRead = bytesRead - prevBytesRead; + prevoffset += spanBytesRead; + flushRectangle(rect); + flushMuticast(rfb, bytes); + if (last && bytesRead == span) { + return; + } else { + newMulticastPacket(rfb, rect); + deflater.deflate(c1, Deflater.NO_FLUSH); + } + } + } while (! deflater.needsInput()); + prevoffset = offset; + if (last) { flushRectangle(rect); flushMuticast(rfb, bytes); - if (!last) { - newMulticastPacket(rfb, rect); - deflater.deflate(c1, Deflater.NO_FLUSH); - } else { - deflater.deflate(c1, Deflater.NO_FLUSH); - deflater.finish(); - flushMuticast(rfb, bytes); - } - return ; } - // deflater.deflate(c1); - prevoffset = offset; width += tileW; if (c1rect.x > rect.x) { // phase 0 if (c1rect.x + c1rect.width < rect.x + rect.width) { @@ -249,8 +253,8 @@ int zippedLength = (int) reader.readUInt32(); if (0 == zippedLength) return; int length = rect.width * rect.height * renderer.getBytesPerPixel(); - byte[] bytes = unzip(reader, zippedLength, length, rect.getEncodingType()).array(); - decode1(renderer, null, rect, bytes, zippedLength, null); + ByteBuffer buf = unzip(reader, zippedLength, length, rect.getEncodingType()); + decode1(renderer, null, rect, buf, zippedLength, null); } @@ -261,14 +265,15 @@ int zippedLength = (int) reader.readUInt32(); if (0 == zippedLength) return; int length = rect.width * rect.height * renderer.getBytesPerPixel(); - byte[] bytes = unzip(reader, zippedLength, length, rect.getEncodingType()).array(); - decode1(renderer, header, rect, bytes, zippedLength, rfb); + ByteBuffer buf = unzip(reader, zippedLength, length, rect.getEncodingType()); + decode1(renderer, header, rect, buf, zippedLength, rfb); } - public void decode1(Renderer renderer, ByteBuffer header, FramebufferUpdateRectangle rect, byte[] bytes, int zippedLength, TreeRFBProto rfbProto) throws TransportException { + public void decode1(Renderer renderer, ByteBuffer header, FramebufferUpdateRectangle rect, ByteBuffer buf, int zippedLength, TreeRFBProto rfbProto) throws TransportException { int offset = zippedLength; int maxX = rect.x + rect.width; int maxY = rect.y + rect.height; + byte[] bytes = buf.array(); TileLoop tileloop = new TileLoop(rfbProto, zippedLength); //System.out.println("decode1: "+rect.toString());
--- a/src/main/java/com/glavsoft/rfb/encoding/decoder/ZRLEESender.java Fri Feb 07 14:50:01 2020 +0900 +++ b/src/main/java/com/glavsoft/rfb/encoding/decoder/ZRLEESender.java Fri Feb 07 17:08:01 2020 +0900 @@ -34,12 +34,12 @@ if (rect.getEncodingType() == EncodingType.ZRLE) { // ReadSendData convert ZRLE to ZRLEE // unzipped data in the bytes - byte[] bytes = new byte[rect.width * rect.height * renderer.getBytesPerPixel()]; + ByteBuffer buf = ByteBuffer.allocate(rect.width * rect.height * renderer.getBytesPerPixel()); if (rfb.multicastBlocking) { decoder.multicastDecode(reader, renderer, rect, rfb); } else { - ByteBuffer header = rfb.readSendData(dataLen, reader, bytes, rect); - decoder.decode1(renderer, header, rect, bytes, 0, rfb); + ByteBuffer header = rfb.readSendData(dataLen, reader, buf.array(), rect); + decoder.decode1(renderer, header, rect, buf, 0, rfb); } return; } else {
--- a/src/main/java/com/glavsoft/rfb/protocol/ReceiverTask.java Fri Feb 07 14:50:01 2020 +0900 +++ b/src/main/java/com/glavsoft/rfb/protocol/ReceiverTask.java Fri Feb 07 17:08:01 2020 +0900 @@ -43,6 +43,7 @@ import java.io.*; import java.nio.ByteBuffer; +import java.util.Arrays; import java.util.LinkedList; import java.util.Timer; import java.util.logging.Logger; @@ -410,8 +411,10 @@ } private void compareBytes(byte[] compressBytes, byte[] unCompressBytes, int flushOffset, int flushEnd) { - if (compressBytes.length == (flushEnd - flushOffset)) { - if (Objects.deepEquals(compressBytes, unCompressBytes)) { + int span = flushEnd - flushOffset; + if (compressBytes.length == span) { + byte[] offsetBytes = Arrays.copyOfRange(unCompressBytes, flushOffset, flushEnd); + if (Objects.deepEquals(compressBytes, offsetBytes)) { System.out.println("Bytes compair is true"); } else { System.out.println("Bytes is not equal elements");