Skip to content

Commit

Permalink
config: add min_fps_target setting
Browse files Browse the repository at this point in the history
  • Loading branch information
ReenigneArcher committed Mar 28, 2023
1 parent 648df66 commit acb1750
Show file tree
Hide file tree
Showing 5 changed files with 47 additions and 3 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 @@ -409,6 +409,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
2 changes: 2 additions & 0 deletions src/config.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -330,6 +330,7 @@ namespace config {

0, // hevc_mode

10, // min_fps_target
1, // min_threads
{
"superfast"s, // preset
Expand Down Expand Up @@ -957,6 +958,7 @@ namespace config {
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 @@ namespace config {

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 @@ -1311,6 +1311,10 @@ namespace video {
return;
}

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

auto frame = session->device->frame;

auto shutdown_event = mail->event<bool>(mail::shutdown);
Expand All @@ -1336,9 +1340,9 @@ namespace video {
idr_events->pop();
}

// Encode at a minimum of 10 FPS to avoid image quality issues with static content
// Encode at a minimum 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 @@ -550,6 +550,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 config-page" v-if="platform === 'linux'">
<label for="output_name" class="form-label">Monitor number</label>
<input
Expand Down Expand Up @@ -595,7 +611,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 @@ -983,6 +999,7 @@ <h1 class="my-4">Configuration</h1>
"key_rightalt_to_key_win": "disabled",
"keyboard": "enabled",
"min_log_level": 2,
"min_fps_target": 10,
"mouse": "enabled",
"nv_coder": "auto",
"nv_preset": "p4",
Expand Down

0 comments on commit acb1750

Please sign in to comment.