Skip to content

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

Open
Grimkaaah wants to merge 1 commit into
xcl-dev:mainfrom
Grimkaaah:fix/327-opus-framing-mapping-mft
Open

Grimkaaah wants to merge 1 commit into
xcl-dev:mainfrom
Grimkaaah:fix/327-opus-framing-mapping-mft

Conversation

@Grimkaaah

Copy link
Copy Markdown

Summary

Fixes #327

Test plan

  • cargo test -p xcl --lib hle::opus:: (15 passed, including new framing + 6.1 mapping tests)

…l-dev#327)

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]>
@H0UNDZER0

Copy link
Copy Markdown

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)

@MesshM

MesshM commented Nov 24, 2026

Copy link
Copy Markdown

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.

@mastrr9

mastrr9 commented Nov 24, 2026

Copy link
Copy Markdown

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.

@wilu222

wilu222 commented Nov 24, 2026 •

Copy link
Copy Markdown

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:

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.

@throny

throny commented Nov 25, 2026

Copy link
Copy Markdown
Collaborator

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.

@DavidM1911

Copy link
Copy Markdown
Contributor

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

Thanks!

@CalvyPZ CalvyPZ added the duplicate This issue or pull request already exists label Nov 25, 2026
@CalvyPZ CalvyPZ closed this Nov 25, 2026
@CalvyPZ CalvyPZ reopened this Nov 25, 2026
@CalvyPZ CalvyPZ removed the duplicate This issue or pull request already exists label Nov 25, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

XAudio2 / Opus: single length-prefixed packet misread as raw RFC 6716, 6.1 mapping stream count, and MFT output checks

8 participants