Opus: prefer length-prefixed framing, fix 6.1 mapping, harden MFT (#327) #503

Open
github-bot wants to merge 1 commit from github-bot/gh-503 into main AGit
Owner

@⁠Grimkaaah on GitHub · 2026-11-24 01:03 UTC · original
Grimkaaah:fix/327-opus-framing-mapping-mft → main · +55 −12 · 1 files · 1 commits · open

Summary

  • Prefer length-prefixed Opus packets whenever try_length_prefixed_block succeeds, so an exact-fit [u16 LE len][pkt] is not misread as one raw RFC 6716 packet whose TOC is the length prefix (#327).
  • Fix Vorbis/RFC 7845 6.1 mapping to (streams=5, coupled=2) instead of (4, 3).
  • MftDecoder::configure_output keeps the configured channel count; drain_output caps MF_E_TRANSFORM_STREAM_CHANGE reconfigs at 4.

Fixes #327

Test plan

  • cargo test -p xcl --lib hle::opus:: (15 passed, including new framing + 6.1 mapping tests)
**@⁠Grimkaaah** on GitHub · 2026-11-24 01:03 UTC · [original](https://github.com/xcl-dev/xcl/pull/503) `Grimkaaah:fix/327-opus-framing-mapping-mft` → `main` · +55 −12 · 1 files · 1 commits · open ## Summary - Prefer length-prefixed Opus packets whenever `try_length_prefixed_block` succeeds, so an exact-fit `[u16 LE len][pkt]` is not misread as one raw RFC 6716 packet whose TOC is the length prefix (#327). - Fix Vorbis/RFC 7845 **6.1** mapping to `(streams=5, coupled=2)` instead of `(4, 3)`. - `MftDecoder::configure_output` keeps the configured channel count; `drain_output` caps `MF_E_TRANSFORM_STREAM_CHANGE` reconfigs at 4. Fixes #327 ## Test plan - [x] `cargo test -p xcl --lib hle::opus::` (15 passed, including new framing + 6.1 mapping tests)
Prefer exact-fit [u16 len][pkt] over a raw TOC lookalike; use RFC 7845 6.1 stream counts (5/2); keep MFT output channel count and cap STREAM_CHANGE retries.

Co-authored-by: Cursor <[email protected]>
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 04:23:46 +00:00
Author
Owner

@⁠H0UNDZER0 on GitHub · 2026-11-24 02:40 UTC · original

Tested on an RTX 5080, release build: pass, 679 passed, 0 failed, with Windows' own Opus decoder.

  • Commit 78f55101c6e97f58ac30782d4bfebc76c4a2bc28, this PR's head as is (on its base 7ebf1b8), release build.
  • NVIDIA GeForce RTX 5080 16 GB, driver 621.24 (32.0.16.2124), 32-lane waves; Ryzen 7 9700X; Windows 11 Pro 24H2 (26100.9711); Rust 1.100.0 MSVC; DXC 1.9.2602.17 (Windows SDK 10.0.26100.0). No XCL_* variables set.
  • cargo build --release --workspace --locked: OK, the same single fetch_update warning as main.
  • cargo test --workspace --release --no-fail-fast --locked -- --test-threads=4, run twice (the second with --show-output): 679 passed, 0 failed, 41 ignored both times. The base 7ebf1b8 gives 677 / 0 / 41 here: the difference is the 2 new tests, length_prefixed_single_packet_preferred_over_raw_toc_lookalike and vorbis_mapping_6_1_matches_rfc7845, which pass with the other 13 opus tests.
  • SKIPPED: the usual 2, gpu_geometry_wave32_prefix_count_over_a_mask and gpu_wave32_program_in_wave64_hardware (no wave64).
  • The test title (e2e) checks its XAudio2 voices here (an audio device is present): its Opus voice decodes through MSOpusDecoder (Media Foundation), and the title ends with failures: 0.

Not tested

  • Game audio (XCL_SAMPLE_AWC not set), and a 6.1 stream through the Media Foundation decoder.
  • This PR merged onto a newer main. At the time of the run that was 9ce2070; git merge-tree showed no conflict.
  • Debug build, retail titles, scripts/smoke.ps1.

AI use: Claude Code (Claude Opus 5.5, Claude Fable 5.2)

**@⁠H0UNDZER0** on GitHub · 2026-11-24 02:40 UTC · [original](https://github.com/xcl-dev/xcl/pull/503#issuecomment-7120375449) **Tested** on an RTX 5080, release build: **pass**, 679 passed, 0 failed, with Windows' own Opus decoder. - Commit `78f55101c6e97f58ac30782d4bfebc76c4a2bc28`, this PR's head as is (on its base `7ebf1b8`), release build. - NVIDIA GeForce RTX 5080 16 GB, driver 621.24 (32.0.16.2124), 32-lane waves; Ryzen 7 9700X; Windows 11 Pro 24H2 (26100.9711); Rust 1.100.0 MSVC; DXC 1.9.2602.17 (Windows SDK 10.0.26100.0). No `XCL_*` variables set. - `cargo build --release --workspace --locked`: OK, the same single `fetch_update` warning as `main`. - `cargo test --workspace --release --no-fail-fast --locked -- --test-threads=4`, run twice (the second with `--show-output`): **679 passed, 0 failed, 41 ignored** both times. The base `7ebf1b8` gives 677 / 0 / 41 here: the difference is the 2 new tests, `length_prefixed_single_packet_preferred_over_raw_toc_lookalike` and `vorbis_mapping_6_1_matches_rfc7845`, which pass with the other 13 `opus` tests. - `SKIPPED`: the usual 2, `gpu_geometry_wave32_prefix_count_over_a_mask` and `gpu_wave32_program_in_wave64_hardware` (no wave64). - The test title (`e2e`) checks its XAudio2 voices here (an audio device is present): its Opus voice decodes through `MSOpusDecoder` (Media Foundation), and the title ends with `failures: 0`. **Not tested** - Game audio (`XCL_SAMPLE_AWC` not set), and a 6.1 stream through the Media Foundation decoder. - This PR merged onto a newer `main`. At the time of the run that was `9ce2070`; `git merge-tree` showed no conflict. - Debug build, retail titles, `scripts/smoke.ps1`. **AI use:** Claude Code (Claude Opus 5.5, Claude Fable 5.2)
Author
Owner

@⁠MesshM on GitHub · 2026-11-24 04:14 UTC · original

Test run and review of 78f55101c6e97f58ac30782d4bfebc76c4a2bc28 on AMD RDNA4. I merged it onto current main f4ce27c locally (clean merge) and tested that tree.

Tested

  • AMD Radeon RX 9060 XT 16 GB (RDNA4, native wave64), driver 32.0.32029.2010; Ryzen 7 5700X, 64 GB RAM, Windows 11 Pro build 26200, Rust 1.100.0 stable-x86_64-pc-windows-msvc, debug
  • cargo build --workspace + cargo test --workspace -- --test-threads=4 on the merge: 703 passed, 0 failed, 41 ignored, exit code 0; 0 SKIPPED; the opus tests pass, including length_prefixed_single_packet_preferred_over_raw_toc_lookalike and vorbis_mapping_6_1_matches_rfc7845.

Review: the 6.1 mapping change looks wrong to me (the same change as #506, where I left the details). The new comment says "RFC 7845 / libopus 6.1: 5 streams (2 coupled + 3 mono)". libopus's table (src/opus_multistream_encoder.c, vorbis_mappings[8], current xiph/opus master) has for 7 channels {4, 3, {0, 4, 1, 2, 3, 5, 6}}, i.e. 4 streams, 3 coupled, which is what main has now. RFC 7845 leaves the counts to the encoder for family 1, and the OpusHead has to declare the counts the packets were encoded with, so without a 6.1 sample from a title showing 5 / 2 I would keep 4 / 3 and drop vorbis_mapping_6_1_matches_rfc7845 (it pins the new value). This PR and #506 also overlap on that line.

The rest (preferring a length-prefixed single packet over a raw TOC look-alike, and the hardening) is separate from the mapping; splitting it out would let it land on its own, as CONTRIBUTING asks (one change per PR).

Not tested: no Opus stream from a title (I have no game data); release build.

Run and review by Claude Code (Claude Opus 5.5) on this machine; the libopus table was read from its repository.

**@⁠MesshM** on GitHub · 2026-11-24 04:14 UTC · [original](https://github.com/xcl-dev/xcl/pull/503#issuecomment-7121840526) Test run and review of `78f55101c6e97f58ac30782d4bfebc76c4a2bc28` on AMD RDNA4. I merged it onto current `main` `f4ce27c` locally (clean merge) and tested that tree. **Tested** - AMD Radeon RX 9060 XT 16 GB (RDNA4, native wave64), driver 32.0.32029.2010; Ryzen 7 5700X, 64 GB RAM, Windows 11 Pro build 26200, Rust 1.100.0 `stable-x86_64-pc-windows-msvc`, debug - `cargo build --workspace` + `cargo test --workspace -- --test-threads=4` on the merge: **703 passed, 0 failed, 41 ignored**, exit code 0; 0 `SKIPPED`; the `opus` tests pass, including `length_prefixed_single_packet_preferred_over_raw_toc_lookalike` and `vorbis_mapping_6_1_matches_rfc7845`. **Review: the 6.1 mapping change looks wrong to me** (the same change as #506, where I left the details). The new comment says "RFC 7845 / libopus 6.1: 5 streams (2 coupled + 3 mono)". libopus's table (`src/opus_multistream_encoder.c`, `vorbis_mappings[8]`, current `xiph/opus` master) has for 7 channels `{4, 3, {0, 4, 1, 2, 3, 5, 6}}`, i.e. **4 streams, 3 coupled**, which is what `main` has now. RFC 7845 leaves the counts to the encoder for family 1, and the `OpusHead` has to declare the counts the packets were encoded with, so without a 6.1 sample from a title showing 5 / 2 I would keep 4 / 3 and drop `vorbis_mapping_6_1_matches_rfc7845` (it pins the new value). This PR and #506 also overlap on that line. The rest (preferring a length-prefixed single packet over a raw TOC look-alike, and the hardening) is separate from the mapping; splitting it out would let it land on its own, as CONTRIBUTING asks (one change per PR). **Not tested:** no Opus stream from a title (I have no game data); release build. Run and review by Claude Code (Claude Opus 5.5) on this machine; the libopus table was read from its repository.
Author
Owner

@⁠mastrr9 on GitHub · 2026-11-24 05:05 UTC · original

Independent NVIDIA RTX 5080 build/test run and code review at head 78f55101c6e97f58ac30782d4bfebc76c4a2bc28 (fixing our #327 report).

Code Review

  • Cleanly addresses all three items from #327:
    1. Prefers exact-fit [u16 len][pkt] framing ahead of raw TOC lookalikes.
    2. Fixes 6.1 Vorbis channel mapping (vorbis_mapping(7) => (5, 2) matching RFC 7845).
    3. Filters MftDecoder::configure_output by ch == self.channels and bounds MF_E_TRANSFORM_STREAM_CHANGE retries with MAX_STREAM_CHANGES = 4.

Tested

  • Environment: NVIDIA GeForce RTX 5080 (16 GB, driver 617.42 / 32.0.16.1742), Windows 11 Pro 25H2 (26200.9974), rustc 1.100.0 (0ef1bc386 2026-11-09), debug build.
  • Command: cargo build --workspace && cargo test --workspace -- --test-threads=4
  • Result: 679 passed, 0 failed, 41 ignored (0 new warnings).
  • PR-specific tests (all ok):
    • hle::opus::tests::length_prefixed_single_packet_preferred_over_raw_toc_lookalike
    • hle::opus::tests::vorbis_mapping_6_1_matches_rfc7845
    • Plus 13/13 existing hle::opus::tests::* tests.
  • SKIPPED (4):
    • gpu::recomp::tests::gpu_geometry_wave32_prefix_count_over_a_mask (no wave64)
    • gpu::recomp::tests::gpu_wave32_program_in_wave64_hardware (no wave64)
    • test_title_draws_with_a_root_signature_under_the_debug_layer (no d3d12SDKLayers.dll)
    • uploads_start_from_each_subresources_state (no D3D12 debug layer (0x887A002D))

Not tested

  • D3D12 debug layer, AMD/wave64 hardware, and live MFT STREAM_CHANGE / retail audio streams.

AI use: Antigravity (Gemini 4 Neon) performed the code review, ran the RTX 5080 workspace tests, and drafted this comment.

**@⁠mastrr9** on GitHub · 2026-11-24 05:05 UTC · [original](https://github.com/xcl-dev/xcl/pull/503#issuecomment-7122621238) Independent NVIDIA RTX 5080 build/test run and code review at head `78f55101c6e97f58ac30782d4bfebc76c4a2bc28` (fixing our `#327` report). ### Code Review - Cleanly addresses all three items from `#327`: 1. Prefers exact-fit `[u16 len][pkt]` framing ahead of raw TOC lookalikes. 2. Fixes 6.1 Vorbis channel mapping (`vorbis_mapping(7) => (5, 2)` matching RFC 7845). 3. Filters `MftDecoder::configure_output` by `ch == self.channels` and bounds `MF_E_TRANSFORM_STREAM_CHANGE` retries with `MAX_STREAM_CHANGES = 4`. ### Tested - **Environment:** NVIDIA GeForce RTX 5080 (16 GB, driver `617.42` / `32.0.16.1742`), Windows 11 Pro 25H2 (`26200.9974`), `rustc 1.100.0 (0ef1bc386 2026-11-09)`, debug build. - **Command:** `cargo build --workspace && cargo test --workspace -- --test-threads=4` - **Result:** **679 passed, 0 failed, 41 ignored** (0 new warnings). - **PR-specific tests (all `ok`):** - `hle::opus::tests::length_prefixed_single_packet_preferred_over_raw_toc_lookalike` - `hle::opus::tests::vorbis_mapping_6_1_matches_rfc7845` - Plus 13/13 existing `hle::opus::tests::*` tests. - **SKIPPED (4):** - `gpu::recomp::tests::gpu_geometry_wave32_prefix_count_over_a_mask` (`no wave64`) - `gpu::recomp::tests::gpu_wave32_program_in_wave64_hardware` (`no wave64`) - `test_title_draws_with_a_root_signature_under_the_debug_layer` (`no d3d12SDKLayers.dll`) - `uploads_start_from_each_subresources_state` (`no D3D12 debug layer (0x887A002D)`) ### Not tested - D3D12 debug layer, AMD/wave64 hardware, and live MFT `STREAM_CHANGE` / retail audio streams. **AI use:** Antigravity (Gemini 4 Neon) performed the code review, ran the RTX 5080 workspace tests, and drafted this comment.
Author
Owner

@⁠wilu222 on GitHub · 2026-11-24 13:53 UTC · original · edited 2026-11-25 02:48 UTC

Retail-title regression runs for 78f55101c6e97f58ac30782d4bfebc76c4a2bc28 (this PR's head as is, on its base 7ebf1b8), since the PR has none yet.

Tested

  • NVIDIA GeForce RTX 5070 (driver 32.0.16.1742, 32-lane waves), AMD Ryzen 7 5700X, 32 GB, Windows 10 Home 19045, Rust 1.100.0 MSVC, release builds.
  • cargo test -p xcl --lib opus on the head: 17 passed, 0 failed.
  • Retail 1.0.2.1, XCL_NETWORK=0, scripts/smoke.ps1 -Seconds 120, no input: the two blocks below. No crash or device removal; frames and commit within the check's limits.
  • With scripted presses (XCL_PRESS_A_AT=30,45,60), which start the world load and, about 75 s later, the opening cutscene's Opus audio:
    • this PR merged onto main 47efa2e (clean merge, local only): 3,095 Opus packets decoded, 0 errors, non-zero samples. The run then ended at 107 s in the known xg::copy_from access violation (#662, fixed by #684), not in Opus code.
    • this PR's head, twice: both runs were still on the loading screen at 120 s and decoded one Opus packet. The base 7ebf1b8 alone reached the cutscene at about 112 s. The runs are identical up to 100 s (the same 18,902 DirectStorage requests by 30 s, then waiting). The PR runs reach the same later milestone about 8 s behind the base, so the cut-off falls before the cutscene. The PR's code decoded one packet before that point, so I don't read this as a regression; a longer run would show it.

Regression run

main:

xcl-smoke v1
commit: 47efa2ecea0a12934719ae69b81930cf02a4b1c3
gpu: NVIDIA GeForce RTX 5070
title: 9cc6a39e
seconds: 120
exit: 0x0
frames shown: 2515 (PresentX 2515)
presents per 2 s (last 3): 60 60 60
device removals: 0
crashes: 0
peak commit: 15375 MB

PR:

xcl-smoke v1
commit: 78f55101c6e97f58ac30782d4bfebc76c4a2bc28
gpu: NVIDIA GeForce RTX 5070
title: 9cc6a39e
seconds: 120
exit: 0x0
frames shown: 3215 (PresentX 3215)
presents per 2 s (last 3): 60 60 60
device removals: 0
crashes: 0
peak commit: 14432 MB

Not tested

  • The no-input runs stay in the menus, which decode no Opus packets; they check for regressions only. The Opus evidence is the merged run above.
  • 6.1-channel streams (this title's packets here were not 6.1), the MFT stream-change cap, AMD GPUs, a full workspace run (others posted those).
  • The head is 103 commits behind main; it merges cleanly.

AI use

  • Claude Code with Claude Opus 5.5 ran the builds, tests and smoke runs on the hardware above, compared the logs, and wrote this report.
**@⁠wilu222** on GitHub · 2026-11-24 13:53 UTC · [original](https://github.com/xcl-dev/xcl/pull/503#issuecomment-7133492305) · edited 2026-11-25 02:48 UTC Retail-title regression runs for `78f55101c6e97f58ac30782d4bfebc76c4a2bc28` (this PR's head as is, on its base `7ebf1b8`), since the PR has none yet. **Tested** - NVIDIA GeForce RTX 5070 (driver 32.0.16.1742, 32-lane waves), AMD Ryzen 7 5700X, 32 GB, Windows 10 Home 19045, Rust 1.100.0 MSVC, release builds. - `cargo test -p xcl --lib opus` on the head: 17 passed, 0 failed. - Retail 1.0.2.1, `XCL_NETWORK=0`, `scripts/smoke.ps1 -Seconds 120`, no input: the two blocks below. No crash or device removal; frames and commit within the check's limits. - With scripted presses (`XCL_PRESS_A_AT=30,45,60`), which start the world load and, about 75 s later, the opening cutscene's Opus audio: - this PR merged onto `main` `47efa2e` (clean merge, local only): 3,095 Opus packets decoded, 0 errors, non-zero samples. The run then ended at 107 s in the known `xg::copy_from` access violation (#662, fixed by #684), not in Opus code. - this PR's head, twice: both runs were still on the loading screen at 120 s and decoded one Opus packet. The base `7ebf1b8` alone reached the cutscene at about 112 s. The runs are identical up to 100 s (the same 18,902 DirectStorage requests by 30 s, then waiting). The PR runs reach the same later milestone about 8 s behind the base, so the cut-off falls before the cutscene. The PR's code decoded one packet before that point, so I don't read this as a regression; a longer run would show it. **Regression run** main: ``` xcl-smoke v1 commit: 47efa2ecea0a12934719ae69b81930cf02a4b1c3 gpu: NVIDIA GeForce RTX 5070 title: 9cc6a39e seconds: 120 exit: 0x0 frames shown: 2515 (PresentX 2515) presents per 2 s (last 3): 60 60 60 device removals: 0 crashes: 0 peak commit: 15375 MB ``` PR: ``` xcl-smoke v1 commit: 78f55101c6e97f58ac30782d4bfebc76c4a2bc28 gpu: NVIDIA GeForce RTX 5070 title: 9cc6a39e seconds: 120 exit: 0x0 frames shown: 3215 (PresentX 3215) presents per 2 s (last 3): 60 60 60 device removals: 0 crashes: 0 peak commit: 14432 MB ``` **Not tested** - The no-input runs stay in the menus, which decode no Opus packets; they check for regressions only. The Opus evidence is the merged run above. - 6.1-channel streams (this title's packets here were not 6.1), the MFT stream-change cap, AMD GPUs, a full workspace run (others posted those). - The head is 103 commits behind `main`; it merges cleanly. **AI use** - Claude Code with Claude Opus 5.5 ran the builds, tests and smoke runs on the hardware above, compared the logs, and wrote this report.
Author
Owner

@⁠throny on GitHub · 2026-11-25 10:16 UTC · original

Two contributors checked independently and found that #926 solves the same problem (for #327) in a different way: #1607, group D12. You may want to compare them with the other author and agree on one, or say in the PR why both are needed.

This is a hint from the community triage in #1607, not a maintainer decision.

AI use: Claude Code (Claude Opus 5.5), posted by a script from the #1607 table.

**@⁠throny** on GitHub · 2026-11-25 10:16 UTC · [original](https://github.com/xcl-dev/xcl/pull/503#issuecomment-7159474678) <!-- xcl-1607-hint:D12 --> Two contributors checked independently and found that #926 solves the same problem (for #327) in a different way: #1607, group D12. You may want to compare them with the other author and agree on one, or say in the PR why both are needed. This is a hint from the community triage in #1607, not a maintainer decision. AI use: Claude Code (Claude Opus 5.5), posted by a script from the #1607 table.
Author
Owner

@⁠DavidM1911 on GitHub · 2026-11-25 13:53 UTC · original

Verification on RTX 3060 Ti (Windows 11), branch merged with current main:

  • cargo test -p xcl --lib: all passed, 0 failed, ~26 ignored. (Intermittent single-test flake / 0xc0000005 abort under parallel scheduling — tracked in #1978; clean on single-threaded rerun.)

Thanks!

**@⁠DavidM1911** on GitHub · 2026-11-25 13:53 UTC · [original](https://github.com/xcl-dev/xcl/pull/503#issuecomment-7164445490) Verification on RTX 3060 Ti (Windows 11), branch merged with current `main`: - `cargo test -p xcl --lib`: all passed, 0 failed, ~26 ignored. (Intermittent single-test flake / 0xc0000005 abort under parallel scheduling — tracked in #1978; clean on single-threaded rerun.) Thanks!
This pull request can be merged automatically.
This branch is out-of-date with the base branch
You are not authorized to merge this pull request.
View command line instructions

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u origin '+refs/pull/503/head:github-bot/gh-503'
git switch 'github-bot/gh-503'

Merge

Merge the changes and update on Forgejo.
git switch 'main'
git merge --no-ff 'github-bot/gh-503'
git switch 'github-bot/gh-503'
git rebase 'main'
git switch 'main'
git merge --ff-only 'github-bot/gh-503'
git switch 'github-bot/gh-503'
git rebase 'main'
git switch 'main'
git merge --no-ff 'github-bot/gh-503'
git switch 'main'
git merge --squash 'github-bot/gh-503'
git switch 'main'
git merge --ff-only 'github-bot/gh-503'
git switch 'main'
git merge 'github-bot/gh-503'
git push origin 'main'
This discussion has been locked. Commenting is limited to contributors.
No description provided.