blob: 7f39e2c68aae124775e8fb617156ea3fa0b2916c [file] [log] [blame]
Constantin Kaplinskya2adc8d2006-05-25 05:01:55 +00001/* Copyright (C) 2002-2005 RealVNC Ltd. All Rights Reserved.
DRCb4a83232011-08-19 04:57:18 +00002 * Copyright (C) 2011 D. R. Commander. All Rights Reserved.
Constantin Kaplinskya2adc8d2006-05-25 05:01:55 +00003 *
4 * This is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 2 of the License, or
7 * (at your option) any later version.
8 *
9 * This software is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public License
15 * along with this software; if not, write to the Free Software
16 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,
17 * USA.
18 */
Adam Tkac20e0d712008-11-14 14:48:21 +000019#include <stdio.h>
Constantin Kaplinskya2adc8d2006-05-25 05:01:55 +000020#include <rdr/InStream.h>
21#include <rdr/OutStream.h>
22#include <rfb/Exception.h>
23#include <rfb/encodings.h>
24#include <rfb/Encoder.h>
25#include <rfb/ConnParams.h>
26#include <rfb/util.h>
27
28using namespace rfb;
29
30ConnParams::ConnParams()
Adam Tkac3d0af202010-11-18 15:19:47 +000031 : majorVersion(0), minorVersion(0),
Constantin Kaplinskyce0907d2006-09-08 12:55:37 +000032 width(0), height(0), useCopyRect(false),
Pierre Ossmanc5e25602009-03-20 12:59:05 +000033 supportsLocalCursor(false), supportsLocalXCursor(false),
34 supportsDesktopResize(false), supportsExtendedDesktopSize(false),
35 supportsDesktopRename(false), supportsLastRect(false),
Pierre Ossmanc754cce2011-11-14 15:44:11 +000036 supportsSetDesktopSize(false), supportsFence(false),
Pierre Ossmanc898d9a2011-11-14 16:22:23 +000037 supportsContinuousUpdates(false),
Pierre Ossman701ad682011-11-20 15:39:17 +000038 customCompressLevel(false), compressLevel(2),
DRCb4a83232011-08-19 04:57:18 +000039 noJpeg(false), qualityLevel(-1), fineQualityLevel(-1),
Pierre Ossman941d2902014-01-15 13:51:53 +010040 subsampling(SUBSAMP_UNDEFINED), name_(0),
Constantin Kaplinskya2adc8d2006-05-25 05:01:55 +000041 currentEncoding_(encodingRaw), verStrPos(0)
42{
43 setName("");
44}
45
46ConnParams::~ConnParams()
47{
48 delete [] name_;
Constantin Kaplinskya2adc8d2006-05-25 05:01:55 +000049}
50
51bool ConnParams::readVersion(rdr::InStream* is, bool* done)
52{
53 if (verStrPos >= 12) return false;
54 while (is->checkNoWait(1) && verStrPos < 12) {
55 verStr[verStrPos++] = is->readU8();
56 }
57
58 if (verStrPos < 12) {
59 *done = false;
60 return true;
61 }
62 *done = true;
63 verStr[12] = 0;
64 return (sscanf(verStr, "RFB %03d.%03d\n", &majorVersion,&minorVersion) == 2);
65}
66
67void ConnParams::writeVersion(rdr::OutStream* os)
68{
69 char str[13];
70 sprintf(str, "RFB %03d.%03d\n", majorVersion, minorVersion);
71 os->writeBytes(str, 12);
72 os->flush();
73}
74
75void ConnParams::setPF(const PixelFormat& pf)
76{
77 pf_ = pf;
78
79 if (pf.bpp != 8 && pf.bpp != 16 && pf.bpp != 32)
80 throw Exception("setPF: not 8, 16 or 32 bpp?");
81}
82
83void ConnParams::setName(const char* name)
84{
85 delete [] name_;
Adam Tkacd36b6262009-09-04 10:57:20 +000086 name_ = strDup(name);
Constantin Kaplinskya2adc8d2006-05-25 05:01:55 +000087}
88
Peter Åstrand98fe98c2010-02-10 07:43:02 +000089void ConnParams::setEncodings(int nEncodings, const rdr::S32* encodings)
Constantin Kaplinskya2adc8d2006-05-25 05:01:55 +000090{
Constantin Kaplinskya2adc8d2006-05-25 05:01:55 +000091 useCopyRect = false;
92 supportsLocalCursor = false;
93 supportsDesktopResize = false;
Pierre Ossmanc5e25602009-03-20 12:59:05 +000094 supportsExtendedDesktopSize = false;
Constantin Kaplinskya2adc8d2006-05-25 05:01:55 +000095 supportsLocalXCursor = false;
96 supportsLastRect = false;
97 customCompressLevel = false;
98 compressLevel = -1;
99 noJpeg = true;
100 qualityLevel = -1;
DRCb4a83232011-08-19 04:57:18 +0000101 fineQualityLevel = -1;
102 subsampling = SUBSAMP_UNDEFINED;
Constantin Kaplinskya2adc8d2006-05-25 05:01:55 +0000103 currentEncoding_ = encodingRaw;
104
105 for (int i = nEncodings-1; i >= 0; i--) {
Constantin Kaplinskya2adc8d2006-05-25 05:01:55 +0000106 if (encodings[i] == encodingCopyRect)
107 useCopyRect = true;
108 else if (encodings[i] == pseudoEncodingCursor)
109 supportsLocalCursor = true;
110 else if (encodings[i] == pseudoEncodingXCursor)
111 supportsLocalXCursor = true;
112 else if (encodings[i] == pseudoEncodingDesktopSize)
113 supportsDesktopResize = true;
Pierre Ossmanc5e25602009-03-20 12:59:05 +0000114 else if (encodings[i] == pseudoEncodingExtendedDesktopSize)
115 supportsExtendedDesktopSize = true;
Peter Åstrandc39e0782009-01-15 12:21:42 +0000116 else if (encodings[i] == pseudoEncodingDesktopName)
117 supportsDesktopRename = true;
Constantin Kaplinskya2adc8d2006-05-25 05:01:55 +0000118 else if (encodings[i] == pseudoEncodingLastRect)
119 supportsLastRect = true;
Pierre Ossmanc754cce2011-11-14 15:44:11 +0000120 else if (encodings[i] == pseudoEncodingFence)
121 supportsFence = true;
Pierre Ossmanc898d9a2011-11-14 16:22:23 +0000122 else if (encodings[i] == pseudoEncodingContinuousUpdates)
123 supportsContinuousUpdates = true;
Constantin Kaplinskya2adc8d2006-05-25 05:01:55 +0000124 else if (encodings[i] >= pseudoEncodingCompressLevel0 &&
125 encodings[i] <= pseudoEncodingCompressLevel9) {
126 customCompressLevel = true;
127 compressLevel = encodings[i] - pseudoEncodingCompressLevel0;
128 } else if (encodings[i] >= pseudoEncodingQualityLevel0 &&
129 encodings[i] <= pseudoEncodingQualityLevel9) {
130 noJpeg = false;
131 qualityLevel = encodings[i] - pseudoEncodingQualityLevel0;
Adam Tkacea633a72010-07-21 14:12:18 +0000132 } else if (Encoder::supported(encodings[i]))
Constantin Kaplinskya2adc8d2006-05-25 05:01:55 +0000133 currentEncoding_ = encodings[i];
134 }
DRCb4a83232011-08-19 04:57:18 +0000135
136 // If the TurboVNC fine quality/subsampling encodings exist, let them
137 // override the coarse TightVNC quality level
138 for (int i = nEncodings-1; i >= 0; i--) {
139 if (encodings[i] >= pseudoEncodingFineQualityLevel0 + 1 &&
140 encodings[i] <= pseudoEncodingFineQualityLevel100) {
141 noJpeg = false;
142 fineQualityLevel = encodings[i] - pseudoEncodingFineQualityLevel0;
143 } else if (encodings[i] >= pseudoEncodingSubsamp1X &&
144 encodings[i] <= pseudoEncodingSubsampGray) {
145 noJpeg = false;
146 subsampling = (JPEG_SUBSAMP)(encodings[i] - pseudoEncodingSubsamp1X);
147 }
148 }
Constantin Kaplinskya2adc8d2006-05-25 05:01:55 +0000149}