Added backwards-compatible support for new stream source API.
This commit is contained in:
parent
f04c2b8547
commit
88e52ad936
1 changed files with 26 additions and 7 deletions
|
@ -10,19 +10,20 @@ namespace Controller {
|
||||||
std::map<std::string, int> lastBuffer; ///< Last moment of contact with all buffers.
|
std::map<std::string, int> lastBuffer; ///< Last moment of contact with all buffers.
|
||||||
|
|
||||||
bool streamsEqual(JSON::Value & one, JSON::Value & two){
|
bool streamsEqual(JSON::Value & one, JSON::Value & two){
|
||||||
if (one["channel"]["URL"] != two["channel"]["URL"]){
|
if (one["source"] != two["source"]){
|
||||||
return false;
|
|
||||||
}
|
|
||||||
if (one["preset"]["cmd"] != two["preset"]["cmd"]){
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
void startStream(std::string name, JSON::Value & data){
|
void startStream(std::string name, JSON::Value & data){
|
||||||
std::string URL = data["channel"]["URL"];
|
std::string URL = data["source"];
|
||||||
std::string preset = data["preset"]["cmd"];
|
|
||||||
std::string cmd1, cmd2, cmd3;
|
std::string cmd1, cmd2, cmd3;
|
||||||
|
if (URL == ""){
|
||||||
|
Log("STRM", "Error for stream " + name + "! Source parameter missing.");
|
||||||
|
data["error"] = "Missing source parameter!";
|
||||||
|
return;
|
||||||
|
}
|
||||||
if (URL.substr(0, 4) == "push"){
|
if (URL.substr(0, 4) == "push"){
|
||||||
std::string pusher = URL.substr(7);
|
std::string pusher = URL.substr(7);
|
||||||
cmd2 = "MistBuffer -s " + name + " " + pusher;
|
cmd2 = "MistBuffer -s " + name + " " + pusher;
|
||||||
|
@ -40,7 +41,7 @@ namespace Controller {
|
||||||
data["error"] = "Available";
|
data["error"] = "Available";
|
||||||
return; //MistPlayer handles VoD
|
return; //MistPlayer handles VoD
|
||||||
}else{
|
}else{
|
||||||
cmd1 = "ffmpeg -re -async 2 -i " + URL + " " + preset + " -f flv -";
|
cmd1 = "ffmpeg -re -async 2 -i " + URL + " -f flv -";
|
||||||
cmd2 = "MistFLV2DTSC";
|
cmd2 = "MistFLV2DTSC";
|
||||||
}
|
}
|
||||||
cmd3 = "MistBuffer -s " + name;
|
cmd3 = "MistBuffer -s " + name;
|
||||||
|
@ -87,6 +88,8 @@ namespace Controller {
|
||||||
|
|
||||||
void CheckStreams(JSON::Value & in, JSON::Value & out){
|
void CheckStreams(JSON::Value & in, JSON::Value & out){
|
||||||
bool changed = false;
|
bool changed = false;
|
||||||
|
|
||||||
|
//check for new streams and updates
|
||||||
for (JSON::ObjIter jit = in.ObjBegin(); jit != in.ObjEnd(); jit++){
|
for (JSON::ObjIter jit = in.ObjBegin(); jit != in.ObjEnd(); jit++){
|
||||||
if (out.isMember(jit->first)){
|
if (out.isMember(jit->first)){
|
||||||
if ( !streamsEqual(jit->second, out[jit->first])){
|
if ( !streamsEqual(jit->second, out[jit->first])){
|
||||||
|
@ -99,12 +102,28 @@ namespace Controller {
|
||||||
startStream(jit->first, jit->second);
|
startStream(jit->first, jit->second);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//check for deleted streams
|
||||||
for (JSON::ObjIter jit = out.ObjBegin(); jit != out.ObjEnd(); jit++){
|
for (JSON::ObjIter jit = out.ObjBegin(); jit != out.ObjEnd(); jit++){
|
||||||
if ( !in.isMember(jit->first)){
|
if ( !in.isMember(jit->first)){
|
||||||
Log("STRM", std::string("Deleted stream ") + jit->first);
|
Log("STRM", std::string("Deleted stream ") + jit->first);
|
||||||
Util::Procs::Stop(jit->first);
|
Util::Procs::Stop(jit->first);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//update old-style configurations to new-style
|
||||||
|
for (JSON::ObjIter jit = in.ObjBegin(); jit != in.ObjEnd(); jit++){
|
||||||
|
if (jit->second.isMember("channel")){
|
||||||
|
if ( !jit->second.isMember("source")){
|
||||||
|
jit->second["source"] = jit->second["channel"]["URL"];
|
||||||
|
}
|
||||||
|
jit->second.removeMember("channel");
|
||||||
|
}
|
||||||
|
if (jit->second.isMember("preset")){
|
||||||
|
jit->second.removeMember("preset");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
out = in;
|
out = in;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue