Skip to content

Commit

Permalink
x264: make threads configurable
Browse files Browse the repository at this point in the history
Closes: neutrinolabs#3366
(cherry picked from commit e6f5e3b)
  • Loading branch information
metalefty committed Dec 27, 2024
1 parent 4c8c773 commit ad5b76d
Show file tree
Hide file tree
Showing 14 changed files with 41 additions and 1 deletion.
1 change: 1 addition & 0 deletions tests/xrdp/gfx/gfx_codec_h264_only.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ vbv_max_bitrate = 0
vbv_buffer_size = 0
fps_num = 24
fps_den = 1
threads = 1

[x264.lan]
[x264.wan]
Expand Down
1 change: 1 addition & 0 deletions tests/xrdp/gfx/gfx_codec_h264_preferred.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ vbv_max_bitrate = 0
vbv_buffer_size = 0
fps_num = 24
fps_den = 1
threads = 1

[x264.lan]
[x264.wan]
Expand Down
1 change: 1 addition & 0 deletions tests/xrdp/gfx/gfx_codec_order_undefined.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ vbv_max_bitrate = 0
vbv_buffer_size = 0
fps_num = 24
fps_den = 1
threads = 1

[x264.lan]
[x264.wan]
Expand Down
1 change: 1 addition & 0 deletions tests/xrdp/gfx/gfx_codec_rfx_only.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ vbv_max_bitrate = 0
vbv_buffer_size = 0
fps_num = 24
fps_den = 1
threads = 1

[x264.lan]
[x264.wan]
Expand Down
1 change: 1 addition & 0 deletions tests/xrdp/gfx/gfx_codec_rfx_preferred.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ vbv_max_bitrate = 0
vbv_buffer_size = 0
fps_num = 24
fps_den = 1
threads = 1

[x264.lan]
[x264.wan]
Expand Down
1 change: 1 addition & 0 deletions tests/xrdp/gfx/gfx_codec_rfx_preferred_odd.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ vbv_max_bitrate = 0
vbv_buffer_size = 0
fps_num = 24
fps_den = 1
threads = 1

[x264.lan]
[x264.wan]
Expand Down
1 change: 1 addition & 0 deletions tests/xrdp/gfx/gfx_h264_encoder_invalid.toml
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ vbv_max_bitrate = 0
vbv_buffer_size = 0
fps_num = 60
fps_den = 1
threads = 1

[x264.lan]
# inherits default
Expand Down
1 change: 1 addition & 0 deletions tests/xrdp/gfx/gfx_h264_encoder_openh264.toml
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ vbv_max_bitrate = 0
vbv_buffer_size = 0
fps_num = 60
fps_den = 1
threads = 1

[x264.lan]
# inherits default
Expand Down
1 change: 1 addition & 0 deletions tests/xrdp/gfx/gfx_h264_encoder_undefined.toml
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ vbv_max_bitrate = 0
vbv_buffer_size = 0
fps_num = 60
fps_den = 1
threads = 1

[x264.lan]
# inherits default
Expand Down
1 change: 1 addition & 0 deletions tests/xrdp/gfx/gfx_h264_encoder_x264.toml
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ vbv_max_bitrate = 0
vbv_buffer_size = 0
fps_num = 60
fps_den = 1
threads = 1

[x264.lan]
# inherits default
Expand Down
1 change: 1 addition & 0 deletions xrdp/gfx.toml
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ vbv_max_bitrate = 0
vbv_buffer_size = 0
fps_num = 60
fps_den = 1
threads = 1 # recommended: 1 or 2, see `man gfx.toml` for details

[x264.lan]
# inherits default
Expand Down
2 changes: 1 addition & 1 deletion xrdp/xrdp_encoder_x264.c
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ xrdp_encoder_x264_encode(void *handle, int session, int left, int top,
x264_param_default_preset(&(xe->x264_params),
xg->x264_param[ct].preset,
xg->x264_param[ct].tune);
xe->x264_params.i_threads = 1;
xe->x264_params.i_threads = xg->x264_param[ct].threads;
xe->x264_params.i_width = (width + 15) & ~15;
xe->x264_params.i_height = (height + 15) & ~15;
xe->x264_params.i_fps_num = xg->x264_param[ct].fps_num;
Expand Down
28 changes: 28 additions & 0 deletions xrdp/xrdp_tconfig.c
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@
#define X264_DEFAULT_PROFILE "main"
#define X264_DEFAULT_FPS_NUM 24
#define X264_DEFAULT_FPS_DEN 1
#define X264_DEFAULT_THREADS 1 /* not to exhaust CPU threads for 1 user */

const char *
tconfig_codec_order_to_str(
Expand Down Expand Up @@ -334,6 +335,33 @@ tconfig_load_gfx_x264_ct(toml_table_t *tfile, const int connection_type,
param[connection_type].fps_den = X264_DEFAULT_FPS_DEN;
}

/* threads */
datum = toml_int_in(x264_ct, "threads");
if (datum.ok)
{
if (datum.u.i >= 0)
{
param[connection_type].threads = datum.u.i;
}
else
{
TCLOG(LOG_LEVEL_WARNING,
"[x264.%s] an invalid value (< 0) is specified for threads, "
"adopting the default value [%d]",
rdpbcgr_connection_type_names[connection_type],
X264_DEFAULT_THREADS);
param[connection_type].threads = X264_DEFAULT_THREADS;
}
}
else if (connection_type == 0)
{
TCLOG(LOG_LEVEL_WARNING,
"[x264.%s] threads is not set, adopting the default value [%d]",
rdpbcgr_connection_type_names[connection_type],
X264_DEFAULT_THREADS);
param[connection_type].threads = X264_DEFAULT_THREADS;
}

return 0;
}

Expand Down
1 change: 1 addition & 0 deletions xrdp/xrdp_tconfig.h
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ struct xrdp_tconfig_gfx_x264_param
int vbv_buffer_size;
int fps_num;
int fps_den;
int threads;
};

struct xrdp_tconfig_gfx_openh264_param
Expand Down

0 comments on commit ad5b76d

Please sign in to comment.