mirror of
https://github.com/badaix/snapcast.git
synced 2025-04-29 18:27:12 +02:00
Log stream state as string
This commit is contained in:
parent
178888a512
commit
1725cffc6e
5 changed files with 25 additions and 5 deletions
|
@ -72,7 +72,7 @@ namespace strutils = utils::string;
|
||||||
#ifndef WINDOWS
|
#ifndef WINDOWS
|
||||||
static std::string execGetOutput(const std::string& cmd)
|
static std::string execGetOutput(const std::string& cmd)
|
||||||
{
|
{
|
||||||
std::shared_ptr<FILE> pipe(popen((cmd + " 2> /dev/null").c_str(), "r"), pclose);
|
std::shared_ptr<::FILE> pipe(popen((cmd + " 2> /dev/null").c_str(), "r"), pclose);
|
||||||
if (!pipe)
|
if (!pipe)
|
||||||
return "";
|
return "";
|
||||||
char buffer[1024];
|
char buffer[1024];
|
||||||
|
|
|
@ -73,7 +73,7 @@ void Server::onStateChanged(const PcmStream* pcmStream, ReaderState state)
|
||||||
// clang-format off
|
// clang-format off
|
||||||
// Notification: {"jsonrpc":"2.0","method":"Stream.OnUpdate","params":{"id":"stream 1","stream":{"id":"stream 1","status":"idle","uri":{"fragment":"","host":"","path":"/tmp/snapfifo","query":{"chunk_ms":"20","codec":"flac","name":"stream 1","sampleformat":"48000:16:2"},"raw":"pipe:///tmp/snapfifo?name=stream 1","scheme":"pipe"}}}}
|
// Notification: {"jsonrpc":"2.0","method":"Stream.OnUpdate","params":{"id":"stream 1","stream":{"id":"stream 1","status":"idle","uri":{"fragment":"","host":"","path":"/tmp/snapfifo","query":{"chunk_ms":"20","codec":"flac","name":"stream 1","sampleformat":"48000:16:2"},"raw":"pipe:///tmp/snapfifo?name=stream 1","scheme":"pipe"}}}}
|
||||||
// clang-format on
|
// clang-format on
|
||||||
LOG(INFO, LOG_TAG) << "onStateChanged (" << pcmStream->getName() << "): " << static_cast<int>(state) << "\n";
|
LOG(INFO, LOG_TAG) << "onStateChanged (" << pcmStream->getName() << "): " << state << "\n";
|
||||||
// LOG(INFO, LOG_TAG) << pcmStream->toJson().dump(4);
|
// LOG(INFO, LOG_TAG) << pcmStream->toJson().dump(4);
|
||||||
json notification = jsonrpcpp::Notification("Stream.OnUpdate", jsonrpcpp::Parameter("id", pcmStream->getId(), "stream", pcmStream->toJson())).to_json();
|
json notification = jsonrpcpp::Notification("Stream.OnUpdate", jsonrpcpp::Parameter("id", pcmStream->getId(), "stream", pcmStream->toJson())).to_json();
|
||||||
controlServer_->send(notification.dump(), nullptr);
|
controlServer_->send(notification.dump(), nullptr);
|
||||||
|
|
|
@ -94,7 +94,7 @@ void MetaStream::onMetaChanged(const PcmStream* pcmStream)
|
||||||
|
|
||||||
void MetaStream::onStateChanged(const PcmStream* pcmStream, ReaderState state)
|
void MetaStream::onStateChanged(const PcmStream* pcmStream, ReaderState state)
|
||||||
{
|
{
|
||||||
LOG(DEBUG, LOG_TAG) << "onStateChanged: " << pcmStream->getName() << ", state: " << static_cast<int>(state) << "\n";
|
LOG(DEBUG, LOG_TAG) << "onStateChanged: " << pcmStream->getName() << ", state: " << state << "\n";
|
||||||
std::lock_guard<std::mutex> lock(mutex_);
|
std::lock_guard<std::mutex> lock(mutex_);
|
||||||
for (const auto& stream : streams_)
|
for (const auto& stream : streams_)
|
||||||
{
|
{
|
||||||
|
|
|
@ -103,7 +103,8 @@ std::string PcmStream::getCodec() const
|
||||||
|
|
||||||
void PcmStream::start()
|
void PcmStream::start()
|
||||||
{
|
{
|
||||||
LOG(DEBUG, LOG_TAG) << "Start: " << name_ << ", sampleformat: " << sampleFormat_.toString() << "\n";
|
LOG(DEBUG, LOG_TAG) << "Start: " << name_ << ", type: " << uri_.scheme << ", sampleformat: " << sampleFormat_.toString() << ", codec: " << getCodec()
|
||||||
|
<< "\n";
|
||||||
encoder_->init([this](const encoder::Encoder& encoder, std::shared_ptr<msg::PcmChunk> chunk, double duration) { chunkEncoded(encoder, chunk, duration); },
|
encoder_->init([this](const encoder::Encoder& encoder, std::shared_ptr<msg::PcmChunk> chunk, double duration) { chunkEncoded(encoder, chunk, duration); },
|
||||||
sampleFormat_);
|
sampleFormat_);
|
||||||
active_ = true;
|
active_ = true;
|
||||||
|
@ -126,7 +127,7 @@ void PcmStream::setState(ReaderState newState)
|
||||||
{
|
{
|
||||||
if (newState != state_)
|
if (newState != state_)
|
||||||
{
|
{
|
||||||
LOG(INFO, LOG_TAG) << "State changed: " << name_ << ", state: " << static_cast<int>(state_) << " => " << static_cast<int>(newState) << "\n";
|
LOG(INFO, LOG_TAG) << "State changed: " << name_ << ", state: " << state_ << " => " << newState << "\n";
|
||||||
state_ = newState;
|
state_ = newState;
|
||||||
for (auto* listener : pcmListeners_)
|
for (auto* listener : pcmListeners_)
|
||||||
{
|
{
|
||||||
|
|
|
@ -46,6 +46,25 @@ enum class ReaderState
|
||||||
kDisabled = 3
|
kDisabled = 3
|
||||||
};
|
};
|
||||||
|
|
||||||
|
static std::ostream& operator<<(std::ostream& os, const ReaderState& reader_state)
|
||||||
|
{
|
||||||
|
switch (reader_state)
|
||||||
|
{
|
||||||
|
case ReaderState::kIdle:
|
||||||
|
os << "idle";
|
||||||
|
break;
|
||||||
|
case ReaderState::kPlaying:
|
||||||
|
os << "playing";
|
||||||
|
break;
|
||||||
|
case ReaderState::kDisabled:
|
||||||
|
os << "disabled";
|
||||||
|
break;
|
||||||
|
case ReaderState::kUnknown:
|
||||||
|
default:
|
||||||
|
os << "unknown";
|
||||||
|
}
|
||||||
|
return os;
|
||||||
|
}
|
||||||
|
|
||||||
static constexpr auto kUriCodec = "codec";
|
static constexpr auto kUriCodec = "codec";
|
||||||
static constexpr auto kUriName = "name";
|
static constexpr auto kUriName = "name";
|
||||||
|
|
Loading…
Add table
Reference in a new issue