Skip to content

Xbox Cloud Gaming app for PS5 Homebrew

C

Resolution: offer only what is delivered; own Xbox at its top tier

Rafael Abud Ferreiraa7ac1fe65fb6
diff --git a/src/app/ps5_main.cpp b/src/app/ps5_main.cpp
index f8524c0..f8887f8 100644
--- a/src/app/ps5_main.cpp
+++ b/src/app/ps5_main.cpp
@@ -159,6 +159,7 @@ bool g_autoplayDump = false;
int g_autoplayRuns = 1;
bool g_autoplayIdle = false;
bool g_autoplayConsolesTab = false;
+bool g_autoplaySettingsTest = false; // autoplay "settingstest": open the resolution list, save settings.ppm
bool g_autoplayConsolesEmpty = false; // with "consolestab": as if none were found // autoplay "consolestab": open My consoles, save consoles.ppm
bool g_autoplayConsoles = false; // autoplay "consoles": log the account's own consoles (xhome)
bool g_autoplayPad = false; // autoplay "pad": the physical pad stays in use, its buttons logged
@@ -177,7 +178,16 @@ int g_autoplayDeband = -1; // deband=0..2: instead of the setting
int g_autoplaySharpness = -1; // sharp=0..3: instead of the setting
std::string g_autoplayResolution; // res=720p|1080p|1440p: instead of the setting
std::atomic<bool> g_syntheticA{false};
-std::atomic<bool> g_playingHome{false}; // the stream is the user's own Xbox
+std::atomic<bool> g_playingHome{false};
+// This stream measures the tallest picture its kind delivers (asked for the
+// top tier), then asks for g_afterProbeAlias if not empty.
+bool g_probing = false;
+std::string g_afterProbeAlias;
+std::atomic<bool> g_tierPicked{false}; // the game menu chose a tier: the probe leaves it
+constexpr int64_t kReprobeSeconds = 7 * 24 * 3600;
+
+// Caller holds g_settingsMutex. 1440p is offered once a stream delivered it.
+bool allow1440Locked() { return std::max(g_settings.maxHeightCloud, g_settings.maxHeightHome) >= 1440; } // the stream is the user's own Xbox
std::atomic<uint64_t> g_xboxButtonUntil{0}; // the game menu's Xbox button, held until then (ms)
void loadAutoplay() {
@@ -211,6 +221,7 @@ void loadAutoplay() {
if (opt == "pad") g_autoplayPad = true;
if (opt == "consoles") g_autoplayConsoles = true;
if (opt == "consolestab") g_autoplayConsolesTab = true;
+ if (opt == "settingstest") g_autoplaySettingsTest = true;
if (opt == "consolesempty") g_autoplayConsolesTab = g_autoplayConsolesEmpty = true;
if (opt == "librarytest") g_autoplayLibraryTest = true;
if (opt == "imetest") g_autoplayImeTest = true;
@@ -302,6 +313,18 @@ std::string stream(xcloud::GssvClient& gssv) {
bool snapshot1 = false, snapshot2 = false;
bool autoplayDone = false;
int bestRtt = -1; // lowest round trip seen: the region's latency
+ int tallest = 0; // the tallest picture seen (the probe's measure)
+ bool probeDone = !g_probing;
+ auto recordProbe = [&] {
+ probeDone = true;
+ if (tallest <= 0) return;
+ std::lock_guard<std::mutex> lock(g_settingsMutex);
+ (gssv.isHome() ? g_settings.maxHeightHome : g_settings.maxHeightCloud) = tallest;
+ (gssv.isHome() ? g_settings.probedHome : g_settings.probedCloud) = auth::unixNow();
+ g_settings.save(settingsPath());
+ g_ui->setAllow1440(allow1440Locked());
+ XC_LOGI("resolution probe (%s): %dp at most", gssv.isHome() ? "own Xbox" : "cloud", tallest);
+ };
app::StreamPlayer::Stats last{};
while (player.running() && !g_cancel) {
uint64_t elapsed = platform::nowMs() - started;
@@ -346,6 +369,11 @@ std::string stream(xcloud::GssvClient& gssv) {
static_cast<unsigned long long>(st.lateFrames), st.rttMs, st.width, st.height,
st.displayAvgUs / 1000.0, st.displayMaxUs / 1000.0);
if (st.rttMs > 0 && (bestRtt < 0 || st.rttMs < bestRtt)) bestRtt = st.rttMs;
+ tallest = std::max(tallest, st.height);
+ if (!probeDone && platform::nowMs() - started >= 20000) {
+ recordProbe();
+ if (!g_afterProbeAlias.empty() && !g_tierPicked) player.requestResolution(g_afterProbeAlias);
+ }
{
ui::StreamInfo info;
info.region = ui::prettyRegion(gssv.region().name);
@@ -370,6 +398,7 @@ std::string stream(xcloud::GssvClient& gssv) {
std::lock_guard<std::mutex> lock(g_playerMutex);
g_player = nullptr;
}
+ if (!probeDone && player.stats().decodedFrames > 0) recordProbe(); // a short stream still measured
std::string reason = g_cancel ? "left the game" : autoplayDone ? "autoplay finished" : player.endReason();
player.stop();
if (bestRtt > 0) {
@@ -409,10 +438,32 @@ std::string play(auth::AuthManager& am, xcloud::GssvClient& gssv, const ui::Game
{
std::lock_guard<std::mutex> lock(g_settingsMutex);
const std::string& res = g_autoplayResolution.empty() ? g_settings.resolution : g_autoplayResolution;
- gssv.setResolution(res == "720p" ? xcloud::Resolution::P720
- : res == "1440p" ? xcloud::Resolution::P1440
- : res == "1080p-hq" ? xcloud::Resolution::P1080HQ
- : xcloud::Resolution::P1080);
+ // What each kind of stream can deliver is measured, not assumed: the
+ // first stream (and one a week) asks for the top tier and records
+ // the picture's height. The user's own Xbox always gets the top tier
+ // (it sends 1080p either way, at ~16 Mbps instead of ~9.5).
+ bool home = gssv.isHome();
+ int64_t now = auth::unixNow();
+ int known = home ? g_settings.maxHeightHome : g_settings.maxHeightCloud;
+ int64_t probed = home ? g_settings.probedHome : g_settings.probedCloud;
+ g_probing = g_autoplayResolution.empty() && res != "720p" && (known == 0 || now - probed > kReprobeSeconds);
+ g_afterProbeAlias.clear();
+ g_tierPicked = false;
+ xcloud::Resolution tier;
+ if (!g_autoplayResolution.empty())
+ tier = res == "720p" ? xcloud::Resolution::P720
+ : res == "1440p" ? xcloud::Resolution::P1440
+ : res == "1080p-hq" ? xcloud::Resolution::P1080HQ
+ : xcloud::Resolution::P1080;
+ else if (res == "720p")
+ tier = xcloud::Resolution::P720;
+ else if (home || g_probing || (res == "1440p" && known >= 1440))
+ tier = xcloud::Resolution::P1440;
+ else
+ tier = xcloud::Resolution::P1080;
+ // A cloud probe goes back to what the user chose once measured.
+ if (g_probing && !home && !(res == "1440p")) g_afterProbeAlias = "1080HQ";
+ gssv.setResolution(tier);
const xcloud::Region* region = gssv.session().defaultRegion();
const std::string& wanted = regionName.empty() ? g_settings.region : regionName;
for (const auto& r : gssv.session().regions)
@@ -719,7 +770,7 @@ void loadLibrary(xcloud::GssvClient& gssv) {
library->hydrate(changed, &g_stopHydration);
});
if (!g_autoplayTitle.empty() && g_autoplayTitle != "BENCH" && !g_autoplayDetailTest && !g_autoplayLibraryTest &&
- !g_autoplayConsolesTab &&
+ !g_autoplayConsolesTab && !g_autoplaySettingsTest &&
!g_autoplayImeTest && !g_autoplayVibeTest) {
platform::sleepMs(6000); // leave the home screen up for ui.ppm
ui::GameTile tile;
@@ -933,6 +984,7 @@ int main(int argc, char** argv) {
choice.triggerRumble = g_settings.triggerRumble;
choice.circleConfirms = g_settings.circleConfirms;
choice.lightBar = g_settings.lightBar;
+ g_ui->setAllow1440(allow1440Locked());
g_ui->setSettings(choice);
applyControllerSettings();
g_ui->setRegionLatency(g_settings.regionRtt);
@@ -978,6 +1030,7 @@ int main(int argc, char** argv) {
uint32_t overlaySeq = 0; // g_infoSeq + 1 when drawn; 0 = redraw
uint64_t homeSince = 0, launchSince = 0;
bool uiSaved = false, launchSaved = false;
+ bool settingsShot = false; // autoplay "settingstest": save the screen now
for (;;) {
input::poll(pad);
// Autoplay runs unattended: the physical pad must not interfere
@@ -1080,6 +1133,23 @@ int main(int argc, char** argv) {
}
}
+ if (g_autoplaySettingsTest && uiSaved) {
+ // Settings, down to the resolution, open its list; saved 2 s later.
+ static uint64_t since = 0;
+ static int step = 0;
+ if (!since) since = now;
+ const uint64_t at[] = {500, 1500, 2500, 4500};
+ if (step < 4 && now - since >= at[step]) {
+ if (step == 0) nav.options = true;
+ if (step == 1) nav.down = true;
+ if (step == 2) nav.accept = true;
+ if (step == 3) {
+ settingsShot = true; // saved below, once drawn
+ g_autoplaySettingsTest = false;
+ }
+ ++step;
+ }
+ }
if (g_ui->screen() == ui::Screen::Streaming) {
std::lock_guard<std::mutex> lock(g_playerMutex);
if (g_player != overlayPlayer || (g_player && g_player->reconnects() != playerReconnects)) {
@@ -1109,7 +1179,12 @@ int main(int argc, char** argv) {
if (!wasOpen && (menuCombo || swipeMenu) && g_keyboardFor.empty()) {
swipeMenu = false;
menu.setCircleConfirms(g_settings.circleConfirms);
- menu.open(streamResolution, showStats, sharpness, deband, upscaler, g_playingHome);
+ bool allow1440;
+ {
+ std::lock_guard<std::mutex> settingsLock(g_settingsMutex);
+ allow1440 = allow1440Locked();
+ }
+ menu.open(streamResolution, showStats, sharpness, deband, upscaler, g_playingHome, allow1440);
overlaySeq = 0;
} else if (wasOpen) {
switch (menu.handle(nav)) {
@@ -1123,9 +1198,11 @@ int main(int argc, char** argv) {
case ui::MenuAction::Close: g_player->requestKeyframe(); break; // a clean picture back in the game
case ui::MenuAction::Resolution:
streamResolution = menu.resolution();
- g_player->requestResolution(streamResolution == 1 ? "720HQ"
- : streamResolution == 2 ? "1440"
- : "1080HQ");
+ g_tierPicked = true;
+ // The user's own Xbox: 1080p is its top tier ("1440").
+ g_player->requestResolution(streamResolution == 1 ? "720HQ"
+ : streamResolution == 2 || g_playingHome ? "1440"
+ : "1080HQ");
break;
case ui::MenuAction::Sharpness: {
sharpness = menu.sharpness();
@@ -1404,6 +1481,11 @@ int main(int argc, char** argv) {
XC_LOGI("AUTOPLAY END: detail test");
}
}
+ if (settingsShot) {
+ settingsShot = false;
+ saveCanvas("settings.ppm");
+ XC_LOGI("AUTOPLAY END: settings test");
+ }
if (g_autoplayConsolesTab && uiSaved) {
static uint64_t shownAt = 0;
if (!shownAt) {
diff --git a/src/app/settings.cpp b/src/app/settings.cpp
index d3eb87f..7c52069 100644
--- a/src/app/settings.cpp
+++ b/src/app/settings.cpp
@@ -31,6 +31,10 @@ bool Settings::load(const std::string& path) {
circleConfirms = (*j)["circleConfirms"].asBool(circleConfirms);
lightBar = (*j)["lightBar"].asBool(lightBar);
gestureHints = static_cast<int>((*j)["gestureHints"].asInt(gestureHints));
+ maxHeightCloud = static_cast<int>((*j)["maxHeightCloud"].asInt(0));
+ maxHeightHome = static_cast<int>((*j)["maxHeightHome"].asInt(0));
+ probedCloud = (*j)["probedCloud"].asInt(0);
+ probedHome = (*j)["probedHome"].asInt(0);
regionRtt.clear();
for (const auto& [name, ms] : (*j)["regionRtt"].members())
if (ms.asInt() > 0) regionRtt[name] = static_cast<int>(ms.asInt());
@@ -58,6 +62,10 @@ bool Settings::save(const std::string& path) const {
v.set("circleConfirms", circleConfirms);
v.set("lightBar", lightBar);
v.set("gestureHints", gestureHints);
+ v.set("maxHeightCloud", maxHeightCloud);
+ v.set("maxHeightHome", maxHeightHome);
+ v.set("probedCloud", probedCloud);
+ v.set("probedHome", probedHome);
return platform::writeFileAtomic(path, v.dump());
}
diff --git a/src/app/settings.h b/src/app/settings.h
index 9abf084..d4384a2 100644
--- a/src/app/settings.h
+++ b/src/app/settings.h
@@ -34,7 +34,11 @@ struct Settings {
bool circleConfirms = false;
// The DualSense light bar takes the colour of the game in focus.
bool lightBar = true;
- int gestureHints = 0; // streams that showed the touchpad gestures' hint (three do)
+ int gestureHints = 0;
+ // The tallest picture each kind of stream delivered when asked for its
+ // top tier, and when (unix s): 1440p is only offered once one did.
+ int maxHeightCloud = 0, maxHeightHome = 0;
+ int64_t probedCloud = 0, probedHome = 0; // streams that showed the touchpad gestures' hint (three do)
bool load(const std::string& path);
bool save(const std::string& path) const;
diff --git a/src/ui/app_ui.cpp b/src/ui/app_ui.cpp
index 634d3e1..3afe928 100644
--- a/src/ui/app_ui.cpp
+++ b/src/ui/app_ui.cpp
@@ -330,6 +330,12 @@ void AppUi::rebuild(bool keepPosition) {
dirty_ = true;
}
+void AppUi::setAllow1440(bool on) {
+ std::lock_guard<std::mutex> lock(mutex_);
+ allow1440_ = on;
+ dirty_ = true;
+}
+
void AppUi::setConsoles(std::vector<ConsoleTile> consoles, bool known) {
std::lock_guard<std::mutex> lock(mutex_);
consoles_ = std::move(consoles);
@@ -736,7 +742,8 @@ std::vector<std::string> AppUi::settingOptions(int row) const {
if (row == 0) {
for (int i = 0; i < static_cast<int>(Language::Count); ++i) out.push_back(languageName(static_cast<Language>(i)));
} else if (row == 1) {
- out = {tr(Str::Res720), tr(Str::Res1080), tr(Str::Res1440)}; // kResolutionOrder
+ out = {tr(Str::Res720), tr(Str::Res1080)}; // kResolutionOrder
+ if (allow1440_) out.push_back(tr(Str::Res1440));
} else if (row == 3) {
for (int p : kDeadzonePercent) out.push_back(std::to_string(p) + " %");
} else if (row == 4) {
@@ -757,9 +764,11 @@ std::vector<std::string> AppUi::settingOptions(int row) const {
int AppUi::settingSelected(int row) const {
// Caller holds mutex_.
if (row == 0) return settings_.language;
- if (row == 1)
+ if (row == 1) {
+ if (settings_.resolution == 2 && !allow1440_) return 1; // 1440p saved, not offered: 1080p
for (int i = 0; i < 3; ++i)
if (kResolutionOrder[i] == settings_.resolution) return i;
+ }
if (row == 3) return settings_.deadzone;
if (row == 4) return settings_.triggerRumble ? 0 : 1;
if (row == 5) return settings_.circleConfirms ? 1 : 0;
diff --git a/src/ui/app_ui.h b/src/ui/app_ui.h
index 837d4bc..7766985 100644
--- a/src/ui/app_ui.h
+++ b/src/ui/app_ui.h
@@ -163,6 +163,8 @@ public:
// on the phone meanwhile): Cross plays it again, Circle opens its page.
void showPlayError(const std::string& message, const GameTile& game);
void setSettings(const SettingsChoice& choice);
+ // Whether 1440p is offered (a stream delivered it); false hides it.
+ void setAllow1440(bool on);
// The confirm button in force (the hints show it); Settings may be
// showing another choice not saved yet.
void setCircleConfirms(bool on);
@@ -269,6 +271,7 @@ private:
Anim rowY_;
Tab tab_ = Tab::GamePass;
std::vector<ConsoleTile> consoles_;
+ bool allow1440_ = false;
bool consolesKnown_ = false;
int consoleFocus_ = 0;
std::vector<GameTile> owned_, purchasable_, hiddenTiles_; // as shown
diff --git a/src/ui/stream_menu.cpp b/src/ui/stream_menu.cpp
index 47285c7..de47a26 100644
--- a/src/ui/stream_menu.cpp
+++ b/src/ui/stream_menu.cpp
@@ -29,9 +29,12 @@ std::string fmt(const char* f, double v) {
} // namespace
-void StreamMenu::open(int resolution, bool stats, int sharpness, int deband, int upscaler, bool homeConsole) {
+void StreamMenu::open(int resolution, bool stats, int sharpness, int deband, int upscaler, bool homeConsole,
+ bool allow1440) {
open_ = true;
homeConsole_ = homeConsole;
+ allow1440_ = allow1440;
+ if (resolution == 2 && !allow1440) resolution = 0;
stats_ = stats;
sharpness_ = sharpness;
deband_ = deband;
@@ -51,9 +54,10 @@ MenuAction StreamMenu::handle(const NavInput& in) {
if (in.down) selected_ = (selected_ + 1) % ItemCount;
if (selected_ == Resolution && (in.left || in.right)) {
int pos = 0;
- for (int i = 0; i < 3; ++i)
+ int n = allow1440_ ? 3 : 2; // 720p, 1080p (, 1440p)
+ for (int i = 0; i < n; ++i)
if (kResolutionOrder[i] == resolution_) pos = i;
- pos = in.left ? (pos + 2) % 3 : (pos + 1) % 3;
+ pos = in.left ? (pos + n - 1) % n : (pos + 1) % n;
resolution_ = kResolutionOrder[pos];
}
if ((selected_ == Sharpness && (in.left || in.right)) || (selected_ == Sharpness && in.accept)) {
diff --git a/src/ui/stream_menu.h b/src/ui/stream_menu.h
index 7876e6a..72432f5 100644
--- a/src/ui/stream_menu.h
+++ b/src/ui/stream_menu.h
@@ -39,7 +39,9 @@ public:
// low, high.
// `upscaler` 0 = FSR, 1 = Anime4K.
// `homeConsole`: the user's own Xbox ("End the stream" instead of "Leave the game").
- void open(int resolution, bool stats, int sharpness = 0, int deband = 1, int upscaler = 0, bool homeConsole = false);
+ // `allow1440`: offered only once a stream delivered it.
+ void open(int resolution, bool stats, int sharpness = 0, int deband = 1, int upscaler = 0, bool homeConsole = false,
+ bool allow1440 = true);
void close() { open_ = false; }
bool isOpen() const { return open_; }
MenuAction handle(const NavInput& in);
@@ -66,7 +68,7 @@ private:
int sharpness_ = 0, deband_ = 1, upscaler_ = 0;
bool resolutionAsked_ = false;
bool circleConfirms_ = false;
- bool homeConsole_ = false;
+ bool homeConsole_ = false, allow1440_ = true;
PadSlots pads_{};
};
diff --git a/tests/test_main.cpp b/tests/test_main.cpp
index 7b841a7..505408e 100644
--- a/tests/test_main.cpp
+++ b/tests/test_main.cpp
@@ -248,6 +248,14 @@ static void testStreamMenu() {
CHECK(!menu.isOpen());
menu.open(1, true);
CHECK(press([](xc::ui::NavInput& n) { n.back = true; }) == MenuAction::Close);
+ // 1440p not offered: a saved 1440p shows as 1080p, and the row cycles 720p / 1080p.
+ menu.open(2, false, 0, 1, 0, false, false);
+ CHECK(menu.resolution() == 0);
+ for (int i = 0; i < 5; ++i) press([](xc::ui::NavInput& n) { n.down = true; }); // to the resolution
+ press([](xc::ui::NavInput& n) { n.right = true; });
+ CHECK(menu.resolution() == 1); // 1080p -> wraps to 720p
+ press([](xc::ui::NavInput& n) { n.right = true; });
+ CHECK(menu.resolution() == 0); // back to 1080p, never 1440p
}
int main() {
diff --git a/tools/ps5/autotest.sh b/tools/ps5/autotest.sh
index 0d781c3..292abf8 100755
--- a/tools/ps5/autotest.sh
+++ b/tools/ps5/autotest.sh
@@ -37,7 +37,7 @@ import io, sys
from ftplib import FTP, error_perm, error_reply
host, port, d, line = sys.argv[1], int(sys.argv[2]), sys.argv[3], sys.argv[4]
f = FTP(); f.connect(host, port, timeout=15); f.login(); f.cwd(d)
-for name in ("xcloud.log", "frame.ppm", "frame2.ppm", "stream.aus", "ui.ppm", "launch.ppm", "screen.ppm", "detail.ppm", "library.ppm", "library2.ppm", "error.ppm", "consoles.ppm"):
+for name in ("xcloud.log", "frame.ppm", "frame2.ppm", "stream.aus", "ui.ppm", "launch.ppm", "screen.ppm", "detail.ppm", "library.ppm", "library2.ppm", "error.ppm", "consoles.ppm", "settings.ppm"):
try: f.sendcmd(f"DELE {name}")
except (error_perm, error_reply): pass
f.storbinary("STOR autoplay.txt", io.BytesIO(line.encode() + b"\n"))
@@ -82,7 +82,7 @@ PY
if [[ $status != *"$title_id"* ]]; then result=crashed; break; fi
fi
done
-fetch xcloud.log frame.ppm frame2.ppm stream.aus ui.ppm launch.ppm screen.ppm detail.ppm library.ppm library2.ppm error.ppm consoles.ppm || true
+fetch xcloud.log frame.ppm frame2.ppm stream.aus ui.ppm launch.ppm screen.ppm detail.ppm library.ppm library2.ppm error.ppm consoles.ppm settings.ppm || true
ctl kill "$title_id" >/dev/null 2>&1 || true
# Remove the request so a manual launch behaves normally.
python3 - "$PS5_HOST" "${FTP_PORT:-2121}" "/data/homebrew/$title_id" <<'PY'