Repository navigation
Advertise the formats in preference order - #22
Merged
chrisuthe merged 1 commit intoAug 24, 2026
Merged
Conversation
The protocol has `supported_formats` in priority order, first preferred, and servers read it that way -- Music Assistant's `aiosendspin` takes the first entry it can encode and never looks further. supported_formats() emitted the probe ladders in the ascending order they are probed in, so it nominated the worst format the device would take: FLAC at 22050 Hz on ALSA `default`, whose plugin accepts the whole ladder. Rank the same entries on three named ladders instead -- codec, rate, depth. A permissive device now leads with FLAC 2 ch 16-bit @ 48 kHz, and one taking neither 48 nor 44.1 kHz falls to its best remaining rate rather than its lowest. Ordering only: a stable sort keyed on ladder position is a permutation by construction, so nothing is dropped and a rate outside PROBE_RATES sorts to the back rather than disappearing. The advertisement is also the menu a user picks a format from by hand, which is why it must not be narrowed.
chrisuthe
deleted the
chrisuthe/task/order-the-advertised-formats-by-preference
branch
August 24, 2026 15:34
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Why
supported_formats()built the advertisement in the order the device is probedin —
PROBE_RATESandPROBE_BIT_DEPTHSboth run ascending — so the list wentout with 22050 Hz / 8-bit at the front.
That order is load-bearing. The spec has
supported_formatsin priority order,first preferred, and servers read it that way:
aiosendspin'sPlayerRole._ensure_preferred_format()takesfilter_encodable_formats(...)[0]and never looks further. So on any device permissive enough to accept the whole
ladder — the ALSA
defaultPCM in particular, which on a PipeWire or PulseAudiohost converts rather than refuses — Music Assistant settled on FLAC 2 ch
16-bit @ 22050 Hz and stayed there. (16-bit rather than 8-bit only because the
server drops the 8-bit entries itself:
FLAC_BIT_DEPTHS = {16, 24, 32}.)The set was never the problem. The order was.
What changed
supported_formats()returns exactly the same entries, permuted, ranked onthree named ladders:
FLAC, OPUS, PCM48000, 44100, 96000, 88200, 192000, 176400, 32000, 2205016, 24, 32, 8A permissive device now leads with FLAC 2 ch 16-bit @ 48 kHz, and one that takes
neither 48 nor 44.1 kHz falls through to its best remaining rate rather than
its lowest.
The startup digest reads as the ranking it describes:
Ordering only, never narrowing
Dropping entries would be the easy way to force a default, and it would be
wrong: the same advertised list is what Music Assistant builds its per-player
Preferred format menu from, so narrowing it takes choices away from anyone
picking by hand.
The ranking is a
std::stable_sortkeyed on ladder position, which is apermutation by construction — it cannot add or drop an entry — and a rate or
depth outside
PROBE_RATES/PROBE_BIT_DEPTHSsorts to the back rather thandisappearing.
SupportedFormats.RankingOnlyPermutesWhatIsAdvertisedholds thatagainst a spelled-out copy of the old ascending crossing, over ten capability
sets including the degenerate ones.
Tests
New, alongside that permutation test:
ThePermissiveSetLeadsWithFlacStereo48kHz16BitADeviceWithNeitherPreferredRateLeadsWithItsBestRemaining({22050, 96000})RatesAndDepthsGoOutRankedOpusSitsAfterEveryFlacEntryAndBeforeEveryPcmEntryARateTheLaddersDoNotNameIsAdvertisedLastRatherThanDroppedDescribeFormats.GroupsTheAxesPerCodecfollowed the old positional order and isupdated — it now also asserts the codec groups appear in ranked order, which it
did not check before.
ctestis 354/354 green with-DSENDSPIN_CLI_BUILD_TESTS=ON -DSENDSPIN_CLI_WERROR=ON, the same configure line CI uses.