Xbox Cloud Gaming app for PS5 Homebrew
C
fix(stream, gpu): enable triple buffering, fix keepalive thread lifecycle, refine tick dt
Rafael Abud Ferreira5588f164931e
diff --git a/src/app/worker.cpp b/src/app/worker.cppindex e96e5b9..8a1bd31 100644--- a/src/app/worker.cpp+++ b/src/app/worker.cpp@@ -216,7 +216,7 @@ std::string stream(xcloud::GssvClient& gssv) {degradedLogged = false;}info.degraded = now < degradedUntil;- lastTickAt = now;+ lastTickAt = tickNow;++session.seconds;session.kbps += st.rtpKbps;if (st.rttMs > 0) session.rttSum += static_cast<uint64_t>(st.rttMs), ++session.rttCount;diff --git a/src/display/gpu.cpp b/src/display/gpu.cppindex ba38ce2..2e9b839 100644--- a/src/display/gpu.cpp+++ b/src/display/gpu.cpp@@ -169,7 +169,7 @@ std::atomic<int> g_deband{1};std::atomic<int> g_upscaler{0}; // 0 FSR (EASU), 1 Anime4Kstd::atomic<bool> g_restore{false}; // Anime4K Restore before the upscaleuint32_t g_frame = 0;-uint32_t g_swapImages = 2;+uint32_t g_swapImages = 3;bool g_noPresentWait = true;PFN_vkWaitForPresentKHR vkWaitForPresentKHR = nullptr;// The last frame known on the screen: its present id and when (us).diff --git a/src/stream/stream_session.cpp b/src/stream/stream_session.cppindex eb51dc1..46ec80c 100644--- a/src/stream/stream_session.cpp+++ b/src/stream/stream_session.cpp@@ -106,6 +106,7 @@ struct StreamSession::Impl {std::atomic<uint32_t> inputSequence{1};uint64_t lastKeepaliveMs = 0;std::atomic<bool> keepaliveInFlight{false};+ std::thread keepaliveThread;uint64_t lastKeyframeMs = 0;VideoReceiveStats videoStats;std::shared_ptr<RtcpReporter> videoReporter;@@ -649,12 +650,15 @@ struct StreamSession::Impl {uint64_t now = platform::nowMs();if (now - lastKeepaliveMs >= 30000) {lastKeepaliveMs = now;+ if (keepaliveThread.joinable() && !keepaliveInFlight.load()) {+ keepaliveThread.join();+ }if (!keepaliveInFlight.exchange(true)) {- std::thread([this] {+ keepaliveThread = std::thread([this] {std::string err;if (!gssv.keepalive(err)) XC_LOGW("%s", err.c_str());keepaliveInFlight = false;- }).detach();+ });}}if (opt.keyframeIntervalSec > 0 && now - lastKeyframeMs >= static_cast<uint64_t>(opt.keyframeIntervalSec) * 1000u) {@@ -666,6 +670,9 @@ struct StreamSession::Impl {// Before the session goes: no callback of libdatachannel's (they hold// `this`) may run any more. Each reset waits for a call in progress.void detach() {+ if (keepaliveThread.joinable()) {+ keepaliveThread.join();+ }{std::lock_guard<std::mutex> lock(guard->mutex);guard->self = nullptr;@@ -694,6 +701,12 @@ struct StreamSession::Impl {}}}++ ~Impl() {+ if (keepaliveThread.joinable()) {+ keepaliveThread.join();+ }+ }};StreamSession::StreamSession(xcloud::GssvClient& gssv, StreamCallbacks callbacks, StreamOptions options)diff --git a/tools/ps5/log_stream.py b/tools/ps5/log_stream.pyindex 1a95f9c..5546330 100755--- a/tools/ps5/log_stream.py+++ b/tools/ps5/log_stream.py@@ -102,7 +102,11 @@ def stream_logs(use_color: bool = True,poll_interval: float = 0.5,):- filter_re = re.compile(filter_pattern, re.IGNORECASE) if filter_pattern else None+ try:+ filter_re = re.compile(filter_pattern, re.IGNORECASE) if filter_pattern else None+ except re.error as e:+ print(f"{B_RED}Invalid filter regex pattern '{filter_pattern}': {e}{RESET}", file=sys.stderr)+ return 1try:ftp = connect_ftp(host, port)