plietar / librespot

Open Source Spotify client library
MIT License
1.14k stars 185 forks source link

HiFiBerry / ALSA errors #56

Closed arigit closed 8 years ago

arigit commented 8 years ago

Trying to use librespot with HiFiBerry, on OSMC; audio on HiFiBerry DAC works perfect on OSMC/Kodi

Using the latest binary package from here: https://github.com/herrernst/librespot/releases

When launching librespot, I authentication works but then I get a bunch of ALSA errors, can spotify clients are unable to see the Raspberry

./librespot --name Raspberry --bitrate 320 --username YOURUSERNAME --password YOURPASSOWORD --appkey /home/osmc/spotify-connect/spotify_appkey.key --cache /tmp Authenticated ! ALSA lib pcm.c:2239:(snd_pcm_open_noupdate) Unknown PCM cards.pcm.front ALSA lib pcm.c:2239:(snd_pcm_open_noupdate) Unknown PCM cards.pcm.rear ALSA lib pcm.c:2239:(snd_pcm_open_noupdate) Unknown PCM cards.pcm.center_lfe ALSA lib pcm.c:2239:(snd_pcm_open_noupdate) Unknown PCM cards.pcm.side ALSA lib pcm.c:2239:(snd_pcm_open_noupdate) Unknown PCM cards.pcm.surround21 ALSA lib pcm.c:2239:(snd_pcm_open_noupdate) Unknown PCM cards.pcm.surround21 ALSA lib pcm.c:2239:(snd_pcm_open_noupdate) Unknown PCM cards.pcm.surround40 ALSA lib pcm.c:2239:(snd_pcm_open_noupdate) Unknown PCM cards.pcm.surround41 ALSA lib pcm.c:2239:(snd_pcm_open_noupdate) Unknown PCM cards.pcm.surround50 ALSA lib pcm.c:2239:(snd_pcm_open_noupdate) Unknown PCM cards.pcm.surround51 ALSA lib pcm.c:2239:(snd_pcm_open_noupdate) Unknown PCM cards.pcm.surround71 ALSA lib pcm.c:2239:(snd_pcm_open_noupdate) Unknown PCM cards.pcm.iec958 ALSA lib pcm.c:2239:(snd_pcm_open_noupdate) Unknown PCM cards.pcm.iec958 ALSA lib pcm.c:2239:(snd_pcm_open_noupdate) Unknown PCM cards.pcm.iec958 ALSA lib pcm.c:2239:(snd_pcm_open_noupdate) Unknown PCM cards.pcm.hdmi ALSA lib pcm.c:2239:(snd_pcm_open_noupdate) Unknown PCM cards.pcm.hdmi ALSA lib pcm.c:2239:(snd_pcm_open_noupdate) Unknown PCM cards.pcm.modem ALSA lib pcm.c:2239:(snd_pcm_open_noupdate) Unknown PCM cards.pcm.modem ALSA lib pcm.c:2239:(snd_pcm_open_noupdate) Unknown PCM cards.pcm.phoneline ALSA lib pcm.c:2239:(snd_pcm_open_noupdate) Unknown PCM cards.pcm.phoneline ALSA lib pcm_direct.c:896:(snd1_pcm_direct_initialize_slave) slave plugin does not support mmap interleaved or mmap noninterleaved access ALSA lib pcm_dmix.c:1034:(snd_pcm_dmix_open) unable to initialize slave kMessageTypeHello Raspberry b7870749a82019bec25fcc2db279951e62cdbd42 1 1457572877310

The output of aplay -l is:

aplay -l \ List of PLAYBACK Hardware Devices ** card 0: sndrpihifiberry [snd_rpi_hifiberry_dacplus], device 0: HiFiBerry DAC+ Pro HiFi pcm512x-hifi-0 [] Subdevices: 1/1 Subdevice #0: subdevice #0

arigit commented 8 years ago

Made some progress by:

Now I get the following error:

Authenticated ! ALSA lib pcm.c:2239:(snd_pcm_open_noupdate) Unknown PCM cards.pcm.rear ALSA lib pcm.c:2239:(snd_pcm_open_noupdate) Unknown PCM cards.pcm.center_lfe ALSA lib pcm.c:2239:(snd_pcm_open_noupdate) Unknown PCM cards.pcm.side ALSA lib pcm.c:2239:(snd_pcm_open_noupdate) Unknown PCM cards.pcm.surround21 ALSA lib pcm.c:2239:(snd_pcm_open_noupdate) Unknown PCM cards.pcm.surround21 ALSA lib pcm.c:2239:(snd_pcm_open_noupdate) Unknown PCM cards.pcm.surround40 ALSA lib pcm.c:2239:(snd_pcm_open_noupdate) Unknown PCM cards.pcm.surround41 ALSA lib pcm.c:2239:(snd_pcm_open_noupdate) Unknown PCM cards.pcm.surround50 ALSA lib pcm.c:2239:(snd_pcm_open_noupdate) Unknown PCM cards.pcm.surround51 ALSA lib pcm.c:2239:(snd_pcm_open_noupdate) Unknown PCM cards.pcm.surround71 ALSA lib pcm.c:2239:(snd_pcm_open_noupdate) Unknown PCM cards.pcm.iec958 ALSA lib pcm.c:2239:(snd_pcm_open_noupdate) Unknown PCM cards.pcm.iec958 ALSA lib pcm.c:2239:(snd_pcm_open_noupdate) Unknown PCM cards.pcm.iec958 ALSA lib pcm.c:2239:(snd_pcm_open_noupdate) Unknown PCM cards.pcm.hdmi ALSA lib pcm.c:2239:(snd_pcm_open_noupdate) Unknown PCM cards.pcm.hdmi ALSA lib pcm.c:2239:(snd_pcm_open_noupdate) Unknown PCM cards.pcm.modem ALSA lib pcm.c:2239:(snd_pcm_open_noupdate) Unknown PCM cards.pcm.modem ALSA lib pcm.c:2239:(snd_pcm_open_noupdate) Unknown PCM cards.pcm.phoneline ALSA lib pcm.c:2239:(snd_pcm_open_noupdate) Unknown PCM cards.pcm.phoneline Expression 'SetApproximateSampleRate( pcm, hwParams, defaultSr )' failed in 'src/hostapi/alsa/pa_linux_alsa.c', line: 932 kMessageTypeHello Raspberry b7870749a82019bec25fcc2db279951e62cdbd42 1 1457575041944

herrernst commented 8 years ago

Seems to be mostly a problem with ALSA configuration. I'm also using a HiFiBerry, without any problems. Do you have an ~/.asoundrc or /etc/asound.conf, and what's in there? I'm using direct hardware access for now, but of course then librespot is locking the device and no other process can use your sound card:

pcm.!default  {
 type hw card 0
}
ctl.!default {
 type hw card 0
}

I always get the following messages on librespot start (and have learned to ignore them instead of fixing them):

ALSA lib pcm.c:2239:(snd_pcm_open_noupdate) Unknown PCM cards.pcm.front
ALSA lib pcm.c:2239:(snd_pcm_open_noupdate) Unknown PCM cards.pcm.rear
ALSA lib pcm.c:2239:(snd_pcm_open_noupdate) Unknown PCM cards.pcm.center_lfe
ALSA lib pcm.c:2239:(snd_pcm_open_noupdate) Unknown PCM cards.pcm.side
ALSA lib pcm.c:2239:(snd_pcm_open_noupdate) Unknown PCM cards.pcm.surround21
ALSA lib pcm.c:2239:(snd_pcm_open_noupdate) Unknown PCM cards.pcm.surround21
ALSA lib pcm.c:2239:(snd_pcm_open_noupdate) Unknown PCM cards.pcm.surround40
ALSA lib pcm.c:2239:(snd_pcm_open_noupdate) Unknown PCM cards.pcm.surround41
ALSA lib pcm.c:2239:(snd_pcm_open_noupdate) Unknown PCM cards.pcm.surround50
ALSA lib pcm.c:2239:(snd_pcm_open_noupdate) Unknown PCM cards.pcm.surround51
ALSA lib pcm.c:2239:(snd_pcm_open_noupdate) Unknown PCM cards.pcm.surround71
ALSA lib pcm.c:2239:(snd_pcm_open_noupdate) Unknown PCM cards.pcm.iec958
ALSA lib pcm.c:2239:(snd_pcm_open_noupdate) Unknown PCM cards.pcm.iec958
ALSA lib pcm.c:2239:(snd_pcm_open_noupdate) Unknown PCM cards.pcm.iec958
ALSA lib pcm.c:2239:(snd_pcm_open_noupdate) Unknown PCM cards.pcm.hdmi
ALSA lib pcm.c:2239:(snd_pcm_open_noupdate) Unknown PCM cards.pcm.hdmi
ALSA lib pcm.c:2239:(snd_pcm_open_noupdate) Unknown PCM cards.pcm.modem
ALSA lib pcm.c:2239:(snd_pcm_open_noupdate) Unknown PCM cards.pcm.modem
ALSA lib pcm.c:2239:(snd_pcm_open_noupdate) Unknown PCM cards.pcm.phoneline
ALSA lib pcm.c:2239:(snd_pcm_open_noupdate) Unknown PCM cards.pcm.phoneline
ALSA lib pulse.c:243:(pulse_connect) PulseAudio: Unable to connect: Connection refused
ALSA lib pulse.c:243:(pulse_connect) PulseAudio: Unable to connect: Connection refused
ALSA lib pcm_direct.c:896:(snd1_pcm_direct_initialize_slave) slave plugin does not support mmap interleaved or mmap noninterleaved access
ALSA lib pcm_dmix.c:1034:(snd_pcm_dmix_open) unable to initialize slave

But then, it plays fine.

arigit commented 8 years ago

Thanks this looks more promising then :)

I created /etc/asound.conf Without doing anything else but adding that file, I am getting this: .... ALSA lib pcm_direct.c:896:(snd1_pcm_direct_initialize_slave) slave plugin does not support mmap interleaved or mmap noninterleaved access ALSA lib pcm_dmix.c:1034:(snd_pcm_dmix_open) unable to initialize slave

(same as you posted!)

Then when I launch the android client, librespot immediately crashes:

kMessageTypeHello Raspberry b7870749a82019bec25fcc2db279951e62cdbd42 1 1457617858419 thread '' panicked at 'called Result::unwrap() on an Err value: WireError("invalid value for enum: 10")', ../src/libcore/result.rs:746 note: Run with RUST_BACKTRACE=1 for a backtrace. thread '' panicked at 'called Result::unwrap() on an Err value: RecvError', ../src/libcore/result.rs:746 thread '

' panicked at 'called Result::unwrap() on an Err value: "SendError(..)"', ../src/libcore/result.rs:746

And the availability of Spotify Connect devices never shows in the Client. I tried running librespot as "osmc" and as "root" and same output.

Here is the backtrace for reference: https://paste.gnome.org/pqkqrnpdy

I have a HiFiBerry DAC+, is that what you have? do you recall modifying any other config file? What about /boot/config.txt - is this needed or not: dtoverlay=i2s-mmap

If I add the extra dtoverlay line, I get an extra error at launch, but then it seems to crash in the exact same way.

Expression 'SetApproximateSampleRate( pcm, hwParams, defaultSr )' failed in 'src/hostapi/alsa/pa_linux_alsa.c', line: 932 kMessageTypeHello Raspberry b7870749a82019bec25fcc2db279951e62cdbd42 1 1457618856227 thread '' panicked at 'called Result::unwrap() on an Err value: WireError("invalid value for enum: 10")', ../src/libcore/result.rs:746 note: Run with RUST_BACKTRACE=1 for a backtrace. thread '' panicked at 'called Result::unwrap() on an Err value: RecvError', ../src/libcore/result.rs:746 thread '

' panicked at 'called Result::unwrap() on an Err value: "SendError(..)"', ../src/libcore/result.rs:746

herrernst commented 8 years ago

The WireError crash is because of an older librespot and a new/current Android app, see #54 and #55. I will update my RPi build later today.

arigit commented 8 years ago

Thank you for this!

herrernst commented 8 years ago

Try this, hope it works: https://github.com/herrernst/librespot/releases/tag/v20160307-d27c4ca

When you see the HiFiBerry device in aplay -l, you should be fine. For me, works then without asound.conf. Never messed with i2s-mmap or something else.

arigit commented 8 years ago

Well I am getting closer and closer. This worked nicely once when I first ran your latest release, with audio playback and all. Now, while librespot doesn't crash, I can't get the raspberry to show on the android client any more, not sure why! aplay looks fine (see below)

I am seeing the "jack" messages which I didn't see before; this is on a new OSMC clean install. Tried rebooting, running with sudo, stopping "mediacenter" (kodi), no joy. I found a thread that talks about librespot & jack and I am asking there as well. Any hint?

LSA lib pcm.c:2239:(snd_pcm_open_noupdate) Unknown PCM cards.pcm.modem ALSA lib pcm.c:2239:(snd_pcm_open_noupdate) Unknown PCM cards.pcm.phoneline ALSA lib pcm.c:2239:(snd_pcm_open_noupdate) Unknown PCM cards.pcm.phoneline ALSA lib pcm_direct.c:896:(snd1_pcm_direct_initialize_slave) slave plugin does not support mmap interleaved or mmap noninterleaved access ALSA lib pcm_dmix.c:1034:(snd_pcm_dmix_open) unable to initialize slave Cannot connect to server socket err = No such file or directory Cannot connect to server request channel jack server is not running or cannot be started kMessageTypeHello Raspberry b7870749a82019bec25fcc2db279951e62cdbd42 1 1457712842412 kMessageTypeHello Galaxy S6 b78f746216845f1309d617a88abc6e62c923d1ec 48 0 kMessageTypeNotify Galaxy S6 b78f746216845f1309d617a88abc6e62c923d1ec 49 0


aplay -l \ List of PLAYBACK Hardware Devices ** card 0: sndrpihifiberry [snd_rpi_hifiberry_dacplus], device 0: HiFiBerry DAC+ Pro HiFi pcm512x-hifi-0 [] Subdevices: 0/1 Subdevice #0: subdevice #0

$ cat /etc/asound.conf pcm.!default { type hw card 0 } ctl.!default { type hw card 0 }

herrernst commented 8 years ago

FWIW, I always get this messages:

ALSA lib pcm.c:2239:(snd_pcm_open_noupdate) Unknown PCM cards.pcm.front
ALSA lib pcm.c:2239:(snd_pcm_open_noupdate) Unknown PCM cards.pcm.rear
ALSA lib pcm.c:2239:(snd_pcm_open_noupdate) Unknown PCM cards.pcm.center_lfe
ALSA lib pcm.c:2239:(snd_pcm_open_noupdate) Unknown PCM cards.pcm.side
ALSA lib pcm.c:2239:(snd_pcm_open_noupdate) Unknown PCM cards.pcm.surround21
ALSA lib pcm.c:2239:(snd_pcm_open_noupdate) Unknown PCM cards.pcm.surround21
ALSA lib pcm.c:2239:(snd_pcm_open_noupdate) Unknown PCM cards.pcm.surround40
ALSA lib pcm.c:2239:(snd_pcm_open_noupdate) Unknown PCM cards.pcm.surround41
ALSA lib pcm.c:2239:(snd_pcm_open_noupdate) Unknown PCM cards.pcm.surround50
ALSA lib pcm.c:2239:(snd_pcm_open_noupdate) Unknown PCM cards.pcm.surround51
ALSA lib pcm.c:2239:(snd_pcm_open_noupdate) Unknown PCM cards.pcm.surround71
ALSA lib pcm.c:2239:(snd_pcm_open_noupdate) Unknown PCM cards.pcm.iec958
ALSA lib pcm.c:2239:(snd_pcm_open_noupdate) Unknown PCM cards.pcm.iec958
ALSA lib pcm.c:2239:(snd_pcm_open_noupdate) Unknown PCM cards.pcm.iec958
ALSA lib pcm.c:2239:(snd_pcm_open_noupdate) Unknown PCM cards.pcm.hdmi
ALSA lib pcm.c:2239:(snd_pcm_open_noupdate) Unknown PCM cards.pcm.hdmi
ALSA lib pcm.c:2239:(snd_pcm_open_noupdate) Unknown PCM cards.pcm.modem
ALSA lib pcm.c:2239:(snd_pcm_open_noupdate) Unknown PCM cards.pcm.modem
ALSA lib pcm.c:2239:(snd_pcm_open_noupdate) Unknown PCM cards.pcm.phoneline
ALSA lib pcm.c:2239:(snd_pcm_open_noupdate) Unknown PCM cards.pcm.phoneline
ALSA lib pulse.c:243:(pulse_connect) PulseAudio: Unable to connect: Connection refused

ALSA lib pulse.c:243:(pulse_connect) PulseAudio: Unable to connect: Connection refused

ALSA lib pcm_direct.c:896:(snd1_pcm_direct_initialize_slave) slave plugin does not support mmap interleaved or mmap noninterleaved access
ALSA lib pcm_dmix.c:1034:(snd_pcm_dmix_open) unable to initialize slave

Portaudio supports at least ALSA, Jack and PulseAudio, and I think it just tries to connect to different audio output methods. I think this is not your problem. I noticed discovery not being 100% reliable. Sometimes, the device doesn't appear, and you have to restart the Spotify app (or wait). You could also try specifying username/password, then "discovery" is not needed.

arigit commented 8 years ago

Testing the release that showed up today and it seems to be a lot more stable (no issues so far). Started librespot without username/password, it gets an authentication from the spotify client.

Also FWIW, confirmed that the jackd messages are irrelevant,

Cannot connect to server socket err = No such file or directory
Cannot connect to server request channel
jack server is not running or cannot be started

librespot still works - and now really well, actually better than the python wrapper for libspotify that for some reason has problems (stops after a random number of songs) when used over wifi instead of wired ethernet. I notice that librespot buffers the whole song in the first few seconds while libspotify tends to spread out the download over the whole song and seems to kill the poor wifi dongle.

The challenge I am having now with librespot is that this works only while I keep the ssh terminal open. If I launch librespot with "&" and then disconnect the terminal, I notice (from another terminal) that the librespot process dies as soon as I connect a client to it. How do you normally run librespot?

herrernst commented 8 years ago

How to start on boot depends on your distribution. If you're manually starting from terminal you could try nohup command-to-execute & (the nohup before is necessary so the program keeps running after "hanging up" the terminal by disconnecting). Or you could add the cmd to /etc/rc.local or write a simple systemd unit file: https://discourse.osmc.tv/t/how-to-run-script-at-boot-solved/3562 If librespot works for you now, I would also suggest closing this issue.

arigit commented 8 years ago

Thanks Herrernst. Actually I ran into the same issue now with librespot as I had with libspotify, music stops after some minutes of playback, more or less depending on me having the connectivity/ping script.

Once when on wifi, there is some issue that prevents librespot from recovering gracefully from packetloss (my guess). This happens regardless of 320kbps or 160kbps setting.

One thing I just noticed is that whenever issues start, I can not longer login via ssh, I get the login prompt but after authenticating succesfully, I get "Server refused to allocate pty" in Putty (or "Failed to send channel request" in my android ssh terminal and in the linux desktop. In the internet I found that this is related to having more than 256 "pseudo terminals". When I kill the librespot process from the local terminal, then all comes back to normal.

Could it be that librespot keeps spawning PTY pseudoterminals for some reason, and stops when it hits the limit?

Added kernel.pty.max = 8192 /etc/systemctl.conf (cat /proc/sys/kernel/pty/max)

Understand that this has nothing to do with ALSA though. So, closed.