Skip to content

Opus: only take MFT output types with the decoder's channel count, cap stream-change retries - #926

Open
DavidM1911 wants to merge 1 commit into
xcl-dev:mainfrom
DavidM1911:opus-mft-guards
Open

DavidM1911 wants to merge 1 commit into
xcl-dev:mainfrom
DavidM1911:opus-mft-guards

Conversation

@DavidM1911

@DavidM1911 DavidM1911 commented Nov 24, 2026 •

Copy link
Copy Markdown
Contributor

Part of #327 (item 3).

Two guards on the Media Foundation MFT path in crates/xcl/src/hle/opus.rs:

  • MftDecoder::configure_output accepted the first PCM16/Float32 output type without checking MF_MT_AUDIO_NUM_CHANNELS against the decoder's channel count, then overwrote self.channels — a multistream interleave sized for the expected count could index past the buffer if the MFT enumerated a different count first. Output types whose channel count differs are now skipped; a missing NUM_CHANNELS still defaults to the decoder's count as before.
  • MftDecoder::drain_output retried MF_E_TRANSFORM_STREAM_CHANGE in an unbounded loop; it now gives up after 4 reconfigurations.

What is in it

  • crates/xcl/src/hle/opus.rs only. No new unit test: both paths need a live IMFTransform, which the crate's tests do not mock; the existing Opus/MFT tests still pass.

Tested

  • Windows 11, Ryzen 9 7900X (Radeon iGPU + NVIDIA RTX 3060 Ti 8 GB, driver 610.88), Rust 1.100.0 x86_64-pc-windows-msvc:
    • cargo test -p xcl --lib opus: 15 passed, 0 failed
    • cargo test --workspace -- --test-threads=4: 676 passed, 0 failed, 41 ignored
  • Regression run on the retail title (1.0.2.1, own copy), RTX 3060 Ti, scripts/smoke.ps1 -Seconds 60, cargo build --release -p xcl:

main a6f5f7a (same baseline as the sibling PRs; upstream/main is now 2997c9a, docs-only on top):

xcl-smoke v1
commit: a6f5f7a74cc620c1f88a9e3669a633d10c3c8212
gpu: NVIDIA GeForce RTX 3060 Ti
title: 3c290c16
seconds: 60
exit: 0x0
frames shown: 1503 (PresentX 1503)
presents per 2 s (last 3): 60 60 60
device removals: 0
crashes: 0
peak commit: 14437 MB

this PR's head 8d0176d:

xcl-smoke v1
commit: 8d0176d9b8099092d2c9809bf25630be68e7d7ee
gpu: NVIDIA GeForce RTX 3060 Ti
title: 3c290c16
seconds: 60
exit: 0x0
frames shown: 1468 (PresentX 1468)
presents per 2 s (last 3): 60 60 60
device removals: 0
crashes: 0
peak commit: 14455 MB

Not tested

  • A real MFT that enumerates mismatched channel counts or loops on STREAM_CHANGE (needs a misbehaving decoder); Linux/macOS (crate is Windows-only)

AI use

  • Devin (SWE-2 Flash Medium): implemented the guards, ran the suites and smoke runs.

…p stream-change retries

configure_output accepted the first PCM16/Float32 type regardless of MF_MT_AUDIO_NUM_CHANNELS and then overwrote self.channels, so a multistream interleave could index past the buffer; drain_output retried MF_E_TRANSFORM_STREAM_CHANGE forever. Output types whose channel count differs from the decoder's are now skipped, and more than 4 stream changes is an error.
@SlopTart

Copy link
Copy Markdown

Linux / AMD RDNA3 datapoint.

Merged state: head 8d0176d onto main 9aec53d, clean merge.

Full suite, cargo test --workspace --release --no-fail-fast --target x86_64-pc-windows-gnu -- --test-threads=4: 717 passed, 7 failed, 41 ignored; failures are the known Wine-lane set from my #42 rows. Opus MFT output-type gating green.

Not tested: retail titles (none here), Windows, RDNA4.
Counts only, no game data.

Machine: RX 7900 XT (RADV NAVI31), Mesa 26.2.5, kernel 7.2 (Arch), Proton Experimental (wine-11.0), patched vkd3d-proton v3.1, Rust cross x86_64-pc-windows-gnu, XCL_NETWORK=0, release profile, --test-threads=4. My Linux rows: #42 / #718.

AI use: Hermes agent (local Qwen-class) ran the suite and drafted this; I checked it before posting.

@throny

throny commented Nov 25, 2026

Copy link
Copy Markdown
Collaborator

Two contributors checked independently and found that #503 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.

@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
@github-actions github-actions Bot added area:hle kernelx, XGameRuntime, XAudio2, VFS, PE loader, TLS, EH needs-1st-check Passes gates; needs first independent merge-check (#3041) labels Nov 28, 2026
@throny

throny commented Nov 29, 2026

Copy link
Copy Markdown
Collaborator

merge-check claim
head: 8d0176d

@throny

throny commented Nov 29, 2026

Copy link
Copy Markdown
Collaborator

merge-check
base: d8bd9a3
head: 8d0176d
merge: clean
build: cargo build --workspace -> ok
tests: cargo test --workspace --no-fail-fast -- --test-threads=4 -> 2618 passed, 0 failed, 49 ignored: the base's count, the change has no test of its own (27 SKIPPED lines). Base alone at d8bd9a3: 2618 passed, 0 failed, 49 ignored.
review: no finding (read by me, 16 added lines). An output type whose channel count differs from the decoder's is skipped when the output is configured, instead of being taken and panicking later where the channels are interleaved; and a stream-change reply that keeps coming back after reconfiguring ends in an error after four rounds instead of looping. No test, which is understandable for a path that needs the system's decoder to misbehave.
performance: none.
verdict: safe to merge
hardware / tool and model: RTX 4080 16 GB (621.40), i9-12900K, Windows 11 26300, Rust 1.100.0, debug. Claude Code; merge, build and suite run by Claude Fable 5.2, diff review by Claude Opus 5.5 (every hunk read; nothing run on the GPU beyond the suite).

@github-actions github-actions Bot added needs-2nd-check Has 1 safe merge-check; needs second independent check (#3041) and removed needs-1st-check Passes gates; needs first independent merge-check (#3041) labels Nov 29, 2026
@tiagonleal

tiagonleal commented Nov 30, 2026 •

Copy link
Copy Markdown
Contributor

merge-check
base: cb80246
head: 8d0176d
merge: clean
build: cargo build --workspace -> ok (also cargo build --release -p xcl)
tests: cargo test --workspace --no-fail-fast -j 8 -- --test-threads=4 -> 2809 passed, 1 failed, 51 ignored; SKIPPED: 27 lines (22 no wave64, 3 f16/f32 per-lane cases refused, 2 no heap windows), the same as on the base; failing: hle::d3d12x::standin::tests::concurrent_shell_miss_reuses_winner_and_releases_loser_pipeline, which fails the same way on the base (it came in with #2369; #3474 fixes it). Base alone on this PC: 2809 passed, 1 failed, 51 ignored.
review: whole diff read (+10/-0, opus.rs). Output types of the system decoder whose channel count differs from the decoder's are skipped. If every type is skipped configure_output returns an error: at construction that falls back to libopus, and after a stream change it reaches the caller as a decode error, so nothing loops. drain_output now gives up with an error after more than four MF_E_TRANSFORM_STREAM_CHANGE replies in one call, where it could loop without end before. Buffer sizing is unchanged. No test, which is fair here: it would need a system decoder that misbehaves. One thing for whoever merges: open #503 hardens the same decoder in the same file, so the second of the two to merge will need a rebase. I agree with the earlier check on this head.
performance: none. Measured with scripts/smoke.ps1, 60 s of a retail title, release: 1680 frames and 15884 MB peak commit against 1662 and 1684 frames, 16196 and 15752 MB on the base. No device removal, no crash. That title's first minute may not decode Opus through this path, so the run is a regression check only.
verdict: safe to merge
hardware / tool and model: RTX 5070 Ti 16 GB (617.42, wave32), Ryzen 7 9800X3D, 32 GB, Windows 11 26300, rustc 1.100.0 / Claude Code (Claude Fable 5.2 ran the build, suite and smoke and wrote this; Claude Opus 5.5 read the diff first, and I checked its main points in the merged source)

  • Tiago

@github-actions github-actions Bot added ready-to-merge Has 2 independent safe merge-checks on current head (#3041) and removed needs-2nd-check Has 1 safe merge-check; needs second independent check (#3041) labels Nov 30, 2026
@Prime1997 Prime1997 added the test-only A maintainer reviewed the diff: tests only, no smoke run needed for this revision (CONTRIBUTING.md) label Nov 30, 2026
@Foniass

Foniass commented Dec 1, 2026

Copy link
Copy Markdown
Contributor

Triage (#1607) – head 8d0176d

#503 contains the same two changes in opus.rs (skip MFT output types whose channel count is not self.channels, cap STREAM_CHANGE retries at 4). It also changes the packet framing and the 7-channel Vorbis mapping to 5 streams / 2 coupled. libopus's table (and main) use 4 streams / 3 coupled for 6.1, so that part of #503 looks wrong. This PR is the minimal fix without that change. No problems found in this diff.

Recommendation: keep open.

AI review: Claude Code (Claude Opus 5.5), diffs read only, not built or run; not checked by a human.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area:hle kernelx, XGameRuntime, XAudio2, VFS, PE loader, TLS, EH ready-to-merge Has 2 independent safe merge-checks on current head (#3041) test-only A maintainer reviewed the diff: tests only, no smoke run needed for this revision (CONTRIBUTING.md)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

7 participants