comparison src/main/java/jp/ac/u_ryukyu/treevnc/TreeRFBProto.java @ 499:5455c62a3775

fix multicastput
author oshiro
date Sat, 16 Feb 2019 17:31:34 +0900
parents 8d95d64c33bf
children 57ee5c26e8eb
comparison
equal deleted inserted replaced
498:8d95d64c33bf 499:5455c62a3775
73 private byte[] originalInitData = null; 73 private byte[] originalInitData = null;
74 private boolean childrenMulticast = true; 74 private boolean childrenMulticast = true;
75 private static int uniqueNodeId = 0; // uniquenodeid in all trees (less than MAX_UNIQUE_NODE_ID) 75 private static int uniqueNodeId = 0; // uniquenodeid in all trees (less than MAX_UNIQUE_NODE_ID)
76 private int deflate_size = 65507; 76 private int deflate_size = 65507;
77 private ByteBuffer header; 77 private ByteBuffer header;
78 private ByteBuffer c1;
79 private FramebufferUpdateRectangle c1rect;
78 80
79 public TreeRFBProto(boolean isTreeManager, ViewerInterface viewer) { 81 public TreeRFBProto(boolean isTreeManager, ViewerInterface viewer) {
80 nets.setMyRfb(this); 82 nets.setMyRfb(this);
81 this.isTreeManager = isTreeManager; 83 this.isTreeManager = isTreeManager;
82 this.viewer = viewer; 84 this.viewer = viewer;
756 int inflate_size = rect.width * rect.height * bytePerPixel; 758 int inflate_size = rect.width * rect.height * bytePerPixel;
757 759
758 unzip(inflater, inputs, 0, bytes, inflate_size); 760 unzip(inflater, inputs, 0, bytes, inflate_size);
759 this.header = header; 761 this.header = header;
760 // dump32(inputs); 762 // dump32(inputs);
763 c1 = multicastqueue.allocate(deflate_size);
764 c1rect = new FramebufferUpdateRectangle(rect.x, rect.y, 0, 0);
761 return; 765 return;
762 } 766 }
763 767
764 public void multicastPut(Rectangle rect, byte[] bytes, int prevoffset, int offset, int bytePerPixel) { 768 public void multicastPut(FramebufferUpdateRectangle rect, byte[] bytes, int prevoffset, int offset, int tilex, int tiley) {
765 byte subencoding = bytes[0]; 769 int span = offset - prevoffset;
766 int inputIndex = 1;
767 ByteBuffer c1 = multicastqueue.allocate(deflate_size);
768 int x = rect.x, y = rect.y, w = 0, h = 0, w0 = 0, h0 = 0; 770 int x = rect.x, y = rect.y, w = 0, h = 0, w0 = 0, h0 = 0;
769 int span = rect.width; 771 deflater.setInput(bytes,prevoffset,span);
770 while (inputIndex < INFLATE_BUFSIZE) { 772 c1rect.height = tiley;
771 byte save = bytes[inputIndex-1]; 773 if (c1.remaining() < span || x + tilex >= rect.x + rect.width ) {
772 bytes[inputIndex-1] = subencoding; 774 deflater.deflate(c1, Deflater.FULL_FLUSH);
773 deflater.setInput(bytes,inputIndex-1,span * bytePerPixel +1); 775 c1.flip();
774 if (c1.remaining() < span * bytePerPixel || inputIndex >= INFLATE_BUFSIZE - span * bytePerPixel) { 776 try {
775 deflater.deflate(c1, Deflater.FULL_FLUSH); 777 writeUpdateRectangleWithHeader(c1,header,c1.remaining(), c1rect.x, c1rect.y, c1rect.width, c1rect.height);
776 c1.flip(); 778 } catch (InterruptedException e) {
777 try { 779 e.printStackTrace();
778 writeUpdateRectangleWithHeader(c1,header,c1.remaining(),x+w,y+h,rect.width,h-h0);
779 } catch (InterruptedException e) {
780 e.printStackTrace();
781 }
782 h0 = h;
783 w0 = w;
784 c1 = multicastqueue.allocate(deflate_size);
785 } else {
786 deflater.deflate(c1,Deflater.SYNC_FLUSH);
787 } 780 }
788 bytes[inputIndex-1] = save; 781 c1 = multicastqueue.allocate(deflate_size);
789 w += span; 782 } else {
790 if (w >= rect.width ) { 783 deflater.deflate(c1, Deflater.SYNC_FLUSH);
791 h++; 784 }
792 w = 0; 785 c1rect.width += tilex;
793 w0 = 0; 786 if (c1rect.width >= rect.width) {
794 } 787 c1rect.width = 0;
795 inputIndex += rect.width * bytePerPixel; 788 c1rect.x = 0;
789 c1rect.y += tiley;
796 } 790 }
797 } 791 }
798 792
799 private void writeUpdateRectangleWithHeader(ByteBuffer c1, ByteBuffer header, int len2, int x, int y, int w, int h) throws InterruptedException { 793 private void writeUpdateRectangleWithHeader(ByteBuffer c1, ByteBuffer header, int len2, int x, int y, int w, int h) throws InterruptedException {
800 LinkedList<ByteBuffer> bufs = new LinkedList<ByteBuffer>(); 794 LinkedList<ByteBuffer> bufs = new LinkedList<ByteBuffer>();