Skip to content

Xbox Cloud Gaming app for PS5 Homebrew

C

feat(stream): modular stats indicator selection and jitter-free frametime HUD

Rafael Abud Ferreira17b509cadb69
diff --git a/src/app/settings.cpp b/src/app/settings.cpp
index 95e4f7d..8a80ce9 100644
--- a/src/app/settings.cpp
+++ b/src/app/settings.cpp
@@ -61,6 +61,7 @@ bool Settings::load(const std::string& path) {
if (!id.str().empty()) favorites.push_back(id.str());
librarySort = (*j)["librarySort"].str(librarySort);
streamStats = (*j)["streamStats"].asBool(streamStats);
+ statsMask = static_cast<uint32_t>((*j)["statsMask"].asInt(static_cast<int64_t>(statsMask)));
sharpness = static_cast<int>(std::clamp<int64_t>((*j)["sharpness"].asInt(sharpness), 0, 3));
deband = static_cast<int>(std::clamp<int64_t>((*j)["deband"].asInt(deband), 0, 3));
upscaler = static_cast<int>(std::clamp<int64_t>((*j)["upscaler"].asInt(upscaler), 0, 3));
@@ -209,6 +210,7 @@ bool Settings::save(const std::string& path) const {
v.set("favorites", favIds);
v.set("librarySort", librarySort);
v.set("streamStats", streamStats);
+ v.set("statsMask", static_cast<int64_t>(statsMask));
v.set("sharpness", sharpness);
v.set("deband", deband);
v.set("upscaler", upscaler);
diff --git a/src/app/settings.h b/src/app/settings.h
index f1dde1a..ca8f729 100644
--- a/src/app/settings.h
+++ b/src/app/settings.h
@@ -62,6 +62,7 @@ struct Settings {
std::string librarySort = "recent";
// The statistics line over the game (in-game menu).
bool streamStats = false;
+ uint32_t statsMask = 0x1F; // StatsDefaultMask (Fps, Bitrate, Latency, Loss, Graph)
// Sharpening of the game picture: 0 off, 1..3 low, medium (FSR RCAS), high.
int sharpness = 2;
// Smoothing of compression blocks (GPU display): 0 off, 1 low, 2 high,
diff --git a/src/app/stream_player.cpp b/src/app/stream_player.cpp
index 3936ec6..fb3211b 100644
--- a/src/app/stream_player.cpp
+++ b/src/app/stream_player.cpp
@@ -108,6 +108,12 @@ struct StreamPlayer::Impl {
std::deque<stream::TextInputRequest> textRequests;
std::set<std::string> textWithdrawn;
+ mutable std::mutex frametimesMutex;
+ static constexpr size_t kFrametimeRing = 60;
+ std::array<float, kFrametimeRing> frametimesRing{};
+ size_t frametimesCount = 0;
+ size_t frametimesHead = 0;
+
media::AudioIn audioIn;
media::AudioEncoder audioEncoder;
std::atomic<bool> micEnabled{true};
@@ -201,8 +207,8 @@ struct StreamPlayer::Impl {
// Late or duplicate packet: skip to preserve timeline and prevent timestamp drift
continue;
}
- // Detect packet loss from RTP timestamp gap (conceal up to 5 lost frames)
- if (diff > static_cast<int32_t>(kOpusFrameSamples) && diff <= static_cast<int32_t>(kOpusFrameSamples * 6)) {
+ // Detect packet loss from RTP timestamp gap (conceal up to 10 lost frames = 200ms)
+ if (diff > static_cast<int32_t>(kOpusFrameSamples) && diff <= static_cast<int32_t>(kOpusFrameSamples * 10)) {
uint32_t lostCount = (static_cast<uint32_t>(diff) + kOpusFrameSamples / 2) / kOpusFrameSamples - 1;
for (uint32_t i = 0; i < lostCount; ++i) {
pcm.clear();
@@ -247,6 +253,7 @@ struct StreamPlayer::Impl {
constexpr uint64_t kShownRing = 8;
std::pair<uint64_t, uint64_t> inScreenQueue[kShownRing] = {}; // present id, arrival us
uint64_t lastShownId = 0;
+ uint64_t lastFramePresentUs = 0;
while (running) {
size_t backlog;
{
@@ -329,10 +336,9 @@ struct StreamPlayer::Impl {
// When a burst of packets arrives after network jitter/retransmission,
// fast-forward decode without drawing to drain the stale backlog in a few
// milliseconds and present the newest live frame immediately.
- // backlog is measured after popping the current frame: backlog >= 2 means
- // >= 3 frames buffered (>= 33ms stale). Fast-forwarding flushes the queue
- // without swapchain stall, keeping display latency around ~27ms.
- if (backlog >= 2 && skippedInRow < 5) {
+ // Only drain if backlog is critically high (>= 4 frames buffered, >= 60ms stale),
+ // and drop at most 1 frame per cycle to prevent multi-frame visual hitches.
+ if (backlog >= 4 && skippedInRow < 1) {
++skippedInRow;
++droppedFrames;
continue;
@@ -355,6 +361,16 @@ struct StreamPlayer::Impl {
}
display::present();
uint64_t t3 = platform::nowUs();
+ if (lastFramePresentUs > 0) {
+ float dt = static_cast<float>(t3 - lastFramePresentUs) / 1000.0f;
+ if (dt > 0.0f && dt < 250.0f) {
+ std::lock_guard<std::mutex> lk(frametimesMutex);
+ frametimesRing[frametimesHead % kFrametimeRing] = dt;
+ ++frametimesHead;
+ if (frametimesCount < kFrametimeRing) ++frametimesCount;
+ }
+ }
+ lastFramePresentUs = t3;
// Display latency: network arrival to the TV, once the GPU says
// the frame is on the screen (a frame or so later).
if (uint64_t id = display::lastPresentId()) {
@@ -879,4 +895,20 @@ float StreamPlayer::micLevel() const {
return impl_ ? impl_->audioIn.level() : 0.0f;
}
+void StreamPlayer::getRecentFrametimes(std::vector<float>& out) const {
+ if (!impl_) {
+ out.clear();
+ return;
+ }
+ std::lock_guard<std::mutex> lk(impl_->frametimesMutex);
+ out.clear();
+ out.reserve(impl_->frametimesCount);
+ size_t count = impl_->frametimesCount;
+ size_t head = impl_->frametimesHead;
+ size_t start = head >= count ? head - count : 0;
+ for (size_t i = 0; i < count; ++i) {
+ out.push_back(impl_->frametimesRing[(start + i) % Impl::kFrametimeRing]);
+ }
+}
+
} // namespace xc::app
diff --git a/src/app/stream_player.h b/src/app/stream_player.h
index 4aef47a..ccb0b0b 100644
--- a/src/app/stream_player.h
+++ b/src/app/stream_player.h
@@ -95,6 +95,8 @@ public:
// Before start(): also run every frame through the PS5's hardware
// decoder and log how it does (the picture still comes from FFmpeg).
void setHwDecodeProbe(bool on);
+ // Recent presentation frametimes (ms, up to 60 frames)
+ void getRecentFrametimes(std::vector<float>& out) const;
private:
struct Impl;
diff --git a/src/app/stream_screen.cpp b/src/app/stream_screen.cpp
index b1e3ce5..7e491c9 100644
--- a/src/app/stream_screen.cpp
+++ b/src/app/stream_screen.cpp
@@ -126,6 +126,7 @@ void StreamScreen::update(const input::ControllerState& pad, ui::NavInput nav, b
streamResolution_ = prof.resolution;
showStats_ = g_settings.streamStats;
+ menu_.setStatsMask(g_settings.statsMask);
sharpness_ = g_autoplay.sharpness >= 0 ? g_autoplay.sharpness : prof.sharpness;
display::setSharpness(kSharpAmount[std::clamp(sharpness_, 0, 3)]);
deband_ = g_autoplay.deband >= 0 ? g_autoplay.deband : prof.deband;
@@ -192,6 +193,7 @@ void StreamScreen::update(const input::ControllerState& pad, ui::NavInput nav, b
bool micMuted = g_player ? (g_player->micMuted() || g_player->isMicHardwareMuted()) : false;
menu_.setDebandInUse(autoDeband_.level());
menu_.setGyro(gyroMode_, gyroLevel_);
+ menu_.setStatsMask(g_settings.statsMask);
menu_.open(streamResolution_, showStats_, sharpness_, deband_, upscaler_, g_playingHome, allow1440,
hasCustomProfile_, triggerStrength_, deadzone_, circleConfirms_, micLvl, micMuted);
overlaySeq_ = 0;
@@ -367,6 +369,7 @@ void StreamScreen::update(const input::ControllerState& pad, ui::NavInput nav, b
showStats_ = menu_.statsOn();
std::lock_guard<std::mutex> settingsLock(g_settingsMutex);
g_settings.streamStats = showStats_;
+ g_settings.statsMask = menu_.statsMask();
g_settings.save(settingsPath());
break;
}
@@ -549,8 +552,7 @@ void StreamScreen::update(const input::ControllerState& pad, ui::NavInput nav, b
ui::Canvas c = ui::renderToastPanel(fonts_, shown);
display::setOverlay(c.data(), (static_cast<int>(display::kWidth) - c.width()) / 2, 28, c.width(), c.height(), 235);
} else if (showStats_ && seq) {
- if (info.onScreenMs > 0) menu_.recordFrametime(static_cast<float>(info.onScreenMs));
- else if (info.fps > 0) menu_.recordFrametime(static_cast<float>(1000.0 / info.fps));
+ if (!info.frametimes.empty()) menu_.setFrametimes(info.frametimes);
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) {
diff --git a/src/app/worker.cpp b/src/app/worker.cpp
index 9fbd67b..15c6a6c 100644
--- a/src/app/worker.cpp
+++ b/src/app/worker.cpp
@@ -248,6 +248,7 @@ std::string stream(xcloud::GssvClient& gssv) {
if (s_playtimeRemainingSeconds >= 0) {
info.playtimeHours = static_cast<int>((s_playtimeRemainingSeconds + 3599) / 3600);
}
+ player.getRecentFrametimes(info.frametimes);
std::lock_guard<std::mutex> lock(g_infoMutex);
g_streamInfo = info;
++g_infoSeq;
diff --git a/src/media/audio_queue.h b/src/media/audio_queue.h
index 70de2c8..89717f9 100644
--- a/src/media/audio_queue.h
+++ b/src/media/audio_queue.h
@@ -22,8 +22,8 @@ public:
static constexpr int kRate = 48000;
// Bounded to keep the sound close to the picture while absorbing normal
// network jitter (20-40 ms bursts, up to 150 ms NACK recovery). Stereo frames.
- static constexpr size_t kMaxQueued = kRate * 200 / 1000; // 200 ms
- static constexpr size_t kTrimTo = kRate * 100 / 1000; // 100 ms
+ static constexpr size_t kMaxQueued = kRate * 250 / 1000; // 250 ms
+ static constexpr size_t kTrimTo = kRate * 140 / 1000; // 140 ms
// Since the last log (reset by it).
struct Stats {
diff --git a/src/stream/h264_receiver.h b/src/stream/h264_receiver.h
index e00b2b1..bee875d 100644
--- a/src/stream/h264_receiver.h
+++ b/src/stream/h264_receiver.h
@@ -27,7 +27,7 @@ namespace xc::stream {
class H264Receiver final : public rtc::MediaHandler {
public:
// `onKeyframeNeeded` runs on libdatachannel's thread.
- H264Receiver(std::function<void()> onKeyframeNeeded, VideoReceiveStats& stats, uint64_t waitMs = 300);
+ H264Receiver(std::function<void()> onKeyframeNeeded, VideoReceiveStats& stats, uint64_t waitMs = 90);
void incoming(rtc::message_vector& messages, const rtc::message_callback& send) override;
diff --git a/src/ui/stream_menu.cpp b/src/ui/stream_menu.cpp
index 4a6372e..bfdfc5c 100644
--- a/src/ui/stream_menu.cpp
+++ b/src/ui/stream_menu.cpp
@@ -82,10 +82,35 @@ void StreamMenu::open(int resolution, bool stats, int sharpness, int deband, int
selected_ = XboxButton;
resolution_ = applied_ = resolution;
resolutionAsked_ = false;
+ statsCustomizing_ = false;
+ statsCustomIndex_ = 0;
}
MenuAction StreamMenu::handle(const NavInput& in) {
if (!open_) return MenuAction::None;
+ if (statsCustomizing_) {
+ if (in.back) {
+ statsCustomizing_ = false;
+ return MenuAction::Stats;
+ }
+ if (in.options) {
+ statsCustomizing_ = false;
+ open_ = false;
+ return MenuAction::Close;
+ }
+ constexpr int kCount = 8;
+ if (in.up) statsCustomIndex_ = (statsCustomIndex_ + kCount - 1) % kCount;
+ if (in.down) statsCustomIndex_ = (statsCustomIndex_ + 1) % kCount;
+ if (in.accept || in.left || in.right) {
+ static constexpr uint32_t kMasks[kCount] = {
+ StatsFps, StatsBitrate, StatsLatency, StatsLoss,
+ StatsGraph, StatsDelay, StatsQp, StatsMic
+ };
+ statsMask_ ^= kMasks[statsCustomIndex_];
+ return MenuAction::Stats;
+ }
+ return MenuAction::None;
+ }
if (in.back || in.options) {
open_ = false;
return MenuAction::Close;
@@ -150,10 +175,14 @@ MenuAction StreamMenu::handle(const NavInput& in) {
stats_ = !stats_;
return MenuAction::Stats;
}
+ if (selected_ == Stats && (in.square || in.accept)) {
+ statsCustomizing_ = true;
+ stats_ = true;
+ return MenuAction::Stats;
+ }
if (!in.accept) return MenuAction::None;
switch (selected_) {
case XboxButton: open_ = false; return MenuAction::XboxButton;
- case Stats: stats_ = !stats_; return MenuAction::Stats;
case Resolution:
applied_ = resolution_;
resolutionAsked_ = true;
@@ -168,6 +197,89 @@ Canvas StreamMenu::renderMenu(const StreamInfo& info) const {
c.clear(kPanel);
c.fillRect({0, 0, kMenuW, 6}, kGreen);
constexpr int kPad = 40;
+
+ auto icon = [&](bool cross, int x, int hy) {
+ if (g_glyphStyle == GlyphStyle::Xbox) { // A / B
+ drawFaceButton(c, fonts_.bold, GlyphStyle::Xbox, cross ? PadButton::Cross : PadButton::Circle, x + 13.0f,
+ hy + 12.0f, 13);
+ return;
+ }
+ c.fillCircle(x + 13, hy + 12, 13, rgba(255, 255, 255, 40));
+ if (cross) {
+ c.line(x + 7, hy + 6, x + 19, hy + 18, 2.5f, rgba(124, 178, 232));
+ c.line(x + 19, hy + 6, x + 7, hy + 18, 2.5f, rgba(124, 178, 232));
+ } else {
+ c.strokeArc(x + 13, hy + 12, 6.0f, 2.5f, 0, 6.2832f, rgba(255, 102, 102));
+ }
+ };
+
+ if (statsCustomizing_) {
+ fonts_.bold.draw(c, tr(Str::StatsCustomize), kPad, 38, 28, kWhite);
+ fonts_.regular.draw(c, tr(Str::MenuStats), kPad, 74, 16, kDim);
+
+ struct IndicatorDef {
+ uint32_t mask;
+ Str label;
+ };
+ static constexpr IndicatorDef kIndicators[8] = {
+ {StatsFps, Str::StatsIndicatorFps},
+ {StatsBitrate, Str::StatsIndicatorBitrate},
+ {StatsLatency, Str::StatsIndicatorLatency},
+ {StatsLoss, Str::StatsIndicatorLoss},
+ {StatsGraph, Str::StatsIndicatorGraph},
+ {StatsDelay, Str::StatsIndicatorDelay},
+ {StatsQp, Str::StatsIndicatorQp},
+ {StatsMic, Str::StatsIndicatorMic},
+ };
+
+ constexpr int kRowH = 46, kTop = 108, kPx = 20;
+ for (int i = 0; i < 8; ++i) {
+ Rect row{kPad - 16, kTop + i * kRowH, kMenuW - 2 * (kPad - 16), kRowH - 4};
+ bool sel = i == statsCustomIndex_;
+ if (sel) c.fillRect(row, kWhite, 8);
+ Color fg = sel ? kDark : kWhite;
+ bool on = (statsMask_ & kIndicators[i].mask) != 0;
+
+ int boxX = row.x + 16;
+ int boxY = row.y + (row.h - 22) / 2;
+ if (on) {
+ c.fillRect({boxX, boxY, 22, 22}, sel ? rgba(16, 124, 16) : rgba(30, 215, 96), 5);
+ c.line(boxX + 5, boxY + 11, boxX + 9, boxY + 16, 2.5f, kWhite);
+ c.line(boxX + 9, boxY + 16, boxX + 17, boxY + 7, 2.5f, kWhite);
+ } else {
+ c.strokeRect({boxX, boxY, 22, 22}, sel ? kDark : kDim, 2, 5);
+ }
+
+ int ty = fonts_.semibold.centeredY(row.y, row.h, kPx);
+ fonts_.semibold.draw(c, tr(kIndicators[i].label), boxX + 34, ty, kPx, fg);
+
+ const char* st = tr(on ? Str::On : Str::Off);
+ int sw = fonts_.semibold.measure(st, 18);
+ fonts_.semibold.draw(c, st, row.x + row.w - 16 - sw, ty, 18, sel ? kDark : kGray);
+ }
+
+ int hy = kMenuH - 50, x = kPad;
+ if (g_keyboardHints) {
+ auto cap = [&](const char* key) {
+ int kw = fonts_.bold.measure(key, 15) + 18;
+ c.fillRect({x, hy, kw, 26}, rgba(255, 255, 255, 30), 6);
+ c.strokeRect({x, hy, kw, 26}, kGray, 2, 6);
+ fonts_.bold.draw(c, key, x + 9, fonts_.bold.centeredY(hy, 26, 15), 15, kWhite);
+ return kw;
+ };
+ int kw = cap("Enter");
+ x = fonts_.semibold.draw(c, tr(Str::Select), x + kw + 8, hy, 20, kGray) + 32;
+ kw = cap("Esc");
+ fonts_.semibold.draw(c, tr(Str::Back), x + kw + 8, hy, 20, kGray);
+ } else {
+ icon(!circleConfirms_, x, hy);
+ x = fonts_.semibold.draw(c, tr(Str::Select), x + 34, hy, 20, kGray) + 32;
+ icon(circleConfirms_, x, hy);
+ fonts_.semibold.draw(c, tr(Str::Back), x + 34, hy, 20, kGray);
+ }
+ return c;
+ }
+
fonts_.bold.draw(c, tr(Str::MenuTitle), kPad, 38, 32, kWhite);
// The items: the selected one white, like the Xbox guide.
@@ -200,7 +312,10 @@ Canvas StreamMenu::renderMenu(const StreamInfo& info) const {
value = tr(hasCustomProfile_ ? Str::ProfileCustom : Str::ProfileDefault);
if (sel) value = "< " + value + " >";
}
- if (i == Stats) value = tr(stats_ ? Str::On : Str::Off);
+ if (i == Stats) {
+ value = tr(stats_ ? Str::On : Str::Off);
+ if (sel) value = "< " + value + " >";
+ }
if (i == Sharpness) {
static constexpr Str kLevels[] = {Str::SharpOff, Str::SharpLow, Str::SharpMedium, Str::SharpHigh};
value = tr(kLevels[sharpness_]);
@@ -356,20 +471,6 @@ Canvas StreamMenu::renderMenu(const StreamInfo& info) const {
gy += 22;
}
}
- auto icon = [&](bool cross) {
- if (g_glyphStyle == GlyphStyle::Xbox) { // A / B
- drawFaceButton(c, fonts_.bold, GlyphStyle::Xbox, cross ? PadButton::Cross : PadButton::Circle, x + 13.0f,
- hy + 12.0f, 13);
- return;
- }
- c.fillCircle(x + 13, hy + 12, 13, rgba(255, 255, 255, 40));
- if (cross) {
- c.line(x + 7, hy + 6, x + 19, hy + 18, 2.5f, rgba(124, 178, 232));
- c.line(x + 19, hy + 6, x + 7, hy + 18, 2.5f, rgba(124, 178, 232));
- } else {
- c.strokeArc(x + 13, hy + 12, 6.0f, 2.5f, 0, 6.2832f, rgba(255, 102, 102));
- }
- };
if (g_keyboardHints) { // Enter / Esc as key caps
auto cap = [&](const char* key) {
int kw = fonts_.bold.measure(key, 15) + 18;
@@ -379,14 +480,14 @@ Canvas StreamMenu::renderMenu(const StreamInfo& info) const {
return kw;
};
int kw = cap("Enter");
- x = fonts_.semibold.draw(c, tr(Str::Select), x + kw + 8, hy, 20, kGray) + 32;
+ x = fonts_.semibold.draw(c, selected_ == Stats ? tr(Str::StatsCustomize) : tr(Str::Select), x + kw + 8, hy, 20, kGray) + 32;
kw = cap("Esc");
fonts_.semibold.draw(c, tr(Str::Back), x + kw + 8, hy, 20, kGray);
return c;
}
- icon(!circleConfirms_);
- x = fonts_.semibold.draw(c, tr(Str::Select), x + 34, hy, 20, kGray) + 32;
- icon(circleConfirms_);
+ icon(!circleConfirms_, x, hy);
+ x = fonts_.semibold.draw(c, selected_ == Stats ? tr(Str::StatsCustomize) : tr(Str::Select), x + 34, hy, 20, kGray) + 32;
+ icon(circleConfirms_, x, hy);
fonts_.semibold.draw(c, tr(Str::Back), x + 34, hy, 20, kGray);
return c;
}
@@ -399,49 +500,78 @@ void StreamMenu::recordFrametime(float ms) const {
Canvas StreamMenu::renderStats(const StreamInfo& info) const {
std::string text;
- if (info.height > 0) text += std::to_string(info.height) + "p ";
- 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); // encoder quantiser
- if (info.onScreenMs > 0) text += " Screen " + fmt("%.1f ms", info.onScreenMs);
- if (info.decodeMs > 0) text += " Dec " + fmt("%.1f ms", info.decodeMs);
- if (!micMuted_) text += " MIC";
+ if (statsMask_ & StatsFps) {
+ if (info.height > 0) text += std::to_string(info.height) + "p ";
+ text += fmt("%.0f fps", info.fps);
+ }
+ if (statsMask_ & StatsBitrate) {
+ if (!text.empty()) text += " ";
+ text += fmt("%.1f Mbps", info.mbps);
+ }
+ if (statsMask_ & StatsLatency) {
+ if (!text.empty()) text += " ";
+ text += info.rttMs > 0 ? std::to_string(info.rttMs) + " ms" : "- ms";
+ }
+ if (statsMask_ & StatsLoss) {
+ if (!text.empty()) text += " ";
+ text += fmt("%.1f%%", info.lossPct);
+ }
+ if ((statsMask_ & StatsQp) && info.qp >= 0) {
+ if (!text.empty()) text += " ";
+ text += "QP " + fmt("%.0f", info.qp);
+ }
+ if (statsMask_ & StatsDelay) {
+ if (info.onScreenMs > 0) {
+ if (!text.empty()) text += " ";
+ text += "Screen " + fmt("%.1f ms", info.onScreenMs);
+ }
+ if (info.decodeMs > 0) {
+ if (!text.empty()) text += " ";
+ text += "Dec " + fmt("%.1f ms", info.decodeMs);
+ }
+ }
+ if ((statsMask_ & StatsMic) && !micMuted_) {
+ if (!text.empty()) text += " ";
+ text += "MIC";
+ }
constexpr int kPx = 18;
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;
- w = std::max(w, 440);
+ w = std::max(w, 200);
- constexpr int kH = 62;
+ bool showGraph = (statsMask_ & StatsGraph) != 0;
+ int kH = showGraph ? 62 : 36;
Canvas c(w, kH);
c.clear(kPanel);
- fonts_.semibold.draw(c, text, 14, 8, kPx, kWhite);
+ if (!text.empty()) fonts_.semibold.draw(c, text, 14, 8, kPx, kWhite);
if (!warn.empty()) fonts_.semibold.draw(c, warn, 14 + tw, 8, kPx, kWarnColor);
- // Row 2: Frametime sparkline bars (last 60 frames)
- int graphX = 14;
- int graphY = 32;
- int graphH = 22;
- int graphW = w - 28;
- // Draw subtle baseline
- c.line(graphX, graphY + graphH, graphX + graphW, graphY + graphH, 1.0f, rgba(80, 80, 80, 160));
- // Target 60fps line (16.7ms out of 40ms scale = ~9px above baseline)
- float targetLineY = (graphY + graphH) - (16.7f / 40.0f) * graphH;
- c.line(graphX, targetLineY, graphX + graphW, targetLineY, 1.0f, rgba(60, 160, 90, 120));
-
- if (!frametimes_.empty()) {
- size_t count = frametimes_.size();
- float barW = std::max(2.0f, static_cast<float>(graphW) / 60.0f - 1.0f);
- float step = barW + 1.0f;
- for (size_t i = 0; i < count; ++i) {
- float ms = frametimes_[i];
- float norm = std::clamp(ms / 40.0f, 0.08f, 1.0f);
- float bh = norm * graphH;
- float bx = graphX + i * step;
- if (bx + barW > graphX + graphW) break;
- Color barColor = ms <= 17.5f ? rgba(40, 200, 60) : ms <= 33.3f ? rgba(255, 190, 40) : rgba(255, 60, 60);
- c.fillRect({static_cast<int>(bx), static_cast<int>(graphY + graphH - bh), static_cast<int>(barW), static_cast<int>(bh)}, barColor);
+ if (showGraph) {
+ // Row 2: Frametime sparkline bars (last 60 frames)
+ int graphX = 14;
+ int graphY = 32;
+ int graphH = 22;
+ int graphW = w - 28;
+ // Draw subtle baseline
+ c.line(graphX, graphY + graphH, graphX + graphW, graphY + graphH, 1.0f, rgba(80, 80, 80, 160));
+ // Target 60fps line (16.7ms out of 40ms scale = ~9px above baseline)
+ float targetLineY = (graphY + graphH) - (16.7f / 40.0f) * graphH;
+ c.line(graphX, targetLineY, graphX + graphW, targetLineY, 1.0f, rgba(60, 160, 90, 120));
+
+ if (!frametimes_.empty()) {
+ size_t count = frametimes_.size();
+ float barW = std::max(2.0f, static_cast<float>(graphW) / 60.0f - 1.0f);
+ float step = barW + 1.0f;
+ for (size_t i = 0; i < count; ++i) {
+ float ms = frametimes_[i];
+ float norm = std::clamp(ms / 40.0f, 0.08f, 1.0f);
+ float bh = norm * graphH;
+ float bx = graphX + i * step;
+ if (bx + barW > graphX + graphW) break;
+ Color barColor = ms <= 17.5f ? rgba(40, 200, 60) : ms <= 33.3f ? rgba(255, 190, 40) : rgba(255, 60, 60);
+ c.fillRect({static_cast<int>(bx), static_cast<int>(graphY + graphH - bh), static_cast<int>(barW), static_cast<int>(bh)}, barColor);
+ }
}
}
return c;
diff --git a/src/ui/stream_menu.h b/src/ui/stream_menu.h
index f5431ac..e77fdbe 100644
--- a/src/ui/stream_menu.h
+++ b/src/ui/stream_menu.h
@@ -24,6 +24,19 @@ struct StreamInfo {
double qp = -1; // the pictures' average quantiser (lower: finer); -1 unknown
bool degraded = false; // frames lost / video stalled / round trip far up, in the last seconds
int playtimeHours = -1; // cloud playtime remaining (-1 unknown/uncapped)
+ std::vector<float> frametimes; // presentation frametimes (ms)
+};
+
+enum StatsIndicator : uint32_t {
+ StatsFps = 1 << 0, // "1080p 60 fps"
+ StatsBitrate = 1 << 1, // "12.5 Mbps"
+ StatsLatency = 1 << 2, // "18 ms"
+ StatsLoss = 1 << 3, // "0.0%"
+ StatsGraph = 1 << 4, // Frametime sparkline histogram
+ StatsDelay = 1 << 5, // "Screen 24.0 ms Dec 5.3 ms"
+ StatsQp = 1 << 6, // "QP 29"
+ StatsMic = 1 << 7, // "MIC"
+ StatsDefaultMask = StatsFps | StatsBitrate | StatsLatency | StatsLoss | StatsGraph,
};
// Close: the menu went away (Circle, OPTIONS, or the Xbox button): a fresh key frame is asked for.
@@ -56,6 +69,10 @@ public:
MenuAction handle(const NavInput& in);
int resolution() const { return resolution_; }
bool statsOn() const { return stats_; }
+ uint32_t statsMask() const { return statsMask_; }
+ void setStatsMask(uint32_t mask) { statsMask_ = mask; }
+ bool isCustomizingStats() const { return statsCustomizing_; }
+ void setFrametimes(const std::vector<float>& ft) const { frametimes_ = ft; }
int sharpness() const { return sharpness_; }
int deband() const { return deband_; }
int upscaler() const { return upscaler_; }
@@ -121,6 +138,9 @@ private:
const Fonts& fonts_;
UiCaps caps_;
bool open_ = false, stats_ = false;
+ uint32_t statsMask_ = StatsDefaultMask;
+ bool statsCustomizing_ = false;
+ int statsCustomIndex_ = 0;
int selected_ = XboxButton;
int resolution_ = 0, applied_ = 0;
int sharpness_ = 0, deband_ = 1, upscaler_ = 0, debandInUse_ = 1;
diff --git a/src/ui/strings.cpp b/src/ui/strings.cpp
index 4674f6d..c3c938c 100644
--- a/src/ui/strings.cpp
+++ b/src/ui/strings.cpp
@@ -324,6 +324,15 @@ constexpr Column kEnglish = {
"Racing (ABS)", // TriggerProfileRacing
"Storage %s is not writable: sign-in and settings will not be saved", // StorageNotWritable
"FTP: run 'chmod 777 %s' or delete the folder and relaunch", // StorageFixHint
+ "Customize indicators", // StatsCustomize
+ "FPS & Resolution", // StatsIndicatorFps
+ "Bitrate", // StatsIndicatorBitrate
+ "Latency (RTT)", // StatsIndicatorLatency
+ "Packet loss", // StatsIndicatorLoss
+ "Frametime graph", // StatsIndicatorGraph
+ "Decode & display latency", // StatsIndicatorDelay
+ "Video quality (QP)", // StatsIndicatorQp
+ "Microphone status", // StatsIndicatorMic
};
constexpr Column kPortugueseBR = {
@@ -618,6 +627,15 @@ constexpr Column kPortugueseBR = {
"Corrida (ABS)", // TriggerProfileRacing
"Armazenamento %s não permite gravação: login e ajustes não serão salvos", // StorageNotWritable
"FTP: use 'chmod 777 %s' ou exclua a pasta e reabra o app", // StorageFixHint
+ "Personalizar indicadores", // StatsCustomize
+ "FPS e resolução", // StatsIndicatorFps
+ "Taxa de bits (Bitrate)", // StatsIndicatorBitrate
+ "Latência (RTT)", // StatsIndicatorLatency
+ "Perda de pacotes", // StatsIndicatorLoss
+ "Gráfico de frametime", // StatsIndicatorGraph
+ "Atraso de decodificação e exibição", // StatsIndicatorDelay
+ "Qualidade do vídeo (QP)", // StatsIndicatorQp
+ "Status do microfone", // StatsIndicatorMic
};
constexpr Column kSpanish = {
@@ -912,6 +930,15 @@ constexpr Column kSpanish = {
"Carreras (ABS)", // TriggerProfileRacing
"El almacenamiento %s no permite escritura: la sesión y ajustes no se guardarán", // StorageNotWritable
"FTP: usa 'chmod 777 %s' o borra la carpeta y reinicia la app", // StorageFixHint
+ "Personalizar indicadores", // StatsCustomize
+ "FPS y resolución", // StatsIndicatorFps
+ "Tasa de bits (Bitrate)", // StatsIndicatorBitrate
+ "Latencia (RTT)", // StatsIndicatorLatency
+ "Pérdida de paquetes", // StatsIndicatorLoss
+ "Gráfico de frametime", // StatsIndicatorGraph
+ "Retardo de decodificación y pantalla", // StatsIndicatorDelay
+ "Calidad de vídeo (QP)", // StatsIndicatorQp
+ "Estado del micrófono", // StatsIndicatorMic
};
constexpr Column kFrench = {
@@ -1206,6 +1233,15 @@ constexpr Column kFrench = {
"Course (ABS)", // TriggerProfileRacing
"Le stockage %s n'est pas accessible en écriture : connexion et réglages non enregistrés", // StorageNotWritable
"FTP : faites 'chmod 777 %s' ou supprimez le dossier et relancez", // StorageFixHint
+ "Personnaliser les indicateurs", // StatsCustomize
+ "IPS et résolution", // StatsIndicatorFps
+ "Débit binaire (Bitrate)", // StatsIndicatorBitrate
+ "Latence (RTT)", // StatsIndicatorLatency
+ "Perte de paquets", // StatsIndicatorLoss
+ "Graphique de frametime", // StatsIndicatorGraph
+ "Latence de décodage et d'affichage", // StatsIndicatorDelay
+ "Qualité vidéo (QP)", // StatsIndicatorQp
+ "État du microphone", // StatsIndicatorMic
};
constexpr Column kGerman = {
@@ -1500,6 +1536,15 @@ constexpr Column kGerman = {
"Rennen (ABS)", // TriggerProfileRacing
"Speicher %s ist schreibgeschützt: Anmeldung und Einstellungen werden nicht gespeichert", // StorageNotWritable
"FTP: 'chmod 777 %s' ausführen oder Ordner löschen und neu starten", // StorageFixHint
+ "Indikatoren anpassen", // StatsCustomize
+ "FPS und Auflösung", // StatsIndicatorFps
+ "Bitrate", // StatsIndicatorBitrate
+ "Latenz (RTT)", // StatsIndicatorLatency
+ "Paketverlust", // StatsIndicatorLoss
+ "Frametime-Diagramm", // StatsIndicatorGraph
+ "Dekodier- und Anzeigelatenz", // StatsIndicatorDelay
+ "Videoqualität (QP)", // StatsIndicatorQp
+ "Mikrofonstatus", // StatsIndicatorMic
};
constexpr Column kItalian = {
@@ -1794,6 +1839,15 @@ constexpr Column kItalian = {
"Corsa (ABS)", // TriggerProfileRacing
"La memoria %s non è scrivibile: accesso e impostazioni non verranno salvati", // StorageNotWritable
"FTP: esegui 'chmod 777 %s' o elimina la cartella e riavvia", // StorageFixHint
+ "Personalizza indicatori", // StatsCustomize
+ "FPS e risoluzione", // StatsIndicatorFps
+ "Bitrate", // StatsIndicatorBitrate
+ "Latenza (RTT)", // StatsIndicatorLatency
+ "Perdita pacchetti", // StatsIndicatorLoss
+ "Grafico frametime", // StatsIndicatorGraph
+ "Latenza di decodifica e visualizzazione", // StatsIndicatorDelay
+ "Qualità video (QP)", // StatsIndicatorQp
+ "Stato microfono", // StatsIndicatorMic
};
constexpr std::array<const Column*, kLangs> kTable = {&kEnglish, &kPortugueseBR, &kSpanish,
diff --git a/src/ui/strings.h b/src/ui/strings.h
index d61e9a9..c5be3a6 100644
--- a/src/ui/strings.h
+++ b/src/ui/strings.h
@@ -301,6 +301,15 @@ enum class Str {
TriggerProfileRacing, // Racing (ABS)
StorageNotWritable, // sign-in / notification: storage not writable (%s: path, %d: errno)
StorageFixHint, // sign-in: hint to fix folder permissions (%s: path)
+ StatsCustomize, // in-game menu: customize stats indicators
+ StatsIndicatorFps,
+ StatsIndicatorBitrate,
+ StatsIndicatorLatency,
+ StatsIndicatorLoss,
+ StatsIndicatorGraph,
+ StatsIndicatorDelay,
+ StatsIndicatorQp,
+ StatsIndicatorMic,
Count
};
diff --git a/tests/test_main.cpp b/tests/test_main.cpp
index 426bd98..50a7a3f 100644
--- a/tests/test_main.cpp
+++ b/tests/test_main.cpp
@@ -540,6 +540,23 @@ static void testStreamMenu() {
CHECK(menu.resolution() == 0); // 720p -> 1080p
press([](xc::ui::NavInput& n) { n.right = true; });
CHECK(menu.resolution() == 2); // 1080p -> Best (2)
+
+ // Test stats indicator customization
+ menu.open(0, true);
+ press([](xc::ui::NavInput& n) { n.down = true; }); // -> Profile
+ press([](xc::ui::NavInput& n) { n.down = true; }); // -> Stats
+ CHECK(press([](xc::ui::NavInput& n) { n.accept = true; }) == MenuAction::Stats);
+ CHECK(menu.isCustomizingStats());
+ // Indicator 0 (StatsFps) is on by default in StatsDefaultMask; toggle it off:
+ CHECK(press([](xc::ui::NavInput& n) { n.accept = true; }) == MenuAction::Stats);
+ CHECK((menu.statsMask() & xc::ui::StatsFps) == 0);
+ // Toggle it back on:
+ CHECK(press([](xc::ui::NavInput& n) { n.accept = true; }) == MenuAction::Stats);
+ CHECK((menu.statsMask() & xc::ui::StatsFps) != 0);
+ // Back returns to main menu:
+ press([](xc::ui::NavInput& n) { n.back = true; });
+ CHECK(!menu.isCustomizingStats());
+ CHECK(menu.isOpen());
}
// A zip archive of stored (uncompressed) files, as the test needs one.
@@ -1685,7 +1702,7 @@ static void testNullBackends() {
// --- M1 input / audio backends (pure parts, null backends) ----------------
-// The audio queue: bounded at ~200 ms (cut back to 100 ms, oldest first),
+// The audio queue: bounded at ~250 ms (cut back to 140 ms, oldest first),
// silence past its end, the volume, and what the periodic log counts.
static void testAudioQueue() {
media::AudioQueue q;
@@ -1693,22 +1710,22 @@ static void testAudioQueue() {
q.push(in.data(), 480);
CHECK(q.queuedFrames() == 0); // closed: ignored
q.open();
- for (int i = 0; i < 19; ++i) q.push(in.data(), 480); // 190 ms: under the bound
- CHECK(q.queuedFrames() == 9120 && q.stats().trimmed == 0);
- q.push(in.data(), 480); // 200 ms
- q.push(in.data(), 480); // 210 ms: past 200, back to 100
- CHECK(q.queuedFrames() == media::AudioQueue::kTrimTo && q.stats().trimmed == 10080 - 4800);
+ for (int i = 0; i < 24; ++i) q.push(in.data(), 480); // 240 ms: under the bound
+ CHECK(q.queuedFrames() == 11520 && q.stats().trimmed == 0);
+ q.push(in.data(), 480); // 250 ms
+ q.push(in.data(), 480); // 260 ms: past 250, back to 140
+ CHECK(q.queuedFrames() == media::AudioQueue::kTrimTo && q.stats().trimmed == 12480 - 6720);
// The oldest go first: mark the newest frame and find it last.
float mark[2] = {0.5f, -0.5f};
q.push(mark, 1);
- std::vector<float> out(4801 * 2);
- q.pull(out.data(), 4801);
- CHECK(out[4800 * 2] == 0.5f && out[4800 * 2 + 1] == -0.5f && out[100 * 2] == 0.25f);
+ std::vector<float> out(6721 * 2);
+ q.pull(out.data(), 6721);
+ CHECK(out[6720 * 2] == 0.5f && out[6720 * 2 + 1] == -0.5f && out[100 * 2] == 0.25f);
CHECK(q.queuedFrames() == 0);
q.pull(out.data(), 256); // empty: silence, counted
CHECK(out[0] == 0.0f && out[511] == 0.0f);
media::AudioQueue::Stats st = q.stats();
- CHECK(st.pulls == 2 && st.empty == 1 && st.frames == 4801 + 256 && st.depthMax == 4801);
+ CHECK(st.pulls == 2 && st.empty == 1 && st.frames == 6721 + 256 && st.depthMax == 6721);
// Volume: clamped to 0..2, applied and clipped at full scale.
q.setVolume(5.0f);
CHECK(q.volume() == 2.0f);
@@ -1720,9 +1737,9 @@ static void testAudioQueue() {
CHECK(q.volume() == 0.0f);
q.setVolume(1.0f);
// ~10 s of sound pulled (480000 frames): logged, and the counts start
- // again. 5059 frames so far, so the 1856th grain of 256 crosses it.
+ // again. 6979 frames so far, so the 1848th grain of 256 crosses it.
for (int i = 0; i < 1875; ++i) q.pull(out.data(), 256);
- CHECK(q.stats().pulls == 19 && q.stats().frames == 19 * 256 && q.stats().trimmed == 0);
+ CHECK(q.stats().pulls == 27 && q.stats().frames == 27 * 256 && q.stats().trimmed == 0);
q.close();
q.push(loud, 2);
CHECK(q.queuedFrames() == 0);
@@ -1877,8 +1894,8 @@ static void testNullBackendsM1() {
CHECK(!kbm.keyboard && !kbm.mouse && !kbm.moved && kbm.dx == 0);
input::kbmSetCaptured(false);
CHECK(media::audioStart() && media::audioStart());
- std::vector<float> sound(48 * 2 * 210, 0.1f); // 210 ms, never played: kept to the bound
- media::audioPush(sound.data(), 48 * 210);
+ std::vector<float> sound(48 * 2 * 260, 0.1f); // 260 ms, never played: kept to the bound
+ media::audioPush(sound.data(), 48 * 260);
CHECK(media::audioQueue().queuedFrames() == media::AudioQueue::kTrimTo);
media::audioStop();
CHECK(media::audioQueue().queuedFrames() == 0);