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 0867994
Show file tree
Hide file tree
Showing 5 changed files with 59 additions and 4 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
3 changes: 2 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
1, // min_threads
{
"superfast"s, // preset
"zerolatency"s, // tune
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
24 changes: 22 additions & 2 deletions src/video.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1281,6 +1281,26 @@ void encode_run(
const encoder_t &encoder,
void *channel_data) {

// get minimum fps from config
auto min_fps = config::video.min_fps;
auto minimum_frame_time = std::chrono::milliseconds(1000 / 10); // default value

// check if min_fps is an integer
if(min_fps != (int)min_fps) {
BOOST_LOG(warning) << "Minimum FPS must be an integer, update your config. Falling back to 10 FPS."sv;
}
else {
minimum_frame_time = std::chrono::milliseconds(1000 / config::video.min_fps); // use config value if it is an integer
}

// check if minimum frame time is between 1 and 240 fps
if(minimum_frame_time < std::chrono::milliseconds(1000 / 240)) {
minimum_frame_time = std::chrono::milliseconds(1000 / 240);
}
else if(minimum_frame_time > std::chrono::milliseconds(1000 / 1)) { // 1 fps, showing equation just for clarity... maybe should have a min fps a little higher than 1?
minimum_frame_time = std::chrono::milliseconds(1000 / 1);
}

auto session = make_session(disp.get(), encoder, config, disp->width, disp->height, std::move(hwdevice));
if(!session) {
return;
Expand Down Expand Up @@ -1311,9 +1331,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
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 0867994

Please sign in to comment.