Initial TS Input commit
This commit is contained in:
parent
10f0f6bb92
commit
1f4b523b1b
33 changed files with 1300 additions and 643 deletions
|
@ -244,16 +244,16 @@ int Controller::handleAPIConnection(Socket::Connection & conn){
|
|||
//if object, delete all entries
|
||||
//if string, delete just the one
|
||||
if (Request["deletestream"].isString()){
|
||||
Controller::Storage["streams"].removeMember(Request["deletestream"].asStringRef());
|
||||
Controller::deleteStream(Request["deletestream"].asStringRef(), Controller::Storage["streams"]);
|
||||
}
|
||||
if (Request["deletestream"].isArray()){
|
||||
for (JSON::ArrIter it = Request["deletestream"].ArrBegin(); it != Request["deletestream"].ArrEnd(); ++it){
|
||||
Controller::Storage["streams"].removeMember(it->asString());
|
||||
Controller::deleteStream(it->asStringRef(), Controller::Storage["streams"]);
|
||||
}
|
||||
}
|
||||
if (Request["deletestream"].isObject()){
|
||||
for (JSON::ObjIter it = Request["deletestream"].ObjBegin(); it != Request["deletestream"].ObjEnd(); ++it){
|
||||
Controller::Storage["streams"].removeMember(it->first);
|
||||
Controller::deleteStream(it->first, Controller::Storage["streams"]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -15,6 +15,7 @@
|
|||
|
||||
///\brief Holds everything unique to the controller.
|
||||
namespace Controller {
|
||||
std::map<std::string, pid_t> inputProcesses;
|
||||
|
||||
///\brief Checks whether two streams are equal.
|
||||
///\param one The first stream for the comparison.
|
||||
|
@ -58,6 +59,31 @@ namespace Controller {
|
|||
}
|
||||
if (URL.substr(0, 1) != "/"){
|
||||
//push-style stream
|
||||
if (data["udpport"].asInt()){
|
||||
std::string udpPort = data["udpport"].asString();
|
||||
//Check running
|
||||
if (!inputProcesses.count(name) || !Util::Procs::isRunning(inputProcesses[name])){
|
||||
// False: start TS input
|
||||
INFO_MSG("No TS Input running on port %s for stream %s, starting it", udpPort.c_str(), name.c_str());
|
||||
std::deque<std::string> command;
|
||||
command.push_back(Util::getMyPath() + "MistInTSStream");
|
||||
command.push_back("-s");
|
||||
command.push_back(name);
|
||||
command.push_back("-p");
|
||||
command.push_back(udpPort);
|
||||
command.push_back(URL);
|
||||
int stdIn = 0;
|
||||
int stdOut = 1;
|
||||
int stdErr = 2;
|
||||
pid_t program = Util::Procs::StartPiped(command, &stdIn, &stdOut, &stdErr);
|
||||
if (program){
|
||||
inputProcesses[name] = program;
|
||||
}
|
||||
}
|
||||
//Check hasViewers
|
||||
// True: data["online"] = 2;
|
||||
// False: data["online"] =11;
|
||||
}
|
||||
return;
|
||||
}
|
||||
if (URL.substr(0, 1) == "/"){
|
||||
|
@ -204,13 +230,12 @@ namespace Controller {
|
|||
for (JSON::ObjIter jit = out.ObjBegin(); jit != out.ObjEnd(); jit++){
|
||||
if ( !in.isMember(jit->first)){
|
||||
toDelete.insert(jit->first);
|
||||
Log("STRM", std::string("Deleted stream ") + jit->first);
|
||||
}
|
||||
}
|
||||
//actually delete the streams
|
||||
while (toDelete.size() > 0){
|
||||
std::string deleting = *(toDelete.begin());
|
||||
out.removeMember(deleting);
|
||||
deleteStream(deleting, out);
|
||||
toDelete.erase(deleting);
|
||||
}
|
||||
|
||||
|
@ -229,4 +254,19 @@ namespace Controller {
|
|||
|
||||
}
|
||||
|
||||
void deleteStream(const std::string & name, JSON::Value & out) {
|
||||
if (!out.isMember(name)){
|
||||
return;
|
||||
}
|
||||
Log("STRM", std::string("Deleted stream ") + name);
|
||||
out.removeMember(name);
|
||||
if (inputProcesses.count(name)){
|
||||
pid_t procId = inputProcesses[name];
|
||||
if (Util::Procs::isRunning(procId)){
|
||||
Util::Procs::Stop(procId);
|
||||
}
|
||||
inputProcesses.erase(name);
|
||||
}
|
||||
}
|
||||
|
||||
} //Controller namespace
|
||||
|
|
|
@ -6,9 +6,11 @@ namespace Controller {
|
|||
bool CheckAllStreams(JSON::Value & data);
|
||||
void CheckStreams(JSON::Value & in, JSON::Value & out);
|
||||
void AddStreams(JSON::Value & in, JSON::Value & out);
|
||||
void deleteStream(const std::string & name, JSON::Value & out);
|
||||
|
||||
struct liveCheck {
|
||||
long long int lastms;
|
||||
long long int last_active;
|
||||
};
|
||||
|
||||
} //Controller namespace
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue