This Time Self-Hosted
dark mode light mode Search

Today’s improved features is for… PulseAudio!

Maybe not yet today’s feature, as you’ll have to wait a bit before seeing in your systems, but I coded it today at least.

PulseAudio has some nice optional supports, like HAL for autodiscovery of devices, Avahi for publishing the presence of the PulseAudio server on the network, and of course ALSA/OSS for the actual audio output.

These supports are optional at buildtime, so they are mapped to USE flags as usual; on the other hand, the modules that implement these features are dynamically loaded, so you can easily enable or disable them at runtime through the configuration file, which is a really nice thing.

What’s the problem then? Well, if you do build your PulseAudio with HAL support, or you use a binary package with it enabled, and then you decide you don’t need HAL at all, but don’t want to rebuild PulseAudio, you can just disable it from the configuration file, and it won’t even be loaded in memory; unfortunately, right now it will still be reported as a dependency of the service to baselayout. This means that if you stop or restart hald, you also stop or restart PulseAudio. The same happens for Avahi and ALSA.

Well, thanks to the superhuman efforts of our baselayout “guy” (man, you’re married now, can we still call you the baselayout guy?) Roy Marples, we have already a next generation init system, although still masked, that is Baselayout 2. The new baselayout do support dynamic dependencies based on configuration files, so as my box is already upgraded, I decided to take a look to make the init script smarter.

The new init script now tries to identify the PulseAudio script being used (the default is /etc/pulse/, but you can override it easily), and then greps through it to look for the configuration directives. Thanks to the power of egrep, only for alsa it has to pass through the configuration file more than once; thanks to Baselayout cache, if you don’t change init scripts and don’t change the configuration file, the dependencies are not recalculated, so you’re not going to run it that often.

The result is that you can easily disable HAL in the configuration file, restart PulseAudio, and then stopping HAL won’t stop your PulseAudio, without need for a restart. Same goes for Avahi and ALSA, although for the latter the check is more complex: alsasound is required as a dependency if there is an explicit ALSA module load, if there is an automatic ALSA module load, or if there is one of the two autodetection modules (normal and HAL), as those will most likely find ALSA devices where ALSA was enabled.

I’m also pondering about adding more stuff, like a check for the X11 publishing module, and then telling the init script to use xdm, and a possible automatic load of the capability module if it’s not loaded but present on the system and caps was requested at buildtime (of course this feature is Linux-only).

And if you expect a very bloated init script when running on a minimal set of features, I can tell you it certainly is not: thanks to unifdef I can cut out part of the code when it’s not needed, which means that the HAL and ALSA checks on Gentoo/FreeBSD aren’t present at all, and if I ever implement the capability module load, even that will be present only on the Linux version of the script.

Comments 3
  1. Wasn’t hal ported to freebsd some time ago? I remember seeing it in ports tree recently. And why module loading only for Linux? FreeBSD has kldload…

  2. Pulseaudio seems really interesting. I was reading about it on Gnome desktop-devel mailing list a couple weeks ago, and even though I’m one of the lucky guys with an audio card supporting hardware mixing I’m waiting for the 0.9.7 release to try it. Nice to know that there’s someone interested in it among the developers, so it should work without much hassle… 🙂

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.