Skip to content

Commit

Permalink
Support YUV 4:4:4 formats
Browse files Browse the repository at this point in the history
  • Loading branch information
ns6089 committed Jun 10, 2024
1 parent 92b595a commit 6b27398
Show file tree
Hide file tree
Showing 12 changed files with 399 additions and 23 deletions.
7 changes: 6 additions & 1 deletion app/app.pro
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ unix:!macx {
}
win32 {
LIBS += -llibssl -llibcrypto -lSDL2 -lSDL2_ttf -lavcodec -lavutil -lopus -ldxgi -ld3d11
CONFIG += ffmpeg
CONFIG += ffmpeg libplacebo
}
win32:!winrt {
CONFIG += soundio discord-rpc
Expand Down Expand Up @@ -338,6 +338,11 @@ libplacebo {
streaming/video/ffmpeg-renderers/plvk_c.c
HEADERS += \
streaming/video/ffmpeg-renderers/plvk.h

win32 {
INCLUDEPATH += $((VULKAN_SDK))/Include
LIBS += libplacebo.lib
}
}
config_EGL {
message(EGL renderer selected)
Expand Down
6 changes: 5 additions & 1 deletion app/cli/commandlineparser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -374,6 +374,7 @@ void StreamCommandLineParser::parse(const QStringList &args, StreamingPreference
parser.addToggleOption("keep-awake", "prevent display sleep while streaming");
parser.addToggleOption("performance-overlay", "show performance overlay");
parser.addToggleOption("hdr", "HDR streaming");
parser.addToggleOption("yuv444", "YUV 4:4:4 sampling, if supported");
parser.addChoiceOption("capture-system-keys", "capture system key combos", m_CaptureSysKeysModeMap.keys());
parser.addChoiceOption("video-codec", "video codec", m_VideoCodecMap.keys());
parser.addChoiceOption("video-decoder", "video decoder", m_VideoDecoderMap.keys());
Expand Down Expand Up @@ -425,7 +426,7 @@ void StreamCommandLineParser::parse(const QStringList &args, StreamingPreference
}
} else if (displaySet || parser.isSet("fps")) {
preferences->bitrateKbps = preferences->getDefaultBitrate(
preferences->width, preferences->height, preferences->fps);
preferences->width, preferences->height, preferences->fps, preferences->enableYUV444);
}

// Resolve --packet-size option
Expand Down Expand Up @@ -493,6 +494,9 @@ void StreamCommandLineParser::parse(const QStringList &args, StreamingPreference

// Resolve --hdr and --no-hdr options
preferences->enableHdr = parser.getToggleOptionValue("hdr", preferences->enableHdr);

// Resolve --yuv444 and --no-yuv444 options
preferences->enableYUV444 = parser.getToggleOptionValue("yuv444", preferences->enableYUV444);

// Resolve --capture-system-keys option
if (parser.isSet("capture-system-keys")) {
Expand Down
24 changes: 22 additions & 2 deletions app/gui/SettingsView.qml
Original file line number Diff line number Diff line change
Expand Up @@ -237,6 +237,7 @@ Flickable {
recalculateWidth()

lastIndexValue = currentIndex

}

id: resolutionComboBox
Expand Down Expand Up @@ -283,7 +284,8 @@ Flickable {

StreamingPreferences.bitrateKbps = StreamingPreferences.getDefaultBitrate(StreamingPreferences.width,
StreamingPreferences.height,
StreamingPreferences.fps);
StreamingPreferences.fps,
StreamingPreferences.enableYUV444);
slider.value = StreamingPreferences.bitrateKbps
}

Expand Down Expand Up @@ -448,7 +450,8 @@ Flickable {

StreamingPreferences.bitrateKbps = StreamingPreferences.getDefaultBitrate(StreamingPreferences.width,
StreamingPreferences.height,
StreamingPreferences.fps);
StreamingPreferences.fps,
StreamingPreferences.enableYUV444);
slider.value = StreamingPreferences.bitrateKbps
}

Expand Down Expand Up @@ -1611,6 +1614,23 @@ Flickable {
qsTr("HDR streaming is not supported on this PC.")
}

CheckBox {
id: enableYUV444
width: parent.width
text: qsTr("Enable YUV 4:4:4 (Experimental)")
font.pointSize: 12

checked: StreamingPreferences.enableYUV444
onCheckedChanged: {
StreamingPreferences.enableYUV444 = checked
StreamingPreferences.bitrateKbps = StreamingPreferences.getDefaultBitrate(StreamingPreferences.width,
StreamingPreferences.height,
StreamingPreferences.fps,
StreamingPreferences.enableYUV444);
slider.value = StreamingPreferences.bitrateKbps
}
}

CheckBox {
id: enableMdns
width: parent.width
Expand Down
12 changes: 10 additions & 2 deletions app/settings/streamingpreferences.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
#define SER_AUDIOCFG "audiocfg"
#define SER_VIDEOCFG "videocfg"
#define SER_HDR "hdr"
#define SER_YUV444 "yuv444"
#define SER_VIDEODEC "videodec"
#define SER_WINDOWMODE "windowmode"
#define SER_MDNS "mdns"
Expand Down Expand Up @@ -117,7 +118,8 @@ void StreamingPreferences::reload()
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();
enableYUV444 = settings.value(SER_YUV444, false).toBool();
bitrateKbps = settings.value(SER_BITRATE, getDefaultBitrate(width, height, fps, enableYUV444)).toInt();
enableVsync = settings.value(SER_VSYNC, true).toBool();
gameOptimizations = settings.value(SER_GAMEOPTS, true).toBool();
playAudioOnHost = settings.value(SER_HOSTAUDIO, false).toBool();
Expand Down Expand Up @@ -320,6 +322,7 @@ void StreamingPreferences::save()
settings.setValue(SER_SHOWPERFOVERLAY, showPerformanceOverlay);
settings.setValue(SER_AUDIOCFG, static_cast<int>(audioConfig));
settings.setValue(SER_HDR, enableHdr);
settings.setValue(SER_YUV444, enableYUV444);
settings.setValue(SER_VIDEOCFG, static_cast<int>(videoCodecConfig));
settings.setValue(SER_VIDEODEC, static_cast<int>(videoDecoderSelection));
settings.setValue(SER_WINDOWMODE, static_cast<int>(windowMode));
Expand All @@ -335,7 +338,7 @@ void StreamingPreferences::save()
settings.setValue(SER_KEEPAWAKE, keepAwake);
}

int StreamingPreferences::getDefaultBitrate(int width, int height, int fps)
int StreamingPreferences::getDefaultBitrate(int width, int height, int fps, bool yuv444)
{
// Don't scale bitrate linearly beyond 60 FPS. It's definitely not a linear
// bitrate increase for frame rate once we get to values that high.
Expand Down Expand Up @@ -383,5 +386,10 @@ int StreamingPreferences::getDefaultBitrate(int width, int height, int fps)
}
}

if (yuv444) {
// This is rough estimation based on the fact that 4:4:4 doubles the amount of raw YUV data compared to 4:2:0
resolutionFactor *= 2;
}

return qRound(resolutionFactor * frameRateFactor) * 1000;
}
5 changes: 4 additions & 1 deletion app/settings/streamingpreferences.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ class StreamingPreferences : public QObject
static StreamingPreferences* get(QQmlEngine *qmlEngine = nullptr);

Q_INVOKABLE static int
getDefaultBitrate(int width, int height, int fps);
getDefaultBitrate(int width, int height, int fps, bool yuv444);

Q_INVOKABLE void save();

Expand Down Expand Up @@ -124,6 +124,7 @@ class StreamingPreferences : public QObject
Q_PROPERTY(AudioConfig audioConfig MEMBER audioConfig NOTIFY audioConfigChanged)
Q_PROPERTY(VideoCodecConfig videoCodecConfig MEMBER videoCodecConfig NOTIFY videoCodecConfigChanged)
Q_PROPERTY(bool enableHdr MEMBER enableHdr NOTIFY enableHdrChanged)
Q_PROPERTY(bool enableYUV444 MEMBER enableYUV444 NOTIFY enableYUV444Changed)
Q_PROPERTY(VideoDecoderSelection videoDecoderSelection MEMBER videoDecoderSelection NOTIFY videoDecoderSelectionChanged)
Q_PROPERTY(WindowMode windowMode MEMBER windowMode NOTIFY windowModeChanged)
Q_PROPERTY(WindowMode recommendedFullScreenMode MEMBER recommendedFullScreenMode CONSTANT)
Expand Down Expand Up @@ -168,6 +169,7 @@ class StreamingPreferences : public QObject
AudioConfig audioConfig;
VideoCodecConfig videoCodecConfig;
bool enableHdr;
bool enableYUV444;
VideoDecoderSelection videoDecoderSelection;
WindowMode windowMode;
WindowMode recommendedFullScreenMode;
Expand All @@ -190,6 +192,7 @@ class StreamingPreferences : public QObject
void audioConfigChanged();
void videoCodecConfigChanged();
void enableHdrChanged();
void enableYUV444Changed();
void videoDecoderSelectionChanged();
void uiDisplayModeChanged();
void windowModeChanged();
Expand Down
Loading

0 comments on commit 6b27398

Please sign in to comment.