Formats: treat XMA2 PacketSkipCount 0xff as end-of-stream #2503

Closed
VastyViz wants to merge 1 commit from upstream-pr/2505 into main
VastyViz commented 2026-11-25 14:58:38 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by VastyViz on 2026-11-25T14:58:38Z.


Summary

Per the XMA2 packet header specification, the 8-bit PacketSkipCount field uses 0xff (255) as an end-of-stream sentinel ("no further packets belong to this stream"), while 0..=0xfe give the number of interleaved packets of other streams to skip.

Previously, victory-formats/src/xma.rs always advanced by 1 + skip:

  • next_frame: after the last frame of a packet (or while stepping past zero-frame continuation packets), a packet with skip == 0xff jumped 256 packets forward instead of returning None. Because an XMA input buffer can hold up to 4095 packets, any multi-stream or banked buffer with at least 257 packets past the stream's last packet would continue walking into unrelated stream data instead of ending the buffer and flushing/switching in victory-hle's audio decoder.
  • Cursor::bit: a frame whose bit length ran past a packet with skip == 0xff jumped 256 packets forward and spliced bits from unrelated packets instead of failing to read.

Changes

  • Added END_OF_STREAM: u32 = 0xff and a shared next_packet(index, skip) -> Option<usize> helper in crates/victory-formats/src/xma.rs that returns None on skip == 0xff (and uses checked arithmetic for packet and bit offsets).
  • Updated Cursor::bit and both packet advances in next_frame to route through next_packet.
  • Added three synthetic unit tests in crates/victory-formats/src/xma.rs:
    • skip_count_ff_ends_the_stream_instead_of_jumping_255_packets (direct stop on the ending packet and stop inside next_frame's zero-frame packet walk when valid packets exist 256 packets ahead).
    • skip_count_ff_stops_cross_packet_frame_reads (frame crossing a 0xff packet returns None instead of splicing bits from 256 packets ahead).
    • skip_count_fe_still_skips_254_packets (negative control verifying the largest non-sentinel skip 0xfe still advances 254 packets for both next_frame and cross-packet frame reads).

Verification

  • cargo test -p victory-formats --locked (41 passed, 0 failed)
  • cargo test -p victory-hle --locked -- audio (8 passed, 0 failed)
  • cargo clippy --workspace --all-targets --locked -- -D warnings (0 warnings)
  • cargo clippy --workspace --all-targets --all-features --locked -- -D warnings (0 warnings)
  • cargo xtask policy (asset policy: 182 files ok)
  • git diff --check (clean)
<!-- greyfinch-sync:Marvisak/VIctory:issue:6607370745 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/2505). Originally posted by [VastyViz](https://github.com/VastyViz) on 2026-11-25T14:58:38Z. --- ## Summary Per the XMA2 packet header specification, the 8-bit `PacketSkipCount` field uses `0xff` (`255`) as an **end-of-stream sentinel** ("no further packets belong to this stream"), while `0..=0xfe` give the number of interleaved packets of other streams to skip. Previously, `victory-formats/src/xma.rs` always advanced by `1 + skip`: - **`next_frame`**: after the last frame of a packet (or while stepping past zero-frame continuation packets), a packet with `skip == 0xff` jumped 256 packets forward instead of returning `None`. Because an XMA input buffer can hold up to 4095 packets, any multi-stream or banked buffer with at least 257 packets past the stream's last packet would continue walking into unrelated stream data instead of ending the buffer and flushing/switching in `victory-hle`'s audio decoder. - **`Cursor::bit`**: a frame whose bit length ran past a packet with `skip == 0xff` jumped 256 packets forward and spliced bits from unrelated packets instead of failing to read. ## Changes - Added `END_OF_STREAM: u32 = 0xff` and a shared `next_packet(index, skip) -> Option<usize>` helper in `crates/victory-formats/src/xma.rs` that returns `None` on `skip == 0xff` (and uses checked arithmetic for packet and bit offsets). - Updated `Cursor::bit` and both packet advances in `next_frame` to route through `next_packet`. - Added three synthetic unit tests in `crates/victory-formats/src/xma.rs`: - `skip_count_ff_ends_the_stream_instead_of_jumping_255_packets` (direct stop on the ending packet and stop inside `next_frame`'s zero-frame packet walk when valid packets exist 256 packets ahead). - `skip_count_ff_stops_cross_packet_frame_reads` (frame crossing a `0xff` packet returns `None` instead of splicing bits from 256 packets ahead). - `skip_count_fe_still_skips_254_packets` (negative control verifying the largest non-sentinel skip `0xfe` still advances 254 packets for both `next_frame` and cross-packet frame reads). ## Verification - `cargo test -p victory-formats --locked` (41 passed, 0 failed) - `cargo test -p victory-hle --locked -- audio` (8 passed, 0 failed) - `cargo clippy --workspace --all-targets --locked -- -D warnings` (0 warnings) - `cargo clippy --workspace --all-targets --all-features --locked -- -D warnings` (0 warnings) - `cargo xtask policy` (`asset policy: 182 files ok`) - `git diff --check` (clean)
Marvisak commented 2026-11-25 16:09:31 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by Marvisak on 2026-11-25T15:56:58Z.


Automated triage for the maintainers.

The change in crates/victory-formats/src/xma.rs (next_packet, used by Cursor::bit and next_frame) is cleanly done and well tested, but it changes how XMA streams are walked on the strength of "per the XMA2 packet header specification" with no reference anyone can check. Please point to public evidence that a skip count of 0xff ends the stream rather than meaning a 255-packet skip, for example FFmpeg's or another public decoder's handling, or a stream from the title where a 0xff packet is followed by unrelated data. Note that sources from the console's development kit cannot be cited or copied here (docs/asset-policy.md). With such a reference this would be a good candidate. CI (check) is passing.


Generated by Claude Code

<!-- greyfinch-sync:Marvisak/VIctory:comment:7167456309 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/2505#issuecomment-7167456309). Originally posted by [Marvisak](https://github.com/Marvisak) on 2026-11-25T15:56:58Z. --- <!-- victory-triage v1 head=caaddc00f7ba8cfa45fab0afe11184820716109b verdict=needs-work at=2026-11-25T15:56:35Z --> Automated triage for the maintainers. The change in `crates/victory-formats/src/xma.rs` (`next_packet`, used by `Cursor::bit` and `next_frame`) is cleanly done and well tested, but it changes how XMA streams are walked on the strength of "per the XMA2 packet header specification" with no reference anyone can check. Please point to public evidence that a skip count of `0xff` ends the stream rather than meaning a 255-packet skip, for example FFmpeg's or another public decoder's handling, or a stream from the title where a `0xff` packet is followed by unrelated data. Note that sources from the console's development kit cannot be cited or copied here (docs/asset-policy.md). With such a reference this would be a good candidate. CI (`check`) is passing. --- _Generated by [Claude Code](https://claude.ai/code)_
upstream-sync closed this pull request 2026-11-25 18:02:07 +00:00
VastyViz commented 2026-11-25 18:02:38 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by VastyViz on 2026-11-25T17:09:01Z.


Closing this PR after double-checking public references and the title's XMA2 streams:

  • Public decoders / headers: Neither FFmpeg (libavcodec/wmaprodec.c, libavcodec/xma_parser.c), hcs64's xma_parse, upstream Xenia (xma_context.cc), nor the public June 2010 DirectX SDK xma2defs.h (GetXmaFrameBitPosition / GetLastXmaFrameBitPosition) treat PacketSkipCount == 0xff as an end-of-stream sentinel after decoding a packet's frames — all advance by 1 + skip and stop on buffer bounds. (vgmstream's coding_utils.c and xenia-canary's Decode() handle 0xff differently as a full-packet skip to the next sequential packet rather than decoding and terminating.)
  • Title streams: Checking the title's XMA2 streams locally, all packets (including final packets) have skip == 0.

Without a verifiable public reference or an affected stream from the title, changing the packet-walking semantics isn't justified. Thanks for the triage review!

<!-- greyfinch-sync:Marvisak/VIctory:comment:7169079140 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/2505#issuecomment-7169079140). Originally posted by [VastyViz](https://github.com/VastyViz) on 2026-11-25T17:09:01Z. --- Closing this PR after double-checking public references and the title's XMA2 streams: - **Public decoders / headers**: Neither FFmpeg (`libavcodec/wmaprodec.c`, `libavcodec/xma_parser.c`), `hcs64`'s `xma_parse`, upstream Xenia (`xma_context.cc`), nor the public June 2010 DirectX SDK `xma2defs.h` (`GetXmaFrameBitPosition` / `GetLastXmaFrameBitPosition`) treat `PacketSkipCount == 0xff` as an end-of-stream sentinel after decoding a packet's frames — all advance by `1 + skip` and stop on buffer bounds. (`vgmstream`'s `coding_utils.c` and `xenia-canary`'s `Decode()` handle `0xff` differently as a full-packet skip to the next sequential packet rather than decoding and terminating.) - **Title streams**: Checking the title's XMA2 streams locally, all packets (including final packets) have `skip == 0`. Without a verifiable public reference or an affected stream from the title, changing the packet-walking semantics isn't justified. Thanks for the triage review!

Pull request closed

Sign in to join this conversation.
No reviewers
No labels
No milestone
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Reference
Marvisak/VIctory!2503
No description provided.