2018-06-28 06:15:13 +00:00
|
|
|
#include "streamingpreferences.h"
|
2018-07-26 07:41:46 +00:00
|
|
|
#include "streaming/session.hpp"
|
2018-09-04 04:21:37 +00:00
|
|
|
#include "streaming/streamutils.h"
|
2018-06-28 06:15:13 +00:00
|
|
|
|
|
|
|
#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"
|
2018-08-21 05:25:19 +00:00
|
|
|
#define SER_VSYNC "vsync"
|
2018-06-28 06:15:13 +00:00
|
|
|
#define SER_GAMEOPTS "gameopts"
|
|
|
|
#define SER_HOSTAUDIO "hostaudio"
|
|
|
|
#define SER_MULTICONT "multicontroller"
|
|
|
|
#define SER_AUDIOCFG "audiocfg"
|
|
|
|
#define SER_VIDEOCFG "videocfg"
|
2018-07-09 00:33:47 +00:00
|
|
|
#define SER_VIDEODEC "videodec"
|
2018-09-04 02:17:34 +00:00
|
|
|
#define SER_WINDOWMODE "windowmode"
|
2018-06-28 06:15:13 +00:00
|
|
|
|
|
|
|
StreamingPreferences::StreamingPreferences()
|
|
|
|
{
|
|
|
|
reload();
|
|
|
|
}
|
|
|
|
|
|
|
|
void StreamingPreferences::reload()
|
|
|
|
{
|
|
|
|
QSettings settings;
|
|
|
|
|
|
|
|
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();
|
2018-08-21 05:25:19 +00:00
|
|
|
enableVsync = settings.value(SER_VSYNC, true).toBool();
|
2018-07-09 00:33:47 +00:00
|
|
|
gameOptimizations = settings.value(SER_GAMEOPTS, true).toBool();
|
2018-06-28 06:15:13 +00:00
|
|
|
playAudioOnHost = settings.value(SER_HOSTAUDIO, false).toBool();
|
|
|
|
multiController = settings.value(SER_MULTICONT, true).toBool();
|
|
|
|
audioConfig = static_cast<AudioConfig>(settings.value(SER_AUDIOCFG,
|
2018-09-08 05:51:56 +00:00
|
|
|
static_cast<int>(AudioConfig::AC_FORCE_STEREO)).toInt());
|
2018-06-28 06:15:13 +00:00
|
|
|
videoCodecConfig = static_cast<VideoCodecConfig>(settings.value(SER_VIDEOCFG,
|
|
|
|
static_cast<int>(VideoCodecConfig::VCC_AUTO)).toInt());
|
2018-07-09 00:33:47 +00:00
|
|
|
videoDecoderSelection = static_cast<VideoDecoderSelection>(settings.value(SER_VIDEODEC,
|
|
|
|
static_cast<int>(VideoDecoderSelection::VDS_AUTO)).toInt());
|
2018-09-04 02:17:34 +00:00
|
|
|
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() ?
|
|
|
|
WindowMode::WM_FULLSCREEN : WindowMode::WM_WINDOWED)).toInt());
|
2018-06-28 06:15:13 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
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);
|
2018-08-21 05:25:19 +00:00
|
|
|
settings.setValue(SER_VSYNC, enableVsync);
|
2018-07-09 00:33:47 +00:00
|
|
|
settings.setValue(SER_GAMEOPTS, gameOptimizations);
|
2018-06-28 06:15:13 +00:00
|
|
|
settings.setValue(SER_HOSTAUDIO, playAudioOnHost);
|
|
|
|
settings.setValue(SER_MULTICONT, multiController);
|
|
|
|
settings.setValue(SER_AUDIOCFG, static_cast<int>(audioConfig));
|
|
|
|
settings.setValue(SER_VIDEOCFG, static_cast<int>(videoCodecConfig));
|
2018-07-09 00:33:47 +00:00
|
|
|
settings.setValue(SER_VIDEODEC, static_cast<int>(videoDecoderSelection));
|
2018-09-04 02:17:34 +00:00
|
|
|
settings.setValue(SER_WINDOWMODE, static_cast<int>(windowMode));
|
2018-06-28 06:15:13 +00:00
|
|
|
}
|
|
|
|
|
2018-07-26 07:41:46 +00:00
|
|
|
bool StreamingPreferences::hasAnyHardwareAcceleration()
|
|
|
|
{
|
|
|
|
// Always use VDS_AUTO to avoid spamming the user with warnings
|
|
|
|
// if they've forced software decoding.
|
|
|
|
return Session::isHardwareDecodeAvailable(VDS_AUTO,
|
|
|
|
VIDEO_FORMAT_H264,
|
|
|
|
1920, 1080, 60);
|
|
|
|
}
|
|
|
|
|
2018-08-12 05:42:25 +00:00
|
|
|
bool StreamingPreferences::isRunningWayland()
|
|
|
|
{
|
|
|
|
return qgetenv("XDG_SESSION_TYPE") == QByteArray("wayland");
|
|
|
|
}
|
|
|
|
|
2018-07-28 07:25:52 +00:00
|
|
|
int StreamingPreferences::getMaximumStreamingFrameRate()
|
|
|
|
{
|
|
|
|
// Never let the maximum drop below 60 FPS
|
|
|
|
int maxFrameRate = 60;
|
|
|
|
|
|
|
|
if (SDL_InitSubSystem(SDL_INIT_VIDEO) != 0) {
|
|
|
|
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION,
|
|
|
|
"SDL_InitSubSystem(SDL_INIT_VIDEO) failed: %s",
|
|
|
|
SDL_GetError());
|
|
|
|
return maxFrameRate;
|
|
|
|
}
|
|
|
|
|
2018-09-04 02:54:41 +00:00
|
|
|
SDL_DisplayMode mode, bestMode, desktopMode;
|
|
|
|
for (int displayIndex = 0; displayIndex < SDL_GetNumVideoDisplays(); displayIndex++) {
|
|
|
|
// Get the native desktop resolution
|
2018-09-04 04:21:37 +00:00
|
|
|
if (StreamUtils::getRealDesktopMode(displayIndex, &desktopMode)) {
|
2018-09-04 02:54:41 +00:00
|
|
|
|
|
|
|
// Start at desktop mode and work our way up
|
|
|
|
bestMode = desktopMode;
|
|
|
|
for (int i = 0; i < SDL_GetNumDisplayModes(displayIndex); i++) {
|
|
|
|
if (SDL_GetDisplayMode(displayIndex, i, &mode) == 0) {
|
|
|
|
if (mode.w == desktopMode.w && mode.h == desktopMode.h) {
|
|
|
|
if (mode.refresh_rate > bestMode.refresh_rate) {
|
|
|
|
bestMode = mode;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-08-02 01:26:50 +00:00
|
|
|
// Cap the frame rate at 120 FPS. Past this, the encoders start
|
|
|
|
// to max out and drop frames.
|
2018-09-04 02:54:41 +00:00
|
|
|
maxFrameRate = qMax(maxFrameRate, qMin(120, bestMode.refresh_rate));
|
2018-07-28 07:25:52 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
SDL_QuitSubSystem(SDL_INIT_VIDEO);
|
|
|
|
|
|
|
|
return maxFrameRate;
|
|
|
|
}
|
|
|
|
|
2018-09-04 04:21:37 +00:00
|
|
|
QRect StreamingPreferences::getDesktopResolution(int displayIndex)
|
2018-08-05 21:55:26 +00:00
|
|
|
{
|
|
|
|
if (SDL_InitSubSystem(SDL_INIT_VIDEO) != 0) {
|
|
|
|
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION,
|
|
|
|
"SDL_InitSubSystem(SDL_INIT_VIDEO) failed: %s",
|
|
|
|
SDL_GetError());
|
|
|
|
return QRect();
|
|
|
|
}
|
|
|
|
|
|
|
|
if (displayIndex >= SDL_GetNumVideoDisplays()) {
|
|
|
|
SDL_QuitSubSystem(SDL_INIT_VIDEO);
|
|
|
|
return QRect();
|
|
|
|
}
|
|
|
|
|
|
|
|
SDL_DisplayMode mode;
|
2018-09-04 04:21:37 +00:00
|
|
|
int err = SDL_GetDesktopDisplayMode(displayIndex, &mode);
|
2018-08-05 21:55:26 +00:00
|
|
|
SDL_QuitSubSystem(SDL_INIT_VIDEO);
|
|
|
|
|
|
|
|
if (err == 0) {
|
|
|
|
return QRect(0, 0, mode.w, mode.h);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION,
|
2018-09-04 04:21:37 +00:00
|
|
|
"SDL_GetDesktopDisplayMode() failed: %s",
|
2018-08-05 21:55:26 +00:00
|
|
|
SDL_GetError());
|
|
|
|
return QRect();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-09-04 04:21:37 +00:00
|
|
|
QRect StreamingPreferences::getNativeResolution(int displayIndex)
|
|
|
|
{
|
|
|
|
if (SDL_InitSubSystem(SDL_INIT_VIDEO) != 0) {
|
|
|
|
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION,
|
|
|
|
"SDL_InitSubSystem(SDL_INIT_VIDEO) failed: %s",
|
|
|
|
SDL_GetError());
|
|
|
|
return QRect();
|
|
|
|
}
|
|
|
|
|
|
|
|
if (displayIndex >= SDL_GetNumVideoDisplays()) {
|
|
|
|
SDL_QuitSubSystem(SDL_INIT_VIDEO);
|
|
|
|
return QRect();
|
|
|
|
}
|
|
|
|
|
|
|
|
SDL_DisplayMode mode;
|
|
|
|
bool success = StreamUtils::getRealDesktopMode(displayIndex, &mode);
|
|
|
|
SDL_QuitSubSystem(SDL_INIT_VIDEO);
|
|
|
|
|
|
|
|
if (success) {
|
|
|
|
return QRect(0, 0, mode.w, mode.h);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
return QRect();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-06-28 06:15:13 +00:00
|
|
|
int StreamingPreferences::getDefaultBitrate(int width, int height, int fps)
|
|
|
|
{
|
2018-08-05 21:55:26 +00:00
|
|
|
// 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.
|
|
|
|
|
|
|
|
// This covers 1280x720 and 1280x800 too
|
|
|
|
if (width * height <= 1366 * 768) {
|
2018-07-28 08:22:31 +00:00
|
|
|
return static_cast<int>(5000 * (fps / 30.0));
|
2018-06-28 06:15:13 +00:00
|
|
|
}
|
2018-08-05 21:55:26 +00:00
|
|
|
else if (width * height <= 1920 * 1200) {
|
2018-07-28 08:22:31 +00:00
|
|
|
return static_cast<int>(10000 * (fps / 30.0));
|
2018-06-28 06:15:13 +00:00
|
|
|
}
|
2018-08-05 21:55:26 +00:00
|
|
|
else if (width * height <= 2560 * 1600) {
|
2018-07-28 08:22:31 +00:00
|
|
|
return static_cast<int>(20000 * (fps / 30.0));
|
2018-06-28 06:15:13 +00:00
|
|
|
}
|
2018-07-28 08:22:31 +00:00
|
|
|
else /* if (width * height <= 3840 * 2160) */ {
|
|
|
|
return static_cast<int>(40000 * (fps / 30.0));
|
2018-06-28 06:15:13 +00:00
|
|
|
}
|
|
|
|
}
|