Skip to content

test(libSceAudioOut): pin the port state of a stereo main port - #17554

Open
xXPBSXx wants to merge 1 commit into
boykopovar:mainfrom
xXPBSXx:e/test-audioout-portstate
Open

xXPBSXx wants to merge 1 commit into
boykopovar:mainfrom
xXPBSXx:e/test-audioout-portstate

Conversation

@xXPBSXx

@xXPBSXx xXPBSXx commented Nov 8, 2026

Copy link
Copy Markdown
Contributor

What

Adds the test audio_out_port_state (new AudioOutPortState.cpp): a main port opened with sceAudioOutOpen(user, 0, 0, 1024, 48000, 1) (16-bit stereo) must report channel == 2, flag == 0 and activeState == 0 from sceAudioOutGetPortState, before and after one output of 1024 silent frames. main already behaves this way, so the test passes on main unchanged and only fixes the console value in place.

The fields output, volume and rerouteCounter are not pinned: the console reported output 0, volume -1 and rerouteCounter 5 there, and AnyPS5 reports 1, 127 and 0.

Tested

Measured on a PS5 with firmware 11.60 (kernel_get_fw_version 0x11600005), from a homebrew payload process (ps5-payload-sdk v0.45, elfldr), on 2026-11-07 at 04:56 UTC (the console clock was about 1 h 41 min ahead), one run. sceAudioOutGetPortState returned 0 and a 16-byte record with channel 2 and flag and active state 0, the same before and after the output. A title process may differ. The probe source and its raw output are in the first comment.

On Ubuntu 24.04 under WSL2 with an AddressSanitizer and UBSan build (BUILD_TESTING=ON), ctest -R audio_out_port_state passes on main b0e5efb708. Changing AudioOut.cpp so that a stereo port reports 3 channels makes it fail. tools/check_conventions.py --base upstream/main passes.

Overlap: the 20 other open pull requests that change the library's CMakeLists.txt or AudioOutBufferSize.cpp (the files that touch this change's CMakeLists.txt lines) were checked on 2026-11-08 between 21:35 UTC and 21:43 UTC against main 0bae53facd (the base of this change is the older b0e5efb708; it still merges without a conflict, and sceAudioOutGetPortState is unchanged between the two). Four already conflict with main without this change (#12863, #5021, #12315 and #14212), and none conflicts only with this change. The other sixteen merge cleanly with and without it, among them #17546, #16737, #16736, #16641, #16614 and #16597.

Checklist

  • Based on current main; no other open PR implements the same functions
  • One topic per PR; follow-ups go in a new PR
  • No comments in code except technical debt
  • Unimplemented paths throw (NotImplemented_nid_no_patch); silent stubs are listed under Silent stubs in their library's technical debt file
  • No notes, investigation .md files or images added to the repository (attach them to this PR)
  • New third-party code is a submodule built from source
  • Generic behaviour, not specific to one title
  • Depends on: none
  • Fixes: none
  • Unblocks: none
  • GPUs tested: n/a (audio change)
  • AI-assisted: yes

AI-assisted (Claude Code).

🤖 Generated with Claude Code

A PS5 on firmware 11.60 (payload process) reports 2 channels, flag 0 and active state 0 from sceAudioOutGetPortState for a main port opened as 48 kHz, 1024 frames, 16-bit stereo, before and after one output. Pin those fields.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
@xXPBSXx

xXPBSXx commented Nov 8, 2026

Copy link
Copy Markdown
Contributor Author

Probe source (built with ps5-payload-sdk v0.45; PROBE_BUILD is the first 12 hex digits of the source's SHA-256, here cacbea9945d6) and its complete raw output. The utc in the PROBE line is the console's own clock, about 1 h 41 min ahead of real UTC; the run started at 04:56 UTC. This pull request pins only the channel count, flag and active state of cases 3 and 7 (sceAudioOutGetPortState on the open port, before and after the output); the other cases (last output time, close, invalid handles) belong to other changes. The source is the one that ran, unchanged; its comments were written in English.

/* Probe E: sceAudioOutGetLastOutputTime and sceAudioOutGetPortState, payload process, firmware 11.60 (debt
   libSceAudioOut.md: what the last output time is, and the answer before any output). One port is opened with
   sceAudioOutOpen(0xff, 0, 0, 1024, 48000, 0x1), one block of silence (1024 samples, 16-bit stereo, all zero) is output
   and the port is closed. The output time is printed raw and as the difference to sceKernelGetProcessTime() taken
   just before and just after the output call. The port state record is a 64-byte marker buffer: only the return
   code, the number of changed bytes and its first 16 bytes are printed. No user ID of a person is used (0xff is the
   system user). Nothing is written, nothing is sent. */
#include <dlfcn.h>
#include <errno.h>
#include <pthread.h>
#include <signal.h>
#include <stdint.h>
#include <stdio.h>
#include <string.h>
#include <time.h>
#include <unistd.h>
#include <ps5/kernel.h>   /* only for kernel_get_fw_version() */

#ifndef PROBE_NAME
#define PROBE_NAME "unnamed"
#endif
#ifndef PROBE_BUILD
#define PROBE_BUILD "unbuilt"
#endif
/* Self limit: the runner can only close the connection, it cannot end the process on the console, so the probe ends
   itself after PROBE_MAX_S seconds at the latest (set by the build script). */
#ifndef PROBE_MAX_S
#define PROBE_MAX_S 50
#endif

static void probe_alarm(int sig) {
  static const char msg[] = "TIMEOUT\tprobe self limit\n";
  (void)sig;
  (void)!write(1, msg, sizeof msg - 1);
  _exit(124);
}

/* Watchdog thread: alarm()/SIGALRM does not help when the main thread hangs in a blocking system call or IPC. The
   thread sleeps PROBE_MAX_S seconds, writes TIMEOUT with write() and ends the process with _exit(124). alarm() stays
   as a second safeguard. */
static void* probe_watchdog(void* arg) {
  static const char msg[] = "TIMEOUT\tprobe watchdog thread\n";
  unsigned left = PROBE_MAX_S;
  (void)arg;
  while (left) left = sleep(left);
  (void)!write(1, msg, sizeof msg - 1);
  _exit(124);
  return 0;
}

static void probe_watchdog_start(void) {
  pthread_t t;
  if (pthread_create(&t, 0, probe_watchdog, 0) == 0) pthread_detach(t);
}

static int cases = 0;

static void probe_header(void) {
  char utc[32];
  time_t now = time(0);
  probe_watchdog_start();
  struct tm tmv;
  gmtime_r(&now, &tmv);
  strftime(utc, sizeof utc, "%Y-%m-%dT%H:%M:%SZ", &tmv);
  printf("PROBE\t%s\tfw=0x%08x\tbuild=%s\tpid=%d\tutc=%s\n", PROBE_NAME, kernel_get_fw_version(), PROBE_BUILD,
         getpid(), utc);
  fflush(stdout);
}

static void probe_case(const char* id, const char* call, long ret, int err, const char* extra) {
  printf("CASE\t%s\t%s\t%ld\t%d\t%s\n", id, call, ret, err, extra ? extra : "-");
  fflush(stdout);
  cases++;
}

static void probe_end(void) {
  printf("END\t%d\n", cases);
  fflush(stdout);
}



typedef int (*fn_init)(void);
typedef int (*fn_open)(int, int, int, unsigned, unsigned, unsigned);
typedef int (*fn_close)(int);
typedef int (*fn_output)(int, const void*);
typedef int (*fn_lastout)(int, uint64_t*);
typedef int (*fn_portstate)(int, void*);
typedef uint64_t (*fn_proctime)(void);

static fn_lastout aoLast;
static fn_portstate aoState;
static fn_proctime procTime;

static uint64_t now_us(void) { return procTime ? procTime() : 0; }

static void last_case(const char* id, const char* call, int handle, uint64_t t0, uint64_t t1) {
  uint64_t v = 0xdeadbeefdeadbeefULL;
  char extra[160];
  errno = 0;
  long r = aoLast(handle, &v);
  int e = errno;
  if (v == 0xdeadbeefdeadbeefULL)
    snprintf(extra, sizeof extra, "0x%08x value=untouched", (unsigned)r);
  else
    snprintf(extra, sizeof extra, "0x%08x value=%llu delta_to_before=%lld delta_to_after=%lld", (unsigned)r,
             (unsigned long long)v, (long long)(v - t0), (long long)(v - t1));
  probe_case(id, call, r, e, extra);
}

static void state_case(const char* id, const char* call, int handle) {
  unsigned char buf[64];
  char extra[160];
  memset(buf, 0x5a, sizeof buf);
  errno = 0;
  long r = aoState(handle, buf);
  int e = errno;
  int changed = 0;
  for (size_t b = 0; b < sizeof buf; ++b)
    if (buf[b] != 0x5a) changed++;
  snprintf(extra, sizeof extra, "0x%08x changed=%d first16=%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x",
           (unsigned)r, changed, buf[0], buf[1], buf[2], buf[3], buf[4], buf[5], buf[6], buf[7], buf[8], buf[9], buf[10],
           buf[11], buf[12], buf[13], buf[14], buf[15]);
  probe_case(id, call, r, e, extra);
}

int main(void) {
  signal(SIGALRM, probe_alarm);
  alarm(PROBE_MAX_S);
  char extra[64];
  probe_header();

  errno = 0;
  void* lib = dlopen("libSceAudioOut.sprx", RTLD_LAZY);
  probe_case("0", "load libSceAudioOut.sprx", lib ? 0 : -1, errno, lib ? "loaded" : dlerror());
  if (!lib) { probe_end(); return 0; }
  fn_init aoInit = (fn_init)dlsym(lib, "sceAudioOutInit");
  fn_open aoOpen = (fn_open)dlsym(lib, "sceAudioOutOpen");
  fn_close aoClose = (fn_close)dlsym(lib, "sceAudioOutClose");
  fn_output aoOutput = (fn_output)dlsym(lib, "sceAudioOutOutput");
  aoLast = (fn_lastout)dlsym(lib, "sceAudioOutGetLastOutputTime");
  aoState = (fn_portstate)dlsym(lib, "sceAudioOutGetPortState");
  procTime = (fn_proctime)dlsym(RTLD_DEFAULT, "sceKernelGetProcessTime");
  if (!aoInit || !aoOpen || !aoClose || !aoOutput || !aoLast || !aoState) {
    probe_case("0b", "dlsym of the audio out functions", -1, 0, "missing");
    probe_end();
    return 0;
  }
  probe_case("0c", "dlsym(sceKernelGetProcessTime)", procTime ? 0 : -1, 0, procTime ? "found" : "missing");

  errno = 0;
  long r = aoInit();
  snprintf(extra, sizeof extra, "0x%08x", (unsigned)r);
  probe_case("1", "sceAudioOutInit()", r, errno, extra);
  if (r != 0) { probe_end(); return 0; }   /* no further call without a successful init */

  errno = 0;
  long h = aoOpen(0xff, 0, 0, 1024, 48000, 0x1);
  snprintf(extra, sizeof extra, "0x%08x", (unsigned)h);
  probe_case("2", "sceAudioOutOpen(0xff, 0, 0, 1024, 48000, 0x1)", h, errno, extra);
  if (h <= 0) { probe_end(); return 0; }

  state_case("3", "sceAudioOutGetPortState(own port, &state)", (int)h);
  last_case("4", "sceAudioOutGetLastOutputTime(own port) before any output", (int)h, 0, 0);

  static short block[2048];   /* 1024 samples, stereo, all zero */
  memset(block, 0, sizeof block);
  uint64_t t0 = now_us();
  errno = 0;
  r = aoOutput((int)h, block);
  uint64_t t1 = now_us();
  snprintf(extra, sizeof extra, "0x%08x took_us=%llu", (unsigned)r, (unsigned long long)(t1 - t0));
  probe_case("5", "sceAudioOutOutput(own port, one silent block)", r, errno, extra);

  last_case("6", "sceAudioOutGetLastOutputTime(own port) after one output", (int)h, t0, t1);
  state_case("7", "sceAudioOutGetPortState(own port) after output", (int)h);

  errno = 0;
  long c = aoClose((int)h);
  snprintf(extra, sizeof extra, "0x%08x", (unsigned)c);
  probe_case("8", "sceAudioOutClose(own port)", c, errno, extra);

  last_case("9", "sceAudioOutGetLastOutputTime(closed handle)", (int)h, t0, t1);
  state_case("10", "sceAudioOutGetPortState(closed handle)", (int)h);
  last_case("11", "sceAudioOutGetLastOutputTime(handle -1)", -1, t0, t1);
  state_case("12", "sceAudioOutGetPortState(handle -1)", -1);

  probe_end();
  return 0;
}

Raw output:

PROBE	sceAudioOutGetLastOutputTime	fw=0x11600005	build=cacbea9945d6	pid=99	utc=2026-11-07T06:37:51Z
CASE	0	load libSceAudioOut.sprx	0	3	loaded
CASE	0c	dlsym(sceKernelGetProcessTime)	0	0	found
CASE	1	sceAudioOutInit()	0	0	0x00000000
CASE	2	sceAudioOutOpen(0xff, 0, 0, 1024, 48000, 0x1)	536870912	0	0x20000000
CASE	3	sceAudioOutGetPortState(own port, &state)	0	0	0x00000000 changed=15 first16=0000025affff05000000000000000000
CASE	4	sceAudioOutGetLastOutputTime(own port) before any output	0	0	0x00000000 value=0 delta_to_before=0 delta_to_after=0
CASE	5	sceAudioOutOutput(own port, one silent block)	1024	0	0x00000400 took_us=12
CASE	6	sceAudioOutGetLastOutputTime(own port) after one output	0	0	0x00000000 value=228641 delta_to_before=2 delta_to_after=-10
CASE	7	sceAudioOutGetPortState(own port) after output	0	0	0x00000000 changed=15 first16=0000025affff05000000000000000000
CASE	8	sceAudioOutClose(own port)	0	0	0x00000000
CASE	9	sceAudioOutGetLastOutputTime(closed handle)	-2144993279	0	0x80260001 value=untouched
CASE	10	sceAudioOutGetPortState(closed handle)	-2144993279	0	0x80260001 changed=0 first16=5a5a5a5a5a5a5a5a5a5a5a5a5a5a5a5a
CASE	11	sceAudioOutGetLastOutputTime(handle -1)	-2144993277	0	0x80260003 value=untouched
CASE	12	sceAudioOutGetPortState(handle -1)	-2144993277	0	0x80260003 changed=0 first16=5a5a5a5a5a5a5a5a5a5a5a5a5a5a5a5a
END	14

@DonRyuzaki

Copy link
Copy Markdown
Contributor

Independent Windows focused test of PR head 86ee758c55f406e0412c01f02e37512b7f31473d on pinned base 0bae53facde88e56d2859f4d39cece93c9aab761 (clean source; head and discussion rechecked). Windows / WinLibs GCC 15.2.0 UCRT / Release, two compiler jobs. Built audio_out_port_state_tests, libSceAudioOut.prx and dependencies. Registered audio_out_port_state passed three consecutive CTest runs (0.14, 0.11, 0.11 s), none skipped. The fixture opens a 16-bit stereo main port and checks channel 2, flag 0 and active state 0 before and after a 1024-frame silent output. Credit to @xXPBSXx for the PS5 payload probe, which supplied those expected values in cases 3 and 7. My Windows run checks the emulator fixture; it is not a second console measurement, and the other reported fields are not pinned here. Main advanced to 22ae9a397dd312338200117897086480580d78c8; I did not validate a merge with it. No full Windows suite or game test. AI-assisted: yes (Codex).

@JJenkx

JJenkx commented Nov 8, 2026

Copy link
Copy Markdown
Contributor

Windows check of head 86ee758c55, merged onto main 22ae9a397d (da217bae18, clean merge).

Setup: Windows 11 Enterprise 22621, WinLibs GCC 15.2 UCRT, Release. The hosted Windows check does not run these tests on pull requests.

  • audio_out_port_state passes in 3 of 3 runs, none skipped.

AI-assisted: yes.

@Ethan-Hainline

Copy link
Copy Markdown
Contributor

The red windows check on this head is not from this PR. Run 42527840442 failed on guest_standard_streams (Exit code 0xc0000409), which is the ungetc abort tracked in #17423; it was failing on main at that base for every PR.

main has since merged #17531 at 286b14d2, which removes the failing getdelim fixture. guest_standard_streams passed 3/3 here after that. Rebasing this branch onto current main and letting the Windows job rerun should turn it green; the focused audio_out_port_state run in the comment above already passes.

AI-assisted.

@gabichuuuuu

Copy link
Copy Markdown
Contributor

Windows check of head 86ee758c55, merged onto main 28237a8567 (clean merge, built together with other open PRs that touch different files).

Setup: Windows 11 x64, WinLibs GCC 15.2.0 (r7), Ninja, Release, BUILD_TESTING=ON, Python 3.15.

  • Tests built from this PR's test files: audio_out_port_state.
  • All of them pass in 3 of 3 runs.
  • No negative control: the PR changes only test files.

AI-assisted: yes.

@MarcZX10 MarcZX10 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewed — looks good

Nothing blocks this test addition; the observed behavior is consistent with the implementation.

What I ran

Reviewed head 86ee758c55f406e0412c01f02e37512b7f31473d. No commands or tests were run in this review.

Results

Check Result Note
Diff and changed files passed Both changed files read
Implementation context passed State query and port open paths read
Tests not run No checks executed

Findings

Blocking

None.

Non-blocking

None.

Not verified

Did not run the new test or build it. The manifest lists two reviewed files, and both full texts were read. files.json was unavailable through the reader, so excluded files are not verified. The PR description's console and CI reports were not independently confirmed.

To get this to a good state

Nothing is required.

@github-actions

github-actions Bot commented Nov 19, 2026 •

Copy link
Copy Markdown

Some comparisons could not be completed because a pull request conflicts with the base branch. Review these shared files manually before concluding that there is no overlap.

Pull request Shared files not compared
PR 17430 core/libs/prx/libSceAudioOut/CMakeLists.txt
PR 21034 core/libs/prx/libSceAudioOut/CMakeLists.txt
PR 22585 core/libs/prx/libSceAudioOut/CMakeLists.txt
PR 23239 core/libs/prx/libSceAudioOut/CMakeLists.txt
PR 24322 core/libs/prx/libSceAudioOut/CMakeLists.txt
PR 24917 core/libs/prx/libSceAudioOut/CMakeLists.txt

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants