The aplay command doesn't work

Bug #1598309 reported by Bruno Nova
24
This bug affects 4 people
Affects Status Importance Assigned to Milestone
snapd (Ubuntu)
Fix Released
Medium
Jamie Strandboge

Bug Description

Running the "aplay" command inside a snap with the pulseaudio interface and the "alsa-utils" package bundled doesn't work, even with snapd 2.0.10.
It throws this error:

ALSA lib conf.c:3750:(snd_config_update_r) Cannot access file /usr/share/alsa/alsa.conf
ALSA lib pcm.c:2266:(snd_pcm_open_noupdate) Unknown PCM default
aplay: main:722: audio open error: No such file or directory

Maybe an "alsa" interface is needed, or the "pulseaudio" interface needs to grant access to more things.

Bruno Nova (brunonova)
tags: added: xenial
Revision history for this message
Oliver Grawert (ogra) wrote :

did you try shipping libasound2-data in your stage-packages and set ALSA_CONFIG_PATH [1] in a wrapper ?
/usr/share/alsa/alsa.conf is a generic file, you do not necessarily need to access the one from the host machine.

[1] http://www.alsa-project.org/main/index.php/LibEnvVars

Revision history for this message
Bruno Nova (brunonova) wrote :

Tried that now. There's a new error:

ALSA lib conf.c:3544:(snd_config_hook_load) cannot stat file/directory /usr/share/alsa/cards/aliases.conf
ALSA lib pcm.c:2266:(snd_pcm_open_noupdate) Unknown PCM cards.pcm.default
aplay: main:722: audio open error: No such file or directory

The config file declares that path, along with other ones, relative to "{ @func datadir }".
This may require bundling custom alsa config files, or could that "datadir" be overridden by an environment variable?

Revision history for this message
Launchpad Janitor (janitor) wrote :

Status changed to 'Confirmed' because the bug affects multiple users.

Changed in snapd (Ubuntu):
status: New → Confirmed
tags: added: snapd-interface
Revision history for this message
Jamie Strandboge (jdstrand) wrote :

Note that if the alsa packaging issues are resolved then direct access to /dev/snd/* devices will be needed as well. These aren't (and shouldn't) be included in pulseaudio because with pulseaudio snaps talk to pulseaudio and it is pulseaudio that has direct hardware access (this also happens to be a secure way of handling audio-- in general it is much better when you don't have to hand out device files to snaps). In other words, if direct alsa access is deemed worthwhile, it should be its own interface.

Changed in snapd (Ubuntu):
importance: Undecided → Medium
Changed in snapd (Ubuntu):
assignee: nobody → Jamie Strandboge (jdstrand)
status: Confirmed → In Progress
Revision history for this message
Jamie Strandboge (jdstrand) wrote :

@Bruno - I looked into this a little bit and ALSA doesn't allow you to override the ALSA_CONFIG_DIR in the default configuration. However, your snap can ship a configuration that you point ALSA_CONFIG_PATH at and that configuration file can be setup to work. I'm not an ALSA developer and have only sketched out the following snap so that I might develop security policy for an alsa interface: https://git.launchpad.net/~jdstrand/+git/alsa-utils?h=master

What it does is:
- ship a wrapper in files/bin/wrapper that sets ALSA_CONFIG_PATH="$SNAP/etc/alsa.conf"
- ship files/etc/alsa.conf that is a modified version of /usr/share/alsa/alsa.conf that substitutes references to datadir with values in /snap/alsa-utils/current. ALSA supports 'getenv' in the configuration files so it shouldn't be too much work for someone to getenv the $SNAP dir instead of hard-coding /snap/alsa-utils/current
- ships files/etc/alsa/cards/* that are modified versions of /usr/share/alsa/cards/* that replace 'confdir:pcm' with '/snap/alsa-utils/current/usr/share/alsa/pcm'

With the above, in devmode can:

$ alsa-utils.speaker-test
$ alsa-utils.aplay /snap/alsa-utils/current/usr/share/sounds/alsa/Noise.wav
$ alsa-utils.arecord ~/snap/alsa-utils/common/out.wav
$ alsa-utils.aplay ~/snap/alsa-utils/common/out.wav

I suspect a snapcraft part would be worthwhile for setting up the wrapper, alsa.conf and sed'ing the /usr/share/alsa/cards/*.conf files?

Revision history for this message
Jamie Strandboge (jdstrand) wrote :

A new alsa interface is now committed to trunk.

Changed in snapd (Ubuntu):
status: In Progress → Fix Committed
Revision history for this message
Launchpad Janitor (janitor) wrote :

This bug was fixed in the package snapd - 2.18+17.04ubuntu3

---------------
snapd (2.18+17.04ubuntu3) zesty; urgency=medium

  * disable ppc64el autopkgtest for now, it never worked but for
    some reason autopkgtest thinks it did at some point and asking
    for correction of the DB was not successful so far

 -- Michael Vogt <email address hidden> Fri, 02 Dec 2016 16:27:34 +0100

Changed in snapd (Ubuntu):
status: Fix Committed → Fix Released
Revision history for this message
Ads20000 (ads20000) wrote :

Hi, I'm attempting to snap [Spotify Web Player for Linux](https://github.com/Quacky2200/Spotify-Web-Player-for-Linux) using Electron Builder (and making custom modifications to the snapcraft.yaml file where necessary) and sound doesn't work and I still get the `ALSA lib conf.c:3759:(snd_config_update_r) Cannot access file /usr/share/alsa/alsa.conf` messages even after using devmode and adding the pulseaudio and alsa plugs. The snapcraft.yaml I'm using (generated by Electron Builder and then modified) is [here](https://gist.github.com/Ads20000/5685a7197bb94881878ad1d1beba62c2).

Revision history for this message
Jamie Strandboge (jdstrand) wrote :

@Ads20000, devmode won't help because /usr/share/alsa/alsa.conf isn't in the core snap. See https://bugs.launchpad.net/ubuntu/+source/snapd/+bug/1598309/comments/5 for what you need to do to make ALSA look in the right place for its configuration.

I think someone may have been working on a snapcraft part to make this easier for people. Perhaps file a new bug about making it easier to use ALSA and/or ask on the mailing list/rocket/irc on the status of that work?

Revision history for this message
Ads20000 (ads20000) wrote :

I'm really sorry Jamie I missed that comment and so I didn't follow up, will bring it up on Rocket tomorrow. I'm working with Martin Wimpress to Snap that app now and he said just to use pulseaudio as a plug and a build-depend, that gets sound to work.
I guess it would be good if ALSA worked easily too so I will mention that to the Snapcraft team in Rocket tomorrow.

Revision history for this message
Ads20000 (ads20000) wrote :

*stage-package, not build-depend, I keep saying that...

Revision history for this message
Dev (devtobo) wrote :

I have an electron snap package deployed and when installing on a Ubuntu 14.04LTS, I have the same issue:

ALSA lib conf.c:3750:(snd_config_update_r) Cannot access file /usr/share/alsa/alsa.conf
ALSA lib pcm.c:2266:(snd_pcm_open_noupdate) Unknown PCM default
ALSA lib conf.c:3750:(snd_config_update_r) Cannot access file /usr/share/alsa/alsa.conf
ALSA lib pcm.c:2266:(snd_pcm_open_noupdate) Unknown PCM plug:default

snap.yaml is:
apps:
  bayam:
    command: command-bayam.wrapper
    plugs:
    - home
    - x11
    - unity7
    - browser-support
    - network
    - gsettings
    - pulseaudio
    - opengl

Revision history for this message
Dev (devtobo) wrote :

Thanks @ads20000!
Adding stage-package: "pulseaudio" fix this issue.

Revision history for this message
Nikolay (2xl) wrote :

Hello, sample(with alsa-util) in the begging of this thread doesnt work for me.
$ alsa-utils.speaker-test

speaker-test 1.1.0

Playback device is default
Stream parameters are 48000Hz, S16_LE, 1 channels
Using 16 octaves of pink noise
ALSA lib pcm_dmix.c:1029:(snd_pcm_dmix_open) unable to open slave
Playback open error: -2,No such file or directory

I added pulseaudio into stage packages and it doesn't work too.
$ alsa-utils.speaker-test

speaker-test 1.1.0

Playback device is default
Stream parameters are 48000Hz, S16_LE, 1 channels
Using 16 octaves of pink noise
ALSA lib conf.c:3357:(snd_config_hooks_call) Cannot open shared library libasound_module_conf_pulse.so
ALSA lib pcm.c:2266:(snd_pcm_open_noupdate) Unknown PCM default
Playback open error: -2,No such file or directory

I'm using snan on amd64 machine.
$ snap version
snap 2.21
snapd 2.21
series 16
ubuntu 16.04

Revision history for this message
Oliver Grawert (ogra) wrote :

did you connect the alsa interface to your snap ?

Revision history for this message
Nikolay (2xl) wrote :

No, I didn't...
After I ran
sudo snap connect alsa-utils:alsa :alsa
alsa-utils.speaker-test works for me. Thank you, Oliver.

Revision history for this message
Jamie Strandboge (jdstrand) wrote :

FYI, Martin posted this to the forum recently that should make things easier: https://forum.snapcraft.io/t/reusable-alsa-lib-part/3556

To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.