Repository navigation
Description
Warning / summary
Every message to a client shares one WebSocket, and the fragmentation rules make a fragmented message an indivisible burst: only one fragmented message may be in flight per direction, and the sender must finish it before sending any other frame. A Noise frame carries at most 65,518 bytes of payload, so any artwork image larger than ~64 KB becomes a contiguous fragment train that audio chunks cannot preempt. Even a server that wanted to interleave audio between fragments is forbidden from doing so by the spec.
The resulting audio stall is simply image_size / link_throughput, and it lands on top of whatever buffer cushion the player happens to hold at that moment. For buffered music mid-track the cushion is large and nothing audible happens. But:
- If we want to target live audio, players hold just
min_buffer_msof queued audio, since a live stream can never buffer further ahead. The whole point of the low-latency design is that this can be small (tens of ms on a good network), and then a perfectly ordinary track-change JPEG is enough to underrun every player that shares the connection with an artwork channel. - Even without live audio, the spec-mandated BMP support produces megabyte-class images that threaten conservative buffers too. An 800×480 24-bit BMP is ~1.1 MB, which is ~450 ms of wire occupancy at 20 Mbps. Devices that request BMP (cheap decode, no image library) are exactly the constrained Wi-Fi devices with 10–25 Mbps of real throughput. A display-speaker asking for BMP artwork is a dropout waiting to happen, at today's default buffers.
Numbers
Stall = image size / effective link throughput; one image, one channel:
| Image | Size | @100 Mbps | @20 Mbps |
|---|---|---|---|
| 480×480 JPEG | ~40 KB | 3 ms | 16 ms |
| 1000×1000 JPEG/PNG | 150–400 KB | 12–30 ms | 60–160 ms |
| 800×480 BMP (24bpp) | ~1.1 MB | ~90 ms | ~450 ms |
| Track change: album + artist, 2×1000×1000 JPEG/PNG | 300–800 KB | 24–64 ms | 120–320 ms |
| Track change: 2 BMP channels, 800×480 | ~2.3 MB | ~180 ms | ~0.9 s |
Up to 4 artwork channels can fire near-simultaneously on a track change, multiplying the burst. The most exposed windows are stream start and stream/clear, where the cushion is only the still-building startup lead. The late-join rule explicitly tells servers to send the current image for every channel immediately after an artwork stream/start, i.e. exactly inside that window.
The complete fix: proper fragmentation
Scheduling tweaks can shrink the exposure, but as long as a fragmented message is indivisible, one image = one unbounded stall. The only complete fix is proper fragmentation with interleaving: latency-critical frames (audio chunks, time sync, commands) must be able to preempt a large transfer mid-flight instead of waiting for it to finish. That changes the worst-case stall from image_size / throughput to a single frame (65,535 bytes ≈ 5 ms at 100 Mbps, 26 ms at 20 Mbps), below any plausible min_buffer_ms, independent of image size, format, and channel count. BMP stops being a hazard entirely, and the same fix unblocks time-sync responses and commands, which today queue behind artwork bursts too.
The design needs care around message ordering, since implementations currently get a strict total order per direction for free. The concrete rules (which frames may interleave, what ordering is guaranteed, possibly aborting an in-flight transfer) deserve their own proposal; this issue is about agreeing on the direction.
Additional improvements (likely worth doing regardless)
- Server scheduling: audio first. Artwork is never dropped for lateness and latest-wins, so it is inherently latency-tolerant. Servers should deprioritize artwork relative to audio, e.g. only dequeue an image once every player role's buffered horizon is above a floor. Note that a naive timestamp-ordered send queue does the opposite: artwork stamped "display now" systematically beats audio stamped in the future (send-ahead). The aiosendspin writer currently behaves this way.
- Soften the late-join wording. "Immediately send the current image" should become "promptly, but without starving audio startup"; the startup lead window is the worst possible moment for an artwork burst.
- Client guidance on artwork dimensions. Clients should declare
media_width/media_heightthey can afford to reassemble and decode: a megabyte-class image decode on a single-core device can glitch audio locally no matter how well the wire behaves.
These points shrink the window today without wire changes, but only the fragmentation fix removes the problem.
Metadata
Metadata
Assignees
Labels
Type
Projects
- StatusShow more project fieldsDone
Activity
maximmaxim345 commentedon Aug 18, 2026
@kahrendt As I understand, supporting proper fragmentation will be a lot more memory intensive, again affecting low powered devices this aims to help.
But the three additional improvements sound like good improvements we can adopt.
kahrendt commentedon Aug 19, 2026
I discussed this briefly with Artur yesterday, yes it is challenging, but really any device that supports artwork is going to need PSRAM anyways, so I don't think that's necessarily a blocker. And on devices without PSRAM (which we really haven't ever tried to build BTW), even an audio chunk somehow needing two messages will most likely fail.
maximmaxim345 commentedon Aug 19, 2026
We need to drop bmp since there is no reason to use that if png/jpg exists.
Instead of supporting multi-fragmentation on a protocol level, we need to bake this into just the artwork role.
Letterbox art and remove BMP support (#168)
Split large artwork images across multiple messages (#188)