Repository navigation
Decode the FLAC codec_header at parse into a fixed 42-byte array - #250
Merged
Merged
Conversation
roles/player/v1.md "Codec framing" fixes a FLAC codec_header as the fLaC marker followed by the STREAMINFO block, so the parser reads it as a view, decodes it into a private 42-byte array and rejects anything else. The player hands those bytes to the sync task, and a FLAC stream/start no longer copies the header into a std::string on the protocol task. Breaking: ServerPlayerStreamObject::codec_header is removed from the public API; only the sync task's decoder used it.
Contributor
There was a problem hiding this comment.
🟡 Changes recommended
The FLAC allocation test uses a PCM-only player configuration, violating fixture invariants and making the measurement depend on a stream outside the advertised formats.
2 open issues
What changed in this PR
This PR removes the protocol task’s per-stream FLAC header heap allocation by decoding the header into a private, fixed 42-byte array before handing it to the sync task.
Changes:
- Validate FLAC header framing and Base64 encoding during parsing, then pass decoded bytes to the sync task.
- Remove the public
ServerPlayerStreamObject::codec_headerfield and update consumer and internal documentation. - Add header-validation, handoff, and allocation-count coverage, with valid FLAC fixtures.
| File | Description |
|---|---|
| tests/test_protocol.cpp | Adds FLAC header validation and decoding cases. |
| tests/test_player_role.cpp | Checks decoded-header handoff and adapts payload callers. |
| tests/test_json_arena.cpp | Updates the FLAC fixture and parsed-field access. |
| tests/test_client_lifecycle.cpp | Adapts stream payloads and audio-message handoffs. |
| tests/test_allocations.cpp | Adds a zero-allocation FLAC stream-start window. |
| src/protocol.cpp | Validates and decodes FLAC headers during parsing. |
| src/protocol_messages.h | Defines the fixed header array and private player payload. |
| src/player_role.cpp | Hands decoded header bytes to the sync task. |
| src/player_role_impl.h | Updates the stream-start interface and removes the decoding helper. |
| src/inbound_ring.h | Makes the low-level hand() method private. |
| src/client_dispatch.cpp | Passes the parsed player payload to the role. |
| include/sendspin/player_role.h | Removes the public codec_header field. |
| docs/internals.md | Documents inline header storage and revised allocation sites. |
| docs/integration-guide.md | Updates the public stream-parameter documentation. |
| CLAUDE.md | Documents the new allocation-test window. |
Review effort: Max
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.


Summary
A FLAC
stream/startcopied the player'scodec_headerinto astd::stringon the protocol task, the last per-stream heap allocation there that does not wait on a spec change (Sendspin/backlog#92). roles/player/v1.md "Codec framing" fixes the header as thefLaCmarker followed by the STREAMINFO block, so it is always 42 bytes and can be held inline.Breaking:
ServerPlayerStreamObject::codec_headeris removed from the public API. Only the sync task's decoder used it; neither the examples nor the ESPHome component read it.Breaking Change Migration
codec_headerfromPlayerRole::get_current_stream_params()or aServerPlayerStreamObject. The library already hands the header to its own decoder, so a player needs nothing in its place.codec,sample_rate,channelsandbit_depth, the same values STREAMINFO carries for decoding.Change
PlayerStreamPayloadinprotocol_messages.h). It accepts exactly the 56-character encoding offLaC, a STREAMINFO block header with the last-block flag set (RFC 9639 section 8.1) and length 34, and the 34-byte body. Anything else rejects thestream/start, as a missing header already did.hand_local(), still exempt from the quota.hand_flac_header()is gone, andInboundConsumer::hand()is private now that nothing outside calls it.Tests
sendspin_alloc_testshas a new window around a FLACstream/startthe player takes, expecting 0. It closes inside the listener'son_stream_start(), before the sync task starts decoding, after one warm-up stream that absorbs the main loop's first held-event slot. Restoring thestd::stringcopy fails it with 1 allocation; it passed 20 repeats under ASan and TSan.test_protocol.cppcovers the header rules, with one row per guard (each mutant removing a check fails a row).test_player_role.cppchecks that the sync task's item holds exactly the 42 bytes, typed as a FLAC header.