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

Merged
DavidM1911 merged 1 commit from upstream-pr/926 into main 2026-12-02 13:21:04 +00:00
DavidM1911 commented 2026-11-24 08:29:03 +00:00 (Migrated from github.com)

Imported from ivall/xcl. Originally posted by DavidM1911 on 2026-11-24T08:29:03Z.


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.
<!-- greyfinch-sync:ivall/xcl:issue:5468702064 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/pull/926). Originally posted by [DavidM1911](https://github.com/DavidM1911) on 2026-11-24T08:29:03Z. --- 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.
SlopTart commented 2026-11-24 11:05:48 +00:00 (Migrated from github.com)

Imported from ivall/xcl. Originally posted by SlopTart on 2026-11-24T10:37:35Z.


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.

<!-- greyfinch-sync:ivall/xcl:comment:7129029815 --> Imported from [ivall/xcl](https://github.com/ivall/xcl/pull/926#issuecomment-7129029815). Originally posted by [SlopTart](https://github.com/SlopTart) on 2026-11-24T10:37:35Z. --- 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 commented 2026-11-25 11:08:58 +00:00 (Migrated from github.com)

Imported from ivall/xcl. Originally posted by throny on 2026-11-25T10:16:42Z.


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.

<!-- greyfinch-sync:ivall/xcl:comment:7159475267 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/pull/926#issuecomment-7159475267). Originally posted by [throny](https://github.com/throny) on 2026-11-25T10:16:42Z. --- <!-- xcl-1607-hint:D12 --> 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.
throny commented 2026-11-29 09:36:52 +00:00 (Migrated from github.com)

Imported from ivall/xcl. Originally posted by throny on 2026-11-29T09:36:52Z.


merge-check claim
head: 8d0176d9b8

<!-- greyfinch-sync:ivall/xcl:comment:7253880308 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/pull/926#issuecomment-7253880308). Originally posted by [throny](https://github.com/throny) on 2026-11-29T09:36:52Z. --- merge-check claim head: 8d0176d9b8099092d2c9809bf25630be68e7d7ee
throny commented 2026-11-29 09:41:20 +00:00 (Migrated from github.com)

Imported from ivall/xcl. Originally posted by throny on 2026-11-29T09:41:20Z.


merge-check
base: d8bd9a38
head: 8d0176d9b8
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 d8bd9a38: 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).

<!-- greyfinch-sync:ivall/xcl:comment:7253929579 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/pull/926#issuecomment-7253929579). Originally posted by [throny](https://github.com/throny) on 2026-11-29T09:41:20Z. --- merge-check base: d8bd9a38 head: 8d0176d9b8099092d2c9809bf25630be68e7d7ee 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 d8bd9a38: 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).
tiagonleal commented 2026-11-30 02:49:08 +00:00 (Migrated from github.com)

Imported from ivall/xcl. Originally posted by tiagonleal on 2026-11-30T02:49:08Z.


merge-check
base: cb8024684c
head: 8d0176d9b8
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
<!-- greyfinch-sync:ivall/xcl:comment:7267344793 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/pull/926#issuecomment-7267344793). Originally posted by [tiagonleal](https://github.com/tiagonleal) on 2026-11-30T02:49:08Z. --- merge-check base: cb8024684c7babcb0569ecda2217a54b8bedafb1 head: 8d0176d9b8099092d2c9809bf25630be68e7d7ee 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
Foniass commented 2026-12-01 04:30:38 +00:00 (Migrated from github.com)

Imported from ivall/xcl. Originally posted by Foniass on 2026-12-01T04:30:38Z.


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.

<!-- greyfinch-sync:ivall/xcl:comment:7300806267 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/pull/926#issuecomment-7300806267). Originally posted by [Foniass](https://github.com/Foniass) on 2026-12-01T04:30:38Z. --- **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 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
xcl-dev/xcl!920
No description provided.