6#include <freerdp/channels/rdpgfx.h>
8#include "../../SDL3/sdl_overlay_model.hpp"
15#if defined(WITH_GFX_AV2)
16constexpr const char* av1Unknown =
"AV1/AV2";
18constexpr const char* av1Unknown =
"AV1";
22static std::vector<std::string> statNames()
25 "NETWORK_BYTES_RECEIVED",
"NETWORK_BYTES_SENT",
"NETWORK_BANDWIDTH_KBPS",
26 "NETWORK_RTT_BASE_MS",
"NETWORK_RTT_AVERAGE_MS",
"GFX_CAPS_VERSION",
27 "RDPGFX_CODECID_UNKNOWN",
"RDPGFX_CODECID_AVC420",
"RDPGFX_CODECID_AVC420_BYTES",
28 "RDPGFX_CMDID_CACHETOSURFACE",
"RDPGFX_CODECID_AV1",
"RDPGFX_CODECID_UNKNOWN_BYTES",
29 "FREERDP_CLIENT_STATS_UNUSED",
"NETWORK_BYTES_RECEIVED",
52static Reading reading(uint64_t seconds)
55 r.
ns = seconds * 1000000000ull;
57 r.desktopWidth = 1920;
58 r.desktopHeight = 1080;
62static const Row* find(
const std::vector<Row>& rows,
const std::string& label)
64 for (
const auto& row : rows)
66 if (row.label == label)
73static const Row* next(
const std::vector<Row>& rows,
const std::string& label)
75 for (
size_t x = 0; x + 1 < rows.size(); x++)
77 if (rows.at(x).label == label)
78 return &rows.at(x + 1);
83static bool expect(
const Row* row,
const std::string& value,
int line)
87 (void)fprintf(stderr,
"line %d: no row, expected '%s'\n", line, value.c_str());
90 if (row->value != value)
92 (void)fprintf(stderr,
"line %d: '%s' is '%s', expected '%s'\n", line, row->label.c_str(),
93 row->value.c_str(), value.c_str());
99#define EXPECT(row, value) \
100 if (!expect((row), (value), __LINE__)) \
105 (void)fprintf(stderr, "line %d: %s\n", __LINE__, #cond); \
109static int checkNames()
111 const Names n(statNames());
114 r.
values.at(RX_AGAIN) = 99;
116 CHECK(n.get(r,
"NETWORK_BYTES_RECEIVED").value_or(0) == 7);
117 CHECK(!n.has(
"RDPGFX_CODECID_UNKNOWN"));
118 CHECK(!n.has(
"RDPGFX_CODECID_UNKNOWN_BYTES"));
119 CHECK(!n.has(
"FREERDP_CLIENT_STATS_UNUSED"));
120 CHECK(!n.get(r,
"NO_SUCH_NAME"));
125 CHECK(!n.get(shorter,
"NETWORK_RTT_AVERAGE_MS"));
129static int checkRates()
131 const Names n(statNames());
132 auto prev = reading(10);
133 auto now = reading(12);
134 prev.values.at(RX) = 1000000;
135 now.values.at(RX) = 1500000;
136 now.values.at(TX) = 2500000;
137 prev.values.at(AVC420) = 100;
138 now.values.at(AVC420) = 160;
139 prev.values.at(AVC420_BYTES) = 0;
140 now.values.at(AVC420_BYTES) = 200000;
141 now.values.at(CACHE) = 8;
142 prev.values.at(CACHE) = 0;
146 EXPECT(find(rows,
"Resolution"),
"1920 × 1080, window 1280 × 720");
147 EXPECT(find(rows,
"Network in (RDP)"),
"2000 kbit/s, 1.5 MB this connection");
149 EXPECT(find(rows,
"Network out (RDP)"),
"10000 kbit/s, 2.5 MB this connection");
150 EXPECT(find(rows,
"Video codecs"),
"H.264 4:2:0 (AVC420) 30/s 800 kbit/s");
151 EXPECT(next(rows,
"Video codecs"),
"CacheToSurface 4/s");
152 EXPECT(find(rows,
"Session"),
"2:05");
156 EXPECT(find(first,
"Network in (RDP)"),
"– kbit/s, 1.5 MB this connection");
157 EXPECT(find(first,
"Video codecs"),
"H.264 4:2:0 (AVC420) –/s – kbit/s");
160 prev.values.at(AVC420) = 500;
162 EXPECT(find(reset,
"Video codecs"),
"H.264 4:2:0 (AVC420) –/s 800 kbit/s");
166static int checkLabels()
168 const Names n(statNames());
169 auto now = reading(1);
170 now.values.at(AV1) = 1;
174 EXPECT(find(rows,
"Video codecs"), std::string(av1Unknown) +
" –/s – kbit/s");
176#if defined(WITH_GFX_AV2)
177 now.values.at(CAPS) = RDPGFX_CAPVERSION_FRDP_2;
179 EXPECT(find(rows,
"Video codecs"),
"AV2 –/s – kbit/s");
183 now.values.at(CAPS) = RDPGFX_CAPVERSION_107;
185 EXPECT(find(rows,
"Video codecs"),
"AV1 –/s – kbit/s");
189 EXPECT(find(empty,
"Video codecs"),
"no updates yet");
193static int checkNetwork()
195 const Names n(statNames());
196 auto now = reading(1);
198 EXPECT(find(rows,
"Round trip"),
"not measured");
199 EXPECT(find(rows,
"Bandwidth"),
"not measured");
201 now.values.at(RTT) = 23;
202 now.values.at(RTT_BASE) = 11;
203 now.values.at(KBPS) = 54000;
205 EXPECT(find(rows,
"Round trip"),
"23 ms (lowest 11)");
206 EXPECT(find(rows,
"Bandwidth"),
"54000 kbit/s");
209 const Names few({
"NETWORK_BYTES_RECEIVED" });
211 CHECK(!find(rows,
"Video codecs"));
212 CHECK(!find(rows,
"Round trip"));
216static int checkClient()
218 const char* config =
"Build configuration: WITH_A=ON WITH_B=OFF\n"
219 "Build type: Release\n"
221 "Compiler: GNU, 16.2.0\n"
222 "Target architecture: x86_64\n";
229 return (a.x < b.x + b.w) && (b.x < a.x + a.w) && (a.y < b.y + b.h) && (b.y < a.y + a.h);
232static int checkLayout()
236 CHECK(l.left.x == 12);
237 CHECK(l.left.y == 12);
238 CHECK(l.right.x == 1280 - 12 - 300);
239 CHECK(l.right.y == 12);
243 CHECK(l.right.y == 12 + 110 + 12);
244 CHECK(l.right.x == 1000 - 12 - 480);
248 CHECK(l.right.x == 0);
249 CHECK(l.right.y == 134);
253 CHECK(l.right.y == 12);
256 for (
int w = 50; w <= 3000; w += 7)
258 const auto width =
static_cast<float>(w);
259 for (
const auto& sizes : { std::array<float, 4>{ 590, 110, 480, 200 },
260 std::array<float, 4>{ 100, 300, 900, 50 },
261 std::array<float, 4>{ 700, 90, 700, 400 } })
264 if (overlap(l.left, l.right))
266 (void)fprintf(stderr,
"overlap at width %.0f\n",
static_cast<double>(width));
274int TestSDLOverlayModel([[maybe_unused]]
int argc, [[maybe_unused]]
char* argv[])
277 { checkNames, checkRates, checkLabels, checkNetwork, checkClient, checkLayout })
279 const int rc = check();
Layout layout(float leftWidth, float leftHeight, float rightWidth, float rightHeight, float width, float margin)
std::vector< Row > realtimeRows(const Names &names, const Reading &now, const Reading *prev, const View &view)
std::string buildSummary(const char *config)
std::vector< uint64_t > values