mirror of
https://github.com/badaix/snapcast.git
synced 2025-05-12 00:26:41 +02:00
Force unique stream name, use name as id
This commit is contained in:
parent
d76aac0de7
commit
341466ceb5
7 changed files with 32 additions and 39 deletions
|
@ -294,10 +294,10 @@ void StreamServer::onMessageReceived(StreamSession* connection, const msg::BaseM
|
|||
|
||||
// Assign and update stream
|
||||
PcmStreamPtr stream = streamManager_->getStream(client->config.streamId);
|
||||
if (stream == nullptr)
|
||||
if (!stream)
|
||||
{
|
||||
stream = streamManager_->getDefaultStream();
|
||||
client->config.streamId = stream->getUri().id();
|
||||
client->config.streamId = stream->getId();
|
||||
}
|
||||
Config::instance().save();
|
||||
|
||||
|
@ -384,8 +384,8 @@ void StreamServer::start()
|
|||
//TODO: check uniqueness of the stream
|
||||
for (const auto& streamUri: settings_.pcmStreams)
|
||||
{
|
||||
PcmStream* stream = streamManager_->addStream(streamUri);
|
||||
if (stream != NULL)
|
||||
PcmStreamPtr stream = streamManager_->addStream(streamUri);
|
||||
if (stream)
|
||||
logO << "Stream: " << stream->getUri().toJson() << "\n";
|
||||
}
|
||||
streamManager_->start();
|
||||
|
|
|
@ -77,6 +77,12 @@ const std::string& PcmStream::getName() const
|
|||
}
|
||||
|
||||
|
||||
const std::string& PcmStream::getId() const
|
||||
{
|
||||
return getName();
|
||||
}
|
||||
|
||||
|
||||
const SampleFormat& PcmStream::getSampleFormat() const
|
||||
{
|
||||
return sampleFormat_;
|
||||
|
@ -154,7 +160,7 @@ json PcmStream::toJson() const
|
|||
|
||||
json j = {
|
||||
{"uri", uri_.toJson()},
|
||||
{"id", uri_.id()},
|
||||
{"id", getId()},
|
||||
{"status", state}
|
||||
};
|
||||
return j;
|
||||
|
|
|
@ -78,6 +78,7 @@ public:
|
|||
|
||||
virtual const StreamUri& getUri() const;
|
||||
virtual const std::string& getName() const;
|
||||
virtual const std::string& getId() const;
|
||||
virtual const SampleFormat& getSampleFormat() const;
|
||||
|
||||
virtual ReaderState getState() const;
|
||||
|
|
|
@ -36,7 +36,7 @@ StreamManager::StreamManager(PcmListener* pcmListener, const std::string& defaul
|
|||
}
|
||||
|
||||
|
||||
PcmStream* StreamManager::addStream(const std::string& uri)
|
||||
PcmStreamPtr StreamManager::addStream(const std::string& uri)
|
||||
{
|
||||
StreamUri streamUri(uri);
|
||||
|
||||
|
@ -54,38 +54,44 @@ PcmStream* StreamManager::addStream(const std::string& uri)
|
|||
|
||||
// for (auto kv: streamUri.query)
|
||||
// logD << "key: '" << kv.first << "' value: '" << kv.second << "'\n";
|
||||
PcmStreamPtr stream(nullptr);
|
||||
|
||||
if (streamUri.scheme == "pipe")
|
||||
{
|
||||
streams_.push_back(make_shared<PipeStream>(pcmListener_, streamUri));
|
||||
return streams_.back().get();
|
||||
stream = make_shared<PipeStream>(pcmListener_, streamUri);
|
||||
}
|
||||
else if (streamUri.scheme == "file")
|
||||
{
|
||||
streams_.push_back(make_shared<FileStream>(pcmListener_, streamUri));
|
||||
return streams_.back().get();
|
||||
stream = make_shared<FileStream>(pcmListener_, streamUri);
|
||||
}
|
||||
else if (streamUri.scheme == "process")
|
||||
{
|
||||
streams_.push_back(make_shared<ProcessStream>(pcmListener_, streamUri));
|
||||
return streams_.back().get();
|
||||
stream = make_shared<ProcessStream>(pcmListener_, streamUri);
|
||||
}
|
||||
else if (streamUri.scheme == "spotify")
|
||||
{
|
||||
streams_.push_back(make_shared<SpotifyStream>(pcmListener_, streamUri));
|
||||
return streams_.back().get();
|
||||
stream = make_shared<SpotifyStream>(pcmListener_, streamUri);
|
||||
}
|
||||
else if (streamUri.scheme == "airplay")
|
||||
{
|
||||
streams_.push_back(make_shared<AirplayStream>(pcmListener_, streamUri));
|
||||
return streams_.back().get();
|
||||
stream = make_shared<AirplayStream>(pcmListener_, streamUri);
|
||||
}
|
||||
else
|
||||
{
|
||||
throw SnapException("Unknown stream type: " + streamUri.scheme);
|
||||
}
|
||||
|
||||
return NULL;
|
||||
if (stream)
|
||||
{
|
||||
for (auto s: streams_)
|
||||
{
|
||||
if (s->getName() == stream->getName())
|
||||
throw SnapException("Stream with name \"" + stream->getName() + "\" already exists");
|
||||
}
|
||||
streams_.push_back(stream);
|
||||
}
|
||||
|
||||
return stream;
|
||||
}
|
||||
|
||||
|
||||
|
@ -108,7 +114,7 @@ const PcmStreamPtr StreamManager::getStream(const std::string& id)
|
|||
{
|
||||
for (auto stream: streams_)
|
||||
{
|
||||
if (stream->getUri().id() == id)
|
||||
if (stream->getId() == id)
|
||||
return stream;
|
||||
}
|
||||
return nullptr;
|
||||
|
|
|
@ -13,7 +13,7 @@ class StreamManager
|
|||
public:
|
||||
StreamManager(PcmListener* pcmListener, const std::string& defaultSampleFormat, const std::string& defaultCodec, size_t defaultReadBufferMs = 20);
|
||||
|
||||
PcmStream* addStream(const std::string& uri);
|
||||
PcmStreamPtr addStream(const std::string& uri);
|
||||
void start();
|
||||
void stop();
|
||||
const std::vector<PcmStreamPtr>& getStreams();
|
||||
|
|
|
@ -41,15 +41,6 @@ StreamUri::StreamUri(const std::string& streamUri)
|
|||
string decodedUri = uriDecode(uri);
|
||||
logD << "StreamUri: " << decodedUri << "\n";
|
||||
|
||||
id_ = decodedUri;
|
||||
pos = id_.find('?');
|
||||
if (pos != string::npos)
|
||||
id_ = id_.substr(0, pos);
|
||||
pos = id_.find('#');
|
||||
if (pos != string::npos)
|
||||
id_ = id_.substr(0, pos);
|
||||
logD << "id: '" << id_ << "'\n";
|
||||
|
||||
string tmp(decodedUri);
|
||||
|
||||
pos = tmp.find(':');
|
||||
|
@ -98,8 +89,6 @@ StreamUri::StreamUri(const std::string& streamUri)
|
|||
string key = trim_copy(kv.substr(0, pos));
|
||||
string value = trim_copy(kv.substr(pos+1));
|
||||
query[key] = value;
|
||||
if (key == "id")
|
||||
id_ = value;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -119,12 +108,6 @@ json StreamUri::toJson() const
|
|||
}
|
||||
|
||||
|
||||
std::string StreamUri::id() const
|
||||
{
|
||||
return id_;
|
||||
}
|
||||
|
||||
|
||||
std::string StreamUri::getQuery(const std::string& key, const std::string& def) const
|
||||
{
|
||||
auto iter = query.find(key);
|
||||
|
|
|
@ -49,9 +49,6 @@ struct StreamUri
|
|||
std::string id() const;
|
||||
json toJson() const;
|
||||
std::string getQuery(const std::string& key, const std::string& def = "") const;
|
||||
|
||||
private:
|
||||
std::string id_;
|
||||
};
|
||||
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue