Skip to content

Xbox Cloud Gaming app for PS5 Homebrew

C

Platform module and null backends: the PS5 code in *_ps5.cpp, stand-ins for the desktop

Rafael Abud Ferreira1306c4f799e2
diff --git a/CMakeLists.txt b/CMakeLists.txt
index 0ee5624..3782e53 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -10,6 +10,7 @@ set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
# XCLOUD_PS5 is set by cmake/ps5.toolchain.cmake.
option(XCLOUD_PS5 "Build for the PS5 (payload SDK)" OFF)
+include(cmake/platform.cmake)
# --- Portable core: auth, HTTPS, xCloud protocol -----------------------------
# The CA bundle inside the binary too: used when assets/cacert.pem can't be read.
@@ -34,7 +35,7 @@ add_library(xcloud_core STATIC
src/xcloud/titlehub.cpp
src/xcloud/regions.cpp
src/xcloud/prices.cpp
- src/input/kbm.cpp
+ src/input/controller_common.cpp
src/input/kbm_map.cpp
src/input/key_map.cpp
src/input/keyboard_nav.cpp
@@ -49,7 +50,7 @@ endif()
# mbedTLS and libdatachannel are built from deps/ for both targets.
include(cmake/deps/mbedtls.cmake)
-target_link_libraries(xcloud_core PUBLIC xc_mbedtls)
+target_link_libraries(xcloud_core PUBLIC xc_mbedtls xc_platform)
if(NOT XCLOUD_PS5)
find_package(Threads REQUIRED)
endif()
@@ -107,10 +108,11 @@ if(XCLOUD_PS5)
src/app/price_loop.cpp
src/app/autoplay.cpp
src/app/stream_player.cpp
- src/display/display.cpp
+ src/display/display_ps5.cpp
src/display/gpu.cpp
- src/media/hw_decoder.cpp
- src/input/controller.cpp
+ src/media/hw_decoder_ps5.cpp
+ src/input/controller_ps5.cpp
+ src/input/kbm_ps5.cpp
)
target_include_directories(xcloud_app PRIVATE "${PS5_RADV}/include")
target_link_libraries(xcloud_app PUBLIC xcloud_stream xcloud_media xcloud_ui)
@@ -118,11 +120,24 @@ else()
target_link_libraries(xcloud_core PUBLIC Threads::Threads)
target_sources(xcloud_core PRIVATE src/platform/host/platform_host.cpp)
+ # No screen, pads, USB keyboard or hardware decoder: what a desktop
+ # build links in place of the PS5's backends (docs/multiplatform.md).
+ add_library(xcloud_backends_null OBJECT
+ src/display/display_null.cpp
+ src/input/controller_null.cpp
+ src/input/kbm_null.cpp
+ src/media/hw_decoder_null.cpp
+ )
+ target_link_libraries(xcloud_backends_null PUBLIC xcloud_core)
+ if(NOT MSVC)
+ target_compile_options(xcloud_backends_null PRIVATE -Wall -Wextra -Wno-unused-parameter)
+ endif()
+
add_executable(xcloud-cli src/app/cli_main.cpp)
target_link_libraries(xcloud-cli PRIVATE xcloud_stream xcloud_media xcloud_ui xc_ffmpeg)
enable_testing()
add_executable(xcloud-tests tests/test_main.cpp)
- target_link_libraries(xcloud-tests PRIVATE xcloud_stream xcloud_media xcloud_ui xc_ffmpeg datachannel-static)
+ target_link_libraries(xcloud-tests PRIVATE xcloud_stream xcloud_media xcloud_ui xcloud_backends_null xc_ffmpeg datachannel-static)
add_test(NAME unit COMMAND xcloud-tests)
endif()
diff --git a/THIRD_PARTY_NOTICES.md b/THIRD_PARTY_NOTICES.md
index a9cfbca..94a7c61 100644
--- a/THIRD_PARTY_NOTICES.md
+++ b/THIRD_PARTY_NOTICES.md
@@ -70,7 +70,7 @@ Copyright (c) 2021 Advanced Micro Devices, Inc.: see `extern/fsr1/LICENSE.txt`.
## References
-- `src/media/hw_decoder.cpp` declares libSceVideodec2's structures as the PS5
+- `src/media/hw_decoder_ps5.cpp` declares libSceVideodec2's structures as the PS5
lays them out, and sets the decoder up (sysmodule 207, memory type 12,
compute queue 0/0) after BlackBearReloaded's
[ProsperoLight](https://github.com/blackbearreloaded/ProsperoLight) and
diff --git a/cmake/platform.cmake b/cmake/platform.cmake
new file mode 100644
index 0000000..0cc4649
--- /dev/null
+++ b/cmake/platform.cmake
@@ -0,0 +1,23 @@
+# SPDX-License-Identifier: GPL-3.0-or-later
+# Copyright (C) 2026 RafaelNGP
+# The system the build is for (docs/multiplatform.md): XC_PLATFORM is ps5,
+# linux or windows, decided by the toolchain (cmake/ps5.toolchain.cmake sets
+# XCLOUD_PS5, which stays as it was). Targets that link xc_platform get
+# XC_PLATFORM_PS5, XC_PLATFORM_LINUX or XC_PLATFORM_WINDOWS, and
+# XC_PLATFORM_DESKTOP on the last two. Backends are picked by the sources an
+# app links, not by these: they are for what can't be split that way.
+if(XCLOUD_PS5)
+ set(XC_PLATFORM ps5)
+elseif(WIN32)
+ set(XC_PLATFORM windows)
+else()
+ set(XC_PLATFORM linux) # other Unix-likes build as Linux (untested)
+endif()
+message(STATUS "Platform: ${XC_PLATFORM}")
+
+add_library(xc_platform INTERFACE)
+string(TOUPPER "${XC_PLATFORM}" XC_PLATFORM_UPPER)
+target_compile_definitions(xc_platform INTERFACE XC_PLATFORM_${XC_PLATFORM_UPPER}=1)
+if(NOT XC_PLATFORM STREQUAL "ps5")
+ target_compile_definitions(xc_platform INTERFACE XC_PLATFORM_DESKTOP=1)
+endif()
diff --git a/src/display/display_null.cpp b/src/display/display_null.cpp
new file mode 100644
index 0000000..52612c7
--- /dev/null
+++ b/src/display/display_null.cpp
@@ -0,0 +1,30 @@
+// SPDX-License-Identifier: GPL-3.0-or-later
+// Copyright (C) 2026 RafaelNGP
+// No screen (a headless build): init() succeeds so the app runs as usual,
+// pictures go nowhere and present() waits about a 60 Hz refresh, so a loop
+// paced by it doesn't spin.
+#include "display/display.h"
+
+#include "platform/platform.h"
+
+namespace xc::display {
+
+std::mutex& frameMutex() {
+ static std::mutex m;
+ return m;
+}
+bool init(bool) { return true; }
+void shutdown() {}
+void present() { platform::sleepMs(16); }
+bool drawYuv420(const uint8_t*, const uint8_t*, const uint8_t*, int, int, int, int, int, bool) { return true; }
+void drawRgba(const uint32_t*) {}
+void setOverlay(const uint32_t*, int, int, int, int, uint8_t) {}
+void setSharpness(int) {}
+void setDeband(int) {}
+void setUpscaler(int) {}
+void setRestore(bool) {}
+uint64_t lastPresentId() { return 0; }
+bool lastShown(uint64_t&, uint64_t&) { return false; }
+bool readBackRgb(std::vector<uint8_t>&, int&, int&) { return false; }
+
+} // namespace xc::display
diff --git a/src/display/display.cpp b/src/display/display_ps5.cpp
similarity index 96%
rename from src/display/display.cpp
rename to src/display/display_ps5.cpp
index a1d775e..8802063 100644
--- a/src/display/display.cpp
+++ b/src/display/display_ps5.cpp
@@ -1,5 +1,7 @@
// SPDX-License-Identifier: GPL-3.0-or-later
// Copyright (C) 2026 RafaelNGP
+// The PS5's display: the GPU (gpu.cpp) when it comes up, else VideoOut
+// buffers drawn on the CPU. display_null.cpp stands in elsewhere.
#include "display/display.h"
#include "display/gpu.h"
#include "platform/platform.h"
@@ -17,8 +19,6 @@
#include <thread>
#include <vector>
-#if defined(XCLOUD_PS5)
-
extern "C" {
size_t sceKernelGetDirectMemorySize();
int sceKernelAllocateDirectMemory(int64_t search_start, int64_t search_end,
@@ -517,28 +517,3 @@ void setOverlay(const uint32_t* pixels, int x, int y, int w, int h, uint8_t opac
}
} // namespace xc::display
-
-#else
-
-// Host PC fallback implementation
-namespace xc::display {
-std::mutex& frameMutex() {
- static std::mutex m;
- return m;
-}
-bool init(bool) { return true; }
-void shutdown() {}
-void present() {}
-bool drawYuv420(const uint8_t*, const uint8_t*, const uint8_t*, int, int, int, int, int, bool) { return true; }
-void drawRgba(const uint32_t*) {}
-void setOverlay(const uint32_t*, int, int, int, int, uint8_t) {}
-void setSharpness(int) {}
-void setDeband(int) {}
-void setUpscaler(int) {}
-void setRestore(bool) {}
-uint64_t lastPresentId() { return 0; }
-bool lastShown(uint64_t&, uint64_t&) { return false; }
-bool readBackRgb(std::vector<uint8_t>&, int&, int&) { return false; }
-} // namespace xc::display
-
-#endif
diff --git a/src/input/controller_common.cpp b/src/input/controller_common.cpp
new file mode 100644
index 0000000..2d074cd
--- /dev/null
+++ b/src/input/controller_common.cpp
@@ -0,0 +1,17 @@
+// SPDX-License-Identifier: GPL-3.0-or-later
+// Copyright (C) 2026 RafaelNGP
+// What every controller backend shares (controller_ps5.cpp, controller_null.cpp).
+#include "input/controller.h"
+
+#include <cmath>
+
+namespace xc::input {
+
+bool inUse(const ControllerState& s) {
+ return s.btnA || s.btnB || s.btnX || s.btnY || s.dpadUp || s.dpadDown || s.dpadLeft || s.dpadRight || s.btnL1 ||
+ s.btnR1 || s.btnL3 || s.btnR3 || s.btnOptions || s.btnTouchpad || s.triggerL2 > 0.5f || s.triggerR2 > 0.5f ||
+ std::abs(s.leftStickX) > 0.5f || std::abs(s.leftStickY) > 0.5f || std::abs(s.rightStickX) > 0.5f ||
+ std::abs(s.rightStickY) > 0.5f;
+}
+
+} // namespace xc::input
diff --git a/src/input/controller_null.cpp b/src/input/controller_null.cpp
new file mode 100644
index 0000000..aeb639a
--- /dev/null
+++ b/src/input/controller_null.cpp
@@ -0,0 +1,47 @@
+// SPDX-License-Identifier: GPL-3.0-or-later
+// Copyright (C) 2026 RafaelNGP
+// No controllers (a build without a pad backend): every slot is empty, the
+// effects go nowhere, and the settings are kept so their getters answer.
+#include "input/controller.h"
+
+#include <algorithm>
+#include <atomic>
+
+namespace xc::input {
+
+namespace {
+// Kept as the PS5's backend keeps them; nothing reads the dead zones without a pad.
+std::atomic<float> g_deadzone[2] = {0.15f, 0.15f};
+std::atomic<bool> g_circleConfirms{false};
+} // namespace
+
+bool init() { return true; }
+void shutdown() {}
+bool poll(ControllerState& out) { return pollPad(0, out); }
+bool pollPad(int, ControllerState& out) {
+ out = {};
+ return false;
+}
+void refreshPads() {}
+bool padConnected(int) { return false; }
+uint64_t padActiveAt(int) { return 0; }
+std::string padUserName(int) { return {}; }
+int32_t padUserId(int) { return -1; }
+void setRumble(uint8_t, uint8_t, uint32_t, int) {}
+void setTriggerRumble(uint8_t, uint8_t, uint32_t, int) {}
+void setDeadzone(float left, float right) {
+ g_deadzone[0] = std::clamp(left, 0.0f, 0.5f);
+ g_deadzone[1] = std::clamp(right, 0.0f, 0.5f);
+}
+void setCircleConfirms(bool on) { g_circleConfirms = on; }
+bool circleConfirms() { return g_circleConfirms; }
+void setTriggerFeel(int, int, int, bool) {}
+void setTriggerLogging(bool) {}
+void setTriggerResistanceActive(bool) {}
+void setLightBar(uint8_t, uint8_t, uint8_t, int) {}
+void resetLightBar(int) {}
+void setGyro(int, int) {}
+void setGyroActive(bool) {}
+void setEmbeddedMicActive(bool, int) {}
+
+} // namespace xc::input
diff --git a/src/input/controller.cpp b/src/input/controller_ps5.cpp
similarity index 92%
rename from src/input/controller.cpp
rename to src/input/controller_ps5.cpp
index fadd26c..5b5e161 100644
--- a/src/input/controller.cpp
+++ b/src/input/controller_ps5.cpp
@@ -1,5 +1,7 @@
// SPDX-License-Identifier: GPL-3.0-or-later
// Copyright (C) 2026 RafaelNGP
+// The DualSense through libScePad, one per signed-in user (controller.h).
+// controller_null.cpp stands in elsewhere.
#include "input/controller.h"
#include "input/gyro.h"
#include "input/tuning.h"
@@ -13,17 +15,6 @@
#include "platform/platform.h"
-namespace xc::input {
-bool inUse(const ControllerState& s) {
- return s.btnA || s.btnB || s.btnX || s.btnY || s.dpadUp || s.dpadDown || s.dpadLeft || s.dpadRight || s.btnL1 ||
- s.btnR1 || s.btnL3 || s.btnR3 || s.btnOptions || s.btnTouchpad || s.triggerL2 > 0.5f || s.triggerR2 > 0.5f ||
- std::abs(s.leftStickX) > 0.5f || std::abs(s.leftStickY) > 0.5f || std::abs(s.rightStickX) > 0.5f ||
- std::abs(s.rightStickY) > 0.5f;
-}
-} // namespace xc::input
-
-#if defined(XCLOUD_PS5)
-
extern "C" {
// Layout of OpenOrbis's OrbisPadData, as the console fills it (connected
// sits at offset 76).
@@ -507,37 +498,3 @@ void setEmbeddedMicActive(bool active, int pad) {
}
} // namespace xc::input
-
-#else
-
-// Host PC fallback implementation
-namespace xc::input {
-bool init() { return true; }
-void shutdown() {}
-bool poll(ControllerState& out) { return pollPad(0, out); }
-bool pollPad(int index, ControllerState& out) {
- out = {};
- out.connected = index == 0;
- return out.connected;
-}
-void refreshPads() {}
-void setRumble(uint8_t, uint8_t, uint32_t, int) {}
-void setTriggerRumble(uint8_t, uint8_t, uint32_t, int) {}
-void setDeadzone(float, float) {}
-void setCircleConfirms(bool) {}
-bool circleConfirms() { return false; }
-void setLightBar(uint8_t, uint8_t, uint8_t, int) {}
-void resetLightBar(int) {}
-bool padConnected(int index) { return index == 0; }
-uint64_t padActiveAt(int) { return 0; }
-std::string padUserName(int index) { return index == 0 ? "Player" : ""; }
-int32_t padUserId(int) { return 0; }
-void setTriggerFeel(int, int, int, bool) {}
-void setTriggerLogging(bool) {}
-void setTriggerResistanceActive(bool) {}
-void setEmbeddedMicActive(bool, int) {}
-void setGyro(int, int) {}
-void setGyroActive(bool) {}
-} // namespace xc::input
-
-#endif
diff --git a/src/input/kbm_null.cpp b/src/input/kbm_null.cpp
new file mode 100644
index 0000000..40d3475
--- /dev/null
+++ b/src/input/kbm_null.cpp
@@ -0,0 +1,11 @@
+// SPDX-License-Identifier: GPL-3.0-or-later
+// Copyright (C) 2026 RafaelNGP
+// No USB keyboard or mouse read (a build without a kbm backend).
+#include "input/kbm.h"
+
+namespace xc::input {
+
+bool kbmInit(int32_t) { return false; }
+KbmInput kbmPoll() { return {}; }
+
+} // namespace xc::input
diff --git a/src/input/kbm.cpp b/src/input/kbm_ps5.cpp
similarity index 97%
rename from src/input/kbm.cpp
rename to src/input/kbm_ps5.cpp
index 95284b4..3f0462c 100644
--- a/src/input/kbm.cpp
+++ b/src/input/kbm_ps5.cpp
@@ -1,5 +1,7 @@
// SPDX-License-Identifier: GPL-3.0-or-later
// Copyright (C) 2026 RafaelNGP
+// USB keyboards and mice through libSceKeyboard and libSceMouse (kbm.h).
+// kbm_null.cpp stands in elsewhere.
#include "input/kbm.h"
#include "platform/platform.h"
@@ -9,8 +11,6 @@
#include <cstddef>
#include <string>
-#if defined(XCLOUD_PS5)
-
extern "C" {
int sceSysmoduleLoadModule(uint16_t id);
int sceKernelLoadStartModule(const char* path, size_t argc, const void* argv, uint32_t flags, void* opt, int* res);
@@ -208,12 +208,3 @@ KbmInput kbmPoll() {
}
} // namespace xc::input
-
-#else // the desktop build: no USB devices read
-
-namespace xc::input {
-bool kbmInit(int32_t) { return false; }
-KbmInput kbmPoll() { return {}; }
-} // namespace xc::input
-
-#endif
diff --git a/src/media/hw_decoder.h b/src/media/hw_decoder.h
index 0bbf23f..9cde252 100644
--- a/src/media/hw_decoder.h
+++ b/src/media/hw_decoder.h
@@ -1,8 +1,9 @@
// SPDX-License-Identifier: GPL-3.0-or-later
// Copyright (C) 2026 RafaelNGP
// H.264 on the PS5's hardware video decoder (libSceVideodec2, the system's
-// own: RADV offers no Vulkan Video on the console). PS5 build only.
-// Setup after BlackBearReloaded's ProsperoLight (GPL-3.0-or-later).
+// own: RADV offers no Vulkan Video on the console), in hw_decoder_ps5.cpp.
+// Setup after BlackBearReloaded's ProsperoLight (GPL-3.0-or-later). Other
+// builds link hw_decoder_null.cpp, whose init() fails.
#pragma once
#include <cstddef>
diff --git a/src/media/hw_decoder_null.cpp b/src/media/hw_decoder_null.cpp
new file mode 100644
index 0000000..0d244e3
--- /dev/null
+++ b/src/media/hw_decoder_null.cpp
@@ -0,0 +1,12 @@
+// SPDX-License-Identifier: GPL-3.0-or-later
+// Copyright (C) 2026 RafaelNGP
+// No hardware decoder (anywhere but the PS5): init() fails, FFmpeg decodes.
+#include "media/hw_decoder.h"
+
+namespace xc::media {
+
+HwDecoder::~HwDecoder() = default;
+bool HwDecoder::init(int, int) { return false; }
+bool HwDecoder::decode(const uint8_t*, size_t, uint64_t, Picture&) { return false; }
+
+} // namespace xc::media
diff --git a/src/media/hw_decoder.cpp b/src/media/hw_decoder_ps5.cpp
similarity index 100%
rename from src/media/hw_decoder.cpp
rename to src/media/hw_decoder_ps5.cpp
diff --git a/tests/test_main.cpp b/tests/test_main.cpp
index 5f10839..d1920a7 100644
--- a/tests/test_main.cpp
+++ b/tests/test_main.cpp
@@ -9,6 +9,8 @@
#include "app/report.h"
#include "media/audio_encoder.h"
#include "media/decoder.h"
+#include "media/hw_decoder.h"
+#include "input/controller.h"
#include "input/gyro.h"
#include "input/tuning.h"
#include "net/http.h"
@@ -1121,7 +1123,28 @@ static void testGyro() {
CHECK(std::abs(x5 - xf) < 0.01f);
}
+// The desktop's stand-ins for the PS5 backends: nothing connected, the
+// settings kept for their getters.
+static void testNullBackends() {
+ CHECK(input::init());
+ input::ControllerState pad;
+ pad.btnA = true;
+ CHECK(!input::poll(pad) && !pad.connected && !pad.btnA);
+ CHECK(!input::pollPad(2, pad) && !input::padConnected(0) && input::padUserName(0).empty());
+ CHECK(input::padUserId(0) == -1 && input::padActiveAt(0) == 0);
+ input::setCircleConfirms(true);
+ CHECK(input::circleConfirms());
+ input::setCircleConfirms(false);
+ CHECK(!input::circleConfirms());
+ CHECK(!input::kbmInit(-1));
+ input::KbmInput kbm = input::kbmPoll();
+ CHECK(!kbm.keyboard && !kbm.mouse && kbm.keys.empty() && !kbm.moved);
+ media::HwDecoder hw;
+ CHECK(!hw.init(1920, 1088) && !hw.ready());
+}
+
int main() {
+ testNullBackends();
testLoginRetry();
testGyro();
testReport();