Xbox Cloud Gaming app for PS5 Homebrew
C
1440p request as the xbox.com client makes it
Rafael Abud Ferreirae02cf61f39d4
diff --git a/src/stream/stream_session.cpp b/src/stream/stream_session.cppindex 1d59cf4..d0a23a9 100644--- a/src/stream/stream_session.cpp+++ b/src/stream/stream_session.cpp@@ -55,28 +55,6 @@ std::vector<std::string> midsInOrder(const std::string& sdp) {return mids;}-// a=imageattr after every a=fmtp line: the largest picture we accept. The-// xbox.com client adds "recv [x=[0:1920],y=[0:1080],fps=[0:60]]" to limit-// devices that can't do 1440p; announcing 2560x1440 is what allows 1440p.-std::string advertiseReceiveSize(const std::string& sdp, int w, int h) {- if (sdp.find("a=imageattr") != std::string::npos) return sdp;- std::string out;- size_t pos = 0;- while (pos < sdp.size()) {- size_t eol = sdp.find('\n', pos);- if (eol == std::string::npos) eol = sdp.size() - 1;- std::string line = sdp.substr(pos, eol - pos + 1);- out += line;- if (line.rfind("a=fmtp:", 0) == 0 && line.find("profile-level-id") != std::string::npos) {- std::string pt = line.substr(7, line.find(' ') - 7);- out += "a=imageattr:" + pt + " recv [x=[0:" + std::to_string(w) + "],y=[0:" + std::to_string(h) +- "],fps=[0:60]]\r\n";- }- pos = eol + 1;- }- return out;-}-void initRtcLogging() {static std::once_flag once;std::call_once(once, [] {@@ -122,6 +100,7 @@ struct StreamSession::Impl {std::string failReason;std::atomic<bool> open{false};+ std::atomic<bool> resolutionPending{false}; // 1440: asked at the first video framestd::atomic<bool> closedNotified{false};std::atomic<uint32_t> inputSequence{1};uint64_t lastKeepaliveMs = 0;@@ -209,7 +188,8 @@ struct StreamSession::Impl {// they're enabled; elsewhere the service ignores them and keeps what// it had (1080 at the start). The plain tier first, then: measured,// "720" switches in a few seconds, "720HQ" is ignored in Brazil.- std::string base = alias == "1440" ? "1080" : alias;+ // 1440 alone, as the xbox.com client sends it (never 1080 before it).+ std::string base = alias;if (base.size() > 2 && base.compare(base.size() - 2, 2, "HQ") == 0) base.resize(base.size() - 2);// The user's own Xbox offers every tier on any plan: just the one asked for.if (gssv.isHome()) base = alias;@@ -284,7 +264,12 @@ struct StreamSession::Impl {sendGamepadChanged(0, true);sendGamepadChanged(0, false);sendGamepadChanged(0, true);- if (!opt.resolutionAlias.empty()) sendResolution(opt.resolutionAlias);+ // 1440 once the picture is running (the first video frame), as the+ // xbox.com client sends it; the other tiers right away.+ if (opt.resolutionAlias == "1440" && !gssv.isHome())+ resolutionPending = true;+ else if (!opt.resolutionAlias.empty())+ sendResolution(opt.resolutionAlias);// One touch point, as the web client announces (touch is then turned@@ -487,6 +472,7 @@ struct StreamSession::Impl {videoReceiver->addToChain(videoReporter);video->setMediaHandler(videoReceiver);video->onFrame([this](rtc::binary data, rtc::FrameInfo info) {+ if (resolutionPending.exchange(false)) sendResolution(opt.resolutionAlias);if (cb.video) cb.video(reinterpret_cast<const uint8_t*>(data.data()), data.size(), info.timestamp);});}@@ -519,7 +505,8 @@ struct StreamSession::Impl {return false;}std::string offer = std::string(*local);- if (opt.resolutionAlias == "1440") offer = advertiseReceiveSize(offer, 2560, 1440);+ // No a=imageattr: the xbox.com client adds one only to *limit* a+ // device to 1080p; a 1440p-capable one sends the plain offer.XC_LOGD("local offer:\n%s", offer.c_str());if (!gssv.sendSdpOffer(offer, err)) return false;diff --git a/src/xcloud/gssv.cpp b/src/xcloud/gssv.cppindex 00db2dc..288d3e9 100644--- a/src/xcloud/gssv.cpp+++ b/src/xcloud/gssv.cpp@@ -64,10 +64,19 @@ const std::string& deviceInfo(Resolution res) {json::Value env = json::Value::object();env.set("clientAppId", "www.xbox.com");env.set("clientAppType", "browser");- env.set("clientAppVersion", "1.0.2609.0802");- env.set("clientSdkVersion", "10.6.62");+ env.set("clientAppVersion", "1.0.2610.0201");+ env.set("clientSdkVersion", "10.6.65");env.set("httpEnvironment", "prod");- env.set("sdkInstallId", "");+ env.set("sdkInstallId", [] { // filled in by the web client; random, per run (nothing of the console)+ uint8_t b[16];+ platform::randomBytes(b, sizeof b);+ b[6] = static_cast<uint8_t>((b[6] & 0x0f) | 0x40);+ b[8] = static_cast<uint8_t>((b[8] & 0x3f) | 0x80);+ char id[37];+ std::snprintf(id, sizeof id, "%02x%02x%02x%02x-%02x%02x-%02x%02x-%02x%02x-%02x%02x%02x%02x%02x%02x", b[0], b[1],+ b[2], b[3], b[4], b[5], b[6], b[7], b[8], b[9], b[10], b[11], b[12], b[13], b[14], b[15]);+ return std::string(id);+ }());json::Value app = json::Value::object();app.set("env", env);json::Value dims = json::Value::object();@@ -426,6 +435,7 @@ bool GssvClient::startSession(const std::string& titleId, const std::string& locjson::Value settings = json::Value::object();settings.set("nanoVersion", "V3;WebrtcTransport.dll");settings.set("enableTextToSpeech", false);+ settings.set("magnifier", false);settings.set("highContrast", 0);settings.set("locale", locale);settings.set("useIceConnection", false);@@ -434,10 +444,20 @@ bool GssvClient::startSession(const std::string& titleId, const std::string& locsettings.set("osName", resolution_ == Resolution::P720 ? "android": resolution_ == Resolution::P1080HQ ? "tizen": "windows");+ settings.set("enableOptionalDataCollection", false);json::Value body = json::Value::object();bool home = offering_ == "xhome";- body.set("clientSessionId", "");+ body.set("clientSessionId", [] { // a new id per session, as the web client sends+ uint8_t b[16];+ platform::randomBytes(b, sizeof b);+ b[6] = static_cast<uint8_t>((b[6] & 0x0f) | 0x40);+ b[8] = static_cast<uint8_t>((b[8] & 0x3f) | 0x80);+ char id[37];+ std::snprintf(id, sizeof id, "%02x%02x%02x%02x-%02x%02x-%02x%02x-%02x%02x-%02x%02x%02x%02x%02x%02x", b[0], b[1], b[2],+ b[3], b[4], b[5], b[6], b[7], b[8], b[9], b[10], b[11], b[12], b[13], b[14], b[15]);+ return std::string(id);+ }());body.set("titleId", home ? "" : titleId);body.set("systemUpdateGroup", "");body.set("settings", settings);