Xbox Cloud Gaming app for PS5 Homebrew
C
Docs: the Linux app (M1) in docs/multiplatform.md, README and AGENTS.md
Rafael Abud Ferreiraf3688ce2a003
diff --git a/AGENTS.md b/AGENTS.mdindex f8a861b..e10dcd0 100644--- a/AGENTS.md+++ b/AGENTS.md@@ -104,5 +104,6 @@ Para evitar degradação de desempenho, latência alta e manter a interação á- O **PS5 é a plataforma principal**; Linux e Windows rodam o mesmo núcleo do app (`src/app/app_core.cpp`) com backends próprios. O mapa completo está em `docs/multiplatform.md`.- **Toda alteração deve manter Linux e Windows compilando.** Uma funcionalidade exclusiva do PS5 vira no-op controlado por capacidade no desktop (`display::caps()`, `shell::canSelfUpdate()`...) ou tem a opção escondida — nunca quebra o build nem trava o app.- **NUNCA chame funções `sce*`, inclua headers do SDK do PS5 ou use `XCLOUD_PS5` (ou outro teste de PS5) fora dos arquivos de backend do PS5** (`*_ps5.cpp`, `src/platform/ps5/`, `src/display/gpu.cpp`). O script `tools/check-platform-boundaries.sh` verifica isso (também no CI).-- Antes de considerar uma alteração pronta, compile os alvos de desktop (`ninja -C build-test` ou `build-host`, incluindo `psbox-headless`, e rode `xcloud-tests`), o app do PS5 (`ninja -C build-ps5 xcloud_app` + `bash tools/ps5/link.sh build-ps5`) e rode o script de fronteiras. Um link de desenvolvimento grava os símbolos em `symbols/vX.Y.Z-dev`; só o `tools/release.sh` grava `symbols/vX.Y.Z` (os da release, usados para decodificar crashes dos usuários).+- Antes de considerar uma alteração pronta, compile os alvos de desktop (`ninja -C build-test` ou `build-host`, incluindo `psbox` — o app SDL3, quando o SDL3 existe — e `psbox-headless`, e rode `xcloud-tests`; `psbox-headless`, `xcloud-cli` e `xcloud-tests` nunca dependem do SDL), o app do PS5 (`ninja -C build-ps5 xcloud_app` + `bash tools/ps5/link.sh build-ps5`) e rode o script de fronteiras. Um link de desenvolvimento grava os símbolos em `symbols/vX.Y.Z-dev`; só o `tools/release.sh` grava `symbols/vX.Y.Z` (os da release, usados para decodificar crashes dos usuários).- O fluxo de validação por screenshots no console (seção 2) continua obrigatório para mudanças de UI no PS5.+- No desktop, `psbox --selftest <dir>` (com `SDL_VIDEO_DRIVER=offscreen SDL_AUDIO_DRIVER=dummy`) verifica janela, telas, vídeo, overlay, entrada e áudio sem conta nem rede; use-o (e olhe os PNGs) ao mexer no display, shell ou UI do desktop. Opções que o PC não suporta somem pela capacidade (`ui::UiCaps`); no PS5 todas continuam visíveis.diff --git a/README.md b/README.mdindex 25b4876..033cd68 100644--- a/README.md+++ b/README.md@@ -91,10 +91,30 @@ build-host/xcloud-tests # unit testsbuild-host/xcloud-cli login # sign inbuild-host/xcloud-cli stream BALATRO 30 # stream a title for 30 s (--720p, --region=EASTUS)build-host/xcloud-cli ui-preview /tmp/ui # render every screen to PNG-build-host/psbox-headless # the app itself, no window yet (Ctrl+C closes it)+build-host/psbox-headless # the app with no window or devices (Ctrl+C closes it)bash tools/check-platform-boundaries.sh # PS5 calls only in the PS5 backends```+### Linux (preview)++`psbox` is the app in a window, on SDL3 (3.2 or newer, with its development+files: `SDL3-devel` on Fedora, `libsdl3-dev` on Debian / Ubuntu). It is+built with the desktop build above whenever CMake finds SDL3+(`-DXCLOUD_DESKTOP_APP=ON` to require it, `OFF` to skip it).++```bash+build-host/psbox # F11 or Alt+Enter: fullscreen; --fullscreen, --data-dir <dir>+SDL_VIDEO_DRIVER=offscreen SDL_AUDIO_DRIVER=dummy build-host/psbox --selftest /tmp/psbox-selftest+```++Sign-in, settings and the log live in `~/.local/share/psbox` (or+`$XCLOUD_DATA_DIR`); the fonts and certificates are copied to `assets/`+beside the executable. Controllers (DualSense, DualShock 4, Xbox, Switch...),+keyboard and mouse are supported (a preview: not checked on every pad yet); options the PC can't honour (light bar without a+DualSense, 120 Hz, the PS5's upscalers) are hidden. It doesn't update+itself: Settings > Updates opens the release page. See+`docs/multiplatform.md` (M1).+### PS5 buildThe console build uses the toolchain ofdiff --git a/docs/multiplatform.md b/docs/multiplatform.mdindex b5dfbdb..e9fdd6a 100644--- a/docs/multiplatform.md+++ b/docs/multiplatform.md@@ -24,7 +24,7 @@ plan to get there.|----------------|------------------------------------------------------------|-----------------------------------------------|------------------------|| `XC_PLATFORM` | `ps5` (`cmake/ps5.toolchain.cmake` sets `XCLOUD_PS5`) | `linux` | `windows` (M2) || Build | `build-ps5`: `ninja xcloud_app`, then `tools/ps5/link.sh` | `build-host`: `ninja` | llvm-mingw cross (M2) |-| The app | `xcloud_app` → `eboot.bin` | `psbox-headless` (M0), SDL3 app (M1) | SDL3 app (M2) |+| The app | `xcloud_app` → `eboot.bin` | `psbox` (SDL3, M1), `psbox-headless` | SDL3 app (M2) || Tools / tests | | `xcloud-cli`, `xcloud-tests` | under wine (M2) |`cmake/platform.cmake` sets `XC_PLATFORM` and the `xc_platform` interface@@ -55,32 +55,40 @@ links those objects with its backends:- `psbox-headless` (desktop): core + `xcloud_backends_null` + `shell_null.cpp`+ `headless_main.cpp`. No window, controller, sound or hardware decoder, noSDL: it proves the shared app builds and starts off the PS5. It uses the- desktop data folder (`~/.local/share/xcloud-ps5`, or `XCLOUD_DATA_DIR`) like- `xcloud-cli`; Ctrl+C closes it.+ desktop data folder like `xcloud-cli`; Ctrl+C closes it.+- `psbox` (desktop, SDL3): core + `xcloud_backends_desktop` (`display_sdl.cpp`,+ `shell_desktop.cpp`, the self-test, `hw_decoder_null.cpp`) ++ `xcloud_backends_sdl_io` (controllers, keyboard / mouse, sound) ++ `desktop_main.cpp`. See "M1: the Linux app" below.- `xcloud-cli` and `xcloud-tests` stay SDL-free; the tests link the null backends.## Backend map| Area | Header | PS5 | Desktop (planned) | Null ||-----------------------|---------------------------|---------------------------------------|----------------------------|---------------------------|-| Display | `display/display.h` | `display_ps5.cpp` (+ `gpu.cpp`, RADV) | `display_sdl.cpp` (M1) | `display_null.cpp` |-| Controllers | `input/controller.h` | `controller_ps5.cpp` | `controller_sdl.cpp` (M1) | `controller_null.cpp` |-| USB keyboard / mouse | `input/kbm.h` | `kbm_ps5.cpp` | `kbm_sdl.cpp` (M1) | `kbm_null.cpp` |-| Audio out / in | `media/audio_out.h`, `audio_in.h` | `audio_out.cpp`, `audio_in.cpp` (`#if`, legacy) | SDL audio (M1) | the same files without the PS5 parts (no device) |+| Display | `display/display.h` | `display_ps5.cpp` (+ `gpu.cpp`, RADV) | `display_sdl.cpp` | `display_null.cpp` |+| Controllers | `input/controller.h`, `input_ext.h` | `controller_ps5.cpp` | `controller_sdl.cpp`, `sdl_input.cpp` | `controller_null.cpp` |+| USB keyboard / mouse | `input/kbm.h` | `kbm_ps5.cpp` | `kbm_sdl.cpp` | `kbm_null.cpp` |+| Audio out / in | `media/audio_out.h`, `audio_in.h` | `audio_out_ps5.cpp`, `audio_in_ps5.cpp` | `audio_out_sdl.cpp`, `audio_in_sdl.cpp` | `audio_*_null.cpp` (no device) || Hardware H.264 | `media/hw_decoder.h` | `hw_decoder_ps5.cpp` (libSceVideodec2)| FFmpeg hwaccel (later) | `hw_decoder_null.cpp` |-| Platform layer | `platform/platform.h` | `platform/ps5/*` + `posix_common.cpp` | Linux: `platform/host/platform_host.cpp` + `posix_common.cpp`; Windows: win32 (M2) | |-| Shell | `app/shell.h` | `shell_ps5.cpp` | desktop shell (M1) | `shell_null.cpp` |+| Platform layer | `platform/platform.h` | `platform/ps5/*` + `posix_common.cpp` | Linux: `platform/linux/platform_linux.cpp` + `posix_common.cpp`; Windows: win32 (M2) | |+| Shell | `app/shell.h` | `shell_ps5.cpp` | `shell_desktop.cpp` | `shell_null.cpp` |-Portable, shared by every backend: `controller_common.cpp`, `kbm_map.cpp`,+Portable, shared by every backend: `controller_common.cpp`, `sdl_mapping.cpp`+(pure tables), `media/audio_queue.cpp`, `audio_in_common.cpp`, `kbm_map.cpp`,`key_map.cpp`, `keyboard_nav.cpp`, `gyro.cpp`, the UI (`src/ui`), decoding(`media/decoder.cpp`), the protocol (`src/stream`, `src/xcloud`, `src/auth`).The shell's hooks, in the order `app_core.cpp` calls them:`beforeSettings()` (PS5: an update cut short rolled back, a store update'sfiles brought back), `beforeDisplay(settings)` (PS5: splash screen hidden,-the 120 Hz video-out setup), `iconFontPaths()`, `pumpEvents()` each pass-(false once the user closes the app; never on the PS5), `canSelfUpdate()`,-`isInstalledCopy(dir)` and `restartOrExit()` around an update.+the 120 Hz video-out setup), `afterDisplay(haveDisplay)` (the desktop: its+window to the input backend), `iconFontPaths()`, `pumpEvents()` each pass+(false once the user closes the app; never on the PS5), `hasFocus()`,+`canSelfUpdate()`, `isInstalledCopy(dir)` and `restartOrExit()` around an+update, `beforeShutdown()` (desktop only). `caps()` (console / openUrl /+selfUpdate) words the screens; `openUrl(url)` opens the browser (false on the+PS5).## Capabilities: PS5-only features on other platforms@@ -91,7 +99,14 @@ shared code:`deband`, `sharpen`, `highRefreshSwitch` (120 Hz per stream),`presentTiming`. On the PS5 it is what the GPU path supports; the nulldisplay says false to all. The desktop UI hides the options it can't- honour (M1); the calls themselves are always safe (no-ops).+ honour; the calls themselves are always safe (no-ops).+- `input::padCaps(i)` / `anyPadCaps()` (`input_ext.h`): rumble, trigger+ rumble, adaptive triggers, light bar, gyro, touchpad. The PS5 always+ answers a DualSense with everything, so its UI never changes.+- `app::uiCaps()` gathers the three into `ui::UiCaps`; Settings, a game's+ settings and the in-game menu hide the rows it rules out+ (`ui::visibleSettingsRows()`, unit-tested: with the PS5's caps every row,+ in the same order and groups). A hidden row's setting is kept as it is.- `shell::canSelfUpdate()`: only the PS5 installs updates. Elsewhere a newerrelease is noted in the log and never offered.- Null backends are honest: no pad means `pollPad()` reports nothing@@ -106,7 +121,7 @@ shared code:the GPU's switches behind `display::` and `display::caps()`; the app coreand shell split; `psbox-headless`; `tools/check-platform-boundaries.sh`in CI; the microphone gain fix.-- **M1, Linux app on SDL3**: a window; an `SDL_Renderer` display with a single+- **M1, Linux app on SDL3** (done, below): a window; an `SDL_Renderer` display with a singlerender thread and a video mailbox; `controller_sdl` with the DualSense'seffects, light bar, gyro and touchpad (and the `controller_common` split);`kbm_sdl` with relative mouse; SDL audio, with a portable AudioQueue@@ -127,15 +142,62 @@ shared code:- **Later**: a Vulkan desktop display reusing `gpu.cpp` (FSR, Anime4K),FFmpeg hardware decoding, a desktop updater.+## M1: the Linux app++`psbox` is built when CMake finds SDL3 3.2 or newer (`XCLOUD_DESKTOP_APP`:+`AUTO` by default, `ON` to require it, `OFF` to never look; `cmake/deps/sdl3.cmake`).+`psbox-headless`, `xcloud-cli` and `xcloud-tests` never link SDL.++```bash+cmake -S . -B build-desktop -G Ninja -DCMAKE_BUILD_TYPE=RelWithDebInfo \+ -DCMAKE_C_COMPILER=clang -DCMAKE_CXX_COMPILER=clang+++ninja -C build-desktop+build-desktop/psbox # --fullscreen, --windowed, --data-dir <dir>+SDL_VIDEO_DRIVER=offscreen SDL_AUDIO_DRIVER=dummy build-desktop/psbox --selftest /tmp/psbox-selftest+```++- **Display** (`display_sdl.cpp`): a 1600x900 resizable window (F11 or+ Alt+Enter: fullscreen), an `SDL_Renderer` with vsync, the 1920x1080 picture+ letterboxed. SDL renders on the main thread only: the drawing threads fill a+ back frame, `present()` puts it in a one-slot mailbox (the newest wins; the+ video thread never waits for vsync) and `display::pump()`, each pass of the+ main loop, uploads it (YUV into a BT.709 limited IYUV texture; the menu as+ ABGR8888), blends the overlay and presents. `idleWait()` wakes on a new+ frame. `readBackRgb()` works on the main thread only. No upscalers,+ sharpening, block smoothing or 120 Hz (`caps()`).+- **Shell** (`shell_desktop.cpp`): SDL starts before the display, every event+ goes to `input::sdlInputEvent()`, focus lost lets the mouse go, closing the+ window or Ctrl+C / SIGTERM closes the app in order (the worker leaves its+ loop, a stream and its xCloud session stop, then the backends close, then+ `_Exit`). Notices are toasts in the window; links (sign-in page, report+ form, the release page from Settings > Updates) open in the browser; the+ app never updates itself.+- **Input / sound** (`controller_sdl.cpp`, `kbm_sdl.cpp`, `audio_*_sdl.cpp`):+ gamepads hot-plugged into the first free slot, DualSense trigger effects,+ light bar, gyro and touchpad where SDL reaches them; the mouse is held+ (relative mode) only while a game has the keyboard and mouse and its menu+ is closed; Ctrl + 1-4 picks the keyboard's player (plain digits on the PS5).+- **Files**: the data folder (sign-in, settings, caches, `xcloud.log`) is+ `$XCLOUD_DATA_DIR`, else `$XDG_DATA_HOME/psbox` (`~/.local/share/psbox`;+ an old `~/.local/share/xcloud-ps5` is moved there once); `account.json` is+ readable by the user only. Assets (fonts, certificates) come from+ `$XCLOUD_ASSETS`, else `assets/` beside the executable (the build copies+ it there), else `./assets`.+- **Self-test** (`--selftest <dir>`): window and renderer, the input hooks+ (no pad: slot 0 empty), the sign-in and Settings screens with this+ machine's capabilities, colour bars through the mailbox alone and under+ the game menu (pixels checked), sound out (200 ms) and the microphone+ opened and closed; PNGs in `<dir>`, exit 1 on any failure. No account or+ network.+## Rules for contributors1. No `sce*` call, PS5 SDK header (`<ps5platform/...>`), `XCLOUD_PS5` /`XC_PLATFORM_PS5` / `__PROSPERO__` / `__ORBIS__`, or `#if` on `__FreeBSD__`or on "not `XC_PLATFORM_DESKTOP`" outside the PS5 backends.`tools/check-platform-boundaries.sh` enforces it (CI runs it; comments- don't count) and lists the allowed files; the legacy ones (`audio_out.cpp`,- `audio_in.cpp`, `crash_guard.cpp`) carry a TODO naming the milestone that- splits them.+ don't count) and lists the allowed files; the legacy one+ (`crash_guard.cpp`) carries a TODO naming the milestone that splits it.2. Something new that differs by platform: free functions in a portableheader, one file per backend (`*_ps5.cpp`, `*_null.cpp`, later`*_sdl.cpp`), and the build lists which one each app links. A PS5-only@@ -145,7 +207,7 @@ shared code:and `XCLOUD_PS5` as the PS5 build's switch.4. Before calling a change done, build and check every platform:```bash- ninja -C build-host && build-host/xcloud-tests # desktop: psbox-headless, cli, tests+ ninja -C build-host && build-host/xcloud-tests # desktop: psbox (with SDL3), psbox-headless, cli, testsninja -C build-ps5 xcloud_app && tools/ps5/link.sh build-ps5bash tools/check-platform-boundaries.sh```