Added stream tagging support
This commit is contained in:
parent
4d50364703
commit
6bec4066a9
8 changed files with 293 additions and 35 deletions
|
@ -471,6 +471,43 @@ bool Util::streamAlive(std::string &streamname){
|
|||
}
|
||||
}
|
||||
|
||||
/// Returns active tags for an exact-matching (already sanitized) streamname
|
||||
std::set<std::string> Util::streamTags(const std::string &streamname){
|
||||
std::set<std::string> ret;
|
||||
|
||||
IPC::sharedPage shmStreams(SHM_STATE_STREAMS, 0, false, false);
|
||||
// Abort silently if page cannot be loaded
|
||||
if (!shmStreams){return ret;}
|
||||
|
||||
Util::RelAccX rlxStreams(shmStreams.mapped);
|
||||
// Abort silently if page cannot be loaded
|
||||
if (!rlxStreams.isReady()){return ret;}
|
||||
|
||||
uint64_t startPos = rlxStreams.getDeleted();
|
||||
uint64_t endPos = rlxStreams.getEndPos();
|
||||
for (uint64_t cPos = startPos; cPos < endPos; ++cPos){
|
||||
const std::string & strm = rlxStreams.getPointer("stream", cPos);
|
||||
if (strm != streamname){continue;}
|
||||
|
||||
// Found it! Fill and break, since only one match can exist.
|
||||
std::string tags = rlxStreams.getPointer("tags", cPos);
|
||||
while (tags.size()){
|
||||
size_t endPos = tags.find(' ');
|
||||
if (!endPos){
|
||||
//extra space, ignore
|
||||
tags.erase(0, 1);
|
||||
continue;
|
||||
}
|
||||
if (endPos == std::string::npos){endPos = tags.size();}
|
||||
ret.insert(tags.substr(0, endPos));
|
||||
if (endPos == tags.size()){break;}
|
||||
tags.erase(0, endPos+1);
|
||||
}
|
||||
break;
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
/// Assures the input for the given stream name is active.
|
||||
/// Does stream name sanitation first, followed by a stream name length check (<= 100 chars).
|
||||
/// Then, checks if an input is already active by running streamAlive(). If yes, return true.
|
||||
|
|
|
@ -18,6 +18,7 @@ namespace Util{
|
|||
std::string getTmpFolder();
|
||||
void sanitizeName(std::string &streamname);
|
||||
bool streamAlive(std::string &streamname);
|
||||
std::set<std::string> streamTags(const std::string &streamname);
|
||||
bool startInput(std::string streamname, std::string filename = "", bool forkFirst = true,
|
||||
bool isProvider = false,
|
||||
const std::map<std::string, std::string> &overrides = std::map<std::string, std::string>(),
|
||||
|
|
|
@ -203,6 +203,15 @@ namespace Triggers{
|
|||
if ((streamName.size() == stringLen || splitter == stringLen) &&
|
||||
strncmp(strPtr + bPos + 4, streamName.data(), stringLen) == 0){
|
||||
isHandled = true;
|
||||
break;
|
||||
}
|
||||
// Tag-based? Check tags for this stream
|
||||
if (strPtr[bPos + 4] == '#'){
|
||||
std::set<std::string> tags = Util::streamTags(streamName);
|
||||
if (tags.count(std::string(strPtr + bPos + 5, stringLen - 1))){
|
||||
isHandled = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
bPos += stringLen + 4;
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue