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
New input plugin: TCP stream #511
Comments
Awesome! I think this would be very useful for streaming pulseaudio from a different machine on the network. |
I'd love to test that on my Raspberry 4 running Raspbian Buster. I hope it could solve frequent drop-out of music when I interact with the desktop (for instance browsing internet). Could you please update the building instructions for Raspbian? (in particular, Boost provided with Raspbian Buster seems too old...) |
I will do so tonight. You will just need header only boost libs, i.e. it's enough to download and unzip the latest boost and let make/cmake point to the directory. I think you can pass the boost path to cmake like this |
Interesting. I'm using Mopidy since I first found out about Snapcast. I did not experience audible looping issues... How are you testing for that? Our GStreamer setup is the same. |
I had terrible issues with Mopidy and Gstreamer, changing songs or radio channels meant delays, glitches, looping feedbacks etc then I moved to Mpd and it works great with SC. However I am interested in this imporvement as well. |
Has anyone tried this? I run several clients and a server on raspberry pi's and have some issues with mopidy that don't seem to exist when using librespot - appreciate your good work on this software. |
I'm running with the latest dev commit, and the following configs:
Librespot is running on two separate docker containers and is forwarding FIFO to network via netcat:
and mopidy:
It seems to work well :) I'll do more stress testing this week. |
Ooh this looks good, just been discussing th issues Gstreamer has with fifos with the mopidy devs and one of them pointed me at this. I need to give this a try. One thing is slightly confusing me though, is the nomenclature around client mode/server mode. I'd assume snapserver would always need to be in 'server mode' and snapclient in 'client mode' - but I'm not sure if that makes sense - and then mopidy in... what mode? |
OK I managed to get it to build natively on a RaspberryPi 3B+ and the good news is it's working! For anybody interested in trying, here's what I did. I'm no expert at editing MakeFiles so I just blundered around making edits until it built, so here's the full list of what I changed. Download the latest libboost and unzip it somewhere. This will give you a directory we'll call <boost dir> I only rebuilt the Snapcast server. So, in <snapcast dir>/server: Edit CMakeLists.txt and find the SERVER_INCLUDE section and change it to
Then edit Makefile: Find the long line beginning CXXFLAGS += and change it to
and change the LDFLAGS line below it to
Now do
In my /etc/snapserver.conf I have
And in /etc/mopidy/mopidy.conf I have
Note that using 'localhost' in the mopidy.conf didn't work, I got errors saying GStreamer could not open the source, but using 127.0.0.1 fixed that. Wierd. The only minor issue I now have is that the playback position reported by mopidy is about 5 seconds ahead of what's coming out of my speakers. I assume this is some buffer size thing in the tcp sink, it'd be interesting to know how to change that. |
Can Snapcast run multiple modes at the same time? I still would like to be able to use fifo together with tcp |
@gerroon you can define multiple streams that have different sources (fifo, tcp) |
FWIW, the Mopidy team just dropped version 3.0.1 eleven days ago. I haven't had a chance to play with it yet. It requires Python 3.7 I've read and it uses a much more recent version of GStreamer, 1.14.0. This might be enough to resolve your issue. I'm planning on playing with it tonight. I got all of my backups in line this morning so I can step back if necessary, but I'm really excited about it. https://mopidy.com/blog/2019/12/22/mopidy-3.0/ KO |
I'm already running it. It doesn't solve the issue :) The Mopidy devs say that GStreamer and FIFOs don't play well together. They did try to make a fifo output within Mopidy some time ago but again, GStreamer makes it hard. This new TCP sink is the way forward. |
My biggest concern is that the configuration seems to rely on static IP addresses, which I spent a few days getting rid of in favor of DHCP when I went to OpenWRT a month or two ago . I really want to stay dynamic. My implementation of the static IP addresses was ugly and I'd really prefer to not step back to it. |
Well if you're using it in place of a fifo - which you can't use over a network anyway - then the only IP address you need is 127.0.0.1, which is 'local loopback' and requires no configuration. |
TYVM! |
I've been testing this all night, and it's working great with a bunch of streams. I've been able to separate my services (multiple librespot instances, mopidy, etc) and the FIFO mess is gone! I've also been able to stream the audio from my PC to snapcast from pulseaudio. Config:
On my PC I pipe pulseaudio to netcat:
Does anyone know of a better way to have pulseaudio send raw PCM over a network to a host? |
@badaix I have one suggestion... instead of |
Another confirmed working: the develop branch builds just fine on Armbian (ubuntu bionic) after manually installing the ubuntu libboost1.71-dev package (https://launchpad.net/ubuntu/+source/boost1.71). And the tcp stream works great with mopidy 3.0. Thanks! @fatg3erman very early testing suggests something seems to be up with the RompR snapcast volume control when using the TCP stream. Here's the output I get: RompR v1.30 Cheers |
If I understand this correctly, I could run a stream in server mode, and on another machine netcat a PCM stream to the IP/PORT set in the stream, is that right? This is great timing as I've been looking for a way to easily stream a PCM capture from a remote device. |
@eoware yes, correct. |
can't seem to get this to work with librespot (raspotify) -- could be my lack of understanding about netcat . . . I'm running librespot on the same server as the snapserver.... TCP seems to work ok with mopidy. |
@JayGatsby7 can you provide more information? |
I’m using mopidy with tcp for the time being but would like to get librespot working with tcp on a separate port as well. |
@KraigoMpls: I will keep this in mind for the next version. I already started to implementing host resolution, but removed it for this first version of the tcp plugin. I think for most users the audio source will run on the same host. You can open a feature request for this, so that I will not forget about it. |
To be honest I think that Mopidy using Gstreamer as a backend was a bad move and I myself wasted so many hours on the same issue while trying to fix it. |
Great, glad to know it's not me. I'll stop wasting more hours then :) Ironically I've had a little more success with Mopidy by using the
and then creating a custom entry in my
But it still is not as reliable as |
Any ideas when this plugin might be on official release? I'm interested because of remote parec |
Did you tried to use According to documentation you can specify hostname. |
Dumb question. I've read and re-read this issue and it looks like a plugin is needed? Thanks |
I’ve been running this regularly since it was first released and have at some point encountered all the problems described in the thread. I’ve done a lot of debugging and a lot of research and have come to the conclusion that, if it’s not outputting directly to audio hardware, GStreamer just isn’t very good. To everybody having issues with mopidy my only advice is either learn to live with them or switch to MPD. |
This is why Mopidy is not cutting it. I exactly did what fatg3erman says, switched to MPD. |
Are there other output plugins available that could me more reliable? |
I did get the TCP stream working after upgrading to Mopidy 3. |
Have the following working with TCP between Mopidy and Snapcast, works much better than FIFO:
The issue is if i do 1. and 2. at the same time then both songs come out of music-1.local speakers at the the same time. It there a way to have it so the latest action cancels the previous action? Below are the configurations: Server (Unraid VM/Ubuntu 20.04): music.local /etc/snapserver.conf /etc/mopidy/mopidy.conf
Remote/s (RPI/Ubuntu 20.04): music-1.local, music-2.local /etc/defaults/snapclient /etc/mopidy/mopidy.conf
|
Yes, if used with wavenc. But we don't need wavenc since snapcast wants S16LE PCM @ 48K (or whatever you have configured) and that's what
I've tested with GStreamer 1.16.2.0 on Ubuntu 20.04 and GStreamer 1.14.4.0 on Raspbian Buster. However, I do see the issue with the playback position within Mopidy not corresponding to what snapcast is playing. Mopidy's position is delayed. Need to spend more time looking at that. I also hear a little stutter when playing starts or seeks but I'm not convinced that's a Mopidy/GStreamer issue. It's maybe worth also mentioning that seeking actually works OK if you substitute wavenc for a different encoder e.g. opusenc. Obviously snapcast can't decode opus (although it does try and it doesn't sound great!) but the seek does actually work and there's no GStreamer error as with wavenc. I don't know what's specifically wrong with wavenc or if it's a combination of it's problem along with the tcp*sinks themselves. Those sinks don't see much usage / love, I'm not sure how great they are (but I do like that they let you run Mopidy and Snapcast on different systems and they would also work for Mopidy on Windows). I gave this all a try after also trying filesink. I didn't actually hit any problems using filesink myself - gapless worked, seeking worked, the playback position remained accurate. But it's a complicated beast and it's really not designed with FIFOs in mind, it just happens to work with them ...some of the time. There's a stark difference when comparing GStreamer's jack-of-all-trades filesink implementation to MPD's super simple FIFO output. FIFO-specific things like creating the FIFO (and then removing it after) and sensibly handling the full condition are handled by MPD but not by filesink. I'm a little tempted to have another look at a dedicated GStreamer fifosink... Although I'd want to understand better and reproduce what's currently wrong with filesink. |
Latest snapcast has an ALSA loopback sink which is working much better than either fifo or tcp for me with mopidy. Still has the playback position being off, but surely that's just buffering in snapserver? |
Unsure. Bizarrely the playback position offset seems to be noticeably better (less) when Mopidy is running on a different machine to snapserver. Not sure I expected that. EDIT: But for Mopidy's position to be behind, I think that must be a problem within Mopidy. Maybe tcpclientsink is reporting a much larger latency than it's actually seeing. |
That would be interesting. I am using filesink as well and I am seeing playback stop in a playlist after every track. I am not using waveenc as that would mess up the data by including wav headers. As you write, PCM should be just fine. |
@languitar I realize this was over a year ago now but did you ever solve this problem? I am not using mopidy but have the same results with the android client. |
On Wed, May 19, 2021 at 12:34:33PM -0700, pcwii wrote:
> I've now also tested this with mopidy and things work fine apart from one fact: If I stop music on mopidy or switch the song, this sometimes takes ~ 30 seconds to propagate to the snapclient instances. Any ideas on that? Sounds a like the buffer is too large.
***@***.*** I realize this was over a year ago now but did you ever solve this problem? I am not using mopidy but have the same results with the android client.
This is the logic being implemented in snapcast.
In snapcastc (an own rewrite that was created at a time when badaix was
busy and I wanted things changed) I did experiment with other mechanics
for start/stop and pausing. The program follows the same principle as
snapcast but has different behavior in those two aspects:
* when starting, the audio plays back instantly. Buffers are filled in
the background.
* When stopping the same behavior as with snapcast exists except when
audio is stopped and shortly therafter re-started. In this case the
buffers are discarded and instant playback for the new track starts.
This allows quick switching of songs.
There might be other things that could be tried. In essence snapcast(c)
must be told the users intent. So a side channel is needed besides the
audio stream. If mopidy supports calling hooks this could be realized
with extending the API of either tool.
…--
() ascii ribbon campaign - against html e-mail
/\ www.asciiribbon.org - against proprietary attachments
|
Thanks for the background. Just to update. I changed my tcp connection from mode=server to mode=client and I no longer of the 30 second delay. Now when I start the audio the snapcast begins within <2 seconds. |
What about using an ALSA loopback device? |
Not sure. I have all my source material on one computer (debian) and running the snapcast docker on a second headless computer (were I have all my other containers). TCP seamed to be the logical choice. I tried a pipe fifo with an smb share but that gave me nothing but problems, I also tried analog out of one computer to analog in of second computer but quality was horible. |
@badaix The ALSA loopback works great for me and fixes the seek and playback position issues I was experiencing with the TCP stream. |
In general TCP seems to work well and more reliable than FIFO. However I have been noticing an issue that requires me to restart the Mopidy instance every once and while. If Mopidy has been paused and thus not been playing music for a while, it changes the Snapcast state to idle according to the logs.
(mopidy is the name of the stream here) However when I then want to resume the music, the state is never changed to playing any more and only restarting Mopidy does, even though Mopidy itself (through the Iris frontend) indicates music is playing. I'm not sure if this is an issue in Snapcast or some other part of the stack though. Has anyone been able to reproduce this or do you all have music playing 24/7? 😅 |
According to the Mopidy devs, errors relating to FIFOs and TCP streams are usually down to GStreamer, which really isn't designed to be used that way. I switched to the ALSA loopback method some time ago and I haven't experienced a single problem since, and I sometimes leaves Mopidy paused for days on end. |
I've been trying to do this and based on the logs it seems that I'm able to connect to the server but the client doesn't output any sound. It has a mopidy.conf: snapserver.conf: snapclient (via docker-compose):
aplay -l:
I'm not sure if it makes a difference but I'm trying to play a .flac file What does this mean and how can I solve it please. |
I'm currently using MPD as input for snapcast (connected via pipe) and now I started playing with Mopidy, which seems to be more actively developed and more feature rich.
I've observed some strange audio loops during my Mopidy tests, using this setup GStreamer setup:
I was wondering if there are GStreamer sinks that are more reliable and implemented a TCP stream that can be configured to act as client or as server, allowing the following setups:
Snapcast running in TCP server mode
snapcast.conf:
the general pattern is:
tcp://<IP of the listen interface>:<port>?name=<name>&mode=[client|server]
default for
port
(if omitted) is 4953, default formode
isserver
mopidy.conf (running GStreamer in client mode)
Snapcast running in TCP client mode
snapcast.conf:
in client mode the IP and port are the server's IP, port to connect to (default for port is again 4953)
mopidy.conf (running GStreamer in server mode)
If you want to give it a try: it's available in the current develop branch, any feedback is appreciated!
This would also solve #486 (well, at least it would work around it)
The text was updated successfully, but these errors were encountered: