Skip to content

fix(audio): restore ducked media when the player re-creates its stream - #1128

Open
KitsuneKode wants to merge 1 commit into
peteonrails:devfrom
KitsuneKode:pr/media-restore-recreated-streams
Open

KitsuneKode wants to merge 1 commit into
peteonrails:devfrom
KitsuneKode:pr/media-restore-recreated-streams

Conversation

@KitsuneKode

@KitsuneKode KitsuneKode commented Nov 24, 2026 •

Copy link
Copy Markdown

Description

With duck_media on, media sometimes stayed at the ducked level after a dictation. Two causes:

  1. Paused players were ducked too. With pause_media and duck_media both on, a player that was just paused still has a sink input for a moment, so it was ducked. On resume, the player (Spotify, Firefox, mpv) re-creates its stream; PipeWire's stream-restore gives the new stream the volume we set, under an index restore never saw. Streams of apps whose MPRIS player we paused are now left alone (matched by process name, executable, and the player's Identity / DesktopEntry).
  2. Players that re-create their stream while ducked. After restoring, a short background watch (4 s, 200 ms steps) looks for streams that replaced a ducked one: same app, at that stream's ducked level. It sets them back to the original volume. The next duck cancels the watch before it reads volumes, so the watch never sees (or records) ducked levels as originals.

Restore still never waits on the watch.

Related Issue

None filed; found while daily-driving pause_media + duck_media with Spotify and Firefox on PipeWire. #1126 touches the same function (it skips filter-chain streams); the two changes are independent, and I'm happy to rebase on whichever lands first.

Type of Change

  • Bug fix (non-breaking change that fixes an issue)

Testing

  • I have tested these changes locally (Hyprland, PipeWire, Spotify and Firefox, pause_media + duck_media on)
  • I have run cargo test and all tests pass (see below)
  • I have run cargo clippy --all-targets --no-deps -- -D warnings with no warnings
  • I have run cargo fmt

New tests cover the sink-input parsing of inactive streams, app matching, and the ducked-level match.

Ran CI's jobs locally: cargo fmt --check, cargo clippy --all-targets --no-deps -- -D warnings (default, ONNX engines and osd-native features), and cargo test (default features, and the parakeet features). Everything passes except two tests that fail the same way on a clean dev checkout here: meeting::tests::the_chunk_a_crash_left_untranscribed_is_transcribed_on_finish, and, only when the whole suite runs at once, daemon::tests::streaming_stop_watchdog_recovers_when_backend_never_ends.

Documentation

  • No documentation changes are needed

Pre-merge checklist

  • This PR targets the dev branch (not main)

Additional Notes

Written with Claude Code (Claude Opus 5.5); I reviewed and tested it. Commits are signed.

With pause_media and duck_media both on, a playing player was ducked and
then paused. Players that tear their stream down on pause (Chromium,
Spotify) re-create it on resume, and PipeWire's stream-restore hands the new
stream the volume voxtype had set, under an index the restore never
touched: the music stayed at the ducked level after the take.

- The streams of the players voxtype pauses are no longer ducked; they go
  quiet by themselves.
- After the restore, a background watch (4 s, cancelled by the next take)
  puts any stream an app re-created at its ducked level back at that app's
  original volume. A stream matches on both the app and the expected
  ducked volume, and only a successful pactl write counts.

This branch has not been deployed

No deployments
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.

1 participant