From 7af0bdde65ed11cb7e625f0031c1333132a41565 Mon Sep 17 00:00:00 2001 From: badaix Date: Wed, 2 Nov 2016 09:03:40 +0100 Subject: [PATCH] added optional parameter "logStderr" to ProcessStream --- server/streamreader/processStream.cpp | 21 ++++++++++++--------- server/streamreader/processStream.h | 7 ++++--- server/streamreader/spotifyStream.cpp | 16 ++++++++-------- 3 files changed, 24 insertions(+), 20 deletions(-) diff --git a/server/streamreader/processStream.cpp b/server/streamreader/processStream.cpp index e28b138f..895dd078 100644 --- a/server/streamreader/processStream.cpp +++ b/server/streamreader/processStream.cpp @@ -31,10 +31,10 @@ using namespace std; -ProcessStream::ProcessStream(PcmListener* pcmListener, const StreamUri& uri) : PcmStream(pcmListener, uri), path(""), process_(nullptr) +ProcessStream::ProcessStream(PcmListener* pcmListener, const StreamUri& uri) : PcmStream(pcmListener, uri), path_(""), process_(nullptr) { - logO << "ProcessStream: " << uri_.getQuery("params") << "\n"; - params = uri_.getQuery("params"); + params_ = uri_.getQuery("params"); + logStderr_ = (uri_.getQuery("logStderr", "false") == "true"); } @@ -88,11 +88,11 @@ std::string ProcessStream::findExe(const std::string& filename) void ProcessStream::initExeAndPath(const std::string& filename) { - exe = findExe(filename); - if (exe.find("/") != string::npos) - path = exe.substr(0, exe.find_last_of("/")); + exe_ = findExe(filename); + if (exe_.find("/") != string::npos) + path_ = exe_.substr(0, exe_.find_last_of("/")); - if (!fileExists(exe)) + if (!fileExists(exe_)) throw SnapException("file not found: \"" + filename + "\""); } @@ -115,7 +115,10 @@ void ProcessStream::stop() void ProcessStream::onStderrMsg(const char* buffer, size_t n) { - /// do nothing + if (logStderr_) + { + logO << string(buffer, n); + } } @@ -139,7 +142,7 @@ void ProcessStream::worker() while (active_) { - process_.reset(new Process(exe + " " + params, path)); + process_.reset(new Process(exe_ + " " + params_, path_)); int flags = fcntl(process_->getStdout(), F_GETFL, 0); fcntl(process_->getStdout(), F_SETFL, flags | O_NONBLOCK); diff --git a/server/streamreader/processStream.h b/server/streamreader/processStream.h index f0cfc599..28bd91f2 100644 --- a/server/streamreader/processStream.h +++ b/server/streamreader/processStream.h @@ -43,11 +43,12 @@ public: virtual void stop(); protected: - std::string exe; - std::string path; - std::string params; + std::string exe_; + std::string path_; + std::string params_; std::unique_ptr process_; std::thread stderrReaderThread_; + bool logStderr_; virtual void worker(); virtual void stderrReader(); diff --git a/server/streamreader/spotifyStream.cpp b/server/streamreader/spotifyStream.cpp index 6b3d622d..a1547752 100644 --- a/server/streamreader/spotifyStream.cpp +++ b/server/streamreader/spotifyStream.cpp @@ -39,8 +39,8 @@ SpotifyStream::SpotifyStream(PcmListener* pcmListener, const StreamUri& uri) : P if (password.empty()) throw SnapException("missing parameter \"password\""); - params = "--name \"" + devicename + "\" --username \"" + username + "\" --password \"" + password + "\" --bitrate " + bitrate + " --backend stdout"; - logO << "params: " << params << "\n"; + params_ = "--name \"" + devicename + "\" --username \"" + username + "\" --password \"" + password + "\" --bitrate " + bitrate + " --backend stdout"; +// logO << "params: " << params << "\n"; } @@ -51,16 +51,16 @@ SpotifyStream::~SpotifyStream() void SpotifyStream::initExeAndPath(const std::string& filename) { - exe = findExe(filename); - if (!fileExists(exe) || (exe == "/")) + exe_ = findExe(filename); + if (!fileExists(exe_) || (exe_ == "/")) { - exe = findExe("librespot"); - if (!fileExists(exe)) + exe_ = findExe("librespot"); + if (!fileExists(exe_)) throw SnapException("librespot not found"); } - if (exe.find("/") != string::npos) - path = exe.substr(0, exe.find_last_of("/")); + if (exe_.find("/") != string::npos) + path_ = exe_.substr(0, exe_.find_last_of("/")); }