Skip to content

Xbox Cloud Gaming app for PS5 Homebrew

C

Fix silent audio after switching games

Rafael Abud Ferreira8e08ad41d030
diff --git a/README.md b/README.md
index 9d87e6f..6fa6828 100644
--- a/README.md
+++ b/README.md
@@ -10,7 +10,7 @@ Cliente nativo de Xbox Cloud Gaming (xCloud) para PS5 com homebrew.
| Login (conta salva), lista de jogos, sessão, fila | testado | testado |
| WebRTC (SDP/ICE, DTLS-SRTP, canais de dados) | testado | testado |
| Vídeo 1080p60 H.264 (FFmpeg, 3,1 ms/quadro no PS5) | testado | testado: 3 min, 99,6% dos quadros exibidos |
-| Áudio Opus → sceAudioOut | decodificação testada | decodificado e enviado à saída (falta confirmar de ouvido) |
+| Áudio Opus → sceAudioOut | decodificação testada | testado (ouvido no console; também ao trocar de jogo) |
| DualSense → controle Xbox no jogo | — | testado (autoplay aperta A no Balatro) |
## Teste automático no console
@@ -23,6 +23,7 @@ estatísticas por segundo e salva quadros em `frame.ppm`/`frame2.ppm`.
```bash
PS5_HOST=<ip> tools/ps5/autotest.sh BALATRO 60 # streaming
PS5_HOST=<ip> tools/ps5/autotest.sh BALATRO 30 dump # + grava stream.aus (H.264 recebido)
+PS5_HOST=<ip> tools/ps5/autotest.sh BALATRO 20 repeat # duas sessões seguidas no mesmo processo
XC_SAMPLE=amostra.h264 PS5_HOST=<ip> tools/ps5/autotest.sh BENCH 30 # só o decoder
build-host/xcloud-cli bench-decode build-ps5/autotest/stream.aus # reproduz no PC
```
@@ -37,6 +38,8 @@ Resultados em `build-ps5/autotest/`.
- `ioctl(FIONBIO)`/`fcntl(O_NONBLOCK)` em sockets dão `EACCES`;
`setsockopt(SO_NBIO)` funciona (`ioctl` é embrulhado via `ps5/compat/ps5_lfs.h`).
- O callback de log padrão do FFmpeg derruba o app: o log vai para o nosso logger.
+- `sceAudioOutInit` só pode ser chamado uma vez por processo (a segunda
+ chamada devolve `0x8026000E`); só a porta é aberta/fechada por jogo.
- O depacketizador H.264 às vezes entrega unidades vazias, que o libavcodec
entende como fim de stream: são descartadas.
diff --git a/src/app/ps5_main.cpp b/src/app/ps5_main.cpp
index e01624c..7d92af1 100644
--- a/src/app/ps5_main.cpp
+++ b/src/app/ps5_main.cpp
@@ -92,6 +92,7 @@ int g_autoplaySeconds = 0;
// Autoplay presses A at 15 s and 20 s into the stream (input check).
std::atomic<bool> g_syntheticA{false};
bool g_autoplayDump = false;
+int g_autoplayRuns = 1; // "repeat": two sessions in one process
void loadAutoplay() {
std::string text;
@@ -102,6 +103,7 @@ void loadAutoplay() {
if (std::sscanf(text.c_str(), "%127s %d %63s", title, &seconds, option) >= 1) {
if (std::string(option) == "nosimd") media::disableSimd();
g_autoplayDump = std::string(option) == "dump";
+ if (std::string(option) == "repeat") g_autoplayRuns = 2;
g_autoplayTitle = title;
g_autoplaySeconds = seconds > 0 ? seconds : 60;
XC_LOGI("AUTOPLAY %s for %ds", title, g_autoplaySeconds);
@@ -287,7 +289,14 @@ void doProvision(auth::AuthManager& am, xcloud::GssvClient& gssv, const std::str
if (g_cancel && result.rfind("Stream", 0) != 0) result = "Cancelado";
gssv.stopSession();
setSession(result, false);
- if (!g_autoplayTitle.empty()) XC_LOGI("AUTOPLAY END: %s", result.c_str());
+ if (!g_autoplayTitle.empty()) {
+ if (--g_autoplayRuns > 0) {
+ XC_LOGI("AUTOPLAY next run: %s", result.c_str());
+ g_command = kProvision;
+ } else {
+ XC_LOGI("AUTOPLAY END: %s", result.c_str());
+ }
+ }
}
void worker() {
diff --git a/src/media/audio_out.cpp b/src/media/audio_out.cpp
index 3f874b3..563b1b0 100644
--- a/src/media/audio_out.cpp
+++ b/src/media/audio_out.cpp
@@ -59,10 +59,16 @@ void loop() {
bool audioStart() {
if (g_running) return true;
#if defined(XCLOUD_PS5)
- int rc = sceAudioOutInit();
- if (rc < 0 && rc != static_cast<int>(0x8026000C)) { // already initialised
- XC_LOGE("sceAudioOutInit: 0x%08x", static_cast<unsigned>(rc));
- return false;
+ // Once per process: a second sceAudioOutInit answers "already
+ // initialised" (0x8026000E on this firmware, 0x8026000C elsewhere).
+ static bool initialised = false;
+ if (!initialised) {
+ int rc = sceAudioOutInit();
+ if (rc < 0 && rc != static_cast<int>(0x8026000C) && rc != static_cast<int>(0x8026000E)) {
+ XC_LOGE("sceAudioOutInit: 0x%08x", static_cast<unsigned>(rc));
+ return false;
+ }
+ initialised = true;
}
// The system user (0xFF), MAIN port, float stereo: as the WoW-PS5 port.
g_handle = sceAudioOutOpen(0xFF, 0, 0, kGrain, kRate, 4);