Snap can't produce sound without pulseaudio

Hello everyone. The snap I am working on used to play sound in ubuntu core using pulseaudio, but since it is too old, and as suggested by @ogra we are thinking of dropping pulseaudio and use only alsa since it is the base audio system and is well maintained. But I can’t seem to make it work. Any help would be really appreciated.

Here is the current snapcraft.yaml

name: cluemaster-mediadisplay-core 
base: core20 
version: "0.1"
summary: summary
description: description
grade: stable 
confinement: strict 

apps:
  cluemaster-mediadisplay-core:
    daemon: simple
    restart-condition: always
    command-chain:
      - env-setup
    command: usr/local/bin/x11_kiosk_launch $SNAP/bin/desktop-launch $SNAP/bin/prepare-launch $SNAP/cluemaster_display
    plugs:
      - home
      - desktop
      - wayland
      - x11
      - network
      - opengl
      - network-bind
      - audio-playback
      - shutdown
      - process-control
      - mount-observe
      - network-control
      - alsa
    environment:
      DISABLE_WAYLAND: 1

parts:
  copy-source-code:
    after: [desktop-qt5]
    plugin: dump
    source: cluemaster_display/
    stage-packages:
      - ffmpeg
      - libass9
      - mpv
      - alsa-base
      - locales
      - libvdpau1
      - i965-va-driver
      - libmpv1
      - va-driver-all
      - vdpau-driver-all
      - mesa-va-drivers
      - libvdpau-va-gl1
      - libglu1-mesa
      - samba-libs
      - git
      - python3-dbus
      - qtwayland5
      - mesa-utils
      - libgl1-mesa-dri
      - python3-pyqt5.qtmultimedia
      - libqt5multimedia5-plugins
      
    stage-snaps: [mir-kiosk-x11]

  extras:
    plugin: dump
    source: static/
    organize: 
      "prepare-launch": "bin/"

  desktop-qt5:
    source: https://github.com/ubuntu/snapcraft-desktop-helpers.git
    source-subdir: qt
    plugin: make
    make-parameters: ["FLAVOR=qt5"]
    build-packages:
      - build-essential
      - qtbase5-dev
      - dpkg-dev
    stage-packages:
      - libxkbcommon0
      - ttf-ubuntu-font-family
      - dmz-cursor-theme
      - light-themes
      - adwaita-icon-theme
      - gnome-themes-standard
      - shared-mime-info
      - libqt5gui5
      - libgdk-pixbuf2.0-0
      - libqt5svg5 # for loading icon themes which are svg
      - try: [appmenu-qt5] # not available on core18
      - locales-all
      - xdg-user-dirs
      - libdrm2
      - libgbm1
      - fcitx-frontend-qt5

    stage:
      - -usr/lib/x86_64-linux-gnu/dri/d3d12_dri.so
      - -usr/lib/x86_64-linux-gnu/dri/i915_dri.so
      - -usr/lib/x86_64-linux-gnu/dri/i965_dri.so
      - -usr/lib/x86_64-linux-gnu/dri/iris_dri.so
      - -usr/lib/x86_64-linux-gnu/dri/kms_swrast_dri.so
      - -usr/lib/x86_64-linux-gnu/dri/nouveau_dri.so
      - -usr/lib/x86_64-linux-gnu/dri/nouveau_vieux_dri.so
      - -usr/lib/x86_64-linux-gnu/dri/r200_dri.so
      - -usr/lib/x86_64-linux-gnu/dri/r300_dri.so
      - -usr/lib/x86_64-linux-gnu/dri/r600_dri.so
      - -usr/lib/x86_64-linux-gnu/dri/radeon_dri.so
      - -usr/lib/x86_64-linux-gnu/dri/radeonsi_dri.so
      - -usr/lib/x86_64-linux-gnu/dri/swrast_dri.so
      - -usr/lib/x86_64-linux-gnu/dri/virtio_gpu_dri.so
      - -usr/lib/x86_64-linux-gnu/dri/vmwgfx_dri.so
      - -usr/lib/x86_64-linux-gnu/dri/zink_dri.so
      - -usr/lib/x86_64-linux-gnu/libLLVM-12.so.1
      - -usr/lib/x86_64-linux-gnu/libdrm_intel.so.1.0.0
      - -usr/lib/x86_64-linux-gnu/libtiff.so.5.5.0
      - -usr/share/doc/libdrm-common/changelog.Debian.gz
      - -usr/share/doc/libdrm2/changelog.Debian.gz
      - -usr/share/doc/libgbm1/changelog.Debian.gz
      - -usr/share/doc/libglapi-mesa/changelog.Debian.gz
      - -usr/share/doc/libllvm12/changelog.Debian.gz
      - -usr/share/doc/libtiff5/changelog.Debian.gz


layout:
  /usr/share/X11:
    bind: $SNAP/usr/share/X11
  /usr/bin/xkbcomp:
    symlink: $SNAP/usr/bin/xkbcomp
  /usr/share/icons:
    bind: $SNAP/usr/share/icons
  /usr/share/fonts:
    bind: $SNAP/usr/share/fonts
  /usr/local/share/fonts:
    bind: $SNAP/usr/local/share/fonts
  /etc/fonts:
    bind: $SNAP/etc/fonts

i did some work on a newer version of pulseaudio, you could try building:

… and see if that makes your app work …

Hi @ogra. Thanks for the reply. Would you like me to build it and then connect its interfaces with the cluemaster-mediadisplay-core snap interfaces? Sorry for these silly questions, I am not that advanced in snapcrafting and the related topics. Thanks

Hi @ogra. I snapped the pulse-server and the audio-playback of the cluemaster app successfully connected with that of the pulse-server. But it didn’t produce any sound. I think it is muted.

I tried to run the command

sudo pulse-server.pactl list sinks

But I got the following output

Failed to create secure directory (/var/run/pulse): Permission denied
Connection failure: Connection refused
pa_context_connect() failed: Connection refused

Any idea, how to access the sinks? Thanks in advance

I fixed this issue by restarting the pulseaudio service. It was not running. Here is the output

Sink #0
	State: SUSPENDED
	Name: auto_null
	Description: Dummy Output
	Driver: module-null-sink.c
	Sample Specification: s16le 2ch 44100Hz
	Channel Map: front-left,front-right
	Owner Module: 12
	Mute: no
	Volume: front-left: 65536 / 100% / 0.00 dB,   front-right: 65536 / 100% / 0.00 dB
	        balance 0.00
	Base Volume: 65536 / 100% / 0.00 dB
	Monitor Source: auto_null.monitor
	Latency: 0 usec, configured 0 usec
	Flags: DECIBEL_VOLUME LATENCY SET_FORMATS 
	Properties:
		device.description = "Dummy Output"
		device.class = "abstract"
		device.icon_name = "audio-card"
	Formats:
		pcm

Looks like the sink is not mute, but the state of the sink is “SUSPENDED”

that does not look like a physical sink …

what is the full output of:

sudo pulse-server.pactl list sinks

Hi @ogra. Sorry for the late reply. I fixed it by running the following command

snap connect pulse-server:alsa :alsa

and

snap connect pulse-server:hardware-observe :hardware-observe

and restarted the snap. Now I am getting the correct audio device

Sink #0
	State: SUSPENDED
	Name: alsa_output.pci-0000_00_05.0.analog-stereo
	Description: Built-in Audio Analog Stereo
	Driver: module-alsa-card.c
	Sample Specification: s16le 2ch 48000Hz
	Channel Map: front-left,front-right
	Owner Module: 6
	Mute: yes
	Volume: front-left: 1847 /   3% / -93.00 dB,   front-right: 1847 /   3% / -93.00 dB
	        balance 0.00
	Base Volume: 65536 / 100% / 0.00 dB
	Monitor Source: alsa_output.pci-0000_00_05.0.analog-stereo.monitor
	Latency: 0 usec, configured 0 usec
	Flags: HARDWARE HW_MUTE_CTRL HW_VOLUME_CTRL DECIBEL_VOLUME LATENCY 
	Properties:
		alsa.resolution_bits = "16"
		device.api = "alsa"
		device.class = "sound"
		alsa.class = "generic"
		alsa.subclass = "generic-mix"
		alsa.name = "Intel 82801AA-ICH"
		alsa.id = "Intel ICH"
		alsa.subdevice = "0"
		alsa.subdevice_name = "subdevice #0"
		alsa.device = "0"
		alsa.card = "0"
		alsa.card_name = "Intel 82801AA-ICH"
		alsa.long_card_name = "Intel 82801AA-ICH with AD1980 at irq 21"
		alsa.driver_name = "snd_intel8x0"
		device.bus_path = "pci-0000:00:05.0"
		sysfs.path = "/devices/pci0000:00/0000:00:05.0/sound/card0"
		device.bus = "pci"
		device.vendor.id = "8086"
		device.vendor.name = "Intel Corporation"
		device.product.id = "2415"
		device.product.name = "82801AA AC'97 Audio Controller"
		device.form_factor = "internal"
		device.string = "front:0"
		device.buffering.buffer_size = "19188"
		device.buffering.fragment_size = "6396"
		device.access_mode = "mmap"
		device.profile.name = "analog-stereo"
		device.profile.description = "Analog Stereo"
		device.description = "Built-in Audio Analog Stereo"
		module-udev-detect.discovered = "1"
		device.icon_name = "audio-card-pci"
	Ports:
		analog-output;output-amplifier-on: Analog Output / Amplifier (type: Analog, priority: 9910, availability unknown)
		analog-output;output-amplifier-off: Analog Output / No Amplifier (type: Analog, priority: 9900, availability unknown)
	Active Port: analog-output;output-amplifier-on
	Formats:
		pcm

1 Like

Hi @ogra. I am trying to integrate pulse-server into the snap I am working on. So the audio system is independent. Here is the snapcraft.yaml

name: cluemaster-mediadisplay-core 
base: core20 
version: '0.1'
description: decription
   
grade: stable 
confinement: strict
compression: lzo

apps:
  cluemaster-mediadisplay-core:
    daemon: simple
    restart-condition: always
    command-chain:
      - env-setup
    command: usr/local/bin/x11_kiosk_launch $SNAP/bin/desktop-launch $SNAP/bin/prepare-launch $SNAP/cluemaster_display
    plugs:
      - home
      - desktop
      - wayland
      - x11
      - network
      - opengl
      - network-bind
      - audio-playback
      - shutdown
      - process-control
      - mount-observe
      - network-control
      - alsa
      - hardware-observe
    environment:
      DISABLE_WAYLAND: 1
      
  pulseaudio:
    command: bin/pulseaudio
    daemon: simple
    install-mode: disable
    plugs:
      - alsa
      - bluez
      - hardware-observe
      - network
      - network-bind
    slots:
      - audio-playback
      - audio-record
  pactl:
    command-chain: [bin/client-wrapper]
    command: usr/bin/pactl
    plugs:
      - network
      - playback
      - record
  paplay:
    command-chain: [bin/client-wrapper]
    command: usr/bin/paplay
    plugs:
      - home
      - network
      - playback
  parec:
    command-chain: [bin/client-wrapper]
    command: usr/bin/parec
    plugs:
      - home
      - network
      - playback
      - record
  config:
    command: bin/config

parts:
  copy-source-code:
    after: [desktop-qt5]
    plugin: dump
    source: cluemaster_display/
    stage-packages:
      - ffmpeg
      - libass9
      - mpv
      - locales
      - libvdpau1
      - i965-va-driver
      - libmpv1
      - va-driver-all
      - vdpau-driver-all
      - mesa-va-drivers
      - libvdpau-va-gl1
      - libglu1-mesa
      - samba-libs
      - git
      - python3-dbus
      - qtwayland5
      - mesa-utils
      - libgl1-mesa-dri
      - python3-pyqt5.qtmultimedia
      - libqt5multimedia5-plugins
      
    stage:
      - -usr/share/alsa/alsa.conf
      - -usr/share/alsa/cards/HDA-Intel.conf
      - -usr/share/alsa/cards/USB-Audio.conf
      - -usr/share/alsa/cards/aliases.conf
      - -usr/share/alsa/pcm/center_lfe.conf
      - -usr/share/alsa/pcm/default.conf
      - -usr/share/alsa/pcm/dmix.conf
      - -usr/share/alsa/pcm/dsnoop.conf
      - -usr/share/alsa/pcm/front.conf
      - -usr/share/alsa/pcm/hdmi.conf
      - -usr/share/alsa/pcm/iec958.conf
      - -usr/share/alsa/pcm/modem.conf
      - -usr/share/alsa/pcm/rear.conf
      - -usr/share/alsa/pcm/side.conf
      - -usr/share/alsa/pcm/surround21.conf
      - -usr/share/alsa/pcm/surround40.conf
      - -usr/share/alsa/pcm/surround41.conf
      - -usr/share/alsa/pcm/surround50.conf
      - -usr/share/alsa/pcm/surround51.conf
      - -usr/share/alsa/pcm/surround71.conf
      - -usr/lib/x86_64-linux-gnu/libicudata.so.66.1
      - -usr/lib/x86_64-linux-gnu/libicui18n.so.66.1
      - -usr/lib/x86_64-linux-gnu/libicuio.so.66.1
      - -usr/lib/x86_64-linux-gnu/libicutest.so.66.1
      - -usr/lib/x86_64-linux-gnu/libicutu.so.66.1
      - -usr/lib/x86_64-linux-gnu/libicuuc.so.66.1
      - -usr/share/doc/libicu66/changelog.Debian.gz
      - -usr/lib/x86_64-linux-gnu/libtdb.so.1
      - -usr/share/doc/libtdb1/changelog.Debian.gz


      
    stage-snaps: [mir-kiosk-x11]

  extras:
    plugin: dump
    source: static/
    organize: 
      "prepare-launch": "bin/"

  desktop-qt5:
    source: https://github.com/ubuntu/snapcraft-desktop-helpers.git
    source-subdir: qt
    plugin: make
    make-parameters: ["FLAVOR=qt5"]
    build-packages:
      - build-essential
      - qtbase5-dev
      - dpkg-dev
    stage-packages:
      - libxkbcommon0
      - ttf-ubuntu-font-family
      - dmz-cursor-theme
      - light-themes
      - adwaita-icon-theme
      - gnome-themes-standard
      - shared-mime-info
      - libqt5gui5
      - libgdk-pixbuf2.0-0
      - libqt5svg5 # for loading icon themes which are svg
      - try: [appmenu-qt5] # not available on core18
      - locales-all
      - xdg-user-dirs
      - libdrm2
      - libgbm1
      - fcitx-frontend-qt5

    stage:
      - -usr/lib/x86_64-linux-gnu/dri/d3d12_dri.so
      - -usr/lib/x86_64-linux-gnu/dri/i915_dri.so
      - -usr/lib/x86_64-linux-gnu/dri/i965_dri.so
      - -usr/lib/x86_64-linux-gnu/dri/iris_dri.so
      - -usr/lib/x86_64-linux-gnu/dri/kms_swrast_dri.so
      - -usr/lib/x86_64-linux-gnu/dri/nouveau_dri.so
      - -usr/lib/x86_64-linux-gnu/dri/nouveau_vieux_dri.so
      - -usr/lib/x86_64-linux-gnu/dri/r200_dri.so
      - -usr/lib/x86_64-linux-gnu/dri/r300_dri.so
      - -usr/lib/x86_64-linux-gnu/dri/r600_dri.so
      - -usr/lib/x86_64-linux-gnu/dri/radeon_dri.so
      - -usr/lib/x86_64-linux-gnu/dri/radeonsi_dri.so
      - -usr/lib/x86_64-linux-gnu/dri/swrast_dri.so
      - -usr/lib/x86_64-linux-gnu/dri/virtio_gpu_dri.so
      - -usr/lib/x86_64-linux-gnu/dri/vmwgfx_dri.so
      - -usr/lib/x86_64-linux-gnu/dri/zink_dri.so
      - -usr/lib/x86_64-linux-gnu/libLLVM-12.so.1
      - -usr/lib/x86_64-linux-gnu/libdrm_intel.so.1.0.0
      - -usr/lib/x86_64-linux-gnu/libtiff.so.5.5.0
      - -usr/share/doc/libdrm-common/changelog.Debian.gz
      - -usr/share/doc/libdrm2/changelog.Debian.gz
      - -usr/share/doc/libgbm1/changelog.Debian.gz
      - -usr/share/doc/libglapi-mesa/changelog.Debian.gz
      - -usr/share/doc/libllvm12/changelog.Debian.gz
      - -usr/share/doc/libtiff5/changelog.Debian.gz
      - -usr/lib/x86_64-linux-gnu/libicudata.so.66.1
      - -usr/lib/x86_64-linux-gnu/libicui18n.so.66.1
      - -usr/lib/x86_64-linux-gnu/libicuio.so.66.1
      - -usr/lib/x86_64-linux-gnu/libicutest.so.66.1
      - -usr/lib/x86_64-linux-gnu/libicutu.so.66.1
      - -usr/lib/x86_64-linux-gnu/libicuuc.so.66.1
      - -usr/share/doc/libicu66/changelog.Debian.gz

      
  pulseaudio-common:
    source: bin
    plugin: dump
    organize:
      client-wrapper: bin/client-wrapper
      config: bin/config
      pulseaudio: bin/pulseaudio
  alsa-lib:
    plugin: autotools
    source: https://github.com/alsa-project/alsa-lib.git
    source-tag: v1.2.5.1
    prime:
      - -usr/include
      - -usr/share/aclocal
      - -usr/lib/lib*.la
      - -usr/lib/pkgconfig
  pulseaudio:
    plugin: meson
    source: https://github.com/pulseaudio/pulseaudio.git
    source-tag: v15.0
    source-depth: 1
    after: [ alsa-lib ]
    build-packages:
      - check
      - doxygen
      - intltool
      - libapparmor-dev
      - libdbus-1-dev
      - libjson-c-dev
      - libglib2.0-dev
      - libspeexdsp-dev
      - libbluetooth-dev
      - libltdl-dev
      - libsndfile1-dev
      - libtdb-dev
      - libudev-dev
      - libasyncns-dev
      - libsbc-dev
      - libsnapd-glib-dev
      - libsoxr-dev
    stage-packages:
      - libapparmor1
      - libasyncns0
      - libbluetooth3
      - libflac8
      - libglib2.0-0
      - libgomp1
      - libjson-c4
      - libltdl7
      - libogg0
      - libsbc1
      - libsnapd-glib1
      - libsndfile1
      - libsoxr0
      - libsoxr-lsr0
      - libspeexdsp1
      - libtdb1
      - libudev1
      - libvorbis0a
      - libvorbisenc2
    meson-parameters:
      - --prefix="/usr"
      - --sysconfdir=/etc
      - --libexec=/usr/lib
      - --libdir=/usr/lib
      - --localstatedir=/var
      - -Dgstreamer="disabled"
      - -Dbluez5-gstreamer="disabled"
      - -Dorc="disabled"
      - -Dgsettings="disabled"
      - -Dadrian-aec="false"
      - -Dgtk="disabled"
      - -Dhal-compat="false"
      - -Dwebrtc-aec="disabled"
      - -Doss-output="disabled"
      - -Djack="disabled"
      - -Dx11="disabled"
      - -Dsystem_user="root"
      - -Dsystem_group="root"
      - -Daccess_group="root"
    override-build: |
      snapcraftctl build
      VER=$(cd $SNAPCRAFT_PART_SRC; git tag|sed 's/^v//')
      snapcraftctl set-version $VER
      mkdir -p $SNAPCRAFT_PART_INSTALL/usr/share/applications
    override-prime: |
      snapcraftctl prime
      find usr/share/doc/ -type f,l ! -name copyright | xargs rm -rf
    prime:
      - -usr/include
      - -usr/share/zsh
      - -usr/share/bash-completion
      - -usr/share/man
      - -usr/share/GConf
      - -usr/share/lintian
      - -usr/share/vala
      - -usr/libexec
      - -usr/lib/cmake
      - -usr/lib/pkgconfig
      - -usr/lib/systemd
      - -etc/dconf
  alsa-plugins:
    plugin: autotools
    source: https://github.com/alsa-project/alsa-plugins.git
    source-tag: v1.2.5
    after: [ pulseaudio, alsa-lib ]
    autotools-configure-parameters:
      - --prefix=/usr
      - --sysconfdir=/etc
    prime:
      - -usr/lib/alsa-lib/*.la
  alsa-ucm:
    plugin: dump
    source: https://github.com/alsa-project/alsa-ucm-conf.git
    source-tag: v1.2.5.1
    after: [ alsa-plugins ]
    organize:
      ucm: usr/share/alsa/ucm
      ucm2: usr/share/alsa/ucm2
    prime:
      - -README.md
      
plugs:
  playback:
    interface: audio-playback
  record:
    interface: audio-record
    
environment:
  LD_LIBRARY_PATH: "$SNAP/usr/lib/pulseaudio:$SNAP/usr/lib/alsa-lib"
  PULSE_RUNTIME_PATH: /var/run/pulse
  PULSE_STATE_PATH: $SNAP_COMMON/state
  ALSA_CONFIG_UCM: $SNAP/usr/share/alsa/ucm2
  ALSA_CONFIG_TPLG: $SNAP/usr/share/alsa/topology
  ALSA_CONFIG_PATH: $SNAP/usr/share/alsa/alsa.conf
  ALSA_MIXER_SIMPLE: $SNAP/usr/share/alsa/smixer.conf
  ALSA_PLUGIN_DIR: $SNAP/usr/lib/alsa-lib

layout:
  /etc/pulse:
    bind: $SNAP/etc/pulse
  /etc/alsa:
    bind: $SNAP/etc/alsa
  /var/lib/pulse:
    bind: $SNAP_DATA
  /usr/lib/pulse-15.0:
    symlink: $SNAP/usr/lib/pulse-15.0
  /usr/lib/alsa-lib:
    bind: $SNAP/usr/lib/alsa-lib
  /usr/share/pulseaudio:
    symlink: $SNAP/usr/share/pulseaudio
  /usr/share/alsa:
    symlink: $SNAP/usr/share/alsa
  /usr/share/applications:
    bind: $SNAP/usr/share/applications
  /usr/share/X11:
    bind: $SNAP/usr/share/X11
  /usr/bin/xkbcomp:
    symlink: $SNAP/usr/bin/xkbcomp
  /usr/share/icons:
    bind: $SNAP/usr/share/icons
  /usr/share/fonts:
    bind: $SNAP/usr/share/fonts
  /usr/local/share/fonts:
    bind: $SNAP/usr/local/share/fonts
  /etc/fonts:
    bind: $SNAP/etc/fonts

But It always fails with the following output.

Failed to create snap, snap command failed:
stdout:

stderr:
error: cannot pack "/root/prime": cannot validate snap "cluemaster-mediadisplay-core": cannot have plug and slot with the same name: "audio-playback"

Any idea how I can fix? Thanks in advance

Hi @ogra. I fixed all the issues and its working, I just had to rearrange the plugs and the slots. But when I am uploading the snap to the store, I am getting the following error:

human review required due to 'deny-connection' constraint (on-classic) declaration-snap-v2_slots_connection (audio-playback, audio-playback)
human review required due to 'deny-connection' constraint (on-classic) declaration-snap-v2_slots_connection (audio-record, audio-record)

Here is the snapcraft.yaml: https://pastebin.ubuntu.com/p/cFMtQBtF55/

Thanks in advance

Hey @ogra :wave:

Any reason why this https://github.com/ogra1/pulse-server work of yours couldn’t be published as a snap?

Total beginner in Linux audio system here, but building locally and using your snap gave us sound output to wpe-webkit-mir-kiosk (see here) :tada:

Should I read some blog/doc about why we should do that by any other mean? I’m afraid the audio-playback interface doesn’t seem to “just work” and I couldn’t find (yet?) any reliable piece of documentation to use it and get sound output… Only your pulse-server snap helped :heart_eyes: