Skip to content

Commit

Permalink
gui: Add new 'custom' quality preset for placebo
Browse files Browse the repository at this point in the history
Will monitor the file `pl_render_params.conf` in the Chiaki config
directory for custom rendering settings and apply them to the running
stream. For available options see [1], the syntax is simply a set of
`key=value` pairs, separated from each other with either whitespace,
comma, semicolon, colon or newline characters.

[1] https://libplacebo.org/options/
  • Loading branch information
jbaiter committed Aug 13, 2024
1 parent 4adbe34 commit f0d215e
Show file tree
Hide file tree
Showing 5 changed files with 54 additions and 4 deletions.
7 changes: 6 additions & 1 deletion gui/include/qmlmainwindow.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
#include <QWindow>
#include <QQuickWindow>
#include <QLoggingCategory>
#include <QFileSystemWatcher>

extern "C" {
#include <libavcodec/avcodec.h>
Expand Down Expand Up @@ -55,7 +56,8 @@ class QmlMainWindow : public QWindow
enum class VideoPreset {
Fast,
Default,
HighQuality
HighQuality,
Custom
};
Q_ENUM(VideoPreset);

Expand Down Expand Up @@ -154,6 +156,9 @@ class QmlMainWindow : public QWindow
bool quick_frame = false;
bool quick_need_sync = false;
std::atomic<bool> quick_need_render = {false};
QFileSystemWatcher *renderparams_watcher = {};
pl_options renderparams_opts = {};
bool renderparams_changed = false;

struct {
PFN_vkGetDeviceProcAddr vkGetDeviceProcAddr;
Expand Down
3 changes: 2 additions & 1 deletion gui/include/settings.h
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,8 @@ enum class Decoder
enum class PlaceboPreset {
Fast,
Default,
HighQuality
HighQuality,
Custom
};

enum class WindowType {
Expand Down
3 changes: 2 additions & 1 deletion gui/src/qml/SettingsDialog.qml
Original file line number Diff line number Diff line change
Expand Up @@ -283,14 +283,15 @@ DialogView {

C.ComboBox {
Layout.preferredWidth: 400
model: [qsTr("Fast"), qsTr("Default"), qsTr("High Quality")]
model: [qsTr("Fast"), qsTr("Default"), qsTr("High Quality"), qsTr("Custom")]
currentIndex: Chiaki.settings.videoPreset
onActivated: (index) => {
Chiaki.settings.videoPreset = index;
switch (index) {
case 0: Chiaki.window.videoPreset = ChiakiWindow.VideoPreset.Fast; break;
case 1: Chiaki.window.videoPreset = ChiakiWindow.VideoPreset.Default; break;
case 2: Chiaki.window.videoPreset = ChiakiWindow.VideoPreset.HighQuality; break;
case 3: Chiaki.window.videoPreset = ChiakiWindow.VideoPreset.Custom; break;
}
}
}
Expand Down
42 changes: 42 additions & 0 deletions gui/src/qmlmainwindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,13 @@ static QString shader_cache_path()
return path;
}


static const char *render_params_path()
{
static QString path = QStandardPaths::writableLocation(QStandardPaths::ConfigLocation) + "/Chiaki/pl_render_params.conf";
return qPrintable(path);
}

class RenderControl : public QQuickRenderControl
{
public:
Expand Down Expand Up @@ -134,6 +141,7 @@ QmlMainWindow::~QmlMainWindow()
pl_renderer_destroy(&placebo_renderer);
pl_vulkan_destroy(&placebo_vulkan);
pl_vk_inst_destroy(&placebo_vk_inst);
pl_options_free(&renderparams_opts);
pl_log_destroy(&placebo_log);
}

Expand Down Expand Up @@ -510,13 +518,31 @@ void QmlMainWindow::init(Settings *settings)
dropped_frames_current = 0;
});

this->renderparams_opts = pl_options_alloc(this->placebo_log);
pl_options_reset(this->renderparams_opts, &pl_render_high_quality_params);

this->renderparams_watcher = new QFileSystemWatcher(this);
this->renderparams_watcher->addPath(render_params_path());
this->renderparams_changed = true;
connect(
this->renderparams_watcher,
&QFileSystemWatcher::fileChanged, this,
[this](const QString &path) {
this->renderparams_changed = true;
this->renderparams_watcher->addPath(render_params_path());
});


switch (settings->GetPlaceboPreset()) {
case PlaceboPreset::Fast:
setVideoPreset(VideoPreset::Fast);
break;
case PlaceboPreset::Default:
setVideoPreset(VideoPreset::Default);
break;
case PlaceboPreset::Custom:
setVideoPreset(VideoPreset::Custom);
break;
case PlaceboPreset::HighQuality:
default:
setVideoPreset(VideoPreset::HighQuality);
Expand Down Expand Up @@ -783,6 +809,22 @@ void QmlMainWindow::render()
case VideoPreset::HighQuality:
render_params = &pl_render_high_quality_params;
break;
case VideoPreset::Custom:
if (renderparams_changed) {
renderparams_changed = false;
QFile paramsFile(render_params_path());
bool loaded = false;
if (paramsFile.open(QIODevice::ReadOnly)) {
QByteArray paramsData = paramsFile.readAll();
if (!pl_options_load(this->renderparams_opts, paramsData.constData())) {
qCCritical(chiakiGui) << "Failed to load custom render params!";
} else {
qCInfo(chiakiGui) << "Updated custom render parameters.";
}
}
}
render_params = &(this->renderparams_opts->params);
break;
}

if (current_frame.num_planes) {
Expand Down
3 changes: 2 additions & 1 deletion gui/src/settings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -403,7 +403,8 @@ void Settings::SetDecoder(Decoder decoder)
static const QMap<PlaceboPreset, QString> placebo_preset_values = {
{ PlaceboPreset::Fast, "fast" },
{ PlaceboPreset::Default, "default" },
{ PlaceboPreset::HighQuality, "high_quality" }
{ PlaceboPreset::HighQuality, "high_quality" },
{ PlaceboPreset::Custom, "custom" }
};

PlaceboPreset Settings::GetPlaceboPreset() const
Expand Down

0 comments on commit f0d215e

Please sign in to comment.