From 2dbcd283545921d4c9a53196e0bd461d2d2fd25d Mon Sep 17 00:00:00 2001 From: Rodwin Spruel Date: Tue, 22 Apr 2025 11:22:20 +0000 Subject: [PATCH] Adding ability to override webp benchmark value --- common/rfb/EncodeManager.cxx | 2 +- common/rfb/ServerCore.cxx | 5 +++++ common/rfb/ServerCore.h | 1 + common/rfb/TightWEBPEncoder.cxx | 5 +++-- unix/vncserver | 9 +++++++++ 5 files changed, 19 insertions(+), 3 deletions(-) diff --git a/common/rfb/EncodeManager.cxx b/common/rfb/EncodeManager.cxx index 5e94cdc..30bfdce 100644 --- a/common/rfb/EncodeManager.cxx +++ b/common/rfb/EncodeManager.cxx @@ -395,7 +395,7 @@ void EncodeManager::doUpdate(bool allowLossy, const Region& changed_, screenArea = pb->getRect().width() * pb->getRect().height(); screenArea *= 1024; screenArea /= 256 * 256; - screenArea *= webpBenchResult; + screenArea *= screenArea *= Server::webpEncodingTime > 0 ? Server::webpEncodingTime : webpBenchResult; // Encoding the entire screen would take this many 1024*msecs, worst case // Calculate how many us we can send webp for, before switching to jpeg diff --git a/common/rfb/ServerCore.cxx b/common/rfb/ServerCore.cxx index 03a69d9..3c15be6 100644 --- a/common/rfb/ServerCore.cxx +++ b/common/rfb/ServerCore.cxx @@ -287,3 +287,8 @@ rfb::PresetParameter rfb::Server::preferBandwidth ("PreferBandwidth", "Set various options for lower bandwidth use. The default is off, aka to prefer quality.", false, bandwidthPreset); + +rfb::IntParameter rfb::Server::webpEncodingTime +("udpPort", + "Sets the benchmak WebP encoding time in KasmVNC. Default is calculated in TightWEBPEncoder benchmark function", + 0, 0, 10000); diff --git a/common/rfb/ServerCore.h b/common/rfb/ServerCore.h index 2035cf6..c3a53e5 100644 --- a/common/rfb/ServerCore.h +++ b/common/rfb/ServerCore.h @@ -91,6 +91,7 @@ namespace rfb { static BoolParameter ignoreClientSettingsKasm; static BoolParameter selfBench; static PresetParameter preferBandwidth; + static IntParameter webpEncodingTime; }; }; diff --git a/common/rfb/TightWEBPEncoder.cxx b/common/rfb/TightWEBPEncoder.cxx index 89d9b3a..2e79c6c 100644 --- a/common/rfb/TightWEBPEncoder.cxx +++ b/common/rfb/TightWEBPEncoder.cxx @@ -259,13 +259,14 @@ void TightWEBPEncoder::writeRect(const PixelBuffer* pb, const Palette& palette) WebPMemoryWriterClear(&wrt); } -// How many milliseconds would it take to encode a 256x256 block at quality 8 +// How many milliseconds would it take to encode a 256x256 block at quality 5 rdr::U32 TightWEBPEncoder::benchmark() const { rdr::U8* buffer; struct timeval start; int stride, i; - const uint8_t quality = 8, method = 2; + // the minimum WebP quality settings used in KasmVNC + const uint8_t quality = 5, method = 0; WebPConfig cfg; WebPPicture pic; WebPMemoryWriter wrt; diff --git a/unix/vncserver b/unix/vncserver index 41fc1be..eb2695f 100755 --- a/unix/vncserver +++ b/unix/vncserver @@ -2068,6 +2068,15 @@ sub DefineConfigToCLIConversion { $value; } }), + KasmVNC::CliOption->new({ + name => 'webpEncodingTime', + configKeys => [ + KasmVNC::ConfigKey->new({ + name => "encoding.video_encoding_mode.webp_encoding_time", + type => KasmVNC::ConfigKey::INT + }) + ] + }), KasmVNC::CliOption->new({ name => 'CompareFB', configKeys => [