Skip to content

Commit

Permalink
tconfig: add new toml config parser for gfx.toml
Browse files Browse the repository at this point in the history
  • Loading branch information
metalefty committed Aug 23, 2024
1 parent 9f59c6a commit b3513ba
Show file tree
Hide file tree
Showing 7 changed files with 412 additions and 12 deletions.
50 changes: 50 additions & 0 deletions tests/xrdp/test_tconfig.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
#if defined(HAVE_CONFIG_H)
#include "config_ac.h"
#endif

#include "xrdp_tconfig.h"
#include "test_xrdp.h"
#include "xrdp.h"

START_TEST(test_tconfig_gfx_always_success)
{
ck_assert_int_eq(1, 1);
}
END_TEST

START_TEST(test_tconfig_gfx_x264_load_basic)
{
struct xrdp_tconfig_gfx gfxconfig;
int rv = tconfig_load_gfx(XRDP_TOP_SRCDIR "/xrdp/gfx.toml", &gfxconfig);

ck_assert_int_eq(rv, 0);

/* default */
ck_assert_str_eq(gfxconfig.x264_param[0].preset, "ultrafast");
ck_assert_str_eq(gfxconfig.x264_param[0].tune, "zerolatency");
ck_assert_str_eq(gfxconfig.x264_param[0].profile, "main");
ck_assert_int_eq(gfxconfig.x264_param[0].vbv_max_bitrate, 0);
ck_assert_int_eq(gfxconfig.x264_param[0].vbv_buffer_size, 0);
ck_assert_int_eq(gfxconfig.x264_param[0].fps_num, 24);
ck_assert_int_eq(gfxconfig.x264_param[0].fps_den, 1);

}
END_TEST

/******************************************************************************/
Suite *
make_suite_tconfig_load_gfx(void)
{
Suite *s;
TCase *tc_tconfig_load_gfx;

s = suite_create("GfxLoad");

tc_tconfig_load_gfx = tcase_create("xrdp_tconfig_load_gfx");
tcase_add_test(tc_tconfig_load_gfx, test_tconfig_gfx_always_success);
tcase_add_test(tc_tconfig_load_gfx, test_tconfig_gfx_x264_load_basic);

suite_add_tcase(s, tc_tconfig_load_gfx);

return s;
}
1 change: 1 addition & 0 deletions tests/xrdp/test_xrdp.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,6 @@ Suite *make_suite_test_bitmap_load(void);
Suite *make_suite_test_keymap_load(void);
Suite *make_suite_egfx_base_functions(void);
Suite *make_suite_region(void);
Suite *make_suite_tconfig_load_gfx(void);

#endif /* TEST_XRDP_H */
1 change: 1 addition & 0 deletions tests/xrdp/test_xrdp_main.c
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ int main (void)
srunner_add_suite(sr, make_suite_test_keymap_load());
srunner_add_suite(sr, make_suite_egfx_base_functions());
srunner_add_suite(sr, make_suite_region());
srunner_add_suite(sr, make_suite_tconfig_load_gfx());

srunner_set_tap(sr, "-");
srunner_run_all (sr, CK_ENV);
Expand Down
27 changes: 27 additions & 0 deletions xrdp/gfx.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@

[x264.default]
preset = "ultrafast"
tune = "zerolatency"
profile = "main"
vbv_max_bitrate = 0
vbv_buffer_size = 0
fps_num = 24
fps_den = 1


[x264.lan]
[x264.wan]
[x264.broadband_high]
[x264.satellite]

[x264.broadband_low]
preset = "veryfast"
tune = "zerolatency"
vbv_max_bitrate = 1800
vbv_buffer_size = 40

[x264.modem]
preset = "fast"
tune = "zerolatency"
vbv_max_bitrate = 500
vbv_buffer_size = 40
35 changes: 23 additions & 12 deletions xrdp/xrdp_encoder_x264.c
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
#include "arch.h"
#include "os_calls.h"
#include "xrdp_encoder_x264.h"
#include "xrdp_tconfig.h"

#define X264_MAX_ENCODERS 16

Expand All @@ -47,14 +48,25 @@ struct x264_encoder
struct x264_global
{
struct x264_encoder encoders[X264_MAX_ENCODERS];
struct xrdp_tconfig_gfx_x264_param x264_param[NUM_CONNECTION_TYPES];
};

/*****************************************************************************/
void *
xrdp_encoder_x264_create(void)
{
LOG_DEVEL(LOG_LEVEL_TRACE, "xrdp_encoder_x264_create:");
return g_new0(struct x264_global, 1);

struct x264_global *xg;
struct xrdp_tconfig_gfx gfxconfig;
xg = g_new0(struct x264_global, 1);
tconfig_load_gfx(GFX_CONF, &gfxconfig);

memcpy(&xg->x264_param, &gfxconfig.x264_param,
sizeof(struct xrdp_tconfig_gfx_x264_param) * NUM_CONNECTION_TYPES);

return xg;

}

/*****************************************************************************/
Expand Down Expand Up @@ -128,20 +140,19 @@ xrdp_encoder_x264_encode(void *handle, int session, int left, int top,
}
if ((width > 0) && (height > 0))
{
//x264_param_default_preset(&(xe->x264_params), "superfast", "zerolatency");
x264_param_default_preset(&(xe->x264_params), "ultrafast", "zerolatency");
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_width = (width + 15) & ~15;
xe->x264_params.i_height = (height + 15) & ~15;
xe->x264_params.i_fps_num = 24;
xe->x264_params.i_fps_den = 1;
//xe->x264_params.b_cabac = 1;
//xe->x264_params.i_bframe = 0;
//xe->x264_params.rc.i_rc_method = X264_RC_CQP;
//xe->x264_params.rc.i_qp_constant = 23;
//x264_param_apply_profile(&(xe->x264_params), "high");
x264_param_apply_profile(&(xe->x264_params), "main");
//x264_param_apply_profile(&(xe->x264_params), "baseline");
xe->x264_params.i_fps_num = xg->x264_param[ct].fps_num;
xe->x264_params.i_fps_den = xg->x264_param[ct].fps_den;
xe->x264_params.rc.i_rc_method = X264_RC_CRF;
xe->x264_params.rc.i_vbv_max_bitrate = xg->x264_param[ct].vbv_max_bitrate;
xe->x264_params.rc.i_vbv_buffer_size = xg->x264_param[ct].vbv_buffer_size;
x264_param_apply_profile(&(xe->x264_params),
xg->x264_param[ct].profile);
xe->x264_enc_han = x264_encoder_open(&(xe->x264_params));
LOG(LOG_LEVEL_INFO, "xrdp_encoder_x264_encode: "
"x264_encoder_open rv %p for width %d height %d",
Expand Down
Loading

0 comments on commit b3513ba

Please sign in to comment.