Discussion:
[pulseaudio-discuss] starting multiple pulseaudio instances for the same user
Antoine Martin
2011-04-08 20:20:03 UTC
Permalink
Hi,

How can I start multiple copies of pulseaudio for the same $USER, but in
different contexts?
This was working a while back (last year or so - not sure about version
numbers).. but doesn't any more?

My software starts a virtual X server (xpra, vnc..), dbus and a
dedicated pulseaudio server for each "session application" it launches.
This allows it to redirect the sound (in and out) to/from remote
machines (potentially multiple at once too, some directly, some via
gstreamer+vorbis over ssh) - all this together with the display. see (1)

Each "application session" gets its own environment and starts
pulseaudio with:
/usr/bin/pulseaudio --start -vvvv --disable-shm=true --daemonize=false
--use-pid-file=false --system=false --exit-idle-time=-1 -n
--load=module-suspend-on-idle --load=module-null-sink
"--load=module-native-protocol-unix socket=/tmp/pulse-$DISPLAY/native"

A single $USER may start dozens of those sessions, each with a different
(virtual) $DISPLAY.
Now, when I start the second instance I can see that it somehow finds
the previous copy (not the one used by my local X11 session)
[pid 3044]
open("/home/antoine/.pulse/70a1ab2a8c9d6cb7625f17060000000d-runtime/autospawn.lock",
O_RDWR|O_CREAT|O_NOCTTY|O_NOFOLLOW, 0600) = 5
[pid 3044] fcntl(5, F_SETLKW, {type=F_WRLCK, whence=SEEK_SET, start=0,
len=0}
From that point onwards, nothing happens.
Can you please advise on how to restore this functionality?

Thanks
Antoine

(1)
http://winswitch.org/
Antoine Martin
2011-04-13 16:13:16 UTC
Permalink
I have found a workaround for this problem by setting a different $HOME
before launching each pulseaudio instance for the same $USER.

Since the pid file option says:
"use-pid-file= Create a PID file in /tmp/pulse-$USER/pid. Of this is
enabled you may use commands like --kill or --check. If you are planning
to start more than one PulseAudio process per user, you better
disable this option since it effectively disables multiple instances.
Takes a boolean argument, defaults to yes. The --no-cpu-limit command
line option takes precedence."
I think it is fair to assume that multiple instances per user should
work, shouldn't it?

The problem seems to come from the softlink from:
$HOME/.pulse/${MACHINE_ID}-runtime
Where MACHINE_ID=`cat /var/lib/dbus/machine-id`
And when this link exists you cannot start another instance as it will
block on the autospawn.lock.
(tested on a fully up to date Fedora 14 system)

Thanks
Antoine
Post by Antoine Martin
Hi,
How can I start multiple copies of pulseaudio for the same $USER, but in
different contexts?
This was working a while back (last year or so - not sure about version
numbers).. but doesn't any more?
My software starts a virtual X server (xpra, vnc..), dbus and a
dedicated pulseaudio server for each "session application" it launches.
This allows it to redirect the sound (in and out) to/from remote
machines (potentially multiple at once too, some directly, some via
gstreamer+vorbis over ssh) - all this together with the display. see (1)
Each "application session" gets its own environment and starts
/usr/bin/pulseaudio --start -vvvv --disable-shm=true --daemonize=false
--use-pid-file=false --system=false --exit-idle-time=-1 -n
--load=module-suspend-on-idle --load=module-null-sink
"--load=module-native-protocol-unix socket=/tmp/pulse-$DISPLAY/native"
A single $USER may start dozens of those sessions, each with a different
(virtual) $DISPLAY.
Now, when I start the second instance I can see that it somehow finds
the previous copy (not the one used by my local X11 session)
[pid 3044]
open("/home/antoine/.pulse/70a1ab2a8c9d6cb7625f17060000000d-runtime/autospawn.lock",
O_RDWR|O_CREAT|O_NOCTTY|O_NOFOLLOW, 0600) = 5
[pid 3044] fcntl(5, F_SETLKW, {type=F_WRLCK, whence=SEEK_SET, start=0,
len=0}
From that point onwards, nothing happens.
Can you please advise on how to restore this functionality?
Thanks
Antoine
(1)
http://winswitch.org/
_______________________________________________
pulseaudio-discuss mailing list
pulseaudio-discuss at mail.0pointer.de
https://tango.0pointer.de/mailman/listinfo/pulseaudio-discuss
Colin Guthrie
2011-04-13 16:50:54 UTC
Permalink
Post by Antoine Martin
Hi,
How can I start multiple copies of pulseaudio for the same $USER, but in
different contexts?
This was working a while back (last year or so - not sure about version
numbers).. but doesn't any more?
My software starts a virtual X server (xpra, vnc..), dbus and a
dedicated pulseaudio server for each "session application" it launches.
This allows it to redirect the sound (in and out) to/from remote
machines (potentially multiple at once too, some directly, some via
gstreamer+vorbis over ssh) - all this together with the display. see (1)
Each "application session" gets its own environment and starts
/usr/bin/pulseaudio --start -vvvv --disable-shm=true --daemonize=false
--use-pid-file=false --system=false --exit-idle-time=-1 -n
--load=module-suspend-on-idle --load=module-null-sink
"--load=module-native-protocol-unix socket=/tmp/pulse-$DISPLAY/native"
A single $USER may start dozens of those sessions, each with a different
(virtual) $DISPLAY.
Now, when I start the second instance I can see that it somehow finds
the previous copy (not the one used by my local X11 session)
[pid 3044]
open("/home/antoine/.pulse/70a1ab2a8c9d6cb7625f17060000000d-runtime/autospawn.lock",
O_RDWR|O_CREAT|O_NOCTTY|O_NOFOLLOW, 0600) = 5
[pid 3044] fcntl(5, F_SETLKW, {type=F_WRLCK, whence=SEEK_SET, start=0,
len=0}
From that point onwards, nothing happens.
Can you please advise on how to restore this functionality?
This is something that is not supported.

PA is, plain and simple, a per-user daemon.

If you want to direct sound from different DISPLAYs to different PA
servers/sinks you can use the PULSE_SERVER and/or PULSE_SINK property on
the X11 root window.

This functionality will get even more difficult to hack round in the
future when XDG_SESSION_DIR is supported (i.e. when it's rolled out via
systemd and supported by PA) so I'd recommend trying to find a way that
works where just one PA daemon per-user is started but appropriate
hacking of the X11 root window properties is done instead to acheive the
same result.

There will ultimately likely always be ways to get the end result you
need tho' :)

Col
--
Colin Guthrie
gmane(at)colin.guthr.ie
http://colin.guthr.ie/

Day Job:
Tribalogic Limited [http://www.tribalogic.net/]
Open Source:
Mageia Contributor [http://www.mageia.org/]
PulseAudio Hacker [http://www.pulseaudio.org/]
Trac Hacker [http://trac.edgewall.org/]
Antoine Martin
2011-04-13 17:06:59 UTC
Permalink
Post by Colin Guthrie
Post by Antoine Martin
Hi,
How can I start multiple copies of pulseaudio for the same $USER, but in
different contexts?
This was working a while back (last year or so - not sure about version
numbers).. but doesn't any more?
(snip)
Post by Colin Guthrie
Post by Antoine Martin
Can you please advise on how to restore this functionality?
This is something that is not supported.
PA is, plain and simple, a per-user daemon.
IMO this should be made clearer (as the current man page implies the
opposite), and if possible workarounds like the one I found should be
documented.
Post by Colin Guthrie
If you want to direct sound from different DISPLAYs to different PA
servers/sinks you can use the PULSE_SERVER and/or PULSE_SINK property on
the X11 root window.
This functionality will get even more difficult to hack round in the
future when XDG_SESSION_DIR is supported (i.e. when it's rolled out via
systemd and supported by PA) so I'd recommend trying to find a way that
works where just one PA daemon per-user is started but appropriate
hacking of the X11 root window properties is done instead to acheive the
same result.
There will ultimately likely always be ways to get the end result you
need tho' :)
Using the $HOME trick will do for now.

However please bear in mind that the solutions you suggest (X11
properties) are unusable in a number of scenarios, for example:
* in my case applications should be able start running and talk to a
pulseaudio server whether the session is actually shown anywhere or not.
The sound can then be dispatched wherever it is needed (clients over the
network). The X11 root window properties does not help here as you
cannot change the value after the application is started (well, you can
but it just won't have any effect)
* when running over slow-ish links. Last time I measured it, my solution
using gstreamer+vorbis consumes 25KB/s (albeit lossy) whereas pulseaudio
would require close to 1MB/s using its tcp sockets..

I understand the rationale for wanting only one server per user, but
please bear in mind that others may have different environments and
valid reasons for doing things differently.

Thanks!
Antoine
Post by Colin Guthrie
Col
Loading...