mikebrady / shairport-sync

AirPlay and AirPlay 2 audio player
Other
7.27k stars 573 forks source link

[Problem]: Can't connect to pulse audio running via docker #1878

Closed rossdargan closed 3 months ago

rossdargan commented 3 months ago

What happened?

I'm running three containers inside docker on a raspberry pi. 1) woahbase/alpine-pulseaudio:aarch64 (called pulseaudio) 2) this container 3) a container with pulseaudio installed on it (a custom one called wyoming-snd-external)

From the custom one I can use pulseaudio in the container by setting this environment setting: PULSE_SERVER=pulseaudio:4713. From the host I can also play sounds like this: paplay /usr/share/sounds/alsa/Front_Center.wav --property=media.role=announce -s 127.0.0.1:4713. The pulseaudio container logs also show connections (And showed authorization issues if I try and connect via the wrong IP ([pulseaudio] protocol-native.c: Denied access to client with invalid authentication data.)

With this configuration

  airplay:
    container_name: airplay

    restart: unless-stopped
    environment:
      - PULSE_SERVER=pulseaudio:4713
    network_mode: host
    group_add:
      - audio
    image: mikebrady/shairport-sync:latest
    devices:
      - /dev/snd:/dev/snd
    command:
      - -o
      - pa
    depends_on:
      - pulseaudio

Produces this error: fatal error: failed to connect to the pulseaudio context -- the error message is "Connection refused". however, I get no logs in the pulseaudio container.

I copied the pulseaudio client.conf out of the shairport container, and modified the default server to be "pulseaudio:4713". I then mounted it as a volume. This gives me the following error instead fatal error: pa context is not good -- the error message "Connection refused".

Looking at the code this suggest that it maybe ignores the environmental variable PULSE_SERVER, however the pulse audio container still doesn't show any connection issues.

I then stopped the pulse audio container and still get the error fatal error: pa context is not good -- the error message "Connection refused"..

Relevant log output

s6-rc: info: service s6rc-fdholder: starting
s6-rc: info: service s6rc-oneshot-runner: starting
s6-rc: info: service s6rc-oneshot-runner successfully started
s6-rc: info: service fix-attrs: starting
s6-rc: info: service s6rc-fdholder successfully started
s6-rc: info: service fix-attrs successfully started
s6-rc: info: service legacy-cont-init: starting
s6-rc: info: service legacy-cont-init successfully started
s6-rc: info: service syslogd-prepare: starting
s6-rc: info: service 01-startup: starting
STARTING - Sun Jul 14 09:11:35 UTC 2024
s6-rc: info: service 01-startup successfully started
s6-rc: info: service 04-nqptp: starting
s6-rc: info: service 02-dbus: starting
s6-rc: info: service 04-nqptp successfully started
Starting nqptp
Starting dbus
s6-rc: info: service syslogd-prepare successfully started
s6-rc: info: service syslogd-log: starting
s6-rc: info: service syslogd-log successfully started
s6-rc: info: service syslogd: starting
s6-rc: info: service syslogd successfully started
s6-rc: info: service 02-dbus successfully started
s6-rc: info: service 03-avahi: starting
Starting avahi
Found user 'avahi' (UID 86) and group 'avahi' (GID 86).
Successfully dropped root privileges.
avahi-daemon 0.8 starting up.
WARNING: No NSS support for mDNS detected, consider installing nss-mdns!
Loading service file /etc/avahi/services/sftp-ssh.service.
Loading service file /etc/avahi/services/ssh.service.
*** WARNING: Detected another IPv4 mDNS stack running on this host. This makes mDNS unreliable and is thus not recommended. ***
*** WARNING: Detected another IPv6 mDNS stack running on this host. This makes mDNS unreliable and is thus not recommended. ***
Joining mDNS multicast group on interface br-a7709f3a5644.IPv4 with address 172.18.0.1.
New relevant interface br-a7709f3a5644.IPv4 for mDNS.
Joining mDNS multicast group on interface br-7ec441408b27.IPv4 with address 172.19.0.1.
New relevant interface br-7ec441408b27.IPv4 for mDNS.
Joining mDNS multicast group on interface docker0.IPv4 with address 172.17.0.1.
New relevant interface docker0.IPv4 for mDNS.
Joining mDNS multicast group on interface wlan0.IPv6 with address fe80::a276:7c75:fc47:5492.
New relevant interface wlan0.IPv6 for mDNS.
Joining mDNS multicast group on interface wlan0.IPv4 with address 192.168.86.20.
New relevant interface wlan0.IPv4 for mDNS.
Joining mDNS multicast group on interface lo.IPv6 with address ::1.
New relevant interface lo.IPv6 for mDNS.
Joining mDNS multicast group on interface lo.IPv4 with address 127.0.0.1.
New relevant interface lo.IPv4 for mDNS.
Network interface enumeration completed.
Registering new address record for 172.18.0.1 on br-a7709f3a5644.IPv4.
Registering new address record for 172.19.0.1 on br-7ec441408b27.IPv4.
Registering new address record for 172.17.0.1 on docker0.IPv4.
Registering new address record for fe80::a276:7c75:fc47:5492 on wlan0.*.
Registering new address record for 192.168.86.20 on wlan0.IPv4.
Registering new address record for ::1 on lo.*.
Registering new address record for 127.0.0.1 on lo.IPv4.
Server startup complete. Host name is plex-kitchen.local. Local service cookie is 2791849490.
s6-rc: info: service 03-avahi successfully started
s6-rc: info: service legacy-services: starting
s6-rc: info: service legacy-services successfully started
Starting shairport-sync
fatal error: pa context is not good -- the error message "Connection refused".
s6-rc: info: service legacy-services: stopping
s6-rc: info: service legacy-services successfully stopped
s6-rc: info: service syslogd: stopping
s6-rc: info: service 04-nqptp: stopping
s6-rc: info: service 03-avahi: stopping
Got SIGTERM, quitting.
Leaving mDNS multicast group on interface br-a7709f3a5644.IPv4 with address 172.18.0.1.
Leaving mDNS multicast group on interface br-7ec441408b27.IPv4 with address 172.19.0.1.
Leaving mDNS multicast group on interface docker0.IPv4 with address 172.17.0.1.
Leaving mDNS multicast group on interface wlan0.IPv6 with address fe80::a276:7c75:fc47:5492.
Leaving mDNS multicast group on interface wlan0.IPv4 with address 192.168.86.20.
Leaving mDNS multicast group on interface lo.IPv6 with address ::1.
Leaving mDNS multicast group on interface lo.IPv4 with address 127.0.0.1.
avahi-daemon 0.8 exiting.
s6-rc: info: service syslogd successfully stopped
s6-rc: info: service syslogd-log: stopping
s6-rc: info: service 04-nqptp successfully stopped
s6-rc: info: service 03-avahi successfully stopped
s6-rc: info: service 02-dbus: stopping
s6-rc: info: service 02-dbus successfully stopped
s6-rc: info: service 01-startup: stopping
s6-rc: info: service 01-startup successfully stopped
s6-rc: info: service syslogd-log successfully stopped
s6-rc: info: service syslogd-prepare: stopping
s6-rc: info: service s6rc-fdholder: stopping
s6-rc: info: service syslogd-prepare successfully stopped
s6-rc: info: service legacy-cont-init: stopping
s6-rc: info: service s6rc-fdholder successfully stopped
s6-rc: info: service legacy-cont-init successfully stopped
s6-rc: info: service fix-attrs: stopping
s6-rc: info: service fix-attrs successfully stopped
s6-rc: info: service s6rc-oneshot-runner: stopping
s6-rc: info: service s6rc-oneshot-runner successfully stopped

System Information.

Raspberry 5, but it's all running inside docker.

Configuration Information.

NOTE: I could only get this by removing the -o pa command as it crashes instantly otherwise:

>> Display Config Start.

From "uname -a":
 Linux plex-kitchen 6.6.31+rpt-rpi-2712 #1 SMP PREEMPT Debian 1:6.6.31-1+rpt1 (2024-05-29) aarch64 Linux

From /etc/os-release:
 Alpine Linux v3.17

Shairport Sync Version String:
 4.3.4-dirty-AirPlay2-smi10-alac-OpenSSL-Avahi-ALSA-pa-dummy-stdout-pipe-soxr-convolution-metadata-mqtt-dbus-mpris-sysconfdir:/etc

Command Line:
 shairport-sync --displayConfig

Configuration File:
 /etc/shairport-sync.conf

Configuration File Settings:
 pw :
 {
 };

>> Display Config End.
>> Goodbye!

-v:

         0.001383037 "shairport.c:2278" Startup in AirPlay 2 mode, with features 0x405fca00,0x1c340 on device "d8:3a:dd:d5:22:d4".
         0.000059148 "shairport.c:2317" Version String: "4.3.4-dirty-AirPlay2-smi10-alac-OpenSSL-Avahi-ALSA-pa-dummy-stdout-pipe-soxr-convolution-metadata-mqtt-dbus-mpris-sysconfdir:/etc"
         0.000009723 "shairport.c:2336" Command Line: "shairport-sync -v".
         0.000264518 "shairport.c:2372" Log Verbosity is 1.
         0.000072611 "audio_alsa.c:1082" alsa: alsa_maximum_stall_time of 0.200000 sec.
         0.000373723 "audio_alsa.c:1371" alsa: disable_standby_mode is "never".
         0.000029944 "audio_alsa.c:1375" alsa: disable_standby_mode_silence_threshold is 0.040000 seconds.
         0.000055222 "audio_alsa.c:1377" alsa: disable_standby_mode_silence_scan_interval is 0.004000 seconds.
         0.000015889 "audio_alsa.c:1417" alsa: output device name is "default".
         0.000238778 "shairport.c:2440" disable_resend_requests is off.
         0.000157129 "shairport.c:2441" diagnostic_drop_packet_fraction is 0.000000. A value of 0.0 means no packets will be dropped deliberately.
         0.000023649 "shairport.c:2445" statistics_requester status is 0.
         0.000009851 "shairport.c:2450" rtsp listening port is 7000.
         0.000126889 "shairport.c:2451" udp base port is 6001.
         0.000020519 "shairport.c:2452" udp port range is 10.
         0.000104315 "shairport.c:2453" player name is "Plex-kitchen".
         0.000125352 "shairport.c:2454" backend is "alsa".
         0.000024500 "shairport.c:2455" run_this_before_play_begins action is "(null)".
         0.000007333 "shairport.c:2456" run_this_after_play_ends action is "(null)".
         0.000005500 "shairport.c:2457" wait-cmd status is 0.
         0.000004389 "shairport.c:2458" run_this_before_play_begins may return output is 0.
         0.000005481 "shairport.c:2459" run_this_if_an_unfixable_error_is_detected action is "(null)".
         0.000005519 "shairport.c:2461" run_this_before_entering_active_state action is  "(null)".
         0.000030259 "shairport.c:2463" run_this_after_exiting_active_state action is  "(null)".
         0.000006278 "shairport.c:2465" active_state_timeout is  10.000000 seconds.
         0.000005463 "shairport.c:2466" mdns backend "(null)".
         0.000004129 "shairport.c:2468" interpolation setting is "auto".
         0.000004797 "shairport.c:2472" interpolation soxr_delay_threshold is 30000000.
         0.000005555 "shairport.c:2473" resync time is 0.050000 seconds.
         0.000004945 "shairport.c:2474" resync recovery time is 0.100000 seconds.
         0.000005685 "shairport.c:2475" allow a session to be interrupted: 0.
         0.000004426 "shairport.c:2476" busy timeout time is 120.
         0.000004092 "shairport.c:2477" drift tolerance is 0.002000 seconds.
         0.000005612 "shairport.c:2478" password is not set.
         0.000004333 "shairport.c:2479" default airplay volume is: -24.000000.
         0.000005037 "shairport.c:2480" high threshold airplay volume is: -16.000000.
         0.000005537 "shairport.c:2482" check for higher-than-threshold volume for new play session is disabled.
         0.000005370 "shairport.c:2488" ignore_volume_control is 0.
         0.000004260 "shairport.c:2492" volume_max_db is not set
         0.000004407 "shairport.c:2493" volume range in dB (zero means use the range specified by the mixer): 0.
         0.000005518 "shairport.c:2495" volume_range_combined_hardware_priority (1 means hardware mixer attenuation is used first) is 0.
         0.000005889 "shairport.c:2499" playback_mode is 0 (0-stereo, 1-mono, 1-reverse_stereo, 2-both_left, 3-both_right).
         0.000005556 "shairport.c:2501" disable_synchronization is 0.
         0.000006000 "shairport.c:2502" use_mmap_if_available is 1.
         0.000004333 "shairport.c:2503" output_format automatic selection is enabled.
         0.000005204 "shairport.c:2507" output_rate automatic selection is enabled.
         0.000005093 "shairport.c:2511" audio backend desired buffer length is 0.200000 seconds.
         0.000005888 "shairport.c:2513" audio_backend_buffer_interpolation_threshold_in_seconds is 0.120000 seconds.
         0.000007889 "shairport.c:2515" audio backend latency offset is 0.000000 seconds.
         0.000006204 "shairport.c:2517" audio backend silence lead-in time is "auto".
         0.000005056 "shairport.c:2521" zeroconf regtype is "_raop._tcp".
         0.000004500 "shairport.c:2522" decoders_supported field is 3.
         0.000004314 "shairport.c:2523" use_apple_decoder is 1.
         0.000004167 "shairport.c:2524" alsa_use_hardware_mute is 0.
         0.000004722 "shairport.c:2528" no special mdns service interface was requested.
         0.000016519 "shairport.c:2531" configuration file name "/etc/shairport-sync.conf" resolves to "/etc/shairport-sync.conf".
         0.000009333 "shairport.c:2538" metadata enabled is 1.
         0.000004148 "shairport.c:2539" metadata pipename is "/tmp/shairport-sync-metadata".
         0.000005389 "shairport.c:2540" metadata socket address is "(null)" port 0.
         0.000005278 "shairport.c:2542" metadata socket packet size is "500".
         0.000004741 "shairport.c:2543" get-coverart is 1.
         0.000004129 "shairport.c:2546" mqtt is disabled.
         0.000004186 "shairport.c:2547" mqtt hostname is (null), port is 1883.
         0.000004555 "shairport.c:2548" mqtt topic is /Plex-kitchen.
         0.000004500 "shairport.c:2549" mqtt will not publish raw metadata.
         0.000004278 "shairport.c:2550" mqtt will not publish parsed metadata.
         0.000004167 "shairport.c:2551" mqtt will not publish cover Art.
         0.000004370 "shairport.c:2552" mqtt remote control is disabled.
         0.000004333 "shairport.c:2556" convolution is 0.
         0.000004148 "shairport.c:2557" convolution IR file is "(null)"
         0.000004241 "shairport.c:2558" convolution max length 8192
         0.000004148 "shairport.c:2559" convolution gain is 0.000000
         0.000004389 "shairport.c:2561" loudness is 0.
         0.000003982 "shairport.c:2562" loudness reference level is -20.000000
         0.000092463 "rtsp.c:4172" metadata pipe name is "/tmp/shairport-sync-metadata".
         0.002373444 "shairport.c:2689" NQPTP is online.
         0.000757389 "rtsp.c:5492" unable to listen on IPv4 port 7000. The error is: "Address in use".
         0.000047555 "rtsp.c:5492" unable to listen on IPv6 port 7000. The error is: "Address in use".
         0.000028186 "rtsp.c:5702" *fatal error: could not establish a service on port 7000 -- program terminating. Is another instance of Shairport Sync running on this device?
         0.000019389 "shairport.c:1732" emergency exit


### PulseAudio or PipeWire installed?

- [X] Check if your system uses a Sound Server.

### How did you install Shairport Sync?

Docker

### Check previous issues

- [X] Confirm
rossdargan commented 3 months ago

There were a few issues I had, mainly around network: host. On this network the docker container can't see pulse audio, so I needed to use the ip 127.0.0.1. Also I needed to modify the client.conf - looks the the environmental variable does nothing. But this is working now!

mikebrady commented 3 months ago

Glad you got it working!