From 678f102a980576b35db8d602fb36d11a50e764a0 Mon Sep 17 00:00:00 2001 From: Christian Flach Date: Thu, 30 Jan 2020 14:15:54 +0100 Subject: [PATCH] Add option to not kill all librespot instances --- doc/player_setup.md | 4 ++-- server/streamreader/librespot_stream.cpp | 8 ++++++-- server/streamreader/librespot_stream.hpp | 2 ++ 3 files changed, 10 insertions(+), 4 deletions(-) diff --git a/doc/player_setup.md b/doc/player_setup.md index 3a070f7a..8cada6d4 100644 --- a/doc/player_setup.md +++ b/doc/player_setup.md @@ -151,11 +151,11 @@ Snapserver supports [shairport-sync](https://github.com/mikebrady/shairport-sync ### Spotify 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/` - 2. Configure snapserver with `stream = spotify:///librespot?name=Spotify[&username=&password=][&devicename=Snapcast][&bitrate=320][&onstart=][&onstop=][&volume=][&cache=]` + 2. Configure snapserver with `stream = spotify:///librespot?name=Spotify[&username=&password=][&devicename=Snapcast][&bitrate=320][&onstart=][&onstop=][&volume=][&cache=][&killall=true]` * Valid bitrates are 96, 160, 320 * `start command` and `stop command` are executed by Librespot at start/stop * For example: `onstart=/usr/bin/logger -t Snapcast Starting spotify...` - + * 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 Snapserver can start any process and read PCM data from the stdout of the process: diff --git a/server/streamreader/librespot_stream.cpp b/server/streamreader/librespot_stream.cpp index f0cbefd7..b1c4d060 100644 --- a/server/streamreader/librespot_stream.cpp +++ b/server/streamreader/librespot_stream.cpp @@ -44,6 +44,7 @@ LibrespotStream::LibrespotStream(PcmListener* pcmListener, boost::asio::io_conte string devicename = uri_.getQuery("devicename", "Snapcast"); string onevent = uri_.getQuery("onevent", ""); bool normalize = (uri_.getQuery("normalize", "false") == "true"); + killall_ = (uri_.getQuery("killall", "true") == "true"); if (username.empty() != password.empty()) throw SnapException("missing parameter \"username\" or \"password\" (must provide both, or neither)"); @@ -87,8 +88,11 @@ void LibrespotStream::initExeAndPath(const std::string& filename) exe_ = exe_.substr(exe_.find_last_of("/") + 1); } - /// kill if it's already running - execGetOutput("killall " + exe_); + if (killall_) + { + /// kill if it's already running + execGetOutput("killall " + exe_); + } } diff --git a/server/streamreader/librespot_stream.hpp b/server/streamreader/librespot_stream.hpp index 3f05ecc0..ad17c9c3 100644 --- a/server/streamreader/librespot_stream.hpp +++ b/server/streamreader/librespot_stream.hpp @@ -40,6 +40,8 @@ public: LibrespotStream(PcmListener* pcmListener, boost::asio::io_context& ioc, const StreamUri& uri); protected: + bool killall_; + void onStderrMsg(const std::string& line) override; void initExeAndPath(const std::string& filename) override; };