Xbox Cloud Gaming app for PS5 Homebrew
C
The pictures' quantiser (QP) in the statistics line and the log
Rafael Abud Ferreiraa16de467fa1d
diff --git a/ROADMAP.md b/ROADMAP.mdindex dcff0db..fa14abb 100644--- a/ROADMAP.md+++ b/ROADMAP.md@@ -225,7 +225,16 @@ is rolled back at the next start), then the app restarts itself(measured, see the v0.4.0 / v0.5.0 PRs). Re-tested 2026-10-15 with therequest exactly as xbox.com makes it: still 1920x1080 (H.264 4.2) at~11–13 Mbps in motion, the same with Tizen's 1080HQ. "Best" keeps asking- for 1440p for when Microsoft grants it.+ for 1440p for when Microsoft grants it. Measured by the pictures' QP+ (2026-10-15, FH5 / Starfield / Cyberpunk, Brazil and Australia regions): the+ service caps cloud 1080p at ~12–13 Mbps (QP ~24–27, up to ~33 in the+ heaviest motion). Tried, no gain: H.264 High (the session's+ `clientStreamingConfigOverrides` says `preferMainH264Profile`),+ transport-cc with real feedback (accepted, same bitrate), `b=AS` and+ `x-google-*-bitrate`, 4K-browser / Mac-Chrome (XboxTV's, which got 1440p in+ Australia) / Xbox-console identities (the console one got 720p),+ `VideoPreference` + `a=max-fr`, 1440 asked at once; the 5 s key frames cost+ ~2 % of the bits. 1440p seems to depend on the account / market.- **HDR**: xCloud doesn't stream HDR.- **1440p only for Ultimate**: not limited in the app; "Best" asks for themost and the service gives what the plan allows.diff --git a/src/app/cli_main.cpp b/src/app/cli_main.cppindex 33c1898..62556fa 100644--- a/src/app/cli_main.cpp+++ b/src/app/cli_main.cpp@@ -877,6 +877,7 @@ int main(int argc, char** argv) {info.onScreenMs = 23.2;info.width = 1920;info.height = 1080;+ info.qp = 26;auto save = [&](const std::string& name, const ui::Canvas& over, int ox, int oy, int alpha) {ui::Canvas frame(1920, 1080);frame.gradientH({0, 0, 1920, 1080}, ui::rgba(40, 90, 160), ui::rgba(200, 120, 40));diff --git a/src/app/stream_player.cpp b/src/app/stream_player.cppindex 12abbeb..89ca3f4 100644--- a/src/app/stream_player.cpp+++ b/src/app/stream_player.cpp@@ -82,6 +82,7 @@ struct StreamPlayer::Impl {std::atomic<uint64_t> triggerVibrations{0};std::atomic<uint64_t> displayUs{0}, displayCount{0}, displayMaxUs{0};std::atomic<uint64_t> decodeUs{0}, decodeCalls{0}, decodeMaxUs{0}, drawUs{0}, drawCalls{0}, drawMaxUs{0};+ std::atomic<uint64_t> qpSumX100{0}, qpCount{0}; // pictures' quantiser since the last stats()int decodeThreads = 1;int simulatedLoss = 0;int maxBitrateMbps = 0;@@ -284,6 +285,10 @@ struct StreamPlayer::Impl {continue;}++decodedFrames;+ if (decoder.lastQp() >= 0) {+ qpSumX100 += static_cast<uint64_t>(decoder.lastQp() * 100);+ ++qpCount;+ }pictureSize = (static_cast<uint32_t>(pic.width) << 16) | static_cast<uint32_t>(pic.height);bool screenshot = saveSnapshotIfAsked(pic);// A newer frame already waits: decode this one (the next needs it)@@ -777,6 +782,8 @@ StreamPlayer::Stats StreamPlayer::stats() const {uint64_t rc = impl_->drawCalls.exchange(0), ru = impl_->drawUs.exchange(0);st.decodeAvgUs = dc ? du / dc : 0;st.decodeMaxUs = impl_->decodeMaxUs.exchange(0);+ uint64_t qn = impl_->qpCount.exchange(0), qs = impl_->qpSumX100.exchange(0);+ st.qpAvg = qn ? qs / 100.0 / static_cast<double>(qn) : -1;st.drawAvgUs = rc ? ru / rc : 0;st.drawMaxUs = impl_->drawMaxUs.exchange(0);uint64_t dn = impl_->displayCount.exchange(0), du2 = impl_->displayUs.exchange(0);diff --git a/src/app/stream_player.h b/src/app/stream_player.hindex 259e05a..4aef47a 100644--- a/src/app/stream_player.h+++ b/src/app/stream_player.h@@ -82,6 +82,8 @@ public:uint64_t decodeAvgUs = 0, decodeMaxUs = 0, drawAvgUs = 0, drawMaxUs = 0;// Network arrival to on the screen (GPU path), since the last call.uint64_t displayAvgUs = 0, displayMaxUs = 0;+ // The pictures' average quantiser since the last call (lower: finer); -1 none.+ double qpAvg = -1;};Stats stats() const;// Before start(): H.264 decoder threads (more than 1 = frame threading).diff --git a/src/app/worker.cpp b/src/app/worker.cppindex 1103412..f7941d5 100644--- a/src/app/worker.cpp+++ b/src/app/worker.cpp@@ -65,7 +65,7 @@ std::string stream(xcloud::GssvClient& gssv) {crash::setStage(gssv.isHome() ? "streaming own Xbox" : ("streaming " + g_stageTitle).c_str());g_gameClosedOnServer = false;app::StreamPlayer player(gssv);- if (g_autoplay.dump) player.dumpVideo(platform::dataDir() + "/stream.aus", 20);+ if (g_autoplay.dump) player.dumpVideo(platform::dataDir() + "/stream.aus", g_autoplay.seconds + 15);player.setDecodeThreads(g_autoplay.decodeThreads);player.setSimulatedLoss(g_autoplay.videoLoss);player.setHwDecodeProbe(g_autoplay.hwDecode);@@ -155,7 +155,7 @@ std::string stream(xcloud::GssvClient& gssv) {XC_LOGI("stream: %llu frames, %llu decoded, %llu skipped, %llu failed, %llu resets, %llu kf req, ""%llu queued, %llu audio; rtp %llu pkts, %llu lost, %llu recovered, %llu nacks, ""%llu frames dropped; %llu kbps (remb %llu); %llu rumble; decode %.1f/%.1f ms, draw %.1f/%.1f ms, %llu late; "- "rtt %d ms; %dx%d; on screen %.1f/%.1f ms after arrival",+ "rtt %d ms; %dx%d; on screen %.1f/%.1f ms after arrival; qp %.1f",static_cast<unsigned long long>(st.videoFrames), static_cast<unsigned long long>(st.decodedFrames),static_cast<unsigned long long>(st.droppedFrames), static_cast<unsigned long long>(st.decodeFailures),static_cast<unsigned long long>(st.queueResets), static_cast<unsigned long long>(st.keyframeRequests),@@ -166,7 +166,7 @@ std::string stream(xcloud::GssvClient& gssv) {static_cast<unsigned long long>(st.rembKbps), static_cast<unsigned long long>(st.vibrations),st.decodeAvgUs / 1000.0, st.decodeMaxUs / 1000.0, st.drawAvgUs / 1000.0, st.drawMaxUs / 1000.0,static_cast<unsigned long long>(st.lateFrames), st.rttMs, st.width, st.height,- st.displayAvgUs / 1000.0, st.displayMaxUs / 1000.0);+ st.displayAvgUs / 1000.0, st.displayMaxUs / 1000.0, st.qpAvg);if (st.rttMs > 0 && (bestRtt < 0 || st.rttMs < bestRtt)) bestRtt = st.rttMs;tallest = std::max(tallest, st.height);if (!probeDone && platform::nowMs() - started >= 20000) {@@ -185,6 +185,7 @@ std::string stream(xcloud::GssvClient& gssv) {info.onScreenMs = st.displayAvgUs / 1000.0;info.width = st.width;info.height = st.height;+ info.qp = st.qpAvg;if (last.decodedFrames > 0) { // once the picture is runninguint64_t dropped = st.rtpDroppedFrames - last.rtpDroppedFrames;uint64_t now = platform::nowMs();diff --git a/src/media/decoder.cpp b/src/media/decoder.cppindex e4d3f8d..ca34518 100644--- a/src/media/decoder.cpp+++ b/src/media/decoder.cpp@@ -10,6 +10,7 @@ extern "C" {#include <libavutil/cpu.h>#include <libavutil/log.h>#include <libavutil/error.h>+#include <libavutil/video_enc_params.h>}#include <algorithm>@@ -115,6 +116,8 @@ bool VideoDecoder::init(int threads) {ctx_->thread_type = FF_THREAD_SLICE;}XC_LOGI("h264 decoder: cpu flags 0x%x, %d thread(s)", av_get_cpu_flags(), ctx_->thread_count);+ // The quantiser of each picture, for the quality measure (lastQp()).+ ctx_->export_side_data |= AV_CODEC_EXPORT_DATA_VIDEO_ENC_PARAMS;int rc = avcodec_open2(ctx_, codec, nullptr);if (rc < 0) {XC_LOGE("avcodec_open2(h264): %s", averr(rc).c_str());@@ -165,6 +168,12 @@ bool VideoDecoder::decode(const uint8_t* data, size_t len, Picture& out, uint32_if (failuresLogged_++ < 20) XC_LOGI("h264 packet dropped: %s (%zu bytes)", averr(again).c_str(), len);}}+ if (AVFrameSideData* sd = av_frame_get_side_data(frame_, AV_FRAME_DATA_VIDEO_ENC_PARAMS)) {+ auto* par = reinterpret_cast<AVVideoEncParams*>(sd->data);+ double sum = 0;+ for (unsigned i = 0; i < par->nb_blocks; ++i) sum += par->qp + av_video_enc_params_block(par, i)->delta_qp;+ lastQp_ = par->nb_blocks ? sum / par->nb_blocks : par->qp;+ }if (frame_->decode_error_flags || (frame_->flags & AV_FRAME_FLAG_CORRUPT)) {needsKeyframe_ = true;} else if (frame_->flags & AV_FRAME_FLAG_KEY) {diff --git a/src/media/decoder.h b/src/media/decoder.hindex 507ca6b..8f69303 100644--- a/src/media/decoder.h+++ b/src/media/decoder.h@@ -53,6 +53,9 @@ public:// The last decode() returned no picture without an error: the decoder// wants more input (frame threads still busy, or no reference yet).bool pending() const { return pending_; }+ // The quantiser of the last picture (its macroblocks' average, as the+ // encoder set it): lower is finer. -1 before any.+ double lastQp() const { return lastQp_; }private:AVCodecContext* ctx_ = nullptr;@@ -62,6 +65,7 @@ private:bool profileLogged_ = false;bool pending_ = false;int failuresLogged_ = 0;+ double lastQp_ = -1;};class AudioDecoder {diff --git a/src/ui/stream_menu.cpp b/src/ui/stream_menu.cppindex dd4fa25..5ba4f91 100644--- a/src/ui/stream_menu.cpp+++ b/src/ui/stream_menu.cpp@@ -344,6 +344,7 @@ Canvas StreamMenu::renderStats(const StreamInfo& info) const {text += fmt("%.0f fps", info.fps) + " " + fmt("%.1f Mbps", info.mbps);if (info.rttMs > 0) text += " " + std::to_string(info.rttMs) + " ms";text += " " + fmt("%.1f%%", info.lossPct);+ if (info.qp >= 0) text += " QP " + fmt("%.0f", info.qp); // the encoder's quantiser: lower is finerif (!micMuted_) text += " MIC";constexpr int kPx = 20, kH = 36;std::string warn = info.degraded ? std::string(" ") + tr(Str::ConnectionUnstable) : std::string();diff --git a/src/ui/stream_menu.h b/src/ui/stream_menu.hindex 19529eb..75980aa 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+ double qp = -1; // the pictures' average quantiser (lower: finer); -1 unknownbool degraded = false; // frames lost / video stalled / round trip far up, in the last seconds};