Hi I am trying to build a snap which is using OpenCV and SoX to alert if masks are not worn properly. The code works fine on Ubuntu Desktop (not as a snap) and now I am trying to snap it for Ubuntu Core as this will be a Kiosk.
The vision part is mostly working now (after some headache) but it seems that the audio part which I thought will be simple is an even bigger headache. My basic premise is to use sox and play a simple wav file upon detection. I added the sox library to stage-packages and if I shell into the snap (snapcraft --shell-after --use-lxd) I can see the sox library and dependencies installed. However, when I ldd /root/prime/usr/bin/sox the library libsox3 is not found.
linux-vdso.so.1 (0x00007fffa8add000)
libsox.so.3 => not found
libm.so.6 => /lib/x86_64-linux-gnu/libm.so.6 (0x00007f15ebd9b000)
libpthread.so.0 => /lib/x86_64-linux-gnu/libpthread.so.0 (0x00007f15ebb7c000)
libc.so.6 => /lib/x86_64-linux-gnu/libc.so.6 (0x00007f15eb78b000)
/lib64/ld-linux-x86-64.so.2 (0x00007f15ec139000)
I added a bunch of the dependencies to stage packages as well but that does not seem to help. However in the shell-after if I directly do sudo apt install libsox3 then it installs it and now ldd /root/prime/usr/bin/sox finds it. I tried to see if there is any weird installation triggers in libsox3 but did not see anything telling.
the final result of all of this is that when I actually deploy the snap on Core (as a daemon) I get video but when trying to play a sound I get
2021-05-09T06:50:04Z camsnap.camsnap[5157]: play FAIL formats: no handler for given file type alsa' 2021-05-09T06:50:15Z camsnap.camsnap[5157]: play FAIL formats: no handler for detected file type
vorbis’
I get two messages as I tried both .wav and .ogg file. From the sox documentation it seems that libsox-fmt-base and libsox-fmt-alsa are key to be able to handle wav files. There is also libsox-fmt-all which I also tried including but did not help. My assumption so far is that there is something funky going on with the sox dependency libraries. Please suggest how can I further troubleshoot to solve this issue.
Finally I am also assuming that I can directly plug :alsa in my snap and don’t need pulseaudio for this but I still experimented with pulse nevertheless, however did not see any improvement.
Please see the majority of my snapcraft.yaml below. Really appreciate some advice on this as I have been digging through the web and trying all sorts of stuff but have not been able to solve this.
name: camsnap
base: core20
version: '1'
summary: example camera X11 kiosk
description: example camera X11 kiosk
confinement: devmode
grade: devel
environment:
LD_LIBRARY_PATH: $LD_LIBRARY_PATH:$SNAP/usr/lib/$SNAPCRAFT_ARCH_TRIPLET:$SNAP/usr/lib/$SNAPCRAFT_ARCH_TRIPLET/lapack:$SNAP/usr/lib/$SNAPCRAFT_ARCH_TRIPLET/blas:$SNAP/usr/lib/$SNAPCRAFT_ARCH_TRIPLET/sox:$SNAP/usr/share/lintian/overrides:$SNAP/usr/lib/$SNAPCRAFT_ARCH_TRIPLET/pulseaudio
PYTHONPATH: $SNAP/usr/lib/python3/dist-packages
AUDIODEV: hw:0,0
AUDIODRIVER: alsa
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
/etc/fonts:
bind: $SNAP/etc/fonts
/usr/share/alsa:
bind: $SNAP/usr/share/alsa
apps:
camsnap:
daemon: simple
restart-condition: always
command-chain:
- env-setup
command: usr/local/bin/x11_kiosk_launch $SNAP/run_maskdetector
plugs:
- opengl # For Mir
- wayland # For Mir
- network-bind # For Mir (to serve X11)
- camera # for camera
- home # home directory
- pulseaudio
- alsa
parts:
mask-detector:
plugin: python
source: .
build-packages:
- python3
stage-packages:
- mesa-utils
- libice6
- libsm6
- libx11-6
- libxext6
- libxrender1
- libpsm-infinipath1
- python3-opencv
- alsa-base #not sure if I need this or not
- libgsm1 # seems to be required for libsox3
- libltdl7 # seems to be required for libsox3
- libmagic-mgc # seems to be required for libsox3
- libmagic1 # seems to be required for libsox3
- libsox-fmt-base
- libsox-fmt-alsa
- libsox3
- sox
# - libpulse0 #for pulse audio
stage-snaps:
- mir-kiosk-x11
override-build: |
snapcraftctl build
ln -sf ../libpsm1/libpsm_infinipath.so.1.16 $SNAPCRAFT_PART_INSTALL/usr/lib/x86_64-linux-gnu/libpsm_infinipath.so.1