Skip to content

Commit

Permalink
Revert "feat!: drop advertised resolutions and fps (LizardByte#2924)"
Browse files Browse the repository at this point in the history
This reverts commit 04df80f.
  • Loading branch information
qiin2333 committed Aug 10, 2024
1 parent 97e9118 commit a40ba6b
Show file tree
Hide file tree
Showing 7 changed files with 127 additions and 2 deletions.
17 changes: 17 additions & 0 deletions src/config.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -416,6 +416,21 @@ namespace config {
boost::asio::ip::host_name(), // sunshine_name,
"sunshine_state.json"s, // file_state
{}, // external_ip
{
"352x240"s,
"480x360"s,
"858x480"s,
"1280x720"s,
"1920x1080"s,
"2560x1080"s,
"2560x1440"s,
"3440x1440"s,
"1920x1200"s,
"3840x2160"s,
"3840x1600"s,
}, // supported resolutions

{ 10, 30, 60, 90, 120 }, // supported fps
};

input_t input {
Expand Down Expand Up @@ -1090,6 +1105,8 @@ namespace config {
path_f(vars, "credentials_file", config::sunshine.credentials_file);

string_f(vars, "external_ip", nvhttp.external_ip);
list_string_f(vars, "resolutions"s, nvhttp.resolutions);
list_int_f(vars, "fps"s, nvhttp.fps);
list_prep_cmd_f(vars, "global_prep_cmd", config::sunshine.prep_cmds);

string_f(vars, "audio_sink", audio.sink);
Expand Down
2 changes: 2 additions & 0 deletions src/config.h
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,8 @@ namespace config {
std::string file_state;

std::string external_ip;
std::vector<std::string> resolutions;
std::vector<int> fps;
};

struct input_t {
Expand Down
25 changes: 25 additions & 0 deletions src/nvhttp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -761,6 +761,31 @@ namespace nvhttp {
}
tree.put("root.ServerCodecModeSupport", codec_mode_flags);

pt::ptree display_nodes;
for (auto &resolution : config::nvhttp.resolutions) {
auto pred = [](auto ch) { return ch == ' ' || ch == '\t' || ch == 'x'; };

auto middle = std::find_if(std::begin(resolution), std::end(resolution), pred);
if (middle == std::end(resolution)) {
BOOST_LOG(warning) << resolution << " is not in the proper format for a resolution: WIDTHxHEIGHT"sv;
continue;
}

auto width = util::from_chars(&*std::begin(resolution), &*middle);
auto height = util::from_chars(&*(middle + 1), &*std::end(resolution));
for (auto fps : config::nvhttp.fps) {
pt::ptree display_node;
display_node.put("Width", width);
display_node.put("Height", height);
display_node.put("RefreshRate", fps);

display_nodes.add_child("DisplayMode", display_node);
}
}

if (!config::nvhttp.resolutions.empty()) {
tree.add_child("root.SupportedDisplayMode", display_nodes);
}
auto current_appid = proc::proc.running();
tree.put("root.PairStatus", pair_status);
tree.put("root.currentgame", current_appid);
Expand Down
34 changes: 32 additions & 2 deletions src_assets/common/assets/web/config.html
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,8 @@ <h1 class="my-4">{{ $t('config.configuration') }}</h1>
saved: false,
restarted: false,
config: null,
fps: [],
resolutions: [],
currentTab: "general",
global_prep_cmd: [],
display_mode_remapping: [],
Expand Down Expand Up @@ -334,6 +336,16 @@ <h1 class="my-4">{{ $t('config.configuration') }}</h1>
});
});

this.fps = JSON.parse(this.config.fps);
//Resolutions should be fixed because are not valid JSON
let res = this.config.resolutions.substring(
1,
this.config.resolutions.length - 1
);
let resolutions = [];
res.split(",").forEach((r) => resolutions.push(r.trim()));
this.resolutions = resolutions;

this.config.global_prep_cmd = this.config.global_prep_cmd || [];
this.global_prep_cmd = JSON.parse(this.config.global_prep_cmd);

Expand All @@ -346,6 +358,16 @@ <h1 class="my-4">{{ $t('config.configuration') }}</h1>
this.$forceUpdate()
},
serialize() {
let nl = this.config === "windows" ? "\r\n" : "\n";
this.config.resolutions =
"[" +
nl +
" " +
this.resolutions.join("," + nl + " ") +
nl +
"]";
// remove quotes from values in fps
this.config.fps = JSON.stringify(this.fps).replace(/"/g, "");
this.config.global_prep_cmd = JSON.stringify(this.global_prep_cmd);
this.config.display_mode_remapping = JSON.stringify(this.display_mode_remapping);
},
Expand All @@ -365,8 +387,16 @@ <h1 class="my-4">{{ $t('config.configuration') }}</h1>
if (["resolutions", "fps", "global_prep_cmd", "display_mode_remapping"].includes(optionKey)) {
let config_value, default_value

config_value = JSON.parse(config[optionKey])
default_value = JSON.parse(tab.options[optionKey])
if (optionKey === "resolutions") {
let regex = /([\d]+x[\d]+)/g

// Use a regular expression to find each value and replace it with a quoted version
config_value = JSON.parse(config[optionKey].replace(regex, '"$1"')).toString()
default_value = JSON.parse(tab.options[optionKey].replace(regex, '"$1"')).toString()
} else {
config_value = JSON.parse(config[optionKey])
default_value = JSON.parse(tab.options[optionKey])
}

if (config_value === default_value) {
delete_value = true
Expand Down
2 changes: 2 additions & 0 deletions src_assets/common/assets/web/configs/tabs/AudioVideo.vue
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,8 @@ const config = ref(props.config)
<DisplayModesSettings
:platform="platform"
:config="config"
:resolutions="resolutions"
:fps="fps"
:min_fps_factor="min_fps_factor"
/>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,65 @@ import PlatformLayout from '../../../PlatformLayout.vue'
const props = defineProps([
'platform',
'config',
'resolutions',
'fps',
'min_fps_factor',
])
const config = ref(props.config)
const resolutions = ref(props.resolutions)
const fps = ref(props.fps)
const resIn = ref("")
const fpsIn = ref("")
</script>

<template>
<div class="mb-3">
<!-- Advertised Resolutions -->
<div id="resolutions" class="resolutions-container">
<label>{{ $t('config.resolutions') }}</label>
<div class="resolutions d-flex flex-wrap">
<div class="p-2 ms-item m-2 d-flex justify-content-between" v-for="(r,i) in resolutions" :key="r">
<span class="px-2">{{r}}</span>
<span style="cursor: pointer" @click="resolutions.splice(i,1)">&times;</span>
</div>
</div>
<form @submit.prevent="resolutions.push(resIn);resIn = '';" class="d-flex align-items-center">
<input type="text" v-model="resIn" required pattern="[0-9]+x[0-9]+" style="
width: 12ch;
border-top-right-radius: 0;
border-bottom-right-radius: 0;
" class="form-control" />
<button style="border-top-left-radius: 0; border-bottom-left-radius: 0" class="btn btn-success">
+
</button>
</form>
</div>

<!-- Advertised FPS -->
<div id="fps" class="fps-container">
<label>{{ $t('config.fps') }}</label>
<div class="fps d-flex flex-wrap">
<div class="p-2 ms-item m-2 d-flex justify-content-between" v-for="(f,i) in fps" :key="f">
<span class="px-2">{{f}}</span>
<span style="cursor: pointer" @click="fps.splice(i,1)">&times;</span>
</div>
</div>
<form @submit.prevent="fps.push(fpsIn);fpsIn = '';" class="d-flex align-items-center">
<input type="text" v-model="fpsIn" required pattern="[0-9]+" style="
width: 6ch;
border-top-right-radius: 0;
border-bottom-right-radius: 0;
" class="form-control" />
<button style="border-top-left-radius: 0; border-bottom-left-radius: 0" class="btn btn-success">
+
</button>
</form>
</div>

<div class="form-text mb-3">{{ $t('config.res_fps_desc') }}</div>

<!--min_fps_factor-->
<div class="mb-3">
<label for="qp" class="form-label">{{ $t('config.min_fps_factor') }}</label>
Expand Down
1 change: 1 addition & 0 deletions src_assets/common/assets/web/public/assets/locale/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,7 @@
"file_apps_desc": "The file where current apps of Sunshine are stored.",
"file_state": "State File",
"file_state_desc": "The file where current state of Sunshine is stored",
"fps": "Advertised FPS",
"gamepad": "Emulated Gamepad Type",
"gamepad_auto": "Automatic selection options",
"gamepad_desc": "Choose which type of gamepad to emulate on the host",
Expand Down

0 comments on commit a40ba6b

Please sign in to comment.