Files
AnyPS5/docs/dev/debt/libSceAjm.native.md
T
Dean 1bcaa14234 Merge pull request #8307 from hypermoist/fix/libs-console-results-part2
fix(libs): return what the firmware returns from 31 more calls it does not implement
2026-10-21 20:57:00 +13:00

14 KiB
Raw Blame History

libSceAjm.native technical debt

Unknown function info

  • sceAjmBatchGetLog, sceAjmInstanceAvailable (libSceAjm.native) - names and NIDs are present in the PS5 3.20 export inventory, but no credible prototypes were found. They are declared without parameters solely to resolve known imports; this is not an ABI claim.
  • sceAjmInstanceExtend, sceAjmInstanceSwitch (libSceAjm.native) - their signatures follow shadPS4 and SharpProspero, not measured on a console; these throwing declarations only resolve imports.
  • sceAjmInstanceCreate (libSceAjm.native) - a full 14-bit instance slot namespace returns 0x80930007 (OUT_OF_RESOURCES), as shadPS4's InstanceCreate does for its own instance pool (PS4). The 16384 slots per codec prefix are this runtime's existing ID layout, not a measured console capacity; the PS5 capacity and exhaustion result are unverified.
  • ATRAC9 vibration decoding (libSceAjm.native): channel configurations 6 (mono) and 7 (dual mono) use the pinned vgmstream decoder, including its 12/24/48 kHz profile limits. Synthetic fixtures cover interleaving, reset after malformed input, partial superframes and PCM16/PCM32/float output; console PCM rounding and physical haptic output are unverified. Ordinary channel configurations and discrete multichannel streams still use LibAtrac9. Decoder creation and decoding run under the existing AJM instance lock because the dependency rebuilds shared Huffman tables during initialization.
  • sceAjmDecWVorbisCreateHeaderPacket, sceAjmDecWVorbisCreateSetupPacket (libSceAjmWVorbis, implemented in libSceAjm.native) - unknown signatures
  • sceAjmBatchJobGetInfo (libSceAjm.native) - writes the result and format sideband of a run job without buffers with the SIDEBAND_FORMAT flag (0x400000000000), as KytyPS5 does, not confirmed on a PS5 title; the format reports bitrate 0 for ATRAC9 as in KytyPS5, while shadPS4 derives it from the superframe size; before the instance is initialized it returns the not-initialized result (1) and no format, like the other run jobs here, while KytyPS5 returns result 0 with the format of the uninitialized decoder
  • sceAjmDecMp3ParseFrame (libSceAjm.native) - signature, result layout and rate tables taken from the shadPS4 reimplementation of the PS4 library, not confirmed on a PS5 title: the layer field is not checked and MPEG-2.5 stops at 64 kbps; the original file length (parse_ofl) layout (Xing/Info + LAME tag, VBRI, Fraunhofer 0xB4 block with its CRC, encoder delay = samples per frame + LAME delay + 529) also comes from shadPS4 only, and the Fraunhofer block has no other public description
  • sceAjmBatchJobGetCodecInfo, sceAjmBatchJobGetGaplessDecode (libSceAjm.native) - the RUN_GET_CODEC_INFO flag (0x800), the ATRAC9 codec info layout and its next frame size are taken from the shadPS4 and RPCSX reimplementations, not confirmed on a PS5 title; a run job without buffers returns result 0, as in shadPS4. The gapless sideband reports the total and skip counts the title set and does not count them down: RPCSX does the same, shadPS4 counts them down and BryKytyPS5 returns its current counts
  • AJM Opus decoder (libSceAjm.native, codec 24) - the initialize parameter layout and little-endian u16 packet byte count come from The Smurfs Dreams (2, 48000, 0) and Lost Soul Aside (4, 48000, 1). The third word is interpreted as the mapping family, as in KytyPS5's initialize structure. Family 1 uses the conventional stream counts, coupled counts and channel map from libopus 1.5.2's surround layout, passed to FFmpeg through an RFC 7845 section 5.1 header with zero pre-skip and gain; gapless skipping remains controlled by AJM sideband parameters. FFmpeg returns PCM in its native speaker order. The implicit stream layout, PCM channel order and invalid family-0 channel count result are not verified on a console. NHL 27 (PPSA34063) passes 1, 48000, 255. Family 255 with one channel is decoded as one mono stream, the same as family 0; this is assumed, since the stream count, coupled stream count and channel mapping that a family-255 Opus header carries (RFC 7845 section 5.1.1) are not passed. Only 48000 Hz, mapping families 0 and 1, and family 255 with one channel are implemented; other rates and families, and family 255 with more channels, throw
  • AJM codec 23 (libSceAjm.native) - taken as interleaved s16 PCM that only passes through the resampler, from Broken Sword - Shadow of the Templars: Reforged (PPSA21480); no source names a codec 23 (shadPS4's PS4 header ends its codec list with Max = 23) and the name CODEC_PCM is ours. The title decodes its Ogg Opus and Vorbis audio itself and, for every block, initializes the instance (flags 0x1002) with 0, 2, 44100, sets the ratio 0.91875 (44100/48000) and decodes 235 stereo frames into a 256-frame output. The 12 initialize bytes are taken as input format (0 is s16, other values throw), channel count and sample rate; the rate is only reported in the format sideband; other sizes throw; zero or more than 8 channels or a zero rate return the invalid-parameter result as for Opus, not verified. A run consumes its whole input and emits every output frame whose position (output index × ratio) is below the input frame count, with the 4-point Catmull-Rom of the other codecs' resampler and the first and last input frames repeated past the edges, so each run restarts at position 0; totalDecodedSamples counts input frames; s32 and float outputs are accepted although only s16 was seen. Throwing because the console's behaviour is unknown: a run after a resampled run without an initialize or context clear in between (whether the console carries the resampler position across runs), a ratio change per sample, gapless counts, an empty input or one that is not a whole number of frames, an output that cannot hold the resampled input, run flags other than SIDEBAND_STREAM and initialization through sceAjmBatchJobControl
  • sceAjmBatchJobSetResampleParametersEx (libSceAjm.native) - the (info, instance, float ratio_start, float ratio_change_per_sample, flags, result) signature is inferred from the name and from sceAjmBatchJobSetResampleParameters; with a zero change per sample it sets the ratio as sceAjmBatchJobSetResampleParameters does (Watch Dogs: Legion, PPSA01500, calls it so). How a non-zero change ramps the ratio is not confirmed on a console (no source: KytyPS5 ignores it, prosper stubs it, the PS5 firmware does not export the batch builders to a payload): it is assumed to be added to the ratio after each emitted output frame, clamped at zero, and kept across batches. RIDE 4 (PPSA01599) passes one call with a change of 4.6e-7, so the exact rule matters little there.
  • sceAjmBatchJobControl (libSceAjm.native) - RESET (bit 13), INITIALIZE (bit 14) and the sideband input order (gapless decode, then initialize parameters) come from shadPS4 (PS4); other flags throw
  • sceAjmBatchJobControl (libSceAjm.native) - RESET is assumed to clear the context as sceAjmBatchJobClearContext does
  • sceAjmBatchJobControl (libSceAjm.native) - initialize parameters are 8 bytes for ATRAC9 and M4AAC, 12 for Opus and none for MP3, as one title passes them; other codecs and sizes, and an output other than the 8-byte result, throw
  • sceAjmBatchJobControl (libSceAjm.native) - SIDEBAND_GAPLESS_DECODE with RESET overwrites both counts as in RPCSX; shadPS4 ignores a zero count when the other is nonzero. Without RESET they differ, so it throws
  • sceAjmBatchJobSetResampleParameters, sceAjmBatchJobGetResampleInfo (libSceAjm) - the ratio is taken as decoded samples per output sample and num_samples as the decoded samples the resampler holds, both inferred from FMOD (Hades II); the console's interpolation is unknown, a 4-point Catmull-Rom is used. The flags argument is ignored, as in shadPS4 and Kyty

Functional

  • AJM batch contexts (libSceAjm.native): start, wait and cancel reject context IDs not allocated by initialization; batches belong to their creating context, as in shadPS4. This is not verified on PS5. Finalization still does not invalidate contexts or release their instances and outstanding batches; jobs execute synchronously and cancellation does not interrupt them.

  • sceAjmDecMp3ParseFrame (libSceAjm.native) throws when the original file length is requested (parse_ofl non-zero) for a layer other than III, for a CRC-protected frame, or for a VBRI header outside MPEG-1 stereo: shadPS4 looks for the tag after the CRC and after the side information, while LAME and FFmpeg place it without the CRC and VBRI always at byte 36.

  • ATRAC9 gapless segments (libSceAjm.native) - a run job stops after the gapless total of output samples counted from the start of the segment, leaving the rest of its input unconsumed, and the next run starts the next segment with the decoder as it is and without a second skip. FMOD in PPSA29141 sets a total shorter than a sound's frames and reads the frames after it on later runs; with the output held at the total its stream reader waited for them forever and the last buffer repeated. The console's handling of the frames after the total is not documented; a reset (SetGaplessDecode with the reset flag, ClearContext, initialization) starts a new segment. An ATRAC9 run job without RUN_MULTIPLE_FRAMES decodes its whole input as one with it: FMOD in PPSA29141 puts two run jobs in one batch with the second's input right after the whole of the first's. Whether the console stops after one frame there is not verified; MP3 and Opus run jobs still stop after one frame

  • AJM M4AAC decoder (libSceAjm.native, codec 2) - Ghost of Yotei (PPSA26344) initializes it through sceAjmBatchJobControl. The initialize parameters (u32 config type, 1 ADTS or 2 raw, then u32 sampling frequency index), instance flags (channels in bits 3-6, ENABLE_SBR_DECODE bit 32, ENABLE_NONDELAY_OUTPUT bit 33, surround interleave order bits 34-35), {heaac, reserved} codec info and decoder error result (CODEC_ERROR | FATAL) follow shadPS4 (PS4, fdk-aac) and are unverified on PS5; decoding uses FFmpeg's AAC decoder. Without ENABLE_NONDELAY_OUTPUT, the first two frames after initialization or reset are consumed without output. Raw input takes its channel configuration from the instance (0 means stereo) and is decoded as one access unit per run job. The format reports the last frame's bitrate. Invalid config type or raw sampling frequency index above 11 returns invalid-parameter result 4. The implementation throws for ADTS without a frame header, profiles other than AAC LC, multiple raw data blocks per ADTS frame, unsupported channel configurations, more channels than the instance supports, HE-AAC without ENABLE_SBR_DECODE, raw input with RUN_MULTIPLE_FRAMES, output room smaller than the previous frame length, and unknown codec flags.

  • AJM, APR and NGS2 state is allocated with new and never freed on purpose: title threads still call into these libraries while std::exit runs static destructors, so ordinary statics would be destroyed under them. Keep them leaked; guest_ajm_teardown covers the AJM case on Unix.

  • AJM Opus mapping family 255 with several channels (libSceAjm.native): the initialization words carry no stream count or channel mapping, so the decoder opens on the first packet. It counts the self-delimited streams of that multistream packet (RFC 6716 appendix B) and takes each stream's stereo flag from its TOC byte as coupled, then decodes with an identity channel mapping. A packet whose streams do not add up to the channel count throws. The layout is inferred, not read from the console; unverified on hardware.