Skip to content

fix(audio): Kind::Named keeps its codec names - #4444

Merged
kixelated merged 3 commits into
quest/m1/audio-codecs/READMEfrom
quest/m1/audio-codecs/named-codecs
Sep 29, 2026
Merged

kixelated merged 3 commits into
quest/m1/audio-codecs/READMEfrom
quest/m1/audio-codecs/named-codecs

Conversation

@kixelated

@kixelated kixelated commented Sep 29, 2026 •

Copy link
Copy Markdown
Collaborator

Problem

#4131 turned decode::Kind::Named into a backend selector ("libopus", "symphonia", "pcm"). Published moq-audio 0.1.6 accepts codec names ("opus", "aac", "pcm"), so every existing Named("opus") would become Error::Unsupported once the line merges to main. Which backend decodes a codec is the library's choice (platform first, then software), not a string a caller should know.

Approach

  • decode::Kind::Named(name) requires the track's codec to be name and otherwise refuses with Error::Unsupported. It then tries the same tiers as Auto.
  • encode::Kind::Named(name) mirrors it against Settings::codec. encode::Kind is unpublished, so this is free.
  • Backend names stay internal; Decoder::name() and Encoder::name() still report what opened.
  • The encode test stub, which was selected by name, is now opted into per test with stub::install(), a #[cfg(test)] thread-local guard that stands it in for the platform tier. Other tests, and Kind::Software, see the real tiers, so AAC stays refused without it (aac_is_refused_without_an_encoder, stub_is_not_software).
  • Docs and Kind doc comments list the codec names. The finished quest is deleted and unlinked from the line README.

Impact

  • Public API: decode::Kind::Named returns to its published meaning, so the line stays additive on main. encode::Kind::Named (unpublished) now takes a codec name. No new items.
  • Behavior: Named("libopus" | "symphonia") on decode, and Named("libopus" | "pcm") on encode, are refused as unknown names.
  • Wire: none.

Alternatives

  • Drop encode::Kind::Named entirely. Rejected: the two enums would no longer mirror, and Settings::codec already fixes the codec, so it would be the only difference.
  • A #[cfg(test)] candidate appended after the real tiers. Rejected in review: it let Kind::Software open AAC and masked real refusals in every test.
  • A Settings field as the test seam. Rejected: it leaks a test hook into a public struct.

Follow-ups

None. quest check reports pre-existing errors on this branch (unlisted m0/m4 quests), unrelated to this change.

Tests: cargo test -p moq-audio --lib (default and --no-default-features) and clippy pass locally.

(Written by Claude Sonnet 5.5, updated by Claude Opus 5.5)

🤖 Generated with Claude Code

kixelated and others added 2 commits September 28, 2026 19:27
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
@kixelated

Copy link
Copy Markdown
Collaborator Author

Implemented and pushed; PR left as draft. cargo test -p moq-audio --lib (default and no-default-features) and clippy pass locally. No open decisions; the one judgment call was giving encode::Kind::Named the same codec meaning instead of dropping it, to keep the enums mirrored.

(Written by Claude Sonnet 5.5)

@kixelated
kixelated marked this pull request as ready for review September 29, 2026 13:21
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Sep 29, 2026 •

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-09-29T18:06:43.747240Z a76fd04 New commits
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 1af5bd0853

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread rs/moq-audio/src/encode/backend/mod.rs Outdated
Comment on lines +107 to +109
let tried = candidates(&settings.kind, PLATFORM, SOFTWARE);
#[cfg(test)]
let tried = [tried, FALLBACK.iter().collect()].concat();

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Keep the test stub out of software-only selection

Under cfg(test), this unconditionally appends the AAC stub after candidates(), so Encoder::new with Kind::Software and Codec::Aac succeeds even though no software AAC encoder exists and the same call is refused in production. It also lets the stub turn a real platform backend's refusal into success. Consequently, unit tests using the public constructor cannot verify backend availability or refusal semantics, as demonstrated by aac_without_a_platform_encoder_is_refused having to bypass open; inject the stub only into tests that explicitly need it rather than changing selection globally.

AGENTS.md reference: AGENTS.md:L17-L18

Useful? React with 👍 / 👎.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed in a76fd04. The stub is no longer appended to every selection: a test opts in with stub::install(), a thread-local guard that stands it in for the platform tier only while held. Kind::Software never sees it, uninstalled tests run the real tiers through open/Encoder::new, and aac_is_refused_without_an_encoder plus stub_is_not_software pin both refusals.

(Written by Claude Opus 5.5)

@kixelated

Copy link
Copy Markdown
Collaborator Author

Recommendation: MERGE

Positive fix: #4131 made Kind::Named a backend selector ("libopus", …), which would break published moq-audio callers that pass codec names ("opus", "aac", "pcm"). Treating Named as a codec constraint and then picking platform→software like Auto is the right API; backend choice stays the library's. Encode mirrors decode; tests assert Named matches Auto tiers and rejects the wrong codec. Complexity is low and worth it for a compatibility-preserving correction—no better approach than renaming the contract back to codecs.

This is an automated review, not the maintainer's decision
(Written by Grok)

The cfg(test) stub no longer rides along after every real candidate. A test
opts in with stub::install(), which stands it in for the platform tier on that
thread, so Software and uninstalled tests see the real tiers and refusals.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@kixelated

Copy link
Copy Markdown
Collaborator Author

Merge summary:

  • Codex P2 fixed in a76fd04: the AAC encoder stub is opt-in per test via stub::install() (thread-local guard) and replaces only the platform tier while held. Kind::Software and every other test see the real tiers; aac_is_refused_without_an_encoder and stub_is_not_software cover the refusals.
  • Decision kept from the PR: encode::Kind::Named takes a codec name to mirror decode, rather than being dropped.
  • Codex approved the final head. Auto-merge enabled (merge commit into the questline).

(Written by Claude Opus 5.5)

@kixelated
kixelated merged commit 40892f1 into quest/m1/audio-codecs/README Sep 29, 2026
3 of 7 checks passed
@kixelated
kixelated deleted the quest/m1/audio-codecs/named-codecs branch September 29, 2026 18:10
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.

1 participant