How to record audio on Snap? Jack server is not running or cannot be started

As title. I’m am trying to run my java app (XT-Audio lib) on Snap but it doesn’t work.

It works well natively and on Flatpak but on Snap it doesn’t work even if I opened the Jack, pulseaudio plug.

This is the error:

[Instance #1] 2024-11-29 15:14:13,347 ERROR o.d.a.AudioLoopbackNative [pool-30-thread-1] No line matching interface TargetDataLine supporting format PCM_SIGNED 44100.0 Hz, 16 bit, stereo, 4 bytes/frame, big-endian is supported.
[Instance #1] 2024-11-29 15:14:13,347 TRACE o.d.a.AudioLoopbackSoftware [pool-30-thread-1] Pro Audio: JACK (true)
[Instance #1] 2024-11-29 15:14:13,347 TRACE o.d.a.AudioLoopbackSoftware [pool-30-thread-1] System Audio: ALSA (true)
[Instance #1] 2024-11-29 15:14:13,347 TRACE o.d.a.AudioLoopbackSoftware [pool-30-thread-1] Consumer Audio: PULSE_AUDIO (true)
[Instance #1] 2024-11-29 15:14:13,347 TRACE o.d.a.AudioLoopbackSoftware [pool-30-thread-1] System JACK:
[Instance #1] 2024-11-29 15:14:13,347 TRACE o.d.a.AudioLoopbackSoftware [pool-30-thread-1]   Capabilities: [TIME, FULL_DUPLEX, CHANNEL_MASK, XRUN_DETECTION]
[Instance #1] 2024-11-29 15:14:13,347 TRACE o.d.a.AudioLoopbackSoftware [pool-30-thread-1]   Default input: JACK (0)
[Instance #1] 2024-11-29 15:14:13,347 TRACE o.d.a.AudioLoopbackSoftware [pool-30-thread-1]   Default output: JACK (0)
[Instance #1] 2024-11-29 15:14:13,347 TRACE o.d.a.AudioLoopbackSoftware [pool-30-thread-1]   Input device count: 1
[Instance #1] 2024-11-29 15:14:13,349 TRACE o.d.a.AudioLoopbackSoftware [pool-30-thread-1] Jack.cpp:12: in function XtiJackErrorCallback: Cannot connect to server socket err = No such file or directory
[Instance #1] 2024-11-29 15:14:13,349 TRACE o.d.a.AudioLoopbackSoftware [pool-30-thread-1] Jack.cpp:12: in function XtiJackErrorCallback: Cannot connect to server request channel
[Instance #1] 2024-11-29 15:14:13,351 TRACE o.d.a.AudioLoopbackSoftware [pool-30-thread-1] Jack.cpp:12: in function XtiJackErrorCallback: jack server is not running or cannot be started
[Instance #1] 2024-11-29 15:14:13,351 TRACE o.d.a.AudioLoopbackSoftware [pool-30-thread-1] Jack.cpp:12: in function XtiJackErrorCallback: JackShmReadWritePtr::~JackShmReadWritePtr - Init not done for -1, skipping unlock
[Instance #1] 2024-11-29 15:14:13,351 TRACE o.d.a.AudioLoopbackSoftware [pool-30-thread-1] Jack.cpp:12: in function XtiJackErrorCallback: JackShmReadWritePtr::~JackShmReadWritePtr - Init not done for -1, skipping unlock
[Instance #1] 2024-11-29 15:14:13,351 TRACE o.d.a.AudioLoopbackSoftware [pool-30-thread-1] Shared.cpp:111: in function XtiCreateError: JACK Service Error: 3 (No such process)
[Instance #1] 2024-11-29 15:14:13,351 TRACE o.d.a.AudioLoopbackSoftware [pool-30-thread-1] JACK Service Error: 3 (No such process)
[Instance #1] 2024-11-29 15:14:13,351 TRACE o.d.a.AudioLoopbackSoftware [pool-30-thread-1]   Output device count: 1
[Instance #1] 2024-11-29 15:14:13,353 TRACE o.d.a.AudioLoopbackSoftware [pool-30-thread-1] Jack.cpp:12: in function XtiJackErrorCallback: Cannot connect to server socket err = No such file or directory
[Instance #1] 2024-11-29 15:14:13,353 TRACE o.d.a.AudioLoopbackSoftware [pool-30-thread-1] Jack.cpp:12: in function XtiJackErrorCallback: Cannot connect to server request channel
[Instance #1] 2024-11-29 15:14:13,355 TRACE o.d.a.AudioLoopbackSoftware [pool-30-thread-1] Jack.cpp:12: in function XtiJackErrorCallback: jack server is not running or cannot be started
[Instance #1] 2024-11-29 15:14:13,355 TRACE o.d.a.AudioLoopbackSoftware [pool-30-thread-1] Jack.cpp:12: in function XtiJackErrorCallback: JackShmReadWritePtr::~JackShmReadWritePtr - Init not done for -1, skipping unlock
[Instance #1] 2024-11-29 15:14:13,355 TRACE o.d.a.AudioLoopbackSoftware [pool-30-thread-1] Jack.cpp:12: in function XtiJackErrorCallback: JackShmReadWritePtr::~JackShmReadWritePtr - Init not done for -1, skipping unlock
[Instance #1] 2024-11-29 15:14:13,355 TRACE o.d.a.AudioLoopbackSoftware [pool-30-thread-1] Shared.cpp:111: in function XtiCreateError: JACK Service Error: 3 (No such process)
[Instance #1] 2024-11-29 15:14:13,355 TRACE o.d.a.AudioLoopbackSoftware [pool-30-thread-1] JACK Service Error: 3 (No such process)
[Instance #1] 2024-11-29 15:14:13,355 TRACE o.d.a.AudioLoopbackSoftware [pool-30-thread-1] System ALSA:
[Instance #1] 2024-11-29 15:14:13,355 TRACE o.d.a.AudioLoopbackSoftware [pool-30-thread-1]   Capabilities: [TIME, LATENCY, AGGREGATION, XRUN_DETECTION]
[Instance #1] 2024-11-29 15:14:13,355 TRACE o.d.a.AudioLoopbackSoftware [pool-30-thread-1] Service.cpp:48: in function OpenDeviceList: snd_device_name_hint(-1, "pcm", &hints)
[Instance #1] 2024-11-29 15:14:13,355 TRACE o.d.a.AudioLoopbackSoftware [pool-30-thread-1] Shared.cpp:111: in function XtiCreateError: ALSA Endpoint Error: 4294967294 (No such file or directory)
[Instance #1] 2024-11-29 15:14:13,355 ERROR o.d.a.AudioLoopbackSoftware [pool-30-thread-1] ALSA Endpoint Error: 4294967294 (No such file or directory)

Any idea on a possible solution?

This is the code that throws that error:

And this is my current snapcraft.yaml

Don’t use jack. It’s dead. Better use pulseaudio or pipewire. If you’re going to use pipewire, try to do it via portals, not directly accessing the socket. This can only be done for pulseaudio. So, may be pulseaudio is the ideal choice for you in starting.

Ok, thanks for the answer. I am trying to use aplay, I updated my snapcraft to reflect this changes by installing alsa pulseaudio libs

but the command
aplay -l
returns this on my sandbox.

sblantipodi@DeskStarLinux:/home/sblantipodi$ aplay -l
**** List of PLAYBACK Hardware Devices ****
ALSA lib conf.c:4579:(snd_config_update_r) Cannot access file /usr/share/alsa/alsa.conf
ALSA lib control.c:1570:(snd_ctl_open_noupdate) Invalid CTL hw:0
aplay: device_list:286: control open (0): No such file or directory
ALSA lib conf.c:4579:(snd_config_update_r) Cannot access file /usr/share/alsa/alsa.conf
ALSA lib control.c:1570:(snd_ctl_open_noupdate) Invalid CTL hw:1
aplay: device_list:286: control open (1): No such file or directory
ALSA lib conf.c:4579:(snd_config_update_r) Cannot access file /usr/share/alsa/alsa.conf
ALSA lib control.c:1570:(snd_ctl_open_noupdate) Invalid CTL hw:2
aplay: device_list:286: control open (2): No such file or directory
ALSA lib conf.c:4579:(snd_config_update_r) Cannot access file /usr/share/alsa/alsa.conf
ALSA lib control.c:1570:(snd_ctl_open_noupdate) Invalid CTL hw:3
aplay: device_list:286: control open (3): No such file or directory

Same code works on native and Flatpak. what can it be?

thanks

Nope, not alsa too. Use pulseaudio or pipewire directly. Alsa is very much deprecated now. Even pulseaudio isn’t used that much anymore.

The java code above seems to probe audio devices directly…

That might actually need the alsa interface…

Though if the code can work with sound servers like pulse or pipewire, the audio-record interface and staging libpulseaudio (along with the required LD_LIBRARY_PATH adjustments) should be sufficient…

I tried setting the LD_LIBRARY in this way

apps:
  fireflyluciferin:
    command: bin/FireflyLuciferin
    desktop: usr/share/applications/fireflyluciferin.desktop
    extensions: [ gnome ]
    plugs:
      - network
      - home
      - pulseaudio
      - alsa
      - x11
      - desktop
      - desktop-legacy
      - audio-playback
      - audio-record
    environment:
      LD_LIBRARY_PATH: ${SNAP}/usr/lib/$SNAPCRAFT_ARCH_TRIPLET/pulseaudio
      TMPDIR: $XDG_RUNTIME_DIR
      DISABLE_WAYLAND: 1
      NOTIFY_IGNORE_PORTAL: 1

but then my gstreamer plugn stopped working. is this the correct way to set the LD PATH for this purpose?

The path is correct, are you sure your Deb is actually compiled on 24.04 and linked against the respective pulseaudio lib ? If your symbols do not match the versions this will indeed cause crashes and instability

Oh, and don’t forget that you need to connect the plugs after you installed your snap, just defining them is not enough for some of the higher privileged ones (see snap connections)

What do you mean? Does the distro I use for the build affect the final snap?

I’m running ubuntu 24.10 as my OS, but on the snapcraft.yaml I’m using core24.

Isn’t the output produced by the snapcraft command portable on all distros? O_o Should I snapcraft on every distro I want to support?

Using this LD_LIBRARY_PATH: ${SNAP}/usr/lib/$SNAPCRAFT_ARCH_TRIPLET/pulseaudio makes my app crash on gstreamer O_o

those are my connections:

am I supposed to connect them manually?

EDIT: I connected them manually but same problem.

You need to set up a bit more config to get the Alsa → Pulse backend working.

  1. You need this file somewhere in $SNAP, e.g., $SNAP/etc/asound.conf
pcm.!default {
        type pulse
        fallback "sysdefault"
        hint {
                show on
                description "Default ALSA Output (currently PulseAudio Sound Server)"
        }
}
ctl.!default {
        type pulse
        fallback "sysdefault"
}
  1. You need these stage packages
      - libasound2
      - libasound2-plugins
  1. You need this environment variable
environment:
      ALSA_CONFIG_PATH: $SNAP/etc/asound.conf
  1. You need the Gnome extension (which includes libpulse0 and modifies the environment to correctly connect to a Pulseaudio socket, including the one provided by Pipewire).

  2. You need audio-playback in the interfaces (which the extension does automatically).

  3. Since you’ve mentioned recording, you’ll also want audio-record as an interface, which the extension does not do automatically, and will require manual connection or store approval to be overridden on install for your users.

This covers any arbitrary use of ALSA as a userspace library for simple input/output needs (which currently is all Java apps except for a specific niche of Java 8 from the Ubuntu/Debian repositories which actually has direct PulseAudio support through custom patches that were later removed), it doesn’t cover more advanced ALSA features like MIDI keyboards, which would need direct ALSA access and is a fair bit more complex (and usually unnecessary, and not preferred as a default on modern setups because it can do things like lock the soundcard from other apps).

You are using a pre-built binary Deb that you import into your snap… that should preferably have been built on the distro that is used inside the snap sandbox so that corresponding libs match the versions that snapcraft will stage into your snap during build… for core24 that would be 24.04, for core22 it is 22.04 etc etc

Hi, thanks for the answer, I really appreciate it. :slight_smile:

I added the stage packages, I added the environment variable I have the gnome extension I have all the needed interfaces enabled and plugged

but there is no asound.conf file in my $SNAP/ folder

how can I create that file in that folder?

and more over, I see that my /snap/myappid folder contains jack dependencies, even if I not staged it. this are my stage packages

      - xdg-user-dirs
      - xdg-utils
      - libgtk-3-0
      - libxtst6
      - libglib2.0-dev
      - gstreamer1.0-tools
      - gstreamer1.0-alsa
      - gstreamer1.0-gl
      - gstreamer1.0-gtk3
      - gstreamer1.0-qt5
      - gstreamer1.0-x
      - gstreamer1.0-plugins-base
      - gstreamer1.0-plugins-good
      - gstreamer1.0-plugins-bad
      - gstreamer1.0-plugins-ugly
      - gstreamer1.0-pulseaudio
      - gstreamer1.0-libav
      - libgstreamer1.0-dev
      - libgstreamer-plugins-base1.0-dev
      - libgstreamer-plugins-bad1.0-dev
      - libayatana-appindicator3-1
      - libayatana-appindicator3-dev
      - libayatana-indicator3-7
      - libayatana-ido3-0.4-0
      - libnotify-dev
      - libnotify4
      - libnotify-bin
      - libatlas3-base
      - libblas3
      - libpulse0
      - pulseaudio-utils
      - libpulse-dev
      - libasound2
      - libasound2-plugins
      - alsa-utils

along with the gnome extension. probably jack comes from the gnome extension?

Thanks for the help Ogra, I appreciate the continued tips. I agree on the fact that bundling a deb may not be the best thing to do but my deb only contains java bytecode (and some images/config files).

Compiling the same Java code on two different operating systems (even Windows and Linux) produces identical bytecode. Java is an interpreted language (if you don’t compile is as native and this is not my case). This is because Java is designed to be portable across platforms through the JVM (Java Virtual Machine).

2 Likes

A really cheeky way to get the file in there, assuming this is the only odd thing you need, would be a part like so:

alsa-pulseaudio:
    plugin: dump
    source: .
    override-pull: |
      mkdir etc -p
      cat > etc/asound.conf <<EOF
      pcm.!default {
          type pulse
          fallback "sysdefault"
          hint {
              show on
              description "Default ALSA Output (currently PulseAudio Sound Server)"
          }
      }
      ctl.!default {
          type pulse
          fallback "sysdefault"
      }
      EOF

Alternatively, you’d just create a folder e.g., extras/etc/asound.conf and use the dump plugin pointing to the extras folder (this is relative from the repository root). That’s better if you’ve various small files like this because it doesn’t clutter the snapcraft.yaml. For this as a one off, either looks about fine really.

It wouldn’t do, I imagine your stage-packages is bloated. The Gnome extension has a lot of those in implicitly, but they remain part of the Gnome extension itself, they shouldn’t appear in your own snaps content (except at runtime, due to the binding magic), and the extension doesn’t include any support for ALSA or JACK because they’re not common enough and when they are needed in full, you probably don’t want the extension to be fighting the packager too much on assumptions (e.g., you wouldn’t want the Gnome extension setting its own alsa.conf because it could deny people who do need to go crazy with MIDI keyboards the ability to do it, similarly so for JACK, few people outside of professional audio context use it and so it’s probably bloat for most people to have libraries for it.)

I’d suggest once you have a viable product trying to delete all your stage-packages and re-adding packages one at a time in a functionality based approach. You might be able to get away with purely Java, and the libasound packages. All the other common desktop stuff would be part of the extension, and this should make your snap lighter and less error prone.

This is true generally, but not universally. Some Java code will use the JNI and the JNI bindings are native C++ and have ABI problems of their own.

A good example would be JOGL, fairly widely used in Java 3D graphics software, the OpenGL bits are infact C++ beyond the Java interface to them.

If your app doesn’t have any bundled libraries like that, you’re probably fine. But it wouldn’t be hard at all to find Java apps that don’t actually run everywhere due to their JNI usage, and the “technically correct” (even if perhaps, not absolutely essential for your snap since through luck it can work anyway) solution is to indeed rebuild it on the same platform as the rest of the applications you have running. (So basically, on Ubuntu 24.04 or in Snapcraft itself against Core24, so that when e.g., Maven or Ant runs, it pulls JOGL for 24.04 matching the rest of the snap.)

1 Like

That made the trick my friend, thanks.

1 Like