Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Can't get snapclient to work raspbian buster (pulseaudio) #779

Closed
paszczaq opened this issue Jan 26, 2021 · 12 comments
Closed

Can't get snapclient to work raspbian buster (pulseaudio) #779

paszczaq opened this issue Jan 26, 2021 · 12 comments
Labels
bug feature request next release fixed in develop branch and will be part of the next release

Comments

@paszczaq
Copy link

I'm trying to setup headless RPI Zero W connected over bluetooth to speaker to stream from snapserver. It doesnt work when snapclient is run as service. I can run as user (pi) and then it works fine.

Steps to Reproduce

  1. Installed fresh rpi os (full / lite)
  2. Connected Pi over bluetooth with speaker - it can play fine from mopidy using pulse (output = pulsesink server=127.0.0.1)
  3. snapclient -l shows:
    `pi@sypialnia-pi0:~ $ snapclient -l
    0: default
    Playback/recording through the PulseAudio sound server

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

2: jack
JACK Audio Connection Kit

3: pulse
PulseAudio Sound Server

4: sysdefault:CARD=b1
bcm2835 HDMI 1, bcm2835 HDMI 1
Default Audio Device

5: dmix:CARD=b1,DEV=0
bcm2835 HDMI 1, bcm2835 HDMI 1
Direct sample mixing device

6: dsnoop:CARD=b1,DEV=0
bcm2835 HDMI 1, bcm2835 HDMI 1
Direct sample snooping device

7: hw:CARD=b1,DEV=0
bcm2835 HDMI 1, bcm2835 HDMI 1
Direct hardware device without any conversions

8: plughw:CARD=b1,DEV=0
bcm2835 HDMI 1, bcm2835 HDMI 1
Hardware device with all software conversions

9: usbstream:CARD=b1
bcm2835 HDMI 1
USB Stream Output
`

when trying to run snapclient as snapclient user:

`pi@sypialnia-pi0:/usr/share/sounds/alsa $ sudo -u snapclient -g snapclient snapclient -l
0: null
Discard all samples (playback) or generate zero samples (capture)

1: jack
JACK Audio Connection Kit

2: pulse
PulseAudio Sound Server

3: default:CARD=b1
bcm2835 HDMI 1, bcm2835 HDMI 1
Default Audio Device

4: sysdefault:CARD=b1
bcm2835 HDMI 1, bcm2835 HDMI 1
Default Audio Device

5: dmix:CARD=b1,DEV=0
bcm2835 HDMI 1, bcm2835 HDMI 1
Direct sample mixing device

6: dsnoop:CARD=b1,DEV=0
bcm2835 HDMI 1, bcm2835 HDMI 1
Direct sample snooping device

7: hw:CARD=b1,DEV=0
bcm2835 HDMI 1, bcm2835 HDMI 1
Direct hardware device without any conversions

8: plughw:CARD=b1,DEV=0
bcm2835 HDMI 1, bcm2835 HDMI 1
Hardware device with all software conversions

9: usbstream:CARD=b1
bcm2835 HDMI 1
USB Stream Output`

When trying to run:

`pi@sypialnia-pi0:$ sudo -u snapclient -g snapclient snapclient -s 2 -h 192.168.0.14
2021-01-26 14-16-14.397 [Info] (Connection) Resolving host IP for: 192.168.0.14
2021-01-26 14-16-14.413 [Info] (Connection) Connecting
2021-01-26 14-16-14.443 [Notice] (Connection) Connected to 192.168.0.14
2021-01-26 14-16-14.444 [Info] (Connection) My MAC: "b8:27:eb:e2:ad:93", socket: 8
2021-01-26 14-16-18.010 [Info] (Controller) ServerSettings - buffer: 1000, latency: 0, volume: 100, muted: 0
metadata:{"STREAM":"default"}
2021-01-26 14-16-18.017 [Info] (Controller) Codec: flac, sampleformat: 48000:16:2
2021-01-26 14-16-18.019 [Info] (Player) Player name: alsa, device: pulse, description: PulseAudio Sound Server, idx: 2, sharing mode: unspecified, parameters:
2021-01-26 14-16-18.025 [Info] (Player) Mixer mode: software, parameters:
2021-01-26 14-16-18.027 [Info] (Player) Sampleformat: 48000:16:2, stream: 48000:16:2
2021-01-26 14-16-18.032 [Info] (Alsa) Using buffer_time: 80 ms, fragments: 4
ALSA lib pulse.c:243:(pulse_connect) PulseAudio: Unable to connect: Connection refused

2021-01-26 14-16-18.096 [Error] (Alsa) Exception: Can't open pulse, error: Connection refused, code: -111
2021-01-26 14-16-18.105 [Fatal] (Snapclient) Exception: Can't open pulse, error: Connection refused
2021-01-26 14-16-18.115 [Notice] (Snapclient) Snapclient terminated.`

Environment details

  • OS: Raspbian 10 ( 5.4.83+ #1379 Mon Dec 14 13:06:05 GMT 2020 armv6l GNU/Linux)
  • Snapcast version: v0.23.0
  • Installed from a package (deb form arm)
@paszczaq paszczaq added the bug label Jan 26, 2021
@badaix
Copy link
Owner

badaix commented Jan 26, 2021

Seems like alsa cannot connect to pulse. That's an alsa/setup issue.
Why aren't you using --player pulse to connect to your PulseAudio sink?

@paszczaq
Copy link
Author

Hello, unfortunetly same issue when trying with snapclient.service

journalctl -u snapclient.service:
sty 26 14:39:36 sypialnia-pi0 snapclient[1082]: Snapclient terminated.
sty 26 14:39:36 sypialnia-pi0 systemd[1]: snapclient.service: Main process exited, code=exited, status=1/FAILURE
sty 26 14:39:36 sypialnia-pi0 systemd[1]: snapclient.service: Failed with result 'exit-code'.
sty 26 14:39:37 sypialnia-pi0 systemd[1]: snapclient.service: Service RestartSec=100ms expired, scheduling restart.
sty 26 14:39:37 sypialnia-pi0 systemd[1]: snapclient.service: Scheduled restart job, restart counter is at 4.
sty 26 14:39:37 sypialnia-pi0 systemd[1]: Stopped Snapcast client.
sty 26 14:39:37 sypialnia-pi0 systemd[1]: Started Snapcast client.
sty 26 14:39:37 sypialnia-pi0 snapclient[1083]: Exception: Failed to connect to PulseAudio context: Connection refused
sty 26 14:39:37 sypialnia-pi0 snapclient[1083]: Snapclient terminated.
sty 26 14:39:37 sypialnia-pi0 systemd[1]: snapclient.service: Main process exited, code=exited, status=1/FAILURE
sty 26 14:39:37 sypialnia-pi0 systemd[1]: snapclient.service: Failed with result 'exit-code'.
sty 26 14:39:37 sypialnia-pi0 systemd[1]: snapclient.service: Service RestartSec=100ms expired, scheduling restart.
sty 26 14:39:37 sypialnia-pi0 systemd[1]: snapclient.service: Scheduled restart job, restart counter is at 5.
sty 26 14:39:37 sypialnia-pi0 systemd[1]: Stopped Snapcast client.
sty 26 14:39:37 sypialnia-pi0 systemd[1]: snapclient.service: Start request repeated too quickly.
sty 26 14:39:37 sypialnia-pi0 systemd[1]: snapclient.service: Failed with result 'exit-code'.
sty 26 14:39:37 sypialnia-pi0 systemd[1]: Failed to start Snapcast client.

I know that PulseAudio is running per user mode, but my mopidy instance which runs as user: mopidy is working fine (playing music)

@badaix
Copy link
Owner

badaix commented Jan 26, 2021

But in mopidy you're using the pulse sink. Again: did you use --player pulse?

@paszczaq
Copy link
Author

paszczaq commented Jan 26, 2021

Yes, i tried with --player pulse via: /etc/defaults/snapclient

pi@sypialnia-pi0:~ $ sudo cat /etc/default/snapclient
START_SNAPCLIENT=true
SNAPCLIENT_OPTS="--player pulse -h 192.168.0.14"

Try to start snapclient.service

pi@sypialnia-pi0:~ $ sudo systemctl start snapclient.service
pi@sypialnia-pi0:~ $ sudo systemctl status snapclient.service
● snapclient.service - Snapcast client
   Loaded: loaded (/lib/systemd/system/snapclient.service; enabled; vendor preset: enabled)
   Active: failed (Result: exit-code) since Tue 2021-01-26 18:48:55 CET; 5s ago
     Docs: man:snapclient(1)
  Process: 931 ExecStart=/usr/bin/snapclient --logsink=system $SNAPCLIENT_OPTS (code=exited, status=1/FAILURE)
 Main PID: 931 (code=exited, status=1/FAILURE)

sty 26 18:48:55 sypialnia-pi0 systemd[1]: snapclient.service: Service RestartSec=100ms expired, scheduling restart.
sty 26 18:48:55 sypialnia-pi0 systemd[1]: snapclient.service: Scheduled restart job, restart counter is at 5.
sty 26 18:48:55 sypialnia-pi0 systemd[1]: Stopped Snapcast client.
sty 26 18:48:55 sypialnia-pi0 systemd[1]: snapclient.service: Start request repeated too quickly.
sty 26 18:48:55 sypialnia-pi0 systemd[1]: snapclient.service: Failed with result 'exit-code'.
sty 26 18:48:55 sypialnia-pi0 systemd[1]: Failed to start Snapcast client.

and also tried from command line with

pi@sypialnia-pi0:~ $ sudo -u snapclient -g snapclient snapclient --player pulse -h 192.168.0.14
2021-01-26 18-45-44.497 [Fatal] (Snapclient) Exception: Failed to connect to PulseAudio context: Connection refused
2021-01-26 18-45-44.500 [Notice] (Snapclient) Snapclient terminated.

I think I'm missing something, or maybe didnt configure something...

@badaix
Copy link
Owner

badaix commented Jan 26, 2021

Is Snapclient in the audio group? (execute groups snapclient).
Can snapclient run in the audio group? sudo -u snapclient -g audio snapclient -s 2 -h 192.168.0.14
What user/group is mopidy running as?

@paszczaq
Copy link
Author

Yes snapclient is in the audio group:

pi@sypialnia-pi0:~ $ groups snapclient
snapclient : snapclient audio video bluetooth

compared to mopidy:

pi@sypialnia-pi0:~ $ groups mopidy
mopidy : audio video

mopidy is running as user mopidy and group audio

I've tried to run:

pi@sypialnia-pi0:~ $ sudo -u snapclient -g audio snapclient -s 2 -h 192.168.0.14
2021-01-27 13-58-51.690 [Info] (Connection) Resolving host IP for: 192.168.0.14
2021-01-27 13-58-51.693 [Info] (Connection) Connecting
2021-01-27 13-58-51.697 [Notice] (Connection) Connected to 192.168.0.14
2021-01-27 13-58-51.700 [Info] (Connection) My MAC: "b8:27:eb:e2:ad:93", socket: 8
2021-01-27 13-58-52.727 [Info] (Controller) ServerSettings - buffer: 1000, latency: 0, volume: 100, muted: 0
metadata:{"STREAM":"default"}
2021-01-27 13-58-52.733 [Info] (Controller) Codec: flac, sampleformat: 48000:16:2
2021-01-27 13-58-52.735 [Info] (Player) Player name: alsa, device: pulse, description: PulseAudio Sound Server, idx: 2, sharing mode: unspecified, parameters: <none>
2021-01-27 13-58-52.739 [Info] (Player) Mixer mode: software, parameters: <none>
2021-01-27 13-58-52.741 [Info] (Player) Sampleformat: 48000:16:2, stream: 48000:16:2
2021-01-27 13-58-52.743 [Info] (Alsa) Using buffer_time: 80 ms, fragments: 4
ALSA lib pulse.c:243:(pulse_connect) PulseAudio: Unable to connect: Connection refused

2021-01-27 13-58-52.764 [Error] (Alsa) Exception: Can't open pulse, error: Connection refused, code: -111
2021-01-27 13-58-52.770 [Fatal] (Snapclient) Exception: Can't open pulse, error: Connection refused
2021-01-27 13-58-52.774 [Notice] (Snapclient) Snapclient terminated.

so same error.

I have second Pi - RPI 2B - but same OS (newest Pi OS) and same isssue if I try to run with --player pulse or select soundcard -> PulseServer. I can run snapclint on Pi2 by selecting jack output... but that cannot be done on Pi Zero (becouse currently i do not have any hifi berry)

Seems like issue with Pi OS / PulseAudio permissions...
I will try to run on different sd card ubuntu server 20.04 LTS to see if it work fine (as I guest it also uses PulseAudio)

@badaix
Copy link
Owner

badaix commented Jan 28, 2021

Is the pulseaudio server running? I also get connection refused on RPi where no PulseAudio sound server is installed.

@paszczaq
Copy link
Author

Yes pulseaudio is running (I configured it to start with user pi and configured pi via raspi-config to autologin user pi to console) to make sure its running

pi@sypialnia-pi0:~ $ systemctl --user status pulseaudio.service
● pulseaudio.service - Sound Service
   Loaded: loaded (/usr/lib/systemd/user/pulseaudio.service; enabled; vendor preset: enabled)
   Active: active (running) since Wed 2021-01-27 22:20:28 CET; 24h ago
 Main PID: 499 (pulseaudio)
   CGroup: /user.slice/user-1000.slice/[email protected]/pulseaudio.service
           ├─499 /usr/bin/pulseaudio --daemonize=no
           └─521 /usr/lib/arm-linux-gnueabihf/pulse/gsettings-helper

sty 27 22:12:58 sypialnia-pi0 systemd[488]: Starting Sound Service...
sty 27 22:20:27 sypialnia-pi0 pulseaudio[499]: W: [pulseaudio] module.c: module-combine is deprecated: Please use module
sty 27 22:20:27 sypialnia-pi0 pulseaudio[499]: W: [pulseaudio] module-combine.c: We will now load module-combine-sink. P
sty 27 22:20:28 sypialnia-pi0 systemd[488]: Started Sound Service.

Well PulseAudio is installed now by default as stated in release notes for Pi OS - see change from 2020-12-02
https://downloads.raspberrypi.org/raspios_full_armhf/release_notes.txt
PulseAudio now included and running by default

@kingosticks
Copy link
Contributor

kingosticks commented Jan 28, 2021

When using it with Mopidy you specify the server IP. But how does snapclient know what pulse server to connect to? It passes in NULL for that parameter when calling pa_context_connect() which apparently uses the "default" server. What is the "default" pulse server on a system? It sounds reasonable that it would be the local one at 127.0.0.1 but maybe it's not? Try specifying it using pulseaudio's default-server config setting?

Edit: Found this:

If the the application using the library specifies a server to connect to it is used. If the connection fails, the library fails too.
If the environment variable $PULSE_SERVER is defined the library connects to that server. If the connection fails, the library fails too.
If $DISPLAY is set, the library tries to connect to that server and looks for the root window property PULSE_SERVER for the host to connect to. If PULSE_COOKIE is set it is used as the path to the authentication cookie.
If the client configuration file (~/.pulse/client.conf or /etc/pulse/client.conf) sets the server address, the library connects to that server. If the connection fails, the library fails too.
The library tries to connect to the default local UNIX socket for PulseAudio servers. If the connection fails, it proceeds with the next item.
The library tries to connect to the default local TCP socket for PulseAudio servers. If the connection fails, it proceeds with the next item.
If $DISPLAY is set, the library tries to connect to the default TCP port of that host. If the connection fails, it proceeds with the next item. 
The connection fails.

Also:

PulseAudio now included and running by default

As I understand it, pulseaudio is only included and running by default for the "full" flavour of Pi OS. It's not yet clear what they plan to do for the lite version but last time I tried it (post 2/12/20) it was not using pulse and it worked as before. Having two different audio configurations for the two flavours is going to be a total mess for everyone so I hope they work it out.

@paszczaq
Copy link
Author

@kingosticks Thank You very much! Seems that was the issue with settings in PulseAudio (defaults obviously) and snapclient - i guest it dosnt know about local server? And also your're rigt about the mess in Pi OS - the lite version doesnt include PulseAudio and 'normal' version does.
So to sum up: On rpi4 - running snapcast server and 'normal' version of Pi OS (gui etc) i did setup

/etc/pulse/client.conf

with

; default-sink =
; default-source =
default-server = 127.0.0.1
; default-dbus-server =

It worked, snapclient can start as service!

The second pi which is RaspberryPi Zero W - i've installed lite version and didnt do anything (just put server address :)

@badaix
Copy link
Owner

badaix commented Feb 1, 2021

With commit ed9a8c6 you can configure the PulseAudio server by adding the server parameter to the player argument: --player pulse:server=<PA server>.
An automated built is available in actions

@badaix badaix added feature request next release fixed in develop branch and will be part of the next release labels Feb 1, 2021
@gribouk
Copy link

gribouk commented Feb 20, 2021

Dear Community, I am having similar problems with the PiOs full but with different outcome when I try to impliment your solution. Would you advise what steps to undertake, please... (below is the compy of my post in another branch where I have opened the issue. Do not take it as spam. I copy it here again for the reason more people who know the problem to see it):

Before the finall step it seemed exactly my case - all the errors were reproduced step by step. But, when I made the changes marked as a solution:

changes to /etc/pulse/client.conf

; default-sink =
; default-source =
default-server = 127.0.0.1
; default-dbus-server =

, everything stopped working completely. Describe it step by step:

Before:
    When I call from command line: snapclient -i 3
        Client starts
    When I call from the command line: systemctl start snapclient.service
        Error from my original post
Now:
    When I call from command line: snapclient -i 3
        Error:

2021-02-20 15-34-50.799 [Info] (Avahi) (Browser) NEW: service 'Snapcast' of type '_snapcast._tcp' in domain 'local'
2021-02-20 15-34-50.800 [Info] (Avahi) (Browser) CACHE_EXHAUSTED
2021-02-20 15-34-50.938 [Info] (Avahi) Service 'Snapcast' of type '_snapcast._tcp' in domain 'local':
2021-02-20 15-34-50.938 [Info] (Avahi)  tigraresidence-NUC10i7-srv1.local:1704 (192.168.1.246)
2021-02-20 15-34-50.939 [Info] (Controller) Found server 192.168.1.246:1704
2021-02-20 15-34-50.939 [Info] (Connection) Resolving host IP for: 192.168.1.246
2021-02-20 15-34-50.939 [Info] (Connection) Connecting
2021-02-20 15-34-50.943 [Notice] (Connection) Connected to 192.168.1.246
2021-02-20 15-34-50.943 [Info] (Connection) My MAC: "dc:a6:32:c5:51:4c", socket: 8
2021-02-20 15-34-51.081 [Info] (Controller) ServerSettings - buffer: 1000, latency: 0, volume: 10, muted: 0
metadata:{"STREAM":"tigra_is_broadcasting"}
2021-02-20 15-34-51.081 [Info] (Controller) Codec: flac, sampleformat: 44100:16:2
2021-02-20 15-34-51.081 [Info] (Player) Player name: alsa, device: default, description: <none>, idx: 4, sharing mode: unspecified, parameters: <none>
2021-02-20 15-34-51.081 [Info] (Player) Mixer mode: software, parameters: <none>
2021-02-20 15-34-51.081 [Info] (Player) Sampleformat: 44100:16:2, stream: 44100:16:2
2021-02-20 15-34-51.081 [Info] (Alsa) Using buffer_time: 80 ms, fragments: 4
ALSA lib pulse.c:243:(pulse_connect) PulseAudio: Unable to connect: Connection refused

2021-02-20 15-34-51.084 [Error] (Alsa) Exception: Can't open default, error: Connection refused, code: -111
2021-02-20 15-34-51.084 [Fatal] (Snapclient) Exception: Can't open default, error: Connection refused
2021-02-20 15-34-51.085 [Notice] (Snapclient) Snapclient terminated.

I have tried to indicate the ip of the computer where it is all installed and PulseServer too explicitelly: 192.168.1.247 - same result

When I try to tell --player pulse, I get this error:

pi@raspberrypi:~ $ snapclient -i 3 -s 4 --player pulse
Assertion 'o' failed at pulse/operation.c:133, function pa_operation_get_state(). Aborting.
Aborted
Do you know why this might be happening? Thank you in advance for any help.

UPD: I have checked if PulseAudio server starts when I indicate default server IP and it does not. Am I missing something?

@badaix badaix closed this as completed Feb 26, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug feature request next release fixed in develop branch and will be part of the next release
Projects
None yet
Development

No branches or pull requests

4 participants