badaix / snapcast

Synchronous multiroom audio player
GNU General Public License v3.0
6.21k stars 456 forks source link

Understanding Fedora Support #1012

Open candlelightreveal opened 2 years ago

candlelightreveal commented 2 years ago

Hello. Firstly thank you for this project, I have been using it on my Raspberry Pis for some time and it has performed perfectly (better than commercial solutions, imo).

I've recently started migrating my desktop systems to Fedora as it has been recently described as a better desktop OS than Ubuntu. However, Snapcast's Fedora support seems to be confusing/incomplete - though there are build instructions for Fedora in the docs, there are two open issues regarding Post Install Scripts and Pipewire that prevent snapclient from functioning. The post install is easy enough to work around. However, Pipewire has been the default on Fedora for a couple of versions now (I'm on the lastest, Fedora 36) and it doesn't appear snapclient has any way of playing audio on these systems.

I'm trying to see if I can hack snapclient to work on Fedora manually. I've built the binaries and manually placed them. I've tried the below commands but have been unable to get audio playing through this host (the rest of the clients on the network running on Pis are working fine).

Q: Can you please clarify if and how Fedora is supported and if there is a workaround for me to get snapclient to play audio on the latest Fedora versions that use Pipewire?


Build on Fedora 36

sudo dnf install -y @development-tools
sudo dnf install -y alsa-lib-devel avahi-devel gcc-c++ libatomic libvorbis-devel opus-devel pulseaudio-libs-devel flac-devel soxr-devel libstdc++-static expat boost-devel

git clone https://github.com/badaix/snapcast.git
cd snapcast
make

mv client/snapclient /usr/bin/snapclient

List Devices

sudo /usr/bin/snapclient -l

0: null
Discard all samples (playback) or generate zero samples (capture)

1: pipewire
PipeWire Sound Server

2: default
Default ALSA Output (currently PipeWire Media Server)

...

Run with No Args, -s 1 or -s 2

sudo /usr/bin/snapclient --host=<redacted> // -s 1 // -s 2
2022-05-30 11-56-24.351 [Info] (Snapclient) Version 0.26.0
2022-05-30 11-56-24.351 [Info] (Connection) Resolving host IP for: <redacted>
2022-05-30 11-56-24.351 [Info] (Connection) Connecting
2022-05-30 11-56-24.369 [Notice] (Connection) Connected to <redacted>
2022-05-30 11-56-24.369 [Info] (Connection) My MAC: "<redacted>, socket: 8
2022-05-30 11-56-24.398 [Info] (Controller) ServerSettings - buffer: 1000, latency: 0, volume: 100, muted: 0
2022-05-30 11-56-24.411 [Info] (Controller) Codec: flac, sampleformat: 44100:16:2
2022-05-30 11-56-24.412 [Info] (Player) Player name: alsa, device: default, description: Default ALSA Output (currently PipeWire Media Server), idx: 2, sharing mode: unspecified, parameters: <none>
2022-05-30 11-56-24.412 [Info] (Player) Mixer mode: software, parameters: <none>
2022-05-30 11-56-24.412 [Info] (Player) Sampleformat: 44100:16:2, stream: 44100:16:2
2022-05-30 11-56-24.412 [Info] (Alsa) Using default buffer_time: 80 ms, default fragments: 4
2022-05-30 11-56-24.414 [Error] (Alsa) Exception: Can't open default, error: Host is down, code: -112
2022-05-30 11-56-24.414 [Fatal] (Snapclient) Exception: Can't open default, error: Host is down
2022-05-30 11-56-24.414 [Notice] (Snapclient) Snapclient terminated.

Run with --player pulse

sudo /usr/bin/snapclient --host=<redacted> --player pulse                                              1 ⨯
2022-05-30 11-59-35.506 [Fatal] (Snapclient) Exception: Failed to connect to PulseAudio context, error: Connection refused
2022-05-30 11-59-35.506 [Notice] (Snapclient) Snapclient terminated.

Run with --player alsa

sudo /usr/bin/snapclient --host=<redacted> --player alsa                                           2022-05-30 13-24-48.261 [Info] (Snapclient) Version 0.26.0
2022-05-30 13-24-48.261 [Info] (Connection) Resolving host IP for: <redacted>
2022-05-30 13-24-48.261 [Info] (Connection) Connecting
2022-05-30 13-24-48.266 [Notice] (Connection) Connected to 10.0.0.162
2022-05-30 13-24-48.266 [Info] (Connection) My MAC: "<redacted>", socket: 8
2022-05-30 13-24-48.274 [Info] (Controller) ServerSettings - buffer: 1000, latency: 0, volume: 100, muted: 0
2022-05-30 13-24-48.274 [Info] (Controller) Codec: flac, sampleformat: 44100:16:2
2022-05-30 13-24-48.274 [Info] (Player) Player name: alsa, device: default, description: Default ALSA Output (currently PipeWire Media Server), idx: 2, sharing mode: unspecified, parameters: <none>
2022-05-30 13-24-48.274 [Info] (Player) Mixer mode: software, parameters: <none>
2022-05-30 13-24-48.274 [Info] (Player) Sampleformat: 44100:16:2, stream: 44100:16:2
2022-05-30 13-24-48.274 [Info] (Alsa) Using default buffer_time: 80 ms, default fragments: 4
2022-05-30 13-24-48.276 [Error] (Alsa) Exception: Can't open default, error: Host is down, code: -112
2022-05-30 13-24-48.276 [Fatal] (Snapclient) Exception: Can't open default, error: Host is down
2022-05-30 13-24-48.276 [Notice] (Snapclient) Snapclient terminated.
candlelightreveal commented 2 years ago

After a few more hours of experimenting, I was able to get to a working state.

Although I am not a Linux audio or Pipewire expert, it appears that Pipewire requires audio to be played from the same user that is currently logged into the local session. So running the service under the snapclient user doesn't work when logged in as my desktop user. Additionally, if running the binary directly, it has to be executed from a keyboard attached to the computer - over SSH doesn't work, I'm assuming something to do with environment variables but I didn't dig deeper.

My working solution was to set up a user service with the service definition without the User and Group variables under ~/.config/systemd/user/snapclient.service which can be enabled with systemctl --user daemon-reload && systemctl --user enable snapclient.service && systemctl --user start snapclient.service.

I'm still hoping to hear from the snapcast team to see if my solution makes sense or if there is a better way. Hopefully my findings can be used to improve Fedora support in future versions.

deisi commented 1 year ago

over SSH doesn't work, I'm assuming something to do with environment variables but I didn't dig deeper.

For pulse based systems, only up on a GUI login, the pulse audio service was started. Otherwise there was no systemctl --user status pulse.service service running. As a result you had no audio via pulse. I'm assuming pipewire behaves the same.