From 7aff148e9f602047b580f22028d539bcdf023184 Mon Sep 17 00:00:00 2001 From: Cameron Gutman Date: Tue, 21 Jan 2020 19:10:10 -0800 Subject: [PATCH] Add --packet-size command-line option --- app/cli/commandlineparser.cpp | 9 +++++++++ app/settings/streamingpreferences.cpp | 3 +++ app/settings/streamingpreferences.h | 1 + app/streaming/session.cpp | 29 ++++++++++++++++++--------- 4 files changed, 33 insertions(+), 9 deletions(-) diff --git a/app/cli/commandlineparser.cpp b/app/cli/commandlineparser.cpp index e10e7501..6faf15ea 100644 --- a/app/cli/commandlineparser.cpp +++ b/app/cli/commandlineparser.cpp @@ -280,6 +280,7 @@ void StreamCommandLineParser::parse(const QStringList &args, StreamingPreference parser.addToggleOption("vsync", "V-Sync"); parser.addValueOption("fps", "FPS"); parser.addValueOption("bitrate", "bitrate in Kbps"); + parser.addValueOption("packet-size", "video packet size"); parser.addChoiceOption("display-mode", "display mode", m_WindowModeMap.keys()); parser.addChoiceOption("audio-config", "audio config", m_AudioConfigMap.keys()); parser.addToggleOption("multi-controller", "multiple controller support"); @@ -345,6 +346,14 @@ void StreamCommandLineParser::parse(const QStringList &args, StreamingPreference preferences->width, preferences->height, preferences->fps); } + // Resolve --packet-size option + if (parser.isSet("packet-size")) { + preferences->packetSize = parser.getIntOption("packet-size"); + if (preferences->packetSize < 1024) { + parser.showError("Packet size must be greater than 1024 bytes"); + } + } + // Resolve --display option if (parser.isSet("display-mode")) { preferences->windowMode = mapValue(m_WindowModeMap, parser.getChoiceOptionValue("display-mode")); diff --git a/app/settings/streamingpreferences.cpp b/app/settings/streamingpreferences.cpp index fa5141bb..8bc4c294 100644 --- a/app/settings/streamingpreferences.cpp +++ b/app/settings/streamingpreferences.cpp @@ -26,6 +26,7 @@ #define SER_RICHPRESENCE "richpresence" #define SER_GAMEPADMOUSE "gamepadmouse" #define SER_DEFAULTVER "defaultver" +#define SER_PACKETSIZE "packetsize" #define CURRENT_DEFAULT_VER 1 @@ -64,6 +65,7 @@ void StreamingPreferences::reload() connectionWarnings = settings.value(SER_CONNWARNINGS, true).toBool(); richPresence = settings.value(SER_RICHPRESENCE, true).toBool(); gamepadMouse = settings.value(SER_GAMEPADMOUSE, true).toBool(); + packetSize = settings.value(SER_PACKETSIZE, 0).toInt(); audioConfig = static_cast(settings.value(SER_AUDIOCFG, static_cast(AudioConfig::AC_STEREO)).toInt()); videoCodecConfig = static_cast(settings.value(SER_VIDEOCFG, @@ -107,6 +109,7 @@ void StreamingPreferences::save() settings.setValue(SER_CONNWARNINGS, connectionWarnings); settings.setValue(SER_RICHPRESENCE, richPresence); settings.setValue(SER_GAMEPADMOUSE, gamepadMouse); + settings.setValue(SER_PACKETSIZE, packetSize); settings.setValue(SER_AUDIOCFG, static_cast(audioConfig)); settings.setValue(SER_VIDEOCFG, static_cast(videoCodecConfig)); settings.setValue(SER_VIDEODEC, static_cast(videoDecoderSelection)); diff --git a/app/settings/streamingpreferences.h b/app/settings/streamingpreferences.h index 93e10efb..bf94edde 100644 --- a/app/settings/streamingpreferences.h +++ b/app/settings/streamingpreferences.h @@ -90,6 +90,7 @@ public: bool connectionWarnings; bool richPresence; bool gamepadMouse; + int packetSize; AudioConfig audioConfig; VideoCodecConfig videoCodecConfig; VideoDecoderSelection videoDecoderSelection; diff --git a/app/streaming/session.cpp b/app/streaming/session.cpp index 9af42531..30a60c11 100644 --- a/app/streaming/session.cpp +++ b/app/streaming/session.cpp @@ -942,17 +942,28 @@ void Session::exec(int displayOriginX, int displayOriginY) hostInfo.serverInfoGfeVersion = siGfeVersion.data(); } - // isReachableOverVpn() does network I/O, so we only attempt to check - // VPN reachability if we've already contacted the PC successfully - if (m_Computer->isReachableOverVpn()) { - // It looks like our route to this PC is over a VPN. - // Treat it as remote even if the target address is in RFC 1918 address space. - m_StreamConfig.streamingRemotely = STREAM_CFG_REMOTE; - m_StreamConfig.packetSize = 1024; + if (m_Preferences->packetSize != 0) { + // Override default packet size and remote streaming detection + // NB: Using STREAM_CFG_AUTO will cap our packet size at 1024 for remote hosts. + m_StreamConfig.streamingRemotely = STREAM_CFG_LOCAL; + m_StreamConfig.packetSize = m_Preferences->packetSize; + SDL_LogWarn(SDL_LOG_CATEGORY_APPLICATION, + "Using custom packet size: %d bytes", + m_Preferences->packetSize); } else { - m_StreamConfig.streamingRemotely = STREAM_CFG_AUTO; - m_StreamConfig.packetSize = 1392; + // isReachableOverVpn() does network I/O, so we only attempt to check + // VPN reachability if we've already contacted the PC successfully + if (m_Computer->isReachableOverVpn()) { + // It looks like our route to this PC is over a VPN. + // Treat it as remote even if the target address is in RFC 1918 address space. + m_StreamConfig.streamingRemotely = STREAM_CFG_REMOTE; + m_StreamConfig.packetSize = 1024; + } + else { + m_StreamConfig.streamingRemotely = STREAM_CFG_AUTO; + m_StreamConfig.packetSize = 1392; + } } int err = LiStartConnection(&hostInfo, &m_StreamConfig, &k_ConnCallbacks,