diff --git a/server/streamreader/airplayStream.cpp b/server/streamreader/airplayStream.cpp index 003f7b8b..b27e0de2 100644 --- a/server/streamreader/airplayStream.cpp +++ b/server/streamreader/airplayStream.cpp @@ -18,6 +18,7 @@ #include "airplayStream.h" #include "common/snapException.h" +#include "common/utils.h" using namespace std; @@ -28,7 +29,7 @@ using namespace std; AirplayStream::AirplayStream(PcmListener* pcmListener, const StreamUri& uri) : ProcessStream(pcmListener, uri) { logStderr_ = true; - + sampleFormat_ = SampleFormat("44100:16:2"); uri_.query["sampleformat"] = sampleFormat_.getFormat(); @@ -44,6 +45,7 @@ AirplayStream::~AirplayStream() void AirplayStream::initExeAndPath(const std::string& filename) { + path_ = ""; exe_ = findExe(filename); if (!fileExists(exe_) || (exe_ == "/")) { @@ -53,6 +55,12 @@ void AirplayStream::initExeAndPath(const std::string& filename) } if (exe_.find("/") != string::npos) - path_ = exe_.substr(0, exe_.find_last_of("/")); + { + path_ = exe_.substr(0, exe_.find_last_of("/") + 1); + exe_ = exe_.substr(exe_.find_last_of("/") + 1); + } + + /// kill if it's already running + execGetOutput("killall " + exe_); } diff --git a/server/streamreader/processStream.cpp b/server/streamreader/processStream.cpp index 9fb7cd37..02466e96 100644 --- a/server/streamreader/processStream.cpp +++ b/server/streamreader/processStream.cpp @@ -88,11 +88,15 @@ std::string ProcessStream::findExe(const std::string& filename) void ProcessStream::initExeAndPath(const std::string& filename) { + path_ = ""; exe_ = findExe(filename); if (exe_.find("/") != string::npos) - path_ = exe_.substr(0, exe_.find_last_of("/")); + { + path_ = exe_.substr(0, exe_.find_last_of("/") + 1); + exe_ = exe_.substr(exe_.find_last_of("/") + 1); + } - if (!fileExists(exe_)) + if (!fileExists(path_ + exe_)) throw SnapException("file not found: \"" + filename + "\""); } @@ -119,7 +123,7 @@ void ProcessStream::onStderrMsg(const char* buffer, size_t n) { string line = trim_copy(string(buffer, n)); if ((line.find('\0') == string::npos) && !line.empty()) - logO << "(" << uri_.getQuery("name") << ") " << line << "\n"; + logO << "(" << exe_ << ") " << line << "\n"; } } @@ -144,7 +148,7 @@ void ProcessStream::worker() while (active_) { - process_.reset(new Process(exe_ + " " + params_, path_)); + process_.reset(new Process(path_ + exe_ + " " + params_, path_)); int flags = fcntl(process_->getStdout(), F_GETFL, 0); fcntl(process_->getStdout(), F_SETFL, flags | O_NONBLOCK); diff --git a/server/streamreader/spotifyStream.cpp b/server/streamreader/spotifyStream.cpp index 3ce5bbf8..4b0d9773 100644 --- a/server/streamreader/spotifyStream.cpp +++ b/server/streamreader/spotifyStream.cpp @@ -54,6 +54,7 @@ SpotifyStream::~SpotifyStream() void SpotifyStream::initExeAndPath(const std::string& filename) { + path_ = ""; exe_ = findExe(filename); if (!fileExists(exe_) || (exe_ == "/")) { @@ -63,7 +64,13 @@ void SpotifyStream::initExeAndPath(const std::string& filename) } if (exe_.find("/") != string::npos) - path_ = exe_.substr(0, exe_.find_last_of("/")); + { + path_ = exe_.substr(0, exe_.find_last_of("/") + 1); + exe_ = exe_.substr(exe_.find_last_of("/") + 1); + } + + /// kill if it's already running + execGetOutput("killall " + exe_); } @@ -93,7 +100,7 @@ void SpotifyStream::onStderrMsg(const char* buffer, size_t n) (logmsg.find('\0') == string::npos) && (logmsg.size() > 4)) { - logO << logmsg << "\n"; + logO << "(" << exe_ << ") " << logmsg << "\n"; } }