Skip to content

fix: don't clip the start of a track on the pulseaudio backend#328

Merged
devgianlu merged 1 commit into
devgianlu:masterfrom
plisker:fix/pulseaudio-cold-start-clip
Jul 18, 2026
Merged

fix: don't clip the start of a track on the pulseaudio backend#328
devgianlu merged 1 commit into
devgianlu:masterfrom
plisker:fix/pulseaudio-cold-start-clip

Conversation

@plisker

@plisker plisker commented Jul 12, 2026

Copy link
Copy Markdown
Contributor

Fixes #292.

On pulseaudio, cold (non-prefetched) track loads start ~1s in. Drop() is the only backend that self-restarts the stream (Stop + FlushPlaybackStream + Start), against its Output contract ("empties the buffer without waiting"). A load runs SetPrimary -> Resume -> Drop; since Resume no-ops on an already-running stream, the pull loop has already read the new track's opening into the buffer, which Drop's flush then discards. Prefetched loads buffer ahead and survive it (hence next/prev stay clean).

Fix:

  • Drop() stops and flushes without restarting (matching the alsa/toolbox/pipe backends and the interface contract).
  • The load path flushes before switching sources.
  • The seek path resumes explicitly, since Drop no longer restarts.

Adds a player test covering the drop-before-switch ordering and the seek resume/paused behavior. Verified on a Raspberry Pi 4 (pipewire-pulse).

Note: seeking in the brief window right after end-of-track auto-pause now resumes playback, since the player now tracks pause state to decide whether to resume after the flush.

On a cold (non-prefetched) load, pulseaudio Drop() stopped, flushed and
restarted the stream. The load path set the new source and resumed before
dropping, so the stream was already reading the new track's opening into the
buffer, which the flush then discarded — clipping ~1s (devgianlu#292).

Drop() now only stops and flushes, matching the Output contract and the other
backends. The load path flushes before switching sources, and the seek path
resumes explicitly since Drop no longer restarts.
@devgianlu
devgianlu merged commit bd41ed5 into devgianlu:master Jul 18, 2026
8 checks passed
@plisker
plisker deleted the fix/pulseaudio-cold-start-clip branch July 21, 2026 20:11
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.

Playback doesn't start from the beginning when using Pulseaudio

2 participants