Added basic stream fallback feature, allowing to redirect to a different stream name on stream source load errors

This commit is contained in:
Thulinma 2019-05-24 20:39:08 +02:00
parent 6e125707f1
commit 7beea43d31
4 changed files with 22 additions and 1 deletions

View file

@ -363,6 +363,7 @@ bool Util::startInput(std::string streamname, std::string filename, bool forkFir
// check required parameters // check required parameters
if (input.isMember("required")){ if (input.isMember("required")){
jsonForEachConst(input["required"], prm){ jsonForEachConst(input["required"], prm){
if (!prm->isMember("option")){continue;}
const std::string opt = (*prm)["option"].asStringRef(); const std::string opt = (*prm)["option"].asStringRef();
// check for overrides // check for overrides
if (overrides.count(opt)){ if (overrides.count(opt)){
@ -379,6 +380,7 @@ bool Util::startInput(std::string streamname, std::string filename, bool forkFir
// check optional parameters // check optional parameters
if (input.isMember("optional")){ if (input.isMember("optional")){
jsonForEachConst(input["optional"], prm){ jsonForEachConst(input["optional"], prm){
if (!prm->isMember("option")){continue;}
const std::string opt = (*prm)["option"].asStringRef(); const std::string opt = (*prm)["option"].asStringRef();
// check for overrides // check for overrides
if (overrides.count(opt)){ if (overrides.count(opt)){

View file

@ -82,6 +82,11 @@ namespace Mist {
capa["optional"]["segmentsize"]["option"] = "--segment-size"; capa["optional"]["segmentsize"]["option"] = "--segment-size";
capa["optional"]["segmentsize"]["type"] = "uint"; capa["optional"]["segmentsize"]["type"] = "uint";
capa["optional"]["segmentsize"]["default"] = 1900; capa["optional"]["segmentsize"]["default"] = 1900;
capa["optional"]["fallback_stream"]["name"] = "Fallback stream";
capa["optional"]["fallback_stream"]["help"] = "Alternative stream to load for playback when there is no active broadcast";
capa["optional"]["fallback_stream"]["type"] = "str";
capa["optional"]["fallback_stream"]["default"] = "";
option.null(); option.null();
/*LTS-end*/ /*LTS-end*/

View file

@ -372,6 +372,19 @@ namespace Mist{
} }
}else{ }else{
if (!Util::startInput(streamName, "", true, isPushing())){ if (!Util::startInput(streamName, "", true, isPushing())){
//If stream is configured, use fallback stream setting, if set.
JSON::Value strCnf = Util::getStreamConfig(streamName);
if (strCnf && strCnf["fallback_stream"].asStringRef().size()){
streamName = strCnf["fallback_stream"].asStringRef();
Util::Config::streamName = streamName;
INFO_MSG("Switching to configured fallback stream '%s'", streamName.c_str());
reconnect();
return;
}
//Not configured or no fallback stream? Use the default stream handler instead
//Note: Since fallback stream is handled recursively, the defaultStream handler
//may still be triggered for the fallback stream! This is intentional.
JSON::Value defStrmJson = Util::getGlobalConfig("defaultStream"); JSON::Value defStrmJson = Util::getGlobalConfig("defaultStream");
std::string defStrm = defStrmJson.asString(); std::string defStrm = defStrmJson.asString();
if(Triggers::shouldTrigger("DEFAULT_STREAM", streamName)){ if(Triggers::shouldTrigger("DEFAULT_STREAM", streamName)){

View file

@ -433,7 +433,8 @@ namespace Mist {
H.Clean(); //clean for any possible next requests H.Clean(); //clean for any possible next requests
return; return;
}else if (HTTP::URL(H.url).getExt().substr(0, 3) != "m3u") { }else if (HTTP::URL(H.url).getExt().substr(0, 3) != "m3u") {
std::string tmpStr = H.getUrl().substr(5 + streamName.size()); size_t slashPos = H.getUrl().find('/', 5);
std::string tmpStr = H.getUrl().substr(slashPos);
long long unsigned int from; long long unsigned int from;
if (sscanf(tmpStr.c_str(), "/%u_%u/%llu_%llu.ts", &vidTrack, &audTrack, &from, &until) != 4) { if (sscanf(tmpStr.c_str(), "/%u_%u/%llu_%llu.ts", &vidTrack, &audTrack, &from, &until) != 4) {
if (sscanf(tmpStr.c_str(), "/%u/%llu_%llu.ts", &vidTrack, &from, &until) != 3) { if (sscanf(tmpStr.c_str(), "/%u/%llu_%llu.ts", &vidTrack, &from, &until) != 3) {