Mercurial > hg > Applications > TreeVNC
changeset 578:c6893847c73a
zlib flush margin 16kbytes
author | Shinji KONO <kono@ie.u-ryukyu.ac.jp> |
---|---|
date | Fri, 07 Feb 2020 17:57:05 +0900 |
parents | a236602a9191 |
children | 5bc128c8e6aa |
files | src/main/java/com/glavsoft/rfb/encoding/decoder/ZRLEDecoder.java src/main/java/com/glavsoft/rfb/protocol/ReceiverTask.java |
diffstat | 2 files changed, 23 insertions(+), 23 deletions(-) [+] |
line wrap: on
line diff
--- a/src/main/java/com/glavsoft/rfb/encoding/decoder/ZRLEDecoder.java Fri Feb 07 17:08:01 2020 +0900 +++ b/src/main/java/com/glavsoft/rfb/encoding/decoder/ZRLEDecoder.java Fri Feb 07 17:57:05 2020 +0900 @@ -42,7 +42,8 @@ class TileLoop { private final boolean blocking; - private int deflate_size = 55507; + final int MARGIN = 18000; + final int deflate_size = 60000-MARGIN; private ByteBuffer c1; private int width; // phase2 length private FramebufferUpdateRectangle c1rect; @@ -99,8 +100,8 @@ } private void newMulticastPacket(TreeRFBProto rfb, FramebufferUpdateRectangle rect) { - c1 = rfb.multicastqueue.allocate(deflate_size + 20); - c1.limit(c1.limit() - 20); + c1 = rfb.multicastqueue.allocate(deflate_size + MARGIN); + c1.limit(deflate_size); if (rfb.addSerialNum) c1.putLong(rfb.counter++); if (rfb.checkDelay) @@ -151,23 +152,17 @@ * @param tileH */ - int MAX_ZTILE = 512; - public void multicastPut(TreeRFBProto rfb, boolean last, FramebufferUpdateRectangle rect, byte[] bytes, int offset, int tileW, int tileH) { if (!blocking) return; int span = offset - prevoffset; deflater.setInput(bytes, prevoffset, span); - long prevBytesRead = deflater.getBytesRead(); do { - int output = deflater.deflate(c1, Deflater.NO_FLUSH); + deflater.deflate(c1, Deflater.SYNC_FLUSH); long bytesRead = deflater.getBytesRead(); - if (output == 0) { + if (!deflater.needsInput()) { // compression failed - c1.limit(c1.limit() + 5); - deflater.setInput(bytes, prevoffset, 0); - deflater.deflate(c1, Deflater.FULL_FLUSH); - long spanBytesRead = bytesRead - prevBytesRead; - prevoffset += spanBytesRead; + flushDeflator(bytes); + prevoffset += bytesRead; flushRectangle(rect); flushMuticast(rfb, bytes); if (last && bytesRead == span) { @@ -180,6 +175,7 @@ } while (! deflater.needsInput()); prevoffset = offset; if (last) { + flushDeflator(bytes); flushRectangle(rect); flushMuticast(rfb, bytes); } @@ -200,6 +196,16 @@ } } + private void flushDeflator(byte[] bytes) { + byte [] n = {}; + c1.limit(c1.limit() + MARGIN); + deflater.setInput(n); + deflater.deflate(c1, Deflater.FULL_FLUSH); + if (c1.remaining()==0) { + System.out.println("Multicast packet overrun."); + } + } + /** * fix rectangle header
--- a/src/main/java/com/glavsoft/rfb/protocol/ReceiverTask.java Fri Feb 07 17:08:01 2020 +0900 +++ b/src/main/java/com/glavsoft/rfb/protocol/ReceiverTask.java Fri Feb 07 17:57:05 2020 +0900 @@ -392,8 +392,7 @@ int zippedLength = (int) in.readUInt32(); ZRLEDecoder decoder = new ZRLEDecoder(); ByteBuffer buf = decoder.unzip(in, zippedLength, length, rect.getEncodingType()); - byte[] unzipBytes = buf.array(); - compareBytes(unzipBytes, checkBytes, flushOffset, flushEnd); + compareBytes(buf, checkBytes, flushOffset, flushEnd); } in.reset(); } @@ -410,15 +409,10 @@ } } - private void compareBytes(byte[] compressBytes, byte[] unCompressBytes, int flushOffset, int flushEnd) { + private void compareBytes(ByteBuffer buf, byte[] unCompressBytes, int flushOffset, int flushEnd) { 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"); - } + if (buf.remaining() == span) { + }else { System.out.println("Bytes is not equal length"); }