Repository navigation
player role: carry the server's send-ahead on binary audio chunks - #167
Merged
Merged
Conversation
Players report required_lead_time_ms and min_buffer_ms but have no way to measure them. The only server transmit timestamps on the wire were the server_transmitted field on stream/start, stream/clear and stream/end, which sample the network once per stream event. Intermittent interference - a Wi-Fi neighbour taking 300 ms of airtime every few minutes - almost never coincides with a stream event, so a player sizes its buffer from measurements that never saw the condition that underruns it, and truncates the start of an announcement when it hits. Audio chunks now carry send_ahead: the microseconds between the server transmitting the chunk and the chunk's playback timestamp. Recovering the transmit time from it gives a player a delay sample per chunk, enough to build a distribution rather than infer one from a handful of points. send_ahead is a duration rather than a second absolute timestamp. It halves the added header (4 bytes, not 8) at a chunk rate where the overhead is worst in the low-latency case that motivates the change, and it cannot overflow in practice: uint32 microseconds covers about 71 minutes against a send-ahead bounded by buffer_capacity. The field saturates at both ends instead of wrapping, so a lead too large to represent degrades to a discarded sample rather than a plausible wrong one. Define where the transmit timestamp is taken - as late as the implementation permits, never at enqueue - and where the matching arrival time is taken. Without that, two conforming servers stamping at different points report different delays for the same network and players tune to whichever server they were developed against. Drop server_transmitted from stream/end, which nothing consumes. The artwork and visualizer roles are deliberately unchanged: artwork is never dropped for lateness, and a visualizer losing its first frames is cosmetic. The source role is unchanged too - its chunks already carry a capture timestamp, and splitting out the client's pipeline latency would give a server information it has no lever to act on.
maximmaxim345
left a comment
Member
There was a problem hiding this comment.
Left two nits.
This is also technically a breaking change if a server took server_transmitted at enqueue time for server/time. (I mean aiosendspin already took it right before sending, but still good to explicitly mention in the breaking changes section of this PR)
maximmaxim345
added a commit
to Sendspin/aiosendspin
that referenced
this pull request
Aug 25, 2026
A client that advertises no timing preferences falls back to the server default, so most ESPHome players run on it. At 500ms that is the entire jitter budget for a device on WiFi, where hiccups of one to two seconds are possible. Measured against the late chunk timings in music-assistant/support#6006, moving from the 250ms those reports ran on to 500ms accounts for about 40% of the drops, and 1s for about 80%. The cost is 500ms of extra scheduling lead before the first chunk plays. Follows the same reasoning as #285, which raised this default from 250ms to 500ms. This will of course not be needed anymore once proper measurement is implemented (powered by Sendspin/spec#167)
This was referenced Sep 16, 2026
5 tasks done
1 of 9 tasks
maximmaxim345
added a commit
to Sendspin/sendspin-js
that referenced
this pull request
Oct 28, 2026
# What does this implement/fix? <!-- Quick description and explanation of changes. --> Audio from a server that sends the spec's 13-byte audio chunk header was corrupted, since the client read the 4-byte `send_ahead` field as audio. The client also sent `trust_level` and player `supported_commands` in `client/hello`, which strict servers reject. The client now sends the rc1 `client/hello` and skips the full 13-byte header, and `send_ahead` doesn't affect playback. The operator's `languages` for a spoken pairing code are now read from `server/hello`, where the spec defines them. Breaking changes: - A server that still sends 9-byte audio chunk headers now plays corrupted audio. - `ClientHello` no longer has `trust_level` or player `supported_commands`, and `ActivatePairing` no longer has `languages`. Closing the connection on an audio message shorter than 13 bytes is left for a later PR. **Related issue or spec PR (if applicable):** - Sendspin/spec#158 - Sendspin/spec#167 - Sendspin/spec#177 - Sendspin/spec#241 ## Types of changes <!-- Tick exactly one box. CI (.github/workflows/pr-labels.yaml) applies the matching label, and the release notes use it to sort this change. --> - [ ] Bugfix (non-breaking change which fixes an issue): `bugfix` - [ ] New feature (non-breaking change which adds functionality): `new-feature` - [ ] Enhancement to an existing feature: `enhancement` - [x] Breaking change (changes the public API or the protocol in a way that is not backwards compatible): `breaking-change` - [ ] Refactor (no behavior change): `refactor` - [ ] Documentation only: `documentation` - [ ] Maintenance / chore: `maintenance` - [ ] CI / workflow change: `ci` - [ ] Dependencies bump: `dependencies`
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.
Players report
required_lead_time_msandmin_buffer_msbut have no way to measure them. The only server transmit timestamps on the wire were theserver_transmittedfield on stream/start, stream/clear and stream/end, which sample the network once per stream event. Intermittent interference; e.g., a doorbell camera taking 300 ms of airtime every few minutes, almost never coincides with a stream event, so a player sizes its buffer from measurements that never saw the condition that underruns. This causes a too smallmin_buffer_mscausing frequent dropouts during live streams.Audio chunks now carry
send_ahead: the microseconds between the server transmitting the chunk and the chunk's playback timestamp. Recovering the transmit time from it gives a player a delay sample per chunk, enough to build a distribution rather than infer one from a handful of points.send_aheadis a duration rather than a second absolute timestamp. It halves the added header (4 bytes, not 8) at a chunk rate where the overhead is worst in the low-latency case that motivates the change, and it cannot overflow in practice: uint32 microseconds covers about 71 minutes against a send-ahead bounded by buffer_capacity. The field saturates at both ends instead of wrapping, so a lead too large to represent degrades to a discarded sample rather than a plausible wrong one.Defines where the transmit timestamp is taken, as late as the implementation permits, never at enqueue, and where the matching arrival time is taken. Without that, two conforming servers stamping at different points report different delays for the same network and players tune to whichever server they were developed against.
Drops
server_transmittedfrom stream/end, which nothing consumes.The artwork and visualizer roles are deliberately unchanged: artwork is never dropped for lateness, and a visualizer losing its first frames is cosmetic. The source role is unchanged too; its chunks already carry a capture timestamp, and splitting out the client's pipeline latency would give a server information it has no lever to act on.
Closes #156
Breaking changes
Binary audio chunk layout.
send_aheadoccupies bytes 9-12, so the encoded audio frame moves from byte 9 to byte 13. Every player must update its chunk parser; one reading the payload at the old offset gets four bytes of header prepended to each frame and will fail to decode.server_transmittedstamping point is now normative. Transmit timestamps requires the value to be taken as late as the implementation permits and prohibits stamping at enqueue time. The field's previous definition said only "timestamp that the server transmitted this message", so a server stamping at enqueue was not clearly wrong before and is non-conforming now. This applies toserver/time,stream/startandstream/clear;server/timeis where it matters most, since the value feeds the client's time filter directly.aiosendspinalready stamps immediately before sending and needs no change.server_transmittedremoved fromstream/end. Nothing consumed it, but a client that treats the field as required will reject the message.