Multiplexing audio between containers


#1

Hello,

I have two containers running, and which ever is the first to play audio, holds audio, and if I were to use play for instance, I receive the following error:

ALSA lib pcm_dmix.c:1052:(snd_pcm_dmix_open) unable to open slave
Arithmetic exception (core dumped)

I have created the following within the root resin-OS /etc/asound.conf rebooted and not had luck sharing/multiplexing audio sent by multiple containers:

  pcm.dsp {    
      type plug    
      slave.pcm "dmix"
  }

Does anyone have any ideas or input?

Thanks,

Matt


#2

Hi @mbrownnyc, what version of resinOS are you running two containers? Is it a version managed on resin.io, or the open source, unmanaged version? How are you starting the two containers? (is it possible to check out what code are you running on the device?)


#3

Thanks for your reply:

root@hassio:~# cat /etc/*release
ID="resin-os"
NAME="Resin OS"
VERSION="2.3.0+rev1"
VERSION_ID="2.0.9"
PRETTY_NAME="Resin OS 2.3.0+rev1"
RESIN_BOARD_REV="0c6de83"
SLUG="raspberrypi3"
MACHINE="raspberrypi3"
VARIANT="Production"
VARIANT_ID="prod"

This is the home-assistant image (hass.io) which I assume is an unmanaged version.

The containers are started automatically upon boot.

As I didn’t create the containers or the resinOS image, I’m a bit at a loss on specific details.

I have no issues with ALSA and sound access within the containers; I would figure it would be fairly simple to allow multiplexing of audio to both containers. This is my first dive into docker though, but if I understand correctly, containers are not VMs, they are somewhat virtualized filesystems only (?). So I’m not sure why the above /etc/asound.conf dmix implementation doesn’t work.

Any assistance or direction is appreciated.

Thanks!


#4

I see, that’s useful info. Will have to check how the home-assistant image is created…
Probably modifying the underlying resinOS image is not the completely correct way to fix this, but definitely good for debugging.

I’ve seen that the ArchLinux wiki (which has a lot of great Linux knowledge, regardless of distro) as some info on simultaneous playback: https://wiki.archlinux.org/index.php/Advanced_Linux_Sound_Architecture/Troubleshooting#Simultaneous_playback_problems and also linking to upstream maybe http://www.alsa-project.org/main/index.php/Asoundrc#dmix

I would guess that the above change you mentioned is not totally correct (or rather, not all the changes that are needed).

Definitely need some more investigation.


#5

Thanks for your reply. The resinOS image they use does not have apt-get or alsatools installed. The containers that can access sound are Alpine and Debian. Again, I’m not sure who goes where… as in… I’ve read that docker containers are “not VMs!” But, if they were VMs the responsibility for sharing a hardware resource is on the host OS, in this case (well not this case because containers are not VMs) that responsibility would be on resinOS.

However, alsa or alsa-util are not installed in resinOS:

  root@hassio:~# find / -iname *alsa* |  grep -v docker
  /lib/modules/4.4.50/kernel/drivers/media/usb/cx231xx/cx231xx-alsa.ko
  /lib/modules/4.4.50/kernel/drivers/media/usb/em28xx/em28xx-alsa.ko
  /lib/modules/4.4.50/kernel/drivers/media/usb/tm6000/tm6000-alsa.ko
  /lib/udev/rules.d/60-persistent-alsa.rules
  /etc/modprobe.d/alsa-blacklist.conf

I’ve added the following to /etc/asound.conf on both containers:

pcm.dmixer {
    type dmix
    ipc_key 1024
    ipc_key_add_uid 0
    ipc_perm 0660
}
pcm.dsp {
    type plug
    slave.pcm "dmix"
}

I’ve also installed and switched to using alsamixer on mopidy.

I am able to use aplay to play a wav from the same container where mopidy is playing music… to me this proves the issue isn’t the process locking ALSA, but the actual container locking ALSA. Although, inspecting files below /dev/snd/ shows a PID locking audio that isn’t listed in ps within the resinOS, but when killed stops Mopidy from playing (of course).

How is the hardware virtualized/multiplexed (for lack of better terms) between docker containers?

Would /resin-data/addons/core/snips/asoundrc be used by anything?

Thanks,

Matt


#6

I was advised in #alsa on freenode to look at using the ipc switch to share memory between containers.

Is it possible to provide guidance on using that with /dev/snd/?

Thanks,

Matt