yktoo / indicator-sound-switcher

Sound input/output selector indicator for Linux
https://yktoo.com/en/software/sound-switcher-indicator/
GNU General Public License v3.0
369 stars 29 forks source link

Reset stream-restore database on stream switching #42

Closed Districtfine closed 2 years ago

Districtfine commented 7 years ago

For example, if I have my default device set as my speaker then I change the default device to headphones, all sounds currently playing will switch to headphones. But if I launch a program, its audio will play from the speakers, until I open the sound switcher and select headphones for a second time.

crazymaster commented 7 years ago

I can reproduce it. Is there anything I can do to help?

yktoo commented 7 years ago

Okay I can confirm this one. However that's the way the PulseAudio daemon maps streams, and this indicator is not affecting that.

At the same time, the standard Sound Panel in Gnome Control Center does switch the default sink/source in such a way that any stream appearing after that is mapped to the default.

I'll investigate how the Sound Panel handles it once I've got enough time.

deadmd commented 5 years ago

I use 2.2.0 in Linux Mint 19.1. Problem is actual.

breunigs commented 5 years ago

This happens for me when restore_device is true, which is the default. Disabling it makes re-appearing streams go to the newly selected output:

# /etc/pulse/default.pa
load-module module-stream-restore restore_device=false

The line already exists, so you just need to add restore_device=false.

breunigs commented 5 years ago

The docs actually explain how the gnome sound switcher works – it simply edits the database for all streams to the newly selected device: https://www.freedesktop.org/wiki/Software/PulseAudio/Documentation/User/DefaultDevice/

I took a look my file (tdbdump ~/.config/pulse/*stream-volumes.tdb) and it seems this is the format: https://sources.debian.org/src/pulseaudio/12.2-4/src/modules/module-stream-restore.c/?hl=2474#L998-L1008 with these prefixes: https://github.com/pulseaudio/pulseaudio/blob/master/src/pulsecore/tagstruct.h#L41-L61 However, I can't quite match my local entries to how I believe the code reads them, so I must've a misunderstanding somewhere.

yktoo commented 5 years ago

Thanks @breunigs, it looks indeed that it "works as designed":

Whenever a new stream appears, PulseAudio's stream-restore module checks if the same stream has been seen before, and if it is, then the stream is connected to the same sink or source that was used previously. There is a concept of a "fallback" device, which is used if the stream has not been seen before.

For those who happen to dislike the way PulseAudio works, the same page lists four possible solutions:

  1. use Gnome Volume Control,
  2. use pavucontrol,
  3. delete the file containing stream-volumes in its name in the ~/.pulse directory and restart PulseAudio, or
  4. set restore_device=false like in the comment above.

If I have time, I'll try to mimic Gnome's behaviour (not sure what "modifying the stream-restore database" entails exactly).

yktoo commented 2 years ago

Considering the alternatives (especially the persistent fix of editing PA config, item 4 above), this item is closed.