public void HandleSetEncodingsTest(bool forceConnect, VncEncoding expectedEncoding)
        {
            using (var stream = new TestStream())
            {
                // Have the client send a list of supported encodings, including
                // Raw and zlib
                VncStream clientStream = new VncStream(stream.Input);
                clientStream.SendByte(0);
                clientStream.SendUInt16BE(2); // 2 encodings are supported
                clientStream.SendUInt32BE((uint)VncEncoding.Raw);
                clientStream.SendUInt32BE((uint)VncEncoding.Zlib);
                stream.Input.Position = 0;

                var session = new VncServerSession();
                session.Connect(stream, null, startThread: false, forceConnected: forceConnect);

                session.HandleSetEncodings();

                // The server should not have written any output, but switched
                // to zlib encoding
                VncStream serverStream = new VncStream(stream.Output);
                Assert.Equal(0, serverStream.Stream.Length);
                stream.Output.Position = 0;

                Assert.Equal(expectedEncoding, session.Encoder.Encoding);
            }
        }
Example #2
0
        private void RecordEncoderTransfer(VncEncoding encoding, int rawLength, int encodedLength)
        {
            if (!this.Statistics.ContainsKey(encoding))
            {
                this.Statistics.Add(encoding, new EncoderStatistics());
            }

            this.Statistics[encoding].EncodedBytes += (ulong)encodedLength;
            this.Statistics[encoding].RawBytes     += (ulong)rawLength;
            this.Statistics[encoding].Rectangles++;
        }
        void AddRegion(VncRectangle region, VncEncoding encoding, byte[] contents)
        {
            _fbuRectangles.Add(new Rectangle()
            {
                Region = region, Encoding = encoding, Contents = contents
            });

            // Avoid the overflow of updated rectangle count.
            // NOTE: EndUpdate may implicitly add one for desktop resizing.
            if (_fbuRectangles.Count >= ushort.MaxValue - 1)
            {
                FramebufferManualEndUpdate(); FramebufferManualBeginUpdate();
            }
        }
        void HandleSetEncodings()
        {
            _c.Receive(1);

            int encodingCount  = _c.ReceiveUInt16BE(); VncStream.SanityCheck(encodingCount <= 0x1ff);
            var clientEncoding = new VncEncoding[encodingCount];

            for (int i = 0; i < clientEncoding.Length; i++)
            {
                uint encoding = _c.ReceiveUInt32BE();
                clientEncoding[i] = (VncEncoding)encoding;
            }
            _clientEncoding = clientEncoding;
        }
Example #5
0
        private static int GetLevel(IVncServerSession vncServerSession, VncEncoding lower, VncEncoding upper, int defaultValue)
        {
            if (vncServerSession?.ClientEncodings == null)
            {
                return(defaultValue);
            }

            foreach (var encoding in vncServerSession.ClientEncodings)
            {
                if (encoding >= lower && encoding <= upper)
                {
                    return(encoding - lower);
                }
            }

            return(defaultValue);
        }
Example #6
0
        private void NegotiateEncodings()
        {
            var encodings = new VncEncoding[]
            {
                VncEncoding.Zlib,
                VncEncoding.Hextile,
                VncEncoding.CopyRect,
                VncEncoding.Raw,
                VncEncoding.PseudoDesktopSize
            };

            this.c.Send(new[] { (byte)2, (byte)0 });
            this.c.SendUInt16BE((ushort)encodings.Length);
            foreach (var encoding in encodings)
            {
                this.c.SendUInt32BE((uint)encoding);
            }
        }
        public void GetTightQualityLevelTest(int expectedQualityLevel, VncEncoding encoding)
        {
            Collection <VncEncoding> encodings = new Collection <VncEncoding>();

            encodings.Add(VncEncoding.Raw);
            encodings.Add(VncEncoding.Tight);
            encodings.Add(encoding);

            var mock = new Mock <IVncServerSession>();

            mock
            .Setup(m => m.ClientEncodings)
            .Returns(encodings);

            var compressionLevel = TightEncoder.GetQualityLevel(mock.Object);

            Assert.Equal(expectedQualityLevel, compressionLevel);
        }
        private void AddRegion(VncRectangle region, VncEncoding encoding, byte[] contents)
        {
            this.fbuRectangles.Add(new Rectangle() { Region = region, Encoding = encoding, Contents = contents });

            // Avoid the overflow of updated rectangle count.
            // NOTE: EndUpdate may implicitly add one for desktop resizing.
            if (this.fbuRectangles.Count >= ushort.MaxValue - 1)
            {
                this.FramebufferManualEndUpdate();
                this.FramebufferManualBeginUpdate();
            }
        }
        private void HandleSetEncodings()
        {
            this.c.Receive(1);

            int encodingCount = this.c.ReceiveUInt16BE();
            VncStream.SanityCheck(encodingCount <= 0x1ff);
            var clientEncoding = new VncEncoding[encodingCount];
            for (int i = 0; i < clientEncoding.Length; i++)
            {
                uint encoding = this.c.ReceiveUInt32BE();
                clientEncoding[i] = (VncEncoding)encoding;
            }

            this.clientEncoding = clientEncoding;
        }
Example #10
0
        private void NegotiateEncodings()
        {
            var encodings = new VncEncoding[]
            {
                VncEncoding.Zlib,
                VncEncoding.Hextile,
                VncEncoding.CopyRect,
                VncEncoding.Raw,
                VncEncoding.PseudoDesktopSize
            };

            this.c.Send(new[] { (byte)2, (byte)0 });
            this.c.SendUInt16BE((ushort)encodings.Length);
            foreach (var encoding in encodings)
            {
                this.c.SendUInt32BE((uint)encoding);
            }
        }