From 22f1349adedaab5b5f5326dbcffe3213a4ecd69b Mon Sep 17 00:00:00 2001 From: Koichiro Iwao Date: Fri, 23 Aug 2024 16:54:10 +0900 Subject: [PATCH] GFX: add config which to prefer H264 vs RFX --- tests/xrdp/Makefile.am | 7 +- tests/xrdp/gfx/gfx_codec_h264_preferred.toml | 3 + tests/xrdp/gfx/gfx_codec_order_undefined.toml | 3 + tests/xrdp/gfx/gfx_codec_rfx_preferred.toml | 3 + tests/xrdp/test_tconfig.c | 19 ++++++ xrdp/gfx.toml | 3 + xrdp/xrdp_tconfig.c | 67 +++++++++++++++++++ xrdp/xrdp_tconfig.h | 7 ++ 8 files changed, 111 insertions(+), 1 deletion(-) create mode 100644 tests/xrdp/gfx/gfx_codec_h264_preferred.toml create mode 100644 tests/xrdp/gfx/gfx_codec_order_undefined.toml create mode 100644 tests/xrdp/gfx/gfx_codec_rfx_preferred.toml diff --git a/tests/xrdp/Makefile.am b/tests/xrdp/Makefile.am index 02f8b3e26..b80cae1d3 100644 --- a/tests/xrdp/Makefile.am +++ b/tests/xrdp/Makefile.am @@ -21,7 +21,12 @@ EXTRA_DIST = \ test_not4_8bit.bmp \ test_not4_24bit.bmp \ test1.jpg \ - test_alpha_blend.png + test_alpha_blend.png \ + gfx/gfx.toml\ + gfx/gfx_codec_order_undefined.toml \ + gfx/gfx_codec_h264_preferred.toml \ + gfx/gfx_codec_rfx_preferred.toml + TESTS = test_xrdp check_PROGRAMS = test_xrdp diff --git a/tests/xrdp/gfx/gfx_codec_h264_preferred.toml b/tests/xrdp/gfx/gfx_codec_h264_preferred.toml new file mode 100644 index 000000000..828a65cb6 --- /dev/null +++ b/tests/xrdp/gfx/gfx_codec_h264_preferred.toml @@ -0,0 +1,3 @@ +[codec] + +order = [ "H264", "RFX" ] diff --git a/tests/xrdp/gfx/gfx_codec_order_undefined.toml b/tests/xrdp/gfx/gfx_codec_order_undefined.toml new file mode 100644 index 000000000..e31872683 --- /dev/null +++ b/tests/xrdp/gfx/gfx_codec_order_undefined.toml @@ -0,0 +1,3 @@ +[codec] + +order = [ ] diff --git a/tests/xrdp/gfx/gfx_codec_rfx_preferred.toml b/tests/xrdp/gfx/gfx_codec_rfx_preferred.toml new file mode 100644 index 000000000..e9d52f02e --- /dev/null +++ b/tests/xrdp/gfx/gfx_codec_rfx_preferred.toml @@ -0,0 +1,3 @@ +[codec] + +order = [ "RFX", "H264" ] diff --git a/tests/xrdp/test_tconfig.c b/tests/xrdp/test_tconfig.c index 14f81c2b6..bdc5797f1 100644 --- a/tests/xrdp/test_tconfig.c +++ b/tests/xrdp/test_tconfig.c @@ -31,6 +31,24 @@ START_TEST(test_tconfig_gfx_x264_load_basic) } END_TEST +START_TEST(test_tconfig_gfx_codec_order) +{ + struct xrdp_tconfig_gfx gfxconfig; + + /* H264 earlier */ + tconfig_load_gfx("./gfx/gfx_codec_h264_preferred.toml", &gfxconfig); + ck_assert_int_lt(gfxconfig.codec.h264_idx, gfxconfig.codec.rfx_idx); + + /* RFX earlier */ + tconfig_load_gfx("./gfx/gfx_codec_rfx_preferred.toml", &gfxconfig); + ck_assert_int_lt(gfxconfig.codec.rfx_idx, gfxconfig.codec.h264_idx); + + /* RFX is preferred if order undefined */ + tconfig_load_gfx("./gfx/gfx_codec_order_undefined.toml", &gfxconfig); + ck_assert_int_lt(gfxconfig.codec.h264_idx, gfxconfig.codec.rfx_idx); +} +END_TEST + /******************************************************************************/ Suite * make_suite_tconfig_load_gfx(void) @@ -43,6 +61,7 @@ make_suite_tconfig_load_gfx(void) 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); + tcase_add_test(tc_tconfig_load_gfx, test_tconfig_gfx_codec_order); suite_add_tcase(s, tc_tconfig_load_gfx); diff --git a/xrdp/gfx.toml b/xrdp/gfx.toml index 5b7f27c41..367edab64 100644 --- a/xrdp/gfx.toml +++ b/xrdp/gfx.toml @@ -1,3 +1,6 @@ +[codec] +order = [ "H264", "RFX" ] + [x264.default] preset = "ultrafast" tune = "zerolatency" diff --git a/xrdp/xrdp_tconfig.c b/xrdp/xrdp_tconfig.c index d16a0f4a5..d71959086 100644 --- a/xrdp/xrdp_tconfig.c +++ b/xrdp/xrdp_tconfig.c @@ -199,6 +199,70 @@ tconfig_load_gfx_x264_ct(toml_table_t *tfile, const int connection_type, return 0; } +static int tconfig_load_gfx_order(toml_table_t *tfile, struct xrdp_tconfig_gfx *config) +{ + TCLOG(LOG_LEVEL_DEBUG, "tconfig_load_gfx_order:"); + + int h264_found = 0; + int rfx_found = 0; + + toml_table_t *codec = toml_table_in(tfile, "codec"); + if (!codec) + { + goto return_default_codec_order; + } + + toml_array_t *order = toml_array_in(codec, "order"); + if (!order) + { + goto return_default_codec_order; + } + + for (int i = 0; ; i++) + { + toml_datum_t datum = toml_string_at(order, i); + + if (datum.ok) + { + if (g_strcasecmp(datum.u.s, "h264") == 0 || + g_strcasecmp(datum.u.s, "h.264") == 0) + { + h264_found = 1; + config->codec.h264_idx = i; + } + if (g_strcasecmp(datum.u.s, "rfx") == 0) + { + rfx_found = 1; + config->codec.rfx_idx = i; + } + free(datum.u.s); + } + else + { + break; + } + } + + if (h264_found == 0 && rfx_found == 0) + { + goto return_default_codec_order; + } + + TCLOG(LOG_LEVEL_DEBUG, "codec_order: h264_idx=%d, rfx_idx=%d", + config->codec.h264_idx, config->codec.rfx_idx); + return 0; + +return_default_codec_order: + config->codec.h264_idx = 0; + config->codec.rfx_idx = 1; + + TCLOG(LOG_LEVEL_ERROR, "coder_order: could not get codec order, using default order" + "h264_idx=%d, rfx_idx=%d", + config->codec.h264_idx, config->codec.rfx_idx); + + return 1; +} + int tconfig_load_gfx(const char *filename, struct xrdp_tconfig_gfx *config) { @@ -225,6 +289,9 @@ tconfig_load_gfx(const char *filename, struct xrdp_tconfig_gfx *config) memset(config, 0, sizeof(struct xrdp_tconfig_gfx)); + /* Load GFX order */ + tconfig_load_gfx_order(tfile, config); + /* First of all, read the default params and override later */ tconfig_load_gfx_x264_ct(tfile, 0, config->x264_param); diff --git a/xrdp/xrdp_tconfig.h b/xrdp/xrdp_tconfig.h index 6a5ba9704..8364dcd8d 100644 --- a/xrdp/xrdp_tconfig.h +++ b/xrdp/xrdp_tconfig.h @@ -42,8 +42,15 @@ struct xrdp_tconfig_gfx_x264_param int fps_den; }; +struct xrdp_tconfig_gfx_codec_order +{ + int h264_idx; + int rfx_idx; +}; + struct xrdp_tconfig_gfx { + struct xrdp_tconfig_gfx_codec_order codec; /* store x264 parameters for each connection type */ struct xrdp_tconfig_gfx_x264_param x264_param[NUM_CONNECTION_TYPES]; };