noelhibbard / shairport-sync-docker

18 stars 1 forks source link

Docker not Sending Audio to PulseAudio #3

Open KSti56 opened 1 week ago

KSti56 commented 1 week ago

Hey @noelhibbard, thanks for the great work on this repository. I'm trying to help someone run 3-4 AirPlay instances through a 4-channel USB interface. It took quite a while for me to figure out that I needed to disable promiscuous mode in VirtualBox and in the VM (just adding that in hopes that it helps someone in the future!). Now I have everything set up and can connect to the AirPlay server(s) from my phone. Unfortunately, it seems that there is no audio going to PulseAudio. Here's my docker-compose.yml file:

services:
  Instance1:
    container_name: Instance 1
    image: mikebrady/shairport-sync:latest
    restart: unless-stopped
    volumes:
      - ./instances/instance1.conf:/etc/shairport-sync.conf
      - /var/run/pulse/native:/tmp/pulseaudio.socket
    environment:
      - PULSE_SERVER=unix:/tmp/pulseaudio.socket
    networks:
      spsnet_shared:
      spsnet:
        ipv4_address: 192.168.2.90
  Instance2:
    container_name: Instance 2
    image: mikebrady/shairport-sync:latest
    restart: unless-stopped
    volumes:
      - ./instances/instance2.conf:/etc/shairport-sync.conf
      - /var/run/pulse/native:/tmp/pulseaudio.socket
    environment:
      - PULSE_SERVER=unix:/tmp/pulseaudio.socket
    networks:
      spsnet_shared:
      spsnet:
        ipv4_address: 192.168.2.91
networks:
  spsnet:
    name: spsnet
    driver: macvlan
    driver_opts:
      parent: enp0s3
    ipam:
      config:
        - subnet: 192.168.2.0/24
          gateway: 192.168.2.1
  spsnet_shared:
    name: spsnet_shared
    driver: bridge

This is what my instance 1 config file looks like at the moment (I removed everything that was commented out):

general =
{
    name = "Family Room";
    output_backend = "pa";
    playback_mode = "mono";
};

pa = {
    server = "unix:/tmp/pulseaudio.socket";
    sink = "sink_ch1";
};

diagnostics = {
    log_output_to = "stdout";
    log_verbosity = 2;
};

I've tried changing the playback_modes, removing the server property for the pa block, and I've tried multiple different sinks (including the main one for the USB interface).

Here's my /etc/pulse/system.pa file:

load-module module-native-protocol-unix auth-anonymous=1

load-module module-alsa-sink device=hw:CARD=TesiraFORTE,DEV=0 sink_name=multi_channel_sink

load-module module-remap-sink sink_name=sink_ch1 master=multi_channel_sink channels=1 master_channel_map=front-left channel_map=mono
load-module module-remap-sink sink_name=sink_ch2 master=multi_channel_sink channels=1 master_channel_map=front-right channel_map=mono
load-module module-remap-sink sink_name=sink_ch3 master=multi_channel_sink channels=1 master_channel_map=rear-left channel_map=mono
load-module module-remap-sink sink_name=sink_ch4 master=multi_channel_sink channels=1 master_channel_map=rear-right channel_map=mono

As for the host side, everything seems fine. I can play audio using ALSA directly and I can also play audio using paplay. Here's the command I use to test that: sudo paplay --device=sink_ch1 /usr/share/sounds/alsa/Front_Center.wav

The Docker container is definitely making some connection to the PulseAudio socket. I tried deliberately changing the server path and it crashed saying it couldn't connect (whereas it connects just fine using "unix:/tmp/pulseaudio.socket"), so obviously it's at least seeing the PulseAudio server. At this point it seems like I need to troubleshoot/monitor between Docker and PulseAudio, I'm just not exactly sure how to do that. I tried running this command a few times while playing audio, but it continued to show 0 volume for all of the sinks: sudo pactl list sink-inputs | grep -e Sink: -e media.name -e application.name -e Volume:

I don't mind troubleshooting myself, I'm just at a loss for what to try next. Is there a way for me to view the sinks inside of the Docker container? Or somehow install and use paplay in the container?

I'm not super familiar with ALSA, PulseAudio, or Docker, so it's entirely possible that this is just a simple mistake. I appreciate any advice or help you can give!

noelhibbard commented 1 week ago

You should be able to shell into one of the containers and then install pulseaudio-utils which includes paplay. From there it should be easier to trouble shoot.

From the host run this to shell into the container:

docker compose exec Instance1 sh

Once in the container, run this to install paplay:

apk add pulseaudio-utils