Integrating Pulseaudio with YOCTO Recipe

Hi everyone,

I’m working on integrating the Pulseaudio package into my YOCTO-based system and facing similar issues as discussed in this post. Here is the approach I have taken:

In my local.conf file, I have added the following lines to include Pulseaudio:

IMAGE_INSTALL:append = “ pulseaudio pulseaudio-server pulseaudio-misc”
DISTRO_FEATURES:append = “ pulseaudio”

Additionally, in ./layers/openembedded-core/meta/recipes-multimedia/pulseaudio/pulseaudio.inc, I included the necessary configurations to enable WebRTC audio processing:

EXTRA_OEMESON += “-Dwebrtc-aec=enabled”
EXTRA_OECONF += “--enable-webrtc-aec”
DEPENDS += “webrtc-audio-processing”
RDEPENDS:pulseaudio-server = " \
    pulseaudio-module-echo-cancel \
    ...... \

After building the image and deploying it, Pulseaudio is successfully integrated on the board. Here is the list of available Pulseaudio modules, confirmed by running pactl list modules short:

0       module-device-restore
1       module-stream-restore
2       module-card-restore
3       module-augment-properties
4       module-switch-on-port-available
5       module-udev-detect      tsched=0
6       module-native-protocol-unix
7       module-default-device-restore
9       module-always-sink
10      module-null-sink        sink_name=auto_null sink_properties='device.description="Dummy Output"'
11      module-intended-roles
12      module-suspend-on-idle
13      module-position-event-sounds
14      module-role-cork
15      module-filter-heuristics
16      module-filter-apply

To run Pulseaudio, I created a non-root user named test. Here are the commands I used:

adduser test
usermod -aG audio test
pulseaudio --kill
pulseaudio --start

I then tested the audio playback using aplay -l as the test user, and it successfully listed the device:

aplay -l
**** List of PLAYBACK Hardware Devices ****
card 0: imx8mmwm8904 [imx8mm-wm8904], device 0: 30020000.sai-wm8904-hifi wm8904-hifi-0 [30020000.sai-wm8904-hifi wm8904-hifi-0]
  Subdevices: 0/1
  Subdevice #0: subdevice #0

However, when I run pactl list cards, it doesn’t show any cards:

pactl list cards

Additionally, I noticed the following behavior with audio playback:

  • When running aplay test_audio.wav as the test user, I encounter the following error:
    ALSA lib ../../../alsa-lib-1.2.6.1/src/pcm/pcm_dmix.c:1032:(snd_pcm_dmix_open) unable to open slave
    aplay: main:831: audio open error: Device or resource busy
  • When running paplay test_audio.wav as the test user, no sound is heard.
  • However, when running aplay test_audio.wav as the root user, the audio plays correctly.

If anyone has further insights or suggestions for optimizing this setup, your input would be greatly appreciated.

Best regards,
Ferran

Hi, I’m the Toradex AI Assistant. I’m in early beta, and I would appreciate your feedback.
The Toradex Support team will follow up with you shortly!

Did you like my answer?

:+1: :-1:


Hello Ferran,

Integrating PulseAudio into a Yocto-based system and ensuring it works correctly with your hardware can indeed present some challenges. Based on the details you’ve provided, it seems like you’ve successfully integrated PulseAudio into your system, but are encountering issues with device recognition and audio playback under a non-root user.

Here are a few suggestions and insights that might help you optimize your setup:

  1. PulseAudio Configuration for Non-Root Users: PulseAudio is designed to run per-user, not system-wide by default, although it can be configured to run system-wide if necessary. Since you’re starting PulseAudio as a non-root user (test), ensure that the user has the correct permissions to access the audio devices. You’ve already added the user to the audio group, which is a good step. Also, verify that the home directory for the user test is properly set up and that PulseAudio’s user configuration files are correctly placed in the user’s home directory.

  2. Device or Resource Busy Error: This error typically indicates that the audio device is being used by another process. Since PulseAudio is running, it might be taking exclusive control of the audio device, preventing aplay from accessing it directly. This is expected behavior when PulseAudio is in use, as applications should communicate with PulseAudio rather than directly with ALSA. Ensure that PulseAudio is correctly configured to manage the device and that applications use PulseAudio for playback.

  3. No Sound with paplay: If paplay doesn’t produce sound, it could be due to PulseAudio not correctly recognizing or configuring the audio hardware. This might be related to the issue with pactl list cards not showing any cards. Ensure that PulseAudio is correctly configured to recognize and use your audio hardware. You might need to manually configure PulseAudio modules for your specific hardware in /etc/pulse/default.pa or ~/.config/pulse/default.pa (for the test user).

  4. PulseAudio Module Configuration: Since you’re using specific PulseAudio modules for WebRTC audio processing and echo cancellation, ensure these modules are correctly loaded and configured. You can manually load a module using pactl load-module <module-name> and verify its status with pactl list modules short. This might help in diagnosing why the audio cards are not listed.

  5. Debugging PulseAudio: PulseAudio offers extensive debugging capabilities. You can increase the

Please, also check if these links can help you solve your problem:

Audio (Linux) | Toradex Developer Center.

Hello @ferranmc,

I apologize for the delay on this topic.

Thanks for the additional information about this issue.
We did some investigation into the problem in the linked post.

We were initially unable to use the HFP profile with pulseaudio.
Therefore we did not reproduce the exact problem that you have.

That being said, one of our domain experts is looking into the echo problem and is working to reproduce the problem, so updates are expected soon.

Best Regards,
Bruno

Hi @bruno.tx,
I don’t understand why they can’t reproduce the bug. Using your BSP and making the modifications I mention in the recipes you should get the same failure. So far we have not tried to use HFP profile with pulseaudio either.

As @ferranmc says, we have detected another bug. After creating a new user, the developers of pulseaudio advise against using the root user, we are not able to listen to the playback of an audio file.

adduser test
usermod -aG audio test
pulseaudio --kill
pulseaudio --start
paplay test_audio.wav

When listing the sound cards from pulseaudio, we see that the result is null. We understand that this may be the reason for not being able to listen to the audio.

pactl list cards

Does the same thing happen to you? Could you help us with this bug?

Best regards,
Julián

Hello @bruno.tx,

I managed to get PulseAudio working by stopping the BlueALSA service. Once that was done, it could be used from the test user.

Run as root:

systemctl stop bluealsa

Run as the test user:

pulseaudio --kill
pulseaudio --start

pactl list cards
Sink Input #5
        Driver: protocol-native.c
        Owner Module: 7
        Client: 8
        Sink: 0
        Sample Specification: s16le 2ch 22050Hz
        Channel Map: front-left,front-right
        Format: pcm, format.sample_format = "\"s16le\""  format.rate = "22050"  format.channels = "2"  format.channel_map = "\"front-left,front-right\""
        Corked: no
        Mute: no
        Volume: front-left: 65536 / 100% / 0.00 dB,   front-right: 65536 / 100% / 0.00 dB
                balance 0.00
        Buffer Latency: 0 usec
        Sink Latency: 78870 usec
        Resample method: ffmpeg
        Properties:
                application.name = "paplay"
                media.name = "paplay"
                native-protocol.peer = "UNIX socket client"
                native-protocol.version = "35"
                application.process.id = "1962"
                application.process.user = "antonio"
                application.process.host = "NIIRA-06894995"
                application.process.binary = "pacat"
                application.language = "C"
                window.x11.display = ":0.0"
                application.process.machine_id = "4d69720a3de04e4c8d35f1bafdcc1849"
                module-stream-restore.id = "sink-input-by-application-name:paplay"

Sink Input #10
        Driver: protocol-native.c
        Owner Module: 7
NIIRA-06894995:~$ pactl list cards
Card #0
        Name: alsa_card.platform-sound-card
        Driver: module-alsa-card.c
        Owner Module: 6
        Properties:
                alsa.card = "0"
                alsa.card_name = "imx8mm-wm8904"
                alsa.long_card_name = "imx8mm-wm8904"
                device.bus_path = "platform-sound-card"
                sysfs.path = "/devices/platform/sound-card/sound/card0"
                device.form_factor = "internal"
                device.string = "0"
                device.description = "Built-in Audio"
                module-udev-detect.discovered = "1"
                device.icon_name = "audio-card"
        Profiles:
                input:stereo-fallback: Stereo Input (sinks: 0, sources: 1, priority: 51, available: yes)
                output:stereo-fallback: Stereo Output (sinks: 1, sources: 0, priority: 5100, available: yes)
                output:stereo-fallback+input:stereo-fallback: Stereo Output + Stereo Input (sinks: 1, sources: 1, priority: 5151, available: yes)
                off: Off (sinks: 0, sources: 0, priority: 0, available: yes)
        Active Profile: output:stereo-fallback+input:stereo-fallback
        Ports:
                analog-input: Analog Input (type: Analog, priority: 10000, latency offset: 0 usec, availability unknown)                        Part of profile(s): input:stereo-fallback, output:stereo-fallback+input:stereo-fallback
                analog-output-headphones: Headphones (type: Headphones, priority: 9900, latency offset: 0 usec, availability unknown)
                        Properties:
                                device.icon_nam

Now my question is, how can I use Bluetooth with PulseAudio? Can you recommend anything?

Hello @ferranmc,

Thanks for the update.

I am glad you were able to get pulseaudio to work from another user.
In the related post I also mentioned that an empty output from pactl list cards can also be caused by a device tree misconfiguration.

You should be able to still use bluealsa together with pulseaudio using the module-alsa-sink, but let’s continue that conversation on your new post about this specific topic.

Best Regards,
Bruno