Skip to content

Land the pre-release fixes: keep-output-alive, busy ALSA recovery, idle Pulse/PipeWire streams, offline builds - #127

Merged
chrisuthe merged 14 commits into
mainfrom
chrisuthe/task/triage-open-issues-and-land-the-pre-release-fixes
Nov 19, 2026
Merged

chrisuthe merged 14 commits into
mainfrom
chrisuthe/task/triage-open-issues-and-land-the-pre-release-fixes

Conversation

@chrisuthe

@chrisuthe chrisuthe commented Nov 19, 2026 •

Copy link
Copy Markdown
Member

Pre-release triage of the open issues, and the fixes picked for the coming release.

Changes

  • Feature request: keep the ALSA output running briefly between streams (--keep-output-alive <s>) #109 --keep-output-alive <s>: tho22's commit, cherry-picked with their authorship kept. The conflicts were add/add only (--alsa-mixer, --pairing-token-endpoint). It fits the v0.10.0 sink model: the keep-alive window resets on any reopen, and --release-device wins. On top of it: a PCM that went away between streams (unplugged, suspended) is reopened at stream start instead of being kept alive, and its comments are trimmed to the repo's one-line rule. From review: the window now runs from when queued audio finishes playing (a buffer longer than the window is no longer cut off), the boundary refill keeps topping up instead of draining behind the 60 ms idle guard, the silence reserve has a 40 ms floor, and --buffer-ms under 40 with keep-alive logs a warning. Live check on an HDMI hw: port with --keep-output-alive 5: the PCM stayed RUNNING on silence for about 5 s after Stream ended, then dropped to PREPARED. Documented in the README and the configuration reference. Not changed, a follow-up for tho22: the silence queued at a stream boundary is 2 periods, which grows with --buffer-ms (40 ms at the default, 800 ms at 2000).
  • ALSA: keep the device open only while a stream plays #80 busy ALSA device: an -EBUSY open now logs Output device '…' is busy (held by another process) instead of blaming the format and pointing at -l. It also keeps retrying the open in the background (2/4/8/16/30 s, then again from 2 s) for as long as the stream lasts, so playback resumes within the stream once the device is free. At stream end the retries stop, so an idle sendspin never grabs a device another player just released. Before, the stream discarded until it ended. Once the sink reports the device open again, the listener logs Output device '…' is free -- playing, status shows the format, and the end-of-stream byte count stops counting.
  • Idle CPU: a fixed 10 ms main loop, and a PulseAudio stream that stays open after the stream ends #92 part 2, idle streams: the PulseAudio stream is corked at stream end. The PipeWire stream, which also kept its node RUNNING, is paused the same way. The next stream opens a fresh, uncorked stream, since configure() always replaces it.
  • Allow offline builds for Linux distribution packaging #106 offline builds: documents the FETCHCONTENT_SOURCE_DIR_<NAME> + FETCHCONTENT_FULLYDISCONNECTED=ON route in the README and the wiki's Build from source section. There's no CMake change, so the default build is untouched. sendspin-cpp installs no CMake package config, so a SENDSPIN_CLI_USE_SYSTEM_SENDSPIN / find_package option has nothing to find yet.
  • Mid-session format change leaves the stream desynced until a manual pause/play #30: a new test switches 48 kHz/16-bit to 192 kHz/24-bit inside one stream.
  • tests/state_store_test.cpp: builds one test record at full size, because GCC 16 raises a false-positive -Warray-bounds under SENDSPIN_CLI_WERROR=ON.

Triage

Issue Status Evidence Action on GitHub
#97 lost sync every 10 s while the clock slews Fixed on main sendspin-cpp#208 (merge 90cbd80) is an ancestor of v0.10.0 (a10289a), which CMakeLists.txt pins Close after the release; ask the reporter to retest on it
#30 mid-session format change desyncs Fixed on main 5b1099b reopens in each write's format once the old one has played out; the new test covers 48k/16 → 192k/24 Close after the release; ask for a retest
#80 release the ALSA device between streams Fixed: flags on main, follow-ups in this PR --release-device / --fixed-volume confirmed by the reporter. Busy message and in-stream recovery in this PR. The 21-reconnects loop did not reproduce on main against sendspin serve (0 Connection lost in 45 s), but the stream also never resumed once the device was free; this PR fixes that (live: a 75 s hold resumes once freed; a busy stream that ends leaves the device closed) Close after the release; ask spockfish to retest the busy case against Music Assistant
#92 idle CPU / Pulse stream left open Part 2 fixed in this PR; part 1 deferred Live on a null sink: after Stream ended the sink-input is Corked: yes and the sink goes IDLE → SUSPENDED (Pulse and PipeWire); the next stream plays Keep open for part 1 (10 ms main loop): it needs a waitable fd from sendspin-cpp's network provider, so mark the issue Requires-Upstream
#106 offline builds for distro packaging Fixed in this PR (docs) Configure + build with no network (unshare -rn) from vendored sources Close after the release; open an upstream request for sendspin-cpp to install a CMake package config
#109 --keep-output-alive Fixed in this PR Cherry-picked commit, author kept; live check above Close after the release; thank tho22
#121 source-only mode Deferred Feature request; the Music Assistant side of the flow is unclear Keep open, post-release
#63 pacing the discard during a device outage Deferred Design question still open with iibaranov-IG. Also seen here: a held device discards about 1.8× real time against sendspin serve Keep open, post-release
#32 -o pulse keeps losing sync Deferred Still ~5 ms Lost sync/Regained cycles on a Pulse null sink, the same on a fresh stream as after a cork; -o pipewire on the same sink is clean Keep open, investigate after the release
#108 "update with ESPHome 2026.5.1" in HA Not ours That repair comes from HA's ESPHome integration (Bluetooth proxy firmware check over the ESPHome native API). Neither sendspin-cli nor sendspin-cpp speaks that API or advertises as ESPHome, and the default manufacturer is unset Ask the reporter whether that host also runs an ESPHome device, then close as not ours
#126 armhf libsystemd0 skew (filed after this triage started) Likely fixed on main #125 (merged 20:12Z, before #126 was filed at 20:24Z) adds amd64 archive.ubuntu.com and takes phased updates; the failing run was on #124, branched before #125 Rebase #124 onto main; close #126 once the armhf leg passes there

No issue was commented on, labelled or closed.

Compatibility

Nothing breaks for CLI users. No existing flag, config key, control-socket message, state-store format or exit code changes.

Additive or visible but not breaking:

  • New --keep-output-alive <s> / keep-output-alive key. Default 0 keeps today's behaviour.
  • A busy ALSA device logs … is busy (held by another process) and Stream ended: N bytes discarded, because '…' was busy instead of the "refused … format" wording. A log watcher matching "refused" won't see busy cases any more.
  • A stream that opens a busy ALSA device now starts playing once the device is free, instead of discarding until the stream ends. While it waits, the sink retries the open in the background.
  • After a stream ends, the Pulse stream is corked and the PipeWire stream is paused, so the server may suspend the sink.

Neither Usage Breaking nor Requires-Upstream applies to this PR.

Testing

Refs #30, #32, #63, #80, #92, #97, #106, #108, #109, #121, #126

tho22 and others added 9 commits November 19, 2026 14:15
With an HDMI or S/PDIF receiver behind the player, clear() and the
same-format configure() stop the PCM at every stream boundary. The
receiver loses the digital signal and needs 2-3 s to re-lock, which
swallows the start of the next stream, e.g. most of a Music Assistant
announcement.

--keep-output-alive <s> (config key keep-output-alive, 0-3600, default 0)
keeps the ALSA PCM running instead: at a stream boundary the queued audio
is rewound to one period ahead of the hardware pointer and replaced with
silence, and poll() tops the ring up with silence once write() has been
idle for 60 ms, re-preparing an XRUN. Every real write() and same-format
configure() restarts a window of <s> seconds; when it runs out the PCM is
dropped and prepared as before, so the receiver can still go to standby.
Sync is unaffected: the silence is just queued frames that the next
write() measures through snd_pcm_delay().

Other backends get a no-op AudioSink::set_keep_alive(). With
--release-device the device is closed at stream end anyway, so the
option is ignored there and says so.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
A refused open never armed the sink's rescan, so a stream that found the device held discarded to its end; before v0.10.0 a reconnect loop happened to restart it. An -EBUSY open now owes poll() the same rescans a lost device gets.
@chrisuthe
chrisuthe marked this pull request as ready for review November 19, 2026 20:37
@chrisuthe
chrisuthe requested an adaptive review from Copilot November 19, 2026 20:37
…it ends

The rescan budget ran out after about a minute, and a rescan left owed when a busy stream ended could open the device for nobody and hold it from the next player.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Changes recommended

The keep-alive deadline starts at write time rather than playback completion, so it can truncate queued real audio when the PCM buffer exceeds the timeout.

6 open issues
What changed in this PR

Prepares the CLI for release by improving audio-output lifecycle handling and documenting offline builds.

Changes:

  • Adds configurable ALSA keep-alive, busy-device retries, and clearer discard reporting.
  • Corks idle PulseAudio streams and pauses idle PipeWire streams, resuming them on writes.
  • Documents offline builds and adds regression tests, including a compiler-warning workaround.
File Description
tests/​state_store_test.cpp Builds a full-size fixture to avoid a compiler warning.
tests/​player_listener_test.cpp Covers format switches, busy reporting, and discard accounting.
tests/​config_file_test.cpp Tests keep-alive configuration values and defaults.
tests/​cli_test.cpp Tests keep-alive argument validation.
src/​pulse_sink.h Tracks stream cork state.
src/​pulse_sink.cpp Corks idle output and uncorks on writes.
src/​player_listener.h Tracks busy-device refusals.
src/​player_listener.cpp Distinguishes busy opens and adjusts discard accounting.
src/​pipewire_sink.h Tracks paused stream state.
src/​pipewire_sink.cpp Pauses idle streams and reactivates on writes.
src/​main.cpp Applies keep-alive with release-device precedence.
src/​cli.h Declares the keep-alive option and limit.
src/​cli.cpp Adds keep-alive parsing, configuration, and help text.
src/​audio_sink.h Adds busy-state and keep-alive backend hooks.
src/​alsa_sink.h Declares keep-alive and busy-recovery state.
src/​alsa_sink.cpp Implements timed silence and busy-device rescanning.
README.md Introduces keep-alive and offline build commands.
packaging/​sendspin-cli.conf.example Adds a keep-alive configuration example.
docs/​wiki/​Installation.md Documents offline builds using local dependencies.
docs/​wiki/​Configuration.md Describes keep-alive behavior and precedence.

Review effort: Max (adaptive)

Comment thread src/alsa_sink.cpp Resolved
Comment thread src/alsa_sink.cpp Resolved
Comment thread src/alsa_sink.cpp Resolved
Comment thread src/alsa_sink.cpp Resolved
Comment thread src/player_listener.cpp Resolved
Comment thread src/player_listener.cpp Resolved
Run the window from when queued audio finishes, so a buffer longer than the window is not cut off; let a boundary top up from the next tick, so the forced refill cannot drain behind the idle guard; floor the reserve at 40 ms of a few loop ticks; fall through to the reopen when the flush leaves the PCM unusable; warn when --buffer-ms is too small to bridge loop ticks.
The listener took a false device_busy() as recovery, which a non-EBUSY rescan failure also gives, and never refreshed the stream format. poll() now waits for the sink to report the device open, then clears the refusal and records the format.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

linux-armv7: armhf dependency install fails when libsystemd0 versions skew between the runner and ports.ubuntu.com

3 participants