changeset 615:e7d48fb40262

fix blocking
author Shinji KONO <kono@ie.u-ryukyu.ac.jp>
date Sat, 22 Feb 2020 11:07:27 +0900
parents cab01ab88422
children 69fb13d5f9ec
files Todo.txt src/main/java/com/glavsoft/rfb/encoding/decoder/ZRLEDecoder.java
diffstat 2 files changed, 25 insertions(+), 19 deletions(-) [+]
line wrap: on
line diff
--- a/Todo.txt	Sat Feb 22 01:54:33 2020 +0900
+++ b/Todo.txt	Sat Feb 22 11:07:27 2020 +0900
@@ -1,3 +1,11 @@
+Sat Feb 22 01:58:25 JST 2020
+
+    log 
+       total update rectangle from server
+       compression rate
+       non-blocking packet
+       compression rate after blocking
+
 Wed Feb 19 06:42:34 JST 2020
 
     TreeManager が見つからなかった時に何もしてない
--- a/src/main/java/com/glavsoft/rfb/encoding/decoder/ZRLEDecoder.java	Sat Feb 22 01:54:33 2020 +0900
+++ b/src/main/java/com/glavsoft/rfb/encoding/decoder/ZRLEDecoder.java	Sat Feb 22 11:07:27 2020 +0900
@@ -48,9 +48,8 @@
 		final int MARGIN = 25000;
 		final int deflate_size = 62000-MARGIN;
 		private ByteBuffer c1;
-		private int width; // phase2 length
+		private int width; // of current rectangle (phase 0 or phase 2)
 		private FramebufferUpdateRectangle c0rect,c1rect,rect;
-		private int prevLineOffset;
 		private int prevC1Offset;
 		private int prevC1LineOffset;
 		private int prevoffset;
@@ -79,7 +78,7 @@
 		 */
 
 		public TileLoop(TreeRFBProto rfb, int offset) {
-			prevoffset = prevLineOffset = flushOffset = offset;
+			prevoffset = flushOffset = offset;
 			prevC1Offset = 0;
 			if (rfb == null || offset < deflate_size + MARGIN) {
 				// packet size fit in broadcast send it all at once
@@ -119,7 +118,7 @@
 			c1.putInt(0);     // should be data length
 			prevC1Offset = c1.position();
 			prevC1LineOffset = prevC1Offset;
-			c1rect.width = c1rect.height = 0;
+			c1rect.width = 0;
 			c0rect = null;
 		}
 
@@ -156,6 +155,7 @@
 		public void multicastPut(TreeRFBProto rfb, boolean last, byte[] bytes, int offset, int tileW, int tileH, int tileX, int tileY) throws TransportException {
 			if (!blocking) return;
 			int span = offset - prevoffset;
+			if (span==0) return; // assert(last==true) and all packet is flushed
 			deflater.setInput(bytes, prevoffset, span);
 			width += tileW;
 			c1rect.width += tileW;
@@ -169,11 +169,11 @@
 					assert(prevoffset==offset);
 					// System.out.println("od prevOffset = "+prevoffset+" span = "+(prevoffset-flushOffset)+ " " + c1rect);
 					if (c0rect!=null) { // finish pahse 1
-						flushRectangle(c0rect,prevC1LineOffset);
+						flushRectangle(c0rect,prevC1LineOffset," full c0rect");
 						makeHeaderSpace();
 						c0rect = null;
 					}
-					flushRectangle(c1rect,c1.position()); // phase 2
+					flushRectangle(c1rect,c1.position()," full c1rect"); // phase 2
 					flushMuticast(rfb, bytes);
 					if (last) {
 						return;
@@ -182,8 +182,8 @@
 						if (width<rect.width) { // phase 0
 							c1rect.x = rect.x + width;
 						} else {
-							c1rect.x = 0; // phase 1
-							c1rect.y += tileH;
+							width = 0;
+							c1rect.x = rect.x; // phase 1
 						}
 						return;
 					}
@@ -194,23 +194,22 @@
 				// System.out.println("last prevOffset = "+prevoffset+" span = "+(prevoffset-flushOffset)+ " " + c1rect);
 				flushDeflator(false," last");
 				if (c0rect!=null) {
-					flushRectangle(c0rect,prevC1LineOffset);
+					flushRectangle(c0rect,prevC1LineOffset," last c0rect");
 					makeHeaderSpace();
 					c0rect = null;
 				}
-				flushRectangle(c1rect,c1.position());
+				flushRectangle(c1rect,c1.position()," last c1rect");
 				flushMuticast(rfb, bytes);
 				return;
 			}
-			if (c1rect.height==0) c1rect.height = tileH;
 			if (c1rect.x > rect.x) {  // phase 0
 				assert(c0rect==null);
-				if (c1rect.x + c1rect.width >= rect.x + rect.width) {  // end of phase 0
+				if (width >= rect.width) {  // end of phase 0
 					boolean end = flushDeflator(false," end of phase 0 ");
 					width = 0;
-					flushRectangle(c1rect,c1.position());
+					flushRectangle(c1rect,c1.position()," end of phase 0");
 					c1rect = new FramebufferUpdateRectangle(rect.x,c1rect.y+tileH,0,0);
-					if (end || c1rect.y + tileY >= rect.y+rect.height) {
+					if (end || c1rect.y  >= rect.y+rect.height) {
 						flushMuticast(rfb,bytes);
 						return;
 					}
@@ -228,12 +227,11 @@
 						c0rect = c1rect;
 					}
 					c1rect = new FramebufferUpdateRectangle(rect.x, c0rect.y+c0rect.height, 0, 0);
-					if (end || c1rect.y + tileY >= rect.y+rect.height) {
+					if (end || c1rect.y >= rect.y+rect.height) {
 						c0rect = null; // next will be first phase 1 case
 						flushMuticast(rfb,bytes);
 						return;
 					}
-					prevLineOffset = offset;
 				}
 			}
 		}
@@ -277,10 +275,10 @@
 		 * update position paramater
 		 * send muticast pacate if nessesally
 		 */
-		private void flushRectangle(FramebufferUpdateRectangle rect,int pos) {
+		private void flushRectangle(FramebufferUpdateRectangle rect,int pos,String where) {
 			if (rect.width==0) return;
-			System.out.println("sending broadcast" + rect);
-			if (rect.y >= this.rect.y+this.rect.height)
+			System.out.println("sending broadcast" + rect + where);
+			if (rect.y >= this.rect.y+this.rect.height || rect.height==0)
 				System.out.println("over y broadcast" + this.rect);
 			c1.putShort(prevC1Offset - 16, (short) rect.x);
 			c1.putShort(prevC1Offset - 14, (short) rect.y);