Xbox Cloud Gaming app for PS5 Homebrew
C
Network warning in games and a summary at the end of each session
Rafael Abud Ferreirae9ea780724ff
diff --git a/src/app/cli_main.cpp b/src/app/cli_main.cppindex 0442de8..4720d6b 100644--- a/src/app/cli_main.cpp+++ b/src/app/cli_main.cpp@@ -909,6 +909,11 @@ int main(int argc, char** argv) {save("stats", menu.renderStats(info), ui::StreamMenu::kStatsX, ui::StreamMenu::kStatsY, 200);ui::setLanguage(ui::Language::PortugueseBR);save("menu_pt", menu.renderMenu(info), ui::StreamMenu::kMenuX, ui::StreamMenu::kMenuY, 235);+ // The connection warning: in the statistics line, and alone.+ info.degraded = true;+ save("stats_warn", menu.renderStats(info), ui::StreamMenu::kStatsX, ui::StreamMenu::kStatsY, 200);+ ui::Canvas warn = menu.renderWarning();+ save("warn", warn, ui::StreamMenu::kWarnRight - warn.width(), ui::StreamMenu::kWarnY, 200);return 0;} else if (cmd == "ui-badges" && argi < argc) {// Offline: "Your games" with every badge, hiding, sorting and thediff --git a/src/app/report.cpp b/src/app/report.cppindex 293959b..a3955be 100644--- a/src/app/report.cpp+++ b/src/app/report.cpp@@ -112,11 +112,13 @@ std::string logExcerpt(const std::string& logText, bool previousSession, size_tif (nl > at) lines.push_back(logText.substr(at, nl - at));at = nl + 1;}- // The first line (the version's start), warnings and errors, and the+ // The first line (the version's start), warnings and errors, the game+ // sessions' summaries, and the// last lines; in order, each once, each at most 160 characters.std::set<size_t> keep;for (size_t i = 0; i < lines.size(); ++i)if (i == 0 || lines[i].find("[E]") != std::string::npos || lines[i].find("[W]") != std::string::npos ||+ lines[i].find("session summary:") != std::string::npos ||i + lastLines >= lines.size())keep.insert(i);std::string out;diff --git a/src/app/stream_screen.cpp b/src/app/stream_screen.cppindex efba40b..32a98fa 100644--- a/src/app/stream_screen.cpp+++ b/src/app/stream_screen.cpp@@ -392,6 +392,10 @@ void StreamScreen::update(const input::ControllerState& pad, ui::NavInput nav, b} else if (showStats_ && seq) {ui::Canvas c = menu_.renderStats(info);display::setOverlay(c.data(), ui::StreamMenu::kStatsX, ui::StreamMenu::kStatsY, c.width(), c.height(), 200);+ } else if (info.degraded) {+ ui::Canvas c = menu_.renderWarning();+ display::setOverlay(c.data(), ui::StreamMenu::kWarnRight - c.width(), ui::StreamMenu::kWarnY, c.width(),+ c.height(), 200);} else {display::setOverlay(nullptr, 0, 0, 0, 0, 0);}diff --git a/src/app/worker.cpp b/src/app/worker.cppindex c36dbf9..5b51dcd 100644--- a/src/app/worker.cpp+++ b/src/app/worker.cpp@@ -98,6 +98,16 @@ std::string stream(xcloud::GssvClient& gssv) {bool autoplayDone = false;int bestRtt = -1; // lowest round trip seen: the region's latencyint tallest = 0; // the tallest picture seen (the probe's measure)+ // The connection's state for the warning and the end-of-session summary:+ // a second is bad when the jitter buffer dropped a frame (lost for good),+ // no video arrived at all, or the round trip went far above the best seen.+ // Not the frame rate: games send fewer frames in some scenes.+ uint64_t degradedUntil = 0, lastTickAt = 0;+ bool degradedLogged = false;+ int reconnectsSeen = 0;+ struct {+ uint64_t seconds = 0, badSeconds = 0, kbps = 0, rttSum = 0, rttCount = 0;+ } session;bool probeDone = !g_probing;auto recordProbe = [&] {probeDone = true;@@ -170,6 +180,32 @@ std::string stream(xcloud::GssvClient& gssv) {info.onScreenMs = st.displayAvgUs / 1000.0;info.width = st.width;info.height = st.height;+ if (last.decodedFrames > 0) { // once the picture is running+ uint64_t dropped = st.rtpDroppedFrames - last.rtpDroppedFrames;+ uint64_t now = platform::nowMs();+ // No video for a second; or the loop itself held up (a+ // reconnection blocks it) / a new session after a drop.+ bool stalled = st.videoFrames == last.videoFrames || (lastTickAt && now - lastTickAt > 2500) ||+ player.reconnects() != reconnectsSeen;+ reconnectsSeen = player.reconnects();+ bool slow = st.rttMs > 0 && bestRtt > 0 && st.rttMs > bestRtt + 60;+ if (dropped || stalled || slow) {+ if (!degradedLogged) // once per episode+ XC_LOGW("connection degraded: %llu frame(s) lost, %s, rtt %d ms (best %d)",+ static_cast<unsigned long long>(dropped), stalled ? "no video for a second" : "video arriving",+ st.rttMs, bestRtt);+ degradedLogged = true;+ degradedUntil = now + 3000;+ ++session.badSeconds;+ } else if (now >= degradedUntil) {+ degradedLogged = false;+ }+ info.degraded = now < degradedUntil;+ lastTickAt = now;+ ++session.seconds;+ session.kbps += st.rtpKbps;+ if (st.rttMs > 0) session.rttSum += static_cast<uint64_t>(st.rttMs), ++session.rttCount;+ }std::lock_guard<std::mutex> lock(g_infoMutex);g_streamInfo = info;++g_infoSeq;@@ -198,6 +234,21 @@ std::string stream(xcloud::GssvClient& gssv) {g_ui->setRegionLatency(rtt);}auto st = player.stats();+ if (session.seconds >= 10) {+ // The session in one line: the log (and so a report) and a notification.+ double lossPct = st.rtpPackets + st.rtpLost ? 100.0 * (st.rtpLost - std::min(st.rtpRecovered, st.rtpLost)) /+ static_cast<double>(st.rtpPackets + st.rtpLost)+ : 0;+ char details[160];+ std::snprintf(details, sizeof details, "%llu min, %dp, %.1f Mbps, %.2f%% lost, %d ms",+ static_cast<unsigned long long>((session.seconds + 30) / 60), tallest,+ session.kbps / 1000.0 / static_cast<double>(session.seconds), lossPct,+ session.rttCount ? static_cast<int>(session.rttSum / session.rttCount) : -1);+ XC_LOGI("session summary: %s; %llu s with a degraded connection, %llu frames lost, %llu recovered packets",+ details, static_cast<unsigned long long>(session.badSeconds),+ static_cast<unsigned long long>(st.rtpDroppedFrames), static_cast<unsigned long long>(st.rtpRecovered));+ if (!autoplayDone || g_autoplay.title.empty()) platform::notify(ui::trf(ui::Str::SessionSummary, details), "session summary (notification)");+ }// Ended before a single frame: the game never started (e.g. it closed on// the server); say so on the error screen instead of going back quietly.if (st.decodedFrames == 0 && !g_cancel && !autoplayDone) {diff --git a/src/ui/stream_menu.cpp b/src/ui/stream_menu.cppindex 872b0c0..5279053 100644--- a/src/ui/stream_menu.cpp+++ b/src/ui/stream_menu.cpp@@ -17,6 +17,7 @@ constexpr Color kGray = rgba(190, 190, 190);constexpr Color kDim = rgba(140, 140, 140);constexpr Color kDark = rgba(20, 20, 20);constexpr Color kGreen = rgba(16, 124, 16);+constexpr Color kWarnColor = rgba(255, 176, 32); // the connection warning// Left to right on the resolution row: SettingsChoice::resolution values.constexpr int kResolutionOrder[] = {1, 0, 2};@@ -329,10 +330,24 @@ Canvas StreamMenu::renderStats(const StreamInfo& info) const {text += " " + fmt("%.1f%%", info.lossPct);if (!micMuted_) text += " MIC";constexpr int kPx = 20, kH = 36;- int w = fonts_.semibold.measure(text, kPx) + 28;+ std::string warn = info.degraded ? std::string(" ") + tr(Str::ConnectionUnstable) : std::string();+ int tw = fonts_.semibold.measure(text, kPx);+ int w = tw + fonts_.semibold.measure(warn, kPx) + 28;Canvas c(w, kH);c.clear(kPanel);fonts_.semibold.draw(c, text, 14, fonts_.semibold.centeredY(0, kH, kPx), kPx, kWhite);+ if (!warn.empty()) fonts_.semibold.draw(c, warn, 14 + tw, fonts_.semibold.centeredY(0, kH, kPx), kPx, kWarnColor);+ return c;+}++Canvas StreamMenu::renderWarning() const {+ const char* text = tr(Str::ConnectionUnstable);+ constexpr int kPx = 20, kH = 36, kDot = 6;+ int w = fonts_.semibold.measure(text, kPx) + 28 + 2 * kDot + 10;+ Canvas c(w, kH);+ c.clear(kPanel);+ c.fillCircle(14.0f + kDot, kH / 2.0f, static_cast<float>(kDot), kWarnColor);+ fonts_.semibold.draw(c, text, 14 + 2 * kDot + 10, fonts_.semibold.centeredY(0, kH, kPx), kPx, kWhite);return c;}diff --git a/src/ui/stream_menu.h b/src/ui/stream_menu.hindex 4f01ef9..19529eb 100644--- a/src/ui/stream_menu.h+++ b/src/ui/stream_menu.h@@ -21,6 +21,7 @@ struct StreamInfo {double fps = 0, mbps = 0, lossPct = 0, decodeMs = 0;double onScreenMs = 0; // network arrival to on the TV (GPU path); 0 = unknownint width = 0, height = 0; // of the decoded picture+ bool degraded = false; // frames lost / video stalled / round trip far up, in the last seconds};// Close: the menu went away (Circle, OPTIONS, or the Xbox button): a fresh key frame is asked for.@@ -34,6 +35,8 @@ public:static constexpr int kMenuW = 620, kMenuH = 1064;static constexpr int kMenuX = 80, kMenuY = (1080 - kMenuH) / 2;static constexpr int kStatsX = 32, kStatsY = 28;+ // The connection warning, alone (the statistics line off), top right.+ static constexpr int kWarnRight = 1888, kWarnY = 28;explicit StreamMenu(const Fonts& fonts) : fonts_(fonts) {}@@ -78,6 +81,8 @@ public:Canvas renderMenu(const StreamInfo& info) const;Canvas renderStats(const StreamInfo& info) const;+ // "Unstable connection", on its own (when the statistics line is off).+ Canvas renderWarning() const;private:enum Item {diff --git a/src/ui/strings.cpp b/src/ui/strings.cppindex dc0979a..5e141e3 100644--- a/src/ui/strings.cpp+++ b/src/ui/strings.cpp@@ -264,6 +264,8 @@ constexpr Column kEnglish = {"Estimated wait: %s min", // QueueMinutes"120 Hz output (VRR)", // HighRefresh"On (in games)", // HighRefreshOn+ "Unstable connection", // ConnectionUnstable+ "Session: %s", // SessionSummary};constexpr Column kPortugueseBR = {@@ -498,6 +500,8 @@ constexpr Column kPortugueseBR = {"Espera estimada: %s min", // QueueMinutes"Saída 120 Hz (VRR)", // HighRefresh"Ativada (nos jogos)", // HighRefreshOn+ "Conexão instável", // ConnectionUnstable+ "Sessão: %s", // SessionSummary};constexpr Column kSpanish = {@@ -732,6 +736,8 @@ constexpr Column kSpanish = {"Espera estimada: %s min", // QueueMinutes"Salida 120 Hz (VRR)", // HighRefresh"Activada (en los juegos)", // HighRefreshOn+ "Conexión inestable", // ConnectionUnstable+ "Sesión: %s", // SessionSummary};constexpr Column kFrench = {@@ -966,6 +972,8 @@ constexpr Column kFrench = {"Attente estimée : %s min", // QueueMinutes"Sortie 120 Hz (VRR)", // HighRefresh"Activée (en jeu)", // HighRefreshOn+ "Connexion instable", // ConnectionUnstable+ "Session : %s", // SessionSummary};constexpr Column kGerman = {@@ -1200,6 +1208,8 @@ constexpr Column kGerman = {"Geschätzte Wartezeit: %s Min.", // QueueMinutes"120-Hz-Ausgabe (VRR)", // HighRefresh"An (in Spielen)", // HighRefreshOn+ "Instabile Verbindung", // ConnectionUnstable+ "Sitzung: %s", // SessionSummary};constexpr Column kItalian = {@@ -1434,6 +1444,8 @@ constexpr Column kItalian = {"Attesa stimata: %s min", // QueueMinutes"Uscita 120 Hz (VRR)", // HighRefresh"Attiva (nei giochi)", // HighRefreshOn+ "Connessione instabile", // ConnectionUnstable+ "Sessione: %s", // SessionSummary};constexpr std::array<const Column*, kLangs> kTable = {&kEnglish, &kPortugueseBR, &kSpanish,diff --git a/src/ui/strings.h b/src/ui/strings.hindex 15ad78f..9d31c26 100644--- a/src/ui/strings.h+++ b/src/ui/strings.h@@ -241,6 +241,8 @@ enum class Str {QueueMinutes, // ... in minutes (%s)HighRefresh, // Settings row: 119.88 Hz outputHighRefreshOn, // ... its "on" choice (while a game streams; the menus stay at 60 Hz)+ ConnectionUnstable, // in a game: frames lost, video stalled or the round trip far up+ SessionSummary, // notification at the end of a game (%s: minutes, resolution, Mbps, loss, ms)Count};