Forward metadata and properties in meta stream

This commit is contained in:
badaix 2021-06-27 13:00:35 +02:00
parent fba20fb7fe
commit 3120a18326
4 changed files with 36 additions and 13 deletions

View file

@ -123,7 +123,7 @@ void Controller::getNextMessage()
reconnect();
return;
}
if (!response)
{
return getNextMessage();

View file

@ -86,18 +86,21 @@ void MetaStream::stop()
void MetaStream::onMetadataChanged(const PcmStream* pcmStream, const Metatags& metadata)
{
std::ignore = metadata;
LOG(DEBUG, LOG_TAG) << "onMetadataChanged: " << pcmStream->getName() << "\n";
std::lock_guard<std::mutex> lock(mutex_);
if (pcmStream != active_stream_.get())
return;
setMetadata(metadata);
}
void MetaStream::onPropertiesChanged(const PcmStream* pcmStream, const Properties& properties)
{
std::ignore = properties;
LOG(DEBUG, LOG_TAG) << "onPropertiesChanged: " << pcmStream->getName() << "\n";
std::lock_guard<std::mutex> lock(mutex_);
if (pcmStream != active_stream_.get())
return;
setProperties(properties);
}
@ -117,6 +120,8 @@ void MetaStream::onStateChanged(const PcmStream* pcmStream, ReaderState state)
LOG(INFO, LOG_TAG) << "Stream: " << name_ << ", switching active stream: " << (active_stream_ ? active_stream_->getName() : "<null>") << " => "
<< stream->getName() << "\n";
active_stream_ = stream;
setMetadata(active_stream_->getMetadata());
setProperties(active_stream_->getProperties());
resampler_ = make_unique<Resampler>(active_stream_->getSampleFormat(), sampleFormat_);
}

View file

@ -158,6 +158,9 @@ void PcmStream::onControlNotification(const jsonrpcpp::Notification& notificatio
if (response.error().code() == 0)
setMetadata(response.result());
});
// TODO: Add capabilities or settings?
// {"jsonrpc": "2.0", "method": "Plugin.Stream.Ready", "params": {"pollProperties": 10, "responseTimeout": 5}}
pollProperties();
}
else if (notification.method() == "Plugin.Stream.Log")

View file

@ -136,6 +136,13 @@ void StreamControl::onLog(std::string message)
ScriptStreamControl::ScriptStreamControl(boost::asio::io_context& ioc, const std::string& script) : StreamControl(ioc), script_(script)
{
// auto fileExists = [](const std::string& filename) {
// struct stat buffer;
// return (stat(filename.c_str(), &buffer) == 0);
// };
// if (!fileExists(script_))
// throw SnapException("Control script not found: \"" + script_ + "\"");
}
@ -147,16 +154,24 @@ void ScriptStreamControl::doStart(const std::string& stream_id, const ServerSett
params << " \"--stream=" + stream_id + "\"";
if (server_setttings.http.enabled)
params << " --snapcast-port=" << server_setttings.http.port;
process_ = bp::child(
script_ + params.str(), bp::std_out > pipe_stdout_, bp::std_err > pipe_stderr_, bp::std_in < in_,
bp::on_exit =
[](int exit, const std::error_code& ec_in) {
auto severity = AixLog::Severity::debug;
if (exit != 0)
severity = AixLog::Severity::error;
LOG(severity, LOG_TAG) << "Exit code: " << exit << ", message: " << ec_in.message() << "\n";
},
ioc_);
try
{
process_ = bp::child(
script_ + params.str(), bp::std_out > pipe_stdout_, bp::std_err > pipe_stderr_, bp::std_in < in_,
bp::on_exit =
[](int exit, const std::error_code& ec_in) {
auto severity = AixLog::Severity::debug;
if (exit != 0)
severity = AixLog::Severity::error;
LOG(severity, LOG_TAG) << "Exit code: " << exit << ", message: " << ec_in.message() << "\n";
},
ioc_);
}
catch (const std::exception& e)
{
throw SnapException("Failed to start control script: '" + script_ + "', exception: " + e.what());
}
stream_stdout_ = make_unique<boost::asio::posix::stream_descriptor>(ioc_, pipe_stdout_.native_source());
stream_stderr_ = make_unique<boost::asio::posix::stream_descriptor>(ioc_, pipe_stderr_.native_source());
stdoutReadLine();