Add support for controlscriptparams

This commit is contained in:
badaix 2022-07-13 14:14:00 +02:00
parent b71e303083
commit 60dc1aa48a
8 changed files with 24 additions and 10 deletions

View file

@ -64,7 +64,10 @@ PcmStream::PcmStream(PcmStream::Listener* pcmListener, boost::asio::io_context&
if (uri_.query.find(kControlScript) != uri_.query.end())
{
stream_ctrl_ = std::make_unique<ScriptStreamControl>(strand_, uri_.query[kControlScript]);
std::string params;
if (uri_.query.find(kControlScriptParams) != uri_.query.end())
params = uri_.query[kControlScriptParams];
stream_ctrl_ = std::make_unique<ScriptStreamControl>(strand_, uri_.query[kControlScript], params);
}
if (uri_.query.find(kUriChunkMs) != uri_.query.end())
@ -442,7 +445,7 @@ void PcmStream::sendRequest(const std::string& method, const jsonrpcpp::Paramete
jsonrpcpp::Request req(++req_id_, method, params);
stream_ctrl_->command(req, [handler](const jsonrpcpp::Response& response) {
if (response.error().code())
if (response.error().code() != 0)
handler({static_cast<ControlErrc>(response.error().code()), response.error().data()});
else
handler({ControlErrc::success});
@ -463,7 +466,7 @@ void PcmStream::setProperties(const Properties& properties)
if (props.metadata.has_value() && props.metadata->art_data.has_value() && !props.metadata->art_url.has_value())
{
auto data = base64_decode(props.metadata->art_data->data);
auto md5 = server_settings_.http.image_cache.setImage(getName(), std::move(data), props.metadata->art_data->extension);
auto md5 = ServerSettings::Http::image_cache.setImage(getName(), std::move(data), props.metadata->art_data->extension);
std::stringstream url;
url << "http://" << server_settings_.http.host << ":" << server_settings_.http.port << "/__image_cache?name=" << md5;
@ -471,7 +474,7 @@ void PcmStream::setProperties(const Properties& properties)
}
else if (!props.metadata.has_value() || !props.metadata->art_data.has_value())
{
server_settings_.http.image_cache.clear(getName());
ServerSettings::Http::image_cache.clear(getName());
}
if (props == properties_)

View file

@ -91,6 +91,7 @@ static constexpr auto kUriName = "name";
static constexpr auto kUriSampleFormat = "sampleformat";
static constexpr auto kUriChunkMs = "chunk_ms";
static constexpr auto kControlScript = "controlscript";
static constexpr auto kControlScriptParams = "controlscriptparams";
/// Reads and decodes PCM data

View file

@ -140,7 +140,8 @@ void StreamControl::onLog(std::string message)
ScriptStreamControl::ScriptStreamControl(const boost::asio::any_io_executor& executor, const std::string& script) : StreamControl(executor), script_(script)
ScriptStreamControl::ScriptStreamControl(const boost::asio::any_io_executor& executor, const std::string& script, const std::string& params)
: StreamControl(executor), script_(script), params_(params)
{
namespace fs = utils::file;
if (!fs::exists(script_))
@ -159,9 +160,14 @@ void ScriptStreamControl::doStart(const std::string& stream_id, const ServerSett
pipe_stderr_ = bp::pipe();
pipe_stdout_ = bp::pipe();
stringstream params;
params << " " << params_;
params << " \"--stream=" + stream_id + "\"";
if (server_setttings.http.enabled)
{
params << " --snapcast-port=" << server_setttings.http.port;
params << " --snapcast-host=" << server_setttings.http.host;
}
LOG(DEBUG, LOG_TAG) << "Starting control script: '" << script_ << "', params: '" << params.str() << "'\n";
try
{
process_ = bp::child(

View file

@ -87,7 +87,7 @@ private:
class ScriptStreamControl : public StreamControl
{
public:
ScriptStreamControl(const boost::asio::any_io_executor& executor, const std::string& script);
ScriptStreamControl(const boost::asio::any_io_executor& executor, const std::string& script, const std::string& params);
virtual ~ScriptStreamControl() = default;
void stop() override;
@ -109,6 +109,7 @@ protected:
boost::asio::streambuf streambuf_stderr_;
std::string script_;
std::string params_;
bp::opstream in_;
};