Skip to content

[audio] AudioFormatNegotiator::primaryRateOrder: add Q_UNREACHABLE on switch fall-through #3432

@ten9876

Description

@ten9876

Tiny follow-up to #3397 (merged as 204585b).

AudioFormatNegotiator::primaryRateOrder() (src/core/AudioFormatNegotiator.cpp:19-47) has two per-direction switches over TargetOs, then a return {internalRate} fallback after both switches. The fallback is only reachable if a new TargetOs enum value is added later without updating one of the inner switches.

Flagged in the @aethersdr-agent bot review as a non-blocking nit. The current shape is correct; this is documentation polish for future contributors.

Suggested change

Replace the trailing fallback with Q_UNREACHABLE() so the invariant ("every TargetOs value is handled in both directions") is enforced by the compiler / runtime instead of papered over with a silent default:

QList<int> primaryRateOrder(TargetOs os, Direction dir, int internalRate)
{
    if (dir == Direction::Output) {
        switch (os) {
        case TargetOs::Windows: return {48000, internalRate};
        case TargetOs::MacOS:   return {48000, internalRate};
        case TargetOs::Linux:   return {internalRate, 48000};
        }
    } else {
        switch (os) {
        case TargetOs::Windows: return {48000, 44100, internalRate, 16000};
        case TargetOs::MacOS:   return {48000, 44100, internalRate, 16000};
        case TargetOs::Linux:   return {internalRate, 48000, 44100};
        }
    }
    Q_UNREACHABLE();  // every TargetOs value is covered above
}

When

Cheap enough to roll into the next audio-sink-factory PR (the live Qt wrapper, currently open as #3398) rather than landing as a standalone change.

Refs #3306 #3397

Metadata

Metadata

Assignees

No one assigned

    Labels

    GUIUser interfaceaudioAudio engine and streamingenhancementImprovement to existing featuregood first issueGood for newcomersmaintainer-reviewRequires maintainer review before any action is taken

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions