If snapcast would be available in Kodi, then it would be much easier to have multiroom-audio.
You can have a "Music-server" which is the snapcast-server also. Then you could connect all other Kodi instances (zones) to it and control it via UPnP (from Kodi -> JSON) from every client or the server.
This would need a Win/MacOS port, btw.
The next benefit would be, it could then go to LibreElec also.
If you use pulseaudio for your sound-output in Kodi you have that already.
I don't know about LibreElec though. I guess they use pulseaudio as well. In the case of OSMC I know it for sure. You need some instructions?
I don't have a problem setting it up on linux, but a solution for LibreELEC would be awesome!
My FR was more to have a _easy_ solution for multiroom audio with Kodi and $opensource.
If you want to play multi-room audio, you could have a context-menu in Kodi with
So FWIW, I was able to get snapcast working on LibreELEC with Kodi, but it's not pretty:
LibreELEC has a docker addon, so I was able to get snapcast server / client running as docker images. Pulse audio can be used to create a file sink which snapserver can read. After switching Kodi to the new output the ALSA output is released for writing by snapclient.
I still agree that an addon would be really nice. I just wanted to share how I got my system working if anyone else is looking for a solution, since LibreELEC is pretty tough to modify.
Relating Pulseaudio as a solution: This can be a solution for the sound conflict, but pulseaudio is not an option on some devices. Examples: Pulseaudio does not support Passthrough. When KODI plays a movie with passthrough, alsa is blocked, which currently conflicts with a running snapcast server. Even without passthrough, Kodi LCPM Multichannel (5.1, 7.1) does not work on a raspberry PI 2 or 3 with pulseaudio. This is a limitation of the hardware, but I assume this device is widely used as KODI box.
Related KODI in general: A KODI client should be more than just a snapcast client with a GUI. It should integrate a snapcast controller and a snapcast client with e.g. a MPD/Mopidy controller. In a configuration where each Snapclient stream is representing one MPD instance, the GUI could dynamically control always that MPD instance, on which stream the client is listening. I have implemented exactly this functionality (Snapcast with MPD combined) as module for the FHEM home automation system, but this is a system without a GUI. And it is only a snapcast controler, not a client.
Agree with all of that. I think ideally there should be two components of the Kodi setup. A snapcast server component, which routes Kodi media to a built-in snapcast server, and a snapcast client component which connects to any snapcast server (potentially but not necessarily the Kodi snapcast server), and routes the audio output through Kodi's audio output subsystem.
This sort of routing should be possible with the Kodi DSP API.
I think the first step however, would be exposing an API to create snapcast servers/clients directly in python, via SWIG or something else. That could start getting done before even worrying about Kodi.
Wouldn't it be possible to add snapcast as a virtual package and build it with LE?
https://forum.libreelec.tv/thread-1654.html
https://forum.libreelec.tv/thread-688.html
This would be a start. My WetekPlay is running as a TV-server 24/7. Would be nice, if it could do snapcast also ;)
I haven't compiled LE, only OE some time ago ...
I'm having a snapcast server on Raspi which works well for 3 rooms now. It's a great piece of software. Would it be that difficult to build a snapcast client for KODI / LibreElec? That would be a great enhancement to the possibilities to use KODI as DLNA-Client or Airplay client.
yeah, currently i am running the client in the background, but if it was integrated into kodi, that would be nice!
How did you snapclient get to work in KODI? Have not tried so far.
I've copied the binary and the missing libraries to KODI and the binary starts well. But it can't connect to pulseaudio. Is there any way to get that working? Here's the output, when I start snapclient manually:
Glotze:~/.kodi/addons/snapclient # ./snapclient
soundcard "default" not found
2017-03-20 09-36-04 [out] (Browser) NEW: service 'Snapcast' of type '_snapcast._tcp' in domain 'local'
2017-03-20 09-36-04 [out] (Browser) CACHE_EXHAUSTED
2017-03-20 09-36-05 [out] Service 'Snapcast' of type '_snapcast._tcp' in domain 'local':
2017-03-20 09-36-05 [out] beere.local:1704 (192.168.178.251)
2017-03-20 09-36-05 [out] Found server 192.168.178.251:1704
2017-03-20 09-36-05 [out] Latency: 0
2017-03-20 09-36-05 [out] Connecting
2017-03-20 09-36-05 [Notice] Connected to 192.168.178.251
2017-03-20 09-36-05 [out] My MAC: "b8:27:eb:0d:f4:77", socket: 6
2017-03-20 09-36-05 [out] ServerSettings - buffer: 1000, latency: 0, volume: 100, muted: 0
2017-03-20 09-36-05 [out] Codec: flac
2017-03-20 09-36-05 [state] sampleformat: 48000:16:2
ALSA lib /home/chewitt/LibreELEC.80-official/build.LibreELEC-RPi2.arm-8.0.0/alsa-lib-1.1.2/src/pcm/pcm.c:2450:(snd_pcm_open_noupdate) Unknown PCM
2017-03-20 09-36-05 [err] Controller::onException: Can't open PCM device: No such file or directory
2017-03-20 09-36-07 [out] timeout while waiting for response to: 2, timeout 2000
2017-03-20 09-36-09 [out] timeout while waiting for response to: 3, timeout 4000
2017-03-20 09-36-11 [out] timeout while waiting for response to: 4, timeout 6000
2017-03-20 09-36-13 [out] timeout while waiting for response to: 5, timeout 8000
2017-03-20 09-36-15 [out] timeout while waiting for response to: 6, timeout 10000
2017-03-20 09-36-17 [out] timeout while waiting for response to: 7, timeout 12000
2017-03-20 09-36-17 [Err] Exception in Controller::worker(): sum timeout exceeded 10s
I finally got it working by connecting a small USB sound card to the Raspi and putting the lines
(
pactl load-module module-udev-detect
sleep 2
/storage/.kodi/addons/snapclient/snapclient -d
) &
into autostart.sh.
This gives me an audio sink via the USB soundcard which I can handle on a different input at my receiver.
Kodi sound in parallel via HDMI still works without problems.
That's the solution I ever wanted :+1:
Sorry to chime in this thread but I might have a suggestion for a really great Kodi integration.
In that case the snapclient hosts a small webserver serving the RAW/PCM audio. A small Kodi add-on listens to commands and when playback is requested it tells Kodi to connect to that internally hosted webstream.
That way, the playback is entirely handled by Kodi and thus fully integrated. You can even serve the metadata so stuff like vizualisation still works.
The addon would even be more fancy if it has indeed a Mopidy/MPD client integrated.
You can than have this set-up:
Centralized server component with Mopidy, snapcast server etc.
This may as well be one of your kodi boxes
Kodi clients with the kodi client addon which connect to the centralized component.
Oh wow, that would be awesome indeed. I am currently in the process of installing my new RasPi 3 with Hifiberry Dac, and was still figuring how I could combine all my needs and wishes. This sounds like a nice solution.
That would indeed be very great if snapcast was integrated as an installable plugin into Kodi / LibreELEC so that it would use the audio output from Kodi. The sound quality through the HDMI is much better than through the external cheap USB sound card.
Is here anybody capable of porting snapcast to an installable Kodi addon which uses the Kodi sound device? That would be great.
The solution that I built for now is ok for music by the way but not for a HIFI-esc pleasure.
I think it should be possible that both snapcast and Kodi can use the same audio device. In that case it's possible to create something. In that case I think it's best to let snapcast output the sound to the soundcard because when you place Kodi in the middle you will definitely get issues with sync.
WOW I am excited with this one! I am currently setting up my audio system and I really think Kodi should be my audio server let's say in addition with snapcast! Damn this would make my day
I already have a working solution with squeezelite, something I created a few weeks ago.
As soon as I'm able to build snapcast on Windows I'll port my previous work to support the snapcast client and will provide a test kodi addon here
Thanks a lot! Well done! :+1:
@marcelveldt If you wish any tester let me know I will be able to help.
Any progress?
@marcelveldt
Hi there, I've already spent a couple of hours setting up a test system on two RPi3s carrying each a HiFiBerry Amp2 on their resp. backs. What I achieved so far is configuring one as a snapserver (snapclient at the same time), configuring a pulse audio pipe as outlined in the instructable, installing mpd, mpc and I'm also able to play an mp3 file on both machines simultaneously via mpc running on the snapserver machine.
So far, so good.
On the server there's also Kodi running, Kodi's audio output is configured to work via pulseaudio server. Unfortunately, audio output only comes from the server machine, not from the client, which works, as already mentioned, via mpd/mpc. What else is missing? Why does Kodi not pump its audio to the fifo pipe file? I thought that pulseaudio itself should be doing exactly this redirection to the file but obviously it does not, at least not properly.
Any hints would be highly welcome!
I think you actively need to tell pulseaudio to pipe the audio of kodi
into the snapcast fifo. Take a look at https://unix.stackexchange.com/questions/65246/change-pulseaudio-input-output-from-shell/67398
In how to do this from the terminal.
I tried a similar systems, but I found a reasonable delay (500ms) between
sound an image. Even after minimizing all involved buffers from snapcast. I
assume the pulseaudio fifo adds this delay and I found no way to remove it.
If you find a solution to this I would love to know about it.
Am 25.10.2017 21:48 schrieb "FHoevi" notifications@github.com:
Hi there, I've already spent a couple of hours setting up a test system on
two RPi3s carrying each a HiFiBerry Amp2 on their resp. backs. What I
achieved so far is configuring one as a snapserver (snapclient at the same
time), configuring a pulse audio pipe as outlined in the instructable,
installing mpd, mpc and I'm also able to play an mp3 file on both machines
simultaneously via mpc running on the snapserver machine.So far, so good.
On the server there's also Kodi running, Kodi's audio output is configured
to work via pulseaudio server. Unfortunately, audio output only comes from
the server machine, not from the client, which works, as already mentioned,
via mpd/mpc. What else is missing? Why does Kodi not pump its audio to the
fifo pipe file? I thought that pulseaudio itself should be doing exactly
this redirection to the file but obviously it does not, at least not
properly.Any hints would be highly welcome!
—
You are receiving this because you commented.
Reply to this email directly, view it on GitHub
https://github.com/badaix/snapcast/issues/155#issuecomment-339449743,
or mute the thread
https://github.com/notifications/unsubscribe-auth/AFL2NFQSKIJMuKCq3d4YwdH1wQwwev2Nks5sv5CogaJpZM4LV3ii
.
Thanks for that hint but before being able to redirect I would need to do something like this, I guess sudo pacmd load-module module-pipe-sink file=/tmp/FIFO_FILENAME where FIFO_FILENAME is the file snapcast also knows about, right? The error message I get tells me that no PulseAudio service is currently running at all. How to get that? Sorry, I'm not so experienced with the intricacies of Linux as to know how it works with services of that kind.
Ah, and snapclient does neither work in daemonized mode nor does autostart on both of my test machines. When I start from a terminal playing music with mpd/mpc off the server machine it works.
Could you please provide a step-by-step guide of how you have set this up?
Within Kodi you could define a delay between audio and video as far as I remember, maybe that could solve the problem of lagging audio.
pacmd load-module module-pipe-sink file=/tmp/FIFO_FILENAME sink-name=NAME
pacmd update-sink-proplist NAME device.description=Snapcast
i.e. not executed as superuser. Now "Snapcast" shows up in pavucontrol but still Kodi plays only on the ALSA device. Maybe it's still about the wrong output settings of Kodi. But they are set to "PulseAudio server", what's missing?
When clicking on Advanced in pavucontrol -> output and the device you're interested in, there's a "Latency offset" option you could use for adjusting plus/minus steps in msec.
I think I do not understand basic concepts of pulseaudio and when which user has to start what, I'm confused. Please, could anyone provide me with a step-by-step instruction? I'm really going nuts by wasting so many hours.
Did you try/check the sample rate of your pulseaudio sinks? they should either be 44100 or 48000 Hz I belive.
@deisi Of course I did, with a sample rate of 44100 Hz set at all relevant places audio is stuttering ridiculously, after switching back to 48000 Hz it's still like in a Disney movie. BTW, 48 kHz is the native audio sample rate of the movie I use for testing purposes. In addition to the pitch being too high I also observe occasional breaks of audio transmission.
But at least a latency offset of 1000ms for the physical audio output device on all snapclients (by using pavucontrol) does the job in terms of sync'ing video and audio in my case.
There are no dropouts at all. The only remaining little thing is adjusting volume to a value at which one could adjust it comfortably, currently it is still really low.
load-module module-pipe-sink file=PATHTOFIFOFILE sink_name=SINKAME
update-sink-proplist SINKNAME device.description=Snapcast
set-default-sink SINKNAME
at the very end of /etc/pulse/default.pa where all uppercase expressions need to be adjusted according to own setup.
Audio volume has to be set properly in Kodi.
I as can see some of you been interested to see how to run snapcast on Kodi, I've
compiled instructions, they are too big to post them as comment. available here. The setup is running for couple of months no issues so far. I hope it will help to someone else.
Thx for the info
Atm my RPi3 can't find any soundcards:
LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/storage/.kodi/addons/snapserver/lib /storage/.kodi/addons/snapserver/snapclient --list
0: null
Discard all samples (playback) or generate zero samples (capture)
Here is another possible solution. Don't know which works better
https://github.com/badaix/snapcast/issues/307
@walterheisenberg snapclient is ALSA application, so it should return alsa configured soundcards.
You can list alsa devices exported in /proc by running:
`OpenELEC:~ # cat /proc/asound/cards
0 [audiocodec ]: audiocodec - audiocodec
audiocodec
1 [sndhdmi ]: sndhdmi - sndhdmi
sndhdmi
2 [audiohub ]: audio-hub - audio-hub
audio-hub
3 [NX ]: USB-Audio - SB Audigy 2 NX
Creative Technology Ltd SB Audigy 2 NX at usb-sunxi-ehci-1, high speed
`
if the output of command above is empty for you, there are no alsa soundcards configured on you system.
My aforementioned problem is solved. In case you'd be interested, have a look at this: https://github.com/frafall/service.snapcast/issues/1.
Another problem popped up, it relates to a machine running snapclient as a service. From the pi user's console I could use a couple of pactl commands to adjust e.g. latency or volume of the audio output, this works like charm. But how could I do that already at startup, i.e. with no user logged in to that machine? /etc/pulse/default.pa does not work (it seems to be bound to a user being logged in), /etc/pulse/system.pa does not work either, adding corresponding pactl commands ro /etc/rc.local does also not work. How could I get that working such that I do not necessarily have to log in and to adjust everything manually by entering pactl commands to the console at runtime?
Another couple of hours spent with that kind of s..t but I did not get the slightest step ahead so far in that respect sigh.
OK, clientwise snapclient's --latency parameter (value in ms, not mus!) indeed seems to do the job... But one has to make sure that all snapclient services involved run smoothly. So, no pulseaudio needed.
I may be hijacking this thread, but hopefully that may help someone with his setup.
Here is my feedback after connecting Kodi and Snapcast. First, I use OSMC, not Librelec, and it doesn't seem to use PulseAudio, so here's that. Oh and I use a Rasp 3 and HiFiBerry DAC.
So I went ahead with the Alsa solution ( https://github.com/badaix/snapcast/blob/master/doc/player_setup.md#alsa ) except I created a named PCM (snapcast) instead of the !default one.
Then I installed the client, configured its sound card, trifled with aplay: good to go.
If you go into Settings → System → Audio, you now find ALSA:snapcast, and yey, it was that simple. Audio works fine, all good. Well except when you want to watch any kind of video, then snapcast will not do. It obviously needs some kind of buffer to have a synchronized sound and that will be noticeable when watching a video. Plus, I use a DAC, but some people may want to use Passthrough on their HDMI out, and avoid the downsampling.
So, what I wanted was: if I'm playing audio, use snapcast, use the DAC for the rest. This feature in Kodi, well, it'll not happen apparently. This guy, cert_, did patch it though, and it worked fine for him: https://forum.kodi.tv/showthread.php?tid=137359&page=4 . Some use different profiles to manage both outputs.
Since Kodi is integrated in my home automation system, I went ahead with using the API: https://kodi.wiki/view/JSON-RPC_API/v9#Settings.GetSettings (then look for audiooutput.audiodevice). If someone's using Yaste for its remote (which I do recommend), it's pretty easy to craft a custom command to make the switch.
For the record
Running Snapclient on RPi3 w/ LibreELEC (pulseaudio) is a no brainer. Install from Repo, configure sound card in the plug-in's GUI, reboot, done.
I didn't notice any problem with running Snapclient alongside with KODI (movie, GUI sound, whatever), no matter if both run on the same output device or on separate ones.
Hey there,
is there any way to get snapclient working under libreELEC 9?
seems to be solved
Most helpful comment
Relating Pulseaudio as a solution: This can be a solution for the sound conflict, but pulseaudio is not an option on some devices. Examples: Pulseaudio does not support Passthrough. When KODI plays a movie with passthrough, alsa is blocked, which currently conflicts with a running snapcast server. Even without passthrough, Kodi LCPM Multichannel (5.1, 7.1) does not work on a raspberry PI 2 or 3 with pulseaudio. This is a limitation of the hardware, but I assume this device is widely used as KODI box.
Related KODI in general: A KODI client should be more than just a snapcast client with a GUI. It should integrate a snapcast controller and a snapcast client with e.g. a MPD/Mopidy controller. In a configuration where each Snapclient stream is representing one MPD instance, the GUI could dynamically control always that MPD instance, on which stream the client is listening. I have implemented exactly this functionality (Snapcast with MPD combined) as module for the FHEM home automation system, but this is a system without a GUI. And it is only a snapcast controler, not a client.