owntone / owntone-server

Linux/FreeBSD DAAP (iTunes) and MPD audio server with support for AirPlay 1 and 2 speakers (multiroom), Apple Remote (and compatibles), Chromecast, Spotify and internet radio.
https://owntone.github.io/owntone-server
GNU General Public License v2.0
2.07k stars 236 forks source link

Feature request: several different streams simultaneous to different groups of receivers #1189

Open maichai opened 3 years ago

maichai commented 3 years ago

It would be great if one could have different ephemeral groups of receivers that can receive different streams simultaneously, where the speakers that are members of a given group play the stream in sync if they are supporting Airplay2.

I am aware that the Apple remote control protocol might possible not be able to represent this use case, but I am not sure. Would this use case be covered by the AirPlay2 spec or not?

At least it could be controlled using the web UI or the admin API and use some home automation platform as UI, such as Home Assistant/Lovelace.

It would be a great addition to forked-daapd (I think snapcast is able to do run this use case).

ejurgensen commented 3 years ago

Yes, there is no support for speaker groups, but I agree it could make sense to have.

derekatkins commented 2 years ago

Even more simpler than speaker groups, is it possible to play different streams simultaneously to different speakers? I.e., could I play "playlist 1" to "Speaker 1" and "playlist 2" to "Speaker 2"? I can't even figure out how to do that (via the WebUI)

ejurgensen commented 2 years ago

Unfortunately that is also not supported, except possibly by running multiple instances of OwnTone.

derekatkins commented 2 years ago

Unfortunately that is also not supported, except possibly by running multiple instances of OwnTone.

Is it possible to run multiple instances on the same server with the same media library? My guess is that I will need to duplicate the configuration and run with -c option. What configuration(s) would need to be modified? Looks like I would need to manually update the general -> websocket_port and update the library -> port on each instance. Can multiple instances share the db_path? logfile? cache_path? (assume they share the "directories").

ejurgensen commented 2 years ago

Is it possible to run multiple instances on the same server with the same media library?

I think it is possible, but I haven't tried it in practice. Like you say, each instance should have its own config, and they cannot share anything that gets written to, so that means db, cache, log file and ports. The separate db's would mean that some features wouldn't work as desired, like when OwnTone saves a certain state, e.g. rating and playback position (for podcasts).

aleszczynskig commented 2 years ago

I run two instances in the same server from the same library as described above without issue. Another point to note is that fifo pipes may not work. I work around this without issue but it might cause conflict if two instances are trying to open the same pipe.

derekatkins commented 2 years ago

I run two instances in the same server from the same library as described above without issue. Another point to note is that fifo pipes may not work. I work around this without issue but it might cause conflict if two instances are trying to open the same pipe.

Thanks. I'm not worried about pipes. @aleszczynskig -- did you change the various DB paths as well? @ejurgensen -- how hard would it be to enable multiple streams from the app sharing a common music library? (Alternately I can easily build an owntone@.service to allow one to easily set up multiple services simultaneously.

aleszczynskig commented 2 years ago

@derekatkins. Yes I created two sets of databases and changed the daap, websocket and mpd ports to not conflict. I created a second service file with the -c option pointing to a different configuration file as well. I've only set this up last week as I am looking to consolidate multiple owntone instances on to a single dedicated rpi4. So far no issues. I guess it's worth pointing out that I do not share audio hardware between the instances, I only use airplay targets.

derekatkins commented 2 years ago

@aleszczynskig -- thanks. I only use Airplay targets myself, so that's not an issue. I guess different DBs wont be too bad. I presume that the protocols will "announce" themselves so that a client that connects to HTTP-1 will know to connect to WS-1 and MPD-1, and HTTP-2 to WS-2 and MPD-2, etc. And thanks for pointing out MPD. I would have missed that.

Another thing I noticed -- when I hooked this into Home Assistant, when it shows up as a player the default source is pipe -- Any idea how to disable that? Maybe "pipe_autostart = false"?

ejurgensen commented 2 years ago

how hard would it be to enable multiple streams from the app sharing a common music library?

Very hard, I would say. A new layer of abstraction would be need to handle parallel players, and also dealing with shared playback ressources and shared playback state. Something basic like giving status to a client will also be difficult - e.g. when Remote or mpd asks what is being played then what is the answer? It would also be necessary to add a mechanism for locking a particular speaker to a player instance.

derekatkins commented 2 years ago

how hard would it be to enable multiple streams from the app sharing a common music library?

Very hard, I would say. A new layer of abstraction would be need to handle parallel players, and also dealing with shared playback ressources and shared playback state. Something basic like giving status to a client will also be difficult - e.g. when Remote or mpd asks what is being played then what is the answer? It would also be necessary to add a mechanism for locking a particular speaker to a player instance.

Yeah, clearly an active speaker would need to be locked to a player instance -- you can't really play two streams to a single speaker, so... yeah.

Thanks for the feedback -- Would you accept a PR that adds a owntone@.service to allow one to create parametrized owntone services?

ejurgensen commented 2 years ago

Another thing I noticed -- when I hooked this into Home Assistant, when it shows up as a player the default source is pipe -- Any idea how to disable that? Maybe "pipe_autostart = false"?

pipe_autostart is only relevant if you have added a fifo to your library. I'm unsure what a "default source" is? Maybe be better to ask over at Home Assistant.

Would you accept a PR that adds a owntone@.service to allow one to create parametrized owntone services?

I'm not sure what a owntone@service is? Can you elaborate? Or maybe if you have a link to something that explains it?

derekatkins commented 2 years ago

Another thing I noticed -- when I hooked this into Home Assistant, when it shows up as a player the default source is pipe -- Any idea how to disable that? Maybe "pipe_autostart = false"?

pipe_autostart is only relevant if you have added a fifo to your library. I'm unsure what a "default source" is? Maybe be better to ask over at Home Assistant.

If I knew how to post a photo into a comment I would show you what I mean. I think that owntone is still advertising the pipe as a source, even if one is not in the library. Regardless, I will ask over there.

Would you accept a PR that adds a owntone@.service to allow one to create parametrized owntone services?

I'm not sure what a owntone@service is? Can you elaborate? Or maybe if you have a link to something that explains it?

Sure. It's a systemd template service that lets you pass an argument into a service, like a zone name. See https://fedoramagazine.org/systemd-template-unit-files/

ejurgensen commented 2 years ago

I think that owntone is still advertising the pipe as a source, even if one is not in the library

What does OwnTone's own web UI show?

derekatkins commented 2 years ago

I think that owntone is still advertising the pipe as a source, even if one is not in the library

What does OwnTone's own web UI show?

Frankly I'm not sure where to look for it in the OwnTone web UI. It's not listed in the list of playlists. But from HA (which I think uses the WS interface) when I click on "source", it gives me a popup that says: "Clear Queue", "Default (no pipe)", "Playlist 1 (playlist)"

If I click on the bottom-right of the OT WebUI the popup has a master volume control, the list of all my airplay devices, and then at the bottom it says "HTTP Stream (stream.mp3)" -- I disabled "Computer" (there is no audio output device from the OT server).

ejurgensen commented 2 years ago

If OwnTone was using a pipe as source (playing from it), you would see it right away in the web UI. So can't say why HA is showing what it does.

It's a systemd template service that lets you pass an argument into a service

Thanks for the link, I get it now. Sounds good, you are welcome to make a PR.

aleszczynskig commented 2 years ago

I believe the HA pipe source entry may relate to the special condition where the plugin can control a librespot pipe. It's very specific. See the pipe section of the documentation here.

https://www.home-assistant.io/integrations/forked_daapd/

I use this integration extensively however it hasn't been updated for sometime and whilst it works fine it's a little out of date now. As a starting point, it should be updated to reflect the name change to owntone. It takes a long time for changes to make it into a HA release so maybe something is in the works but has not been approved yet.

aleszczynskig commented 2 years ago

@aleszczynskig -- thanks. I only use Airplay targets myself, so that's not an issue. I guess different DBs wont be too bad. I presume that the protocols will "announce" themselves so that a client that connects to HTTP-1 will know to connect to WS-1 and MPD-1, and HTTP-2 to WS-2 and MPD-2, etc. And thanks for pointing out MPD. I would have missed that.

Another thing I noticed -- when I hooked this into Home Assistant, when it shows up as a player the default source is pipe -- Any idea how to disable that? Maybe "pipe_autostart = false"?

Actually the credit for this should goto @ejurgensen. I was reading an old issue (https://github.com/owntone/owntone-server/issues/494) from several years ago where a similar question was asked and the mpd port was listed as something that needed changing. On my initial attempt to run two parallel processes on a single box, the second instance was failing with a rather cryptic error, it was not until I changed the mpd port that it all sprang to life after a little digging through the old issues.

aleszczynskig commented 2 years ago

Sure. It's a systemd template service that lets you pass an argument into a service, like a zone name. See https://fedoramagazine.org/systemd-template-unit-files/

@derekatkins - Thanks for this info. I will update my implementation to take advantage of this. I had noticed elements of these templates during my various hacks but had never looked into the documentation to understand it correctly.

derekatkins commented 2 years ago

@aleszczynskig -- I plan to create a PR to add a template service unit. Should be very straightforward to add :)

I am curious -- are you willing to share a "diff -u" between your two config files? I'm curious what all you needed to change to get it all to work. I'm sure the changes are all spread out.

I believe the HA pipe source entry may relate to the special condition where the plugin can control a librespot pipe. It's very specific. See the pipe section of the documentation here.

I looked at those docs and noticed the pipe thing in there, but couldn't figure out how to turn that "feature" off. Even setting "pipe_autostart = false" in the OT config didn't help.

aleszczynskig commented 2 years ago

I'm happy to share a diff though it's not something I can do immediately as I don't have access to my pi until tomorrow.

It's just the 3 port config entires and the songs.db path and cache.db path that need changing though. I comment out the alsa section as much as possible as well.

You probably also want to give consideration to the backup db path as that would need to be defined separately in each configuration file as well. I suspect most people don't use that but you wouldn't want to overwrite the same backup from each instance I wouldn't think.

derekatkins commented 2 years ago

@aleszczynskig -- Thanks. I plan to try it out shortly.

FYI, if you care to try my changes in https://github.com/derekatkins/owntone-server/tree/template_service -- that includes my template service file.