mirror of
https://github.com/moonlight-stream/moonlight-qt
synced 2024-11-13 23:17:09 +00:00
5096ff6496
Fixes #463 Fixes #467
167 lines
7.4 KiB
C++
167 lines
7.4 KiB
C++
#include "streamingpreferences.h"
|
|
|
|
#include <QSettings>
|
|
|
|
#define SER_STREAMSETTINGS "streamsettings"
|
|
#define SER_WIDTH "width"
|
|
#define SER_HEIGHT "height"
|
|
#define SER_FPS "fps"
|
|
#define SER_BITRATE "bitrate"
|
|
#define SER_FULLSCREEN "fullscreen"
|
|
#define SER_VSYNC "vsync"
|
|
#define SER_GAMEOPTS "gameopts"
|
|
#define SER_HOSTAUDIO "hostaudio"
|
|
#define SER_MULTICONT "multicontroller"
|
|
#define SER_AUDIOCFG "audiocfg"
|
|
#define SER_VIDEOCFG "videocfg"
|
|
#define SER_VIDEODEC "videodec"
|
|
#define SER_WINDOWMODE "windowmode"
|
|
#define SER_UNSUPPORTEDFPS "unsupportedfps"
|
|
#define SER_MDNS "mdns"
|
|
#define SER_QUITAPPAFTER "quitAppAfter"
|
|
#define SER_ABSMOUSEMODE "mouseacceleration"
|
|
#define SER_ABSTOUCHMODE "abstouchmode"
|
|
#define SER_STARTWINDOWED "startwindowed"
|
|
#define SER_FRAMEPACING "framepacing"
|
|
#define SER_CONNWARNINGS "connwarnings"
|
|
#define SER_RICHPRESENCE "richpresence"
|
|
#define SER_GAMEPADMOUSE "gamepadmouse"
|
|
#define SER_DEFAULTVER "defaultver"
|
|
#define SER_PACKETSIZE "packetsize"
|
|
#define SER_DETECTNETBLOCKING "detectnetblocking"
|
|
#define SER_SWAPMOUSEBUTTONS "swapmousebuttons"
|
|
#define SER_MUTEONMINIMIZE "muteonminimize"
|
|
#define SER_BACKGROUNDGAMEPAD "backgroundgamepad"
|
|
#define SER_REVERSESCROLL "reversescroll"
|
|
#define SER_SWAPFACEBUTTONS "swapfacebuttons"
|
|
|
|
#define CURRENT_DEFAULT_VER 1
|
|
|
|
StreamingPreferences::StreamingPreferences(QObject *parent)
|
|
: QObject(parent)
|
|
{
|
|
reload();
|
|
}
|
|
|
|
void StreamingPreferences::reload()
|
|
{
|
|
QSettings settings;
|
|
|
|
int defaultVer = settings.value(SER_DEFAULTVER, 0).toInt();
|
|
|
|
#ifdef Q_OS_DARWIN
|
|
recommendedFullScreenMode = WindowMode::WM_FULLSCREEN_DESKTOP;
|
|
#else
|
|
recommendedFullScreenMode = WindowMode::WM_FULLSCREEN;
|
|
#endif
|
|
|
|
width = settings.value(SER_WIDTH, 1280).toInt();
|
|
height = settings.value(SER_HEIGHT, 720).toInt();
|
|
fps = settings.value(SER_FPS, 60).toInt();
|
|
bitrateKbps = settings.value(SER_BITRATE, getDefaultBitrate(width, height, fps)).toInt();
|
|
enableVsync = settings.value(SER_VSYNC, true).toBool();
|
|
gameOptimizations = settings.value(SER_GAMEOPTS, true).toBool();
|
|
playAudioOnHost = settings.value(SER_HOSTAUDIO, false).toBool();
|
|
multiController = settings.value(SER_MULTICONT, true).toBool();
|
|
unsupportedFps = settings.value(SER_UNSUPPORTEDFPS, false).toBool();
|
|
enableMdns = settings.value(SER_MDNS, true).toBool();
|
|
quitAppAfter = settings.value(SER_QUITAPPAFTER, false).toBool();
|
|
absoluteMouseMode = settings.value(SER_ABSMOUSEMODE, false).toBool();
|
|
absoluteTouchMode = settings.value(SER_ABSTOUCHMODE, true).toBool();
|
|
startWindowed = settings.value(SER_STARTWINDOWED, true).toBool();
|
|
framePacing = settings.value(SER_FRAMEPACING, false).toBool();
|
|
connectionWarnings = settings.value(SER_CONNWARNINGS, true).toBool();
|
|
richPresence = settings.value(SER_RICHPRESENCE, true).toBool();
|
|
gamepadMouse = settings.value(SER_GAMEPADMOUSE, true).toBool();
|
|
detectNetworkBlocking = settings.value(SER_DETECTNETBLOCKING, true).toBool();
|
|
packetSize = settings.value(SER_PACKETSIZE, 0).toInt();
|
|
swapMouseButtons = settings.value(SER_SWAPMOUSEBUTTONS, false).toBool();
|
|
muteOnMinimize = settings.value(SER_MUTEONMINIMIZE, false).toBool();
|
|
backgroundGamepad = settings.value(SER_BACKGROUNDGAMEPAD, false).toBool();
|
|
reverseScrollDirection = settings.value(SER_REVERSESCROLL, false).toBool();
|
|
swapFaceButtons = settings.value(SER_SWAPFACEBUTTONS, false).toBool();
|
|
audioConfig = static_cast<AudioConfig>(settings.value(SER_AUDIOCFG,
|
|
static_cast<int>(AudioConfig::AC_STEREO)).toInt());
|
|
videoCodecConfig = static_cast<VideoCodecConfig>(settings.value(SER_VIDEOCFG,
|
|
static_cast<int>(VideoCodecConfig::VCC_AUTO)).toInt());
|
|
videoDecoderSelection = static_cast<VideoDecoderSelection>(settings.value(SER_VIDEODEC,
|
|
static_cast<int>(VideoDecoderSelection::VDS_AUTO)).toInt());
|
|
windowMode = static_cast<WindowMode>(settings.value(SER_WINDOWMODE,
|
|
// Try to load from the old preference value too
|
|
static_cast<int>(settings.value(SER_FULLSCREEN, true).toBool() ?
|
|
recommendedFullScreenMode : WindowMode::WM_WINDOWED)).toInt());
|
|
|
|
// Perform default settings updates as required based on last default version
|
|
if (defaultVer == 0) {
|
|
#ifdef Q_OS_DARWIN
|
|
// Update window mode setting on macOS from full-screen (old default) to borderless windowed (new default)
|
|
if (windowMode == WindowMode::WM_FULLSCREEN) {
|
|
windowMode = WindowMode::WM_FULLSCREEN_DESKTOP;
|
|
}
|
|
#endif
|
|
}
|
|
}
|
|
|
|
void StreamingPreferences::save()
|
|
{
|
|
QSettings settings;
|
|
|
|
settings.setValue(SER_WIDTH, width);
|
|
settings.setValue(SER_HEIGHT, height);
|
|
settings.setValue(SER_FPS, fps);
|
|
settings.setValue(SER_BITRATE, bitrateKbps);
|
|
settings.setValue(SER_VSYNC, enableVsync);
|
|
settings.setValue(SER_GAMEOPTS, gameOptimizations);
|
|
settings.setValue(SER_HOSTAUDIO, playAudioOnHost);
|
|
settings.setValue(SER_MULTICONT, multiController);
|
|
settings.setValue(SER_UNSUPPORTEDFPS, unsupportedFps);
|
|
settings.setValue(SER_MDNS, enableMdns);
|
|
settings.setValue(SER_QUITAPPAFTER, quitAppAfter);
|
|
settings.setValue(SER_ABSMOUSEMODE, absoluteMouseMode);
|
|
settings.setValue(SER_ABSTOUCHMODE, absoluteTouchMode);
|
|
settings.setValue(SER_STARTWINDOWED, startWindowed);
|
|
settings.setValue(SER_FRAMEPACING, framePacing);
|
|
settings.setValue(SER_CONNWARNINGS, connectionWarnings);
|
|
settings.setValue(SER_RICHPRESENCE, richPresence);
|
|
settings.setValue(SER_GAMEPADMOUSE, gamepadMouse);
|
|
settings.setValue(SER_PACKETSIZE, packetSize);
|
|
settings.setValue(SER_DETECTNETBLOCKING, detectNetworkBlocking);
|
|
settings.setValue(SER_AUDIOCFG, static_cast<int>(audioConfig));
|
|
settings.setValue(SER_VIDEOCFG, static_cast<int>(videoCodecConfig));
|
|
settings.setValue(SER_VIDEODEC, static_cast<int>(videoDecoderSelection));
|
|
settings.setValue(SER_WINDOWMODE, static_cast<int>(windowMode));
|
|
settings.setValue(SER_DEFAULTVER, CURRENT_DEFAULT_VER);
|
|
settings.setValue(SER_SWAPMOUSEBUTTONS, swapMouseButtons);
|
|
settings.setValue(SER_MUTEONMINIMIZE, muteOnMinimize);
|
|
settings.setValue(SER_BACKGROUNDGAMEPAD, backgroundGamepad);
|
|
settings.setValue(SER_REVERSESCROLL, reverseScrollDirection);
|
|
settings.setValue(SER_SWAPFACEBUTTONS, swapFaceButtons);
|
|
}
|
|
|
|
int StreamingPreferences::getDefaultBitrate(int width, int height, int fps)
|
|
{
|
|
// This table prefers 16:10 resolutions because they are
|
|
// only slightly more pixels than the 16:9 equivalents, so
|
|
// we don't want to bump those 16:10 resolutions up to the
|
|
// next 16:9 slot.
|
|
|
|
if (width * height <= 640 * 360) {
|
|
return static_cast<int>(1000 * (fps / 30.0));
|
|
}
|
|
else if (width * height <= 854 * 480) {
|
|
return static_cast<int>(1500 * (fps / 30.0));
|
|
}
|
|
// This covers 1280x720 and 1280x800 too
|
|
else if (width * height <= 1366 * 768) {
|
|
return static_cast<int>(5000 * (fps / 30.0));
|
|
}
|
|
else if (width * height <= 1920 * 1200) {
|
|
return static_cast<int>(10000 * (fps / 30.0));
|
|
}
|
|
else if (width * height <= 2560 * 1600) {
|
|
return static_cast<int>(20000 * (fps / 30.0));
|
|
}
|
|
else /* if (width * height <= 3840 * 2160) */ {
|
|
return static_cast<int>(40000 * (fps / 30.0));
|
|
}
|
|
}
|