networking - How can I force the rediscovery of PulseAudio virtual sound devices?

19
2014-04
  • Christian

    I'm using the PulseAudio feature of network sound devices (not Multicast/RTP) to play sound from my netbook on the audio equipment connected to the HTPC when at home. This creates a virtual sound device that I can then use instead of the physical built-in one. Most of the time this works just fine. Sometimes however, the virtual sound device just doesn't appear. Disconnecting from and reconnecting to the network helps sometimes but not always and it's annoying and potentially bad for existing TCP connections.

    So my question basically is: Is there some way to tell PulseAudio "Hey, just look again if you really can't find a network sound device."?


    Edit: Unloading and reloading the module-zeroconf-discover with pacmd does not help either and it doesn't appear to be an avahi problem per se since avahi-browse -t --all | grep PulseAudio shows lots of right-looking stuff, even when the devices aren't listed in pavucontrol or pacmd list-sinks.


    Edit 2: I'm using Ubuntu 12.04 on both boxes for all the difference it might make.

  • Answers
  • Christian

    A simple sudo service avahi-daemon restart does the trick, even though avahi-browse sees the devices before that avahi restart. Thanks to Takkat for pointing me in the right direction.

  • Takkat

    This answer is untested so it might not work, but it may lead you to the right direction.

    I can confirm unresolved issues with an Avahi service that sometimes is unable to connect to a PulseAudio server. We may succeed reconnecting by either restarting the network, or the pulseaudio server but alas this does not always work.

    To overcome this issue we may try to establish a network audio stream using the native TCP protocol to stream directly to the IP rather than using an Avahi name resolution.

    To do so we can tunnel a remote sink by loading the module-tunnel-sink on the receiver side. On the sender we have to enable the native TCP protocol by loading module-native-protocol-tcp.

    See also this question for terminology and how to define the PULSE_SERVER variable:

    How to automatically set PulseAudio default sink to remote server at boot - Ubuntu 9.04

    It is a rather old question for Ubuntu 9.04 but to my knwoledge terminology and procedures have not changed much since then.

    Please also follow the PulseAudio Wiki on network connections.


  • Related Question

    pulseaudio - My sound stopped working today, how can I fix it?
  • Oli

    This seems to be a problem with pulseaudio. I was logged in over VNC on my phone and started playing a video this caused X to crash (as sometimes happens). I restarted and suddenly the sound doesn't work.

    • I have a Intel HDA/Realtek ALC889

      00:1b.0 Audio device: Intel Corporation 82801JI (ICH10 Family) HD Audio Controller
      
    • alsamixer is detecting this just fine.
    • PulseAudio doesn't detect this alsa device so is using auto_null as the default sink (logs below).
    • When I properly kill PulseAudio (tell it not to auto-start) direct ALSA communication with the sound card works just fine. speaker-test, for example, works. So the hardware and ALSA layers are fine IMO.
    • In the logs, it seems that the card might be "busy" but I really don't know how or why it would be now (and never before). Is there an ALSA lock file somewhere that it still there because of my crash?
    • I just ran sudo fuser /dev/snd/* and saw this:

      oli@bert:~$ sudo fuser /dev/snd/*
      /dev/snd/controlC0:   1884
      /dev/snd/pcmC0D0c:    1884m
      /dev/snd/timer:       1884
      

      A look at the process list (ps aux | grep 1884) tells me process 1884 is arecord -c 1 -f S16_LE -r 8000 -t raw. No idea what this is or why it's running.

    • When I try and kill arecord (as root), it just respawns and rebinds on the hardware.

    I'm in a very annoying situation where I don't know what is going on and don't know how to find out. I'm open to all suggestions to get this working again. Fire away.

    And here's what I get when I stop PA auto-loading, kill it and then start it with -vvvv.

    oli@bert:~$ pulseaudio -vvvvv
    I: main.c: setrlimit(RLIMIT_NICE, (31, 31)) failed: Operation not permitted
    I: main.c: setrlimit(RLIMIT_RTPRIO, (9, 9)) failed: Operation not permitted
    D: core-rtclock.c: Timer slack is set to 50 us.
    D: core-util.c: RealtimeKit worked.
    I: core-util.c: Successfully gained nice level -11.
    I: main.c: This is PulseAudio 0.9.21-63-gd3efa-dirty
    D: main.c: Compilation host: x86_64-pc-linux-gnu
    D: main.c: Compilation CFLAGS: -g -O2 -g -Wall -O3 -Wall -W -Wextra -pipe -Wno-long-long -Winline -Wvla -Wno-overlength-strings -Wunsafe-loop-optimizations -Wundef -Wformat=2 -Wlogical-op -Wsign-compare -Wformat-security -Wmissing-include-dirs -Wformat-nonliteral -Wold-style-definition -Wpointer-arith -Winit-self -Wdeclaration-after-statement -Wfloat-equal -Wmissing-prototypes -Wstrict-prototypes -Wredundant-decls -Wmissing-declarations -Wmissing-noreturn -Wshadow -Wendif-labels -Wcast-align -Wstrict-aliasing=2 -Wwrite-strings -Wno-unused-parameter -ffast-math -Wp,-D_FORTIFY_SOURCE=2 -fno-common -fdiagnostics-show-option
    D: main.c: Running on host: Linux x86_64 2.6.38-rc3 #1 SMP Tue Feb 1 10:53:04 GMT 2011
    D: main.c: Found 8 CPUs.
    I: main.c: Page size is 4096 bytes
    D: main.c: Compiled with Valgrind support: no
    D: main.c: Running in valgrind mode: no
    D: main.c: Running in VM: no
    D: main.c: Optimised build: yes
    D: main.c: All asserts enabled.
    I: main.c: Machine ID is 8310740c4729ef474fe5ecec4bbf5a6b.
    I: main.c: Session ID is 8310740c4729ef474fe5ecec4bbf5a6b-1297338553.571075-1050119523.
    I: main.c: Using runtime directory /home/oli/.pulse/8310740c4729ef474fe5ecec4bbf5a6b-runtime.
    I: main.c: Using state directory /home/oli/.pulse.
    I: main.c: Using modules directory /usr/lib/pulse-0.9.21/modules.
    I: main.c: Running in system mode: no
    I: main.c: Fresh high-resolution timers available! Enjoy ol' chap!
    I: cpu-x86.c: CPU flags: CMOV MMX SSE SSE2 SSE3 SSSE3 SSE4_1 SSE4_2 
    I: svolume_mmx.c: Initialising MMX optimized functions.
    I: remap_mmx.c: Initialising MMX optimized remappers.
    I: svolume_sse.c: Initialising SSE2 optimized functions.
    I: remap_sse.c: Initialising SSE2 optimized remappers.
    I: sconv_sse.c: Initialising SSE2 optimized conversions.
    D: memblock.c: Using shared memory pool with 1024 slots of size 64.0 KiB each, total size is 64.0 MiB, maximum usable slot size is 65472
    D: database-tdb.c: Opened TDB database '/home/oli/.pulse/8310740c4729ef474fe5ecec4bbf5a6b-device-volumes.tdb'
    I: module-device-restore.c: Sucessfully opened database file '/home/oli/.pulse/8310740c4729ef474fe5ecec4bbf5a6b-device-volumes'.
    I: module.c: Loaded "module-device-restore" (index: #0; argument: "").
    D: database-tdb.c: Opened TDB database '/home/oli/.pulse/8310740c4729ef474fe5ecec4bbf5a6b-stream-volumes.tdb'
    I: module-stream-restore.c: Sucessfully opened database file '/home/oli/.pulse/8310740c4729ef474fe5ecec4bbf5a6b-stream-volumes'.
    I: module.c: Loaded "module-stream-restore" (index: #1; argument: "").
    D: database-tdb.c: Opened TDB database '/home/oli/.pulse/8310740c4729ef474fe5ecec4bbf5a6b-card-database.tdb'
    I: module-card-restore.c: Sucessfully opened database file '/home/oli/.pulse/8310740c4729ef474fe5ecec4bbf5a6b-card-database'.
    I: module.c: Loaded "module-card-restore" (index: #2; argument: "").
    I: module.c: Loaded "module-augment-properties" (index: #3; argument: "").
    D: cli-command.c: Checking for existance of '/usr/lib/pulse-0.9.21/modules/module-udev-detect.so': success
    D: module-udev-detect.c: /dev/snd/controlC0 is accessible: yes
    D: module-udev-detect.c: /devices/pci0000:00/0000:00:1b.0/sound/card0 is busy: yes
    I: module-udev-detect.c: Found 1 cards.
    I: module.c: Loaded "module-udev-detect" (index: #4; argument: "").
    D: cli-command.c: Checking for existance of '/usr/lib/pulse-0.9.21/modules/module-bluetooth-discover.so': success
    D: dbus-util.c: Successfully connected to D-Bus system bus ba7c9a1f90b3d49d930bca2100000015 as :1.62
    D: bluetooth-util.c: dbus: interface=org.freedesktop.DBus, path=/org/freedesktop/DBus, member=NameAcquired
    D: bluetooth-util.c: Bluetooth daemon is apparently not available.
    I: module.c: Loaded "module-bluetooth-discover" (index: #5; argument: "").
    D: cli-command.c: Checking for existance of '/usr/lib/pulse-0.9.21/modules/module-esound-protocol-unix.so': success
    I: module.c: Loaded "module-esound-protocol-unix" (index: #6; argument: "").
    I: module.c: Loaded "module-native-protocol-unix" (index: #7; argument: "").
    D: cli-command.c: Checking for existance of '/usr/lib/pulse-0.9.21/modules/module-gconf.so': success
    I: module.c: Loaded "module-gconf" (index: #8; argument: "").
    I: module-default-device-restore.c: Saved default sink 'auto_null' not existant, not restoring default sink setting.
    I: module-default-device-restore.c: Saved default source 'auto_null.monitor' not existant, not restoring default source setting.
    I: module.c: Loaded "module-default-device-restore" (index: #9; argument: "").
    I: module.c: Loaded "module-rescue-streams" (index: #10; argument: "").
    D: module-always-sink.c: Autoloading null-sink as no other sinks detected.
    I: sink.c: Created sink 0 "auto_null" with sample spec s16le 6ch 44100Hz and channel map front-left,front-left-of-center,front-center,front-right,front-right-of-center,rear-center
    I: sink.c:     device.description = "Dummy Output"
    I: sink.c:     device.class = "abstract"
    I: sink.c:     device.icon_name = "audio-card"
    D: core-subscribe.c: Dropped redundant event due to change event.
    I: source.c: Created source 0 "auto_null.monitor" with sample spec s16le 6ch 44100Hz and channel map front-left,front-left-of-center,front-center,front-right,front-right-of-center,rear-center
    I: source.c:     device.description = "Monitor of Dummy Output"
    I: source.c:     device.class = "monitor"
    I: source.c:     device.icon_name = "audio-input-microphone"
    D: module-null-sink.c: Thread starting up
    I: module.c: Loaded "module-null-sink" (index: #11; argument: "sink_name=auto_null sink_properties='device.description="Dummy Output"'").
    I: module.c: Loaded "module-always-sink" (index: #12; argument: "").
    I: module.c: Loaded "module-intended-roles" (index: #13; argument: "").
    D: module-suspend-on-idle.c: Sink auto_null becomes idle, timeout in 5 seconds.
    I: module.c: Loaded "module-suspend-on-idle" (index: #14; argument: "").
    I: client.c: Created 0 "ConsoleKit Session /org/freedesktop/ConsoleKit/Session1"
    D: module-console-kit.c: Added new session /org/freedesktop/ConsoleKit/Session1
    I: module.c: Loaded "module-console-kit" (index: #15; argument: "").
    I: module.c: Loaded "module-position-event-sounds" (index: #16; argument: "").
    D: dbus-util.c: Successfully connected to D-Bus session bus efbffc6788fad56cfd64d40c00000018 as :1.182
    D: main.c: Got org.pulseaudio.Server!
    I: main.c: Daemon startup complete.
    I: client.c: Created 1 "Native client (UNIX socket client)"
    I: client.c: Created 2 "Native client (UNIX socket client)"
    D: protocol-native.c: Protocol version: remote 16, local 16
    I: protocol-native.c: Got credentials: uid=1000 gid=1000 success=1
    D: protocol-native.c: SHM possible: yes
    D: protocol-native.c: Negotiated SHM: yes
    D: protocol-native.c: Protocol version: remote 16, local 16
    I: protocol-native.c: Got credentials: uid=1000 gid=1000 success=1
    D: protocol-native.c: SHM possible: yes
    D: protocol-native.c: Negotiated SHM: yes
    D: module-augment-properties.c: Looking for .desktop file for gnome-volume-control-applet
    D: module-augment-properties.c: Looking for .desktop file for gnome-settings-daemon
    D: core-subscribe.c: Dropped redundant event due to change event.
    I: module-suspend-on-idle.c: Sink auto_null idle for too long, suspending ...
    D: sink.c: Suspend cause of sink auto_null is 0x0004, suspending
    

    Note the one section that seems to find the hardware but says it's busy (no idea if this is relevant).

    D: cli-command.c: Checking for existance of '/usr/lib/pulse-0.9.21/modules/module-udev-detect.so': success
    D: module-udev-detect.c: /dev/snd/controlC0 is accessible: yes
    D: module-udev-detect.c: /devices/pci0000:00/0000:00:1b.0/sound/card0 is busy: yes
    I: module-udev-detect.c: Found 1 cards.
    

  • Related Answers
  • Oli

    HUZZAH

    Right. arecord was the dodgy looking element here that I eventually found through fusering the sound files (see my question for my process). But I couldn't find what was causing arecord to start as root on boot. Here's how I did that:

    1. Run pstree | less
    2. In that, type /arecord and press return to find the arecord process.
    3. Press up once and you'll see its parent. In my case this was randomsound.

    I installed randomsound a few days ago to generate extra entropy (for regenerating /dev/random) using my sound card. I had completely forgotten it was installed and I guess this was the first time I restarted since installing it.

    In short sudo apt-get remove randomsound fixed it. PulseAudio can now grab my sound card and I can listen to some trashy europop while I work.