Fix linter warnings, add Shairport version

This commit is contained in:
badaix 2020-03-30 09:43:25 +02:00
parent 3c9f2e2da3
commit 7e47207bd1

View file

@ -1,17 +1,20 @@
Setup of audio players/server # Setup of audio players/server
-----------------------------
Snapcast can be used with a number of different audio players and servers, and so it can be integrated into your favorite audio-player solution and make it synced-multiroom capable. Snapcast can be used with a number of different audio players and servers, and so it can be integrated into your favorite audio-player solution and make it synced-multiroom capable.
The only requirement is that the player's audio can be redirected into the Snapserver's fifo `/tmp/snapfifo`. In the following configuration hints for [MPD](http://www.musicpd.org/) and [Mopidy](https://www.mopidy.com/) are given, which are the base of other audio player solutions, like [Volumio](https://volumio.org/) or [RuneAudio](http://www.runeaudio.com/) (both MPD) or [Pi MusicBox](http://www.pimusicbox.com/) (Mopidy). The only requirement is that the player's audio can be redirected into the Snapserver's fifo `/tmp/snapfifo`. In the following configuration hints for [MPD](http://www.musicpd.org/) and [Mopidy](https://www.mopidy.com/) are given, which are the base of other audio player solutions, like [Volumio](https://volumio.org/) or [RuneAudio](http://www.runeaudio.com/) (both MPD) or [Pi MusicBox](http://www.pimusicbox.com/) (Mopidy).
The goal is to build the following chain: The goal is to build the following chain:
audio player software -> snapfifo -> snapserver -> network -> snapclient -> alsa ```plain_text
audio player software -> snapfifo -> snapserver -> network -> snapclient -> alsa
```
## Streams
#### Streams
Snapserver can read audio from several input streams, which are configured in the `snapserver.conf` file (default location is `/etc/snapserver.conf`); the config file can be changed with the `-c` parameter. Snapserver can read audio from several input streams, which are configured in the `snapserver.conf` file (default location is `/etc/snapserver.conf`); the config file can be changed with the `-c` parameter.
Within the config file a list of input streams can be configured in the `[stream]` section: Within the config file a list of input streams can be configured in the `[stream]` section:
``` ```ini
[stream] [stream]
... ...
# stream URI of the PCM input stream, can be configured multiple times # stream URI of the PCM input stream, can be configured multiple times
@ -20,90 +23,117 @@ stream = pipe:///tmp/snapfifo?name=default
... ...
``` ```
#### About the notation ## About the notation
In this document some expressions are in brackets: In this document some expressions are in brackets:
* `<angle brackets>`: the whole expression must be replaced with your specific setting * `<angle brackets>`: the whole expression must be replaced with your specific setting
* `[square brackets]`: the whole expression is optional and can be left out * `[square brackets]`: the whole expression is optional and can be left out
* `[key=value]`: if you leave this option out, `value` will be the default for `key` * `[key=value]`: if you leave this option out, `value` will be the default for `key`
For example: For example:
```
```ini
stream = spotify:///librespot?name=Spotify[&username=<my username>&password=<my password>][&devicename=Snapcast][&bitrate=320] stream = spotify:///librespot?name=Spotify[&username=<my username>&password=<my password>][&devicename=Snapcast][&bitrate=320]
``` ```
* `username` and `password` are both optional in this case. You need to specify neither or both of them. * `username` and `password` are both optional in this case. You need to specify neither or both of them.
* `bitrate` is optional. If not configured, `320` will be used. * `bitrate` is optional. If not configured, `320` will be used.
* `devicename` is optional. If not configured, `Snapcast` will be used. * `devicename` is optional. If not configured, `Snapcast` will be used.
For instance, a valid usage would be: For instance, a valid usage would be:
```
```ini
stream = spotify:///librespot?name=Spotify&bitrate=160 stream = spotify:///librespot?name=Spotify&bitrate=160
``` ```
### MPD ### MPD
To connect [MPD](http://www.musicpd.org/) to the Snapserver, edit `/etc/mpd.conf`, so that mpd will feed the audio into the snapserver's named pipe. To connect [MPD](http://www.musicpd.org/) to the Snapserver, edit `/etc/mpd.conf`, so that mpd will feed the audio into the snapserver's named pipe.
Disable alsa audio output by commenting out this section: Disable alsa audio output by commenting out this section:
#audio_output { ```plain_text
# type "alsa" #audio_output {
# name "My ALSA Device" # type "alsa"
# device "hw:0,0" # optional # name "My ALSA Device"
# format "48000:16:2" # optional # device "hw:0,0" # optional
# mixer_device "default" # optional # format "48000:16:2" # optional
# mixer_control "PCM" # optional # mixer_device "default" # optional
# mixer_index "0" # optional # mixer_control "PCM" # optional
#} # mixer_index "0" # optional
#}
```
Add a new audio output of the type "fifo", which will let mpd play audio into the named pipe `/tmp/snapfifo`. Add a new audio output of the type "fifo", which will let mpd play audio into the named pipe `/tmp/snapfifo`.
Make sure that the "format" setting is the same as the format setting of the Snapserver (default is "48000:16:2", which should make resampling unnecessary in most cases). Make sure that the "format" setting is the same as the format setting of the Snapserver (default is "48000:16:2", which should make resampling unnecessary in most cases).
audio_output { ```plain_text
audio_output {
type "fifo" type "fifo"
name "my pipe" name "my pipe"
path "/tmp/snapfifo" path "/tmp/snapfifo"
format "48000:16:2" format "48000:16:2"
mixer_type "software" mixer_type "software"
} }
```
To test your mpd installation, you can add a radio station by To test your mpd installation, you can add a radio station by
$ sudo su ```sh
$ echo "http://wdr-1live-live.icecast.wdr.de/wdr/1live/live/mp3/128/stream.mp3" > /var/lib/mpd/playlists/einslive.m3u sudo su
echo "http://wdr-1live-live.icecast.wdr.de/wdr/1live/live/mp3/128/stream.mp3" > /var/lib/mpd/playlists/einslive.m3u
```
### Mopidy ### Mopidy
[Mopidy](https://www.mopidy.com/) can stream the audio output into the Snapserver's fifo with a `filesink` as audio output in `mopidy.conf`: [Mopidy](https://www.mopidy.com/) can stream the audio output into the Snapserver's fifo with a `filesink` as audio output in `mopidy.conf`:
[audio] ```ini
#output = autoaudiosink [audio]
output = audioresample ! audioconvert ! audio/x-raw,rate=48000,channels=2,format=S16LE ! wavenc ! filesink location=/tmp/snapfifo #output = autoaudiosink
output = audioresample ! audioconvert ! audio/x-raw,rate=48000,channels=2,format=S16LE ! wavenc ! filesink location=/tmp/snapfifo
```
With newer kernels one might also have to change this sysctl-setting, as default settings have changed recently: `sudo sysctl fs.protected_fifos=0` With newer kernels one might also have to change this sysctl-setting, as default settings have changed recently: `sudo sysctl fs.protected_fifos=0`
See https://unix.stackexchange.com/questions/503111/group-permissions-for-root-not-working-in-tmp for more details. You need to run this after each reboot or add it to /etc/sysctl.conf or /etc/sysctl.d/50-default.conf depending on distribution. See [stackexchange](https://unix.stackexchange.com/questions/503111/group-permissions-for-root-not-working-in-tmp) for more details. You need to run this after each reboot or add it to /etc/sysctl.conf or /etc/sysctl.d/50-default.conf depending on distribution.
### FFmpeg ### FFmpeg
Pipe FFmpeg's audio output to the snapfifo: Pipe FFmpeg's audio output to the snapfifo:
ffmpeg -y -i http://wms-15.streamsrus.com:11630 -f u16le -acodec pcm_s16le -ac 2 -ar 48000 /tmp/snapfifo ```sh
ffmpeg -y -i http://wms-15.streamsrus.com:11630 -f u16le -acodec pcm_s16le -ac 2 -ar 48000 /tmp/snapfifo
```
### mpv ### mpv
Pipe mpv's audio output to the snapfifo: Pipe mpv's audio output to the snapfifo:
mpv http://wms-15.streamsrus.com:11630 --audio-display=no --audio-channels=stereo --audio-samplerate=48000 --audio-format=s16 --ao=pcm:file=/tmp/snapfifo ```sh
mpv http://wms-15.streamsrus.com:11630 --audio-display=no --audio-channels=stereo --audio-samplerate=48000 --audio-format=s16 --ao=pcm:file=/tmp/snapfifo
```
### MPlayer ### MPlayer
Use `-novideo` and `-ao` to pipe MPlayer's audio output to the snapfifo: Use `-novideo` and `-ao` to pipe MPlayer's audio output to the snapfifo:
mplayer http://wms-15.streamsrus.com:11630 -novideo -channels 2 -srate 48000 -af format=s16le -ao pcm:file=/tmp/snapfifo ```sh
mplayer http://wms-15.streamsrus.com:11630 -novideo -channels 2 -srate 48000 -af format=s16le -ao pcm:file=/tmp/snapfifo
```
### Alsa ### Alsa
If the player cannot be configured to route the audio stream into the snapfifo, Alsa or PulseAudio can be redirected, resulting in this chain: If the player cannot be configured to route the audio stream into the snapfifo, Alsa or PulseAudio can be redirected, resulting in this chain:
```plain_text
audio player software -> Alsa -> Alsa file plugin -> snapfifo -> snapserver -> network -> snapclient -> Alsa audio player software -> Alsa -> Alsa file plugin -> snapfifo -> snapserver -> network -> snapclient -> Alsa
```
Edit or create your Alsa config `/etc/asound.conf` like this: Edit or create your Alsa config `/etc/asound.conf` like this:
``` ```plain_text
pcm.!default { pcm.!default {
type plug type plug
slave.pcm rate48000Hz slave.pcm rate48000Hz
@ -127,29 +157,36 @@ pcm.writeFile {
``` ```
### PulseAudio ### PulseAudio
Redirect the PulseAudio stream into the snapfifo: Redirect the PulseAudio stream into the snapfifo:
audio player software -> PulseAudio -> PulseAudio pipe sink -> snapfifo -> snapserver -> network -> snapclient -> Alsa ```plain_text
audio player software -> PulseAudio -> PulseAudio pipe sink -> snapfifo -> snapserver -> network -> snapclient -> Alsa
```
PulseAudio will create the pipe file for itself and will fail if it already exists; see the [Configuration section](https://github.com/badaix/snapcast#configuration) in the main README file on how to change the pipe creation mode to read-only. PulseAudio will create the pipe file for itself and will fail if it already exists; see the [Configuration section](https://github.com/badaix/snapcast#configuration) in the main README file on how to change the pipe creation mode to read-only.
Load the module `pipe-sink` like this: Load the module `pipe-sink` like this:
pacmd load-module module-pipe-sink file=/tmp/snapfifo sink_name=Snapcast format=s16le rate=48000 ```plain_text
pacmd update-sink-proplist Snapcast device.description=Snapcast pacmd load-module module-pipe-sink file=/tmp/snapfifo sink_name=Snapcast format=s16le rate=48000
pacmd update-sink-proplist Snapcast device.description=Snapcast
```
It might be neccessary to set the PulseAudio latency environment variable to 60 msec: `PULSE_LATENCY_MSEC=60` It might be neccessary to set the PulseAudio latency environment variable to 60 msec: `PULSE_LATENCY_MSEC=60`
### AirPlay ### AirPlay
Snapserver supports [shairport-sync](https://github.com/mikebrady/shairport-sync) with the `stdout` backend. Snapserver supports [shairport-sync](https://github.com/mikebrady/shairport-sync) with the `stdout` backend.
1. Build shairport-sync with `stdout` backend: `./configure --with-stdout --with-avahi --with-ssl=openssl --with-metadata`
1. Build shairport-sync (version 3.3 or later) with `stdout` backend: `./configure --with-stdout --with-avahi --with-ssl=openssl --with-metadata`
2. Copy the `shairport-sync` binary somewhere to your `PATH`, e.g. `/usr/local/bin/` 2. Copy the `shairport-sync` binary somewhere to your `PATH`, e.g. `/usr/local/bin/`
3. Configure snapserver with `stream = airplay:///shairport-sync?name=Airplay[&devicename=Snapcast][&port=5000]` 3. Configure snapserver with `stream = airplay:///shairport-sync?name=Airplay[&devicename=Snapcast][&port=5000]`
### Spotify ### Spotify
Snapserver supports [librespot](https://github.com/librespot-org/librespot) with the `pipe` backend. Snapserver supports [librespot](https://github.com/librespot-org/librespot) with the `pipe` backend.
1. Build and copy the `librespot` binary somewhere to your `PATH`, e.g. `/usr/local/bin/` 1. Build and copy the `librespot` binary somewhere to your `PATH`, e.g. `/usr/local/bin/`
2. Configure snapserver with `stream = spotify:///librespot?name=Spotify[&username=<my username>&password=<my password>][&devicename=Snapcast][&bitrate=320][&onstart=<start command>][&onstop=<stop command>][&volume=<volume in percent>][&cache=<cache dir>][&killall=true]` 2. Configure snapserver with `stream = spotify:///librespot?name=Spotify[&username=<my username>&password=<my password>][&devicename=Snapcast][&bitrate=320][&onstart=<start command>][&onstop=<stop command>][&volume=<volume in percent>][&cache=<cache dir>][&killall=true]`
* Valid bitrates are 96, 160, 320 * Valid bitrates are 96, 160, 320
@ -158,16 +195,19 @@ Snapserver supports [librespot](https://github.com/librespot-org/librespot) with
* If `killall` is `true` (default), all running instances of Librespot will be killed. This MUST be disabled on all spotify streams by setting it to `false` if you want to use multiple spotify streams. * If `killall` is `true` (default), all running instances of Librespot will be killed. This MUST be disabled on all spotify streams by setting it to `false` if you want to use multiple spotify streams.
### Process ### Process
Snapserver can start any process and read PCM data from the stdout of the process: Snapserver can start any process and read PCM data from the stdout of the process:
Configure snapserver with `stream = process:///path/to/process?name=Process[&params=<--my list --of params>][&log_stderr=false]` Configure snapserver with `stream = process:///path/to/process?name=Process[&params=<--my list --of params>][&log_stderr=false]`
### Line-in ### Line-in
Audio captured from line-in can be redirected to the snapserver's pipe, e.g. by using: Audio captured from line-in can be redirected to the snapserver's pipe, e.g. by using:
#### cpiped #### cpiped
[cpipe](https://github.com/b-fitzpatrick/cpiped) [cpipe](https://github.com/b-fitzpatrick/cpiped)
#### PulseAudio #### PulseAudio
`parec >/tmp/snapfifo` (defaults to 44.1kHz, 16bit, stereo) `parec >/tmp/snapfifo` (defaults to 44.1kHz, 16bit, stereo)