Skip to content

fix(alsa): stop flooding error callback during timestamp startup transient#1116

Merged
roderickvd merged 2 commits intomasterfrom
fix/alsa-timestamp-startup-transient
Mar 2, 2026
Merged

fix(alsa): stop flooding error callback during timestamp startup transient#1116
roderickvd merged 2 commits intomasterfrom
fix/alsa-timestamp-startup-transient

Conversation

@roderickvd
Copy link
Member

Attempt to fix RustAudio/rodio#853, where a user on Raspberry Pi was seeing 80 copies of:

audio stream error: get_htstamp 0.0 was earlier than get_trigger_htstamp 1791.541402389

The 80 messages then stopped and audio worked fine. So it's a startup thing, not a permanent failure.

What may be happening: the timestamp detection at stream creation checks get_htstamp() while the PCM is still in PREPARED state. At that point the PulseAudio ALSA plugin returns a valid-looking wall clock, so we decide "hardware timestamps work, use them." But for the first N periods after the stream is triggered, htstamp comes back as (0, 0), which is earlier than trigger_htstamp and causes the error.

The fix is to always store a fallback Instant at creation and use it silently when hardware timestamp computation fails, instead of routing the transient failure through the error callback. Once the hardware timestamps stabilise (which they do, quickly) the hardware path takes over automatically and the fallback is never touched again.

Some ALSA backends (notably the PulseAudio ALSA plugin on Raspberry Pi)
return a valid htstamp before the stream is triggered but then return
(0, 0) for the first several periods after it starts. This caused a
flood of "get_htstamp was earlier than get_trigger_htstamp" errors on
every audio callback until the timestamps stabilised.

Store a fallback Instant at stream creation and use it silently whenever
hardware timestamp computation fails, rather than routing the transient
error through the user's error callback.

Fixes RustAudio/rodio#853
@roderickvd roderickvd merged commit f1f5f95 into master Mar 2, 2026
@roderickvd roderickvd deleted the fix/alsa-timestamp-startup-transient branch March 2, 2026 21:42
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

get_pos much further ahead than actual playback position

1 participant