February 2017

Socket activation for root

As explained in last month’s report, systemd’s socket activation should be disabled for the root user’s PulseAudio service. I made a patch for that. It took three iterations, with three different approaches, because the first two (ConditionPathIsReadWrite and ConditionCapability) didn’t work as first imagined. In the end I had to use ExecStartPre to run a command that checks whether we’re root. That’s not ideal, because now the socket unit goes into “failed” state with error messages in the syslog/journal, which may make people think that things aren’t working as they should, but that’s the best solution we could come up with. Felipe Sateler submitted a feature request for systemd to add a better way to make units conditional based on the current user.

Build problem with clang

It turned out that the 10.0 release can’t be built with clang. I made a fix for that, and Arun modified our Travis configuration so that builds are also tested with clang, so a similar problem shouldn’t happen any more in the future.

Access control

I reviewed Wim Tayman’s work on adding access control infrastructure for limiting the range of things sandboxed applications can do in PulseAudio. It’s not yet merged (it was kind of prototype-ish code anyway). Wim has updated the code, and it’s now waiting for another review round.

Improving default device selection

Back in September I made patches for improving the default device handling: among the fixed issues were that a device that is not plugged in (e.g. headphones) could be made the default device when better options exist, and at least the D-Bus interface didn’t always send update signals when the default device changes. Now I got the patches reviewed, and based on the feedback, I submitted the second version of the patch set. The second version turned out to cause crashing in module-dbus-protocol, so I had to make yet another version of the patches. The third version is now waiting for review.

module-loopback improvements

Georg Chini submitted a new version of his module-loopback patch set that among other things fixes the initial latency of the loopback. Previously the initial latency could be much too low or much too large depending on circumstances, and while the module did eventually adjust the buffered amount of audio to match the requested latency, that was a slow process. The patch set is pretty large. I started reviewing it (and the biggest latency issues should now be fixed in git master), but there’s a lot more to be reviewed.

OpenEmbedded stuff

I updated the alsa-lib recipe to the newest upstream release.

I started to look into upstreaming the patches that OpenEmbedded has for alsa-tools. At least one of them seemed trivial. I planned to apply it on a fresh clone of the upstream alsa-tools git repository, and test that it builds (just a routine test – it’s actually obvious to see that the patch can’t cause build problems). It turned out that building alsa-tools is a pain. All the tools are separated in their own build systems, but they also have some dependencies on each other. Running “make” at the top level tries to build everything, but the dependencies are handled in a way that doesn’t work out of the box, and one tool also depends on Qt3, which is deprecated and not available in current distributions any more. I pondered a bit whether I should try to make the build system more sane so that “make” at the top level could actually be expected to work, but I don’t think I’ll spend time on that. I believe the problematic tools are used by very few people, so it’s not really worth the effort to make all of them work. I’ll just patch out some of the tools (like OpenEmbedded and other distributions do also) to be able to build the parts that I’m interested in.

Ross Burton reported that the pulseaudio recipe had started producing warnings about text relocations. It seems that something in Ross’s local configuration triggers the problem, because I couldn’t reproduce it with the default configuration. It seems likely that there’s some bug in PulseAudio, but it remains a mystery how to trigger the bug.

This post was originally written on 2017-03-02, and first made available to my Patreon supporters. Speaking of Patreon – I’m using crowdfunding in an attempt to make it financially sustainable to continue my volunteer work as a PulseAudio maintainer. If you’d like to help, check out my Patreon page.

January 2017

PulseAudio 10.0 is out!

The first release candidate for PulseAudio 10.0 was published in the beginning of January. There weren’t many problems with the RC, so this time the first release candidate turned out to be also the last. The final version was released on 2017-01-19. Here are the release notes in case you haven’t seen them yet: https://www.freedesktop.org/wiki/Software/PulseAudio/Notes/10.0/

Bluetooth MTU problems

I merged a patch that was supposed to fix bluetooth HSP audio with some bluetooth adapters that don’t work with the hardcoded audio chunk sizes (a.k.a. MTUs) that PulseAudio has traditionally used. Now PulseAudio asks the appropriate chunk size from the kernel, but it turned out that the change breaks audio with some adapters that used to work with the hardcoded chunk sizes. The situation is difficult: the patch does the right thing in theory, but it’s not clear if it does more harm or good in practice. In the long term I think it’s best to keep the patch and cooperate with the kernel developers to add fixes (or workarounds, if it’s the hardware’s fault) in the kernel so that the kernel gives working parameters for all hardware. I can only hope that the patch won’t cause huge havoc on bluetooth users once it gets more widely used.

Crashing in x32 environments

I did some investigation about crashes in ORC code when running PulseAudio in an x32 environment. It’s likely an ORC bug, but I nevertheless set up an x32 environment and did some investigation in order to be able to make a good bug report for ORC developers. I didn’t get very far in my investigation, however, because if I built PulseAudio without optimizations, PulseAudio would crash already at startup when querying the CPU model, and looking into that problem distracted me from the ORC crash. The CPU querying crash happened inside assembly code, and I’m not fluent at reading x86 assembly code (nor any other architecture assembly code for that matter), but after struggling for some time I figured out why the crash happens. It looks like a compiler bug to me, but I’m not sure. In any case, I should report the problem to the GCC developers.

Better remixing

I don’t report all patch reviews here, but one of the more interesting patch sets was the one from David Mandelberg that added the “remixing-use-all-sink-channels” option to daemon.conf. If you have a surround speaker setup, PulseAudio by default has always used all speakers for playing back stereo audio. There are good reasons why some people don’t like that, but the only way to avoid that has been to disable all remixing, and that would break some use cases, such as trying to play mono audio (since no speaker is designated as a “mono” speaker, mono audio would just not play at all). Now it’s possible to leave remixing on, but set remixing-use-all-sink-channels to “no”, which changes remixing so that stereo audio is only played to the two front speakers, while mono audio is handled in a sane way (mono is actually a special case with special handling, but more generally if the audio input has channels that don’t have a corresponding channel in the output setup, then those channels get remixed to other channels, but if the output side has channels that don’t exist in the input, then those output channels get silence).

Combine sink improvements soon?

I reviewed a patch that made it possible for clients to dynamically add and remove outputs on a running combine sink. I had to reject the first version, but hopefully Steffen Pfendtner will continue working on it. People request this feature every now and then.

RAOP patches merged

It was discussed earlier that it would probably be a good idea to merge the big RAOP sink patch set from Hajime Fujita, Martin Blanchard and Colin Leroy without full review, because nobody seems to find the time to review the patches (the patches have existed for years), while the existing RAOP sink implementation is becoming obsolete, since it doesn’t support newer hardware. That has now happened – PulseAudio 11.0 will have much better RAOP support.

Socket activation for root

I noticed that systemd had created a pulseaudio socket for root on a user’s system (this came up while debugging a different problem), which is not a good thing. For some background: before PulseAudio started to use systemd’s socket activation, PulseAudio had a mechanism for automatically starting the server if it’s not running when a client tries to connect to it. That autospawning mechanism is still used when necessary, but it’s not used if a distribution uses the socket activation mechanism. The old autospawning mechanism is not used for root, because automatically starting PulseAudio for root messes up audio for regular users, because the alsa device handover doesn’t work for root. The systemd socket activation doesn’t currently have similar protection, however. We need some way to disable the socket for root, and I started a mailing list thread asking for ideas. Ahmed S. Darwish and Felipe Sateler had some ideas, and while systemd doesn’t provide a straightforward way to do this, it seems that there are ways to make this happen.

Crash with more than 32 channels

PulseAudio has a limit of 32 channels per device or stream. That’s rarely a problem, but there are some sound cards that have more channels than that. A user of one of such cards reported that PulseAudio crashes when the card is plugged in. I made a fix for the crash, but such cards still can’t be used by PulseAudio. There was some talk about adding better support for such cards, but it doesn’t seem likely that anyone is going to work on that.

High sample rates

Here’s another interesting patch that I reviewed: In the default configuration PulseAudio will configure the sound card to only use 44100 Hz or 48000 Hz sample rate. Some people want to configure the sound card to use higher sample rates to avoid resampling when playing content with high sample rates. It has always been possible to do that, but only in an inflexible way: it was only possible to configure two rates to be used. Arun Raghavan made a patch that added the “avoid-resampling” option to daemon.conf. Setting that option to “yes” will make PulseAudio configure the sound card to use whatever rate the content has that is being played back.

Access control

Wim Taymans requested comments about his work on adding infrastructure for doing access control within PulseAudio (for example, disallowing microphone access for untrusted applications). I started looking into it, but I didn’t have time to go through it all. I will continue the review soon (I hope).

OpenEmbedded stuff

On the OpenEmbedded front, I updated the alsa-tools, flac and pulseaudio recipes to use the newest upstream releases.

This post was originally written on 2017-02-04, and first made available to my Patreon supporters. Speaking of Patreon – I’m using crowdfunding in an attempt to make it financially sustainable to continue my volunteer work as a PulseAudio maintainer. If you’d like to help, check out my Patreon page.

December 2016

I fixed a crash that happened if module-combine-sink was used on top of a filter sink, and the filter sink was removed while the combine sink was running.

It was reported that module-xenpv-sink fails to build. I contacted Giorgos Boutsioukis (the module author) in hopes of getting some clues about why the module might have suddenly stopped building. He didn’t have ideas about the build failure, but he explained that the module has probably never been used by anyone (if I understood correctly, there was a project to develop an audio driver in Xen which the PulseAudio module was intended to use, but the driver was never adopted in Xen). We decided to remove the module from PulseAudio.

I addressed a couple of licensing issues: the license text for the audio filtering code copied from WebKit was not being included in release tarballs, and the top-level license file didn’t mention that the qpaeq utility is licensed under AGPL. Regarding qpaeq, I added the missing note to the top-level license file, but I also started the process to relicense qpaeq from AGPL to LGPL like the rest of PulseAudio code. I haven’t yet received permission from all qpaeq contributors to change the license.

A serious regression was about to creep in the 10.0 release (streaming would stop if a client sent “proactively” more data than the server had requested), but luckily Ahmed Darwish noticed it while working on a different bug. I made a fix for that.

It seemed that I could make the first 10.0 release candidate in December, but due to last minute problems it was postponed a bit. Now the release candidate is out, however, so please test it if you can!

This post was originally written on 2017-01-06, and first made available to my Patreon supporters. Speaking of Patreon – I’m using crowdfunding in an attempt to make it financially sustainable to continue my volunteer work as a PulseAudio maintainer. If you’d like to help, check out my Patreon page.

November 2016

Preparing for the 10.0 release

I continued to work on the combine sink crash that is blocking the release. My fix (which still needs some work) changes the core memory handling in such an invasive way that I think it’s best to postpone merging it after the release so that it gets a bit more testing before becoming widely used. The crash that it fixes is so rare that it’s not very serious if we don’t get the fix in the upcoming release.

My patch for making module-raop-sink compatible with the newest openssl release got reviewed, and I had to make a couple of revisions for the patch. Now it’s merged.

Ahmed Darwish was awesome and fixed two blocker bugs (97769 and 98475), so now only two release blockers remain: removing module-xen-sink and fixing one crash. module-xen-sink will be removed, because it doesn’t build any more, and the module author said that it’s probably not used by anyone. Removing the module is easy, and the remaining crash looks like it will be easy to reproduce, so hopefully we can publish the first release candidate in December.

Other things

I had prepared a libsamplerate update for OpenEmbedded earlier, and now that the OpenEmbedded-Core repository was unfrozen after a release, I submitted the update and cleaned up the libsamplerate packaging a bit. I also studied some odd bits of the OpenEmbedded alsa-lib packaging, resulting in a couple of minor fixes.

Hajime Fujita submitted a new version of his big RAOP patch set that makes module-raop-sink compatible with more recent AirPlay hardware. The patches have existed for a long time, but nobody has had time to review them. This time around Anton Lundin helped by reviewing some of them. It was also discussed that it might be best to skip the review step for the patches if nobody has time for reviewing, since the patches mostly affect just module-raop-sink and that module is becoming more and more obsolete due to only supporting old hardware.

It was reported that the “System Sounds” volume slider doesn’t affect the sounds that are played by module-x11-bell. X11 has its own volume setting for bell sounds, and PulseAudio used to honor that setting, but since the result is a confusing UI, I changed module-x11-bell so that it uses the system sound volume instead of the X11 volume.

This post was originally written on 2016-12-05, and first made available to my Patreon supporters. Speaking of Patreon – I’m using crowdfunding in an attempt to make it financially sustainable to continue my volunteer work as a PulseAudio maintainer. If you’d like to help, check out my Patreon page.

October 2016

Here’s my second monthly report about my PulseAudio activity (there’s not really anything to report on the OpenEmbedded front this time). We’re preparing for the 10.0 release, which means that I should concentrate on getting rid of the release blocker bugs, but actually I ended up doing some other things too.

Another default device handling improvement

I continued to work on the bug about HDMI being preferred over headphones (it should be the other way around). In September I made patches that set the headphone sink as the default when headphones are plugged in, now I made a patch that also moves existing streams to the headphones. So if the user hasn’t explicitly chosen a sink for a stream, such streams now automatically move when the default sink changes. I’m happy this is finally fixed (the patches still are pending review, though), now I think the only major remaining issue with our default device handling is that if the user sets a USB device as the default, that choice is forgotten if the device is removed and plugged in again later.

module-combine-sink crash

Another major work item was bug 95352, which is about a crash when using module-combine-sink. It’s great that we got a backtrace from the bug reporter, because trying to reproduce the problem would be very hard. Based on the backtrace, I’m pretty confident I know why the crash happens, and I’ve been working on a fix. The fix requires relatively big changes, and my first idea didn’t work as well as I expected, so it will take some time to finish it.

The problem is basically that when a client exits, the shared memory associated with the client is freed, and if there’s some part of the system still using a “memblock” that references that memory area, the memory is copied from the shared memory to a local memory pool in the server. This copying involves changing the “type” of the memblock. However, there’s code that assumes that the memblock type won’t change, and if such code runs at the same time the memblock type is being changed, a crash happens. One option would be to remove the incorrect assumptions by adding more locking to the memblock code, but that could cause performance problems and it would also increase the complexity of the memblock code that I think is complex enough already. My current plan is to get rid of the memblock type changes instead. There should be no need to forcibly free the shared memory area that is associated with a disconnecting client, so the memblock type change should be avoidable. There’s also a different situation where the memblock type changes, but I have a plan for getting rid of that too.

module-bluetooth-policy crash

The new feature in module-bluetooth-policy for automatic switching beween A2DP and HSP turned out to cause crashing if there are no other sources in the system than the HSP source. I made a fix for that, but the fix then made module-suspend-on-idle crash due to an old bug that just hadn’t been triggered before. I fixed that too.

Patreon launch

Preparing for the Patreon launch took a significant chunk of time. In particular, deciding what to say in the introduction pitch on the main Patreon page and how to say it was a slow process. Whatever I wrote, it never seemed to be quite right. Well, now I’m finally reasonably happy with the page, and the campaign is live! It has been about a week now since the launch, and the results are better than what I expected – big thanks to all of you who signed up already!

Other things

Thanks to investigating bug 97064, I learnt that I can comfortably blame the kernel or hardware configuration for a certain class of Bluetooth audio problems: if PulseAudio successfully creates a sink and source for HSP, but no audio gets transmitted, the reason may be missing firmware or the Bluetooth adapter may be in a wrong mode.

We have an annoying dependency on GConf due to paprefs, but Sylvain Baubeau has done some work to move paprefs to GSettings. There was initially some unclarity about how to cleanly manage the transition so that the existing settings stored in GConf are preserved, but now it’s starting to look much clearer: we’ll probably ship PulseAudio with both GConf and GSettings enabled by default, and then a bit later update paprefs. The first time the new version of paprefs is run, the settings in GConf get moved to GSettings. At some point in the future we can then drop GConf support from PulseAudio.

I also wrote a few miscellaneous small patches, here’s a list:

  • a patch for allowing Chinese characters (or anything else in UTF-8) in Bluetooth device descriptions.
  • a patch that removes the use of readdir_r(), which glibc has recently deprecated.
  • a couple of patches for making the system.pa configuration file more similar to default.pa. Some modules were loaded in the wrong order, causing volume restoring to not work properly. It seems that the system mode configuration has been severely neglected over the years, and there would still be work to be done to make the configuration more similar to the normal per-user mode (the configuration files can’t be exactly the same, though – there’s a reason why system.pa and default.pa are separate files).
  • a fix for a small error in threaded mainloop example code.
  • a fix for a minor bug found by Coverity: we didn’t always check the return value of dbus_message_iter_append_basic(). The function can in theory fail due to lack of memory.

I think that’s all for now. Thanks for reading!

This post was originally written on 2016-11-01, and first made available to my Patreon supporters. Speaking of Patreon – I’m using crowdfunding in an attempt to make it financially sustainable to continue my volunteer work as a PulseAudio maintainer. If you’d like to help, check out my Patreon page.

September 2016

Here’s my first monthly summary! Last month I made the decision to start a Patreon campaign, and the first concrete action towards that was to start writing notes every day about things I did, because it was clear from the beginning that monthly reports would be a part of the campaign, and there was no way I could write them without notes. So, let’s see what the notes say…

The loopback patches

The month began with reviewing the last few loopback patches from the big patch set that I had started reviewing already a while ago. Georg Chini has been working on them for a long time, this was already the sixth iteration. The patches include many improvements, my favourite is that module-loopback shouldn’t any more accumulate huge latencies if the audio consuming device (speakers) is for some reason slow to start. It’s also nice that it’s now much clearer to me how the dynamic sample rate regulation works in principle. Previously even the basic logic was unclear to me, now it works simply by measuring the end-to-end latency every now and then, and if it’s something else than desired, the sample rate is adjusted accordingly. The specifics of the regulator still go above my head, but according to Georg’s measurements, the latency should be very stable, and the new regulator should work much better than the old one.

Some of the patches were accepted, but most of the good stuff will have to wait until Georg submits the seventh iteration.

Improving default device selection

I decided to tackle bug 93006 (“headphone output is not preferred over HDMI”), even though there are release blocker bugs open and this was not one of them. I try to make occasional contributions to OpenEmbedded(/Yocto) beyond just the routine package updates, and this kind of falls into that category. My understanding is that the bug was found as part of the Yocto project’s QA process. The bug probably isn’t a serious problem for the Yocto folks, but I was motivated to fix it anyway (the problem is certainly not some weird corner case that would only affect Yocto).

So the problem was that the default sink was chosen badly. Headphones should be preferred over HDMI by default. Sinks have a priority value assigned to them, and the priorities are used to determine which sink is the default. Obviously there was something wrong with the priorities.

Headphone and HDMI output priorities are actually associated with ports, not sinks. The headphone port already has a higher priority than the HDMI port, so that was not the issue, but when the default sink is chosen, only sink priorities matter and the port priorities are ignored. I figured that there’s no need to have separate priorities for sinks and ports, so I changed things so that the sink priority is always the same as the priority of the active port. If a sink has multiple ports, the sink’s priority changes when changing the port.

My patches haven’t been reviewed yet, which means that the fix won’t be in the upcoming 10.0 release.

There’s still the problem that if the default sink changes, existing streams don’t get automatically moved to the new default sink (except when using Gnome’s sound settings application). So in the case of HDMI and headphones, my patches fix things so that after headphones are plugged in, new streams will correctly be routed to headphones, but it’s still so that streams that play to HDMI at the time when headphones are plugged in don’t get automatically moved to headphones. I plan to fix this during this month. This behaviour has annoyed me for a long time, so I’m excited to finally make it right.

Enabling memfd by default

PulseAudio 9.0 got the ability to use memfd for shared memory, but the feature wasn’t enabled by default. We want to enable it in 10.0, so I made a simple patch for that. Phoronix created a news story about that, which seemed funny, because users won’t notice any change (with the exception of firejail users, since firejail isn’t compatible with PulseAudio’s old shared memory mechanism). I guess it’s kind of newsworthy, though, since it’s a step towards really useful stuff like safe audio access for untrusted sandboxed applications.

Unfortunately, a serious problem was found relating to memfd. It turned out that 32-bit applications don’t work with 64-bit server if memfd is enabled. This is considered a release blocker bug, so either this will be fixed, or memfd can’t be enabled by default after all. The bug report is here: 67769.

Squashing release blocker bugs

I made some good progress on fixing the bugs that are blocking the 10.0 release. The master branch was frozen on 2016-09-22, but there’s no release candidate yet, because some release blocker bugs are still lacking a fix. Here are the bugs that got attention from me last month:

The new openssl 1.1.0 release is not compatible with code that was written against older versions, so I had to make some changes in module-raop-sink to make it compatible with both old and new openssl versions. It seems weird that an established project like openssl does something like this – libraries should in principle never break compatibility in this way, but I’d guess there was some very good reason for this. I expect distributions to have a lot of fun with transitioning all software to the new openssl version. At least PulseAudio is ready for that transition.

Running out of file descriptors makes the server crash. Fix submitted.

module-rtp-recv crashes when receiving an eight-channel audio stream. Fix submitted.

On some systems unloading a module also removes the module from the memory, which causes crashing if a module unloads itself (this has happened at least with module-bluez5-device). I submitted a fix that makes it safe for a module to unload itself.

The new automatic switching of bluetooth profiles makes the server crash if the bluetooth headset is the only audio device in the system. I started to investigate this, but at the time of writing I don’t have a fix, or even know why the crash happens.

libsamplerate update

On Monday 2016-09-19 the OpenEmbedded recipe reporting system reported that libsamplerate had got a new release (the first new release in years, by the way). That was surprising, since I’m on the libsamplerate mailing list and there was no release announcement (the recipe reporting system found out about the release by monitoring the libsamplerate download page). Nevertheless, I started the usual package update process.

The new release has a new optional dependency on alsa-lib, but the configure script warned about unsupported options when trying to enable or disable the alsa code. Those warnings turned out to be harmless, but I anyway submitted a fix for the configure script to get rid of the warnings.

The current status is weird. I have the package update ready for OpenEmbedded, but the new release has been removed from the libsamplerate web site. The release seemed a bit unfinished from the very start, so I guess the libsamplerate maintainer decided to pull the new release until he has time to do the release properly. The maintainer was travelling last week, but I’d expect something to happen this week.

Miscellaneous patch reviews

Sylvain Baubeau: “Use local icon for zeroconf shared devices” – This improves (in some situations) the device icon shown in GUIs for remote devices. Accepted.

Sylvain Baubeau: “module-gsettings: new module to store configuration using gsettings” – This helps us get rid of the gconf dependency of paprefs (gconf is a dead project). I didn’t review the code in detail, because it was very unclear how the data transition is supposed to be done without causing trouble for paprefs users with old configuration stored in gconf. The discussion is still ongoing, but I expect this to move forward soon.

Jan Steffens: “launch: Remove the already implicit After=pulseaudio.socket” – Cleanup for our systemd service file. Accepted.

Marcin Lewandowski: “core-util: log error if we hit file descriptors limit” – Accepted.

Pali Rohár: “bluetooth: Add support for automatic switch between hsp and a2dp profiles also for bluez5” – PulseAudio 10.0 will have a new feature for automatically switching bluetooth headsets to HSP mode when starting a VoIP call. I haven’t tested this myself, but I hope that this will be a big usability improvement for people that use bluetooth headsets for VoIP calls. This particular patch just adds bluez5 support, because at first this was supported only with bluez4. Accepted.

Pali Rohár: “bluetooth: bluez5: Add profile name to sinks and sources” – This makes A2DP and HSP volumes separate. I hope that’s a good thing. Accepted.

Deepak Srivastava: “xen: Fixed possible memory leak.” – Accepted.

Philip Withnall: “zeroconf-discover: fix a memory leak” – Accepted.

Other things

As usual, some of my time went to responding to questions on the mailing list bug tracker and IRC.

Setting up Patreon and the blog took a significant chunk of time, more than I expected. I expected to launch in September, but I still have things to do before that can happen.

I upgraded my “desktop” computer, a Raspberry Pi 2, from the old Wheezy based Raspbian to the newest release. As was recommended, I did the upgrade by installing the system from scratch. There were some issues with setting up the keyboard layout, so I got an opportunity to contribute to a new project – I submitted a fix for raspberrypi-ui-mods.

Last words

This turned out to be a rather lengthy post. This whole monthly summary thing is new to me – did you like the format? Should there be more or less detail? Would it be better to write two posts per month so that the individual posts would be shorter? Let me know in the comments.

This post was originally written on 2016-10-03, and first made available to my Patreon supporters. In the future these monthly reports will appear on my blog with much less delay than this one. Speaking of Patreon – I’m using crowdfunding in an attempt to make it financially sustainable to continue my volunteer work as a PulseAudio maintainer. If you’d like to help, check out my Patreon page.