Skip to content

Commit

Permalink
config: add min_fps setting
Browse files Browse the repository at this point in the history
  • Loading branch information
ReenigneArcher committed Mar 16, 2023
1 parent afc6966 commit 0870c09
Show file tree
Hide file tree
Showing 5 changed files with 48 additions and 4 deletions.
20 changes: 20 additions & 0 deletions docs/source/about/advanced_usage.rst
Original file line number Diff line number Diff line change
Expand Up @@ -378,6 +378,26 @@ dwmflush
dwmflush = enabled
min_fps_target
^^^^^^^^^^^^^^

**Description**
The minimum FPS Sunshine will attempt to maintain. Increasing this value slightly may help when streaming
mostly static content.

.. Warning:: Higher values will consume more bandwidth.

**Default**
``10``

**Range**
``1-240``

**Example**
.. code-block:: text
min_fps_target = 10
Audio
-----

Expand Down
4 changes: 3 additions & 1 deletion src/config.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -314,7 +314,8 @@ video_t video {

0, // hevc_mode

1, // min_threads
10, // min_fps_target
1, // min_threads
{
"superfast"s, // preset
"zerolatency"s, // tune
Expand Down Expand Up @@ -886,6 +887,7 @@ void apply_config(std::unordered_map<std::string, std::string> &&vars) {
string_f(vars, "adapter_name", video.adapter_name);
string_f(vars, "output_name", video.output_name);
bool_f(vars, "dwmflush", video.dwmflush);
int_between_f(vars, "min_fps_target", video.min_fps_target, { 1, 240 });

path_f(vars, "pkey", nvhttp.pkey);
path_f(vars, "cert", nvhttp.cert);
Expand Down
1 change: 1 addition & 0 deletions src/config.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ struct video_t {

int hevc_mode;

int min_fps_target; // Minimum fps target, determines minimum frame time
int min_threads; // Minimum number of threads/slices for CPU encoding
struct {
std::string sw_preset;
Expand Down
8 changes: 6 additions & 2 deletions src/video.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1281,6 +1281,10 @@ void encode_run(
const encoder_t &encoder,
void *channel_data) {

// set minimum frame time
auto minimum_frame_time = std::chrono::milliseconds(1000 / config::video.min_fps_target);
BOOST_LOG(info) << "Minimum frame time set to "sv << minimum_frame_time.count() << "ms, based on min fps target of "sv << config::video.min_fps_target << "."sv;

auto session = make_session(disp.get(), encoder, config, disp->width, disp->height, std::move(hwdevice));
if(!session) {
return;
Expand Down Expand Up @@ -1311,9 +1315,9 @@ void encode_run(
idr_events->pop();
}

// Encode at a minimum of 10 FPS to avoid image quality issues with static content
// Encode at a minimum of FPS to avoid image quality issues with static content
if(!frame->key_frame || images->peek()) {
if(auto img = images->pop(100ms)) {
if(auto img = images->pop(minimum_frame_time)) {
if(session->device->convert(*img)) {
BOOST_LOG(error) << "Could not convert image"sv;
return;
Expand Down
19 changes: 18 additions & 1 deletion src_assets/common/assets/web/config.html
Original file line number Diff line number Diff line change
Expand Up @@ -502,6 +502,22 @@ <h1 class="my-4">Configuration</h1>
Disable if you encounter any VSync-related issues.
</div>
</div>
<!--min_fps_target-->
<div class="mb-3">
<label for="qp" class="form-label">Minimum FPS Target</label>
<input
type="number"
class="form-control"
id="min_fps_target"
placeholder="10"
v-model="config.min_fps_target"
/>
<div class="form-text">
The minimum FPS Sunshine will attempt to maintain.<br />
Increasing this value slightly may help when streaming mostly static content.<br />
Higher values will consume more bandwidth.<br />
</div>
</div>
<div class="mb-3" class="config-page" v-if="platform === 'linux'">
<label for="output_name" class="form-label">Monitor number</label>
<input
Expand Down Expand Up @@ -547,7 +563,7 @@ <h1 class="my-4">Configuration</h1>
Quantization Parameter<br />
Some devices may not support Constant Bit Rate.<br />
For those devices, QP is used instead.<br />
Higher value means more compression, but less quality<br />
Higher value means more compression, but less quality.<br />
</div>
</div>
<!-- Min Threads -->
Expand Down Expand Up @@ -914,6 +930,7 @@ <h1 class="my-4">Configuration</h1>
"dwmflush": "enabled",
"encoder": "",
"fps": "[10,30,60,90,120]",
"min_fps_target": 10,
"gamepad": "x360",
"hevc_mode": 0,
"key_rightalt_to_key_win": "disabled",
Expand Down

0 comments on commit 0870c09

Please sign in to comment.