mirror of
https://github.com/badaix/snapcast.git
synced 2025-04-28 17:57:05 +02:00
Add support for controlscriptparams
This commit is contained in:
parent
b71e303083
commit
60dc1aa48a
8 changed files with 24 additions and 10 deletions
|
@ -13,7 +13,7 @@ The following notation is used in this paragraph:
|
|||
The general format of an audio source is:
|
||||
|
||||
```sh
|
||||
TYPE://host/path?name=<name>[&codec=<codec>][&sampleformat=<sampleformat>][&chunk_ms=<chunk ms>][&controlscript=<control script filename>]
|
||||
TYPE://host/path?name=<name>[&codec=<codec>][&sampleformat=<sampleformat>][&chunk_ms=<chunk ms>][&controlscript=<control script filename>[&controlscriptparams=<control script command line arguments>]]
|
||||
```
|
||||
|
||||
Within the `[stream]` section there are some global parameters valid for all `source`s:
|
||||
|
@ -37,6 +37,7 @@ Supported parameters for all source types:
|
|||
- `chunk_ms`: Override the global `chunk_ms`
|
||||
- `dryout_ms`: Supported by non-blocking sourced: when no new data is read from the source, send silence to the clients
|
||||
- `controlscript`: Script to control the stream source and read and provide meta data, see [stream_plugin.md](json_rpc_api/stream_plugin.md)
|
||||
- `controlscriptparams`: Control script command line arguments, must be url-encoded (use `%20` instead of a space ` `), e.g. `--mopidy-host=192.168.42.23%20--debug`
|
||||
|
||||
Available audio source types are:
|
||||
|
||||
|
|
|
@ -11,6 +11,7 @@ source = pipe:///tmp/snapfifo?name=MPD&controlscript=meta_mpd.py
|
|||
```
|
||||
|
||||
If a relative path is given, Snapserver will search the script in `/usr/share/snapserver/plug-ins`. An example script `meta_mpd.py` is shipped with the server installation, that can be used with mpd stream sources.
|
||||
Paramters are passed to the control script using the `controlscriptparams` stream source parameter.
|
||||
|
||||
A Stream plugin must support and handle the following [requests](#requests), sent by the Snapcast server
|
||||
|
||||
|
|
|
@ -114,7 +114,7 @@ doc_root = /usr/share/snapserver/snapweb
|
|||
# [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"
|
||||
#
|
||||
# Format: TYPE://host/path?name=<name>[&codec=<codec>][&sampleformat=<sampleformat>][&chunk_ms=<chunk ms>][&controlscript=<control script filename>]
|
||||
# Format: TYPE://host/path?name=<name>[&codec=<codec>][&sampleformat=<sampleformat>][&chunk_ms=<chunk ms>][&controlscript=<control script filename>[&controlscriptparams=<control script command line arguments>]]
|
||||
# parameters have the form "key=value", they are concatenated with an "&" character
|
||||
# parameter "name" is mandatory for all sources, while codec, sampleformat and chunk_ms are optional
|
||||
# and will override the default codec, sampleformat or chunk_ms settings
|
||||
|
@ -157,6 +157,7 @@ source = pipe:///tmp/snapfifo?name=default
|
|||
#send_to_muted = false
|
||||
#
|
||||
|
||||
|
||||
# Streaming client options ####################################################
|
||||
#
|
||||
[streaming_client]
|
||||
|
|
|
@ -119,8 +119,8 @@ int main(int argc, char* argv[])
|
|||
&settings.stream.sendAudioToMutedClients);
|
||||
|
||||
// streaming_client options
|
||||
conf.add<Value<uint16_t>>("", "streaming_client.initial_volume", "Volume [percent] assigned to new streaming clients", settings.streamingclient.initialVolume,
|
||||
&settings.streamingclient.initialVolume);
|
||||
conf.add<Value<uint16_t>>("", "streaming_client.initial_volume", "Volume [percent] assigned to new streaming clients",
|
||||
settings.streamingclient.initialVolume, &settings.streamingclient.initialVolume);
|
||||
|
||||
// logging settings
|
||||
conf.add<Value<string>>("", "logging.sink", "log sink [null,system,stdout,stderr,file:<filename>]", settings.logging.sink, &settings.logging.sink);
|
||||
|
|
|
@ -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_)
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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(
|
||||
|
|
|
@ -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_;
|
||||
};
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue