Hi,
A few people have been discussing the status of jack support with
pulseaudio at pulseaudio-discuss.
I thought that it would be useful to post the main details for people
here and also to have a more complete overview in the search engines,
I am following up on the dbus situation in regards to legacy jack.
However the scripts below should be useful for people who use non dbus
jack and still want to run pulseaudio at the same time. They can be
called from qjackctl for convenience.
++++++++
> I would like to get some feedback on why exactly
PA is not currently
> able to autoreconfigure itself to play nicely with jack out of the
> box.
Recent PA versions do just that. If you have a recent dbus'ified
version of JACK and PA 0.9.15 then PA will give up access to the
device when JACK asks for it and take it back afterwards. JACK is king
and PA obeys.
++++++++++
As mentioned we have two modules to connect PA to JACK. Called
module-jack-sink and module-jack-source. Presumably those are the
modules included in that package.
Ok so not running both at the same time. But how do
you stop
pulseaudio from
> running and restart it after you used JACK?
Newer PA and JACK versions cooperate in this way
automatically. If you fire up JACK PA will go out of the way for that
device. And after JACK is done PA takes the device back. JACK is king
and PA will comply.
In older versions you can use a tool like "pasuspender". It will
suspend PA's access to the audio devices temporarily as long as child
process is running. If you make that child process JACK you have a
neat way to make JACK and PA not fight for device access.
A more brutal way is to stop PA with "pulseaudio -k" before you run
JACK and then start PA with "pulseaudio -D" afterwards. But that
probably won't work that nicely since PA is configured to autospawn in
most cases these days -- which you can disable however by editing
/etc/pulse/client.conf
+++++++++++
Do you or anyone else have a specific reasoning for
using only the
jackdbus
> version? Is is just because the person who wrote
the code wrote it
to work
> with jackdbus?
>
> Is this something that could be handled in a different way to give
legacy
> jack users this feature?
I don't use Jack myself (anymore), but from what I understand, this
feature is tied to jackdbus, because D-Bus is the protocol Jack and PA
use to communicate with each other. When PA is running and Jack is
started, Jack can't force PA to release the device, if PA doesn't want
to cooperate (well, it could use the "kill" command or something...).
PA cooperates by listening for device release requests using D-Bus, so
Jack has to use D-Bus too. And apparently jackdbus is the only
implementation that does that.
++++++++++++
Currently what I'm doing, which is just a bit hackish, is to use pactl
list to get the IDs of the alsa sink/source, unloading them via pactl
unload-module, then starting JACK and loading the appropriate
module-jack-sink/source.
In the reverse, again pactl list to get the relevant IDs, unload via
pactl unload-module, then loading the ALSA modules.
This actually works most of the time, but there's a segmentation fault
that I've encountered recently when unloading the jack modules while
sound is playing. The bug report with traces has been submitted at
http://www.pulseaudio.org/ticket/560 and Lennart will be getting round
to it.
Can you provide a command line for this that works for
you please? I
> would like to test it here.
Okay. As I warned, it IS rather hackish. There's two scripts, the first
one I name pulse-nojack, the second I name pulse-withjack. Sequence of
events is as follows:-
1. Start pulseaudio (I comment out every HAL/alsa-related line
in /etc/pulse/*.pa, so pulse just starts with a null sink if it hasn't
yet). Using the --start means if pulse is already started nothing will
be done (use current server).
2. Check for modules needing to be unloaded. Just pactl with some greps
and sed, then pactl unload-module.
3. Check for jackd (this may need to be changed once jack2 comes out,
I've been monitoring the jackdbus conversations and things are in real
flux there), kill/start if needed.
4. Load the modules which need loading.
Please note there's probably some wrapping problems with this code.
Please check it out, should not be hard to figure out what to do.
FIRST SCRIPT: PULSE-NOJACK----------------------------------------------
#!/bin/bash
# ORIGINAL SCRIPT FROM:
#http://ubuntuforums.org/showthread.php?t=904379&highlight=bash+ping
# edited by edmondt in:
http://ubuntuforums.org/showthread.php?t=939183
# edited by ngoonee, Feb 2009
# Start pulseaudio if it hasn't already been started
pulseaudio --start
# Name the module to be unloaded.
MODULE="alsa"
# The line used to startup JACK.
JACKSTART="/usr/bin/jackd -R -dalsa -r44100 -p64 -n3 -D -Chw:0 -Phw:0"
SINKID=$(pactl list | grep -B 1 "Name: module-$MODULE-sink" | grep
Module | sed 's/[^0-9]//g')
SOURCEID=$(pactl list | grep -B 1 "Name: module-$MODULE-source" | grep
Module | sed 's/[^0-9]//g')
if [ -e $SINKID ]; then
echo $MODULE sinks/sources not loaded, proceeding....
else
echo $MODULE sinks/sources are loaded, ID of $MODULE sink is $SINKID
ID of $MODULE source is $SOURCEID...
echo Unloading module $SINKID and $SOURCID
pactl unload-module $SINKID
pactl unload-module $SOURCEID
fi
if [ $( pidof jackd ) ]; then
echo JACK is running, nothing to be done.
else
echo JACK is not running, starting JACK...
$JACKSTART &
sleep 3
fi
JACKSINKID=$(pactl list | grep -B 1 "Name: module-jack-sink" | grep
Module | sed 's/[^0-9]//g')
JACKSOURCEID=$(pactl list | grep -B 1 "Name: module-jack-source" | grep
Module | sed 's/[^0-9]//g')
if [ -e $JACKSINKID ]; then
echo JACK sinks/sources not loaded, loading now...
pactl load-module module-jack-sink
pactl load-module module-jack-source
else
echo JACK sinks/sources are loaded, ID of JACK sink is $JACKSINKID
ID of JACK source is $JACKSOURCEID...
fi
exit 0
------------------------------------------------------------------------
SECOND SCRIPT: PULSE-WITHJACK-------------------------------------------
#!/bin/bash
# ORIGINAL SCRIPT FROM:
#
http://ubuntuforums.org/showthread.php?t=904379&highlight=bash+ping
# edited by edmondt in:
http://ubuntuforums.org/showthread.php?t=939183
# edited by ngoonee, Feb 2009
# Start pulseaudio if it hasn't already been started
pulseaudio --start
# Name the module to be unloaded.
MODULE="alsa"
# The line used to startup JACK.
JACKSTART="/usr/bin/jackd -R -dalsa -r44100 -p64 -n3 -D -Chw:0 -Phw:0"
SINKID=$(pactl list | grep -B 1 "Name: module-$MODULE-sink" | grep
Module | sed 's/[^0-9]//g')
SOURCEID=$(pactl list | grep -B 1 "Name: module-$MODULE-source" | grep
Module | sed 's/[^0-9]//g')
if [ -e $SINKID ]; then
echo $MODULE sinks/sources not loaded, proceeding....
else
echo $MODULE sinks/sources are loaded, ID of $MODULE sink is $SINKID
ID of $MODULE source is $SOURCEID...
echo Unloading module $SINKID and $SOURCID
pactl unload-module $SINKID
pactl unload-module $SOURCEID
fi
if [ $( pidof jackd ) ]; then
echo JACK is running, nothing to be done.
else
echo JACK is not running, starting JACK...
$JACKSTART &
sleep 3
fi
JACKSINKID=$(pactl list | grep -B 1 "Name: module-jack-sink" | grep
Module | sed 's/[^0-9]//g')
JACKSOURCEID=$(pactl list | grep -B 1 "Name: module-jack-source" | grep
Module | sed 's/[^0-9]//g')
if [ -e $JACKSINKID ]; then
echo JACK sinks/sources not loaded, loading now...
pactl load-module module-jack-sink
pactl load-module module-jack-source
else
echo JACK sinks/sources are loaded, ID of JACK sink is $JACKSINKID
ID of JACK source is $JACKSOURCEID...
fi
exit 0
------------------------------------------------------------------------
--
Patrick Shirkey
Boost Hardware Ltd