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 15, 2023
1 parent afc6966 commit efc275f
Show file tree
Hide file tree
Showing 5 changed files with 49 additions and 3 deletions.
17 changes: 17 additions & 0 deletions docs/source/about/advanced_usage.rst
Original file line number Diff line number Diff line change
Expand Up @@ -378,6 +378,23 @@ dwmflush
dwmflush = enabled
fps_min
^^^^^^^

**Description**
The minimum framerate 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``

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

Expand Down
1 change: 1 addition & 0 deletions src/config.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -314,6 +314,7 @@ video_t video {

0, // hevc_mode

10, // min_fps
1, // min_threads
{
"superfast"s, // preset
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; // Minimum framerate
int min_threads; // Minimum number of threads/slices for CPU encoding
struct {
std::string sw_preset;
Expand Down
15 changes: 13 additions & 2 deletions src/video.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1281,6 +1281,17 @@ void encode_run(
const encoder_t &encoder,
void *channel_data) {

// get minimum fps from config
auto MIN_FPS = std::chrono::milliseconds(*&config::video.min_fps * 10);

// ensure MIN_FPS is at least 10 and less than 2400 milliseconds
if (MIN_FPS < std::chrono::milliseconds(10)) {
MIN_FPS = std::chrono::milliseconds(10);
}
else if (MIN_FPS > std::chrono::milliseconds(2400)) {
MIN_FPS = std::chrono::milliseconds(2400);
}

auto session = make_session(disp.get(), encoder, config, disp->width, disp->height, std::move(hwdevice));
if(!session) {
return;
Expand Down Expand Up @@ -1311,9 +1322,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(MIN_FPS)) {
if(session->device->convert(*img)) {
BOOST_LOG(error) << "Could not convert image"sv;
return;
Expand Down
18 changes: 17 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,21 @@ <h1 class="my-4">Configuration</h1>
Disable if you encounter any VSync-related issues.
</div>
</div>
<!--fps_min-->
<div class="mb-3">
<label for="qp" class="form-label">FPS Minimum</label>
<input
type="number"
class="form-control"
id="fps_min"
placeholder="10"
v-model="config.min_fps"
/>
<div class="form-text">
The minimum framerate 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 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 +562,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 +929,7 @@ <h1 class="my-4">Configuration</h1>
"dwmflush": "enabled",
"encoder": "",
"fps": "[10,30,60,90,120]",
"fps_min": 10,
"gamepad": "x360",
"hevc_mode": 0,
"key_rightalt_to_key_win": "disabled",
Expand Down

0 comments on commit efc275f

Please sign in to comment.