4#include <winpr/wtypes.h>
5#include <winpr/cmdline.h>
6#include <freerdp/server/shadow.h>
11 {
"codec", COMMAND_LINE_VALUE_REQUIRED,
"<codec>:<key>:<value>[,<codec>:<key>:<value>...]",
12 nullptr,
nullptr, -1,
nullptr,
"Encoder settings" },
13 {
nullptr, 0,
nullptr,
nullptr,
nullptr, -1,
nullptr,
nullptr }
19 H264_RATECONTROL_MODE h264Mode;
22#if defined(WITH_GFX_AV1)
23 FREERDP_AV1_RATECONTROL av1Mode;
26#if defined(WITH_GFX_AV2)
27 FREERDP_AV2_RATECONTROL av2Mode;
30#if defined(WITH_GFX_AZURE)
31 FREERDP_HEVC_RATECONTROL hevcMode;
36static void get_fields(
const rdpShadowServer* server, FIELDS* fields)
38 memset(fields, 0,
sizeof(*fields));
39 fields->h264Mode = server->h264RateControlMode;
40 fields->h264BitRate = server->h264BitRate;
41 fields->h264QP = server->h264QP;
42#if defined(WITH_GFX_AV1)
43 fields->av1Mode = server->AV1RateControlMode;
44 fields->av1BitRate = server->AV1BitRate;
46#if defined(WITH_GFX_AV2)
47 fields->av2Mode = server->AV2RateControlMode;
48 fields->av2BitRate = server->AV2BitRate;
50#if defined(WITH_GFX_AZURE)
51 fields->hevcMode = server->HEVCRateControlMode;
52 fields->hevcBitRate = server->HEVCBitRate;
59static BOOL expect(
const char* what,
const char* option, BOOL accepted,
void (*change)(FIELDS*))
61 char* argv[] = {
"freerdp-shadow-cli", (
char*)option,
nullptr };
62 const int argc = option ? 2 : 1;
64 rdpShadowServer* server = shadow_server_new();
67 (void)fprintf(stderr,
"%s: shadow_server_new failed\n", what);
71 FIELDS expected = { 0 };
72 get_fields(server, &expected);
73 if (accepted && change)
76 const int status = shadow_server_parse_command_line(server, argc, argv, options);
78 get_fields(server, &got);
79 shadow_server_free(server);
81 if ((status >= 0) != accepted)
83 (void)fprintf(stderr,
"%s: status %d, expected it %s\n", what, status,
84 accepted ?
"accepted" :
"refused");
87 if (memcmp(&got, &expected,
sizeof(got)) != 0)
90 "%s: the fields are not as expected (h264 mode %d bit rate %" PRIu32
92 what, (
int)got.h264Mode, got.h264BitRate, got.h264QP);
98static void h264_vbr_4000(FIELDS* f)
100 f->h264Mode = H264_RATECONTROL_VBR;
101 f->h264BitRate = 4000000;
104static void h264_cqp_26(FIELDS* f)
106 f->h264Mode = H264_RATECONTROL_CQP;
110static void h264_limits(FIELDS* f)
112 f->h264BitRate = 1000;
116#if defined(WITH_GFX_AV1)
117static void av1_cq_5000(FIELDS* f)
119 f->av1Mode = FREERDP_AV1_CQ;
120 f->av1BitRate = 5000;
124#if defined(WITH_GFX_AV2)
125static void av2_q_800(FIELDS* f)
127 f->av2Mode = FREERDP_AV2_Q;
132#if defined(WITH_GFX_AZURE)
133static void hevc_vbr_2000(FIELDS* f)
135 f->hevcMode = FREERDP_HEVC_VBR;
136 f->hevcBitRate = 2000000;
140static void mixed(FIELDS* f)
143#if defined(WITH_GFX_AV1)
144 f->av1BitRate = 3500;
148int TestShadowCodecOptions(
int argc,
char* argv[])
156 ok &= expect(
"none",
nullptr, TRUE,
nullptr);
159 ok &= expect(
"h264 vbr 4000",
"/codec:h264:rate-control:vbr,h264:bitrate:4000", TRUE,
161 ok &= expect(
"h264 cqp 26",
"/codec:h264:rate-control:cqp,h264:qp:26", TRUE, h264_cqp_26);
162 ok &= expect(
"h264 limits",
"/codec:h264:bitrate:1,h264:qp:51", TRUE, h264_limits);
163 ok &= expect(
"h264 qp 52",
"/codec:h264:qp:52", FALSE,
nullptr);
164 ok &= expect(
"h264 qp -1",
"/codec:h264:qp:-1", FALSE,
nullptr);
165 ok &= expect(
"h264 cbr",
"/codec:h264:rate-control:cbr", FALSE,
nullptr);
166 ok &= expect(
"h264 bit rate 4M",
"/codec:h264:bitrate:4M", FALSE,
nullptr);
167 ok &= expect(
"h264 bit rate 0",
"/codec:h264:bitrate:0", FALSE,
nullptr);
168 ok &= expect(
"h264 bit rate too high",
"/codec:h264:bitrate:1000001", FALSE,
nullptr);
169 ok &= expect(
"h264 unknown key",
"/codec:h264:fps:60", FALSE,
nullptr);
172 ok &= expect(
"one wrong part",
"/codec:h264:rate-control:cqp,h264:qp:99", FALSE,
nullptr);
173 ok &= expect(
"unknown codec",
"/codec:vp9:bitrate:1000", FALSE,
nullptr);
174 ok &= expect(
"no key",
"/codec:h264", FALSE,
nullptr);
175 ok &= expect(
"no value",
"/codec", FALSE,
nullptr);
177#if defined(WITH_GFX_AV1)
178 ok &= expect(
"av1 cq 5000",
"/codec:av1:rate-control:cq,av1:bitrate:5000", TRUE, av1_cq_5000);
179 ok &= expect(
"av1 bad mode",
"/codec:av1:rate-control:cqp", FALSE,
nullptr);
180 ok &= expect(
"av1 qp",
"/codec:av1:qp:20", FALSE,
nullptr);
181 ok &= expect(
"mixed",
"/codec:h264:rate-control:cqp,h264:qp:26,av1:bitrate:3500", TRUE, mixed);
183 ok &= expect(
"av1 not built in",
"/codec:av1:bitrate:3000", FALSE,
nullptr);
184 ok &= expect(
"mixed",
"/codec:h264:rate-control:cqp,h264:qp:26", TRUE, mixed);
187#if defined(WITH_GFX_AV2)
188 ok &= expect(
"av2 q 800",
"/codec:av2:rate-control:q,av2:bitrate:800", TRUE, av2_q_800);
189 ok &= expect(
"av2 bad mode",
"/codec:av2:rate-control:fast", FALSE,
nullptr);
191 ok &= expect(
"av2 not built in",
"/codec:av2:bitrate:500", FALSE,
nullptr);
194#if defined(WITH_GFX_AZURE)
195 ok &= expect(
"hevc vbr 2000",
"/codec:hevc:rate-control:vbr,hevc:bitrate:2000", TRUE,
197 ok &= expect(
"hevc cbr",
"/codec:hevc:rate-control:cbr", FALSE,
nullptr);
199 ok &= expect(
"hevc not built in",
"/codec:hevc:bitrate:500", FALSE,
nullptr);