Repository navigation
Land the pre-release fixes: keep-output-alive, busy ALSA recovery, idle Pulse/PipeWire streams, offline builds - #127
Merged
chrisuthe merged 14 commits intoNov 19, 2026
Conversation
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.
…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.
Contributor
There was a problem hiding this comment.
🟡 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
Expire keep-alive after queued audio finishes · New Reopen unusable PCM instead of reporting success · New Mark clear boundaries idle before refilling · New Coordinate silence reserves and refill cadence · New Clear busy-origin refusal only after successful recovery · New Refresh stream format after confirmed device recovery · New
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)
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.
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.


Pre-release triage of the open issues, and the fixes picked for the coming release.
Changes
--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-devicewins. 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-msunder 40 with keep-alive logs a warning. Live check on an HDMIhw:port with--keep-output-alive 5: the PCM stayedRUNNINGon silence for about 5 s afterStream ended, then dropped toPREPARED. 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).-EBUSYopen now logsOutput 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 logsOutput device '…' is free -- playing,statusshows the format, and the end-of-stream byte count stops counting.RUNNING, is paused the same way. The next stream opens a fresh, uncorked stream, sinceconfigure()always replaces it.FETCHCONTENT_SOURCE_DIR_<NAME>+FETCHCONTENT_FULLYDISCONNECTED=ONroute 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 aSENDSPIN_CLI_USE_SYSTEM_SENDSPIN/find_packageoption has nothing to find yet.tests/state_store_test.cpp: builds one test record at full size, because GCC 16 raises a false-positive-Warray-boundsunderSENDSPIN_CLI_WERROR=ON.Triage
90cbd80) is an ancestor ofv0.10.0(a10289a), whichCMakeLists.txtpins--release-device/--fixed-volumeconfirmed by the reporter. Busy message and in-stream recovery in this PR. The 21-reconnects loop did not reproduce on main againstsendspin serve(0Connection lostin 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)Stream endedthe sink-input isCorked: yesand the sink goes IDLE → SUSPENDED (Pulse and PipeWire); the next stream playsRequires-Upstreamunshare -rn) from vendored sources--keep-output-alivesendspin serve-o pulsekeeps losing syncLost sync/Regainedcycles on a Pulse null sink, the same on a fresh stream as after a cork;-o pipewireon the same sink is cleanarchive.ubuntu.comand takes phased updates; the failing run was on #124, branched before #125No 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:
--keep-output-alive <s>/keep-output-alivekey. Default0keeps today's behaviour.… is busy (held by another process)andStream ended: N bytes discarded, because '…' was busyinstead of the "refused … format" wording. A log watcher matching "refused" won't see busy cases any more.Neither
Usage BreakingnorRequires-Upstreamapplies to this PR.Testing
SENDSPIN_CLI_WERROR=ONbuild is clean;scripts/format.sh --checkandscripts/smoke_test.shpass.<build>/sendspin.sockpast the 107-byte socket limit. They pass from a short directory, and CI isn't affected.sendspin serve(aiosendspin 9.1.0) for ALSA: keep the device open only while a stream plays #80, Idle CPU: a fixed 10 ms main loop, and a PulseAudio stream that stays open after the stream ends #92 and Feature request: keep the ALSA output running briefly between streams (--keep-output-alive <s>) #109, as described above.Refs #30, #32, #63, #80, #92, #97, #106, #108, #109, #121, #126