xma: start the frame after a continuation at the next packet that has frames #96

Merged
tedin7 merged 1 commit from upstream-pr/96 into main 2026-11-25 00:15:52 +00:00
tedin7 commented 2026-11-24 00:26:45 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by tedin7 on 2026-11-24T00:26:45Z.


What

xma::next_frame now finds the frame after one that ends in a packet where no frame begins (header frames == 0) by following each packet's skip to the next packet that has frames, instead of returning the position inside that packet. Packets with frames == 0 and first_frame_bit == 0x7fff (a frame spans all of them) are stepped over the same way.

Why

When a frame crosses a continuation packet and ends in a later packet that holds only the tail of that frame plus padding, next_frame returned the bit right after the frame, inside the padding. read_frame then read a zero length there and the walk stopped, so every later frame of the stream was lost (audio cut off early). Only the "last frame of its own packet" and "ends exactly on a packet boundary" cases jumped to the next packet.

Tested

Linux x86_64 only, synthetic in-memory packets (no game data). The new test builds 4 packets: a frame crossing a full continuation packet and ending 64 bits into a packet with no frames, then a packet with one frame.

  • Before the fix: cargo test -j4 -p victory-formats --lib xma:: fails the new test (left: Some(32864), right: Some(49184)).
  • After the fix: cargo test -j4 -p victory-formats gives 18 passed, 0 failed, 3 ignored (the ignored ones need files outside the repo).
  • cargo clippy -j4 -p victory-formats --tests is clean.
  • cargo fmt --check already reports diffs in untouched code in this crate; I did not reformat it. My lines follow the surrounding wide-line style.

Not run: Windows runtime, the GPU, and any real XMA stream or reference decoder (the #[ignore] tests need files outside the repo). The packet layout in the test follows the header description in the module docs; I could not confirm against a real encoder how often it emits a tail-only packet.

<!-- greyfinch-sync:Marvisak/VIctory:issue:6571762043 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/96). Originally posted by [tedin7](https://github.com/tedin7) on 2026-11-24T00:26:45Z. --- **What** `xma::next_frame` now finds the frame after one that ends in a packet where no frame begins (header `frames == 0`) by following each packet's `skip` to the next packet that has frames, instead of returning the position inside that packet. Packets with `frames == 0` and `first_frame_bit == 0x7fff` (a frame spans all of them) are stepped over the same way. **Why** When a frame crosses a continuation packet and ends in a later packet that holds only the tail of that frame plus padding, `next_frame` returned the bit right after the frame, inside the padding. `read_frame` then read a zero length there and the walk stopped, so every later frame of the stream was lost (audio cut off early). Only the "last frame of its own packet" and "ends exactly on a packet boundary" cases jumped to the next packet. **Tested** Linux x86_64 only, synthetic in-memory packets (no game data). The new test builds 4 packets: a frame crossing a full continuation packet and ending 64 bits into a packet with no frames, then a packet with one frame. - Before the fix: `cargo test -j4 -p victory-formats --lib xma::` fails the new test (`left: Some(32864)`, `right: Some(49184)`). - After the fix: `cargo test -j4 -p victory-formats` gives 18 passed, 0 failed, 3 ignored (the ignored ones need files outside the repo). - `cargo clippy -j4 -p victory-formats --tests` is clean. - `cargo fmt --check` already reports diffs in untouched code in this crate; I did not reformat it. My lines follow the surrounding wide-line style. Not run: Windows runtime, the GPU, and any real XMA stream or reference decoder (the `#[ignore]` tests need files outside the repo). The packet layout in the test follows the header description in the module docs; I could not confirm against a real encoder how often it emits a tail-only packet.
DaviTostes commented 2026-11-24 06:54:52 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by DaviTostes on 2026-11-24T01:12:06Z.


Tested ba42db6: pass.

  • Tested on Arch Linux x86_64, rustc 1.98.1, cargo test -p victory-formats: 18 passed, 0 failed, 3 ignored, including the 1 test this PR adds.

No game data used.

<!-- greyfinch-sync:Marvisak/VIctory:comment:7118861306 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/96#issuecomment-7118861306). Originally posted by [DaviTostes](https://github.com/DaviTostes) on 2026-11-24T01:12:06Z. --- Tested `ba42db6`: **pass**. - Tested on **Arch Linux x86_64, rustc 1.98.1**, `cargo test -p victory-formats`: **18 passed, 0 failed, 3 ignored**, including the 1 test this PR adds. No game data used.
mercuryVM commented 2026-11-24 08:50:49 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by mercuryVM on 2026-11-24T08:50:49Z.

Review: APPROVED


Tested ba42db6 on Windows 11, RTX 5070, MSVC: cargo test --workspace --no-fail-fast passes (228 passed, 0 failed; older base), including the_frame_after_continuation_packets_starts_in_the_next_packet_with_frames.

  • The bug matches the format: a packet with frames == 0 holds only a continuation tail and padding, so no frame can start in it. Before, next_frame returned the bit right after the tail, inside the padding, and the walk then read a zero length and stopped the stream.
  • Stepping through skip until a packet with frames > 0 and starting at its first_frame_bit follows the packet layout. The loop is bounded, because packet() returns None past the data.
  • The two existing cases (the last frame of its own packet, and ending exactly on a packet boundary) behave as before.

No issues found.

AI-assisted (Claude Code).

<!-- greyfinch-sync:Marvisak/VIctory:review:6036187990 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/96#pullrequestreview-6036187990). Originally posted by [mercuryVM](https://github.com/mercuryVM) on 2026-11-24T08:50:49Z. **Review:** APPROVED --- Tested ba42db6 on Windows 11, RTX 5070, MSVC: `cargo test --workspace --no-fail-fast` passes (228 passed, 0 failed; older base), including `the_frame_after_continuation_packets_starts_in_the_next_packet_with_frames`. - The bug matches the format: a packet with `frames == 0` holds only a continuation tail and padding, so no frame can start in it. Before, `next_frame` returned the bit right after the tail, inside the padding, and the walk then read a zero length and stopped the stream. - Stepping through `skip` until a packet with `frames > 0` and starting at its `first_frame_bit` follows the packet layout. The loop is bounded, because `packet()` returns `None` past the data. - The two existing cases (the last frame of its own packet, and ending exactly on a packet boundary) behave as before. No issues found. AI-assisted (Claude Code).
upstream-sync closed this pull request 2026-11-25 01:02:39 +00:00
Marvisak commented 2026-11-25 01:07:44 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by Marvisak on 2026-11-25T00:24:09Z.


Automated triage for the maintainers.

Merge candidate. next_frame in crates/victory-formats/src/xma.rs looked for the next frame in a packet's padding when a frame ended partway through a packet whose header has frames == 0, so the frame walk stopped early. It now moves on via skip to the next packet that has frames and steps over frames == 0 continuation packets the same way; this follows from the header layout in the module docs (the count is of frames that begin in the packet), and the loop ends because packet() returns None past the data. The synthetic test checks the next-frame positions; no real stream was tested, as the PR says.

CI: no check runs on the head commit.


Generated by Claude Code

<!-- greyfinch-sync:Marvisak/VIctory:comment:7148471900 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/96#issuecomment-7148471900). Originally posted by [Marvisak](https://github.com/Marvisak) on 2026-11-25T00:24:09Z. --- <!-- victory-triage v1 head=ba42db643c15c1b7fb17ba40464dddda36c1db60 verdict=merge-candidate at=2026-11-25T00:18:46Z --> Automated triage for the maintainers. **Merge candidate.** `next_frame` in `crates/victory-formats/src/xma.rs` looked for the next frame in a packet's padding when a frame ended partway through a packet whose header has `frames == 0`, so the frame walk stopped early. It now moves on via `skip` to the next packet that has frames and steps over `frames == 0` continuation packets the same way; this follows from the header layout in the module docs (the count is of frames that begin in the packet), and the loop ends because `packet()` returns `None` past the data. The synthetic test checks the next-frame positions; no real stream was tested, as the PR says. CI: no check runs on the head commit. --- _Generated by [Claude Code](https://claude.ai/code)_
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!96
No description provided.