|
|
@@ -75,7 +75,7 @@ static const PixelFormat mediumColourPF(8, 8, false, true, |
|
|
|
CConn::CConn(const char* vncServerName, network::Socket* socket=NULL) |
|
|
|
: serverHost(0), serverPort(0), desktop(NULL), |
|
|
|
updateCount(0), pixelCount(0), |
|
|
|
lastServerEncoding((unsigned int)-1) |
|
|
|
lastServerEncoding((unsigned int)-1), bpsEstimate(20000000) |
|
|
|
{ |
|
|
|
setShared(::shared); |
|
|
|
sock = socket; |
|
|
@@ -196,7 +196,7 @@ const char *CConn::connectionInfo() |
|
|
|
strcat(infoText, "\n"); |
|
|
|
|
|
|
|
snprintf(scratch, sizeof(scratch), |
|
|
|
_("Line speed estimate: %d kbit/s"), sock->inStream().kbitsPerSecond()); |
|
|
|
_("Line speed estimate: %d kbit/s"), (int)(bpsEstimate/1000)); |
|
|
|
strcat(infoText, scratch); |
|
|
|
strcat(infoText, "\n"); |
|
|
|
|
|
|
@@ -345,6 +345,10 @@ void CConn::framebufferUpdateStart() |
|
|
|
{ |
|
|
|
CConnection::framebufferUpdateStart(); |
|
|
|
|
|
|
|
// For bandwidth estimate |
|
|
|
gettimeofday(&updateStartTime, NULL); |
|
|
|
updateStartPos = sock->inStream().pos(); |
|
|
|
|
|
|
|
// Update the screen prematurely for very slow updates |
|
|
|
Fl::add_timeout(1.0, handleUpdateTimeout, this); |
|
|
|
} |
|
|
@@ -355,10 +359,29 @@ void CConn::framebufferUpdateStart() |
|
|
|
// appropriately, and then request another incremental update. |
|
|
|
void CConn::framebufferUpdateEnd() |
|
|
|
{ |
|
|
|
unsigned long long elapsed, bps; |
|
|
|
struct timeval now; |
|
|
|
|
|
|
|
CConnection::framebufferUpdateEnd(); |
|
|
|
|
|
|
|
updateCount++; |
|
|
|
|
|
|
|
// Calculate bandwidth everything managed to maintain during this update |
|
|
|
gettimeofday(&now, NULL); |
|
|
|
elapsed = (now.tv_sec - updateStartTime.tv_sec) * 1000000; |
|
|
|
elapsed += now.tv_usec - updateStartTime.tv_usec; |
|
|
|
if (elapsed == 0) |
|
|
|
elapsed = 1; |
|
|
|
bps = (unsigned long long)(sock->inStream().pos() - |
|
|
|
updateStartPos) * 8 * |
|
|
|
1000000 / elapsed; |
|
|
|
// Allow this update to influence things more the longer it took, to a |
|
|
|
// maximum of 20% of the new value. |
|
|
|
if (elapsed > 2000000) |
|
|
|
elapsed = 2000000; |
|
|
|
bpsEstimate = ((bpsEstimate * (10000000 - elapsed)) + |
|
|
|
(bps * elapsed)) / 10000000; |
|
|
|
|
|
|
|
Fl::remove_timeout(handleUpdateTimeout, this); |
|
|
|
desktop->updateWindow(); |
|
|
|
|
|
|
@@ -381,15 +404,11 @@ void CConn::bell() |
|
|
|
|
|
|
|
void CConn::dataRect(const Rect& r, int encoding) |
|
|
|
{ |
|
|
|
sock->inStream().startTiming(); |
|
|
|
|
|
|
|
if (encoding != encodingCopyRect) |
|
|
|
lastServerEncoding = encoding; |
|
|
|
|
|
|
|
CConnection::dataRect(r, encoding); |
|
|
|
|
|
|
|
sock->inStream().stopTiming(); |
|
|
|
|
|
|
|
pixelCount += r.area(); |
|
|
|
} |
|
|
|
|
|
|
@@ -459,28 +478,22 @@ void CConn::resizeFramebuffer() |
|
|
|
// |
|
|
|
void CConn::autoSelectFormatAndEncoding() |
|
|
|
{ |
|
|
|
int kbitsPerSecond = sock->inStream().kbitsPerSecond(); |
|
|
|
unsigned int timeWaited = sock->inStream().timeWaited(); |
|
|
|
bool newFullColour = fullColour; |
|
|
|
int newQualityLevel = ::qualityLevel; |
|
|
|
|
|
|
|
// Always use Tight |
|
|
|
setPreferredEncoding(encodingTight); |
|
|
|
|
|
|
|
// Check that we have a decent bandwidth measurement |
|
|
|
if ((kbitsPerSecond == 0) || (timeWaited < 10000)) |
|
|
|
return; |
|
|
|
|
|
|
|
// Select appropriate quality level |
|
|
|
if (!noJpeg) { |
|
|
|
if (kbitsPerSecond > 16000) |
|
|
|
if (bpsEstimate > 16000000) |
|
|
|
newQualityLevel = 8; |
|
|
|
else |
|
|
|
newQualityLevel = 6; |
|
|
|
|
|
|
|
if (newQualityLevel != ::qualityLevel) { |
|
|
|
vlog.info(_("Throughput %d kbit/s - changing to quality %d"), |
|
|
|
kbitsPerSecond, newQualityLevel); |
|
|
|
(int)(bpsEstimate/1000), newQualityLevel); |
|
|
|
::qualityLevel.setParam(newQualityLevel); |
|
|
|
setQualityLevel(newQualityLevel); |
|
|
|
} |
|
|
@@ -498,14 +511,14 @@ void CConn::autoSelectFormatAndEncoding() |
|
|
|
} |
|
|
|
|
|
|
|
// Select best color level |
|
|
|
newFullColour = (kbitsPerSecond > 256); |
|
|
|
newFullColour = (bpsEstimate > 256000); |
|
|
|
if (newFullColour != fullColour) { |
|
|
|
if (newFullColour) |
|
|
|
vlog.info(_("Throughput %d kbit/s - full color is now enabled"), |
|
|
|
kbitsPerSecond); |
|
|
|
(int)(bpsEstimate/1000)); |
|
|
|
else |
|
|
|
vlog.info(_("Throughput %d kbit/s - full color is now disabled"), |
|
|
|
kbitsPerSecond); |
|
|
|
(int)(bpsEstimate/1000)); |
|
|
|
fullColour.setParam(newFullColour); |
|
|
|
updatePixelFormat(); |
|
|
|
} |